Jpp  15.0.3
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 
10 
11 #include "TFormula.h"
12 
13 namespace {
14 
17 
18 
19  /**
20  * Example object for reweighting mupage events according to a specifiable ROOT TFormula.
21  *
22  * Note: The ROOT TFormula may assume any number of parameters, but should be restricted to\n
23  * the physical variables listed among `JEvtWeightFactorMupage::variables`.\n
24  * These variables may be specified within the ROOT TFormula as 'x[<index>]',\n
25  * where <index> corresponds to the index of the desired physical variable within `JEvtWeightFactorMupage::variables`.
26  */
27  struct JEvtWeightFactorMupage :
28  public TFormula
29  {
30  /**
31  * Indices of reweighting variables for MUPAGE.
32  */
33  enum variables {
34  MUON_MULTIPLICITY, //!< Muon multiplicity
35  MEAN_ZENITH_ANGLE, //!< Average cosine of zenith angle
36  TOTAL_MUON_ENERGY, //!< Muon bundle total energy [GeV]
37  LATERAL_SPREAD, //!< Muon bundle lateral spread [m]
38 
39  NUMBER_OF_VARIABLES //!< Number of reweighting variables; \n
40  //!< N.B.: This enum value needs to be specified last!
41  };
42 
43 
44  /**
45  * Default constructor.
46  */
47  JEvtWeightFactorMupage() :
48  TFormula()
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param name name
56  * \param formula formula
57  */
58  JEvtWeightFactorMupage(const char* name,
59  const char* formula) :
60  TFormula(name, formula)
61  {}
62 
63 
64  /**
65  * Get weighting factor for given event.
66  *
67  * \param evt event
68  * \return weighting factor
69  */
70  double operator()(const Evt& evt) const
71  {
72  using namespace std;
73  using namespace JPP;
74 
75  vector<JTrack3E> muons;
76 
77  vector<Double_t> vars(NUMBER_OF_VARIABLES);
78 
79  for (vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
80 
81  if (is_muon(*i)) {
82 
83  vars[MEAN_ZENITH_ANGLE] += i->dir.z / i->dir.len();
84  vars[TOTAL_MUON_ENERGY] += i->E;
85 
86  muons.push_back(getTrack(*i));
87  }
88  }
89 
90  if (muons.size() > 0) {
91 
92  vars[MUON_MULTIPLICITY] = (Double_t) muons.size();
93  vars[MEAN_ZENITH_ANGLE] /= vars[MUON_MULTIPLICITY];
94 
95  if (this->GetNdim() > (int) LATERAL_SPREAD) {
96 
97  JCircle2D circle = JCircle2D(muons.cbegin(), muons.cend()); // smallest enclosing circle
98  vars[LATERAL_SPREAD] = (Double_t) circle.getRadius();
99  }
100 
101  return this->DoEval(&vars[0]);
102 
103  } else {
104 
105  THROW(JNullPointerException, "JEvtWeightFactorMupage::operator(): No muon for event " << evt.id << '.' << endl);
106  }
107  }
108  };
109 }
110 
111 #endif
Exceptions.
JTrack3E getTrack(const Trk &track)
Get track.
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:696
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