Jpp  master_rocky-43-ge265d140c
the software that should make you happy
JFitEfficiency.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TH1D.h"
8 
11 
12 #include "JAAnet/JHead.hh"
13 #include "JAAnet/JAAnetToolkit.hh"
14 #include "JAAnet/JVolume.hh"
15 
16 #include "JDAQ/JDAQEventIO.hh"
17 #include "JTools/JRange.hh"
20 #include "JSupport/JSupport.hh"
22 
23 #include "JReconstruction/JEvt.hh"
25 
26 #include "JDetector/JDetector.hh"
28 
29 #include "Jeep/JParser.hh"
30 #include "Jeep/JMessage.hh"
31 
32 
33 /**
34  * \file
35  *
36  * Example program to histogram fit efficiency.
37  * \author lquinn
38  */
39 int main(int argc, char **argv)
40 {
41  using namespace std;
42  using namespace JPP;
43  using namespace KM3NETDAQ;
44 
45  typedef JTriggeredFileScanner<JEvt> JTriggeredFileScanner_t;
46  typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
47 
48  JTriggeredFileScanner_t inputFile;
49  JLimit_t& numberOfEvents = inputFile.getLimit();
50  string outputFile;
51  string detectorFile;
52  size_t numberOfPrefits;
53  JRange<double> E_GeV;
54  double quality;
55  bool logx;
56  bool containment;
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Example program to histogram fit results.");
62 
63  zap['f'] = make_field(inputFile);
64  zap['o'] = make_field(outputFile) = "fitefficiency.root";
65  zap['a'] = make_field(detectorFile);
66  zap['n'] = make_field(numberOfEvents) = JLimit::max();
67  zap['N'] = make_field(numberOfPrefits) = 1;
68  zap['E'] = make_field(E_GeV) = JRange<double>(1.0, -1.0);
69  zap['Q'] = make_field(quality) = numeric_limits<double>::min();
70  zap['X'] = make_field(logx);
71  zap['C'] = make_field(containment);
72  zap['d'] = make_field(debug) = 1;
73 
74  zap(argc, argv);
75  }
76  catch(const exception& error) {
77  FATAL(error.what() << endl);
78  }
79 
80 
81  Head head;
82 
83  try {
84  head = getHeader(inputFile);
85  }
86  catch(const JException& error) {
87  FATAL(error);
88  }
89 
90  JHead buffer(head);
91  JVolume volume(head, logx);
92 
93  const double Xmax = E_GeV.is_valid() ? volume.getX(E_GeV.getMaximum()) : volume.getXmax();
94  const double Xmin = E_GeV.is_valid() ? volume.getX(E_GeV.getMinimum()) : volume.getXmin();
95 
96  TFile out(outputFile.c_str(), "recreate");
97 
98  TH1D* hN = new TH1D("hN", NULL, 25, Xmin, Xmax);
99  TH1D* he = new TH1D("he", NULL, 25, Xmin, Xmax);
100 
101  hN->Sumw2();
102  he->Sumw2();
103 
105 
106  try {
107  load(detectorFile, detector);
108  }
109  catch(const JException& error) {
110  FATAL(error);
111  }
112 
113  JCylinder3D cylinder(detector.begin(), detector.end());
114 
115  STATUS("Detector Geometry:" << endl);
116  STATUS("Zmin: " << cylinder.getZmin() << endl);
117  STATUS("Zmax: " << cylinder.getZmax() << endl);
118  STATUS("Z origin: " << 0.5 * (cylinder.getZmax() + cylinder.getZmin()) << endl);
119  STATUS("Radius: " << cylinder.getRadius() << endl);
120 
121  while (inputFile.hasNext()) {
122 
123  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
124 
125  multi_pointer_type ps = inputFile.next();
126 
127  //JDAQEvent* tev = ps;
128  JEvt* evt = ps;
129  Evt* event = ps;
130 
131  if (has_neutrino(*event)) {
132 
133  Trk neutrino = get_neutrino(*event);
134  const double X = volume.getX(neutrino.E);
135 
136  hN->Fill(X);
137 
138  if (!evt->empty()) {
139 
140  JEvt::iterator __end = evt->end();
141 
142  if (numberOfPrefits > 0) {
143 
144  advance(__end = evt->begin(), min(numberOfPrefits, evt->size()));
145 
146  partial_sort(evt->begin(), __end, evt->end(), qualitySorter);
147  }
148 
149 
150  for(JEvt::const_iterator track = evt->begin(); track != __end; ++track) {
151 
152  JPosition3D pos = getPosition(*track);
153 
154  const double R = sqrt(pos.getX() * pos.getX() + pos.getY() * pos.getY());
155 
156  if ((pos.getZ() > cylinder.getZmin()
157  && pos.getZ() < cylinder.getZmax()
158  && R < cylinder.getRadius())
159  || !containment) {
160 
161  double Q = 0.0;
162 
163  if(track->hasW(JGANDALF_CHI2) && track->hasW(JGANDALF_NUMBER_OF_HITS)) {
164  Q = -track->getW(JGANDALF_CHI2)/track->getW(JGANDALF_NUMBER_OF_HITS);
165  }
166  else {
167  Q = track->getQ();
168  }
169 
170  if (Q > quality) {
171  he->Fill(X);
172  }
173  }
174  }
175  }
176  }
177  else {
178  WARNING("No neutrino." << endl);
179  }
180  }
181  STATUS(endl);
182 
183  he->Divide(hN);
184 
185  out.Write();
186  out.Close();
187 }
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
string outputFile
Data structure for detector geometry and calibration.
int main(int argc, char **argv)
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define WARNING(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Auxiliary class to define a range between two values.
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
Detector data structure.
Definition: JDetector.hh:96
double getRadius() const
Get radius.
Definition: JCircle2D.hh:144
Cylinder object.
Definition: JCylinder3D.hh:41
double getZmin() const
Get minimal z position.
Definition: JCylinder3D.hh:111
double getZmax() const
Get maximal z position.
Definition: JCylinder3D.hh:122
Data structure for position in three dimensions.
Definition: JPosition3D.hh:38
double getY() const
Get y position.
Definition: JVector3D.hh:104
double getZ() const
Get z position.
Definition: JVector3D.hh:115
double getX() const
Get x position.
Definition: JVector3D.hh:94
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1698
bool is_valid() const
Check validity of range.
Definition: JRange.hh:311
static T getMaximum()
Get maximum possible value.
Definition: JRange.hh:545
static T getMinimum()
Get minimum possible value.
Definition: JRange.hh:534
static const int JGANDALF_NUMBER_OF_HITS
number of hits from JGandalf.cc
static const int JGANDALF_CHI2
chi2 from JGandalf.cc
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
JPosition3D getPosition(const Vec &pos)
Get position.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:29
Double_t getX(const Double_t E, double constrain=false) const
Get abscissa value.
Definition: JVolume.hh:115
Double_t getXmax() const
Get maximal abscissa value.
Definition: JVolume.hh:102
Double_t getXmin() const
Get minimal abscissa value.
Definition: JVolume.hh:91
Detector file.
Definition: JHead.hh:227
Acoustic event fit.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:15
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20