Jpp  18.0.1-rc.1
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 #include "JLang/JPredicate.hh"
9 
10 #include "JGeometry2D/JCircle2D.hh"
11 
12 #include "TFormula.h"
13 
14 
15 /**
16  * \author bjung
17  */
18 
19 namespace JAANET {
20 
23 
24 
25  /**
26  * Implementation of reweighting factor for mupage events according to a specifiable ROOT TFormula.
27  *
28  * Note: The ROOT TFormula may assume any number of parameters, but should be restricted to\n
29  * the physical variables listed among `JEvtWeightFactorMupage::variables`.\n
30  * These variables may be specified within the ROOT TFormula as 'x[<index>]',\n
31  * where <index> corresponds to the index of the desired physical variable within `JEvtWeightFactorMupage::variables`.
32  */
34  public TFormula
35  {
36  /**
37  * Indices of reweighting variables for MUPAGE.
38  */
39  enum variables {
40  MUON_MULTIPLICITY, //!< Muon multiplicity
41  MEAN_ZENITH_ANGLE, //!< Average cosine of zenith angle
42  TOTAL_MUON_ENERGY, //!< Muon bundle total energy [GeV]
43  LATERAL_SPREAD, //!< Muon bundle lateral spread [m]
44 
45  NUMBER_OF_VARIABLES //!< Number of reweighting variables; \n
46  //!< N.B.\ This enum value needs to be specified last!
47  };
48 
49 
50  /**
51  * Default constructor.
52  */
54  TFormula()
55  {}
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param name name
62  * \param formula formula
63  */
65  const char* formula) :
66  TFormula(name, formula)
67  {}
68 
69 
70  /**
71  * Get weighting factor for given event.
72  *
73  * \param evt event
74  * \return weighting factor
75  */
76  double operator()(const Evt& evt) const
77  {
78  using namespace std;
79  using namespace JPP;
80 
81  static Double_t vars[NUMBER_OF_VARIABLES];
82 
83  // Compute average zenith-angle of final state muons and convert to JTrack3E
84 
85  double Etot = 0.0;
86 
87  vector<JTrack3E> muons;
88 
89  for (vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
90 
91  if (is_muon(*i) && is_finalstate(*i)) {
92 
93  Etot += i->E;
94 
95  vars[MEAN_ZENITH_ANGLE] += i->dir.z / i->dir.len();
96 
97  muons.push_back(getTrack(*i));
98  }
99  }
100 
101  vector<Trk>::const_iterator iBundle = find_if(evt.mc_trks.cbegin(), evt.mc_trks.cend(),
103 
104  vars[MUON_MULTIPLICITY] = (iBundle != evt.mc_trks.cend() && iBundle->len > 0 ?
105  iBundle->len : (Double_t) muons.size());
106 
107  vars[TOTAL_MUON_ENERGY] = (iBundle != evt.mc_trks.cend() ?
108  iBundle->E : Etot);
109 
110  vars[MEAN_ZENITH_ANGLE] /= (Double_t) muons.size();
111 
112  if (muons.size() > 0) {
113 
114  if (this->GetNdim() > (int) LATERAL_SPREAD) {
115 
116  JCircle2D circle = JCircle2D(muons.cbegin(), muons.cend()); // smallest enclosing circle
117  vars[LATERAL_SPREAD] = (Double_t) circle.getRadius();
118  }
119 
120  return this->DoEval(&vars[0]);
121 
122  } else {
123 
124  THROW(JNullPointerException, "JEvtWeightFactorMupage::operator(): No muon for event " << evt.id << '.' << endl);
125  }
126  }
127  };
128 }
129 
130 #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
JTrack3E getTrack(const Trk &track)
Get track.
JEvtWeightFactorMupage(const char *name, const char *formula)
Constructor.
variables
Indices of reweighting variables for MUPAGE.
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
Number of reweighting variables; N.B. This enum value needs to be specified last! ...
bool is_finalstate(const Trk &track)
Test whether given track corresponds to a final state particle.
Exception for null pointer operation.
Definition: JException.hh:216
JEvtWeightFactorMupage()
Default constructor.
static const int TRK_ST_MUONBUNDLE
initial state muon bundle (mupage)
Definition: trkmembers.hh:18
double operator()(const Evt &evt) const
Get weighting factor for given event.
Implementation of reweighting factor for mupage events according to a specifiable ROOT TFormula...
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition: Trk.hh:28
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:162
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