Jpp  master_rocky-43-ge265d140c
the software that should make you happy
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),
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  * Get oscillation probability for given bin indices.
156  *
157  * \param i abscissa bin index
158  * \param j ordinate bin index
159  * \return oscillation probability
160  */
161  double getP(const int i, const int j) const
162  {
163  const double& energy = getEnergy(i, j);
164  const double& costh = getCosth (i, j);
165 
166  return JOscProbHelper::getP(channel, energy, costh);
167  }
168 
169 
170  private:
171 
172 
173  /**
174  * Get energy and cosine zenith angle corresponding to the given bin indices.
175  *
176  * \param i abscissa bin index
177  * \param j ordinate bin index
178  * \return transformed coordinate (E [GeV], costh)
179  */
180  std::pair<double, double> getTransformation(const int i, const int j) const
181  {
182  using namespace std;
183 
184  static int ix = -1;
185  static int iy = -1;
186 
187  static pair<double, double> result = {0.0, 0.0}; // Cache result
188 
189  if (i != ix || j != iy) {
190 
191  ix = i;
192  iy = j;
193 
194  const double x = abscissa.getX(i);
195  const double y = ordinate.getX(j);
196 
197  switch (ordinate.type) {
198  case (int) JOscVars::COSTH:
199  result.second = y;
200  break;
201  case (int) JOscVars::SINTH:
202  result.second = sqrt((1 + y) * (1 - y));
203  break;
204  case (int) JOscVars::BASELINE:
206  break;
207  default:
208  THROW(JValueOutOfRange, "JOscillogram::getCosth(const double): Invalid ordinate type " << ordinate.type);
209  }
210 
211  switch (abscissa.type) {
212  case (int) JOscVars::ENERGY:
213  result.first = x;
214  break;
215  case (int) JOscVars::LOG10E:
216  result.first = pow(10.0, x);
217  break;
218  case (int) JOscVars::LOE:
219  result.first = (x > 0.0 ? this->getBaseline(result.second) / x : 0.0);
220  break;
221  default:
222  THROW(JValueOutOfRange, "JOscillogram::getEnergy(const double, const double): Invalid abscissa type " << abscissa.type);
223  }
224  }
225 
226  return result;
227  }
228 
229 
230  JOscillogramAxis abscissa; //!< Abscissa axis
231  JOscillogramAxis ordinate; //!< Ordinate axis
232 
233  JOscChannel channel; //!< Oscillation channel
234 
235  private:
237  };
238 }
239 
240 #endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Exception for null pointer operation.
Definition: JException.hh:234
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:180
Low-level interface for oscillation probability calculators.
std::pair< int, std::string > const & getType(CLBCommonHeader const &header)
Definition: datatypes.cpp:12
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
int j
Definition: JPolint.hh:792
Definition: JSTDTypes.hh:14
Neutrino oscillation channel.
Definition: JOscChannel.hh:112
Helper class for oscillation probabilities.
double getBaseline(const double costh) const
Get baseline for a given cosine zenith angle.
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...
double getCosth(const double L) const
Get cosine zenith angle for a given baseline.
Auxiliary data structure to hold oscillation variable names.
Auxiliary class for defining an oscillogram axis.
Definition: JOscillogram.hh:39
JOscillogramAxis(const int type, const int N, const double min, const double max)
Constructor.
Definition: JOscillogram.hh:64
JOscillogramAxis(const int type, const JGrid_t binning)
Constructor.
Definition: JOscillogram.hh:49
Auxiliary class for creating oscillograms.
Definition: JOscillogram.hh:82
JOscillogram(const JOscillogramAxis &abscissa, const JOscillogramAxis &ordinate, const JOscChannel &channel, const JOscProbInterface &oscprob)
Constructor.
Definition: JOscillogram.hh:91
double getEnergy(const int i, const int j) const
Get energy corrresponding to the given bin indices.
std::pair< double, double > getTransformation(const int i, const int j) const
Get energy and cosine zenith angle corresponding to the given bin indices.
JOscillogram(const std::string &abscissaName, const JGrid< double > abscissaBinning, const std::string &ordinateName, const JGrid< double > ordinateBinning, const JOscChannel &channel, const JOscProbInterface &oscprob)
Constructor.
JOscChannel channel
Oscillation channel.
double getCosth(const int i, const int j) const
Get cosine zenith angle corrresponding to the given bin indices.
JOscillogramAxis abscissa
Abscissa axis.
JOscillogramAxis ordinate
Ordinate axis.
double getP(const int i, const int j) const
Get oscillation probability for given bin indices.
double getCosth(const double L) const
Get cosine zenith angle for a given baseline.
Simple data structure for an abstract collection of equidistant abscissa values.
Definition: JGrid.hh:40
virtual abscissa_type getX(int index) const override
Get abscissa value.
Definition: JGrid.hh:87