Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOscillogram.hh
Go to the documentation of this file.
1 #ifndef __JOSCPROB__JOSCILLOGRAM__
2 #define __JOSCPROB__JOSCILLOGRAM__
3 
4 #include <iostream>
5 #include <iomanip>
6 #include <string>
7 
8 #include "JLang/JException.hh"
9 
10 #include "JTools/JGrid.hh"
11 
12 #include "JOscProb/JOscChannel.hh"
17 
18 
19 /**
20  * \author bjung, mdejong
21  */
22 
23 namespace JOSCPROB {}
24 namespace JPP { using namespace JOSCPROB; }
25 
26 namespace JOSCPROB {
27 
30 
31  using JTOOLS::JGrid;
32 
33 
34  /**
35  * Auxiliary class for defining an oscillogram axis.
36  */
38  public JGrid<double>
39  {
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param type oscillation variable type
47  * \param binning oscillation variable binning
48  */
50  const JGrid_t binning) :
51  JGrid_t(binning),
52  type (type)
53  {}
54 
55 
56  /**
57  * Constructor.
58  *
59  * \param type oscillogram variable type
60  * \param N number of bins
61  * \param min minimum axis value
62  * \param max maximum axis value
63  */
65  const int N,
66  const double min,
67  const double max) :
68  JGrid_t(N, min, max),
69  type (type)
70  {}
71 
72 
73  int type; //!< axis type
74  };
75 
76 
77  /**
78  * Auxiliary class for creating oscillograms.
79  */
80  struct JOscillogram :
81  public JOscProbHelper
82  {
83  /**
84  * Constructor.
85  *
86  * \param abscissa oscillogram abscissa axis definition
87  * \param ordinate oscillogram ordinate axis definition
88  * \param channel oscillation channel
89  * \param oscprob oscillation probability calculator
90  */
93  const JOscChannel& channel,
94  const JOscProbInterface& oscprob) :
95  JOscProbHelper(oscprob),
96  abscissa (abscissa),
97  ordinate (ordinate),
98  channel (channel)
99  {}
100 
101 
102  /**
103  * Constructor.
104  *
105  * \param abscissaName oscillogram abscissa variable name
106  * \param abscissaBinning oscillogram abscissa binning
107  * \param ordinateName oscillogram ordinate variable name
108  * \param ordinateBinning oscillogram ordinate binning
109  * \param channel oscillation channel
110  * \param oscprob oscillation probability calculator
111  */
112  JOscillogram(const std::string& abscissaName,
113  const JGrid<double> abscissaBinning,
114  const std::string& ordinateName,
115  const JGrid<double> ordinateBinning,
116  const JOscChannel& channel,
117  const JOscProbInterface& oscprob) :
118  JOscProbHelper(oscprob),
119  abscissa (JOscVars::getType(abscissaName), abscissaBinning),
120  ordinate (JOscVars::getType(ordinateName), ordinateBinning),
121  channel (channel)
122  {}
123 
124 
125  /**
126  * Get energy corrresponding to the given bin indices.
127  *
128  * \param i abscissa bin index
129  * \param j ordinate bin index
130  * \return energy [GeV]
131  */
132  double getEnergy(const int i, const int j) const
133  {
135 
136  return result.first;
137  }
138 
139 
140  /**
141  * Get cosine zenith angle corrresponding to the given bin indices.
142  *
143  * \param i abscissa bin index
144  * \param j ordinate bin index
145  * \return energy [GeV]
146  */
147  double getCosth(const int i, const int j) const
148  {
150 
151  return result.second;
152  }
153 
154 
155  /**
156  * Get oscillation probability for given bin indices.
157  *
158  * \param i abscissa bin index
159  * \param j ordinate bin index
160  * \return oscillation probability
161  */
162  double getP(const int i, const int j) const
163  {
164  const double& energy = getEnergy(i, j);
165  const double& costh = getCosth (i, j);
166 
167  return JOscProbHelper::getP(channel, energy, costh);
168  }
169 
170 
171  private:
172 
173 
174  /**
175  * Get energy and cosine zenith angle corresponding to the given bin indices.
176  *
177  * \param i abscissa bin index
178  * \param j ordinate bin index
179  * \return transformed coordinate (E [GeV], costh)
180  */
181  std::pair<double, double> getTransformation(const int i, const int j) const
182  {
183  using namespace std;
184 
185  static int ix = -1;
186  static int iy = -1;
187 
188  static pair<double, double> result = {0.0, 0.0}; // Cache result
189 
190  if (i != ix || j != iy) {
191 
192  ix = i;
193  iy = j;
194 
195  const double x = abscissa.getX(i);
196  const double y = ordinate.getX(j);
197 
198  switch (ordinate.type) {
199  case (int) JOscVars::COSTH:
200  result.second = y;
201  break;
202  case (int) JOscVars::SINTH:
203  result.second = sqrt((1 + y) * (1 - y));
204  break;
205  case (int) JOscVars::BASELINE:
206  result.second = JOscProbHelper::getCosth(y);
207  break;
208  default:
209  THROW(JValueOutOfRange, "JOscillogram::getCosth(const double): Invalid ordinate type " << ordinate.type);
210  }
211 
212  switch (abscissa.type) {
213  case (int) JOscVars::ENERGY:
214  result.first = x;
215  break;
216  case (int) JOscVars::LOG10E:
217  result.first = pow(10.0, x);
218  break;
219  case (int) JOscVars::LOE:
220  result.first = (x > 0.0 ? this->getBaseline(result.second) / x : 0.0);
221  break;
222  default:
223  THROW(JValueOutOfRange, "JOscillogram::getEnergy(const double, const double): Invalid abscissa type " << abscissa.type);
224  }
225  }
226 
227  return result;
228  }
229 
230 
231  JOscillogramAxis abscissa; //!< Abscissa axis
232  JOscillogramAxis ordinate; //!< Ordinate axis
233 
234  JOscChannel channel; //!< Oscillation channel
235  };
236 }
237 
238 #endif
double getCosth(const int i, const int j) const
Get cosine zenith angle corrresponding to the given bin indices.
Exceptions.
double getEnergy(const int i, const int j) const
Get energy corrresponding to the given bin indices.
Neutrino oscillation channel.
Definition: JOscChannel.hh:110
double getP(const JOscChannel &channel, const double energy, const double costh) const
Get oscillation probability corresponding to given oscillation channel, neutrino energy and zenith an...
Low-level interface for oscillation probability calculators.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Helper class for oscillation probabilities.
JOscillogram(const JOscillogramAxis &abscissa, const JOscillogramAxis &ordinate, const JOscChannel &channel, const JOscProbInterface &oscprob)
Constructor.
Definition: JOscillogram.hh:91
JOscillogramAxis ordinate
Ordinate axis.
std::pair< int, std::string > const & getType(CLBCommonHeader const &header)
Definition: datatypes.cpp:12
virtual double getCosth(const double L) const
Get cosine zenith angle for a given baseline.
Exception for null pointer operation.
Definition: JException.hh:232
JOscChannel channel
Oscillation channel.
virtual abscissa_type getX(int index) const override
Get abscissa value.
Definition: JGrid.hh:87
JOscillogramAxis abscissa
Abscissa axis.
then awk string
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
double getP(const int i, const int j) const
Get oscillation probability for given bin indices.
then for APP in event gandalf start energy
Definition: JMuonMCEvt.sh:44
std::pair< double, double > getTransformation(const int i, const int j) const
Get energy and cosine zenith angle corresponding to the given bin indices.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
Simple data structure for an abstract collection of equidistant abscissa values.
Definition: JGrid.hh:38
virtual double getBaseline(const double costh) const
Get baseline for a given cosine zenith angle.
JOscillogramAxis(const int type, const int N, const double min, const double max)
Constructor.
Definition: JOscillogram.hh:64
int j
Definition: JPolint.hh:792
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
JOscillogram(const std::string &abscissaName, const JGrid< double > abscissaBinning, const std::string &ordinateName, const JGrid< double > ordinateBinning, const JOscChannel &channel, const JOscProbInterface &oscprob)
Constructor.
JOscillogramAxis(const int type, const JGrid_t binning)
Constructor.
Definition: JOscillogram.hh:49
Auxiliary class for defining an oscillogram axis.
Definition: JOscillogram.hh:37
Auxiliary class for creating oscillograms.
Definition: JOscillogram.hh:80
Auxiliary data structure to hold oscillation variable names.