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