Jpp  18.1.0
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 
10 #include "JTools/JRange.hh"
11 
12 #include "JAAnet/JHead.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JAANET {}
20 namespace JPP { using namespace JAANET; }
21 
22 namespace JAANET {
23 
24  /**
25  * Auxiliary class for histogramming of effective volume.
26  * In this, it is assumed that events are generated according \f$ \frac{dN}{dE} \propto E^{\alpha} \f$.
27  * The weight is expressed in \f$ \mathrm{km}^{3} \f$.
28  */
29  struct JVolume {
30  /**
31  * Constructor.
32  *
33  * \param head Monte Carlo run header
34  * \param Elog10 application of log10 to energy
35  */
36  JVolume(const Head& head,
37  const bool Elog10 = false) :
38  elog (Elog10),
39  E(0.0, 0.0),
40  alpha (0.0),
41  Wall (1.0)
42  {
43  const JHead buffer(head);
44 
45  if (buffer.is_valid(&JHead::spectrum) &&
46  buffer.is_valid(&JHead::cut_nu) &&
47  buffer.is_valid(&JHead::genvol)) {
48 
49  alpha = buffer.spectrum.alpha;
50  E = buffer.cut_nu.E;
51  Wall = (1.0e-9 * (getW(E.getUpperLimit()) -
52  getW(E.getLowerLimit())) *
53  buffer.genvol.volume / buffer.genvol.numberOfEvents); // km^3
54 
55  } else if (buffer.is_valid(&JHead::cut_in) &&
56  buffer.is_valid(&JHead::livetime)) {
57 
58  E = buffer.cut_in.E;
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(E.getLowerLimit());
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(E.getUpperLimit());
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  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 Ex = (elog ? pow(10.0, x) : x);
141 
142  if (constrain)
143  return E.constrain(Ex);
144  else
145  return Ex;
146  }
147 
148 
149  /**
150  * Get bin width corrected energy spectrum dependent weight.
151  *
152  * \param axis axis
153  * \param E energy
154  * \return weight [km^3]
155  */
156  inline Double_t getW(TAxis* axis, const Double_t E) const
157  {
158  const Int_t index = axis->FindBin(getX(E));
159 
160  const Double_t xmin = axis->GetBinLowEdge(index);
161  const Double_t xmax = axis->GetBinUpEdge (index);
162 
163  const Double_t Wmin = getW(getE(xmin));
164  const Double_t Wmax = getW(getE(xmax));
165 
166  return Wall / (Wmax - Wmin);
167  }
168 
169 
170  /**
171  * Get generation dependent integral value of given energy.
172  *
173  * \param E energy
174  * \return integral value
175  */
176  inline double getW(const double E) const
177  {
178  if (alpha != -1.0)
179  return pow(E, 1.0 + alpha) / (1.0 + alpha);
180  else
181  return log(E);
182  }
183 
184 
185  /**
186  * Multiply weight.
187  *
188  * \param factor factor
189  * \return this volume
190  */
191  JVolume& mul(const double factor)
192  {
193  Wall *= factor;
194 
195  return *this;
196  }
197 
198 
199  /**
200  * Divide weight.
201  *
202  * \param factor factor
203  * \return this volume
204  */
205  JVolume& div(const double factor)
206  {
207  Wall /= factor;
208 
209  return *this;
210  }
211 
212 
213  protected:
214  bool elog; //!< histogram option
215  JTOOLS::JRange<double> E; //!< Energy range [GeV]
216  double alpha; //!< spectral index
217  double Wall; //!< generation volume
218  };
219 }
220 
221 #endif
const double xmax
Definition: JQuadrature.cc:24
JAANET::genvol genvol
Definition: JHead.hh:1582
Double_t getXmin() const
Get minimal abscissa value.
Definition: JVolume.hh:91
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
double volume
Volume [m^3].
Definition: JHead.hh:707
double alpha
Energy spectrum: .
Definition: JHead.hh:553
double numberOfEvents
Number of events.
Definition: JHead.hh:708
Double_t getXmax() const
Get maximal abscissa value.
Definition: JVolume.hh:102
Double_t getX(const Double_t E, double constrain=false) const
Get abscissa value.
Definition: JVolume.hh:115
JRange_t E
Energy range [GeV].
Definition: JHead.hh:406
double Wall
generation volume
Definition: JVolume.hh:217
double getWall() const
Get generation dependent weight.
Definition: JVolume.hh:80
double getAlpha() const
Get spectral index of energy distribution.
Definition: JVolume.hh:69
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:29
JTOOLS::JRange< double > E
Energy range [GeV].
Definition: JVolume.hh:215
JVolume(const Head &head, const bool Elog10=false)
Constructor.
Definition: JVolume.hh:36
JAANET::livetime livetime
Definition: JHead.hh:1586
set_variable E_E log10(E_{fit}/E_{#mu})"
JVolume & div(const double factor)
Divide weight.
Definition: JVolume.hh:205
Double_t getW(TAxis *axis, const Double_t E) const
Get bin width corrected energy spectrum dependent weight.
Definition: JVolume.hh:156
Double_t getE(const Double_t x, double constrain=false) const
Get energy.
Definition: JVolume.hh:138
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
JAANET::spectrum spectrum
Definition: JHead.hh:1579
T constrain(argument_type x) const
Constrain value to range.
Definition: JRange.hh:350
double alpha
spectral index
Definition: JVolume.hh:216
JVolume & mul(const double factor)
Multiply weight.
Definition: JVolume.hh:191
Monte Carlo run header.
Definition: JHead.hh:1221
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
then set_variable DIR else fatal Wrong number of arguments fi for INPUT_FILE in ls rt $DIR stage * log
const double xmin
Definition: JQuadrature.cc:23
double getW(const double E) const
Get generation dependent integral value of given energy.
Definition: JVolume.hh:176
Auxiliary class to define a range between two values.
JAANET::cut_in cut_in
Definition: JHead.hh:1577
bool elog
histogram option
Definition: JVolume.hh:214
JAANET::cut_nu cut_nu
Definition: JHead.hh:1578
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1305
double numberOfSeconds
Live time [s].
Definition: JHead.hh:883