Jpp  18.2.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOscProbInterpolator.hh
Go to the documentation of this file.
1 #ifndef __JOSCPROB__JOSCPROBINTERPOLATOR__
2 #define __JOSCPROB__JOSCPROBINTERPOLATOR__
3 
4 #include "Jeep/JMessage.hh"
5 #include "Jeep/JProperties.hh"
6 
7 #include "JIO/JSerialisable.hh"
8 #include "JIO/JFileStreamIO.hh"
9 
10 #include "JLang/JClonable.hh"
11 #include "JLang/JObjectIO.hh"
12 #include "JLang/JException.hh"
13 
14 #include "JTools/JPolint.hh"
15 #include "JTools/JMapList.hh"
16 #include "JTools/JCollection.hh"
17 #include "JTools/JFunction1D_t.hh"
18 #include "JTools/JMultiFunction.hh"
20 
21 #include "JOscProb/JOscChannel.hh"
26 
27 
28 /**
29  * \author bjung, mdejong
30  */
31 
32 namespace JOSCPROB {}
33 namespace JPP { using namespace JOSCPROB; }
34 
35 namespace JOSCPROB {
36 
37  using JEEP::JMessage;
38 
39  using JLANG::JClonable;
40 
42 
43 
44  /**
45  * Template definition of a multi-dimensional oscillation probability interpolation table.
46  */
47  template<template<class, class> class JCollection_t = JTOOLS::JCollection,
48  class JFunction1D_t = JTOOLS::JPolintFunction1D <1,
50  JCollection_t,
52  class JFunctionalMaplist_t = JTOOLS::JMAPLIST <JTOOLS::JPolint1FunctionalMap,
60  public JMultiFunction <JFunction1D_t, JFunctionalMaplist_t>,
61  public JClonable<JOscProbInterpolatorInterface, JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >,
62  public JMessage <JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >
63  {
64  public:
65 
68 
70 
75 
77 
81 
83 
84 
85  /**
86  * Default constructor.
87  */
90  parameters(),
91  getBaseline()
92  {
93  this->set(JOscParameters(false)); // Initialize buffer with NuFIT NO best fit parameters
94  }
95 
96 
97  /**
98  * Constructor.
99  *
100  * \param fileName oscillation probability table filename
101  */
102  JOscProbInterpolator(const char* fileName) :
104  parameters(),
105  getBaseline()
106  {
107  this->load(fileName);
108  this->set(JOscParameters(false)); // Initialize buffer with NuFIT NO best fit parameters
109  }
110 
111 
112  /**
113  * Constructor.
114  *
115  * \param fileName oscillation probability table filename
116  * \param parameters oscillation parameters
117  */
118  JOscProbInterpolator(const char* fileName,
119  const JOscParameters& parameters) :
121  parameters(),
122  getBaseline()
123  {
124  this->load(fileName);
125  this->set(parameters);
126  }
127 
128 
129  /**
130  * Load oscillation probability table from file.
131  *
132  * \param fileName oscillation probability table filename
133  */
134  void load(const char* fileName) override
135  {
136  using namespace std;
137  using namespace JPP;
138 
139  try {
140 
141  NOTICE("loading oscillation probability table from file " << fileName << "... " << flush);
142 
143  JLANG::load<JIO::JFileStreamReader>(fileName, *this);
144 
145  NOTICE("OK" << endl);
146  }
147  catch(const JException& error) {
148  THROW(JFileReadException, "JOscProbInterpolator::load(): Error reading file " << fileName);
149  }
150  }
151 
152 
153  /**
154  * Get fixed oscillation parameters associated with this interpolation table.
155  *
156  * \return oscillation parameters
157  */
158  const JOscParameters& getTableParameters() const override
159  {
160  return parameters;
161  }
162 
163 
164  /**
165  * Get baseline calculator associated with this interpolation table.
166  *
167  * \return baseline calculator
168  */
170  {
171  return getBaseline;
172  }
173 
174 
175  /**
176  * Set oscillation parameters for interpolation.
177  *
178  * \param parameters oscillation parameters
179  */
180  void set(const JOscParameters& parameters) const override
181  {
182  using namespace JPP;
183 
184  JOscParameters pars(parameters);
185  pars.join(this->parameters);
186 
187  const JProperties properties = pars.getProperties();
188 
189  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
190 
191  const JOscParameters::JParameter_t& parameter = i->second.getValue<JOscParameters::JParameter_t>();
192 
193  if (parameter.isDefined()) {
194 
195  const int index = std::distance(properties.cbegin(), i);
196 
197  this->buffer[index] = parameter.getValue();
198 
199  } else {
200 
201  THROW(JNoValue,
202  "JOscProbInterpolator<...>::set(JOscParameters): " <<
203  "No value for parameter " << i->first);
204  }
205  }
206  }
207 
208 
209  /**
210  * Get oscillation probability for a given oscillation channel.
211  *
212  * \param channel oscillation channel
213  * \param E neutrino energy [GeV]
214  * \param costh cosine zenith angle
215  * \return oscillation probability
216  */
217  double operator()(const JOscChannel& channel,
218  const double E,
219  const double costh) const override
220  {
221  using namespace std;
222  using namespace JPP;
223 
224  const JOscChannel* p = find(getOscChannel, getOscChannel + NUMBER_OF_OSCCHANNELS, channel);
225 
226  if (p != end(getOscChannel)) {
227 
228  const double L = getBaseline(costh);
229 
230  this->buffer[NUMBER_OF_DIMENSIONS-2] = L/E;
231  this->buffer[NUMBER_OF_DIMENSIONS-1] = costh;
232 
233  const argument_type* arguments = this->buffer.data();
234 
235  const size_t index = distance(getOscChannel, p);
236  const result_type& probabilities = this->evaluate(arguments);
237 
238  const double& P = probabilities[index];
239 
240  return (P > 1.0 ? 1.0 : (P < 0.0 ? 0.0 : P));
241 
242  } else {
243 
244  THROW(JValueOutOfRange, "JOscProbInterpolator<...>::operator(): Invalid oscillation channel " << channel << endl);
245  }
246  }
247 
248 
249  /**
250  * Get oscillation probability for a given set of oscillation parameters\n
251  * and a given oscillation channel.
252  *
253  * \param channel oscillation channel
254  * \param parameters oscillation parameters
255  * \param E neutrino energy [GeV]
256  * \param costh cosine zenith angle
257  * \return oscillation probability
258  */
260  const JOscChannel& channel,
261  const double E,
262  const double costh) const override
263  {
264  set(parameters);
265 
266  return (*this)(channel, E, costh);
267  }
268 
269 
270  /**
271  * Read from input.
272  *
273  * \param in reader
274  * \return reader
275  */
276  JReader& read(JReader& in) override
277  {
278  parameters.read(in);
279  getBaseline.read(in);
280 
281  in >> static_cast<multifunction_type&>(*this);
282 
283  this->compile();
284 
285  return in;
286  }
287 
288 
289  /**
290  * Write from input.
291  *
292  * \param out writer
293  * \return writer
294  */
295  JWriter& write(JWriter& out) const override
296  {
297  parameters.write(out);
298  getBaseline.write(out);
299 
300  out << static_cast<const multifunction_type&>(*this);
301 
302  return out;
303  }
304 
305 
306  private:
307 
308  JOscParameters parameters; //!< Fixed oscillation parameters corresponding to the oscillation probability table
309  JBaselineCalculator getBaseline; //!< Baseline functor
310  };
311 }
312 
313 
314 namespace JEEP {
315 
316  /**
317  * JMessage template specialization for oscillation probability interpolators.
318  */
319  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
320  struct JMessage<JOSCPROB::JOscProbInterpolator<JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >
321  {
322  static int debug;
323  };
324 
325 
326  /**
327  * Default verbosity for oscillation probability interpolators.
328  */
329  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
331 
332 }
333 
334 #endif
function_type::argument_type argument_type
double operator()(const JOscParameters &parameters, const JOscChannel &channel, const double E, const double costh) const override
Get oscillation probability for a given set of oscillation parameters and a given oscillation channel...
static int debug
debug level (default is off).
Definition: JMessage.hh:45
void compile()
Compilation.
Type definition of a 2nd degree polynomial interpolation based on a JMap implementation.
Exceptions.
Interface for binary output.
JOscProbInterpolator()
Default constructor.
multimap_type::super_iterator super_iterator
General purpose class for collection of elements, see: &lt;a href=&quot;JTools.PDF&quot;;&gt;Collection of elements...
Definition: JCollection.hh:73
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
Neutrino oscillation channel.
Definition: JOscChannel.hh:110
Parameter class.
Definition: JParameter.hh:34
multimap_type::super_const_iterator super_const_iterator
multifunction_type::argument_type argument_type
JWriter & write(JWriter &out) const override
Binary stream output of oscillation parameters.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
static const unsigned int NUMBER_OF_OSCCHANNELS
Number of neutrino oscillation channels.
Definition: JOscChannel.hh:351
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
notice
Definition: JMessage.hh:32
Utility class to parse parameter values.
Definition: JProperties.hh:497
*fatal Wrong number of arguments
JReader & read(JReader &in) override
Binary stream input of oscillation parameters.
Data structure for single set of oscillation parameters.
JMultiFunction< JFunction1D_t, JFunctionalMaplist_t > multifunction_type
JOscProbInterpolator(const char *fileName, const JOscParameters &parameters)
Constructor.
JOscProbInterpolator(const char *fileName)
Constructor.
Auxiliary data structure for storing and calculating baselines.
Utility class to parse parameter values.
Various implementations of functional maps.
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:136
JProperties getProperties(const JEquationParameters &equation=JOscParameters_t::getEquationParameters())
Get properties of this class.
void set(const JOscParameters &parameters) const override
Set oscillation parameters for interpolation.
JWriter & write(JWriter &out) const override
Binary stream output of oscillation parameters.
JReader & read(JReader &in) override
Binary stream input of baseline extrema.
function_type::value_type value_type
Multidimensional interpolation method.
const JBaselineCalculator & getBaselineCalculator() const override
Get baseline calculator associated with this interpolation table.
JArray< NUMBER_OF_DIMENSIONS, argument_type > buffer
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
static const JOscChannel getOscChannel[]
Declare group of neutrino oscillation channels.
Definition: JOscChannel.hh:326
multifunction_type::value_type value_type
Template class for object cloning.
Definition: JClonable.hh:20
#define NOTICE(A)
Definition: JMessage.hh:64
multifunction_type::multimap_type multimap_type
General purpose class for a collection of sorted elements.
Interface for binary input.
One dimensional array of template objects with fixed length.
Definition: JArray.hh:40
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:108
General purpose messaging.
JOscParameters_t & join(const JOscParameters_t &parameters)
Join the given oscillation parameters with these oscillation parameters.
double operator()(const JOscChannel &channel, const double E, const double costh) const override
Get oscillation probability for a given oscillation channel.
multifunction_type::function_type function_type
JWriter & write(JWriter &out) const override
Write from input.
void load(const char *fileName) override
Load oscillation probability table from file.
multimap_type::result_type result_type
JOscParameters parameters
Fixed oscillation parameters corresponding to the oscillation probability table.
multifunction_type::result_type result_type
multimap_type::abscissa_type abscissa_type
multifunction_type::super_const_iterator super_const_iterator
const T & getValue() const
Get value of parameter.
Definition: JParameter.hh:80
2D Element.
Definition: JElement.hh:46
multifunction_type::abscissa_type abscissa_type
JReader & read(JReader &in) override
Read from input.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
General methods for loading and storing a single object from and to a file, respectively.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
multifunction_type::super_iterator super_iterator
const_pointer data() const
Get pointer to data.
Definition: JArray.hh:284
Template class for polynomial interpolation in 1D.
Definition: JPolint.hh:1003
Multidimensional map.
Definition: JMultiMap.hh:52
Template definition of a multi-dimensional oscillation probability interpolation table.
JBaselineCalculator getBaseline
Baseline functor.
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:62
JOscProbInterpolator< JCollection_t, JFunction1D_t, JFunctionalMaplist_t > interpolator_type
const JOscParameters & getTableParameters() const override
Get fixed oscillation parameters associated with this interpolation table.
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:44