Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JOscProbInterpolator.hh
Go to the documentation of this file.
1#ifndef __JOSCPROB__JOSCPROBINTERPOLATOR__
2#define __JOSCPROB__JOSCPROBINTERPOLATOR__
3
4#include "Jeep/JMessage.hh"
5
8
9#include "JLang/JClonable.hh"
10#include "JLang/JObjectIO.hh"
11#include "JLang/JException.hh"
13
14#include "JTools/JPolint.hh"
15#include "JTools/JMapList.hh"
16#include "JTools/JCollection.hh"
17#include "JTools/JFunctional.hh"
21
27
28
29/**
30 * \author bjung, mdejong
31 */
32
33namespace JOSCPROB {}
34namespace JPP { using namespace JOSCPROB; }
35
36namespace JOSCPROB {
37
38 using JEEP::JMessage;
39
40 using JLANG::JClonable;
42
45
48
49
50 /**
51 * Template definition of a multi-dimensional oscillation probability interpolation table.
52 */
53 template<template<class, class> class JCollection_t = JTOOLS::JCollection,
54 class JFunction1D_t = JTOOLS::JPolintFunction1D <1,
56 JCollection_t,
58 class JFunctionalMaplist_t = JTOOLS::JMAPLIST <JTOOLS::JPolint1FunctionalMap,
66 public JMultiFunction <JFunction1D_t, JFunctionalMaplist_t>,
67 public JClonable<JOscProbInterface, JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >,
68 public JMessage <JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >,
69 public JObjectBinaryIO <JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >,
70 public JSerialisable
71 {
72 public:
73
76
78
83
85
89
95
96
97 /**
98 * Default constructor.
99 */
107
108
109 /**
110 * Constructor.
111 *
112 * \param fileName oscillation probability table filename
113 */
114 JOscProbInterpolator(const char* fileName) :
115 table(*this, fileName)
116 {
118
120
121 load();
122 }
123
124
125 /**
126 * Constructor.
127 *
128 * \param fileName oscillation probability table filename
129 * \param parameters oscillation parameters
130 */
131 JOscProbInterpolator(const char* fileName,
132 const JOscParameters_t& parameters) :
133 JOscProbInterpolator(fileName)
134 {
135 JOscParametersHelper_t::set(parameters);
136 }
137
138
139 /**
140 * Copy constructor.
141 *
142 * \param interpolator oscillation probability interpolator
143 */
145 JOscProbInterpolator(interpolator.table.c_str())
146 {
147 this->baselineComputer = interpolator.baselineComputer;
148 this->getMultiFunction() = interpolator.getMultiFunction();
149
150 this->compile();
151 }
152
153
154 /**
155 * Get cosine zenith angle for a given baseline.
156 *
157 * \param L baseline [km]
158 * \return cosine zenith angle
159 */
160 double getCosth(const double L) const override final
161 {
162 return baselineComputer.getCosth(L);
163 }
164
165
166 /**
167 * Get baseline for a given cosine zenith angle.
168 *
169 * \param costh cosine zenith angle
170 * \return baseline [km]
171 */
172 double getBaseline(const double costh) const override final
173 {
174 return baselineComputer.getBaseline(costh);
175 }
176
177
178 /**
179 * Get oscillation probability for a given oscillation channel.
180 *
181 * \param channel oscillation channel
182 * \param E neutrino energy [GeV]
183 * \param costh cosine zenith angle
184 * \return oscillation probability
185 */
186 double getP(const JOscChannel& channel,
187 const double E,
188 const double costh) const override final
189 {
190 using namespace std;
191 using namespace JPP;
192
194
195 if (p != end(getOscChannel)) {
196
197 const double L = this->getBaseline(costh);
198
199 this->buffer[NUMBER_OF_DIMENSIONS-2] = L/E;
200 this->buffer[NUMBER_OF_DIMENSIONS-1] = costh;
201
202 const double* arguments = this->buffer.data();
203
204 const size_t index = distance(getOscChannel, p);
205 const result_type& probabilities = this->evaluate(arguments);
206
207 const double& P = probabilities[index];
208
209 return min(max(P, 0.0), 1.0);
210
211 } else {
212
213 THROW(JValueOutOfRange, "JOscProbInterpolator<...>::getP(): Invalid oscillation channel " << channel << endl);
214 }
215 }
216
217
218 /**
219 * Load oscillation probability table.
220 */
221 void load()
222 {
223 using namespace std;
224 using namespace JPP;
225
226 if (!table.empty()) {
227
228 NOTICE("Loading oscillation probability table from file " << table << "... " << flush);
229
231
232 NOTICE("OK" << endl);
233 }
234 }
235
236
237 /**
238 * Load oscillation probability table.
239 *
240 * \param table oscillation probability table filename
241 */
242 void load(const char* table)
243 {
244 this->table = table;
245
246 load();
247 }
248
249
250 /**
251 * Read from input.
252 *
253 * \param in reader
254 * \return reader
255 */
256 JReader& read(JReader& in) override final
257 {
258 multifunction_type& multifunction = this->getMultiFunction();
259
260 in >> baselineComputer;
261 in >> multifunction;
262
263 multifunction.compile();
264
265 return in;
266 }
267
268
269 /**
270 * Write from input.
271 *
272 * \param out writer
273 * \return writer
274 */
275 JWriter& write(JWriter& out) const override final
276 {
277 out << baselineComputer;
278 out << static_cast<const multifunction_type&>(*this);
279
280 return out;
281 }
282
283
284 /**
285 * Get properties of this class.
286 *
287 * \param eqpars equation parameters
288 */
290 {
291 return JOscProbInterpolatorHelper(*this, eqpars);
292 }
293
294
295 /**
296 * Get properties of this class.
297 *
298 * \param eqpars equation parameters
299 */
301 {
302 return JOscProbInterpolatorHelper(*this, eqpars);
303 }
304
305
306 private:
307
308 /**
309 * Auxiliary class for I/O of oscillation probability interpolator.
310 */
312 public JProperties
313 {
314 /**
315 * Constructor.
316 *
317 * \param interpolator oscillation probability interpolator
318 * \param eqpars equation parameters
319 */
320 template<class JOscProbInterpolator_t>
321 JOscProbInterpolatorHelper(JOscProbInterpolator_t& interpolator,
322 const JEquationParameters& eqpars) :
323 JProperties(eqpars, 1)
324 {
325 (*this)[JOscProbInterface::getTypeKey()] = "interpolator";
326
327 this->insert(gmake_property(interpolator.table));
328
329 this->join(interpolator.getParameters().getProperties());
330 }
331 };
332
333
334 JBaselineComputer baselineComputer; //!< Baseline computer
335
336 JLoadProperty<interpolator_type, std::string> table; //!< Oscillation probability table filename
337
338 mutable JArray<NUMBER_OF_DIMENSIONS, argument_type> buffer; //!< Buffer for interpolation arguments
339
340 using JMessage<interpolator_type>::debug; //!< Debug level
341 };
342}
343
344
345namespace JEEP {
346
347 /**
348 * JMessage template specialization for oscillation probability interpolators.
349 */
350 template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
351 struct JMessage<JOSCPROB::JOscProbInterpolator<JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >
352 {
353 static int debug;
354 };
355
356
357 /**
358 * Default verbosity for oscillation probability interpolators.
359 */
360 template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
362
363}
364
365#endif
General purpose class for a collection of sorted elements.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Various implementations of functional maps.
General purpose messaging.
#define NOTICE(A)
Definition JMessage.hh:64
int debug
debug level
Definition JSirene.cc:72
General methods for loading and storing a single object from and to a file, respectively.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Utility class to parse parameter values.
JProperties & join(const JProperties &properties)
Join properties objects.
Interface for binary input.
Forward declaration of binary output.
Interface for binary output.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Data structure for object properties which require reloading whenever the property is reread.
Parameter class.
Definition JParameter.hh:36
Exception for accessing a value in a collection that is outside of its range.
Interface class for sets of oscillation parameters.
Data structure for single set of oscillation parameters.
static const char *const getTypeKey()
Get type keyword.
static JEquationParameters & getEquationParameters()
Get equation parameters.
Template definition of a multi-dimensional oscillation probability interpolation table.
multifunction_type::multimap_type multimap_type
JOscProbInterpolator()
Default constructor.
JWriter & write(JWriter &out) const override final
Write from input.
JArray< NUMBER_OF_DIMENSIONS, argument_type > buffer
Buffer for interpolation arguments.
JProperties getProperties(const JEquationParameters &eqpars=JOscProbInterface::getEquationParameters()) override final
Get properties of this class.
multifunction_type::super_iterator super_iterator
multifunction_type::argument_type argument_type
JOscProbInterface::JOscParameter_t JOscParameter_t
JOscProbInterpolator(const char *fileName, const JOscParameters_t &parameters)
Constructor.
multifunction_type::abscissa_type abscissa_type
JOscProbInterface::JOscParameterReferences_t JOscParameterReferences_t
JOscProbInterface::JParameter_t JParameter_t
multifunction_type::value_type value_type
JMultiFunction< JFunction1D_t, JFunctionalMaplist_t > multifunction_type
double getP(const JOscChannel &channel, const double E, const double costh) const override final
Get oscillation probability for a given oscillation channel.
JReader & read(JReader &in) override final
Read from input.
JOscProbInterpolator(const interpolator_type &interpolator)
Copy constructor.
JProperties getProperties(const JEquationParameters &eqpars=JOscProbInterface::getEquationParameters()) const override final
Get properties of this class.
multifunction_type::result_type result_type
void load()
Load oscillation probability table.
multifunction_type::super_const_iterator super_const_iterator
multifunction_type::function_type function_type
JBaselineComputer baselineComputer
Baseline computer.
JOscProbInterpolator(const char *fileName)
Constructor.
JOscProbInterpolator< JCollection_t, JFunction1D_t, JFunctionalMaplist_t > interpolator_type
JLoadProperty< interpolator_type, std::string > table
Oscillation probability table filename.
void load(const char *table)
Load oscillation probability table.
double getBaseline(const double costh) const override final
Get baseline for a given cosine zenith angle.
JOscProbInterface::JOscParametersHelper_t JOscParametersHelper_t
JOscProbInterface::JOscParameters_t JOscParameters_t
double getCosth(const double L) const override final
Get cosine zenith angle for a given baseline.
One dimensional array of template objects with fixed length.
Definition JArray.hh:43
General purpose class for collection of elements, see: <a href="JTools.PDF";>Collection of elements....
Definition JSet.hh:22
Template definition of function object interface.
Multidimensional interpolation method.
multimap_type::super_iterator super_iterator
multimap_type::super_const_iterator super_const_iterator
multimap_type::result_type result_type
void compile()
Compilation.
void insert(const JMultiFunction< __JFunction_t, __JMaplist_t, __JDistance_t > &input)
Insert multidimensional input.
const JMultiFunction & getMultiFunction() const
Get multidimensional function.
function_type::value_type value_type
function_type::argument_type argument_type
multimap_type::abscissa_type abscissa_type
Multidimensional map.
Definition JMultiMap.hh:52
Template class for polynomial interpolation in 1D.
Definition JPolint.hh:1095
General puprpose classes and methods.
@ notice_t
notice
Definition JMessage.hh:32
static const JOscChannel getOscChannel[]
Declare group of neutrino oscillation channels.
static const unsigned int NUMBER_OF_OSCCHANNELS
Number of neutrino oscillation channels.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for handling debug parameter within a class.
Definition JMessage.hh:44
static int debug
debug level (default is off).
Definition JMessage.hh:45
Auxiliary base class for storing and loading a single object to and from a binary file,...
void load(const char *file_name)
Load from input file.
Template class for object cloning.
Definition JClonable.hh:59
Auxiliary data structure for storing and calculating baselines.
double getCosth(const double L) const override final
Get cosine zenith angle for a given baseline.
double getBaseline(const double costh) const override final
Get baseline for a given cosine zenith angle.
Neutrino oscillation channel.
Abstract base class for oscillation parameter.
void set(const std::string &name, const value_type &value) const
Auxiliary class for I/O of oscillation probability interpolator.
JOscProbInterpolatorHelper(JOscProbInterpolator_t &interpolator, const JEquationParameters &eqpars)
Constructor.
2D Element.
Definition JPolint.hh:1131
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
Type definition of a 2nd degree polynomial interpolation based on a JMap implementation.