Jpp
 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 "evt/Head.hh"
#include "evt/Evt.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JDAQ/JDAQEvent.hh"
#include "JTools/JConstants.hh"
#include "JTools/JRange.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JGizmo/JVolume.hh"
#include "JFit/JEvt.hh"
#include "JFit/JEvtToolkit.hh"
#include "JFit/JFitParameters.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 41 of file JFitEfficiency.cc.

42 {
43  using namespace std;
44  using namespace JPP;
45  using namespace KM3NETDAQ;
46 
47  typedef JTriggeredFileScanner<JEvt> JTriggeredFileScanner_t;
48  typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
49 
50  JTriggeredFileScanner_t inputFile;
51  JLimit_t& numberOfEvents = inputFile.getLimit();
52  string outputFile;
53  string detectorFile;
54  size_t numberOfPrefits;
55  JRange<double> E_GeV;
56  double quality;
57  bool logx;
58  bool containment;
59  int debug;
60 
61  try {
62 
63  JParser<> zap("Example program to histogram fit results.");
64 
65  zap['f'] = make_field(inputFile);
66  zap['o'] = make_field(outputFile) = "fitefficiency.root";
67  zap['a'] = make_field(detectorFile);
68  zap['n'] = make_field(numberOfEvents) = JLimit::max();
69  zap['N'] = make_field(numberOfPrefits) = 1;
70  zap['E'] = make_field(E_GeV) = JRange<double>(1.0, -1.0);
71  zap['Q'] = make_field(quality) = numeric_limits<double>::min();
72  zap['X'] = make_field(logx);
73  zap['C'] = make_field(containment);
74  zap['d'] = make_field(debug) = 1;
75 
76  zap(argc, argv);
77  }
78  catch(const exception& error) {
79  FATAL(error.what() << endl);
80  }
81 
82 
83 
84 
85  Head head;
86 
87  try {
88  head = getHeader(inputFile);
89  }
90  catch(const JException& error) {
91  FATAL(error);
92  }
93 
94  JHead buffer(head);
95  JVolume volume(head, logx);
96 
97  const double Xmax = E_GeV.is_valid() ? volume.getX(E_GeV.getMaximum()) : volume.getXmax();
98  const double Xmin = E_GeV.is_valid() ? volume.getX(E_GeV.getMinimum()) : volume.getXmin();
99 
100  TFile out(outputFile.c_str(), "recreate");
101 
102  TH1D* hN = new TH1D("hN", NULL, 25, Xmin, Xmax);
103  TH1D* he = new TH1D("he", NULL, 25, Xmin, Xmax);
104 
105  hN->Sumw2();
106  he->Sumw2();
107 
108  JDetector detector;
109 
110  try {
111  load(detectorFile, detector);
112  }
113  catch(const JException& error) {
114  FATAL(error);
115  }
116 
117  JCylinder3D cylinder(detector.begin(), detector.end());
118 
119  STATUS("Detector Geometry:" << endl);
120  STATUS("Zmin: " << cylinder.getZmin() << endl);
121  STATUS("Zmax: " << cylinder.getZmax() << endl);
122  STATUS("Z origin: " << 0.5 * (cylinder.getZmax() + cylinder.getZmin()) << endl);
123  STATUS("Radius: " << cylinder.getRadius() << endl);
124 
125  while (inputFile.hasNext()) {
126 
127  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
128 
129  multi_pointer_type ps = inputFile.next();
130 
131  //JDAQEvent* tev = ps;
132  JEvt* evt = ps;
133  Evt* event = ps;
134 
135  if (has_neutrino(*event)) {
136 
137  Trk neutrino = get_neutrino(*event);
138  const double X = volume.getX(neutrino.E);
139 
140  hN->Fill(X);
141 
142  if (!evt->empty()) {
143 
144  JEvt::iterator __end = evt->end();
145 
146  if (numberOfPrefits > 0) {
147 
148  advance(__end = evt->begin(), min(numberOfPrefits, evt->size()));
149 
150  partial_sort(evt->begin(), __end, evt->end(), qualitySorter);
151  }
152 
153 
154  for(JEvt::const_iterator track = evt->begin(); track != __end; ++track) {
155 
156  JPosition3D pos = getPosition(*track);
157 
158  const double R = sqrt(pos.getX() * pos.getX() + pos.getY() * pos.getY());
159 
160  if ((pos.getZ() > cylinder.getZmin()
161  && pos.getZ() < cylinder.getZmax()
162  && R < cylinder.getRadius())
163  || !containment) {
164 
165  double Q = 0.0;
166 
167  if(track->hasW(JGANDALF_CHI2) && track->hasW(JGANDALF_NUMBER_OF_HITS)) {
168  Q = -track->getW(JGANDALF_CHI2)/track->getW(JGANDALF_NUMBER_OF_HITS);
169  }
170  else {
171  Q = track->getQ();
172  }
173 
174  if (Q > quality) {
175  he->Fill(X);
176  }
177  }
178  }
179  }
180  }
181  else {
182  WARNING("No neutrino." << endl);
183  }
184  }
185  STATUS(endl);
186 
187  he->Divide(hN);
188 
189  out.Write();
190  out.Close();
191 }
Utility class to parse command line options.
Definition: JParser.hh:1410
#define WARNING(A)
Definition: JMessage.hh:63
#define STATUS(A)
Definition: JMessage.hh:61
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
chi2 from JGandalf.cc
string outputFile
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:214
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:59
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Definition: JCounter.hh:35
Monte Carlo run header.
Definition: JHead.hh:727
#define FATAL(A)
Definition: JMessage.hh:65
number of hits from JGandalf.cc
bool qualitySorter(const JFIT::JFit &first, const JFIT::JFit &second)
Comparison of fit results.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:72
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
JPosition3D getPosition(const Vec &v)
Get position.