Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMultiParticleFlux.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JMULTIPARTICLEFLUX__
2 #define __JAANET__JMULTIPARTICLEFLUX__
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/JFlux.hh"
14 #include "JAAnet/JFluxHelper.hh"
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 flux function for multiple particle types.
28  */
30  public JClonable<JFlux, JMultiParticleFlux>,
31  public std::map<int, JFluxHelper>
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 flux flux function
48  * \param args remaining pairs of PDG codes and flux functions
49  */
50  template<class ...Args>
51  JMultiParticleFlux(const int type,
52  const JFlux& flux,
53  const Args& ...args)
54  {
55  insert(type, flux, args...);
56  }
57 
58 
59  /**
60  * Insert pair of particle code and flux function.
61  *
62  * \param type particle PDG code
63  * \param flux flux function
64  * \param args remaining pairs of PDG codes and flux functions
65  */
66  void insert(const int type,
67  const JFlux& flux)
68  {
69  map_type::insert(std::make_pair(type, JFluxHelper(flux)));
70  }
71 
72 
73  /**
74  * Insert pairs of particle codes and flux functions.
75  *
76  * \param type particle PDG code
77  * \param flux flux function
78  * \param args remaining pairs of PDG codes and flux functions
79  */
80  template<class ...Args>
81  void insert(const int type,
82  const JFlux& flux,
83  const Args& ...args)
84  {
85  insert(type, flux);
86  insert(args...);
87  }
88 
89 
90  /**
91  * Get flux of given event.
92  *
93  * \param evt event
94  * \return flux [GeV * m^-2 * sr^-1 * s^-1]
95  */
96  double getFlux(const Evt& evt) const override
97  {
98  using namespace std;
99  using namespace JPP;
100 
101  vector<Trk>::const_iterator primary = find_if(evt.mc_trks.cbegin(),
102  evt.mc_trks.cend(),
104 
105  if (primary != evt.mc_trks.cend()) {
106 
107  return this->at(primary->type).getFlux(evt);
108 
109  } else if (has_neutrino(evt)) {
110 
111  const Trk& neutrino = get_neutrino(evt);
112 
113  return this->at(neutrino.type).getFlux(evt);
114 
115  } else {
116 
117  THROW(JValueOutOfRange, "JMultiParticleFlux::getFlux(): No primary track found for event " << evt.id << ".");
118  }
119  }
120  };
121 }
122 
123 #endif
Implementation of flux function for multiple particle types.
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
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
JMultiParticleFlux(const int type, const JFlux &flux, const Args &...args)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
void insert(const int type, const JFlux &flux)
Insert pair of particle code and flux function.
bool is_primary() const
Check if this is a primary particle.
Definition: Trk.hh:75
double getFlux(const Evt &evt) const override
Get flux of given event.
void insert(const int type, const JFlux &flux, const Args &...args)
Insert pairs of particle codes and flux functions.
int type
Particle type.
Definition: JHead.hh:1083
Neutrino flux.
Definition: JHead.hh:839
Helper class for event weighing.
Definition: JFluxHelper.hh:23
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Template class for object cloning.
Definition: JClonable.hh:20
Low-level interface for retrieving flux corresponding to an event.
Definition: JFlux.hh:22
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:23
Primary particle.
Definition: JHead.hh:1053
JMultiParticleFlux()
Default constructor.
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.
std::map< int, JFluxHelper > map_type
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:13
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