Jpp  18.5.0
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  */
97  {
98  JOscParameters<> standardParameters;
99 
100  JOscParametersHelper_t::configure(standardParameters);
101 
102  JOscParametersHelper_t::set(standardParameters);
103  }
104 
105 
106  /**
107  * Constructor.
108  *
109  * \param fileName oscillation probability table filename
110  */
111  JOscProbInterpolator(const char* fileName) :
114  {
115  JOscParameters<> standardParameters;
116 
117  JOscParametersHelper_t::configure(standardParameters);
118 
119  JOscParametersHelper_t::set(standardParameters);
120 
121  this->load(fileName);
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) :
135  {
137 
138  JOscParametersHelper_t::set(parameters);
139 
140  this->load(fileName);
141  }
142 
143 
144  /**
145  * Load oscillation probability table from file.
146  *
147  * \param fileName oscillation probability table filename
148  */
149  void load(const char* fileName)
150  {
151  using namespace std;
152  using namespace JPP;
153 
154  try {
155 
156  NOTICE("loading oscillation probability table from file " << fileName << "... " << flush);
157 
158  JLANG::load<JIO::JFileStreamReader>(fileName, static_cast<JOscProbInterpolator&>(*this));
159 
160  NOTICE("OK" << endl);
161  }
162  catch(const JException& error) {
163  THROW(JFileReadException, "JOscProbInterpolator::load(): Error reading file " << fileName);
164  }
165  }
166 
167 
168  /**
169  * Set value for a given oscillation parameter.
170  *
171  * \param name parameter name
172  * \param value parameter value
173  */
174  void set(const std::string& name,
175  argument_type value) const override
176  {
177  JOscParameters_t& parameters = this->getParameters();
178 
179  JProperties properties = parameters.getProperties();
180 
181  JProperties::iterator i = properties.find(name);
182 
183  if (i != properties.end()) {
184 
185  JOscParameter_t& parameter = i->second.getValue<JOscParameter_t>();
186 
187  parameter.setValue(value);
188 
189  const int index = distance(properties.begin(), i);
190 
191  this->buffer[index] = value;
192 
193  } else {
195  "JOscProbInterpolator<...>::set(): Given oscillation parameter " << name <<
196  " is inconsistent with the parameter set of this oscillation probability interpolator");
197  }
198  }
199 
200 
201  /**
202  * Get oscillation probability for a given oscillation channel.
203  *
204  * \param channel oscillation channel
205  * \param E neutrino energy [GeV]
206  * \param costh cosine zenith angle
207  * \return oscillation probability
208  */
209  double getP(const JOscChannel& channel,
210  const double E,
211  const double costh) const override
212  {
213  using namespace std;
214  using namespace JPP;
215 
216  const JOscChannel* p = find(getOscChannel, getOscChannel + NUMBER_OF_OSCCHANNELS, channel);
217 
218  if (p != end(getOscChannel)) {
219 
220  const double L = baselineComputer.getBaseline(costh);
221 
222  this->buffer[NUMBER_OF_DIMENSIONS-2] = L/E;
223  this->buffer[NUMBER_OF_DIMENSIONS-1] = costh;
224 
225  const argument_type* arguments = this->buffer.data();
226 
227  const size_t index = distance(getOscChannel, p);
228  const result_type& probabilities = this->evaluate(arguments);
229 
230  const double& P = probabilities[index];
231 
232  return (P > 1.0 ? 1.0 : (P < 0.0 ? 0.0 : P));
233 
234  } else {
235 
236  THROW(JValueOutOfRange, "JOscProbInterpolator<...>::getP(): Invalid oscillation channel " << channel << endl);
237  }
238  }
239 
240 
241  /**
242  * Get cosine zenith angle for a given baseline.
243  *
244  * \param L baseline [km]
245  * \return cosine zenith angle
246  */
247  double getCosth(const double L) const override
248  {
249  return baselineComputer.getCosth(L);
250  }
251 
252 
253  /**
254  * Get baseline for a given cosine zenith angle.
255  *
256  * \param costh cosine zenith angle
257  * \return baseline [km]
258  */
259  double getBaseline(const double costh) const override
260  {
261  return baselineComputer.getBaseline(costh);
262  }
263 
264 
265  /**
266  * Read from input.
267  *
268  * \param in reader
269  * \return reader
270  */
271  JReader& read(JReader& in) override
272  {
273  using namespace JPP;
274 
275  in >> baselineComputer;
276  in >> static_cast<multifunction_type&>(*this);
277 
278  this->compile();
279 
280  return in;
281  }
282 
283 
284  /**
285  * Write from input.
286  *
287  * \param out writer
288  * \return writer
289  */
290  JWriter& write(JWriter& out) const override
291  {
292  out << baselineComputer;
293  out << static_cast<const multifunction_type&>(*this);
294 
295  return out;
296  }
297 
298 
299  private:
300 
302 
304  };
305 }
306 
307 
308 namespace JEEP {
309 
310  /**
311  * JMessage template specialization for oscillation probability interpolators.
312  */
313  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
314  struct JMessage<JOSCPROB::JOscProbInterpolator<JCollection_t, JFunction1D_t, JFunctionalMaplist_t> >
315  {
316  static int debug;
317  };
318 
319 
320  /**
321  * Default verbosity for oscillation probability interpolators.
322  */
323  template<template<class, class> class JCollection_t, class JFunction1D_t, class JFunctionalMaplist_t>
325 
326 }
327 
328 #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.
void set(const std::string &name, argument_type value) const override
Set value for a given oscillation parameter.
static const unsigned int NUMBER_OF_OSCCHANNELS
Number of neutrino oscillation channels.
Definition: JOscChannel.hh:351
JOscProbInterpolator(const char *fileName, const JOscParameters_t &parameters)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
notice
Definition: JMessage.hh:32
Utility class to parse parameter values.
Definition: JProperties.hh:497
*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.
void setValue(argument_type value)
Set parameter.
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.
JOscProbInterface::JOscParametersHelper_t JOscParametersHelper_t
Forward declaration of binary output.
virtual void set(const std::string &name, argument_type value) const
Set value for a given oscillation parameter.
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
then awk string
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.
virtual JProperties getProperties(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters())=0
Get properties of this class.
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:48
multifunction_type::super_const_iterator super_const_iterator
JOscProbInterface::JOscParameter_t JOscParameter_t
const T & getValue() const
Get value of parameter.
Definition: JParameter.hh:81
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