Jpp  18.1.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"
15 
16 
17 /**
18  * \author bjung, mdejong
19  */
20 
21 namespace JOSCPROB {}
22 namespace JPP { using namespace JOSCPROB; }
23 
24 namespace JOSCPROB {
25 
28 
29  using JTOOLS::JGrid;
30 
31 
32  /**
33  * Auxiliary class for defining an oscillogram axis.
34  */
36  public JGrid<double>
37  {
39 
40 
41  /**
42  * Constructor.
43  *
44  * \param type oscillation variable type
45  * \param binning oscillation variable binning
46  */
48  const JGrid_t binning) :
49  JGrid_t(binning),
50  type (type)
51  {}
52 
53 
54  /**
55  * Constructor.
56  *
57  * \param type oscillogram variable type
58  * \param N number of bins
59  * \param min minimum axis value
60  * \param max maximum axis value
61  */
63  const int N,
64  const double min,
65  const double max) :
66  JGrid_t(N, min, max),
67  type (type)
68  {}
69 
70 
71  int type; //!< axis type
72  };
73 
74 
75  /**
76  * Auxiliary class for creating oscillograms.
77  */
78  struct JOscillogram
79  {
80  /**
81  * Constructor.
82  *
83  * \param abscissa oscillogram abscissa axis definition
84  * \param ordinate oscillogram ordinate axis definition
85  * \param channel oscillation channel
86  * \param pInterpolator pointer to oscillation probability interpolator
87  */
90  const JOscChannel& channel,
92  abscissa (abscissa),
93  ordinate (ordinate),
94  channel (channel),
95  pInterpolator(pInterpolator)
96  {
97  if (pInterpolator == NULL) {
98  THROW(JNullPointerException, "JOscillogram::JOscillogram(...): Oscillation probability interpolator is not set");
99  }
100  }
101 
102 
103  /**
104  * Constructor.
105  *
106  * \param abscissaName oscillogram abscissa variable name
107  * \param abscissaBinning oscillogram abscissa binning
108  * \param ordinateName oscillogram ordinate variable name
109  * \param ordinateBinning oscillogram ordinate binning
110  * \param channel oscillation channel
111  * \param pInterpolator pointer to oscillation probability interpolator
112  */
113  JOscillogram(const std::string& abscissaName,
114  const JGrid<double> abscissaBinning,
115  const std::string& ordinateName,
116  const JGrid<double> ordinateBinning,
117  const JOscChannel& channel,
119  abscissa (JOscVars::getType(abscissaName), abscissaBinning),
120  ordinate (JOscVars::getType(ordinateName), ordinateBinning),
121  channel (channel),
122  pInterpolator(pInterpolator)
123  {
124  if (pInterpolator == NULL) {
125  THROW(JNullPointerException, "JOscillogram::JOscillogram(...): Oscillation probability interpolator is not set");
126  }
127  }
128 
129 
130  /**
131  * Get energy corrresponding to the given bin indices.
132  *
133  * \param i abscissa bin index
134  * \param j ordinate bin index
135  * \return energy [GeV]
136  */
137  double getEnergy(const int i, const int j) const
138  {
140 
141  return result.first;
142  }
143 
144 
145  /**
146  * Get cosine zenith angle corrresponding to the given bin indices.
147  *
148  * \param i abscissa bin index
149  * \param j ordinate bin index
150  * \return energy [GeV]
151  */
152  double getCosth(const int i, const int j) const
153  {
155 
156  return result.second;
157  }
158 
159 
160  /**
161  * Get oscillation probability for given bin indices.
162  *
163  * \param i abscissa bin index
164  * \param j ordinate bin index
165  * \return oscillation probability
166  */
167  double getP(const int i, const int j) const
168  {
169  const double& energy = getEnergy(i, j);
170  const double& costh = getCosth (i, j);
171 
172  return (*pInterpolator)(channel, energy, costh);
173  }
174 
175 
176  private:
177 
178 
179  /**
180  * Get energy and cosine zenith angle corresponding to the given bin indices.
181  *
182  * \param i abscissa bin index
183  * \param j ordinate bin index
184  * \return transformed coordinate (E [GeV], costh)
185  */
186  std::pair<double, double> getTransformation(const int i, const int j) const
187  {
188  using namespace std;
189 
190  static const JBaselineCalculator& baselineCalculator = pInterpolator->getBaselineCalculator();
191 
192  static int ix = -1;
193  static int iy = -1;
194 
195  static pair<double, double> result = {0.0, 0.0}; // Cache result
196 
197  if (i != ix || j != iy) {
198 
199  ix = i;
200  iy = j;
201 
202  const double x = abscissa.getX(i);
203  const double y = ordinate.getX(j);
204 
205  switch (ordinate.type) {
206  case (int) JOscVars::COSTH:
207  result.second = y;
208  break;
209  case (int) JOscVars::SINTH:
210  result.second = sqrt((1 + y) * (1 - y));
211  break;
212  case (int) JOscVars::BASELINE:
213  result.second = baselineCalculator.getCosth(y);
214  break;
215  default:
216  THROW(JValueOutOfRange, "JOscillogram::getCosth(const double): Invalid ordinate type " << ordinate.type);
217  }
218 
219  switch (abscissa.type) {
220  case (int) JOscVars::ENERGY:
221  result.first = x;
222  break;
223  case (int) JOscVars::LOG10E:
224  result.first = pow(10.0, x);
225  break;
226  case (int) JOscVars::LOE:
227  result.first = (x > 0.0 ? baselineCalculator.getBaseline(result.second) / x : 0.0);
228  break;
229  default:
230  THROW(JValueOutOfRange, "JOscillogram::getEnergy(const double, const double): Invalid abscissa type " << abscissa.type);
231  }
232  }
233 
234  return result;
235  }
236 
237 
238  JOscillogramAxis abscissa; //!< Abscissa axis
239  JOscillogramAxis ordinate; //!< Ordinate axis
240 
241  JOscChannel channel; //!< Oscillation channel
242 
243  const JOscProbInterpolatorInterface* pInterpolator; //!< Pointer to oscillation probability interpolator
244  };
245 }
246 
247 #endif
double getCosth(const int i, const int j) const
Get cosine zenith angle corrresponding to the given bin indices.
JOscillogram(const JOscillogramAxis &abscissa, const JOscillogramAxis &ordinate, const JOscChannel &channel, const JOscProbInterpolatorInterface *pInterpolator)
Constructor.
Definition: JOscillogram.hh:88
Exceptions.
const JOscProbInterpolatorInterface * pInterpolator
Pointer to oscillation probability interpolator.
double getEnergy(const int i, const int j) const
Get energy corrresponding 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 JOscProbInterpolatorInterface *pInterpolator)
Constructor.
Neutrino oscillation channel.
Definition: JOscChannel.hh:110
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
virtual const JBaselineCalculator & getBaselineCalculator() const =0
Get baseline calculator associated with this interpolation table.
Auxiliary data structure for storing and calculating baselines.
Low-level interface for oscillation probability tables.
JOscillogramAxis ordinate
Ordinate axis.
std::pair< int, std::string > const & getType(CLBCommonHeader const &header)
Definition: datatypes.cpp:12
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
JOscillogramAxis(const int type, const int N, const double min, const double max)
Constructor.
Definition: JOscillogram.hh:62
int j
Definition: JPolint.hh:703
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
JOscillogramAxis(const int type, const JGrid_t binning)
Constructor.
Definition: JOscillogram.hh:47
Auxiliary class for defining an oscillogram axis.
Definition: JOscillogram.hh:35
Auxiliary class for creating oscillograms.
Definition: JOscillogram.hh:78
Auxiliary data structure to hold oscillation variable names.