Jpp 20.0.0-72-g597b30bc9
the software that should make you happy
Loading...
Searching...
No Matches
JEffectiveMassOffline.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3
4#include "TROOT.h"
5#include "TFile.h"
6#include "TH1D.h"
7
11
12#include "JAAnet/JVolume.hh"
15
16#include "JSupport/JSupport.hh"
19
21
22#include "JROOT/JManager.hh"
23
25
27
28#include "Jeep/JParser.hh"
29#include "Jeep/JMessage.hh"
30
31
32namespace {
33}
34
35
36namespace {
37
38 const char* const Mass_t = "Mass"; //!< Effective mass option
39 const char* const Volume_t = "Volume"; //!< Effecitve volume option
40
41
42 /**
43 * Retrieve weight normalisation from given header.
44 *
45 * \param header header
46 */
47 double getWnorm(const JAANET::JHead& header)
48 {
49 using namespace JPP;
50
51 if (!header.is_valid(&JHead::genvol)) {
52 THROW(JNoValue, "getWnorm(): Mising normalisation in header.");
53 }
54
55 double Wnorm = header.genvol.numberOfEvents;
56
57 if (header.is_valid(&JHead::cut_nu))
58 Wnorm *= 2*PI * (header.cut_nu.cosT.getUpperLimit() - header.cut_nu.cosT.getLowerLimit());
59 else
60 Wnorm *= 4*PI;
61
62 return Wnorm;
63 }
64}
65
66/**
67 * \file
68 *
69 * Example program to histogram neutrino effective mass for triggered events for offline reconstruction files, using the event weights only.\n
70 * The unit of the contents of the histogram is \f$Mton\f$ or \f$km^{3}\f$. It produces histograms based on true neutrino energy (hm0),
71 * total visible energy (hm1), leptonic visible energy (hm2) and hadronic visible energy (hm3).
72 * \author bjung, mdejong
73 */
74int main(int argc, char **argv)
75{
76 using namespace std;
77 using namespace JPP;
78 using namespace KM3NETDAQ;
79
80 typedef JAbstractHistogram<double> JAbstractHistogram_t;
81
82
83 JMultipleFileScanner_t inputFiles;
84 string outputFile;
85
86 JAbstractHistogram_t X;
87 bool logx;
88 double margin;
89 double epsilon;
90 JCylinder3D cylinder;
91
92 std::string option;
93
94 JDAQTriggerMask trigger_mask;
95
96 int debug;
97
98
99 try {
100
101 JParser<> zap("Example program to histogram neutrino effective mass for triggered events using offline files.");
102
103 zap['f'] = make_field(inputFiles);
104 zap['o'] = make_field(outputFile) = "Meff.root";
105 zap['x'] = make_field(X, "Histogram binning")
106 = JAbstractHistogram_t(100, 1.0, 100.0);
107 zap['X'] = make_field(logx, "Use logarithm of energy");
108 zap['C'] = make_field(cylinder, "Cylinder to compute visible energy depositions")
110 zap['m'] = make_field(margin, "Extra margin to consider visible energy depositions")
111 = 0.0;
112 zap['e'] = make_field(epsilon, "Minimal amount of visible energy assigned to events") = 1e-8;
113 zap['O'] = make_field(option, "Result option")
114 = Mass_t, Volume_t;
115 zap['T'] = make_field(trigger_mask, "Trigger mask")
117 zap['d'] = make_field(debug) = 2;
118
119 zap(argc, argv);
120 }
121 catch(const exception &error) {
122 FATAL(error.what() << endl);
123 }
124
125
126 const JEvtWeightFileScannerSet<> scanners(inputFiles);
127
128 const JMultiHead multiheader = getMultiHeader(inputFiles);
129
130 const double Xmin = X.getLowerLimit();
131 const double Xmax = X.getUpperLimit();
132 const int Xnbins = X.getNumberOfBins();
133
134 JManager<int, TH1D> hm0(new TH1D("hm0[%]", option.c_str(), Xnbins, Xmin, Xmax));
135 JManager<int, TH1D> hm1(new TH1D("hm1[%]", option.c_str(), Xnbins, Xmin, Xmax));
136 JManager<int, TH1D> hm2(new TH1D("hm2[%]", option.c_str(), Xnbins, Xmin, Xmax));
137 JManager<int, TH1D> hm3(new TH1D("hm3[%]", option.c_str(), Xnbins, Xmin, Xmax));
138
139 for (JEvtWeightFileScannerSet<>::const_iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
140
141 JHead header = scanner->getHeader();
142
143 JEvtWeightHelper weighter(scanner->getEvtWeighter());
144
145 NOTICE("Scanning file type " << scanner->getName() << endl);
146 DEBUG (header << endl);
147
148 for (JMultipleFileScanner<Evt> in(scanner->getFilelist()); in.hasNext(); ) {
149
150 STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
151
152 Evt* event = in.next();
153 const Trk& primary = get_primary(*event);
154
155
156 if (trigger_mask.hasTriggerMask(event->trigger_mask)) {
157 for (vector<Trk>::iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
158 track->clearusr(); // Prevent visible energy from being calculated based on `mc_usr_keys::energy_lost_in_can`
159 }
160 double Wnorm = 0.0;
161
162 if (header.is_valid(&JHead::genvol)) {
163
164 Wnorm = getWnorm(header);
165
166 } else if (uuid_is_null(event->header_uuid) == 0) {
167
168 const JUUID mergedUUID = multiheader.getHeaderUUID(*event);
169
170 MultiHead::const_iterator i = multiheader.find(mergedUUID.uuid, true);
171
172 if (i == multiheader.cend()) {
173 FATAL("Could not find header corresponding to UUID: " << JUUID(event->header_uuid) << endl);
174 }
175
176 const JHead header1(*i);
177 DEBUG(header1 << endl);
178
179 Wnorm = getWnorm(header1);
180
181 weighter.configure(getEventWeighter(header1));
182
183 } else {
184
185 FATAL("Mising normalisation in event/header." << endl);
186 }
187
188 JCylinder3D can = cylinder;
189
190 if (can.getVolume() == 0.0) {
191 can = getCylinder(header);
192 }
193
194 can.addMargin(margin);
195
196 double Evis = getVisibleEnergy(*event, can);
197 double EvisLL = (has_leading_lepton(*event) ?
199 0.0);
200 double EvisHad = Evis - EvisLL;
201
202 if (Evis == 0) Evis = epsilon;
203 if (EvisLL == 0) EvisLL = epsilon;
204 if (EvisHad == 0) EvisHad = epsilon;
205
206 const double x0 = logx ? log10(primary.E) : primary.E;
207 const double x1 = logx ? log10(Evis) : Evis;
208 const double x2 = logx ? log10(EvisLL) : EvisLL;
209 const double x3 = logx ? log10(EvisHad) : EvisHad;
210
211 double y = 0.0;
212 double w = (getVolume(weighter.getEvtWeighter(), *event) /
213 (logx ? log(10.0) * primary.E * hm0->GetBinWidth(1) : hm0->GetBinWidth(1)) /
214 Wnorm);
215
216 if (option == Mass_t) {
217 y = w * DENSITY_SEA_WATER * 1e-6; // Mton
218 } else if (option == Volume_t) {
219 y = w * 1e-9; // km^3
220 }
221
222 const int interactionID0 = getInteractionID(*event, false, false);
223 const int interactionID1 = getInteractionID(*event, true, false);
224
225 hm0[interactionID0]->Fill(x0, y);
226 hm1[interactionID0]->Fill(x1, y);
227 hm2[interactionID0]->Fill(x2, y);
228 hm3[interactionID0]->Fill(x3, y);
229
230 hm0[interactionID1]->Fill(x0, y);
231 hm2[interactionID1]->Fill(x2, y);
232 hm1[interactionID1]->Fill(x1, y);
233 hm3[interactionID1]->Fill(x3, y);
234
235 if (abs(primary.type) == TRACK_TYPE_NUTAU) {
236
237 const int interactionID2 = getInteractionID(*event, false, true);
238 const int interactionID3 = getInteractionID(*event, true, true);
239
240 hm0[interactionID2]->Fill(x0, y);
241 hm1[interactionID2]->Fill(x1, y);
242 hm2[interactionID2]->Fill(x2, y);
243 hm3[interactionID2]->Fill(x3, y);
244
245 hm0[interactionID3]->Fill(x0, y);
246 hm2[interactionID3]->Fill(x2, y);
247 hm1[interactionID3]->Fill(x1, y);
248 hm3[interactionID3]->Fill(x3, y);
249 }
250 }
251 }
252 STATUS(endl);
253 }
254
255 TFile out(outputFile.c_str(), "recreate");
256
257 out << hm0 << hm1 << hm2 << hm3;
258
259 out.Close();
260}
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
string outputFile
int main(int argc, char **argv)
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Dynamic ROOT object management.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Physics constants.
ROOT TTree parameter settings of various packages.
Auxiliary methods for evaluating visible energies.
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::cut_nu cut_nu
Definition JHead.hh:1614
const JHead & getHeader() const
Get header.
Definition JHead.hh:1270
JAANET::genvol genvol
Definition JHead.hh:1618
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition JHead.hh:1319
Exception for missing value.
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition JManager.hh:47
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
Auxiliary class for trigger mask.
bool hasTriggerMask(const JDAQTriggerMask &mask) const
Has trigger bit pattern.
double getVolume(const JType< JEvtWeightGSeaGen > &type, const Evt &evt)
Get volume of given event according given weighter.
JCylinder3D getCylinder(const JHead &header)
Get cylinder corresponding to the positions of generated tracks (i.e.
bool has_leading_lepton(const Evt &event)
Auxiliary function to check if an event contains the leading lepton of a neutrino interaction.
const Trk & get_primary(const Evt &evt)
Auxiliary function to retrieve the primary track of an event.
JEvtWeighter getEventWeighter
Function object for mapping header to event weighter.
int getInteractionID(const Evt &event, const bool useScatteringType=true, const bool useDecayType=true)
Retrieve interaction identifier.
static const double PI
Mathematical constants.
static const double DENSITY_SEA_WATER
Fixed environment values.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getVisibleEnergyLeadingLepton(const Trk &, const JCylinder3D &)
double getVisibleEnergy(const Trk &, const JCylinder3D &)
Get the visible energy of a track.
JMultiHead getMultiHeader(const JMultipleFileScanner_t &file_list)
Get multi-header corresponding to a given file list.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
static const JDAQTriggerMask TRIGGER_MASK_ON
Trigger mask on;.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Helper class for event weighing.
void configure(const JEvtWeight &weighter)
Configuration.
JEvtWeight & getEvtWeighter() const
Get reference to event-weighter.
Auxiliary data structure to store multiple headers and bookkeep event-weight normalisations.
Definition JMultiHead.hh:39
JUUID getHeaderUUID(const Evt &event) const
Get the header UUID corresponding to the given event.
The cylinder used for photon tracking.
Definition JHead.hh:575
JRange_t cosT
Cosine zenith angle range
Definition JHead.hh:420
double numberOfEvents
Number of events.
Definition JHead.hh:721
Primary particle.
Definition JHead.hh:1174
int type
Particle type.
Definition JHead.hh:1204
Simple wrapper for UUID.
Definition JUUID.hh:24
uuid_t uuid
Definition JUUID.hh:172
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
Auxiliary base class for list of file names.
Simple data structure for histogram binning.
const_iterator find(const uuid_t &uuid, const bool useCache=false) const
Find header with given UUID.
Definition MultiHead.hh:47
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15