Jpp  18.2.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 
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"
25 
26 #include "JAAnet/JFlatFlux.hh"
27 #include "JAAnet/JPowerLawFlux.hh"
30 #include "JAAnet/JParticleTypes.hh"
31 #include "JAAnet/JAAnetToolkit.hh"
32 
33 
34 /**
35  * \author bjung
36  */
37 
38 namespace JAANET {}
39 namespace JPP { using namespace JAANET; }
40 
41 namespace JAANET {
42 
43  /**
44  * Look-up table for event weighters.
45  */
46  struct JEvtWeighter :
47  public std::vector< JLANG::JSharedPointer<JEvtWeight> >
48  {
49  /**
50  * Constructor
51  */
53  {
54  this->push_back(new JEvtWeightGSeaGen());
55  this->push_back(new JEvtWeightKM3BUU());
56  this->push_back(new JEvtWeightCorsika());
57  this->push_back(new JEvtWeightMupage());
58  this->push_back(new JEvtWeightDAQ());
59  this->push_back(new JEvtWeightMiscellaneous());
60  }
61 
62 
63  /**
64  * Get event weighter corresponding to given header.
65  *
66  * \param header header
67  * \return event weighter
68  */
69  const JEvtWeight& operator()(const JHead& header) const
70  {
71  for (const_iterator i = this->begin(); i != this->end(); ++i) {
72 
73  if ((*i)->check(header)) {
74 
75  return *(*i);
76  }
77  }
78 
79  THROW(JValueOutOfRange, "JEvtWeighter::operator(): No event weighter found for given header.");
80  }
81  };
82 
83 
84  /**
85  * Auxiliary class for parsing a vector of neutrino PDG identifiers.
86  */
88  std::vector<int>
89  {
90  /**
91  * Default constructor.
92  */
94  {}
95 
96 
97  /**
98  * Stream input.
99  *
100  * \param in input stream
101  * \param collection collection of neutrino PDG types
102  * \return input stream
103  */
104  friend inline std::istream& operator>>(std::istream& in, JNeutrinoTypeCollection& collection)
105  {
106  for (int type; in >> type; ) {
107 
108  if (abs(type) == TRACK_TYPE_NUE ||
109  abs(type) == TRACK_TYPE_NUMU ||
110  abs(type) == TRACK_TYPE_NUTAU) {
111 
112  collection.push_back(type);
113 
114  } else {
115 
116  THROW(JValueOutOfRange, "JNeutrinoTypeCollection::operator>>(): Invalid particle type: " << type);
117  }
118  }
119 
120  return in;
121  }
122 
123 
124  /**
125  * Stream output.
126  *
127  * \param out output stream
128  * \param collection collection of neutrino PDG types
129  * \return output stream
130  */
131  friend inline std::ostream& operator<<(std::ostream& out, const JNeutrinoTypeCollection& collection)
132  {
133  for (std::vector<int>::const_iterator i = collection.cbegin(); i != collection.cend(); ++i) {
134  out << ' ' << *i;
135  }
136 
137  return out;
138  }
139  };
140 
141 
142  /**
143  * Auxiliary class for parsing multiparticle fluxes.
144  */
145  struct JFluxMapParser :
146  public JEEP::JProperties,
147  public JOscProbHelper
148  {
149  /**
150  * Constructor.
151  */
153  {
154  this->put("flat", flatFluxes);
155  this->put("powerlaw", powerLawFluxes);
156  this->put("atmospheric", atmosphericFluxes);
157  }
158 
159 
160  /**
161  * Get multiparticle flux function.
162  *
163  * \return multiparticle flux function
164  */
166  {
167  using namespace std;
168  using namespace JPP;
169 
170  JFluxMultiParticle multiFlux;
171 
172  for (map<int, JFlatFlux>::const_iterator i = flatFluxes.cbegin(); i != flatFluxes.cend(); ++i) {
173  multiFlux.insert(i->first, make_fluxFunction(i->second));
174  }
175 
177  multiFlux.insert(i->first, make_fluxFunction(i->second));
178  }
179 
180  if (is_valid()) {
181 
182  const JOscProb& oscProbInterface = *(this->get());
183 
184  const JAtmosphericNeutrinoFlux atmFlux(oscProbInterface);
185 
187 
188  for (vector<int>::const_iterator i = atmosphericFluxes.cbegin(); i != atmosphericFluxes.cend(); ++i) {
189  multiFlux.insert(*i, atmFluxFunction);
190  }
191  }
192 
193  return multiFlux;
194  }
195 
196 
197  /**
198  * Conversion operator.
199  *
200  * \return multiparticle flux function
201  */
202  operator JFluxMultiParticle() const
203  {
204  return getMultiParticleFlux();
205  }
206 
207 
208  /**
209  * Stream input.
210  *
211  * \param in input stream
212  * \param fluxMapParser flux map parser
213  * \return input stream
214  */
215  friend inline std::istream& operator>>(std::istream& in, JFluxMapParser& fluxMapParser)
216  {
217  using namespace std;
218  using namespace JPP;
219 
220  JStringStream is(in);
221 
222  if (getFileStatus(is.str().c_str())) {
223  is.load();
224  }
225 
226  is >> static_cast<JProperties&>(fluxMapParser);
227 
228  return in;
229  }
230 
231 
232  /**
233  * Stream output.
234  *
235  * \param out output stream
236  * \param fluxMapParser flux map parser
237  * \return output stream
238  */
239  friend inline std::ostream& operator<<(std::ostream& out, const JFluxMapParser& fluxMapParser)
240  {
241  return out << static_cast<const JProperties&>(fluxMapParser);
242  }
243 
244 
245  std::map<int, JFlatFlux> flatFluxes; //!< Uniform flux functions
246  std::map<int, JPowerLawFlux> powerLawFluxes; //!< Power-law flux functions
247 
248  JNeutrinoTypeCollection atmosphericFluxes; //!< Atmospheric neutrino flux functions
249  };
250 
251 
252  extern JEvtWeighter getEventWeighter; //!< Function object for mapping header to event weighter.
253 }
254 
255 #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:25
void put(const std::string &key, T &object)
Put object at given key.
Definition: JProperties.hh:651
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: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.
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.
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.
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.
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.