Jpp  17.3.2
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  * \return oscillation parameters
179  */
181  {
182  using namespace JPP;
183 
184  parameters.join(this->parameters);
185 
186  const JProperties properties = parameters.getProperties();
187 
188  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
189 
191 
192  if (parameter.isDefined()) {
193 
194  const int index = std::distance(properties.cbegin(), i);
195 
196  this->buffer[index] = parameter.getValue();
197 
198  } else {
199 
200  THROW(JNoValue,
201  "JOscProbInterpolator<...>::set(JOscParameters): " <<
202  "No value for parameter " << i->first);
203  }
204  }
205  }
206 
207 
208  /**
209  * Get oscillation probability for a given oscillation channel.
210  *
211  * \param channel oscillation channel
212  * \param E neutrino energy [GeV]
213  * \param costh cosine zenith angle
214  * \return oscillation probability
215  */
216  double operator()(const JOscChannel& channel,
217  const double E,
218  const double costh) const override
219  {
220  using namespace std;
221  using namespace JPP;
222 
223  const JOscChannel* p = find(getOscChannel, getOscChannel + NUMBER_OF_OSCCHANNELS, channel);
224 
225  if (p != end(getOscChannel)) {
226 
227  const double L = getBaseline(costh);
228 
229  this->buffer[NUMBER_OF_DIMENSIONS-2] = L/E;
230  this->buffer[NUMBER_OF_DIMENSIONS-1] = costh;
231 
232  const argument_type* arguments = this->buffer.data();
233 
234  const size_t index = distance(getOscChannel, p);
235  const result_type& probabilities = this->evaluate(arguments);
236 
237  return probabilities[index];
238 
239  } else {
240 
241  THROW(JValueOutOfRange, "JOscProbInterpolator<...>::operator(): Invalid oscillation channel " << channel << endl);
242  }
243  }
244 
245 
246  /**
247  * Get oscillation probability for a given set of oscillation parameters\n
248  * and a given oscillation channel.
249  *
250  * \param channel oscillation channel
251  * \param parameters oscillation parameters
252  * \param E neutrino energy [GeV]
253  * \param costh cosine zenith angle
254  * \return oscillation probability
255  */
257  const JOscChannel& channel,
258  const double E,
259  const double costh) override
260  {
261  set(parameters);
262 
263  return (*this)(channel, E, costh);
264  }
265 
266 
267  /**
268  * Read from input.
269  *
270  * \param in reader
271  * \return reader
272  */
273  JReader& read(JReader& in) override
274  {
275  parameters.read(in);
276  getBaseline.read(in);
277 
278  in >> static_cast<multifunction_type&>(*this);
279 
280  this->compile();
281 
282  return in;
283  }
284 
285 
286  /**
287  * Write from input.
288  *
289  * \param out writer
290  * \return writer
291  */
292  JWriter& write(JWriter& out) const override
293  {
294  parameters.write(out);
295  getBaseline.write(out);
296 
297  out << static_cast<const multifunction_type&>(*this);
298 
299  return out;
300  }
301 
302 
303  private:
304 
305  JOscParameters parameters; //!< Fixed oscillation parameters corresponding to the oscillation probability table
306  JBaselineCalculator getBaseline; //!< Baseline functor
307  };
308 }
309 
310 
311 namespace JEEP {
312 
313  /**
314  * JMessage template specialization for oscillation probability interpolators.
315  */
316  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
317  struct JMessage<JOSCPROB::JOscProbInterpolator<JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >
318  {
319  static int debug;
320  };
321 
322 
323  /**
324  * Default verbosity for oscillation probability interpolators.
325  */
326  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
328 
329 }
330 
331 #endif
function_type::argument_type argument_type
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
void set(JOscParameters parameters) override
Set oscillation parameters for interpolation.
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 E
Definition: JMuonPostfit.sh:35
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:696
notice
Definition: JMessage.hh:32
Utility class to parse parameter values.
Definition: JProperties.hh:496
*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.
double operator()(const JOscParameters &parameters, const JOscChannel &channel, const double E, const double costh) override
Get oscillation probability for a given set of oscillation parameters and a given oscillation channel...
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.
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:162
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.
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