Jpp 21.0.0
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#include <filesystem>
6
7#include "JLang/JEquation.hh"
8#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 according to one of the following options:
285 * 1. <tt><oscprob_file></tt>,
286 * 2. <tt>oscprob=<oscprob_file></tt>,
287 * 3. <tt><oscprob_key>=<oscprob_value>[<end of line> <oscprob_key>=<oscprob_value> ...]</tt> or
288 * 4. <tt>oscprob.<oscprob_key>=<oscprob_value>[<end of line> oscprob.<oscprob_key>=<oscprob_value> ...]</tt>,
289 * where:
290 * - <tt>oscprob_key</tt> refers to an oscillation probability calculator configuration key;
291 * - <tt>oscprob_value</tt> to an oscillation probability calculator configuration value;
292 * - <tt>oscprob_file</tt> to an oscillation probability calculator configuration file with key-value pairs.
293 *
294 * \param in input stream
295 * \param object object
296 * \return input stream
297 */
298 friend inline std::istream& operator>>(std::istream& in, JOscProbHelper& object)
299 {
300 using namespace std;
301 using namespace JPP;
302
303 static const char* KEYWORD = "oscprob";
304
305 if (!object) { return in; }
306
307 JStringStream is(in);
308
309 const streampos pos = is.tellg();
310 const ios_base::iostate state = is.rdstate();
311
312 JProperties properties1 = object.getProperties();
313
315
316 is.imbue(locale(is.getloc(), facet.clone()));
317
318 JEquation equation;
319 is >> equation;
320
321 if (equation.getKey() == KEYWORD) {
322
323 error_code error;
324
325 if (filesystem::is_regular_file(equation.getValue(), error)) {
326
327 properties1.getEndOfLine() += '\n';
328
329 ifstream ifs(equation.getValue().c_str());
330
331 ifs >> properties1;
332
333 ifs.close();
334
335 } else {
336
337 is.clear(state);
338 is.seekg(pos);
339
340 JProperties properties2;
341
342 properties2[KEYWORD] = properties1;
343
344 is >> properties2;
345 }
346
347 } else if (!equation.getValue().empty()) {
348
349 is.clear(state);
350 is.seekg(pos);
351
352 is >> properties1;
353
354 } else {
355
356 is.setstate(ios::badbit);
357 }
358
359 return in;
360 }
361
362
363 /**
364 * Write to output.
365 *
366 * \param out output stream
367 * \param object object
368 * \return output stream
369 */
370 friend inline std::ostream& operator<<(std::ostream& out, const JOscProbHelper& object)
371 {
372 if (object) {
373 out << object.getProperties();
374 }
375
376 return out;
377 }
378 };
379}
380
381#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Utility class to parse parameter values.
Utility class to parse parameter values.
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
virtual JEquationFacet * clone() const override
Clone this facet.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
const string_type & 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
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
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.