Jpp  19.0.0
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 #include "JGeometry3D/JVector3D.hh"
13 #include "JGeometry3D/JTrack3E.hh"
14 
15 #include "JAAnet/JAAnetToolkit.hh"
16 
17 #pragma GCC diagnostic push
18 #pragma GCC diagnostic ignored "-Wall"
19 #include "TFormula.h"
20 #pragma GCC diagnostic pop
21 
22 
23 /**
24  * \author bjung
25  */
26 
27 namespace JAANET {}
28 namespace JPP { using namespace JAANET; }
29 
30 namespace JAANET {
31 
32  /**
33  * Implementation of reweighting factor for mupage events according to a specifiable ROOT TFormula.
34  *
35  * Note: The ROOT TFormula may assume any number of parameters, but should be restricted to\n
36  * the physical variables listed among `JEvtWeightFactorMupage::variables`.\n
37  * These variables may be specified within the ROOT TFormula as 'x[<index>]',\n
38  * where <index> corresponds to the index of the desired physical variable within `JEvtWeightFactorMupage::variables`.
39  */
41  public TFormula
42  {
43  /**
44  * Indices of reweighting variables for MUPAGE.
45  */
46  enum variables {
47  MUON_MULTIPLICITY, //!< Muon multiplicity
48  MEAN_ZENITH_ANGLE, //!< Average cosine of zenith angle
49  TOTAL_MUON_ENERGY, //!< Muon bundle total energy [GeV]
50  LATERAL_SPREAD, //!< Muon bundle lateral spread [m]
51 
52  NUMBER_OF_VARIABLES //!< Number of reweighting variables; \n
53  //!< N.B.\ This enum value needs to be specified last!
54  };
55 
56 
57  /**
58  * Default constructor.
59  */
61  TFormula()
62  {}
63 
64 
65  /**
66  * Constructor.
67  *
68  * \param name name
69  * \param formula formula
70  */
72  const char* formula) :
73  TFormula(name, formula)
74  {}
75 
76 
77  /**
78  * Get weighting factor for given event.
79  *
80  * \param evt event
81  * \return weighting factor
82  */
83  double operator()(const Evt& evt) const
84  {
85  using namespace std;
86  using namespace JPP;
87 
88  vector<JTrack3E> muons;
89 
90  for (vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
91  if (is_muon(*i) && is_finalstate(*i)) {
92  muons.push_back(getTrack(*i));
93  }
94  }
95 
96  if (!muons.empty()) {
97 
98  Double_t vars[NUMBER_OF_VARIABLES] = { 0.0 };
99 
100  double Etot = 0.0;
101  JVector3D dir;
102 
103  for (vector<JTrack3E>::const_iterator i = muons.begin(); i != muons.end(); ++i) {
104  Etot += i->getE();
105  dir += i->getDirection();
106  }
107 
108  const JDirection3D D(dir);
109  const JRotation3D R(D);
110 
111  for (vector<JTrack3E>::iterator i = muons.begin(); i != muons.end(); ++i) {
112  i->rotate(R);
113  }
114 
115  vector<Trk>::const_iterator iBundle = find_if(evt.mc_trks.cbegin(), evt.mc_trks.cend(),
117 
118  vars[MUON_MULTIPLICITY] = (iBundle != evt.mc_trks.cend() && iBundle->len > 0 ? iBundle->len : (double) muons.size());
119  vars[TOTAL_MUON_ENERGY] = (iBundle != evt.mc_trks.cend() ? iBundle->E : Etot);
120  vars[MEAN_ZENITH_ANGLE] = D.getDZ();
121 
122  if (this->GetNdim() > (int) LATERAL_SPREAD) {
123 
124  const JCircle2D circle = JCircle2D(muons.cbegin(), muons.cend()); // smallest enclosing circle
125 
126  vars[LATERAL_SPREAD] = circle.getRadius();
127  }
128 
129  return this->DoEval(&vars[0]);
130 
131  } else {
132 
133  THROW(JNullPointerException, "JEvtWeightFactorMupage::operator(): No muon for event " << evt.id << '.' << endl);
134  }
135  }
136  };
137 }
138 
139 #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
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
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:712
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.
JEvtWeightFactorMupage()
Default constructor.
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
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...
then fatal The output file must have the wildcard in the name
Definition: JCanberra.sh:31
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition: Trk.hh:28
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
int id
offline event identifier
Definition: Evt.hh:22
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:117
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