Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDataPostfit.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 #include "TMath.h"
10 
12 #include "JReconstruction/JEvt.hh"
14 
15 #include "JAAnet/JHead.hh"
16 #include "JAAnet/JHeadToolkit.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 #include "JGeometry3D/JTrack3D.hh"
24 
25 #include "JGizmo/JVolume.hh"
28 #include "JSupport/JSupport.hh"
29 
35 #include "JAAnet/JHead.hh"
36 #include "JAAnet/JHeadToolkit.hh"
37 #include "JDAQ/JDAQEventIO.hh"
38 
39 /**
40  * \file
41  *
42  * Program to histogram fit results from reconstructed data
43  * \author bofearraigh, rgracia
44  */
45 int main(int argc, char **argv)
46 {
47  using namespace std;
48  using namespace JPP;
49 
50  using namespace KM3NETDAQ;
51 
52  typedef JTriggeredFileScanner<JEvt> JTriggeredFileScanner_t;
53  typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
54 
55  JTriggeredFileScanner<JEvt> inputFile; // Class to scan for reconstructed information only
56  JLimit_t& numberOfEvents = inputFile.getLimit();
57  string outputFile;
58  string option;
59  size_t numberOfPrefits; // The number of reconstructed tracks to plot per event (1 by default)
60  JQualitySorter quality_sorter; // The criterion by which to pick the "best" reconstructed track for each event.
61  int application;
62  int debug;
63 
64  try {
65 
66  JParser<> zap("Program to histogram fit results from reconstructed data.");
67 
68  zap['f'] = make_field(inputFile);
69  zap['o'] = make_field(outputFile) = "postfit.root";
70  zap['n'] = make_field(numberOfEvents) = JLimit::max();
71  zap['N'] = make_field(numberOfPrefits) = 1;
72  zap['A'] = make_field(application) = JMUONENERGY, JMUONPREFIT, JMUONSIMPLEX, JMUONGANDALF, JMUONSTART; //makes histograms after this stage of the reconstruction
74  zap['d'] = make_field(debug) = 2;
75 
76  zap(argc, argv);
77  }
78 
79  catch(const JException& error) {
80  FATAL(error);
81  }
82 
83  const double rad_to_deg = 180/M_PI;
84  const double R_m = 700.0;
85  const int MAX_OVERLAYS = 200;
86  const double zenith_min = -1.0;
87  const double zenith_max = 1.0;
88 
89  TFile out(outputFile.c_str(), "recreate");
90  TH1D hz ("hz", "; cos(#theta)" , 21 , zenith_min, zenith_max);
91  TH1D ho ("ho", "; #overlays" , MAX_OVERLAYS , -0.5, MAX_OVERLAYS-0.5);
92  TH2D hzo ("hzo", "; cos(#theta) ; #overlays" , 21, zenith_min, zenith_max, MAX_OVERLAYS , -0.5, MAX_OVERLAYS-0.5);
93  TH2D hxy ("hxy", "; x position ; y position" , 201, -R_m, R_m, 201, -R_m, R_m);
94  TH1D hq ("hq", "; quality parameter" , 100, -200.0, 800);
95  TH1D hb0 ("hb0", "; log(beta0)" , 60, -2, 3.5);
96  TH1D he ("he", "; log(Ereco [GeV])" , 75, -2, 4);
97  TH2D heo ("heo", "; log(Ereco [GeV]) ; #overlays" , 75, -2, 4, MAX_OVERLAYS , -0.5, MAX_OVERLAYS-0.5);
98  TH2D hzq ("hzq", "; cos(#theta); quality" , 21, zenith_min, zenith_max, 50, -10.0, 500.0);
99  TH2D hze ("hze", "; cos(#theta); log(Ereco [GeV])", 21, zenith_min, zenith_max, 75, -2, 4);
100  TH2D hzb0("hzb0", "; cos(#theta); log(beta0)" , 21, zenith_min, zenith_max, 60, -2, 3.5);
101 
102  while (inputFile.hasNext()) { // Loop over each reconstructed event
103 
104  multi_pointer_type ps = inputFile.next();
105 
106  JDAQEvent* tev = ps;
107  JEvt* evt = ps;
108 
109  if (!evt->empty()) {
110 
111  JEvt::iterator __end = partition(evt->begin(), evt->end(), JHistory::is_event(application));
112 
113  if (evt->begin() == __end) {
114  continue;
115  }
116 
117  if (numberOfPrefits > 0) {
118 
119  JEvt::iterator __q = __end;
120 
121  advance(__end = evt->begin(), min(numberOfPrefits, (size_t) distance(evt->begin(), __q)));
122 
123  partial_sort(evt->begin(), __end, __q, quality_sorter);
124 
125  } else {
126 
127  sort(evt->begin(), __end, quality_sorter);
128  }
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 
138  ho .Fill(tev->getOverlays());
139  hz .Fill(track.getDZ());
140  hzo.Fill(track.getDZ(), tev->getOverlays()) ;
141  hxy.Fill(track.getX(), track.getY());
142  hq .Fill(fit->getQ());
143  hzq.Fill(track.getDZ(), fit->getQ() );
144 
145  if (fit->hasW(JGANDALF_BETA0_RAD)) {
146  hb0 .Fill(log10( rad_to_deg* fit->getW(JGANDALF_BETA0_RAD) ));
147  hzb0.Fill(track.getDZ(), log10( rad_to_deg* fit->getW(JGANDALF_BETA0_RAD)) );
148  }
149  const double Efit = fit->getE();
150  he .Fill(log10(Efit));
151  hze.Fill(track.getDZ(), log10(Efit) );
152  heo.Fill(log10(Efit), tev->getOverlays() );
153  }
154  }
155  }
156 
157  out.Write();
158  out.Close();
159 }
static const int JMUONSTART
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
ROOT TTree parameter settings.
JTrack3E getTrack(const Trk &track)
Get track.
Synchronously read DAQ events and Monte Carlo events (and optionally other events).
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
General purpose sorter of fit results.
Definition: JEvtToolkit.hh:262
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
string outputFile
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
static const int JMUONPREFIT
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
Auxiliary class to test history.
Definition: JHistory.hh:104
static const int JMUONGANDALF
static const int JGANDALF_BETA0_RAD
KM3NeT Data Definitions v1.2.3 https://git.km3net.de/common/km3net-dataformat.
unsigned int getOverlays() const
Get number of overlays.
double getY() const
Get y position.
Definition: JVector3D.hh:103
int debug
debug level
Definition: JSirene.cc:61
Reconstruction type dependent comparison of track quality.
General purpose messaging.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Data structure for set of track fit results.
Definition: JEvt.hh:294
static const int JMUONSIMPLEX
Utility class to parse command line options.
double getX() const
Get x position.
Definition: JVector3D.hh:93
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:114
static const int JMUONENERGY
int main(int argc, char *argv[])
Definition: Main.cpp:15