Jpp
Functions
JVolume1D.cc File Reference
#include <string>
#include <iostream>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "evt/Head.hh"
#include "evt/Evt.hh"
#include "evt/Vec.hh"
#include "JDAQ/JDAQEvent.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JGizmo/JVolume.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JGeometry3D/JPosition3D.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.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 volume for triggered events. For genie/gSeaGen events a histogram depicting the fraction of events that triggered the detector inside the instrumented volume is also shown. The unit of the contents of the histogram is $km^{3}$.

Author
mdejong, bstrandberg

Definition in file JVolume1D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 107 of file JVolume1D.cc.

108 {
109  using namespace std;
110  using namespace JPP;
111  using namespace KM3NETDAQ;
112 
113  //------------------------------------------------------------------------------
114  // parse command line arguments, check that header can be found in the input file
115  //------------------------------------------------------------------------------
116 
117  JTriggeredFileScanner<> inputFile;
118  string outputFile;
119  JLimit& numberOfEvents = inputFile.getLimit();
120  double wall;
121  bool logx;
122  int numberOfBins;
123  int debug;
124  string detectorFile;
125 
126 
127  try {
128 
129  JParser<> zap("Example program to histogram neutrino effective volume for triggered events. For genie/gSeaGen events a histogram depicting the fraction of events that triggered the detector inside the instrumented volume is also shown.");
130 
131  zap['f'] = make_field(inputFile);
132  zap['o'] = make_field(outputFile) = "volume.root";
133  zap['n'] = make_field(numberOfEvents) = JLimit::max();
134  zap['R'] = make_field(wall, "Addition margin around the volume in which the considered events must reside") = 0.0;
135  zap['X'] = make_field(logx, "Use logarithm of energy");
136  zap['N'] = make_field(numberOfBins, "Number of bins in the energy range of the MC simulation") = 10;
137  zap['d'] = make_field(debug) = 1;
138  zap['a'] = make_field(detectorFile, "Detector file: if not provided, trigger fraction is not calculated") = "";
139 
140  zap(argc, argv);
141  }
142  catch(const exception &error) {
143  FATAL(error.what() << endl);
144  }
145 
146  //-------------------------------------------------------------------------
147  // deal with the header and init the detector
148  //-------------------------------------------------------------------------
149 
150  Head head;
151 
152  try {
153  head = getHeader(inputFile);
154  }
155  catch(const JException& error) {
156  FATAL(error);
157  }
158 
160 
161  if (detectorFile != "") {
162 
163  try {
164  load(detectorFile, detector);
165  }
166  catch(const JException& error) {
167  FATAL(error);
168  }
169  }
170 
171  //------------------------------------------------------------------------------
172  // create the can volume from the dimensions stored in the header and instrumented volume from detector file
173  //------------------------------------------------------------------------------
174 
175  const JHead buffer(head);
176 
177  const bool genie = is_genie(buffer);
178 
179  // the can volume comes from the generator header and the coordinate system is consistent by construction
180  const JVolume volume(head, logx);
181  JCylinder3D canvol = get<JCylinder3D>(buffer);
182  canvol.addMargin(wall);
183 
184  // as the detector is constructed from Jpp detector file, the coordinate system needs to be synced
185  // to the one used in the event generator
186  detector -= JAANET::getPosition( get_coord_origin(buffer) );
187  JCylinder3D instvol( detector.begin(), detector.end() );
188  instvol.addMargin(wall);
189 
190  NOTICE("JVolume1D: Instrumented volume dimensions (zmin, zmax, r): " << instvol.getZmin() << " " << instvol.getZmax() << " " << instvol.getRadius() << endl );
191 
192  //------------------------------------------------------------------------------
193  // initialise output
194  //------------------------------------------------------------------------------
195 
196  TFile out(outputFile.c_str(), "recreate");
197 
198  TH1D hV("hV", "effective volume in km^3" , numberOfBins, volume.getXmin(), volume.getXmax());
199  TH1D hF("hF", "n_trig/n_gen in instrumented volume", numberOfBins, volume.getXmin(), volume.getXmax());
200  hV.Sumw2();
201  hF.Sumw2();
202 
203  //------------------------------------------------------------------------------
204  // loop over triggered events in the input file
205  //------------------------------------------------------------------------------
206 
207  NOTICE("JVolume1D: Scanning triggered events." << endl);
208  while (inputFile.hasNext()) {
209 
210  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
211 
213 
214  const Evt* event = ps;
215 
216  if (has_neutrino(*event)) {
217 
218  const Trk& neutrino = get_neutrino(*event);
219  const double E = neutrino.E;
220 
221  // genie/gSeaGen events filled with weight 1, histograms normalised after the second loop below
222  if ( genie ) {
223 
224  // events are filled to hV if they are inside the can
225  hV.Fill(volume.getX(E), test_event(canvol, *event) ? 1.0 : 0.0);
226 
227  // events are filled to hF if they are inside the instrumented volume
228  hF.Fill(volume.getX(E), test_event(instvol, *event) ? 1.0 : 0.0);
229 
230  }
231  // for other simulated events effective volume calculated from event weights, normalisation not required
232  else {
233  hV.Fill(volume.getX(E), volume.getW(hV.GetXaxis(), E));
234  }
235 
236  }
237  else {
238  WARNING("JVolume1D: cannot find neutrino in triggered event " << inputFile.getCounter() );
239  }
240 
241  } // end loop over triggered events
242  STATUS(endl);
243 
244  //------------------------------------------------------------------------------
245  // loop over generated events in the input file; FATAL if generator events have not been stored
246  //------------------------------------------------------------------------------
247 
248  if ( genie ) {
249 
250  // this histogram counts the generated events inside the can volume
251  TH1D* hNV = (TH1D*) hV.Clone("hNV");
252  hNV->Reset();
253 
254  // this histogram counts the generated events inside the instrumented volume
255  TH1D* hNF = (TH1D*) hF.Clone("hNF");
256  hNF->Reset();
257 
258  NOTICE("JVolume1D: Scanning generated events." << endl);
259 
260  JMultipleFileScanner<Evt> in(inputFile);
261 
262  while ( in.hasNext() ) {
263 
264  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
265 
266  const Evt* event = in.next();
267 
268  if (has_neutrino(*event)) {
269 
270  const Trk& neutrino = get_neutrino(*event);
271  const double E = neutrino.E;
272 
273  hNV->Fill(volume.getX(E), test_event(canvol, *event) ? 1.0 : 0.0);
274  hNF->Fill(volume.getX(E), test_event(instvol, *event) ? 1.0 : 0.0);
275 
276  }
277  else {
278  WARNING("JVolume1D: cannot find neutrino in generated event " << inputFile.getCounter() );
279  }
280 
281  }
282  STATUS(endl);
283 
284  if ( in.getCounter() == 0 ) {
285  FATAL("JVolume1D: generated events not stored in the input file, JTriggerEfficiency should be run without option -O");
286  }
287 
288  //------------------------------------------------------------------------------
289  // convert 'generated' and 'triggered' histograms to effective volume and trigger fraction
290  //------------------------------------------------------------------------------
291 
292  hV.Divide(hNV);
293  hV.Scale(canvol.getVolume()*1e-9); // km^3
294  hF.Divide(hNF);
295 
296  delete hNV;
297  delete hNF;
298 
299  }
300 
301  out.Write();
302  out.Close();
303 
304 }
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JGEOMETRY3D::JCylinder3D::getVolume
double getVolume() const
Get volume.
Definition: JCylinder3D.hh:176
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
JLANG::JMultiPointer
General purpose class for multiple pointers.
Definition: JMultiPointer.hh:22
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JGEOMETRY3D::JCylinder3D::addMargin
void addMargin(const double D)
Add (safety) margin.
Definition: JCylinder3D.hh:163
JAANET::JHead
Monte Carlo run header.
Definition: JHead.hh:839
JSUPPORT::JTriggeredFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JTriggeredFileScanner.hh:72
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JGEOMETRY3D::JCylinder3D
Cylinder object.
Definition: JCylinder3D.hh:37
JSUPPORT::getHeader
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:425
JSUPPORT::JMultipleFileScanner< JTypeList< JDAQEvent, JTypelist_t > >::getCounter
counter_type getCounter() const
Get counter.
Definition: JMultipleFileScanner.hh:323
WARNING
#define WARNING(A)
Definition: JMessage.hh:65
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JTriggeredFileScanner::next
virtual const multi_pointer_type & next()
Get next element.
Definition: JTriggeredFileScanner.hh:92
JAANET::get_neutrino
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
Definition: JAAnetToolkit.hh:438
JAANET::has_neutrino
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
Definition: JAAnetToolkit.hh:427
JGIZMO::JVolume
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:26
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JSUPPORT::JTriggeredFileScanner
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
Definition: JTriggeredFileScanner.hh:39
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
JAANET::detector
Detector file.
Definition: JHead.hh:130
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JAANET::is_genie
bool is_genie(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:223
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JLANG::JException
General exception.
Definition: JException.hh:40