Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JEvtWeightFactorMupage.hh
Go to the documentation of this file.
1#ifndef __JAANET__JEVTWEIGHTFACTORMUPAGE__
2#define __JAANET__JEVTWEIGHTFACTORMUPAGE__
3
6
7#include "JLang/JClonable.hh"
8#include "JLang/JException.hh"
9#include "JLang/JPredicate.hh"
10
15
18
19
20/**
21 * \author bjung
22 */
23
24namespace JAANET {}
25namespace JPP { using namespace JAANET; }
26
27namespace JAANET {
28
29 using JLANG::JClonable;
30
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 JClonable<JEvtWeightFactorTFormula, JEvtWeightFactorMupage>
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 */
62
63
64 /**
65 * Constructor.
66 *
67 * \param name name
68 * \param formula formula
69 */
70 JEvtWeightFactorMupage(const char* const name,
71 const char* const formula)
72 {
73 getFormula().SetName(name);
74
75 compile(formula);
76 }
77
78
79 /**
80 * Check whether this formula is valid.
81 *
82 * \return true if valid; else false
83 */
84 bool is_valid() const override final
85 {
86 const int N = getFormula().GetNpar();
87
88 return N >= 0 && N <= (int) NUMBER_OF_VARIABLES;
89 }
90
91
92 /**
93 * Get weighting factor for given event.
94 *
95 * \param evt event
96 * \return weighting factor
97 */
98 double getFactor(const Evt& evt) const override final
99 {
100 using namespace std;
101 using namespace JPP;
102
103 vector<JTrack3E> muons;
104
105 for (vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
106 if (is_muon(*i) && is_finalstate(*i)) {
107 muons.push_back(getTrack(*i));
108 }
109 }
110
111 if (muons.empty()) {
112 THROW(JValueOutOfRange, "JEvtWeightFactorMupage::operator(): No muon for event " << evt.id << '.' << endl);
113 }
114
115 Double_t vars[NUMBER_OF_VARIABLES] = { 0.0 };
116
117 double Etot = 0.0;
118 JVector3D dir;
119
120 for (vector<JTrack3E>::const_iterator i = muons.begin(); i != muons.end(); ++i) {
121 Etot += i->getE();
122 dir += i->getDirection();
123 }
124
125 const JDirection3D D(dir);
126 const JRotation3D R(D);
127
128 for (vector<JTrack3E>::iterator i = muons.begin(); i != muons.end(); ++i) {
129 i->rotate(R);
130 }
131
132 vector<Trk>::const_iterator iBundle = find_if(evt.mc_trks.cbegin(), evt.mc_trks.cend(),
133 make_predicate(&Trk::status, TRK_ST_MUONBUNDLE));
134
135 vars[MUON_MULTIPLICITY] = (double) muons.size();
136 vars[TOTAL_MUON_ENERGY] = (iBundle != evt.mc_trks.cend() ? iBundle->E : Etot);
137 vars[MEAN_ZENITH_ANGLE] = D.getDZ();
138
139 if (this->GetNdim() > (int) LATERAL_SPREAD) {
140
141 const JCircle2D circle = JCircle2D(muons.cbegin(), muons.cend()); // smallest enclosing circle
142
143 vars[LATERAL_SPREAD] = circle.getRadius();
144 }
145
146 return getFormula().EvalPar(&vars[0]);
147 }
148 };
149}
150
151#endif
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Data structure for circle in two dimensions.
Definition JCircle2D.hh:35
double getRadius() const
Get radius.
Definition JCircle2D.hh:144
Data structure for direction in three dimensions.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
double getDZ() const
Get z direction.
Definition JVersor3D.hh:117
Exception for accessing a value in a collection that is outside of its range.
Extensions to Evt data format.
JTrack3E getTrack(const Trk &track)
Get track.
bool is_finalstate(const Trk &track)
Test whether given track corresponds to a final state particle.
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Implementation of reweighting factor for mupage events according to a specifiable ROOT TFormula.
JEvtWeightFactorMupage()
Default constructor.
double getFactor(const Evt &evt) const override final
Get weighting factor for given event.
JEvtWeightFactorMupage(const char *const name, const char *const formula)
Constructor.
variables
Indices of reweighting variables for MUPAGE.
@ TOTAL_MUON_ENERGY
Muon bundle total energy [GeV].
@ LATERAL_SPREAD
Muon bundle lateral spread [m].
@ MEAN_ZENITH_ANGLE
Average cosine of zenith angle.
@ NUMBER_OF_VARIABLES
Number of reweighting variables; N.B. This enum value needs to be specified last!
bool is_valid() const override final
Check whether this formula is valid.
Template class for object cloning.
Definition JClonable.hh:59
int status
MC status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition Trk.hh:28
static const int TRK_ST_MUONBUNDLE
initial state muon bundle (mupage)
Definition trkmembers.hh:18