Jpp  18.3.0-209-g56ce19a
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JEffectiveMass1D.cc File Reference

Example program to histogram neutrino effective mass for triggered events inside the can volume. More...

#include <string>
#include <iostream>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Vec.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JGeometry3D/JPosition3D.hh"
#include "JAAnet/JVolume.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JEvtWeightFileScannerSet.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JROOT/JManager.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to histogram neutrino effective mass for triggered events inside the can volume.


For other than genie/gSeaGen events, use application JVolume1D.
The unit of the contents of the histogram is $Mton$ or $km^{3}$.

Author
mdejong, bstrandberg, bjung

Definition in file JEffectiveMass1D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file JEffectiveMass1D.cc.

50 {
51  using namespace std;
52  using namespace JPP;
53  using namespace KM3NETDAQ;
54 
55  JMultipleFileScanner_t inputFiles;
56  string detectorFile;
57  string outputFile;
58  double margin;
59  bool logx;
60  int numberOfBins;
61  std::string option;
62  int debug;
63 
64 
65  try {
66 
67  JParser<> zap("Example program to histogram neutrino effective mass for triggered events.");
68 
69  zap['f'] = make_field(inputFiles);
70  zap['a'] = make_field(detectorFile, "Detector file: if not provided, instrumented volume is not calculated") = "";
71  zap['o'] = make_field(outputFile) = "Meff.root";
72  zap['R'] = make_field(margin, "Addition or subtraction margin around the volume in which the considered events must reside") = 0.0;
73  zap['X'] = make_field(logx, "Use logarithm of energy");
74  zap['N'] = make_field(numberOfBins, "Number of bins in the energy range of the MC simulation") = 10;
75  zap['O'] = make_field(option, "Result option") = Mass_t, Volume_t;
76  zap['d'] = make_field(debug) = 2;
77 
78  zap(argc, argv);
79  }
80  catch(const exception &error) {
81  FATAL(error.what() << endl);
82  }
83 
85 
86  if (detectorFile != "") {
87 
88  try {
89  load(detectorFile, detector);
90  }
91  catch(const JException& error) {
92  FATAL(error);
93  }
94  }
95 
96  try{
97 
98  double Xmin = numeric_limits<double>::max();
99  double Xmax = numeric_limits<double>::lowest();
100 
101  JEvtWeightFileScannerSet<> scanners(inputFiles);
102 
103  for (JEvtWeightFileScannerSet<>::const_iterator scanner = scanners.cbegin(); scanner != scanners.cend(); ++scanner) {
104 
105  const JHead header = scanner->getHeader();
106 
107  if (!is_gseagen(header)) {
108  ERROR("Not a gSeaGen file; you may want to use JVolume1D" << endl);
109  }
110 
111  const JVolume volume(header, logx);
112 
113  if (volume.getXmin() < Xmin) { Xmin = volume.getXmin(); }
114  if (volume.getXmax() > Xmax) { Xmax = volume.getXmax(); }
115  }
116 
117  JManager<int, TH1D> hM (new TH1D("hM[%]", MAKE_CSTRING(option << " can"), numberOfBins, Xmin, Xmax));
118  JManager<int, TH1D> hm (new TH1D("hm[%]", MAKE_CSTRING(option << " instrumented"), numberOfBins, Xmin, Xmax));
119  JManager<int, TH1D> hNM(new TH1D("hNM[%]", MAKE_CSTRING(option << " normalization can"), numberOfBins, Xmin, Xmax));
120  JManager<int, TH1D> hNm(new TH1D("hNm[%]", MAKE_CSTRING(option << " normalization instrumented"), numberOfBins, Xmin, Xmax));
121 
122 
123  for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) {
124 
125  const JHead header = scanner->getHeader();
126 
127  NOTICE("Scanning file type " << distance(scanners.begin(), scanner) << endl);
128  DEBUG (header << endl);
129 
130  //------------------------------------------------------------------------------
131  // define selection volumes
132  //------------------------------------------------------------------------------
133 
134  // can volume comes from the generator header
135  // position is consistent with those of generated tracks (Evt::mc_trks) by construction
136 
137  JCylinder3D canvol = getCylinder(header);
138 
139  canvol.addMargin(margin);
140 
141  // detector geometry comes from detector file
142  // position needs to be synced to that used in event generator
143 
144  const Vec offset = getOffset(header);
145 
146  JCylinder3D instvol( detector.begin(), detector.end() );
147 
148  instvol -= getPosition(offset);
149  instvol.addMargin(margin);
150 
151  NOTICE("Light simulation volume dimensions, including margin: " << endl << canvol << endl);
152  NOTICE("Instrumented volume dimensions, including margin: " << endl << instvol << endl);
153 
154  //------------------------------------------------------------------------------
155  // loop over generated events in the input files
156  //------------------------------------------------------------------------------
157 
158  size_t N = 0;
159 
160  while (scanner->hasNext()) {
161 
162  STATUS("event: " << setw(10) << scanner->getCounter() << '\r'); DEBUG(endl);
163 
164  const Evt* event = scanner->next();
165  const Trk& primary = get_primary(*event);
166  const JVertex3D& vertex = getVertex(*event);
167  const double x = logx ? log10(primary.E) : primary.E;
168 
169  if (event->mc_hits.empty()) {
170  N += 1;
171  }
172 
173  // events are filled to hM if they are inside the can
174  if (canvol.is_inside(vertex)) {
175  hNM[primary.type]->Fill(x);
176  }
177 
178  // events are filled to hm if they are inside the instrumented volume
179  if (instvol.is_inside(vertex)) {
180  hNm[primary.type]->Fill(x);
181  }
182  }
183  STATUS(endl);
184 
185  if (N == 0) {
186  ERROR("No events with zero hits -> use application JEffectiveMassOffline1D." << endl);
187  }
188 
189  //------------------------------------------------------------------------------
190  // loop over triggered events in the input files
191  //------------------------------------------------------------------------------
192 
193  JTriggeredFileScanner<> in(scanner->getFilelist());
194 
195  while (in.hasNext()) {
196 
197  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
198 
200 
201  const Evt* event = mp;
202  const Trk& primary = get_primary(*event);
203  const double x = logx ? log10(primary.E) : primary.E;
204 
205  double yM = 0.0;
206  double ym = 0.0;
207 
208  if (option == Mass_t) {
209  yM = canvol .getVolume() * DENSITY_SEA_WATER * 1e-6; // Mton
210  ym = instvol.getVolume() * DENSITY_SEA_WATER * 1e-6; // Mton
211  } else if (option == Volume_t) {
212  yM = canvol .getVolume() * 1.0e-15; // km^3
213  ym = instvol.getVolume() * 1.0e-15; // km^3
214  }
215 
216  hM[primary.type]->Fill(x, yM);
217  hm[primary.type]->Fill(x, ym);
218 
219  }
220  STATUS(endl);
221  }
222 
223  //------------------------------------------------------------------------------
224  // convert 'generated' and 'triggered' histograms to effective mass
225  //------------------------------------------------------------------------------
226 
227  for (int pdg : get_keys(hM)) {
228  hM[pdg]->Divide(hNM[pdg]);
229  hm[pdg]->Divide(hNm[pdg]);
230  }
231 
232  TFile out(outputFile.c_str(), "recreate");
233 
234  out << hM << hm;
235 
236  out.Close();
237  }
238  catch(const JException& error) {
239  FATAL(error << endl << "You may want to use \"offline\" formatted file.");
240  }
241 }
JVertex3D getVertex(const Trk &track)
Get vertex.
Utility class to parse command line options.
Definition: JParser.hh:1711
General exception.
Definition: JException.hh:24
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
Vec getOffset(const JHead &header)
Get offset.
JCylinder3D getCylinder(const JHead &header)
Get cylinder corresponding to the positions of generated tracks (i.e.
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:61
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
const Trk & get_primary(const Evt &evt)
Get primary.
static const double DENSITY_SEA_WATER
Fixed environment values.
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
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Cylinder object.
Definition: JCylinder3D.hh:39
Detector file.
Definition: JHead.hh:226
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})"
JPosition3D getPosition(const Vec &pos)
Get position.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
then awk string
void addMargin(const double D)
Add (safety) margin.
Definition: JCylinder3D.hh:172
#define FATAL(A)
Definition: JMessage.hh:67
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
double getVolume() const
Get volume.
Definition: JCylinder3D.hh:185
Auxiliary base class for list of file names.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
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
bool is_inside(const JVector3D &pos) const
Check whether given point is inside cylinder.
Definition: JCylinder3D.hh:208
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.
do set_variable DETECTOR_TXT $WORKDIR detector
General purpose class for multiple pointers.
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:69
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.
Definition: JVectorize.hh:139
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