Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
14 #include "JAAnet/JHeadToolkit.hh"
15 #include "JAAnet/JAAnetToolkit.hh"
16 
17 #include "JSupport/JSupport.hh"
21 
22 #include "JROOT/JManager.hh"
23 
24 #include "JPhysics/JConstants.hh"
25 
26 #include "Jeep/JParser.hh"
27 #include "Jeep/JMessage.hh"
28 
29 namespace {
30 
31  const char* const Mass_t = "Mass";
32  const char* const Volume_t = "Volume";
33 }
34 
35 /**
36  * \file
37  *
38  * Example program to histogram neutrino effective mass for triggered events for online reconstruction files, using the event weights only.\n
39  * The unit of the contents of the histogram is \f$Mton\f$ or \f$km^{3}\f$.
40  * \author bjung, mdejong
41  */
42 int main(int argc, char **argv)
43 {
44  using namespace std;
45  using namespace JPP;
46  using namespace KM3NETDAQ;
47 
48  JMultipleFileScanner_t inputFiles;
49  string outputFile;
50  bool logx;
51  int numberOfBins;
52  std::string option;
53  int debug;
54 
55 
56  try {
57 
58  JParser<> zap("Example program to histogram neutrino effective mass for triggered events.");
59 
60  zap['f'] = make_field(inputFiles);
61  zap['o'] = make_field(outputFile) = "Meff.root";
62  zap['X'] = make_field(logx, "Use logarithm of energy");
63  zap['N'] = make_field(numberOfBins, "Number of bins in the energy range of the MC simulation") = 10;
64  zap['O'] = make_field(option, "Result option") = Mass_t, Volume_t;
65  zap['d'] = make_field(debug) = 2;
66 
67  zap(argc, argv);
68  }
69  catch(const exception &error) {
70  FATAL(error.what() << endl);
71  }
72 
73  try {
74 
75  double Xmin = numeric_limits<double>::max();
76  double Xmax = numeric_limits<double>::lowest();
77 
78  JEvtWeightFileScannerSet<> scanners(inputFiles);
79 
80  for (JEvtWeightFileScannerSet<>::const_iterator scanner = scanners.cbegin(); scanner != scanners.cend(); ++scanner) {
81 
82  const JVolume volume(scanner->getHeader(), logx);
83 
84  if (volume.getXmin() < Xmin) { Xmin = volume.getXmin(); }
85  if (volume.getXmax() > Xmax) { Xmax = volume.getXmax(); }
86  }
87 
88  JManager<int, TH1D> hm(new TH1D("hm[%]", option.c_str(), numberOfBins, Xmin, Xmax));
89 
90  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
91 
92  const JHead header = scanner->getHeader();
93 
94  NOTICE("Scanning file type " << scanner->getName() << endl);
95  DEBUG (header << endl);
96 
97  const JEvtWeight& weighter = scanner->getEvtWeighter();
98 
99  if (!header.is_valid(&JHead::genvol)) {
100  FATAL("Mising normalisation in header." << endl);
101  }
102 
103  double Wnorm = header.genvol.numberOfEvents;
104 
105  if (header.is_valid(&JHead::cut_nu))
106  Wnorm *= 2*PI * (header.cut_nu.cosT.getUpperLimit() - header.cut_nu.cosT.getLowerLimit());
107  else
108  Wnorm *= 4*PI;
109 
110  for (JTriggeredFileScanner<> in(scanner->getFilelist()); in.hasNext(); ) {
111 
112  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
113 
114  const Evt* event = in.next();
115  const Trk& primary = get_primary(*event);
116 
117  double x = logx ? log10(primary.E) : primary.E;
118  double y = 0.0;
119  double w = (getVolume(weighter, *event) /
120  (logx ? log(10.0) * primary.E * hm->GetBinWidth(1) : hm->GetBinWidth(1)) /
121  Wnorm);
122 
123  if (option == Mass_t) {
124  y = w * DENSITY_SEA_WATER * 1e-6; // Mton
125  } else if (option == Volume_t) {
126  y = w * 1e-9; // km^3
127  }
128 
129  hm[primary.type]->Fill(x, y);
130  }
131  STATUS(endl);
132  }
133 
134  TFile out(outputFile.c_str(), "recreate");
135 
136  out << hm;
137 
138  out.Close();
139  }
140  catch(const JException& error) {
141  FATAL(error << endl);
142  }
143 }
Utility class to parse command line options.
Definition: JParser.hh:1711
General exception.
Definition: JException.hh:24
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1319
data_type w[N+1][M+1]
Definition: JPolint.hh:867
Double_t getXmin() const
Get minimal abscissa value.
Definition: JVolume.hh:91
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
Synchronously read DAQ events and Monte Carlo events (and optionally other events).
double getVolume(const JType< JEvtWeightGSeaGen > &type, const Evt &evt)
Get volume of given event according given weighter.
#define STATUS(A)
Definition: JMessage.hh:63
double numberOfEvents
Number of events.
Definition: JHead.hh:721
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
const Trk & get_primary(const Evt &evt)
Get primary.
static const double DENSITY_SEA_WATER
Fixed environment values.
Dynamic ROOT object management.
string outputFile
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:29
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Abstract base class for event weighing.
Definition: JEvtWeight.hh:28
Monte Carlo run header.
Definition: JHead.hh:1234
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
set_variable E_E log10(E_{fit}/E_{#mu})"
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
#define NOTICE(A)
Definition: JMessage.hh:64
Physics constants.
JAANET::cut_nu cut_nu
Definition: JHead.hh:1595
static const double PI
Mathematical constants.
JRange_t cosT
Cosine zenith angle range.
Definition: JHead.hh:420
General purpose messaging.
JAANET::genvol genvol
Definition: JHead.hh:1599
#define FATAL(A)
Definition: JMessage.hh:67
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
Auxiliary base class for list of file names.
std::vector< filescanner_type >::iterator iterator
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Utility class to parse command line options.
Primary particle.
Definition: JHead.hh:1174
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1270
Auxiliary class for organising Monte Carlo file scanners associated with event weighters.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
std::vector< filescanner_type >::const_iterator const_iterator
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:70
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62