Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
JEffectiveMass1D.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
10
11#include "JDAQ/JDAQEventIO.hh"
12
15
16#include "JAAnet/JVolume.hh"
19
20#include "JSupport/JSupport.hh"
24
25#include "JROOT/JManager.hh"
26
27#include "Jeep/JParser.hh"
28#include "Jeep/JMessage.hh"
29
30
31namespace {
32
33 const char* const Mass_t = "Mass";
34 const char* const Volume_t = "Volume";
35}
36
37/**
38 * \file
39 *
40 * Example program to histogram neutrino effective mass for triggered events by counting events inside the can volume.\n
41 * All generated events should therefore be available in the input file(s).\n
42 * This implies that option <tt>JSirene -N 0</tt> should be used and option <tt>JTriggerEfficiency -O</tt> should not be used.\n
43 * Alternatively, the option <tt>-C</tt> can be used to specify a cylinder as the can.\n
44 * The unit of the contents of the histogram is \f$Mton\f$ or \f$km^{3}\f$.
45 * \author mdejong, bstrandberg, bjung
46 */
47int main(int argc, char **argv)
48{
49 using namespace std;
50 using namespace JPP;
51 using namespace KM3NETDAQ;
52
54 string outputFile;
55 double margin;
56 bool logx;
57 int numberOfBins;
59 std::string option;
60 int debug;
61
62
63 try {
64
65 JParser<> zap("Example program to histogram neutrino effective mass for triggered events.");
66
68 zap['o'] = make_field(outputFile) = "Meff.root";
69 zap['R'] = make_field(margin, "Margin around the volume in which the considered events must reside") = 0.0;
70 zap['X'] = make_field(logx, "Use logarithm of energy");
71 zap['N'] = make_field(numberOfBins, "Number of bins in the energy range of the MC simulation") = 10;
72 zap['C'] = make_field(cylinder, "User cylinder") = JPARSER::initialised();
73 zap['O'] = make_field(option, "Result option") = Mass_t, Volume_t;
74 zap['d'] = make_field(debug) = 2;
75
76 zap(argc, argv);
77 }
78 catch(const exception &error) {
79 FATAL(error.what() << endl);
80 }
81
82 try{
83
85 double Xmax = numeric_limits<double>::lowest();
86
88
89 for (JEvtWeightFileScannerSet<>::const_iterator scanner = scanners.cbegin(); scanner != scanners.cend(); ++scanner) {
90
91 const JVolume volume(scanner->getHeader(), logx);
92
93 if (volume.getXmin() < Xmin) { Xmin = volume.getXmin(); }
94 if (volume.getXmax() > Xmax) { Xmax = volume.getXmax(); }
95 }
96
97 JManager<int, TH1D> hM (new TH1D("hM[%]", NULL, numberOfBins, Xmin, Xmax));
98 JManager<int, TH1D> hNM(new TH1D("hNM[%]", NULL, numberOfBins, Xmin, Xmax));
99
100 for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
101
102 const JHead header = scanner->getHeader();
103
104 NOTICE("Scanning file type " << scanner->getName() << endl);
105 DEBUG (header << endl);
106
108
109 if (can.getVolume() == 0.0) {
110 can = getCylinder(header);
111 }
112
113 can.addMargin(margin);
114
115 NOTICE("Cylinder, including margin: " << can << endl);
116
117 //------------------------------------------------------------------------------
118 // loop over all generated events in the input files
119 //------------------------------------------------------------------------------
120
121 size_t N = 0;
122
123 for (JMultipleFileScanner<Evt> in(scanner->getFilelist()); in.hasNext(); ) {
124
125 STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
126
127 const Evt* event = in.next();
128 const Trk& primary = get_primary(*event);
129 const JVertex3D& vertex = getVertex(*event);
130
131 if (event->mc_hits.empty()) {
132 N += 1;
133 }
134
135 const double x = logx ? log10(primary.E) : primary.E;
136
137 if (can.is_inside(vertex)) {
138 hNM[primary.type]->Fill(x);
139 }
140 }
141 STATUS(endl);
142
143 if (N == 0) {
144 ERROR("No events with zero hits -> use application JEffectiveMassOffline1D." << endl);
145 }
146
147 //------------------------------------------------------------------------------
148 // loop over triggered events in the input files
149 //------------------------------------------------------------------------------
150
151 for (JTriggeredFileScanner<> in(scanner->getFilelist()); in.hasNext(); ) {
152
153 STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
154
155 const Evt* event = in.next();
156 const Trk& primary = get_primary(*event);
157
158 double x = logx ? log10(primary.E) : primary.E;
159 double y = 0.0;
160
161 if (option == Mass_t) {
162 y = can .getVolume() * DENSITY_SEA_WATER * 1e-6; // Mton
163 } else if (option == Volume_t) {
164 y = can .getVolume() * 1.0e-9; // km^3
165 }
166
167 hM[primary.type]->Fill(x, y);
168 }
169 STATUS(endl);
170 }
171
172 //------------------------------------------------------------------------------
173 // convert 'generated' and 'triggered' histograms to effective mass
174 //------------------------------------------------------------------------------
175
176 for (int pdg : get_keys(hM)) {
177 hM[pdg]->Divide(hNM[pdg]);
178 }
179
180 TFile out(outputFile.c_str(), "recreate");
181
182 out << hM;
183
184 out.Close();
185 }
186 catch(const JException& error) {
187 FATAL(error << endl);
188 }
189}
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
string outputFile
int main(int argc, char **argv)
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
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
ROOT TTree parameter settings of various packages.
Synchronously read DAQ events and Monte Carlo events (and optionally other events).
Monte Carlo run header.
Definition JHead.hh:1236
const JHead & getHeader() const
Get header.
Definition JHead.hh:1270
General exception.
Definition JException.hh:24
Template definition of a multi-dimensional oscillation probability interpolation table.
JCylinder3D getCylinder(const JHead &header)
Get cylinder corresponding to the positions of generated tracks (i.e.
JVertex3D getVertex(const Trk &track)
Get vertex.
const Trk & get_primary(const Evt &evt)
Auxiliary function to retrieve the primary track of an event.
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
static const double DENSITY_SEA_WATER
Fixed environment values.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Auxiliary class for histogramming of effective volume.
Definition JVolume.hh:29
Double_t getXmax() const
Get maximal abscissa value.
Definition JVolume.hh:102
Double_t getXmin() const
Get minimal abscissa value.
Definition JVolume.hh:91
The cylinder used for photon tracking.
Definition JHead.hh:575
Primary particle.
Definition JHead.hh:1174
int type
Particle type.
Definition JHead.hh:1204
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.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15