Jpp
JPlotData.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 "JFit/JEvt.hh"
11 #include "JFit/JEvtToolkit.hh"
12 #include "JFit/JFitParameters.hh"
13 #include "JFit/JFitApplications.hh"
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 #include "JDetector/JDetector.hh"
20 
21 #include "JGeometry3D/JTrack3D.hh"
24 
26 #include "JSupport/JSupport.hh"
27 
28 /**
29  * \file
30  *
31  * Example program to produce some standard plots of reconstructed data
32  * \author lquinn
33  */
34 int main(int argc, char **argv)
35 {
36  using namespace std;
37  using namespace JPP;
38 
39  JMultipleFileScanner<JEvt> inputFile; // Class to scan for reconstructed information only
40  JLimit_t& numberOfEvents = inputFile.getLimit();
41  string outputFile;
42  string detectorFile;
43  size_t numberOfPrefits; // The number of reconstructed tracks to plot per event (1 by default)
44  JQualitySorter quality_sorter; // The criterion by which to pick the "best" reconstructed track for each event.
45  int application;
46  int debug;
47 
48  try {
49 
50  JParser<> zap("Example program to histogram fit results.");
51 
52  zap['f'] = make_field(inputFile);
53  zap['o'] = make_field(outputFile) = "postfit.root";
54  zap['a'] = make_field(detectorFile);
55  zap['n'] = make_field(numberOfEvents) = JLimit::max();
56  zap['N'] = make_field(numberOfPrefits) = 1;
58  zap['L'] = make_field(quality_sorter) = JPARSER::initialised();
59  zap['d'] = make_field(debug) = 2;
60 
61  zap(argc, argv);
62  }
63  catch(const exception& error) {
64  FATAL(error.what() << endl);
65  }
66 
67 
68 
69  JDetector detector;
70 
71  try {
72  load(detectorFile, detector);
73  }
74  catch(const JException& error) {
75  FATAL(error);
76  }
77 
78  JCylinder3D cylinder(detector.begin(), detector.end()); // Get detector geometry
79 
80  const double R_m = 2.0 * cylinder.getRadius();
81  const double zmin = -2.0 * cylinder.getZmin();
82  const double zmax = 2.0 * cylinder.getZmax();
83 
84  TFile out(outputFile.c_str(), "recreate");
85  TH1D job("job", "", 2, -0.5, 1.5);
86  TH1D hz ("hz ", "", 21 , -1.0, 1.0); // Zenith angle
87  TH2D hxy("hxy", "", 201, -R_m, R_m, 201, -200.0, 200.0); // X and Y position distribution
88  TH2D hzR("hzR", "", 201, 0.0, R_m, 201, zmin, zmax); // Z and R position distribution
89  TH1D hq1("hq1", "", 200, -50.0, 150); // Reconstruction quality (JPrefit and JSimplex)
90  TH1D hq2("hq2", "", 200, -5.0, 5.0); // Reconstruction quality (JGandalf)
91  TH1D hmu("hmu", "", 100, -50, 50); // Atmospheric muon rejection parameter
92  TH2D hmz("hmz", "", 100, -50, 50, 21, -1.0, 1.0); // Zenith angle vs atmospheric muon rejection parameter
93  TH2D hqz("hqz", "", 200, -5, 5, 21, -1.0, 1.0); // Zenith angle vs reconstruction quality (JGandalf)
94 
95  JAtmosphericMuon isAtmosphericMuon;
96 
97  while (inputFile.hasNext()) { // Loop over each reconstructed event
98 
99  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
100 
101  JEvt* evt = inputFile.next();
102 
103  if (!evt->empty()) {
104 
105  job.Fill(1.0);
106 
107  JEvt::iterator __end = partition(evt->begin(), evt->end(), JHistory::is_event(application));
108 
109  if (evt->begin() == __end) {
110  continue;
111  }
112 
113  if (numberOfPrefits > 0) {
114 
115  JEvt::iterator __q = __end;
116 
117  advance(__end = evt->begin(), min(numberOfPrefits, (size_t) distance(evt->begin(), __q)));
118 
119  partial_sort(evt->begin(), __end, __q, quality_sorter);
120 
121  } else {
122 
123  sort(evt->begin(), __end, quality_sorter);
124  }
125 
126  const double muon_probability = isAtmosphericMuon(evt->begin(), __end);
127 
128  hmu.Fill(muon_probability);
129 
130  if (numberOfPrefits > 0) {
131  advance(__end = evt->begin(), min(numberOfPrefits, evt->size()));
132  }
133 
134  for (JEvt::const_iterator fit = evt->begin(); fit != __end; ++fit) {
135 
136  JTrack3D track = getTrack(*fit);
137  track.sub(cylinder.getCenter());// Move the coordinate system so that (0,0,0) is the centre of the detector
138 
139  hz.Fill(track.getDZ());
140  hxy.Fill(track.getX(), track.getY());
141  hzR.Fill(sqrt(track.getX()*track.getX() + track.getY()*track.getY()), track.getZ());
142  hq1.Fill(fit->getQ());
143  hmz.Fill(muon_probability, track.getDZ());
144 
145  if (fit->hasW(JGANDALF_CHI2) && fit->hasW(JGANDALF_NUMBER_OF_HITS)) {
146 
147  const double lambda = fit->getW(JGANDALF_CHI2)/fit->getW(JGANDALF_NUMBER_OF_HITS);
148 
149  hq2.Fill(lambda);
150  hqz.Fill(lambda, track.getDZ());
151  }
152  }
153  }
154  else {
155  job.Fill(0.0);
156  }
157  }
158 
159  NOTICE("Number of events input " << setw(8) << right << job.GetBinContent(1) << endl);
160  NOTICE("Number of events with direction fit" << setw(8) << right << job.GetBinContent(2) << endl);
161 
162  out.Write();
163  out.Close();
164 }
JFIT::JMUONSIMPLEX
JSimplex.cc.
Definition: JFitApplications.hh:24
JFIT::JMUONENERGY
JEnergy.cc.
Definition: JFitApplications.hh:26
JFitApplications.hh
JMessage.hh
JFIT::JMUONGANDALF
JGandalf.cc.
Definition: JFitApplications.hh:25
JTrack3D.hh
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
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
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
JFIT::JMUONSTART
JStart.cc.
Definition: JFitApplications.hh:27
JEvtToolkit.hh
JSUPPORT::JLimit_t
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:215
JAANET::getTrack
JTrack3E getTrack(const Trk &track)
Get track.
Definition: JAAnetToolkit.hh:256
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JEvt.hh
JFIT::JMUONPREFIT
JPrefit.cc.
Definition: JFitApplications.hh:23
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JLimit::getLimit
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
JMultipleFileScanner.hh
JFIT::JMUONPATH
JPath.cc.
Definition: JFitApplications.hh:41
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JFIT::JGANDALF_NUMBER_OF_HITS
number of hits from JGandalf.cc
Definition: JFitParameters.hh:20
JParser.hh
JDetectorToolkit.hh
main
int main(int argc, char **argv)
Definition: JPlotData.cc:34
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JFitParameters.hh
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JCylinder3D.hh
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JGeometry3DToolkit.hh