Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JOscProbHelper.hh
Go to the documentation of this file.
1#ifndef __JOSCPROB__JOSCPROBHELPER__
2#define __JOSCPROB__JOSCPROBHELPER__
3
4#include <memory>
5
6#include "JSystem/JStat.hh"
7
8#include "JLang/JEquation.hh"
9#include "JLang/JException.hh"
10
11#include "Jeep/JProperties.hh"
12
16
17
18/**
19 * \author bjung
20 */
21
22namespace JOSCPROB {}
23namespace JPP { using namespace JOSCPROB; }
24
25namespace JOSCPROB {
26
27 /**
28 * Helper class for oscillation probability calculators.
29 */
31 public std::shared_ptr<JOscProbInterface>
32 {
36
39
40 typedef std::shared_ptr<JOscProbInterface> pointer_type;
41
42
43 /**
44 * Default constructor.
45 */
48
49
50 /**
51 * Copy constructor.
52 *
53 * \param pOscProb shared pointer to oscillation probability function
54 */
55 JOscProbHelper(const pointer_type& pOscProb) :
56 pointer_type(pOscProb)
57 {}
58
59
60 /**
61 * Constructor.
62 *
63 * \param oscProb oscillation probability function
64 */
66 {
67 configure(oscProb);
68 }
69
70
71 /**
72 * Configure oscillation probability function.
73 *
74 * \param pOscProb shared pointer to oscillation probability function
75 */
76 void configure(const pointer_type& pOscProb)
77 {
78 static_cast<pointer_type&>(*this) = pOscProb;
79 }
80
81
82 /**
83 * Configure oscillation probability function.
84 *
85 * \param oscProb oscillation probability function
86 */
87 void configure(const JOscProbInterface& oscProb)
88 {
89 this->reset(oscProb.clone());
90 }
91
92
93 /**
94 * Get reference to oscillation probability interface.
95 *
96 * \return oscillation parameters
97 */
99 {
100 using namespace JPP;
101
102 if (static_cast<const JOscProbHelper&>(*this)) {
103 return *(this->get());
104 } else {
105 THROW(JNullPointerException, "JOscProbHelper::getOscProbInterface(): Oscillation probability interface is not set.");
106 }
107 }
108
109
110 /**
111 * Get reference to oscillation parameters interface.
112 *
113 * \return reference to oscillation parameters interface
114 */
119
120
121 /**
122 * Set oscillation parameters.
123 *
124 * \param parameters oscillation parameters
125 */
126 void set(const JOscParameters_t& parameters) const
127 {
128 return getParameters().set(parameters);
129 }
130
131
132 /**
133 * Set value for a given oscillation parameter.
134 *
135 * \param name parameter name
136 * \param value parameter value
137 */
138 void set(const std::string& name,
139 const value_type& value) const
140 {
141 getParameters().set(name, value);
142 }
143
144
145 /**
146 * Set value for given list of oscillation parameters.
147 *
148 * \param name parameter name
149 * \param value parameter value
150 * \param args remaining pairs of parameter names and values
151 */
152 template<class ...Args>
153 void set(const std::string& name,
154 const value_type& value,
155 const Args& ...args) const
156 {
157 getParameters().set(name, value, args...);
158 }
159
160
161 /**
162 * Get cosine zenith angle for a given baseline.
163 *
164 * \param L baseline [km]
165 * \return cosine zenith angle
166 */
167 double getCosth(const double L) const
168 {
169 return getOscProbInterface().getCosth(L);
170 }
171
172
173 /**
174 * Get baseline for a given cosine zenith angle.
175 *
176 * \param costh cosine zenith angle
177 * \return baseline [km]
178 */
179 double getBaseline(const double costh) const
180 {
181 return getOscProbInterface().getBaseline(costh);
182 }
183
184
185 /**
186 * Get oscillation probability corresponding to given oscillation channel,
187 * neutrino energy and zenith angle.
188 *
189 * \param channel oscillation channel
190 * \param energy neutrino energy [GeV]
191 * \param costh cosine zenith angle
192 * \return oscillation probability
193 */
194 double getP(const JOscChannel& channel,
195 const double energy,
196 const double costh) const
197 {
198 return getOscProbInterface().getP(channel, energy, costh);
199 }
200
201
202 /**
203 * Get oscillation probability for a given set of oscillation parameters\n
204 * and a given oscillation channel.
205 *
206 * \param channel oscillation channel
207 * \param parameters oscillation parameters
208 * \param energy neutrino energy [GeV]
209 * \param costh cosine zenith angle
210 * \return oscillation probability
211 */
212 double getP(const JOscParameters_t& parameters,
213 const JOscChannel& channel,
214 const double energy,
215 const double costh) const
216 {
217 return getOscProbInterface().getP(parameters, channel, energy, costh);
218 }
219
220
221 /**
222 * Get oscillation probability for a given oscillation parameter\n
223 * and a given oscillation channel.
224 *
225 * \param name parameter name
226 * \param value parameter value
227 * \param channel oscillation channel
228 * \param E neutrino energy [GeV]
229 * \param costh cosine zenith angle
230 * \return oscillation probability
231 */
232 double getP(const std::string& name,
233 const double value,
234 const JOscChannel& channel,
235 const double E,
236 const double costh) const
237 {
238 return getOscProbInterface().getP(name, value, channel, E, costh);
239 }
240
241
242 /**
243 * Get oscillation probability for a given set of oscillation parameters\n
244 * and a given oscillation channel.
245 *
246 * \param name parameter name
247 * \param value parameter value
248 * \param args remaining arguments
249 */
250 template<class ...Args>
251 double getP(const std::string& name,
252 const double value,
253 const Args& ...args) const
254 {
255 return getOscProbInterface().getP(name, value, args...);
256 }
257
258
259 /**
260 * Get properties of this class.
261 *
262 * \param eqpars equation parameters
263 */
268
269
270 /**
271 * Get properties of this class.
272 *
273 * \param eqpars equation parameters
274 */
279
280
281 /**
282 * Read from input.
283 *
284 * Input syntax as follows:
285 * <pre>
286 * <oscprob_key>=<oscprob_value>[,<oscprob_key>=<oscprob_value>]...
287 *
288 * oscprob.<oscprob_key>=<oscprob_value>[,oscprob.<oscprob_key>=<oscprob_value>]...
289 *
290 * oscprob=<oscprob_file>
291 *
292 * <oscprob_file>
293 * </pre>
294 * where
295 * - <oscprob_key> refers to an oscillation probability calculator configuration key;
296 * - <oscprob_value> to an oscillation probability calculator configuration value;
297 * - <oscprob_file> to an oscillation probability calculator configuration file with key-value pairs;
298 *
299 * \param in input stream
300 * \param object object
301 * \return input stream
302 */
303 friend inline std::istream& operator>>(std::istream& in, JOscProbHelper& object)
304 {
305 using namespace std;
306 using namespace JPP;
307
308 static const char* KEYWORD = "oscprob";
309
310 if (!object) { return in; }
311
312 // Attempt to read oscillation probability calculator configuration directly as key-value pairs
313
314 JProperties properties1 = object.getProperties();
315
316 streampos pos = in.tellg();
317
318 in >> properties1;
319
320 if (!fail(in)) { return in; }
321
322 // Attempt to read oscillation probability calculator configuration from input file specified by equation
323
324 in.clear();
325 in.seekg(pos);
326
327 JProperties properties2 = properties1;
328
329 JEquation equation;
330 in >> equation;
331
332 if (equation.getKey() == KEYWORD && getFileStatus(equation.getValue().c_str())) {
333
334 properties2 = properties1;
335
336 properties2.getEndOfLine() += '\n';
337
338 ifstream ifs(equation.getValue().c_str());
339
340 ifs >> properties2;
341
342 ifs.close();
343
344 return in;
345 }
346
347 // Attempt to read oscillation probability calculator configuration as key-value pairs with separator
348
349 in.clear();
350 in.seekg(pos);
351
352 properties2.clear();
353
354 properties2[KEYWORD] = properties1;
355
356 in >> properties2;
357
358 if (!fail(in)) { return in; }
359
360 // Attempt to read oscillation probability calculator configuration from input file
361
362 in.clear();
363 in.seekg(pos);
364
365 std::string buffer;
366 in >> buffer;
367
368 if (getFileStatus(buffer.c_str())) {
369
370 ifstream ifs(buffer.c_str());
371
372 ifs >> object;
373
374 ifs.close();
375
376 } else {
377
378 in.clear();
379 in.seekg(pos);
380 }
381
382 return in;
383 }
384
385
386 /**
387 * Write to output.
388 *
389 * \param out output stream
390 * \param object object
391 * \return output stream
392 */
393 friend inline std::ostream& operator<<(std::ostream& out, const JOscProbHelper& object)
394 {
395 if (object) {
396 out << object.getProperties();
397 }
398
399 return out;
400 }
401 };
402}
403
404#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Utility class to parse parameter values.
File status.
Utility class to parse parameter values.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
const std::string & getEndOfLine() const
Get end of line characters.
General purpose equation class.
Definition JEquation.hh:47
const std::string & getKey() const
Get key.
Definition JEquation.hh:163
const std::string & getValue() const
Get value.
Definition JEquation.hh:185
Exception for null pointer operation.
Parameter class.
Definition JParameter.hh:36
Interface class for sets of oscillation parameters.
void set(const std::string &name, const value_type &value)
Set value for a given oscillation parameter.
Low-level interface for oscillation probability calculators.
virtual double getP(const JOscChannel &channel, const double E, const double costh) const =0
Get oscillation probability for a given oscillation channel.
static JEquationParameters & getEquationParameters()
Get equation parameters.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
virtual clone_type clone() const override
Get clone of this object.
Definition JClonable.hh:69
virtual double getBaseline(const double costh) const =0
Get baseline for a given cosine zenith angle.
virtual double getCosth(const double L) const =0
Get cosine zenith angle for a given baseline.
Neutrino oscillation channel.
JOscParameters_t & getParameters() const
Get reference to oscillation parameters interface.
JOscParameters_t::argument_type argument_type
virtual JProperties getProperties(const JEquationParameters &equation=JOscParameters_t::getEquationParameters())
Get properties of this class.
Helper class for oscillation probability calculators.
void set(const std::string &name, const value_type &value) const
Set value for a given oscillation parameter.
void set(const JOscParameters_t &parameters) const
Set oscillation parameters.
double getP(const std::string &name, const double value, const Args &...args) const
Get oscillation probability for a given set of oscillation parameters and a given oscillation channel...
JOscParameterReferences_t & getParameters() const
Get reference to oscillation parameters interface.
JOscProbInterface & getOscProbInterface() const
Get reference to oscillation probability interface.
JOscProbInterface::JOscParameterReferences_t JOscParameterReferences_t
JOscProbInterface::JOscParameters_t JOscParameters_t
JOscProbHelper(const pointer_type &pOscProb)
Copy constructor.
JProperties getProperties(const JEquationParameters &eqpars=JOscProbInterface::getEquationParameters()) const
Get properties of this class.
JOscProbHelper(const JOscProbInterface &oscProb)
Constructor.
JOscProbInterface::value_type value_type
std::shared_ptr< JOscProbInterface > pointer_type
double getBaseline(const double costh) const
Get baseline for a given cosine zenith angle.
JProperties getProperties(const JEquationParameters &eqpars=JOscProbInterface::getEquationParameters())
Get properties of this class.
JOscProbHelper()
Default constructor.
friend std::istream & operator>>(std::istream &in, JOscProbHelper &object)
Read from input.
double getP(const JOscChannel &channel, const double energy, const double costh) const
Get oscillation probability corresponding to given oscillation channel, neutrino energy and zenith an...
double getP(const std::string &name, const double value, const JOscChannel &channel, const double E, const double costh) const
Get oscillation probability for a given oscillation parameter and a given oscillation channel.
JOscProbInterface::argument_type argument_type
double getP(const JOscParameters_t &parameters, const JOscChannel &channel, const double energy, const double costh) const
Get oscillation probability for a given set of oscillation parameters and a given oscillation channel...
void configure(const JOscProbInterface &oscProb)
Configure oscillation probability function.
void configure(const pointer_type &pOscProb)
Configure oscillation probability function.
void set(const std::string &name, const value_type &value, const Args &...args) const
Set value for given list of oscillation parameters.
JOscProbInterface::JParameter_t JParameter_t
double getCosth(const double L) const
Get cosine zenith angle for a given baseline.
friend std::ostream & operator<<(std::ostream &out, const JOscProbHelper &object)
Write to output.