Jpp 21.0.1
the software that should make you happy
Loading...
Searching...
No Matches
JEffectiveMassOnline1D.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
13#include "JAAnet/JVolume.hh"
16
17#include "JTools/JRange.hh"
18
19#include "JSupport/JSupport.hh"
23
24#include "JROOT/JManager.hh"
25
27
28#include "Jeep/JParser.hh"
29#include "Jeep/JMessage.hh"
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 for online reconstruction files, using the event weights only.\n
41 * The unit of the contents of the histogram is \f$Mton\f$ or \f$km^{3}\f$.
42 * \author bjung, mdejong
43 */
44int main(int argc, char **argv)
45{
46 using namespace std;
47 using namespace JPP;
48 using namespace KM3NETDAQ;
49
50 JMultipleFileScanner_t inputFiles;
51 string outputFile;
52 bool logx;
54 int numberOfBins;
55 std::string option;
56 JDAQTriggerMask trigger_mask;
57 int debug;
58
59
60 try {
61
62 JParser<> zap("Example program to histogram neutrino effective mass for triggered events.");
63
64 zap['f'] = make_field(inputFiles);
65 zap['o'] = make_field(outputFile) = "Meff.root";
66 zap['X'] = make_field(logx, "Use logarithm of energy");
67 zap['x'] = make_field(X, "Histogram range") = JRange<double>();
68 zap['N'] = make_field(numberOfBins, "Number of bins in the energy range of the MC simulation") = 10;
69 zap['O'] = make_field(option, "Result option") = Mass_t, Volume_t;
70 zap['T'] = make_field(trigger_mask, "Trigger mask") = TRIGGER_MASK_ON;
71 zap['d'] = make_field(debug) = 2;
72
73 zap(argc, argv);
74 }
75 catch(const exception &error) {
76 FATAL(error.what() << endl);
77 }
78
79 try {
80
81 JEvtWeightFileScannerSet<> scanners(inputFiles);
82
83 double Xmin = numeric_limits<double>::max();
84 double Xmax = numeric_limits<double>::lowest();
85
86 if (X != JRange<double>()) {
87
88 Xmin = (logx ? log10(X.getLowerLimit()) : X.getLowerLimit());
89 Xmax = (logx ? log10(X.getUpperLimit()) : X.getUpperLimit());
90
91 } else {
92
93 for (JEvtWeightFileScannerSet<>::const_iterator scanner = scanners.cbegin(); scanner != scanners.cend(); ++scanner) {
94
95 const JVolume volume(scanner->getHeader(), logx);
96
97 if (volume.getXmin() < Xmin) { Xmin = volume.getXmin(); }
98 if (volume.getXmax() > Xmax) { Xmax = volume.getXmax(); }
99 }
100 }
101
102 JManager<int, TH1D> hm(new TH1D("hm[%]", option.c_str(), numberOfBins, Xmin, Xmax));
103
104 for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
105
106 const JHead header = scanner->getHeader();
107
108 NOTICE("Scanning file type " << scanner->getName() << endl);
109 DEBUG (header << endl);
110
111 const JEvtWeight& weighter = scanner->getEvtWeighter();
112
113 if (!header.is_valid(&JHead::genvol)) {
114 FATAL("Mising normalisation in header." << endl);
115 }
116
117 double Wnorm = header.genvol.numberOfEvents;
118
119 if (header.is_valid(&JHead::cut_nu))
120 Wnorm *= 2*PI * (header.cut_nu.cosT.getUpperLimit() - header.cut_nu.cosT.getLowerLimit());
121 else
122 Wnorm *= 4*PI;
123
124 for (JTriggeredFileScanner<> in(scanner->getFilelist()); in.hasNext(); ) {
125
126 STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
127
129
130 const JDAQEvent* tev = ps;
131 const Evt* event = ps;
132 const Trk& primary = get_primary(*event);
133
134 if (tev->hasTriggerMask(trigger_mask)) {
135
136 double x = logx ? log10(primary.E) : primary.E;
137 double y = 0.0;
138 double w = (getVolume(weighter, *event) /
139 (logx ? log(10.0) * primary.E * hm->GetBinWidth(1) : hm->GetBinWidth(1)) /
140 Wnorm);
141
142 if (option == Mass_t) {
143 y = w * DENSITY_SEA_WATER * 1e-6; // Mton
144 } else if (option == Volume_t) {
145 y = w * 1e-9; // km^3
146 }
147
148 hm[primary.type]->Fill(x, y);
149 }
150 }
151 STATUS(endl);
152 }
153
154 TFile out(outputFile.c_str(), "recreate");
155
156 out << hm;
157
158 out.Close();
159 }
160 catch(const JException& error) {
161 FATAL(error << endl);
162 }
163}
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
string outputFile
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:74
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
Physics constants.
Auxiliary class to define a range between two values.
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:75
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
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
General exception.
Definition JException.hh:25
Utility class to parse command line options.
Definition JParser.hh:1664
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition JManager.hh:47
Range of values.
Definition JRange.hh:42
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.
const Trk & get_primary(const Evt &evt)
Auxiliary function to retrieve the primary track of an event.
static const double PI
Mathematical constants.
static const JX X
Definition JMathlib.hh:1613
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
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
Abstract base class for event weighing.
Definition JEvtWeight.hh:31
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
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
General purpose class for multiple pointers.
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
Auxiliary base class for list of file names.
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
virtual bool hasNext() override
Check availability of next element.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15