Jpp
Functions
JFitEfficiency.cc File Reference
#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/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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 40 of file JFitEfficiency.cc.

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 
107  JDetector detector;
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 }
JROOT::advance
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
qualitySorter
bool qualitySorter(const JFIT::JFit &first, const JFIT::JFit &second)
Comparison of fit results.
Definition: quality_sorter.cc:10
JFIT::JGANDALF_CHI2
chi2 from JGandalf.cc
Definition: JFitParameters.hh:19
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
JSUPPORT::JLimit_t
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:215
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JAANET::JHead
Monte Carlo run header.
Definition: JHead.hh:839
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JSUPPORT::getHeader
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:425
WARNING
#define WARNING(A)
Definition: JMessage.hh:65
debug
int debug
debug level
Definition: JSirene.cc:59
JAANET::get_neutrino
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
Definition: JAAnetToolkit.hh:438
JSUPPORT::JLimit::getLimit
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
JAANET::has_neutrino
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
Definition: JAAnetToolkit.hh:427
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JFIT::JGANDALF_NUMBER_OF_HITS
number of hits from JGandalf.cc
Definition: JFitParameters.hh:20
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37