Jpp  15.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightFactorMupage.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTFACTORMUPAGE__
2 #define __JAANET__JEVTWEIGHTFACTORMUPAGE__
3 
6 
7 #include "JLang/JException.hh"
8 
9 #include "TFormula.h"
10 
11 namespace {
12 
15 
16 
17  /**
18  * Example object for reweighting mupage events according to a specifiable ROOT TFormula.
19  *
20  * Note: The ROOT TFormula may assume any number of parameters, but should be restricted to\n
21  * the physical variables listed among `JEvtWeightFactorMupageVariables`.\n
22  * These variables may be specified within the ROOT TFormula as 'x[<index>]',\n
23  * where <index> corresponds to the index of the desired physical variable within `JEvtWeightFactorMupageVariables`.
24  */
25  struct JEvtWeightFactorMupage :
26  public TFormula
27  {
28  /**
29  * Indices of reweighting variables for MUPAGE.
30  */
31  enum variables {
32  MUON_MULTIPLICITY, //!< Muon multiplicity
33  MEAN_ZENITH_ANGLE, //!< Average cosine of zenith angle
34  TOTAL_MUON_ENERGY, //!< Total muon energy [GeV]
35 
36  NUMBER_OF_VARIABLES //!< Number of reweighting variables; \n
37  //!< N.B.: This enum value needs to be specified last!
38  };
39 
40 
41  /**
42  * Default constructor.
43  */
44  JEvtWeightFactorMupage() :
45  TFormula()
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param name name
53  * \param formula formula
54  */
55  JEvtWeightFactorMupage(const char* name,
56  const char* formula) :
57  TFormula(name, formula)
58  {}
59 
60 
61  /**
62  * Get weighting factor for given event.
63  *
64  * \param evt event
65  * \return weighting factor
66  */
67  double operator()(const Evt& evt) const
68  {
69  using namespace std;
70  using namespace JPP;
71 
72  Double_t vars[NUMBER_OF_VARIABLES];
73 
74  for (vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
75 
76  if (is_muon(*i)) {
77 
78  vars[MUON_MULTIPLICITY] += 1;
79  vars[MEAN_ZENITH_ANGLE] += i->dir.z / i->dir.len();
80  vars[TOTAL_MUON_ENERGY] += i->E;
81  }
82  }
83 
84  if (vars[MUON_MULTIPLICITY] > 0) {
85 
86  vars[MEAN_ZENITH_ANGLE] /= vars[MUON_MULTIPLICITY];
87 
88  return this->DoEval(vars);
89 
90  } else {
91 
92  THROW(JNullPointerException, "JEvtWeightFactorMupage::operator(): No muon for event " << evt.id << '.' << endl);
93  }
94  }
95  };
96 }
97 
98 #endif
Exceptions.
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
Exception for null pointer operation.
Definition: JException.hh:216
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
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