Jpp test-rotations-old
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 * Check whether this formula is valid.
66 *
67 * \return true if valid; else false
68 */
69 bool is_valid() const override final
70 {
71 const int N = this->GetNdim();
72
73 return N >= 0 && N <= (int) NUMBER_OF_VARIABLES;
74 }
75
76
77 /**
78 * Get weighting factor for given event.
79 *
80 * \param evt event
81 * \return weighting factor
82 */
83 double getFactor(const Evt& evt) const override final
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 THROW(JValueOutOfRange, "JEvtWeightFactorMupage::operator(): No muon for event " << evt.id << '.' << endl);
98 }
99
100 Double_t vars[NUMBER_OF_VARIABLES] = { 0.0 };
101
102 double Etot = 0.0;
103 JVector3D dir;
104
105 for (vector<JTrack3E>::const_iterator i = muons.begin(); i != muons.end(); ++i) {
106 Etot += i->getE();
107 dir += i->getDirection();
108 }
109
110 const JDirection3D D(dir);
111 const JRotation3D R(D);
112
113 for (vector<JTrack3E>::iterator i = muons.begin(); i != muons.end(); ++i) {
114 i->rotate(R);
115 }
116
117 vector<Trk>::const_iterator iBundle = find_if(evt.mc_trks.cbegin(), evt.mc_trks.cend(),
118 make_predicate(&Trk::status, TRK_ST_MUONBUNDLE));
119
120 vars[MUON_MULTIPLICITY] = (double) muons.size();
121 vars[TOTAL_MUON_ENERGY] = (iBundle != evt.mc_trks.cend() ? iBundle->E : Etot);
122 vars[MEAN_ZENITH_ANGLE] = D.getDZ();
123
124 if (this->GetNdim() > (int) LATERAL_SPREAD) {
125
126 const JCircle2D circle = JCircle2D(muons.cbegin(), muons.cend()); // smallest enclosing circle
127
128 vars[LATERAL_SPREAD] = circle.getRadius();
129 }
130
131 return this->EvalPar(&vars[0]);
132 }
133 };
134}
135
136#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.
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