Jpp
JPostfit2F.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 #include "TH2D.h"
9 
10 #include "evt/Head.hh"
11 #include "evt/Evt.hh"
12 #include "JAAnet/JAAnetToolkit.hh"
13 #include "JDAQ/JDAQEvent.hh"
16 #include "JSupport/JSupport.hh"
17 #include "JFit/JEvt.hh"
18 #include "JFit/JEvtToolkit.hh"
19 #include "JFit/JFitParameters.hh"
20 #include "JMath/JMathToolkit.hh"
21 
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 #include "JHistogramToolkit.hh"
26 
27 
28 /**
29  * \file
30  *
31  * Example program to compare fit results from two files.
32  * \author mdejong
33  */
34 int main(int argc, char **argv)
35 {
36  using namespace std;
37  using namespace JPP;
38 
39  typedef JTriggeredFileScanner<JEvt> JTriggeredFileScanner_t;
40  typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
41 
42  JTriggeredFileScanner_t inputFileA;
43  JTriggeredFileScanner_t inputFileB;
44  JLimit_t numberOfEvents;
45  string outputFile;
46  double angle_Deg;
47  int debug;
48 
49  try {
50 
51  JParser<> zap("Example program to compare fit results from two files.");
52 
53  zap['a'] = make_field(inputFileA);
54  zap['b'] = make_field(inputFileB);
55  zap['o'] = make_field(outputFile) = "postfit2f.root";
56  zap['n'] = make_field(numberOfEvents) = JLimit::max();
57  zap['A'] = make_field(angle_Deg) = 1.0;
58  zap['d'] = make_field(debug) = 2;
59 
60  zap(argc, argv);
61  }
62  catch(const exception& error) {
63  FATAL(error.what() << endl);
64  }
65 
66  JHead head;
67 
68  try {
69  head = getHeader(inputFileA);
70  }
71  catch(const JException& error) {
72  FATAL(error);
73  }
74  const double E_nu_min = head.cut_nu.Emin; //neutrino minimum energy
75  const double E_nu_max = head.cut_nu.Emax; //neutrino maximum energy
76 
77  inputFileA.setLimit(numberOfEvents);
78  inputFileB.setLimit(numberOfEvents);
79 
80 
81  TFile out(outputFile.c_str(), "recreate");
82 
83  JManager manager;
84 
85  manager.insert(make_key(JQUALITY), 101, 0.0, 250.0);
86  manager.insert(make_key(JGANDALF_BETA0_RAD), 51, 0.0, 2.0e-2);
87  manager.insert(make_key(JGANDALF_BETA1_RAD), 51, 0.0, 2.0e-2);
88  manager.insert(make_key(JGANDALF_NUMBER_OF_HITS), 51, 0.0, 100);
89  manager.insert(make_key(JSTART_NPE_MIP), 51, 0.0, 10.0);
90  manager.insert(make_key(JSTART_NPE_MIP_TOTAL), 51, 0.0, 10.0);
91  manager.insert(make_key(JSTART_LENGTH_METRES), 51, 0.0, 100.0);
92  manager.insert(make_key(JENERGY_ENERGY), 51, 1.0, 5.0, true);
93  manager.insert(make_key(JENERGY_CHI2), 51, 0.0, 200.0);
94 
95  TH1D hA("h[A]", NULL, 100, -3.0, +2.3); // [log(deg)]
96  TH1D hB("h[B]", NULL, 100, -3.0, +2.3); // [log(deg)]
97  TH2D hA_angle_E("hA_angle_E", NULL, 20, E_nu_min, E_nu_max, 100, 0,90); //energy vs angular deviation between true and reco muon direction
98  TH2D hB_angle_E("hB_angle_E", NULL, 20, E_nu_min, E_nu_max, 100, 0,90); //energy vs angular deviation between true and reco muon direction
99  TH2D h2("h2", NULL,
100  100, -100.0, +100.0, // quality
101  360, -180.0, +180.0); // deg
102 
103  while (inputFileA.hasNext() && inputFileB.hasNext()) {
104 
105  STATUS("event: " << setw(10) << inputFileA.getCounter() << '\r'); DEBUG(endl);
106 
107  multi_pointer_type psA = inputFileA.next();
108  multi_pointer_type psB = inputFileB.next();
109 
110  // find the same corresponding Monte Carlo true event based on the event identifier.
111 
112  while (psA.get<Evt>()->mc_id < psB.get<Evt>()->mc_id && inputFileA.hasNext()) { psA = inputFileA.next(); }
113  while (psB.get<Evt>()->mc_id < psA.get<Evt>()->mc_id && inputFileB.hasNext()) { psB = inputFileB.next(); }
114 
115  if (!psA.is_valid()) { continue; }
116  if (!psB.is_valid()) { continue; }
117 
118  if (psA.get<Evt>()->mc_id == psB.get<Evt>()->mc_id) {
119 
120  Evt* event = psA;
121  JEvt* evtA = psA;
122  JEvt* evtB = psB;
123 
124  const Trk neutrino = get_neutrino(*event);
125 
126  vector<Trk>::const_iterator muon = find_if(event->mc_trks.begin(), event->mc_trks.end(), is_muon);
127 
128  if (muon == event->mc_trks.end()) { continue; }
129 
130  if (evtA->empty()) { continue; }
131  if (evtB->empty()) { continue; }
132 
133  JEvt::const_iterator fitA = evtA->begin();
134  JEvt::const_iterator fitB = evtB->begin();
135 
136  const Double_t angleA = getAngle(getDirection(*muon), getDirection(*fitA));
137  const Double_t angleB = getAngle(getDirection(*muon), getDirection(*fitB));
138 
139  hA.Fill(log10(angleA));
140  hB.Fill(log10(angleB));
141 
142  h2.Fill(fitB->getQ() - fitA->getQ(), angleB - angleA);
143 
144  const double Enu = neutrino.E; //true neutrino E
145  hA_angle_E.Fill(Enu, angleA);
146  hB_angle_E.Fill(Enu, angleB);
147 
148  if (angleA > angle_Deg) {
149  manager.Fill(*fitA, *fitB, angleB < angle_Deg);
150  }
151  }
152  }
153  STATUS(endl);
154 
155  out.Write();
156  out.Close();
157 }
JQUALITY
static const int JQUALITY
fit quality identifier
Definition: JHistogramToolkit.hh:19
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JFIT::JENERGY_CHI2
chi2 from JEnergy.cc
Definition: JFitParameters.hh:22
JMessage.hh
JAANET::JHead::cut_nu
JAANET::cut_nu cut_nu
Definition: JHead.hh:1081
JFIT::JGANDALF_BETA0_RAD
angular resolution [rad] from JGandalf.cc
Definition: JFitParameters.hh:17
std::vector
Definition: JSTDTypes.hh:12
JEvtToolkit.hh
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JTriggeredFileScanner.hh
JGIZMO::JManager
Auxiliary class to manage set of compatible ROOT objects (e.g.
Definition: JManager.hh:40
JFIT::JEvt
Data structure for set of track fit results.
Definition: JEvt.hh:292
JAANET::is_muon
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
Definition: JAAnetToolkit.hh:367
JAANET::JHead
Monte Carlo run header.
Definition: JHead.hh:839
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JEvt.hh
JMathToolkit.hh
JSUPPORT::getHeader
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:425
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
JHistogramToolkit.hh
JAAnetToolkit.hh
make_key
#define make_key(PARAMETER)
Make key.
Definition: JHistogramToolkit.hh:63
JFIT::JENERGY_ENERGY
uncorrected energy [GeV] from JEnergy.cc
Definition: JFitParameters.hh:21
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JFIT::JGANDALF_NUMBER_OF_HITS
number of hits from JGandalf.cc
Definition: JFitParameters.hh:20
JFIT::JGANDALF_BETA1_RAD
angular resolution [rad] from JGandalf.cc
Definition: JFitParameters.hh:18
JParser.hh
JFIT::JSTART_NPE_MIP
number of photo-electrons up to the barycentre from JStart.cc
Definition: JFitParameters.hh:25
main
int main(int argc, char **argv)
Definition: JPostfit2F.cc:34
JAANET::getDirection
JDirection3D getDirection(const Vec &v)
Get direction.
Definition: JAAnetToolkit.hh:221
JSUPPORT::JTriggeredFileScanner
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
Definition: JTriggeredFileScanner.hh:39
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JFitParameters.hh
JFIT::JSTART_LENGTH_METRES
distance between first and last hits in metres from JStart.cc
Definition: JFitParameters.hh:27
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JDAQEvent.hh
JAANET::cut::Emax
double Emax
Maximal energy [GeV].
Definition: JHead.hh:211
JAANET::cut::Emin
double Emin
Minimal energy [GeV].
Definition: JHead.hh:210
JMonteCarloFileSupportkit.hh
JMATH::getAngle
double getAngle(const JFirst_t &first, const JSecond_t &second)
Get space angle between objects.
Definition: JMathToolkit.hh:146
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JFIT::JSTART_NPE_MIP_TOTAL
number of photo-electrons along the whole track from JStart.cc
Definition: JFitParameters.hh:26
JLANG::JException
General exception.
Definition: JException.hh:40