Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JEvtWeightFactorProduct.hh
Go to the documentation of this file.
1#ifndef __JAANET__JEVTWEIGHTFACTORPRODUCT__
2#define __JAANET__JEVTWEIGHTFACTORPRODUCT__
3
4#include <vector>
5
7
8#include "JSystem/JStat.hh"
9
10#include "JLang/JToken.hh"
11#include "JLang/JClonable.hh"
13
14#include "Jeep/JPrint.hh"
15#include "Jeep/JProperties.hh"
16
18
20#include "JAAnet/JEvtWeightFactorDictionary.hh"
21
22
23/**
24 * \author bjung
25 */
26
27namespace JAANET {}
28namespace JPP { using namespace JAANET; }
29
30namespace JAANET {
31
32 using JLANG::JClonable;
33
35
37
38
39 /**
40 * Class for product of event-weight factors.
41 *
42 * Input syntax as follows:
43 * <pre>
44 * <factor identifier> [<factor arguments> [& <factor identifier> [<factor arguments]]...];
45 * </pre>
46 * where
47 * - <factor identifier> corresponds to an event-weight factor identifier (c.f. `JAANET::JEvtWeighFactorDictionary::factors`); and
48 * - <factor arguments> to the list of arguments for the corresponding event-weight fact
49 *
50 */
52 public std::vector<JEvtWeightFactorHelper>,
53 public JClonable<JEvtWeightFactor, JEvtWeightFactorProduct>
54 {
55 /**
56 * Default constructor.
57 */
61
62
63 /**
64 * Constructor.
65 *
66 * \param oscProb oscillation probability calculator
67 */
71
72
73 /**
74 * Constructor.
75 *
76 * \param oscProb oscillation probability calculator
77 * \param factor event-weight factor
78 */
80 const JEvtWeightFactorHelper& factor) :
82 {
83 this->push_back(factor);
84 }
85
86
87 /**
88 * Constructor.
89 *
90 * \param oscProb oscillation probability calculator
91 * \param factor event-weight factor
92 * \param args remaining event-weight factors
93 */
94 template<class ...Args>
96 const JEvtWeightFactorHelper& factor,
97 const Args& ...args) :
99 {
100 this->push_back(factor, args...);
101 }
102
103
104
105 /**
106 * Constructor.
107 *
108 * \param factor event-weight factor
109 */
111 oscProb()
112 {
113 this->push_back(factor);
114 }
115
116
117 /**
118 * Constructor.
119 *
120 * \param factor event-weight factor
121 * \param args remaining event-weight factors
122 */
123 template<class ...Args>
125 const Args& ...args) :
126 oscProb()
127 {
128 this->push_back(factor, args...);
129 }
130
131
132 /**
133 * Put event-weight factor.
134 *
135 * \param factor event-weight factor
136 */
138 {
139 const JEvtWeightFactorProduct* p = dynamic_cast<const JEvtWeightFactorProduct*>(factor.get());
140
141 if (p != NULL) {
142 this->insert(this->end(), p->begin(), p->end());
143 } else {
145 }
146 }
147
148
149 /**
150 * Put event-weight factor.
151 *
152 * \param factor event-weight factor
153 * \param args remaining event-weight factors
154 */
155 template<class ...Args>
157 const Args& ...args)
158 {
159 push_back(factor);
160 push_back(args...);
161 }
162
163
164 /**
165 * Join this product of event-weight factors with a given product of event-weight factors.
166 *
167 * \param product product of event-weight factors
168 * \return joined product of event-weight factors
169 */
171 {
172 this->insert(this->end(), product.begin(), product.end());
173
174 return (*this);
175 }
176
177
178 /**
179 * Get multiplication factor of given event.
180 *
181 * \param evt event
182 * \return multiplication factor
183 */
184 double getFactor(const Evt& evt) const override final
185 {
186 using namespace std;
187
188 double factor = 1.0;
189
190 for (vector<JEvtWeightFactorHelper>::const_iterator i = this->cbegin(); i != this->cend(); ++i) {
191 factor *= i->getFactor(evt);
192 }
193
194 return factor;
195 }
196
197
198 /**
199 * Check whether this event-weight factor is valid.
200 *
201 * \return true if valid; else false
202 */
203 bool is_valid() const override final
204 {
205 for (const_iterator i = this->cbegin(); i != this->cend(); ++i) {
206 if (!(i->is_valid())) { return false; }
207 }
208
209 return true;
210 }
211
212
213 /**
214 * Get properties of this class.
215 *
216 * \param eqpars equation parameters
217 */
219 {
220 return JEvtWeightFactorProductHelper(*this, eqpars);
221 }
222
223
224 /**
225 * Get properties of this class.
226 *
227 * \param eqpars equation parameters
228 */
230 {
231 return JEvtWeightFactorProductHelper(*this, eqpars);
232 }
233
234
235
236 /**
237 * Read event-weight factor product from stream.
238 *
239 * \param in input stream
240 * \param object event-weight factor product
241 * \return input stream
242 */
243 std::istream& read(std::istream& in) override final
244 {
245 using namespace std;
246 using namespace JPP;
247
248 static const JEvtWeightFactorDictionary dictionary(oscProb);
249
250 JStringStream is(in);
251
252 if (getFileStatus(is.str().c_str())) {
253 is.load();
254 }
255
256 for (JToken<'&'> token; is >> token; ) {
257
258 int factorID = 0;
259
260 istringstream iss(token);
261
262 if (!(iss >> factorID)) { continue; }
263
264 const JEvtWeightFactorHelper helper(dictionary.at(factorID).getFactor());
265
266 JEvtWeightFactor& factor = helper.getFactor();
267
268 iss >> factor;
269
270 push_back(helper);
271 }
272
273 return in;
274 }
275
276
277 /**
278 * Write event-weight factor to output
279 *
280 * \param out output stream
281 * \return output stream
282 */
283 std::ostream& write(std::ostream& out) const override final
284 {
285 return out << getProperties(JEquationParameters("=", "\n", "./", "#"));
286 }
287
288
289 JOscProbHelper oscProb; //!< Oscillation probability calculator
290
291
292 private:
293
294 /**
295 * Auxiliary class for I/O of product of event-weight factors.
296 */
298 public JProperties
299 {
300 /**
301 * Constructor.
302 *
303 * \param product product of event-weight factors
304 * \param eqpars equation parameters
305 */
306 template<class JEvtWeightFactorProduct_t>
307 JEvtWeightFactorProductHelper(JEvtWeightFactorProduct_t& product,
308 const JEquationParameters& eqpars) :
309 JProperties(eqpars, 1)
310 {
311 using namespace std;
312 using namespace JPP;
313
314 (*this)[JEvtWeightFactor::getTypeKey()] = "product";
315
316 JProperties factors(eqpars, 1);
317
318 for (typename JEvtWeightFactorProduct_t::const_iterator i = product.cbegin(); i != product.cend(); ++i) {
319
320 const int index = 1 + distance(product.cbegin(), i);
321
322 const string key = MAKE_STRING("factor" << index);
323
324 JProperties sub = i->getProperties(eqpars);
325
326 (*this)[key] = sub;
327 }
328 }
329 };
330 };
331}
332
333#endif
I/O formatting auxiliaries.
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
Utility class to parse parameter values.
File status.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Utility class to parse parameter values.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
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.
Wrapper class around string.
Definition JToken.hh:26
Extensions to Evt data format.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Helper class for event-weight factor.
JEvtWeightFactor & getFactor() const
Get reference to event-weight factor.
Auxiliary class for I/O of product of event-weight factors.
JEvtWeightFactorProductHelper(JEvtWeightFactorProduct_t &product, const JEquationParameters &eqpars)
Constructor.
Class for product of event-weight factors.
void push_back(const JEvtWeightFactorHelper &factor)
Put event-weight factor.
std::istream & read(std::istream &in) override final
Read event-weight factor product from stream.
JEvtWeightFactorProduct(const JOscProbHelper &oscProb, const JEvtWeightFactorHelper &factor, const Args &...args)
Constructor.
JEvtWeightFactorProduct(const JEvtWeightFactorHelper &factor)
Constructor.
JEvtWeightFactorProduct(const JOscProbHelper &oscProb)
Constructor.
bool is_valid() const override final
Check whether this event-weight factor is valid.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) const override final
Get properties of this class.
JEvtWeightFactorProduct(const JOscProbHelper &oscProb, const JEvtWeightFactorHelper &factor)
Constructor.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) override final
Get properties of this class.
JOscProbHelper oscProb
Oscillation probability calculator.
double getFactor(const Evt &evt) const override final
Get multiplication factor of given event.
JEvtWeightFactorProduct(const JEvtWeightFactorHelper &factor, const Args &...args)
Constructor.
void push_back(const JEvtWeightFactorHelper &factor, const Args &...args)
Put event-weight factor.
JEvtWeightFactorProduct & join(const JEvtWeightFactorProduct &product)
Join this product of event-weight factors with a given product of event-weight factors.
std::ostream & write(std::ostream &out) const override final
Write event-weight factor to output.
Abstract base class for specifiable event-weight factors.
static const char *const getTypeKey()
Get type keyword.
static JEquationParameters & getEquationParameters()
Get equation parameters.
Template class for object cloning.
Definition JClonable.hh:59
Helper class for oscillation probabilities.