Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVolume.hh
Go to the documentation of this file.
1 #ifndef __JGIZMO__JVOLUME__
2 #define __JGIZMO__JVOLUME__
3 
4 #include <cmath>
5 
6 #include "TAxis.h"
7 
8 #include "evt/Head.hh"
9 #include "JAAnet/JHead.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JGIZMO {}
17 namespace JPP { using namespace JGIZMO; }
18 
19 namespace JGIZMO {
20 
21  /**
22  * Auxiliary class for histogramming of effective volume.
23  * In this, it is assumed that events are generated according \f$\frac{dN}{dE} \propto E^{\alpha}\f$.
24  * The weight is expressed in \f$\mathrm{km}^{3}\f$.
25  */
26  struct JVolume {
27  /**
28  * Constructor.
29  *
30  * \param head Monte Carlo run header
31  * \param Elog10 application of log10 to energy
32  */
33  JVolume(const Head& head,
34  const bool Elog10 = false) :
35  elog (Elog10),
36  Emin (1.0),
37  Emax (1.0),
38  alpha(0.0),
39  Wall (1.0)
40  {
41  using namespace JAANET;
42 
43  const JHead buffer(head);
44 
45  if (is_valid(buffer.spectrum) &&
46  is_valid(buffer.cut_nu) &&
47  is_valid(buffer.genvol)) {
48 
49  alpha = buffer.spectrum.alpha;
50  Emin = buffer.cut_nu.Emin;
51  Emax = buffer.cut_nu.Emax;
52  Wall = 1.0e-9 * (getW(Emax) - getW(Emin)) * buffer.genvol.volume / buffer.genvol.numberOfEvents; // km^3
53 
54  } else if (is_valid(buffer.cut_in) &&
55  is_valid(buffer.livetime)) {
56 
57  Emin = buffer.cut_in.Emin;
58  Emax = buffer.cut_in.Emax;
59  Wall = 1.0 / buffer.livetime.numberOfSeconds; // Hz
60  }
61  }
62 
63 
64  /**
65  * Get spectral index of energy distribution.
66  *
67  * \return spectral index
68  */
69  inline double getAlpha() const
70  {
71  return alpha;
72  }
73 
74 
75  /**
76  * Get generation dependent weight.
77  *
78  * \return weight
79  */
80  inline double getWall() const
81  {
82  return Wall;
83  }
84 
85 
86  /**
87  * Get minimal abscissa value.
88  *
89  * \return abscissa value
90  */
91  inline Double_t getXmin() const
92  {
93  return getX(Emin);
94  }
95 
96 
97  /**
98  * Get maximal abscissa value.
99  *
100  * \return abscissa value
101  */
102  inline Double_t getXmax() const
103  {
104  return getX(Emax);
105  }
106 
107 
108  /**
109  * Get abscissa value.
110  *
111  * \param E energy
112  * \param constrain constrain
113  * \return abscissa value
114  */
115  inline Double_t getX(const Double_t E, double constrain = false) const
116  {
117  const double x = (elog ? log10(E) : E);
118 
119  if (constrain) {
120  if (x < getXmin()) {
121  return getXmin();
122  } else if (x > getXmax()) {
123  return getXmax();
124  }
125  }
126 
127  return x;
128  }
129 
130 
131  /**
132  * Get energy.
133  *
134  * \param x abscissa value
135  * \param constrain constrain
136  * \return energy
137  */
138  inline Double_t getE(const Double_t x, double constrain = false) const
139  {
140  const double E = (elog ? pow(10.0, x) : x);
141 
142  if (constrain) {
143  if (E < Emin) {
144  return Emin;
145  } else if (E > Emax) {
146  return Emax;
147  }
148  }
149 
150  return E;
151  }
152 
153 
154  /**
155  * Get bin width corrected energy spectrum dependent weight.
156  *
157  * \param axis axis
158  * \param E energy
159  * \return weight [km^3]
160  */
161  inline Double_t getW(TAxis* axis, const Double_t E) const
162  {
163  const Int_t index = axis->FindBin(getX(E));
164 
165  const Double_t xmin = axis->GetBinLowEdge(index);
166  const Double_t xmax = axis->GetBinUpEdge (index);
167 
168  const Double_t Wmin = getW(getE(xmin));
169  const Double_t Wmax = getW(getE(xmax));
170 
171  return Wall / (Wmax - Wmin);
172  }
173 
174 
175  /**
176  * Get generation dependent integral value of given energy.
177  *
178  * \param E energy
179  * \return integral value
180  */
181  inline double getW(const double E) const
182  {
183  if (alpha != -1.0)
184  return pow(E, 1.0 + alpha) / (1.0 + alpha);
185  else
186  return log(E);
187  }
188 
189 
190  /**
191  * Multiply weight.
192  *
193  * \param factor factor
194  * \return this volume
195  */
196  JVolume& mul(const double factor)
197  {
198  Wall *= factor;
199 
200  return *this;
201  }
202 
203 
204  /**
205  * Divide weight.
206  *
207  * \param factor factor
208  * \return this volume
209  */
210  JVolume& div(const double factor)
211  {
212  Wall /= factor;
213 
214  return *this;
215  }
216 
217 
218  protected:
219  bool elog; //!< histogram option
220  double Emin; //!< minimal energy
221  double Emax; //!< maximal energy
222  double alpha; //!< spectral index
223  double Wall; //!< generation volume
224  };
225 }
226 
227 #endif
JAANET::genvol genvol
Definition: JHead.hh:864
double getW(const double E) const
Get generation dependent integral value of given energy.
Definition: JVolume.hh:181
double volume
Volume [m^3].
Definition: JHead.hh:422
JVolume & div(const double factor)
Divide weight.
Definition: JVolume.hh:210
double alpha
Energy spectrum: .
Definition: JHead.hh:320
double numberOfEvents
Number of events.
Definition: JHead.hh:423
double Emax
Maximal energy [GeV].
Definition: JHead.hh:207
Double_t getX(const Double_t E, double constrain=false) const
Get abscissa value.
Definition: JVolume.hh:115
double alpha
spectral index
Definition: JVolume.hh:222
Double_t getXmin() const
Get minimal abscissa value.
Definition: JVolume.hh:91
double getAlpha() const
Get spectral index of energy distribution.
Definition: JVolume.hh:69
JAANET::livetime livetime
Definition: JHead.hh:868
JVolume(const Head &head, const bool Elog10=false)
Constructor.
Definition: JVolume.hh:33
JAANET::spectrum spectrum
Definition: JHead.hh:862
double Emin
minimal energy
Definition: JVolume.hh:220
double Emax
maximal energy
Definition: JVolume.hh:221
Double_t getW(TAxis *axis, const Double_t E) const
Get bin width corrected energy spectrum dependent weight.
Definition: JVolume.hh:161
Monte Carlo run header.
Definition: JHead.hh:727
double Wall
generation volume
Definition: JVolume.hh:223
bool elog
histogram option
Definition: JVolume.hh:219
JAANET::cut_in cut_in
Definition: JHead.hh:860
Double_t getE(const Double_t x, double constrain=false) const
Get energy.
Definition: JVolume.hh:138
JAANET::cut_nu cut_nu
Definition: JHead.hh:861
double Emin
Minimal energy [GeV].
Definition: JHead.hh:206
double numberOfSeconds
Live time [s].
Definition: JHead.hh:588
Double_t getXmax() const
Get maximal abscissa value.
Definition: JVolume.hh:102
bool is_valid(const T &value)
Check validity of given value.
Definition: JHead.hh:711
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:26
JVolume & mul(const double factor)
Multiply weight.
Definition: JVolume.hh:196
double getWall() const
Get generation dependent weight.
Definition: JVolume.hh:80