Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightToolkit.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTTOOLKIT__
2 #define __JAANET__JEVTWEIGHTTOOLKIT__
3 
4 #include <map>
5 #include <vector>
6 #include <memory>
7 
10 
11 #include "JLang/JException.hh"
12 
13 #include "Jeep/JProperties.hh"
14 
16 
17 #include "JAAnet/JHead.hh"
18 #include "JAAnet/JHeadToolkit.hh"
19 
20 #include "JAAnet/JEvtWeight.hh"
21 #include "JAAnet/JEvtWeightDAQ.hh"
27 
28 #include "JAAnet/JFlatFlux.hh"
29 #include "JAAnet/JPowerLawFlux.hh"
32 #include "JAAnet/JParticleTypes.hh"
33 #include "JAAnet/JAAnetToolkit.hh"
34 
35 
36 /**
37  * \author bjung
38  */
39 
40 namespace JAANET {}
41 namespace JPP { using namespace JAANET; }
42 
43 namespace JAANET {
44 
45  using JEEP::JProperties;
46 
47 
48  /**
49  * Look-up table for event weighters.
50  */
51  struct JEvtWeighter :
52  public std::vector<std::shared_ptr<JEvtWeight> >
53  {
54  /**
55  * Constructor
56  */
58  {
59  this->emplace_back(new JEvtWeightGSeaGen());
60  this->emplace_back(new JEvtWeightKM3BUU());
61  this->emplace_back(new JEvtWeightCorsika());
62  this->emplace_back(new JEvtWeightMupage());
63  this->emplace_back(new JEvtWeightDAQ());
64  this->emplace_back(new JEvtWeightMiscellaneous());
65  }
66 
67 
68  /**
69  * Get event weighter corresponding to given header.
70  *
71  * \param header header
72  * \return event weighter
73  */
74  const JEvtWeight& operator()(const JHead& header) const
75  {
76  using namespace JPP;
77 
78  for (const_iterator i = this->begin(); i != this->end(); ++i) {
79 
80  if ((*i)->check(header)) {
81  return *(*i);
82  }
83  }
84 
85  THROW(JValueOutOfRange, "JEvtWeighter::operator(): No event weighter found for given header.");
86  }
87  };
88 
89 
90  /**
91  * Auxiliary class for parsing a vector of neutrino PDG identifiers.
92  */
94  {
95  /**
96  * Default constructor.
97  */
99  identifiers()
100  {}
101 
102 
103  /**
104  * Add identifier.
105  *
106  * \param identifier PDG identifier
107  */
108  void put(const int identifier)
109  {
110  if (abs(identifier) == TRACK_TYPE_NUE ||
111  abs(identifier) == TRACK_TYPE_NUMU ||
112  abs(identifier) == TRACK_TYPE_NUTAU) {
113 
114  identifiers.push_back(identifier);
115 
116  } else {
117 
118  THROW(JValueOutOfRange, "JNeutrinoTypeCollection::put(): Invalid PDG identifier: " << identifier);
119  }
120  }
121 
122 
123  /**
124  * Get size of this collection.
125  *
126  * \return size of neutrino type collection.
127  */
128  size_t size() const
129  {
130  return identifiers.size();
131  }
132 
133 
134  /**
135  * Get constant iterator to the first element of the collection.
136  *
137  * \return constant iterator to the first element of the collection
138  */
140  {
141  return identifiers.cbegin();
142  }
143 
144 
145  /**
146  * Get constant iterator to the last element of the collection.
147  *
148  * \return constant iterator to the last element of the collection
149  */
151  {
152  return identifiers.cend();
153  }
154 
155 
156  /**
157  * Stream input.
158  *
159  * \param in input stream
160  * \param collection collection of neutrino PDG types
161  * \return input stream
162  */
163  friend inline std::istream& operator>>(std::istream& in, JNeutrinoTypeCollection& collection)
164  {
165  for (int identifier; in >> identifier; ) {
166  collection.put(identifier);
167  }
168 
169  return in;
170  }
171 
172 
173  /**
174  * Stream output.
175  *
176  * \param out output stream
177  * \param collection collection of neutrino PDG types
178  * \return output stream
179  */
180  friend inline std::ostream& operator<<(std::ostream& out, const JNeutrinoTypeCollection& collection)
181  {
182  using namespace std;
183 
184  const vector<int>& identifiers = collection.identifiers;
185 
186  for (vector<int>::const_iterator i = identifiers.cbegin(); i != identifiers.cend(); ++i) {
187  out << ' ' << *i;
188  }
189 
190  return out;
191  }
192 
193 
194  private:
195 
196  std::vector<int> identifiers; //!< Container for identifiers
197  };
198 
199 
200  /**
201  * Auxiliary class for parsing multiparticle fluxes.
202  */
203  struct JFluxMap :
204  public JOscProbHelper
205  {
206  /**
207  * Default constructor.
208  */
210  {}
211 
212 
213  /**
214  * Get multiparticle flux function.
215  *
216  * \return multiparticle flux function
217  */
219  {
220  using namespace std;
221  using namespace JPP;
222 
223  JFluxMultiParticle multiFlux;
224 
225  for (map<int, JFlatFlux>::const_iterator i = flatFluxes.cbegin(); i != flatFluxes.cend(); ++i) {
226  multiFlux.insert(i->first, make_fluxFunction(i->second));
227  }
228 
229  for (map<int, JPowerLawFlux>::const_iterator i = powerLawFluxes.cbegin(); i != powerLawFluxes.cend(); ++i) {
230  multiFlux.insert(i->first, make_fluxFunction(i->second));
231  }
232 
233  const JOscProbInterface& oscProbInterface = getOscProbInterface();
234 
235  const JAtmosphericNeutrinoFlux atmFlux(oscProbInterface);
236 
238 
239  for (vector<int>::const_iterator i = atmosphericFluxes.cbegin(); i != atmosphericFluxes.cend(); ++i) {
240  multiFlux.insert(*i, atmFluxFunction);
241  }
242 
243  return multiFlux;
244  }
245 
246 
247  /**
248  * Conversion operator.
249  *
250  * \return multiparticle flux function
251  */
252  operator JFluxMultiParticle() const
253  {
254  return getMultiParticleFlux();
255  }
256 
257 
258  /**
259  * Stream input.
260  *
261  * \param in input stream
262  * \param fluxMap flux map
263  * \return input stream
264  */
265  friend inline std::istream& operator>>(std::istream& in, JFluxMap& fluxMap)
266  {
267  return getProperties(fluxMap).read(in);
268  }
269 
270 
271  /**
272  * Stream output.
273  *
274  * \param out output stream
275  * \param fluxMap flux map
276  * \return output stream
277  */
278  friend inline std::ostream& operator<<(std::ostream& out, const JFluxMap& fluxMap)
279  {
280  return getProperties(fluxMap).write(out);
281  }
282 
283 
284  std::map<int, JFlatFlux> flatFluxes; //!< Uniform flux functions
285  std::map<int, JPowerLawFlux> powerLawFluxes; //!< Power-law flux functions
286 
287  JNeutrinoTypeCollection atmosphericFluxes; //!< Atmospheric neutrino flux functions
288 
289  private:
290  /**
291  * Get properties of this class.
292  *
293  * \param object flux map object
294  * \return properties
295  */
296  template<class JFluxMap_t>
297  static inline JProperties getProperties(JFluxMap_t& object)
298  {
299  JProperties properties;
300 
301  properties.insert(gmake_property(object.flatFluxes));
302  properties.insert(gmake_property(object.powerLawFluxes));
303  properties.insert(gmake_property(object.atmosphericFluxes));
304 
305  return properties;
306  }
307  };
308 
309 
310  extern JEvtWeighter getEventWeighter; //!< Function object for mapping header to event weighter.
311 }
312 
313 #endif
friend std::istream & operator>>(std::istream &in, JFluxMap &fluxMap)
Stream input.
static JProperties getProperties(JFluxMap_t &object)
Get properties of this class.
JEvtWeighter getEventWeighter
Function object for mapping header to event weighter.
JNeutrinoTypeCollection()
Default constructor.
bool read(const JEquation &equation)
Read equation.
Definition: JProperties.hh:679
Exceptions.
void insert(const int type, const JEvtWeightFactor_t &factor)
Insert pair of particle code and event-weight factor.
Implementation of event weighing for DAQ data.
JFluxMap()
Default constructor.
friend std::istream & operator>>(std::istream &in, JNeutrinoTypeCollection &collection)
Stream input.
std::vector< int >::const_iterator cbegin() const noexcept
Get constant iterator to the first element of the collection.
JFluxMultiParticle getMultiParticleFlux() const
Get multiparticle flux function.
JProperties & getProperties(T &object, const JEquationParameters &parameters=JEquationParameters(), const int debug=1)
Get properties of a given object.
std::vector< int > identifiers
Container for identifiers.
friend std::ostream & operator<<(std::ostream &out, const JNeutrinoTypeCollection &collection)
Stream output.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Low-level interface for oscillation probability calculators.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
JEvtWeightFactorMultiParticle< JFlux > JFluxMultiParticle
Type-definition of multi-particle event-weight factor for fluxes.
Utility class to parse parameter values.
Definition: JProperties.hh:497
Implementation of event-weight factor interface.
Helper class for oscillation probabilities.
Implementation of event weighing for miscellaneous data such as a merged offline file containing neut...
Auxiliary class for parsing a vector of neutrino PDG identifiers.
JEvtWeightFactorFunction< JFunction_t, JFlux > make_fluxFunction(const JFunction_t &flux)
Auxiliary method for creating an interface to a flux function.
std::map< int, JPowerLawFlux > powerLawFluxes
Power-law flux functions.
std::vector< int >::const_iterator cend() const noexcept
Get constant iterator to the last element of the collection.
Utility class to parse parameter values.
std::ostream & write(std::ostream &out) const
Write the current parameter values.
Definition: JProperties.hh:847
Abstract base class for event weighing.
Definition: JEvtWeight.hh:28
Monte Carlo run header.
Definition: JHead.hh:1234
Implementation of atmospheric neutrino flux using official KM3NeT atmospheric flux function...
Implementation of event-weight factor for multiple particle types.
friend std::ostream & operator<<(std::ostream &out, const JFluxMap &fluxMap)
Stream output.
Implementation of event weighting for GSeaGen data.
size_t size() const
Get size of this collection.
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Auxiliary class for parsing multiparticle fluxes.
JNeutrinoTypeCollection atmosphericFluxes
Atmospheric neutrino flux functions.
Implementation of event weighting for KM3BUU data.
std::map< int, JFlatFlux > flatFluxes
Uniform flux functions.
Implementation of event weighing for MUPAGE data.
Look-up table for event weighters.
JEvtWeighter()
Constructor.
Definition of particle types.
Implementation of event weighting for Corsika data.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
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
void put(const int identifier)
Add identifier.
const JEvtWeight & operator()(const JHead &header) const
Get event weighter corresponding to given header.