Jpp  18.1.0
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 
9 
10 #include "JLang/JException.hh"
11 #include "JLang/JSharedPointer.hh"
12 
13 #include "Jeep/JProperties.hh"
14 
15 #include "JAAnet/JHead.hh"
16 #include "JAAnet/JHeadToolkit.hh"
17 
18 #include "JAAnet/JEvtWeight.hh"
19 #include "JAAnet/JEvtWeightDAQ.hh"
24 
25 #include "JAAnet/JFlatFlux.hh"
26 #include "JAAnet/JPowerLawFlux.hh"
29 #include "JAAnet/JParticleTypes.hh"
30 #include "JAAnet/JAAnetToolkit.hh"
31 
32 
33 /**
34  * \author bjung
35  */
36 
37 namespace JAANET {
38 
41 
42  using JEEP::JProperties;
43 
45 
46 
47  /**
48  * Look-up table for event weighters.
49  */
50  struct JEvtWeighter :
51  public std::vector< JSharedPointer<JEvtWeight> >
52  {
53  /**
54  * Constructor
55  */
57  {
58  this->push_back(new JEvtWeightGSeaGen());
59  this->push_back(new JEvtWeightKM3BUU());
60  this->push_back(new JEvtWeightCorsika());
61  this->push_back(new JEvtWeightMupage());
62  this->push_back(new JEvtWeightDAQ());
63  }
64 
65 
66  /**
67  * Get event weighter corresponding to given header.
68  *
69  * \param header header
70  * \return event weighter
71  */
72  const JEvtWeight& operator()(const JHead& header) const
73  {
74  for (const_iterator i = this->begin(); i != this->end(); ++i) {
75 
76  if ((*i)->check(header)) {
77 
78  return *(*i);
79  }
80  }
81 
82  THROW(JValueOutOfRange, "JEvtWeighter::operator(): No event weighter found for given header.");
83  }
84  };
85 
86 
87  /**
88  * Auxiliary class for parsing a vector of neutrino PDG identifiers.
89  */
91  std::vector<int>
92  {
93  /**
94  * Default constructor.
95  */
97  {}
98 
99 
100  /**
101  * Stream input.
102  *
103  * \param in input stream
104  * \param collection collection of neutrino PDG types
105  * \return input stream
106  */
107  friend inline std::istream& operator>>(std::istream& in, JNeutrinoTypeCollection& collection)
108  {
109  for (int type; in >> type; ) {
110 
111  if (abs(type) == TRACK_TYPE_NUE ||
112  abs(type) == TRACK_TYPE_NUMU ||
113  abs(type) == TRACK_TYPE_NUTAU) {
114 
115  collection.push_back(type);
116 
117  } else {
118 
119  THROW(JValueOutOfRange, "JNeutrinoTypeCollection::operator>>(): Invalid particle type: " << type);
120  }
121  }
122 
123  return in;
124  }
125 
126 
127  /**
128  * Stream output.
129  *
130  * \param out output stream
131  * \param collection collection of neutrino PDG types
132  * \return output stream
133  */
134  friend inline std::ostream& operator<<(std::ostream& out, const JNeutrinoTypeCollection& collection)
135  {
136  for (std::vector<int>::const_iterator i = collection.cbegin(); i != collection.cend(); ++i) {
137  out << ' ' << *i;
138  }
139 
140  return out;
141  }
142  };
143 
144 
145  /**
146  * Auxiliary class for parsing multiparticle fluxes.
147  */
148  struct JFluxMapParser :
149  public JProperties,
150  public JOscProbHelper
151  {
152  /**
153  * Constructor.
154  */
156  {
157  this->put("flat", flatFluxes);
158  this->put("powerlaw", powerLawFluxes);
159  this->put("atmospheric", atmosphericFluxes);
160  }
161 
162 
163  /**
164  * Get multiparticle flux function.
165  *
166  * \return multiparticle flux function
167  */
169  {
170  using namespace std;
171  using namespace JPP;
172 
173  JFluxMultiParticle multiFlux;
174 
175  for (map<int, JFlatFlux>::const_iterator i = flatFluxes.cbegin(); i != flatFluxes.cend(); ++i) {
176  multiFlux.insert(i->first, make_fluxFunction(i->second));
177  }
178 
180  multiFlux.insert(i->first, make_fluxFunction(i->second));
181  }
182 
183  if (is_valid()) {
184 
185  const JOscProb& oscProbInterface = *(this->get());
186 
187  const JAtmosphericNeutrinoFlux atmFlux(oscProbInterface);
188 
190 
191  for (vector<int>::const_iterator i = atmosphericFluxes.cbegin(); i != atmosphericFluxes.cend(); ++i) {
192  multiFlux.insert(*i, atmFluxFunction);
193  }
194  }
195 
196  return multiFlux;
197  }
198 
199 
200  /**
201  * Conversion operator.
202  *
203  * \return multiparticle flux function
204  */
205  operator JFluxMultiParticle() const
206  {
207  return getMultiParticleFlux();
208  }
209 
210 
211  /**
212  * Stream input.
213  *
214  * \param in input stream
215  * \param fluxMapParser flux map parser
216  * \return input stream
217  */
218  friend inline std::istream& operator>>(std::istream& in, JFluxMapParser& fluxMapParser)
219  {
220  using namespace std;
221  using namespace JPP;
222 
223  JStringStream is(in);
224 
225  if (getFileStatus(is.str().c_str())) {
226  is.load();
227  }
228 
229  is >> static_cast<JProperties&>(fluxMapParser);
230 
231  return in;
232  }
233 
234 
235  /**
236  * Stream output.
237  *
238  * \param out output stream
239  * \param fluxMapParser flux map parser
240  * \return output stream
241  */
242  friend inline std::ostream& operator<<(std::ostream& out, const JFluxMapParser& fluxMapParser)
243  {
244  return out << static_cast<const JProperties&>(fluxMapParser);
245  }
246 
247 
248  std::map<int, JFlatFlux> flatFluxes; //!< Uniform flux functions
249  std::map<int, JPowerLawFlux> powerLawFluxes; //!< Power-law flux functions
250 
251  JNeutrinoTypeCollection atmosphericFluxes; //!< Atmospheric neutrino flux functions
252  };
253 
254 
255  extern JEvtWeighter getEventWeighter; //!< Function object for mapping header to event weighter.
256 }
257 
258 #endif
JEvtWeighter getEventWeighter
Function object for mapping header to event weighter.
JNeutrinoTypeCollection()
Default constructor.
JFluxMultiParticle getMultiParticleFlux() const
Get multiparticle flux function.
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.
friend std::istream & operator>>(std::istream &in, JNeutrinoTypeCollection &collection)
Stream input.
Low-level interface for retrieving the oscillation probability corresponding to a given oscillation c...
Definition: JOscProb.hh:22
void put(const std::string &key, T &object)
Put object at given key.
Definition: JProperties.hh:650
friend std::ostream & operator<<(std::ostream &out, const JNeutrinoTypeCollection &collection)
Stream output.
friend std::ostream & operator<<(std::ostream &out, const JFluxMapParser &fluxMapParser)
Stream output.
#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:496
Implementation of event-weight factor interface.
Helper class for oscillation probabilities.
Auxiliary class for parsing a vector of neutrino PDG identifiers.
std::map< int, JFlatFlux > flatFluxes
Uniform flux functions.
JEvtWeightFactorFunction< JFunction_t, JFlux > make_fluxFunction(const JFunction_t &flux)
Auxiliary method for creating an interface to a flux function.
is
Definition: JDAQCHSM.chsm:167
bool is_valid() const
Check validity of pointer.
Utility class to parse parameter values.
The template JSharedPointer class can be used to share a pointer to an object.
Abstract base class for event weighing.
Definition: JEvtWeight.hh:25
Implementation of atmospheric neutrino flux using official KM3NeT atmospheric flux function...
Implementation of event-weight factor for multiple particle types.
Implementation of event weighting for GSeaGen data.
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Auxiliary class for parsing multiparticle fluxes.
Monte Carlo run header.
Definition: JHead.hh:1221
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
Implementation of event weighting for KM3BUU data.
Implementation of event weighing for MUPAGE data.
std::map< int, JPowerLawFlux > powerLawFluxes
Power-law flux functions.
Look-up table for event weighters.
JEvtWeighter()
Constructor.
JNeutrinoTypeCollection atmosphericFluxes
Atmospheric neutrino flux functions.
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:46
friend std::istream & operator>>(std::istream &in, JFluxMapParser &fluxMapParser)
Stream input.
const JEvtWeight & operator()(const JHead &header) const
Get event weighter corresponding to given header.