Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
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"
12
18
19
20/**
21 * \author bjung, mdejong
22 */
23
24namespace JOSCPROB {}
25namespace JPP { using namespace JOSCPROB; }
26
27namespace JOSCPROB {
28
31
32 using JTOOLS::JGrid;
34
35
36 /**
37 * Auxiliary class for defining an oscillogram axis.
38 */
40 public JGrid<double>
41 {
44
45
46 /**
47 * Constructor.
48 *
49 * \param type oscillation variable type
50 * \param grid oscillation variable evaluation point grid
51 */
53 const JGrid_t& grid) :
54 JGrid_t(grid),
55 type (type)
56 {}
57
58
59 /**
60 * Constructor.
61 *
62 * \param type oscillation variable type
63 * \param binning oscillation variable binning
64 */
66 const JAbstractHistogram_t& binning) :
67 JGrid_t(binning.getNumberOfBins(),
68 binning.getLowerLimit() + binning.getBinWidth() / 2.,
69 binning.getUpperLimit() - binning.getBinWidth() / 2.),
70 type (type)
71 {}
72
73
74 /**
75 * Constructor.
76 *
77 * \param type oscillogram variable type
78 * \param N number of bins
79 * \param min minimum axis value
80 * \param max maximum axis value
81 */
83 const int N,
84 const double min,
85 const double max) :
86 JGrid_t(N, min, max),
87 type (type)
88 {}
89
90
91 int type; //!< axis type
92 };
93
94
95 /**
96 * Auxiliary class for creating oscillograms.
97 */
98 struct JOscillogram :
99 public JOscProbHelper
100 {
101 /**
102 * Constructor.
103 *
104 * \param abscissa oscillogram abscissa axis definition
105 * \param ordinate oscillogram ordinate axis definition
106 * \param channel oscillation channel
107 * \param oscprob oscillation probability calculator
108 */
111 const JOscChannel& channel,
112 const JOscProbHelper& oscprob) :
113 JOscProbHelper(oscprob),
117 {}
118
119
120 /**
121 * Constructor.
122 *
123 * \param abscissaName oscillogram abscissa variable name
124 * \param abscissa oscillogram abscissa axis
125 * \param ordinateName oscillogram ordinate variable name
126 * \param ordinate oscillogram ordinate axis
127 * \param channel oscillation channel
128 * \param oscprob oscillation probability calculator
129 */
130 template<class T>
131 JOscillogram(const std::string& abscissaName,
132 const T& abscissa,
133 const std::string& ordinateName,
134 const T& ordinate,
135 const JOscChannel& channel,
136 const JOscProbHelper& oscprob) :
137 JOscProbHelper(oscprob),
138 abscissa (JOscVars::getType(abscissaName), abscissa),
139 ordinate (JOscVars::getType(ordinateName), ordinate),
141 {}
142
143
144 /**
145 * Get energy corrresponding to the given bin indices.
146 *
147 * \param i abscissa bin index
148 * \param j ordinate bin index
149 * \return energy [GeV]
150 */
151 double getEnergy(const int i, const int j) const
152 {
153 const std::pair<double, double>& result = getTransformation(i, j);
154
155 return result.first;
156 }
157
158
159 /**
160 * Get cosine zenith angle corrresponding to the given bin indices.
161 *
162 * \param i abscissa bin index
163 * \param j ordinate bin index
164 * \return energy [GeV]
165 */
166 double getCosth(const int i, const int j) const
167 {
168 const std::pair<double, double>& result = getTransformation(i, j);
169
170 return result.second;
171 }
172
173 /**
174 * Get oscillation probability for given bin indices.
175 *
176 * \param i abscissa bin index
177 * \param j ordinate bin index
178 * \return oscillation probability
179 */
180 double getP(const int i, const int j) const
181 {
182 const double& energy = getEnergy(i, j);
183 const double& costh = getCosth (i, j);
184
185 return JOscProbHelper::getP(channel, energy, costh);
186 }
187
188
189 private:
190
191
192 /**
193 * Get energy and cosine zenith angle corresponding to the given bin indices.
194 *
195 * \param i abscissa bin index
196 * \param j ordinate bin index
197 * \return transformed coordinate (E [GeV], costh)
198 */
199 std::pair<double, double> getTransformation(const int i, const int j) const
200 {
201 using namespace std;
202
203 static int ix = -1;
204 static int iy = -1;
205
206 static pair<double, double> result = {0.0, 0.0}; // Cache result
207
208 if (i != ix || j != iy) {
209
210 ix = i;
211 iy = j;
212
213 const double x = abscissa.getX(i);
214 const double y = ordinate.getX(j);
215
216 switch (ordinate.type) {
217 case (int) JOscVars::COSTH:
218 result.second = y;
219 break;
220 case (int) JOscVars::SINTH:
221 result.second = sqrt((1 + y) * (1 - y));
222 break;
223 case (int) JOscVars::BASELINE:
224 result.second = JOscProbHelper::getCosth(y);
225 break;
226 default:
227 THROW(JValueOutOfRange, "JOscillogram::getCosth(const double): Invalid ordinate type " << ordinate.type);
228 }
229
230 switch (abscissa.type) {
231 case (int) JOscVars::ENERGY:
232 result.first = x;
233 break;
234 case (int) JOscVars::LOG10E:
235 result.first = pow(10.0, x);
236 break;
237 case (int) JOscVars::LOE:
238 result.first = (x > 0.0 ? this->getBaseline(result.second) / x : 0.0);
239 break;
240 default:
241 THROW(JValueOutOfRange, "JOscillogram::getEnergy(const double, const double): Invalid abscissa type " << abscissa.type);
242 }
243 }
244
245 return result;
246 }
247
248
249 JOscillogramAxis abscissa; //!< Abscissa axis
250 JOscillogramAxis ordinate; //!< Ordinate axis
251
252 JOscChannel channel; //!< Oscillation channel
253
254 private:
256 };
257}
258
259#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for null pointer operation.
Exception for accessing a value in a collection that is outside of its range.
std::pair< int, std::string > const & getType(CLBCommonHeader const &header)
Definition datatypes.cpp:12
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Neutrino oscillation channel.
Helper class for oscillation probability calculators.
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.
JOscillogramAxis(const int type, const JAbstractHistogram_t &binning)
Constructor.
JOscillogramAxis(const int type, const JGrid_t &grid)
Constructor.
JAbstractHistogram< double > JAbstractHistogram_t
JOscillogramAxis(const int type, const int N, const double min, const double max)
Constructor.
Auxiliary class for creating oscillograms.
double getEnergy(const int i, const int j) const
Get energy corrresponding to the given bin indices.
JOscChannel channel
Oscillation channel.
double getCosth(const int i, const int j) const
Get cosine zenith angle corrresponding to the given bin indices.
JOscillogram(const std::string &abscissaName, const T &abscissa, const std::string &ordinateName, const T &ordinate, const JOscChannel &channel, const JOscProbHelper &oscprob)
Constructor.
JOscillogramAxis abscissa
Abscissa axis.
JOscillogram(const JOscillogramAxis &abscissa, const JOscillogramAxis &ordinate, const JOscChannel &channel, const JOscProbHelper &oscprob)
Constructor.
std::pair< double, double > getTransformation(const int i, const int j) const
Get energy and cosine zenith angle corresponding to the given bin indices.
JOscillogramAxis ordinate
Ordinate axis.
double getP(const int i, const int j) const
Get oscillation probability for given bin indices.
Simple data structure for histogram binning.
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