Jpp  18.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightFactorMultiParticle.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTFACTORMULTIPARTICLE__
2 #define __JAANET__JEVTWEIGHTFACTORMULTIPARTICLE__
3 
4 #include <map>
5 
8 
9 #include "JLang/JClonable.hh"
10 #include "JLang/JPredicate.hh"
11 #include "JLang/JException.hh"
12 
13 #include "JAAnet/JHead.hh"
14 #include "JAAnet/JFlux.hh"
15 #include "JAAnet/JAAnetToolkit.hh"
18 
19 
20 /**
21  * \author bjung
22  */
23 
24 namespace JAANET {}
25 namespace JPP { using namespace JAANET; }
26 
27 namespace JAANET {
28 
29  using JLANG::JClonable;
30 
31 
32  /**
33  * Implementation of event-weight factor for multiple particle types.
34  *
35  * The first template argument corresponds to the type of event-weight factor class.
36  * This class must contain the method `getFactor(const Evt&)`.
37  * The second template argument refers to the helper-class to the event-weight factor
38  * of the type of the first template argument.
39  */
40  template<class JEvtWeightFactor_t>
42  public JClonable<JEvtWeightFactor_t, JEvtWeightFactorMultiParticle<JEvtWeightFactor_t> >,
43  public std::map<int, JEvtWeightFactorHelper<JEvtWeightFactor_t> >
44  {
47 
48 
49  /**
50  * Default constructor.
51  */
53  map_type()
54  {}
55 
56 
57  /**
58  * Constructor.
59  *
60  * The multi-particle flux function is created\n
61  * listing all the primaries in the JHead::flux vector field of the given header.
62  *
63  * \param header header
64  * \param factor factor
65  */
67  const JEvtWeightFactor_t& factor) :
68  map_type()
69  {
70  using namespace std;
71  using namespace JPP;
72 
73  if (!header.flux.empty()) {
74 
75  for (vector<JAANET::flux>::const_iterator i = header.flux.cbegin(); i != header.flux.cend(); ++i) {
76  insert(i->type, factor);
77  }
78 
79  } else {
80 
81  THROW(JValueOutOfRange, "JEvtWeightFactorMultiParticle::JEvtWeightFactorMultiParticle(): Empty flux header-field.");
82  }
83  }
84 
85 
86  /**
87  * Constructor.
88  *
89  * \param type particle PDG code
90  * \param factor event-weight factor
91  * \param args remaining pairs of PDG codes and event-weight factors
92  */
93  template<class ...Args>
95  const JEvtWeightFactor_t& factor,
96  const Args& ...args) :
97  map_type()
98  {
99  insert(type, factor, args...);
100  }
101 
102 
103  /**
104  * Insert pair of particle code and event-weight factor.
105  *
106  * \param type particle PDG code
107  * \param factor event-weight factor
108  */
109  void insert(const int type,
110  const JEvtWeightFactor_t& factor)
111  {
112  map_type::insert(std::make_pair(type, JEvtWeightFactorHelper_t(factor)));
113  }
114 
115 
116  /**
117  * Insert pairs of particle codes and event-weight factors.
118  *
119  * \param type particle PDG code
120  * \param factor event-weight factor
121  * \param args remaining pairs of PDG codes and event-weight factors
122  */
123  template<class ...Args>
124  void insert(const int type,
125  const JEvtWeightFactor_t& factor,
126  const Args& ...args)
127  {
128  insert(type, factor);
129  insert(args...);
130  }
131 
132 
133  /**
134  * Get weight factor of given event.
135  *
136  * \param evt event
137  * \return weight-factor for given event
138  */
139  virtual double getFactor(const Evt& evt) const override
140  {
141  using namespace std;
142  using namespace JPP;
143 
144  vector<Trk>::const_iterator primary = find_if(evt.mc_trks.cbegin(),
145  evt.mc_trks.cend(),
147 
148  if (primary != evt.mc_trks.cend()) {
149 
150  return this->at(primary->type).getFactor(evt);
151 
152  } else if (has_neutrino(evt)) {
153 
154  const Trk& neutrino = get_neutrino(evt);
155 
156  return this->at(neutrino.type).getFactor(evt);
157 
158  } else {
159 
160  THROW(JValueOutOfRange, "JEvtWeightFactorMultiParticle::getFactor(): No primary track found for event " << evt.id << ".");
161  }
162  }
163  };
164 
165 
166  /**
167  * Type-definition of multi-particle event-weight factor for fluxes.
168  */
170 }
171 
172 #endif
Exceptions.
void insert(const int type, const JEvtWeightFactor_t &factor)
Insert pair of particle code and event-weight factor.
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
JEvtWeightFactorMultiParticle(const int type, const JEvtWeightFactor_t &factor, const Args &...args)
Constructor.
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
virtual double getFactor(const Evt &evt) const override
Get weight factor of given event.
#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.
bool is_primary() const
Check if this is a primary particle.
Definition: Trk.hh:77
std::vector< JAANET::flux > flux
Definition: JHead.hh:1609
int type
Particle type.
Definition: JHead.hh:1204
Monte Carlo run header.
Definition: JHead.hh:1234
Implementation of event-weight factor for multiple particle types.
std::map< int, JEvtWeightFactorHelper_t > map_type
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Template class for object cloning.
Definition: JClonable.hh:20
Helper class for event-weight factor.
JEvtWeightFactorMultiParticle(const JHead &header, const JEvtWeightFactor_t &factor)
Constructor.
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
void insert(const int type, const JEvtWeightFactor_t &factor, const Args &...args)
Insert pairs of particle codes and event-weight factors.
JEvtWeightFactorHelper< JEvtWeightFactor_t > JEvtWeightFactorHelper_t
Primary particle.
Definition: JHead.hh:1174
int id
offline event identifier
Definition: Evt.hh:22
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:49
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20