Jpp - 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 
82 
83  Head head;
84 
85  try {
86  head = getHeader(inputFile);
87  }
88  catch(const JException& error) {
89  FATAL(error);
90  }
91 
92  JHead buffer(head);
93  JVolume volume(head, logx);
94 
95  const double Xmax = E_GeV.is_valid() ? volume.getX(E_GeV.getMaximum()) : volume.getXmax();
96  const double Xmin = E_GeV.is_valid() ? volume.getX(E_GeV.getMinimum()) : volume.getXmin();
97 
98  TFile out(outputFile.c_str(), "recreate");
99 
100  TH1D* hN = new TH1D("hN", NULL, 25, Xmin, Xmax);
101  TH1D* he = new TH1D("he", NULL, 25, Xmin, Xmax);
102 
103  hN->Sumw2();
104  he->Sumw2();
105 
107 
108  try {
109  load(detectorFile, detector);
110  }
111  catch(const JException& error) {
112  FATAL(error);
113  }
114 
115  JCylinder3D cylinder(detector.begin(), detector.end());
116 
117  STATUS("Detector Geometry:" << endl);
118  STATUS("Zmin: " << cylinder.getZmin() << endl);
119  STATUS("Zmax: " << cylinder.getZmax() << endl);
120  STATUS("Z origin: " << 0.5 * (cylinder.getZmax() + cylinder.getZmin()) << endl);
121  STATUS("Radius: " << cylinder.getRadius() << endl);
122 
123  while (inputFile.hasNext()) {
124 
125  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
126 
127  multi_pointer_type ps = inputFile.next();
128 
129  //JDAQEvent* tev = ps;
130  JEvt* evt = ps;
131  Evt* event = ps;
132 
133  if (has_neutrino(*event)) {
134 
135  Trk neutrino = get_neutrino(*event);
136  const double X = volume.getX(neutrino.E);
137 
138  hN->Fill(X);
139 
140  if (!evt->empty()) {
141 
142  JEvt::iterator __end = evt->end();
143 
144  if (numberOfPrefits > 0) {
145 
146  advance(__end = evt->begin(), min(numberOfPrefits, evt->size()));
147 
148  partial_sort(evt->begin(), __end, evt->end(), qualitySorter);
149  }
150 
151 
152  for(JEvt::const_iterator track = evt->begin(); track != __end; ++track) {
153 
154  JPosition3D pos = getPosition(*track);
155 
156  const double R = sqrt(pos.getX() * pos.getX() + pos.getY() * pos.getY());
157 
158  if ((pos.getZ() > cylinder.getZmin()
159  && pos.getZ() < cylinder.getZmax()
160  && R < cylinder.getRadius())
161  || !containment) {
162 
163  double Q = 0.0;
164 
165  if(track->hasW(JGANDALF_CHI2) && track->hasW(JGANDALF_NUMBER_OF_HITS)) {
166  Q = -track->getW(JGANDALF_CHI2)/track->getW(JGANDALF_NUMBER_OF_HITS);
167  }
168  else {
169  Q = track->getQ();
170  }
171 
172  if (Q > quality) {
173  he->Fill(X);
174  }
175  }
176  }
177  }
178  }
179  else {
180  WARNING("No neutrino." << endl);
181  }
182  }
183  STATUS(endl);
184 
185  he->Divide(hN);
186 
187  out.Write();
188  out.Close();
189 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
#define WARNING(A)
Definition: JMessage.hh:65
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:80
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:19
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:26
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:196
Acoustic event fit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
JPosition3D getPosition(const Vec &pos)
Get position.
then break fi done getCenter read X Y Z let X
double getY() const
Get y position.
Definition: JVector3D.hh:104
int debug
debug level
Definition: JSirene.cc:63
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:1113
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:67
#define FATAL(A)
Definition: JMessage.hh:67
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR set_variable NORTH set_variable EAST set_variable SOUTH set_variable WEST set_variable WORKDIR tmp set_variable R set_variable CT set_variable YMAX set_variable YMIN if do_usage *then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:35
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
double getX() const
Get x position.
Definition: JVector3D.hh:94
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
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.
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:13
double getZ() const
Get z position.
Definition: JVector3D.hh:115
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