Jpp 19.3.0-rc.5
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"
11
12#include "Jeep/JProperties.hh"
13
17
18
19/**
20 * \author bjung
21 */
22
23namespace JOSCPROB {}
24namespace JPP { using namespace JOSCPROB; }
25
26namespace JOSCPROB {
27
28 /**
29 * Helper class for oscillation probability calculators.
30 */
32 public std::shared_ptr<JOscProbInterface>
33 {
37
40
41 typedef std::shared_ptr<JOscProbInterface> pointer_type;
42
43
44 /**
45 * Default constructor.
46 */
49
50
51 /**
52 * Copy constructor.
53 *
54 * \param pOscProb shared pointer to oscillation probability function
55 */
56 JOscProbHelper(const pointer_type& pOscProb) :
57 pointer_type(pOscProb)
58 {}
59
60
61 /**
62 * Constructor.
63 *
64 * \param oscProb oscillation probability function
65 */
67 {
68 configure(oscProb);
69 }
70
71
72 /**
73 * Configure oscillation probability function.
74 *
75 * \param pOscProb shared pointer to oscillation probability function
76 */
77 void configure(const pointer_type& pOscProb)
78 {
79 static_cast<pointer_type&>(*this) = pOscProb;
80 }
81
82
83 /**
84 * Configure oscillation probability function.
85 *
86 * \param oscProb oscillation probability function
87 */
88 void configure(const JOscProbInterface& oscProb)
89 {
90 this->reset(oscProb.clone());
91 }
92
93
94 /**
95 * Get reference to oscillation probability interface.
96 *
97 * \return oscillation parameters
98 */
100 {
101 using namespace JPP;
102
103 if (static_cast<const JOscProbHelper&>(*this)) {
104 return *(this->get());
105 } else {
106 THROW(JNullPointerException, "JOscProbHelper::getOscProbInterface(): Oscillation probability interface is not set.");
107 }
108 }
109
110
111 /**
112 * Get reference to oscillation parameters interface.
113 *
114 * \return reference to oscillation parameters interface
115 */
120
121
122 /**
123 * Set oscillation parameters.
124 *
125 * \param parameters oscillation parameters
126 */
127 void set(const JOscParameters_t& parameters) const
128 {
129 return getParameters().set(parameters);
130 }
131
132
133 /**
134 * Set value for a given oscillation parameter.
135 *
136 * \param name parameter name
137 * \param value parameter value
138 */
139 void set(const std::string& name,
140 const value_type& value) const
141 {
142 getParameters().set(name, value);
143 }
144
145
146 /**
147 * Set value for given list of oscillation parameters.
148 *
149 * \param name parameter name
150 * \param value parameter value
151 * \param args remaining pairs of parameter names and values
152 */
153 template<class ...Args>
154 void set(const std::string& name,
155 const value_type& value,
156 const Args& ...args) const
157 {
158 getParameters().set(name, value, args...);
159 }
160
161
162 /**
163 * Get cosine zenith angle for a given baseline.
164 *
165 * \param L baseline [km]
166 * \return cosine zenith angle
167 */
168 double getCosth(const double L) const
169 {
170 return getOscProbInterface().getCosth(L);
171 }
172
173
174 /**
175 * Get baseline for a given cosine zenith angle.
176 *
177 * \param costh cosine zenith angle
178 * \return baseline [km]
179 */
180 double getBaseline(const double costh) const
181 {
182 return getOscProbInterface().getBaseline(costh);
183 }
184
185
186 /**
187 * Get oscillation probability corresponding to given oscillation channel,
188 * neutrino energy and zenith angle.
189 *
190 * \param channel oscillation channel
191 * \param energy neutrino energy [GeV]
192 * \param costh cosine zenith angle
193 * \return oscillation probability
194 */
195 double getP(const JOscChannel& channel,
196 const double energy,
197 const double costh) const
198 {
199 return getOscProbInterface().getP(channel, energy, costh);
200 }
201
202
203 /**
204 * Get oscillation probability for a given set of oscillation parameters\n
205 * and a given oscillation channel.
206 *
207 * \param channel oscillation channel
208 * \param parameters oscillation parameters
209 * \param energy neutrino energy [GeV]
210 * \param costh cosine zenith angle
211 * \return oscillation probability
212 */
213 double getP(const JOscParameters_t& parameters,
214 const JOscChannel& channel,
215 const double energy,
216 const double costh) const
217 {
218 return getOscProbInterface().getP(parameters, channel, energy, costh);
219 }
220
221
222 /**
223 * Get oscillation probability for a given oscillation parameter\n
224 * and a given oscillation channel.
225 *
226 * \param name parameter name
227 * \param value parameter value
228 * \param channel oscillation channel
229 * \param E neutrino energy [GeV]
230 * \param costh cosine zenith angle
231 * \return oscillation probability
232 */
233 double getP(const std::string& name,
234 const double value,
235 const JOscChannel& channel,
236 const double E,
237 const double costh) const
238 {
239 return getOscProbInterface().getP(name, value, channel, E, costh);
240 }
241
242
243 /**
244 * Get oscillation probability for a given set of oscillation parameters\n
245 * and a given oscillation channel.
246 *
247 * \param name parameter name
248 * \param value parameter value
249 * \param args remaining arguments
250 */
251 template<class ...Args>
252 double getP(const std::string& name,
253 const double value,
254 const Args& ...args) const
255 {
256 return getOscProbInterface().getP(name, value, args...);
257 }
258
259
260 /**
261 * Get properties of this class.
262 *
263 * \param eqpars equation parameters
264 */
269
270
271 /**
272 * Get properties of this class.
273 *
274 * \param eqpars equation parameters
275 */
280
281
282 /**
283 * Read from input.
284 *
285 * Input syntax according to one of the following options:
286 * 1. <tt><oscprob_file></tt>,
287 * 2. <tt>oscprob=<oscprob_file></tt>,
288 * 3. <tt><oscprob_key>=<oscprob_value>[<end of line> <oscprob_key>=<oscprob_value> ...]</tt> or
289 * 4. <tt>oscprob.<oscprob_key>=<oscprob_value>[<end of line> oscprob.<oscprob_key>=<oscprob_value> ...]</tt>,
290 * where:
291 * - <tt>oscprob_key</tt> refers to an oscillation probability calculator configuration key;
292 * - <tt>oscprob_value</tt> to an oscillation probability calculator configuration value;
293 * - <tt>oscprob_file</tt> to an oscillation probability calculator configuration file with key-value pairs.
294 *
295 * \param in input stream
296 * \param object object
297 * \return input stream
298 */
299 friend inline std::istream& operator>>(std::istream& in, JOscProbHelper& object)
300 {
301 using namespace std;
302 using namespace JPP;
303
304 static const char* KEYWORD = "oscprob";
305
306 if (!object) { return in; }
307
308 JStringStream is(in);
309
310 if (getFileStatus(is.str().c_str())) {
311 is.load();
312 }
313
314 const streampos pos = is.tellg();
315 const ios_base::iostate state = is.rdstate();
316
317 JProperties properties1 = object.getProperties();
318
320
321 is.imbue(locale(is.getloc(), facet.clone()));
322
323 JEquation equation;
324 is >> equation;
325
326 if (equation.getKey() == KEYWORD) {
327
328 if (getFileStatus(equation.getValue().c_str())) {
329
330 properties1.getEndOfLine() += '\n';
331
332 ifstream ifs(equation.getValue().c_str());
333
334 ifs >> properties1;
335
336 ifs.close();
337
338 } else {
339
340 is.clear(state);
341 is.seekg(pos);
342
343 JProperties properties2;
344
345 properties2[KEYWORD] = properties1;
346
347 is >> properties2;
348 }
349
350 } else if (!equation.getValue().empty()) {
351
352 is.clear(state);
353 is.seekg(pos);
354
355 is >> properties1;
356
357 } else {
358
359 is.setstate(ios::badbit);
360 }
361
362 return in;
363 }
364
365
366 /**
367 * Write to output.
368 *
369 * \param out output stream
370 * \param object object
371 * \return output stream
372 */
373 friend inline std::ostream& operator<<(std::ostream& out, const JOscProbHelper& object)
374 {
375 if (object) {
376 out << object.getProperties();
377 }
378
379 return out;
380 }
381 };
382}
383
384#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.
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 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
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
void load()
Load data from file with name corresponding to current contents.
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.