Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVolume.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JVOLUME__
2 #define __JAANET__JVOLUME__
3 
4 #include <cmath>
5 
6 #include "TAxis.h"
7 
9 #include "JAAnet/JHead.hh"
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace JAANET {}
17 namespace JPP { using namespace JAANET; }
18 
19 namespace JAANET {
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  const JHead buffer(head);
42 
43  if (buffer.is_valid(&JHead::spectrum) &&
44  buffer.is_valid(&JHead::cut_nu) &&
45  buffer.is_valid(&JHead::genvol)) {
46 
47  alpha = buffer.spectrum.alpha;
48  Emin = buffer.cut_nu.Emin;
49  Emax = buffer.cut_nu.Emax;
50  Wall = 1.0e-9 * (getW(Emax) - getW(Emin)) * buffer.genvol.volume / buffer.genvol.numberOfEvents; // km^3
51 
52  } else if (buffer.is_valid(&JHead::cut_in) &&
53  buffer.is_valid(&JHead::livetime)) {
54 
55  Emin = buffer.cut_in.Emin;
56  Emax = buffer.cut_in.Emax;
57  Wall = 1.0 / buffer.livetime.numberOfSeconds; // Hz
58  }
59  }
60 
61 
62  /**
63  * Get spectral index of energy distribution.
64  *
65  * \return spectral index
66  */
67  inline double getAlpha() const
68  {
69  return alpha;
70  }
71 
72 
73  /**
74  * Get generation dependent weight.
75  *
76  * \return weight
77  */
78  inline double getWall() const
79  {
80  return Wall;
81  }
82 
83 
84  /**
85  * Get minimal abscissa value.
86  *
87  * \return abscissa value
88  */
89  inline Double_t getXmin() const
90  {
91  return getX(Emin);
92  }
93 
94 
95  /**
96  * Get maximal abscissa value.
97  *
98  * \return abscissa value
99  */
100  inline Double_t getXmax() const
101  {
102  return getX(Emax);
103  }
104 
105 
106  /**
107  * Get abscissa value.
108  *
109  * \param E energy
110  * \param constrain constrain
111  * \return abscissa value
112  */
113  inline Double_t getX(const Double_t E, double constrain = false) const
114  {
115  const double x = (elog ? log10(E) : E);
116 
117  if (constrain) {
118  if (x < getXmin()) {
119  return getXmin();
120  } else if (x > getXmax()) {
121  return getXmax();
122  }
123  }
124 
125  return x;
126  }
127 
128 
129  /**
130  * Get energy.
131  *
132  * \param x abscissa value
133  * \param constrain constrain
134  * \return energy
135  */
136  inline Double_t getE(const Double_t x, double constrain = false) const
137  {
138  const double E = (elog ? pow(10.0, x) : x);
139 
140  if (constrain) {
141  if (E < Emin) {
142  return Emin;
143  } else if (E > Emax) {
144  return Emax;
145  }
146  }
147 
148  return E;
149  }
150 
151 
152  /**
153  * Get bin width corrected energy spectrum dependent weight.
154  *
155  * \param axis axis
156  * \param E energy
157  * \return weight [km^3]
158  */
159  inline Double_t getW(TAxis* axis, const Double_t E) const
160  {
161  const Int_t index = axis->FindBin(getX(E));
162 
163  const Double_t xmin = axis->GetBinLowEdge(index);
164  const Double_t xmax = axis->GetBinUpEdge (index);
165 
166  const Double_t Wmin = getW(getE(xmin));
167  const Double_t Wmax = getW(getE(xmax));
168 
169  return Wall / (Wmax - Wmin);
170  }
171 
172 
173  /**
174  * Get generation dependent integral value of given energy.
175  *
176  * \param E energy
177  * \return integral value
178  */
179  inline double getW(const double E) const
180  {
181  if (alpha != -1.0)
182  return pow(E, 1.0 + alpha) / (1.0 + alpha);
183  else
184  return log(E);
185  }
186 
187 
188  /**
189  * Multiply weight.
190  *
191  * \param factor factor
192  * \return this volume
193  */
194  JVolume& mul(const double factor)
195  {
196  Wall *= factor;
197 
198  return *this;
199  }
200 
201 
202  /**
203  * Divide weight.
204  *
205  * \param factor factor
206  * \return this volume
207  */
208  JVolume& div(const double factor)
209  {
210  Wall /= factor;
211 
212  return *this;
213  }
214 
215 
216  protected:
217  bool elog; //!< histogram option
218  double Emin; //!< minimal energy
219  double Emax; //!< maximal energy
220  double alpha; //!< spectral index
221  double Wall; //!< generation volume
222  };
223 }
224 
225 #endif
JAANET::genvol genvol
Definition: JHead.hh:1408
Double_t getXmin() const
Get minimal abscissa value.
Definition: JVolume.hh:89
double volume
Volume [m^3].
Definition: JHead.hh:653
double alpha
Energy spectrum: .
Definition: JHead.hh:500
double numberOfEvents
Number of events.
Definition: JHead.hh:654
Double_t getXmax() const
Get maximal abscissa value.
Definition: JVolume.hh:100
double Emax
Maximal energy [GeV].
Definition: JHead.hh:352
Double_t getX(const Double_t E, double constrain=false) const
Get abscissa value.
Definition: JVolume.hh:113
double Wall
generation volume
Definition: JVolume.hh:221
double getWall() const
Get generation dependent weight.
Definition: JVolume.hh:78
double getAlpha() const
Get spectral index of energy distribution.
Definition: JVolume.hh:67
then usage E
Definition: JMuonPostfit.sh:35
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:26
JVolume(const Head &head, const bool Elog10=false)
Constructor.
Definition: JVolume.hh:33
JAANET::livetime livetime
Definition: JHead.hh:1412
JVolume & div(const double factor)
Divide weight.
Definition: JVolume.hh:208
Double_t getW(TAxis *axis, const Double_t E) const
Get bin width corrected energy spectrum dependent weight.
Definition: JVolume.hh:159
Double_t getE(const Double_t x, double constrain=false) const
Get energy.
Definition: JVolume.hh:136
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:98
JAANET::spectrum spectrum
Definition: JHead.hh:1405
double alpha
spectral index
Definition: JVolume.hh:220
JVolume & mul(const double factor)
Multiply weight.
Definition: JVolume.hh:194
Monte Carlo run header.
Definition: JHead.hh:1113
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:67
double getW(const double E) const
Get generation dependent integral value of given energy.
Definition: JVolume.hh:179
JAANET::cut_in cut_in
Definition: JHead.hh:1403
bool elog
histogram option
Definition: JVolume.hh:217
JAANET::cut_nu cut_nu
Definition: JHead.hh:1404
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1183
double Emin
Minimal energy [GeV].
Definition: JHead.hh:351
double numberOfSeconds
Live time [s].
Definition: JHead.hh:829
double Emin
minimal energy
Definition: JVolume.hh:218
double Emax
maximal energy
Definition: JVolume.hh:219