Jpp  18.1.0
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 
26  using JLANG::JClonable;
28 
29  /**
30  * Implementation of event-weight factor for multiple particle types.
31  *
32  * The first template argument corresponds to the type of event-weight factor class.
33  * This class must contain the method `getFactor(const Evt&)`.
34  * The second template argument refers to the helper-class to the event-weight factor
35  * of the type of the first template argument.
36  */
37  template<class JEvtWeightFactor_t>
39  public JClonable<JEvtWeightFactor_t, JEvtWeightFactorMultiParticle<JEvtWeightFactor_t> >,
40  public std::map<int, JEvtWeightFactorHelper<JEvtWeightFactor_t> >
41  {
44 
45 
46  /**
47  * Default constructor.
48  */
50  map_type()
51  {}
52 
53 
54  /**
55  * Constructor.
56  *
57  * The multi-particle flux function is created\n
58  * listing all the primaries in the JHead::flux vector field of the given header.
59  *
60  * \param header header
61  * \param factor factor
62  */
64  const JEvtWeightFactor_t& factor) :
65  map_type()
66  {
67  if (!header.flux.empty()) {
68 
69  for (vector<JAANET::flux>::const_iterator i = header.flux.cbegin(); i != header.flux.cend(); ++i) {
70  insert(i->type, factor);
71  }
72 
73  } else {
74 
75  THROW(JValueOutOfRange, "JEvtWeightFactorMultiParticle::JEvtWeightFactorMultiParticle(): Empty flux header-field.");
76  }
77  }
78 
79 
80  /**
81  * Constructor.
82  *
83  * \param type particle PDG code
84  * \param factor event-weight factor
85  * \param args remaining pairs of PDG codes and event-weight factors
86  */
87  template<class ...Args>
89  const JEvtWeightFactor_t& factor,
90  const Args& ...args) :
91  map_type()
92  {
93  insert(type, factor, args...);
94  }
95 
96 
97  /**
98  * Insert pair of particle code and event-weight factor.
99  *
100  * \param type particle PDG code
101  * \param factor event-weight factor
102  */
103  void insert(const int type,
104  const JEvtWeightFactor_t& factor)
105  {
106  map_type::insert(std::make_pair(type, JEvtWeightFactorHelper_t(factor)));
107  }
108 
109 
110  /**
111  * Insert pairs of particle codes and event-weight factors.
112  *
113  * \param type particle PDG code
114  * \param factor event-weight factor
115  * \param args remaining pairs of PDG codes and event-weight factors
116  */
117  template<class ...Args>
118  void insert(const int type,
119  const JEvtWeightFactor_t& factor,
120  const Args& ...args)
121  {
122  insert(type, factor);
123  insert(args...);
124  }
125 
126 
127  /**
128  * Get weight factor of given event.
129  *
130  * \param evt event
131  * \return weight-factor for given event
132  */
133  virtual double getFactor(const Evt& evt) const override
134  {
135  using namespace std;
136  using namespace JPP;
137 
138  vector<Trk>::const_iterator primary = find_if(evt.mc_trks.cbegin(),
139  evt.mc_trks.cend(),
141 
142  if (primary != evt.mc_trks.cend()) {
143 
144  return this->at(primary->type).getFactor(evt);
145 
146  } else if (has_neutrino(evt)) {
147 
148  const Trk& neutrino = get_neutrino(evt);
149 
150  return this->at(neutrino.type).getFactor(evt);
151 
152  } else {
153 
154  THROW(JValueOutOfRange, "JEvtWeightFactorMultiParticle::getFactor(): No primary track found for event " << evt.id << ".");
155  }
156  }
157  };
158 
159 
160  /**
161  * Type-definition of multi-particle event-weight factor for fluxes.
162  */
164 }
165 
166 #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
std::vector< JAANET::flux > flux
Definition: JHead.hh:1594
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
int type
Particle type.
Definition: JHead.hh:1191
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.
Monte Carlo run header.
Definition: JHead.hh:1221
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:1161
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