Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPostfit.cc File Reference

Example program to histogram fit results. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TProfile.h"
#include "evt/Head.hh"
#include "evt/Evt.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JDAQ/JDAQEvent.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

Definition in file JPostfit.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 72 of file JPostfit.cc.

73 {
74  using namespace std;
75  using namespace JPP;
76  using namespace KM3NETDAQ;
77 
78  typedef JTriggeredFileScanner<JEvt> JTriggeredFileScanner_t;
79  typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
80 
81  JTriggeredFileScanner_t inputFile;
82  JLimit_t& numberOfEvents = inputFile.getLimit();
83  string outputFile;
84  size_t numberOfPrefits;
85  JQualitySorter quality_sorter;
86  JAtmosphericMuon atmosphere;
87  double Emin_GeV;
88  double NPE;
89  int application;
90  string option;
91  int debug;
92 
93  try {
94 
95  JParser<> zap("Example program to histogram fit results.");
96 
97  zap['f'] = make_field(inputFile);
98  zap['o'] = make_field(outputFile) = "postfit.root";
99  zap['n'] = make_field(numberOfEvents) = JLimit::max();
100  zap['N'] = make_field(numberOfPrefits) = 1;
101  zap['L'] = make_field(quality_sorter) = JPARSER::initialised();
102  zap['E'] = make_field(Emin_GeV) = 0.0;
103  zap['M'] = make_field(NPE) = 0.0;
105  zap['a'] = make_field(atmosphere) = JAtmosphericMuon(90.0, 90.0);
106  zap['O'] = make_field(option) = "E", "N", "LINE", "LOGE";
107  zap['d'] = make_field(debug) = 2;
108 
109  zap(argc, argv);
110  }
111  catch(const exception& error) {
112  FATAL(error.what() << endl);
113  }
114 
115 
116 
117 
118  JHead head;
119 
120  try {
121  head = getHeader(inputFile);
122  }
123  catch(const JException& error) {
124  FATAL(error);
125  }
126 
127  const JVolume volume(head, option != "LINE");
128  const JPosition3D center = get<JPosition3D>(head);
129  JCylinder3D cylinder = get<JCylinder3D>(head);
130 
131  cylinder.add(center);
132 
133  NOTICE("Reposition can [m]: " << cylinder << endl);
134 
135  const double EMIN_GEV = 10e3; // MUPAGE
136 
137 
138  TFile out(outputFile.c_str(), "recreate");
139 
140  TH1D job("job", NULL, 100, 0.5, 100.5);
141 
142  TH1D hn("hn", NULL, 250, -0.5, 249.5);
143  TH1D hq("hq", NULL, 300, 0.0, 600.0);
144  TH1D hi("hi", NULL, 101, -0.5, 100.5);
145  TH1D hv("hv", NULL, 200, -6.0, 0.0);
146  TH1D h1("h1", NULL, 200, -2.0, +2.0);
147  TH1D hc("hc", NULL, 200, -1.0, +1.0);
148  TH1D hu("hu", NULL, 400, -1.0e3, 1.0e3);
149 
150  TH1D hx("hx", NULL, 100, -3.0, +2.3); // [log(deg)]
151  TH1D hd("hd", NULL, 100, 0.0, 10.0); // [m]
152  TH1D hz("hz", NULL, 100, -200.0, 200.0); // [m]
153  TH1D ht("ht", NULL, 100, -100.0, 100.0); // [ns]
154 
155  TH1D e0("e0", NULL, 100, volume.getXmin(), volume.getXmax()); // [log(E)]
156  TH1D e1("e1", NULL, 100, volume.getXmin(), volume.getXmax()); // [log(E)]
157  TH1D e2("e2", NULL, 100, volume.getXmin(), volume.getXmax()); // [log(E)]
158  TH1D er("er", NULL, 100, -5.0, +5.0); // [log(E/E)]
159  TH2D ee("ee", NULL,
160  40, volume.getXmin(), volume.getXmax(),
161  40, volume.getXmin(), volume.getXmax());
162 
163  const Int_t ny = 28800;
164  const Double_t ymin = 0.0; // [deg]
165  const Double_t ymax = 180.0; // [deg]
166 
167  vector<double> X;
168 
169  if (option.find('E') != string::npos) {
170 
171  for (double x = volume.getXmin(); x <= volume.getXmax(); x += (volume.getXmax() - volume.getXmin()) / 20) {
172  X.push_back(x);
173  }
174 
175  } else {
176 
177  double x = -0.5;
178 
179  for ( ; x <= 15.5; x += 1.0) { X.push_back(x); }
180  for ( ; x <= 25.5; x += 2.0) { X.push_back(x); }
181  for ( ; x <= 50.5; x += 5.0) { X.push_back(x); }
182  for ( ; x <= 100.5; x += 10.0) { X.push_back(x); }
183  for ( ; x <= 250.5; x += 20.0) { X.push_back(x); }
184  }
185 
186  TH2D h2("h2", NULL, X.size() - 1, X.data(), ny, ymin, ymax);
187  TProfile he("he", NULL, X.size() - 1, X.data());
188 
189  TH2D ha("ha", NULL, 100, 0.0, 0.5e6, 100, -100.0, +900.0);
190  TH2D hb("hb", NULL, 100, 0.0, 0.5e6, 100, -100.0, +900.0);
191 
192  JQuantile Q("Angle", true);
193  JQuantile O("Omega", true);
194 
195 
196  while (inputFile.hasNext()) {
197 
198  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
199 
200  multi_pointer_type ps = inputFile.next();
201 
202  JDAQEvent* tev = ps;
203  JEvt* evt = ps;
204  Evt* event = ps;
205 
206  const JTimeConverter converter(*event, *tev);
207 
208  job.Fill(1.0);
209 
210 
211  double Emu = 0.0;
212  double Emax = 0.0;
213 
214  vector<Trk>::const_iterator muon = event->mc_trks.end();
215 
216  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
217 
218  if (is_muon(*track)) {
219 
220  Emu += track->E;
221 
222  if (track->E > Emax) {
223  muon = track;
224  Emax = track->E;
225  }
226  }
227  }
228 
229  if (muon == event->mc_trks.end()) {
230  continue;
231  }
232 
233  job.Fill(3.0);
234 
235 
236  // abscissa
237 
238  Double_t x = 0.0;
239 
240  if (option.find('E') != string::npos)
241  x = volume.getX(event->mc_trks[0].E);
242  else
243  x = getCount(tev->begin<JDAQTriggeredHit>(), tev->end<JDAQTriggeredHit>());
244 
245 
246  // weight for efficiency determination
247 
248  Double_t W = 0.0;
249 
250  if (!evt->empty()) {
251 
252  JEvt::iterator __end = partition(evt->begin(), evt->end(), JHistory::is_event(application));
253 
254  if (evt->begin() == __end) {
255  continue;
256  }
257 
258  job.Fill(4.0);
259 
260  if (numberOfPrefits > 0) {
261 
262  JEvt::iterator __q = __end;
263 
264  advance(__end = evt->begin(), min(numberOfPrefits, (size_t) distance(evt->begin(), __q)));
265 
266  partial_sort(evt->begin(), __end, __q, quality_sorter);
267 
268  } else {
269 
270  sort(evt->begin(), __end, quality_sorter);
271  }
272 
273  const JPointing pointing(getDirection(*muon));
274 
275  JEvt::iterator best = pointing(evt->begin(), __end);
276  const Double_t beta = pointing.getAngle(*best);
277  const double Efit = best->getE();
278  const double Eraw = best->getW(JENERGY_ENERGY, numeric_limits<double>::min());
279  const double mip = best->getW(JSTART_NPE_MIP, numeric_limits<double>::max());
280  //const double npe = best->getW(JVETO_NPE, 0.0);
281  //const int count = best->getW(JVETO_NUMBER_OF_HITS, 0.0);
282 
283  // selection of fit result
284 
285  bool ok = (Efit >= Emin_GeV &&
286  mip >= NPE);
287 
288  if (ok) {
289 
290  W = 1.0;
291 
292  job.Fill(5.0);
293 
294  hn.Fill((Double_t) best->getNDF());
295  hq.Fill(best->getQ());
296  hi.Fill((Double_t) distance(evt->begin(), best));
297  hc.Fill(best->getDZ());
298 
299  if (( has_neutrino(*event) && get_neutrino(*event).dir.z >= atmosphere.dot2) ||
300  (!has_neutrino(*event) && best->getDZ() >= atmosphere.dot2)) {
301  hu.Fill(atmosphere(evt->begin(), __end));
302  }
303 
304  hx.Fill(max(log10(beta), hx.GetXaxis()->GetXmin()));
305 
306  Q.put(beta);
307 
308  JTrack3E ta = getTrack(*muon);
309  JTrack3E tb = getTrack(*best);
310 
311  ta.add(center);
312  tb.sub(converter.putTime());
313 
314  //ta.move(ta.getIntersection(tb), getSpeedOfLight(), gWater);
315  //tb.move(tb.getIntersection(ta), getSpeedOfLight(), gWater);
316  static_cast<JTrack3D&>(ta).move(ta.getIntersection(tb), getSpeedOfLight());
317  static_cast<JTrack3D&>(tb).move(tb.getIntersection(ta), getSpeedOfLight());
318 
319  hd.Fill((tb.getPosition() - ta.getPosition()).getLength());
320 
321  if (has_neutrino(*event)) {
322 
323  job.Fill(6.0);
324 
325  JPosition3D vertex = getPosition(get_neutrino(*event));
326 
327  vertex.add(center);
328 
329  if (cylinder.is_inside(vertex)) {
330 
331  job.Fill(7.0);
332 
333  JTrack3E tc = getTrack(*best);
334 
335  ha.Fill(best->getX()*best->getX() + best->getY()*best->getY(), best->getZ());
336  hz.Fill(tc.getIntersection(vertex));
337  }
338  }
339 
340  if (best->getE() >= EMIN_GEV) {
341  hb.Fill(best->getX()*best->getX() + best->getY()*best->getY(), best->getZ());
342  }
343 
344  ht.Fill(tb.getT() - ta.getT());
345 
346  e0.Fill(volume.getX(Emu, true));
347  e1.Fill(volume.getX(Eraw, true));
348  e2.Fill(volume.getX(Efit, true));
349  er.Fill(volume.getX(Efit) - volume.getX(Emu));
350  ee.Fill(volume.getX(Emu), volume.getX(Efit));
351 
352  h2.Fill(x, beta);
353 
354  if (best->hasW(JSTART_NPE_MIP)) {
355  h1.Fill(log10(best->getW(JSTART_NPE_MIP)));
356  }
357 
358  if (best->hasW(JVETO_NPE) && best->hasW(JVETO_NUMBER_OF_HITS)) {
359 
360  const double npe = best->getW(JVETO_NPE);
361  const int count = best->getW(JVETO_NUMBER_OF_HITS);
362  const double pv = TMath::PoissonI(count, npe);
363 
364  hv.Fill(max(log10(pv), hv.GetXaxis()->GetXmin()));
365  }
366  }
367  }
368 
369  he.Fill(x, W);
370  }
371  STATUS(endl);
372 
373  NOTICE("Number of events input " << setw(8) << right << job.GetBinContent(1) << endl);
374  NOTICE("Number of events with muon " << setw(8) << right << job.GetBinContent(3) << endl);
375  NOTICE("Number of events with fit " << setw(8) << right << job.GetBinContent(4) << endl);
376  NOTICE("Number of events selected " << setw(8) << right << job.GetBinContent(5) << endl);
377  NOTICE("Number of events with neutrino " << setw(8) << right << job.GetBinContent(6) << endl);
378  NOTICE("Number of events contained " << setw(8) << right << job.GetBinContent(7) << endl);
379 
380  if (Q.getCount() != 0) {
381  NOTICE("Median space angle [deg] " << FIXED (6,3) << Q.getQuantile(0.5) << endl);
382  }
383 
384  out.Write();
385  out.Close();
386 }
Utility class to parse command line options.
Definition: JParser.hh:1410
number of photo-electrons from JVeto.cc
JTrack3E getTrack(const Trk &track)
Get track.
double getCount(TH1D *hptr, int muon_threshold)
const double getSpeedOfLight()
Number of bytes in a gigabyte.
Definition: JConstants.hh:89
#define STATUS(A)
Definition: JMessage.hh:61
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:461
string outputFile
number of hits from JVeto.cc
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:214
const_iterator< T > end() const
Get end of data.
const_iterator< T > begin() const
Get begin of data.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
#define NOTICE(A)
Definition: JMessage.hh:62
int debug
debug level
Definition: JSirene.cc:59
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
Monte Carlo run header.
Definition: JHead.hh:727
uncorrected energy [GeV] from JEnergy.cc
#define FATAL(A)
Definition: JMessage.hh:65
number of photo-electrons up to the barycentre from JStart.cc
JDirection3D getDirection(const Vec &v)
Get direction.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:72
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
JPosition3D getPosition(const Vec &v)
Get position.