Jpp  19.1.0
the software that should make you happy
JOscProbInterpolator.hh
Go to the documentation of this file.
1 #ifndef __JOSCPROB__JOSCPROBINTERPOLATOR__
2 #define __JOSCPROB__JOSCPROBINTERPOLATOR__
3 
4 #include "Jeep/JMessage.hh"
5 
6 #include "JIO/JSerialisable.hh"
7 #include "JIO/JFileStreamIO.hh"
8 
9 #include "JLang/JClonable.hh"
10 #include "JLang/JObjectIO.hh"
11 #include "JLang/JException.hh"
12 
13 #include "JTools/JPolint.hh"
14 #include "JTools/JMapList.hh"
15 #include "JTools/JCollection.hh"
16 #include "JTools/JFunction1D_t.hh"
17 #include "JTools/JMultiFunction.hh"
19 
20 #include "JOscProb/JOscChannel.hh"
25 
26 
27 /**
28  * \author bjung, mdejong
29  */
30 
31 namespace JOSCPROB {}
32 namespace JPP { using namespace JOSCPROB; }
33 
34 namespace JOSCPROB {
35 
36  using JEEP::JMessage;
37 
38  using JLANG::JClonable;
39 
40  using JIO::JSerialisable;
41 
43 
44 
45  /**
46  * Template definition of a multi-dimensional oscillation probability interpolation table.
47  */
48  template<template<class, class> class JCollection_t = JTOOLS::JCollection,
49  class JFunction1D_t = JTOOLS::JPolintFunction1D <1,
51  JCollection_t,
53  class JFunctionalMaplist_t = JTOOLS::JMAPLIST <JTOOLS::JPolint1FunctionalMap,
60  class JOscProbInterpolator final :
61  public JMultiFunction <JFunction1D_t, JFunctionalMaplist_t>,
62  public JClonable<JOscProbInterface, JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >,
63  public JMessage <JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >,
64  public JSerialisable
65  {
66  public:
67 
70 
72 
77 
79 
83 
89 
90 
91  /**
92  * Default constructor.
93  */
95  {
97 
99  }
100 
101 
102  /**
103  * Constructor.
104  *
105  * \param fileName oscillation probability table filename
106  */
107  JOscProbInterpolator(const char* fileName) :
109  {
110  this->load(fileName);
111  }
112 
113 
114  /**
115  * Constructor.
116  *
117  * \param fileName oscillation probability table filename
118  * \param parameters oscillation parameters
119  */
120  JOscProbInterpolator(const char* fileName,
121  const JOscParameters_t& parameters) :
123  {
124  JOscParametersHelper_t::set(parameters);
125 
126  this->load(fileName);
127  }
128 
129 
130  /**
131  * Copy constructor.
132  *
133  * \param interpolator oscillation probability interpolator
134  */
137  {
138  static_cast<multifunction_type&>(*this) = static_cast<const multifunction_type&>(interpolator);
139  }
140 
141 
142  /**
143  * Load oscillation probability table from file.
144  *
145  * \param fileName oscillation probability table filename
146  */
147  void load(const char* const fileName)
148  {
149  using namespace std;
150  using namespace JPP;
151 
152  try {
153 
154  NOTICE("Loading oscillation probability table from file " << fileName << "... " << flush);
155 
156  JLANG::load<JIO::JFileStreamReader>(fileName, static_cast<interpolator_type&>(*this));
157 
158  NOTICE("OK" << endl);
159  }
160  catch(const JException& error) {
161  THROW(JFileReadException, "JOscProbInterpolator::load(): Error reading file " << fileName);
162  }
163  }
164 
165 
166  /**
167  * Get oscillation probability for a given oscillation channel.
168  *
169  * \param channel oscillation channel
170  * \param E neutrino energy [GeV]
171  * \param costh cosine zenith angle
172  * \return oscillation probability
173  */
174  double getP(const JOscChannel& channel,
175  const double E,
176  const double costh) const override final
177  {
178  using namespace std;
179  using namespace JPP;
180 
181  const JOscChannel* p = find(getOscChannel, getOscChannel + NUMBER_OF_OSCCHANNELS, channel);
182 
183  if (p != end(getOscChannel)) {
184 
185  const double L = this->getBaseline(costh);
186 
187  this->buffer[NUMBER_OF_DIMENSIONS-2] = L/E;
188  this->buffer[NUMBER_OF_DIMENSIONS-1] = costh;
189 
190  const double* arguments = this->buffer.data();
191 
192  const size_t index = distance(getOscChannel, p);
193  const result_type& probabilities = this->evaluate(arguments);
194 
195  const double& P = probabilities[index];
196 
197  return (P > 1.0 ? 1.0 : (P < 0.0 ? 0.0 : P));
198 
199  } else {
200 
201  THROW(JValueOutOfRange, "JOscProbInterpolator<...>::getP(): Invalid oscillation channel " << channel << endl);
202  }
203  }
204 
205 
206  /**
207  * Read from input.
208  *
209  * \param in reader
210  * \return reader
211  */
212  JReader& read(JReader& in) override final
213  {
214  in >> this->Lmin >> this->Lmax;
215  in >> static_cast<multifunction_type&>(*this);
216 
217  this->compile();
218 
219  return in;
220  }
221 
222 
223  /**
224  * Write from input.
225  *
226  * \param out writer
227  * \return writer
228  */
229  JWriter& write(JWriter& out) const override final
230  {
231  out << this->Lmin << this->Lmax;
232  out << static_cast<const multifunction_type&>(*this);
233 
234  return out;
235  }
236 
237 
238  private:
239 
241  };
242 }
243 
244 
245 namespace JEEP {
246 
247  /**
248  * JMessage template specialization for oscillation probability interpolators.
249  */
250  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
251  struct JMessage<JOSCPROB::JOscProbInterpolator<JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >
252  {
253  static int debug;
254  };
255 
256 
257  /**
258  * Default verbosity for oscillation probability interpolators.
259  */
260  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
262 
263 }
264 
265 #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.
Definition: JException.hh:712
Various implementations of functional maps.
General purpose messaging.
#define NOTICE(A)
Definition: JMessage.hh:64
General methods for loading and storing a single object from and to a file, respectively.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Interface for binary input.
Forward declaration of binary output.
Interface for binary output.
General exception.
Definition: JException.hh:24
Exception for reading of file.
Definition: JException.hh:396
Parameter class.
Definition: JParameter.hh:36
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:180
Interface class for sets of oscillation parameters.
Data structure for single set of oscillation parameters.
Template definition of a multi-dimensional oscillation probability interpolation table.
JOscProbInterpolator()
Default constructor.
JOscProbInterface::JOscParameter_t JOscParameter_t
JOscProbInterface::JParameter_t JParameter_t
multifunction_type::function_type function_type
JOscProbInterface::JOscParameterReferences_t JOscParameterReferences_t
multifunction_type::abscissa_type abscissa_type
JOscProbInterpolator(const char *fileName, const JOscParameters_t &parameters)
Constructor.
multifunction_type::multimap_type multimap_type
JOscProbInterface::JOscParameters_t JOscParameters_t
multifunction_type::super_const_iterator super_const_iterator
double getP(const JOscChannel &channel, const double E, const double costh) const override final
Get oscillation probability for a given oscillation channel.
JOscProbInterpolator(const interpolator_type &interpolator)
Copy constructor.
multifunction_type::argument_type argument_type
JOscProbInterface::JOscParametersHelper_t JOscParametersHelper_t
multifunction_type::result_type result_type
JWriter & write(JWriter &out) const override final
Write from input.
JOscProbInterpolator< JCollection_t, JFunction1D_t, JFunctionalMaplist_t > interpolator_type
void load(const char *const fileName)
Load oscillation probability table from file.
JReader & read(JReader &in) override final
Read from input.
JOscProbInterpolator(const char *fileName)
Constructor.
JMultiFunction< JFunction1D_t, JFunctionalMaplist_t > multifunction_type
multifunction_type::super_iterator super_iterator
multifunction_type::value_type value_type
One dimensional array of template objects with fixed length.
Definition: JArray.hh:43
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:284
General purpose class for collection of elements, see: <a href="JTools.PDF";>Collection of elements...
Definition: JCollection.hh:79
Multidimensional interpolation method.
multimap_type::result_type result_type
function_type::value_type value_type
void compile()
Compilation.
multimap_type::abscissa_type abscissa_type
multimap_type::super_iterator super_iterator
function_type::argument_type argument_type
JArray< NUMBER_OF_DIMENSIONS, argument_type > buffer
multimap_type::super_const_iterator super_const_iterator
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.
Definition: JOscChannel.hh:326
static const unsigned int NUMBER_OF_OSCCHANNELS
Number of neutrino oscillation channels.
Definition: JOscChannel.hh:351
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
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
Template class for object cloning.
Definition: JClonable.hh:59
Neutrino oscillation channel.
Definition: JOscChannel.hh:112
Abstract base class for oscillation parameter.
void configure(const pointer_type &p)
Configure oscillation parameters.
void set(const std::string &name, const value_type &value) const
Set value for a given oscillation parameter.
2D Element.
Definition: JElement.hh:46
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.