Jpp  15.0.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 
15 #include "JAAnet/JAAnetToolkit.hh"
16 
17 /**
18  * \author bjung
19  */
20 
21 namespace JAANET {
22 
23  using JLANG::JClonable;
25 
26  /**
27  * Implementation of event-weight factor for multiple particle types.
28  */
30  public JClonable<JEvtWeightFactor, JEvtWeightFactorMultiParticle>,
31  public std::map<int, JEvtWeightFactorHelper>
32  {
34 
35  /**
36  * Default constructor.
37  */
39  map_type()
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param type particle PDG code
47  * \param factor event-weight factor
48  * \param args remaining pairs of PDG codes and event-weight factors
49  */
50  template<class ...Args>
52  const JEvtWeightFactor& factor,
53  const Args& ...args)
54  {
55  insert(type, factor, args...);
56  }
57 
58 
59  /**
60  * Insert pair of particle code and event-weight factor.
61  *
62  * \param type particle PDG code
63  * \param factor event-weight factor
64  */
65  void insert(const int type,
66  const JEvtWeightFactor& factor)
67  {
68  map_type::insert(std::make_pair(type, JEvtWeightFactorHelper(factor)));
69  }
70 
71 
72  /**
73  * Insert pairs of particle codes and event-weight factors.
74  *
75  * \param type particle PDG code
76  * \param factor event-weight factor
77  * \param args remaining pairs of PDG codes and event-weight factors
78  */
79  template<class ...Args>
80  void insert(const int type,
81  const JEvtWeightFactor& factor,
82  const Args& ...args)
83  {
84  insert(type, factor);
85  insert(args...);
86  }
87 
88 
89  /**
90  * Get event-weight factor of given event.
91  *
92  * \param evt event
93  * \return weight-factor for given event
94  */
95  double getFactor(const Evt& evt) const override
96  {
97  using namespace std;
98  using namespace JPP;
99 
100  vector<Trk>::const_iterator primary = find_if(evt.mc_trks.cbegin(),
101  evt.mc_trks.cend(),
103 
104  if (primary != evt.mc_trks.cend()) {
105 
106  return this->at(primary->type).getFactor(evt);
107 
108  } else if (has_neutrino(evt)) {
109 
110  const Trk& neutrino = get_neutrino(evt);
111 
112  return this->at(neutrino.type).getFactor(evt);
113 
114  } else {
115 
116  THROW(JValueOutOfRange, "JEvtWeightFactorMultiParticle::getFactor(): No primary track found for event " << evt.id << ".");
117  }
118  }
119  };
120 }
121 
122 #endif
Exceptions.
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
void insert(const int type, const JEvtWeightFactor &factor)
Insert pair of particle code and event-weight factor.
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
JEvtWeightFactorMultiParticle(const int type, const JEvtWeightFactor &factor, const Args &...args)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
bool is_primary() const
Check if this is a primary particle.
Definition: Trk.hh:76
void insert(const int type, const JEvtWeightFactor &factor, const Args &...args)
Insert pairs of particle codes and event-weight factors.
int type
Particle type.
Definition: JHead.hh:1083
Implementation of event-weight factor for multiple particle types.
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.
double getFactor(const Evt &evt) const override
Get event-weight factor of given event.
std::map< int, JEvtWeightFactorHelper > map_type
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
Primary particle.
Definition: JHead.hh:1053
int id
offline event identifier
Definition: Evt.hh:21
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
Low-level interface for retrieving a specifiable multiplication factor corresponding to a given event...
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:46
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19