Jpp  18.6.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 
41  using JIO::JSerialisable;
42 
44 
45 
46  /**
47  * Template definition of a multi-dimensional oscillation probability interpolation table.
48  */
49  template<template<class, class> class JCollection_t = JTOOLS::JCollection,
50  class JFunction1D_t = JTOOLS::JPolintFunction1D <1,
52  JCollection_t,
54  class JFunctionalMaplist_t = JTOOLS::JMAPLIST <JTOOLS::JPolint1FunctionalMap,
62  public JMultiFunction <JFunction1D_t, JFunctionalMaplist_t>,
63  public JClonable<JOscProbInterface, JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >,
64  public JMessage <JOscProbInterpolator <JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >,
65  public JSerialisable
66  {
67  public:
68 
71 
73 
78 
80 
84 
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)
108  {
110 
112 
113  this->load(fileName);
114  }
115 
116 
117  /**
118  * Constructor.
119  *
120  * \param fileName oscillation probability table filename
121  * \param parameters oscillation parameters
122  */
123  JOscProbInterpolator(const char* fileName,
125  {
127 
129 
130  JOscParametersHelper_t::set(parameters);
131 
132  this->load(fileName);
133  }
134 
135 
136  /**
137  * Load oscillation probability table from file.
138  *
139  * \param fileName oscillation probability table filename
140  */
141  void load(const char* fileName)
142  {
143  using namespace std;
144  using namespace JPP;
145 
146  try {
147 
148  NOTICE("loading oscillation probability table from file " << fileName << "... " << flush);
149 
150  JLANG::load<JIO::JFileStreamReader>(fileName, static_cast<JOscProbInterpolator&>(*this));
151 
152  NOTICE("OK" << endl);
153  }
154  catch(const JException& error) {
155  THROW(JFileReadException, "JOscProbInterpolator::load(): Error reading file " << fileName);
156  }
157  }
158 
159 
160  /**
161  * Get oscillation probability for a given oscillation channel.
162  *
163  * \param channel oscillation channel
164  * \param E neutrino energy [GeV]
165  * \param costh cosine zenith angle
166  * \return oscillation probability
167  */
168  double getP(const JOscChannel& channel,
169  const double E,
170  const double costh) const override
171  {
172  using namespace std;
173  using namespace JPP;
174 
175  const JOscChannel* p = find(getOscChannel, getOscChannel + NUMBER_OF_OSCCHANNELS, channel);
176 
177  if (p != end(getOscChannel)) {
178 
179  const double L = baselineComputer.getBaseline(costh);
180 
181  this->buffer[NUMBER_OF_DIMENSIONS-2] = L/E;
182  this->buffer[NUMBER_OF_DIMENSIONS-1] = costh;
183 
184  const double* arguments = this->buffer.data();
185 
186  const size_t index = distance(getOscChannel, p);
187  const result_type& probabilities = this->evaluate(arguments);
188 
189  const double& P = probabilities[index];
190 
191  return (P > 1.0 ? 1.0 : (P < 0.0 ? 0.0 : P));
192 
193  } else {
194 
195  THROW(JValueOutOfRange, "JOscProbInterpolator<...>::getP(): Invalid oscillation channel " << channel << endl);
196  }
197  }
198 
199 
200  /**
201  * Get cosine zenith angle for a given baseline.
202  *
203  * \param L baseline [km]
204  * \return cosine zenith angle
205  */
206  double getCosth(const double L) const override
207  {
208  return baselineComputer.getCosth(L);
209  }
210 
211 
212  /**
213  * Get baseline for a given cosine zenith angle.
214  *
215  * \param costh cosine zenith angle
216  * \return baseline [km]
217  */
218  double getBaseline(const double costh) const override
219  {
220  return baselineComputer.getBaseline(costh);
221  }
222 
223 
224  /**
225  * Read from input.
226  *
227  * \param in reader
228  * \return reader
229  */
230  JReader& read(JReader& in) override
231  {
232  using namespace JPP;
233 
234  in >> baselineComputer;
235  in >> static_cast<multifunction_type&>(*this);
236 
237  this->compile();
238 
239  return in;
240  }
241 
242 
243  /**
244  * Write from input.
245  *
246  * \param out writer
247  * \return writer
248  */
249  JWriter& write(JWriter& out) const override
250  {
251  out << baselineComputer;
252  out << static_cast<const multifunction_type&>(*this);
253 
254  return out;
255  }
256 
257 
258  private:
259 
261 
263  };
264 }
265 
266 
267 namespace JEEP {
268 
269  /**
270  * JMessage template specialization for oscillation probability interpolators.
271  */
272  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
273  struct JMessage<JOSCPROB::JOscProbInterpolator<JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >
274  {
275  static int debug;
276  };
277 
278 
279  /**
280  * Default verbosity for oscillation probability interpolators.
281  */
282  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
284 
285 }
286 
287 #endif
function_type::argument_type argument_type
static int debug
debug level (default is off).
Definition: JMessage.hh:45
Abstract base class for oscillation parameter.
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
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
virtual void set(const std::string &name, const value_type &value) const
Set value for a given oscillation parameter.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
notice
Definition: JMessage.hh:32
*fatal Wrong number of arguments
JOscProbInterface::JOscParameters_t JOscParameters_t
JMultiFunction< JFunction1D_t, JFunctionalMaplist_t > multifunction_type
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
JOscProbInterpolator(const char *fileName)
Constructor.
Utility class to parse parameter values.
double getCosth(const double L) const override
Get cosine zenith angle for a given baseline.
Various implementations of functional maps.
JOscProbInterpolator(const char *fileName, const JOscParametersInterface< double > &parameters)
Constructor.
JOscProbInterface::JOscParametersHelper_t JOscParametersHelper_t
Forward declaration of binary output.
function_type::value_type value_type
double getBaseline(const double costh) const override
Get baseline for a given cosine zenith angle.
void load(const char *fileName)
Load oscillation probability table from file.
Multidimensional interpolation method.
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
double getCosth(const double L) const override
Get cosine zenith angle for a given baseline.
double getBaseline(const double costh) const override
Get baseline for a given cosine zenith angle.
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.
virtual void configure(const JOscParameters_t &parameters)
Configure oscillation parameters.
Auxiliary data structure for storing and calculating baselines.
JOscProbInterface::JParameter_t JParameter_t
multifunction_type::function_type function_type
JWriter & write(JWriter &out) const override
Write from input.
multimap_type::result_type result_type
multifunction_type::result_type result_type
multimap_type::abscissa_type abscissa_type
Data structure for single set of oscillation parameters.
then fatal The output file must have the wildcard in the e g root fi 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:48
multifunction_type::super_const_iterator super_const_iterator
JOscProbInterface::JOscParameter_t JOscParameter_t
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.
Interface class for sets of oscillation parameters.
double getP(const JOscChannel &channel, const double E, const double costh) const override
Get oscillation probability for a given oscillation channel.
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:1092
Multidimensional map.
Definition: JMultiMap.hh:52
Template definition of a multi-dimensional oscillation probability interpolation table.
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:62
JOscProbInterpolator< JCollection_t, JFunction1D_t, JFunctionalMaplist_t > interpolator_type
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:44