source.hh
1 #ifndef _icemc_source_hh
2 #define _icemc_source_hh
3 
15 #include <vector>
16 #include "vector.hh" // only two kinds of vectors? we need more!
17 #include "TMath.h"
18 #include "TF1.h"
19 #include <stdint.h>
20 #include "TRandom.h"
21 
22 
25 class Source;
26 
28 {
29 
30 public:
31 
32  SourceModel(const char * model_name);
33 
43  //a way to further restrict source types.
44  struct Restriction
45  {
46  const char * whichSubtype;
47  const char * whichSources;
48  double whichStartTime;
49  double whichEndTime;
50  double maxDec;
51  static double fromString(const char * time);
52  Restriction(double max_dec = 30, const char * sources = "All", const char * subtype = "All",
53  double startTime = 0, double endTime= 2147483647)
54  : whichSubtype(subtype), whichSources(sources), whichStartTime(startTime), whichEndTime(endTime), maxDec(max_dec) {; }
55  };
56 
57  static SourceModel * getSourceModel(const char * key, Restriction r = Restriction());
58 
60  void setUpWeights(double t0, double t1, double minE = 1e9, double maxE=1e12, int N = 1e6);
61 
65  void addSource(Source * source) { sources.push_back(source) ; }
66  //this is the flux at this time divided by the average flux (computed by setUpWeights).
67  double getTimeWeight(double t, bool use_average_nonzero_flux = true) const;
68  double getPerSourceTimeWeight(double t, int i, bool use_average_nonzero_flux = true) const;
69 
70  const char * getName() const { return name; }
72  int getDirectionAndEnergy( Vector * nudir, double t, double & nuE, double minE = 1e9, double maxE = 1e12) ;
74  int getDirection(Vector &nudir, double t, double nuE = 1e10) { return getDirectionAndEnergy( &nudir, t, nuE, nuE, nuE); }
75  TH1 * estimateFlux (double tmin, double tmax, double Emin, double Emax, int nbins = 100, int Ntrials = 1e6);
76  const Source * getSource(int i ) const { return sources[i]; }
77  unsigned getNSources() const { return sources.size(); }
78  virtual ~SourceModel();
79 
81  void computeFluxTimeChanges(std::vector<double> * changes) const;
82 private:
83  std::vector<Source*> sources;
84  double weight_Emin;
85  double weight_Emax;
86  double average_flux;
87  double average_nonzero_flux;
88  std::vector<double> per_source_average_flux;
89  std::vector<double> per_source_average_nonzero_flux;
90  const char * name;
91 };
92 
93 
96 {
97 public:
98  virtual double getFlux(double E, double t) const = 0;
99  virtual double getFluxBetween(double Emin, double Emax, double t) const = 0;
100  virtual double pickEnergy(double Emin, double Emax, double t, TRandom * rng = gRandom) const = 0;
101  virtual void getFluxTimeChanges(std::vector<double> * changes) const { (void) changes ; }
102  virtual ~SourceFlux() { ; }
103 };
104 
105 
106 
107 
108 /*
109  * Source class... for now assume point sources. Can add extended sources later.
110  * */
111 class Source
112 {
113 
114 public:
115  /* The source will own the flux */
116  // !!! The source function takes RA in decimal hours, and dec in decimal degrees. !!!
117  Source (const char * name, double RA, double dec, SourceFlux * flux);
118  const char * getName() const { return name.c_str(); }
119  double getRA() const { return RA; }
120  double getDec() const { return dec; }
121  Vector getDirection( double t) const;
122  const SourceFlux * getFlux() const { return flux; }
123  virtual ~Source() { delete flux; }
124 
125 protected:
126  std::string name;
127  SourceFlux * flux;
128  double RA, dec;
129 };
130 
133 {
134 
135 public:
136  //gamma is the spectral index (so it's positive). norm is the normalization (in units of GeV / cm^2 / s) at normE, where normE is in GeV
137  ConstantExponentialSourceFlux(double gamma, double norm, double normE=1e5);
138  virtual double getFlux(double E, double t) const
139  { (void) t; return A * TMath::Power(E,-gamma) ; }
140  virtual double getFluxBetween(double Emin, double Emax, double t) const
141  { (void) t; return A * ( TMath::Power(Emin,-gamma+1) / (gamma-1) - TMath::Power(Emax,-gamma+1) / (gamma-1)); }
142  virtual double pickEnergy(double Emin, double Emax, double t, TRandom * rng = gRandom) const;
143  virtual ~ConstantExponentialSourceFlux() { ; }
144 
145 private:
146  double gamma;
147  double A;
148  mutable TF1 f;
149 };
150 
151 
152 
153 
154 
157 {
158 
159 public:
160 
161  TimeWindowedExponentialSourceFlux(double t0, double t1, double gamma, double norm, double normE = 0.1, double cutoff = 0 );
162 
163  virtual double getFlux(double E, double t) const
164  {
165  if (t < t0 || t > t1){ return 0; }
166  if (cutoff && E > cutoff) return 0;
167  else return A * TMath::Power(E,-gamma) ;
168  }
169  virtual double getFluxBetween(double Emin, double Emax, double t) const
170  {
171  if (t < t0 || t > t1){ return 0; }
172  if (cutoff && Emin > cutoff) return 0;
173  if (cutoff && Emax > cutoff) Emax = cutoff;
174  return A * ( TMath::Power(Emin,-gamma+1) / (gamma-1) - TMath::Power(Emax,-gamma+1) / (gamma-1));
175  }
176  virtual double pickEnergy(double Emin, double Emax, double t, TRandom * rng = gRandom) const;
177  virtual ~TimeWindowedExponentialSourceFlux() { ; }
178 
179  virtual void getFluxTimeChanges(std::vector<double> * changes) const { changes->push_back(t0); changes->push_back(t1); }
180 private:
181 
182  double gamma;
183  double A;
184  mutable TF1 f;
185  double t0, t1;
186  double cutoff;
187 };
188 
189 #endif
void computeFluxTimeChanges(std::vector< double > *changes) const
Definition: source.cc:552
int getDirectionAndEnergy(Vector *nudir, double t, double &nuE, double minE=1e9, double maxE=1e12)
Definition: source.cc:568
int getDirection(Vector &nudir, double t, double nuE=1e10)
Definition: source.hh:74
static SourceModel * getSourceModel(const char *key, Restriction r=Restriction())
Definition: source.cc:99
void addSource(Source *source)
Definition: source.hh:65
This class represents a three-vector. Operators are overloaded to provide for the familiar operations...
Definition: vector.hh:27
void setUpWeights(double t0, double t1, double minE=1e9, double maxE=1e12, int N=1e6)
Definition: source.cc:684