Jpp
Functions
JShowerPostfit.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TProfile.h"
#include "TMath.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/online/JDAQModuleIdentifier.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JTools/JConstants.hh"
#include "JTools/JQuantile.hh"
#include "JTrigger/JTimeConverter.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JFit/JEvt.hh"
#include "JFit/JEvtToolkit.hh"
#include "JFit/JFitParameters.hh"
#include "JGizmo/JVolume.hh"
#include "JLang/JPredicate.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 results.

Author
mdejong and adomi -> This code is an adaptation of JPostfit to JShowerFit reconstruction

Definition in file JShowerPostfit.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 75 of file JShowerPostfit.cc.

76 {
77  using namespace std;
78  using namespace JPP;
79  using namespace KM3NETDAQ;
80 
81  typedef JTriggeredFileScanner<JEvt> JTriggeredFileScanner_t;
82  typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
83 
84  JTriggeredFileScanner_t inputFile;
85  JLimit_t& numberOfEvents = inputFile.getLimit();
86  string outputFile;
87  size_t numberOfPrefits;
89  JAtmosphericMuon atmosphere;
90  double Emin_GeV;
91  double NPE;
92  int application;
93  string option;
94  bool isMuon;
95  int debug;
96 
97  try {
98 
99  JParser<> zap("Example program to histogram fit results.");
100 
101  zap['f'] = make_field(inputFile);
102  zap['o'] = make_field(outputFile) = "postfit.root";
103  zap['n'] = make_field(numberOfEvents) = JLimit::max();
104  zap['N'] = make_field(numberOfPrefits) = 1;
106  zap['E'] = make_field(Emin_GeV) = 0.0;
107  zap['M'] = make_field(NPE) = 0.0;
108  zap['A'] = make_field(application) = JSHOWERPREFIT, JSHOWERPOSITIONFIT, JSHOWERCOMPLETEFIT;
109  zap['a'] = make_field(atmosphere) = JAtmosphericMuon(90.0, 90.0);
110  zap['O'] = make_field(option) = "E", "N", "LINE", "LOGE";
111  zap['I'] = make_field(isMuon);
112  zap['d'] = make_field(debug) = 2;
113 
114  zap(argc, argv);
115  }
116  catch(const exception& error) {
117  FATAL(error.what() << endl);
118  }
119 
120  cout << "APPLICATION " << application << endl;
121 
122  JHead head;
123 
124  try {
125  head = getHeader(inputFile);
126  }
127  catch(const JException& error) {
128  FATAL(error);
129  }
130 
131  const JVolume volume(head, option != "LINE");
132  const JPosition3D center = get<JPosition3D>(head);
133  JCylinder3D cylinder = get<JCylinder3D>(head);
134 
135  cylinder.add(center);
136 
137  NOTICE("Reposition can [m]: " << cylinder << endl);
138 
139  const double EMIN_GEV = 10e3; // MUPAGE
140 
141  TFile out(outputFile.c_str(), "recreate");
142 
143  TH1D job("job", NULL, 100, 0.5, 100.5);
144 
145  TH1D hn("hn", NULL, 250, -0.5, 249.5);
146  TH1D hq("hq", NULL, 300, 0.0, 600.0);
147  TH1D hi("hi", NULL, 101, -0.5, 100.5);
148  TH1D hv("hv", NULL, 200, -6.0, 0.0);
149  TH1D h1("h1", NULL, 200, -2.0, +2.0);
150  TH1D hc("hc", NULL, 200, -1.0, +1.0);
151  TH1D hu("hu", NULL, 400, -1.0e3, 1.0e3);
152 
153  TH1D hx("hx", NULL, 100, -3.0, +2.3); // [log(deg)]
154  TH1D hd("hd", NULL, 100, 0.0, 10.0); // [m]
155  TH1D hz("hz", NULL, 100, -200.0, 200.0); // [m]
156  TH1D ht("ht", NULL, 100, -100.0, 100.0); // [ns]
157 
158  TH1D e0("e0", NULL, 100, volume.getXmin(), volume.getXmax()); // [log(E)]
159  TH1D e1("e1", NULL, 100, volume.getXmin(), volume.getXmax()); // [log(E)]
160  TH1D e2("e2", NULL, 100, volume.getXmin(), volume.getXmax()); // [log(E)]
161  TH1D er("er", NULL, 100, -5.0, +5.0); // [log(E/E)]
162  TH2D ee("ee", NULL,
163  40, volume.getXmin(), volume.getXmax(),
164  40, volume.getXmin(), volume.getXmax());
165 
166  TH2D hAngle ("hAngle", ";E_{TRUE};angle [#circ]", 100, volume.getXmin(), volume.getXmax(), 360, 0, 180.0);
167 
168  const Int_t ny = 28800;
169  const Double_t ymin = 0.0; // [deg]
170  const Double_t ymax = 180.0; // [deg]
171 
172  vector<double> X;
173 
174  if (option.find('E') != string::npos) {
175 
176  for (double x = volume.getXmin(); x <= volume.getXmax(); x += (volume.getXmax() - volume.getXmin()) / 20) {
177  X.push_back(x);
178  }
179 
180  } else {
181 
182  double x = -0.5;
183 
184  for ( ; x <= 15.5; x += 1.0) { X.push_back(x); }
185  for ( ; x <= 25.5; x += 2.0) { X.push_back(x); }
186  for ( ; x <= 50.5; x += 5.0) { X.push_back(x); }
187  for ( ; x <= 100.5; x += 10.0) { X.push_back(x); }
188  for ( ; x <= 250.5; x += 20.0) { X.push_back(x); }
189  }
190 
191  TH2D h2("h2", NULL, X.size() - 1, X.data(), ny, ymin, ymax);
192  TProfile he("he", NULL, X.size() - 1, X.data());
193 
194  TH2D ha("ha", NULL, 100, 0.0, 0.5e6, 100, -100.0, +900.0);
195  TH2D hb("hb", NULL, 100, 0.0, 0.5e6, 100, -100.0, +900.0);
196 
197  JQuantile Q("Angle", true);
198  JQuantile O("Omega", true);
199 
200 
201  while (inputFile.hasNext()) {
202 
203  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
204 
205  multi_pointer_type ps = inputFile.next();
206 
207  JDAQEvent* tev = ps;
208  JEvt* evt = ps;
209  Evt* event = ps;
210 
211  const JTimeConverter converter(*event, *tev);
212 
213  job.Fill(1.0);
214 
215  double Emu = 0.0;
216  double Emax = 0.0;
217 
218  vector<Trk>::const_iterator lepton = event->mc_trks.end(); // can be electron or muon
219  // vector<Trk>::const_iterator electron = event->mc_trks.end();
220 
221  for (vector<Trk>::const_iterator shower = event->mc_trks.begin(); shower != event->mc_trks.end(); ++shower) {
222 
223  if (!isMuon && is_electron(*shower)) {
224 
225  Emu += shower->E;
226 
227  if (shower->E > Emax) {
228  lepton = shower;
229  Emax = shower->E;
230  }
231  } else if(isMuon && is_muon(*shower)){
232 
233  Emu += shower->E;
234  if (shower->E > Emax) {
235  lepton = shower;
236  Emax = shower->E;
237  }
238  }
239  }
240 
241  if (lepton == event->mc_trks.end()) {
242  continue;
243  }
244 
245  job.Fill(3.0);
246 
247 
248  // abscissa
249 
250  Double_t x = 0.0;
251 
252  if (option.find('E') != string::npos)
253  x = volume.getX(event->mc_trks[0].E);
254  else
255  x = getCount(tev->begin<JDAQTriggeredHit>(), tev->end<JDAQTriggeredHit>());
256 
257 
258  // weight for efficiency determination
259 
260  Double_t W = 0.0;
261 
262  if (!evt->empty()) {
263 
264  JEvt::iterator __end = partition(evt->begin(), evt->end(), JHistory::is_event(application));
265 
266  if (evt->begin() == __end) {
267  continue;
268  }
269 
270  job.Fill(4.0);
271 
272  if (numberOfPrefits > 0) {
273 
274  JEvt::iterator __q = __end;
275 
276  advance(__end = evt->begin(), min(numberOfPrefits, (size_t) distance(evt->begin(), __q)));
277 
278  partial_sort(evt->begin(), __end, __q, quality_sorter);
279 
280  } else {
281 
282  sort(evt->begin(), __end, quality_sorter);
283  }
284 
285  const JPointing pointing(getDirection(*lepton));
286 
287  JEvt::iterator best = pointing(evt->begin(), __end);
288  const Double_t beta = pointing.getAngle(*best);
289  const double Efit = best->getE();
290  const double Eraw = best->getW(JENERGY_ENERGY, numeric_limits<double>::min());
291  const double mip = best->getW(JSTART_NPE_MIP, numeric_limits<double>::max());
292  //const double npe = best->getW(JVETO_NPE, 0.0);
293  //const int count = best->getW(JVETO_NUMBER_OF_HITS, 0.0);
294 
295  // selection of fit result
296 
297  bool ok = (Efit >= Emin_GeV &&
298  mip >= NPE);
299 
300  if (ok) {
301 
302  W = 1.0;
303 
304  job.Fill(5.0);
305 
306  hn.Fill((Double_t) best->getNDF());
307  hq.Fill(best->getQ());
308  hi.Fill((Double_t) distance(evt->begin(), best));
309  hc.Fill(best->getDZ());
310 
311  if (( has_neutrino(*event) && get_neutrino(*event).dir.z >= atmosphere.dot2) ||
312  (!has_neutrino(*event) && best->getDZ() >= atmosphere.dot2)) {
313  hu.Fill(atmosphere(evt->begin(), __end));
314  }
315 
316  hx.Fill(max(log10(beta), hx.GetXaxis()->GetXmin()));
317 
318  Q.put(beta);
319 
320  JTrack3E ta = getTrack(*lepton);
321  JTrack3E tb = getTrack(*best);
322 
323  ta.add(center);
324  tb.sub(converter.putTime());
325 
326  //ta.move(ta.getIntersection(tb), getSpeedOfLight(), gWater);
327  //tb.move(tb.getIntersection(ta), getSpeedOfLight(), gWater);
328  static_cast<JTrack3D&>(ta).move(ta.getIntersection(tb), getSpeedOfLight());
329  static_cast<JTrack3D&>(tb).move(tb.getIntersection(ta), getSpeedOfLight());
330 
331  hd.Fill((tb.getPosition() - ta.getPosition()).getLength());
332 
333  if (has_neutrino(*event)) {
334 
335  job.Fill(6.0);
336 
337  JPosition3D vertex = getPosition(get_neutrino(*event));
338 
339  vertex.add(center);
340 
341  if (cylinder.is_inside(vertex)) {
342 
343  job.Fill(7.0);
344 
345  JTrack3E tc = getTrack(*best);
346 
347  ha.Fill(best->getX()*best->getX() + best->getY()*best->getY(), best->getZ());
348  hz.Fill(tc.getIntersection(vertex));
349  }
350  }
351 
352  if (best->getE() >= EMIN_GEV) {
353  hb.Fill(best->getX()*best->getX() + best->getY()*best->getY(), best->getZ());
354  }
355 
356  ht.Fill(tb.getT() - ta.getT());
357 
358  e0.Fill(volume.getX(Emu, true));
359  e1.Fill(volume.getX(Eraw, true));
360  e2.Fill(volume.getX(Efit, true));
361  er.Fill(volume.getX(Efit) - volume.getX(Emu));
362  ee.Fill(volume.getX(Emu), volume.getX(Efit));
363 
364  hAngle.Fill(Efit, beta);
365  h2.Fill(x, beta);
366 
367  if (best->hasW(JSTART_NPE_MIP)) {
368  h1.Fill(log10(best->getW(JSTART_NPE_MIP)));
369  }
370 
371  if (best->hasW(JVETO_NPE) && best->hasW(JVETO_NUMBER_OF_HITS)) {
372 
373  const double npe = best->getW(JVETO_NPE);
374  const int count = best->getW(JVETO_NUMBER_OF_HITS);
375  const double pv = TMath::PoissonI(count, npe);
376 
377  hv.Fill(max(log10(pv), hv.GetXaxis()->GetXmin()));
378  }
379  }
380  }
381 
382  he.Fill(x, W);
383  }
384  STATUS(endl);
385 
386  NOTICE("Number of events input " << setw(8) << right << job.GetBinContent(1) << endl);
387  if(!isMuon){
388  NOTICE("Number of events with electron " << setw(8) << right << job.GetBinContent(3) << endl);
389  } else{
390  NOTICE("Number of events with muon " << setw(8) << right << job.GetBinContent(3) << endl);
391  }
392  NOTICE("Number of events with fit " << setw(8) << right << job.GetBinContent(4) << endl);
393  NOTICE("Number of events selected " << setw(8) << right << job.GetBinContent(5) << endl);
394  NOTICE("Number of events with neutrino " << setw(8) << right << job.GetBinContent(6) << endl);
395  NOTICE("Number of events contained " << setw(8) << right << job.GetBinContent(7) << endl);
396 
397  if (Q.getCount() != 0) {
398  NOTICE("Median space angle [deg] " << FIXED (6,3) << Q.getQuantile(0.5) << endl);
399  }
400 
401  out.Write();
402  out.Close();
403 }
JSHOWERPOSITIONFIT
static const int JSHOWERPOSITIONFIT
Definition: reconstruction.hh:24
JGEOMETRY3D::JTrack3D::sub
JTime & sub(const JTime &value)
Subtraction operator.
Definition: JGeometry3D/JTime.hh:80
KM3NETDAQ::JDAQEvent
DAQ Event.
Definition: JDAQEvent.hh:30
Vec::z
double z
Definition: Vec.hh:14
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JTOOLS::getSpeedOfLight
const double getSpeedOfLight()
Number of bytes in a gigabyte.
Definition: JConstants.hh:89
KM3NETDAQ::JDAQEvent::begin
const_iterator< T > begin() const
Get begin of data.
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
JFIT::JAtmosphericMuon::dot2
double dot2
Definition: JEvtToolkit.hh:718
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
JGEOMETRY3D::JCylinder3D::is_inside
bool is_inside(const JVector3D &pos) const
Check whether given point is inside cylinder.
Definition: JCylinder3D.hh:199
std::vector< double >
Evt
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
JGEOMETRY3D::JCylinder3D::add
JCylinder3D & add(const JVector3D &pos)
Add position.
Definition: JCylinder3D.hh:146
JTRIGGER::JTimeConverter
Auxiliary class to convert DAQ/trigger hit time to/from Monte Carlo hit time.
Definition: JTimeConverter.hh:36
JAANET::getTrack
JTrack3E getTrack(const Trk &track)
Get track.
Definition: JAAnetToolkit.hh:256
JSHOWERCOMPLETEFIT
static const int JSHOWERCOMPLETEFIT
Definition: reconstruction.hh:25
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
JFIT::JEvt
Data structure for set of track fit results.
Definition: JEvt.hh:293
JGEOMETRY3D::JTrack3D::getT
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition: JTrack3D.hh:126
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
Trk::dir
Vec dir
track direction
Definition: Trk.hh:16
KM3NETDAQ::JDAQEvent::end
const_iterator< T > end() const
Get end of data.
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
KM3NETDAQ::JDAQTriggeredHit
DAQ triggered hit.
Definition: JDAQTriggeredHit.hh:20
JGEOMETRY3D::JCylinder3D
Cylinder object.
Definition: JCylinder3D.hh:37
JSUPPORT::getHeader
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:458
JSTART_NPE_MIP
static const int JSTART_NPE_MIP
number of photo-electrons up to the barycentre from JStart.cc
Definition: fitparameters.hh:20
JFIT::JQualitySorter
General purpose sorter of fit results.
Definition: JEvtToolkit.hh:239
JGEOMETRY3D::JTrack3D::add
JTime & add(const JTime &value)
Addition operator.
Definition: JGeometry3D/JTime.hh:66
debug
int debug
debug level
Definition: JSirene.cc:59
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
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
JGEOMETRY3D::JTrack3E
3D track with energy.
Definition: JTrack3E.hh:29
JGIZMO::JVolume
Auxiliary class for histogramming of effective volume.
Definition: JVolume.hh:26
JFIT::JHistory::is_event
Auxiliary class to test history.
Definition: JHistory.hh:101
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JTOOLS::JQuantile
Quantile calculator.
Definition: JQuantile.hh: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
JGEOMETRY3D::JPosition3D::getPosition
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
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
JAANET::is_electron
bool is_electron(const Trk &track)
Test whether given track is a (anti-)electron.
Definition: JAAnetToolkit.hh:359
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JSHOWERPREFIT
static const int JSHOWERPREFIT
Definition: reconstruction.hh:23
JGEOMETRY3D::JAxis3D::getIntersection
double getIntersection(const JVector3D &pos) const
Get longitudinal position along axis of position of closest approach with given position.
Definition: JAxis3D.hh:157
JVETO_NPE
static const int JVETO_NPE
number of photo-electrons from JVeto.cc
Definition: fitparameters.hh:23
JFIT::JPointing
Auxiliary class to compare fit results with respect to a reference direction (e.g.
Definition: JEvtToolkit.hh:533
JGEOMETRY3D::JVector3D::add
JVector3D & add(const JVector3D &vector)
Add vector.
Definition: JVector3D.hh:141
JENERGY_ENERGY
static const int JENERGY_ENERGY
uncorrected energy [GeV] from JEnergy.cc
Definition: fitparameters.hh:16
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JVETO_NUMBER_OF_HITS
static const int JVETO_NUMBER_OF_HITS
number of hits from JVeto.cc
Definition: fitparameters.hh:24
JFIT::JAtmosphericMuon
Auxiliary class to evaluate atmospheric muon hypothesis.
Definition: JEvtToolkit.hh:624
JLANG::JException
General exception.
Definition: JException.hh:23
JFIT::getCount
int getCount(const JHitL0 &hit)
Get hit count.
Definition: JEvtToolkit.hh:728
JAANET::quality_sorter
Reconstruction type dependent comparison of track quality.
Definition: JAAnetToolkit.hh:670