Jpp  18.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JFitEfficiency.cc File Reference

Example program to histogram fit efficiency. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JAAnet/JVolume.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JTools/JRange.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JReconstruction/JEvt.hh"
#include "JReconstruction/JEvtToolkit.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 fit efficiency.

Author
lquinn

Definition in file JFitEfficiency.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 39 of file JFitEfficiency.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
Q(UTCMax_s-UTCMin_s)-livetime_s
#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:89
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
string outputFile
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
bool qualitySorter(const JFit &first, const JFit &second)
Comparison of fit results.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:29
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
Cylinder object.
Definition: JCylinder3D.hh:39
Detector file.
Definition: JHead.hh:226
Acoustic event fit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
JPosition3D getPosition(const Vec &pos)
Get position.
double getY() const
Get y position.
Definition: JVector3D.hh:104
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:1221
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
#define FATAL(A)
Definition: JMessage.hh:67
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double getX() const
Get x position.
Definition: JVector3D.hh:94
no fit printf nominal n $STRING awk v X
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
static const int JGANDALF_CHI2
chi2 from JGandalf.cc
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
do set_variable DETECTOR_TXT $WORKDIR detector
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
then echo WARNING
Definition: JTuneHV.sh:91
double getZ() const
Get z position.
Definition: JVector3D.hh:115
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