Jpp  15.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Functions
JPostfit2F.cc File Reference

Example program to compare fit results from two files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JReconstruction/JEvt.hh"
#include "JReconstruction/JEvtToolkit.hh"
#include "JMath/JMathToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Macros

#define make_key(PARAMETER)   JKey(#PARAMETER, PARAMETER)
 Make key. More...
 

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to compare fit results from two files.

Author
mdejong

Definition in file JPostfit2F.cc.

Macro Definition Documentation

#define make_key (   PARAMETER)    JKey(#PARAMETER, PARAMETER)

Make key.

Parameters
PARAMETERparameter
Returns
key

Definition at line 72 of file JPostfit2F.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 267 of file JPostfit2F.cc.

268 {
269  using namespace std;
270  using namespace JPP;
271 
272  typedef JTriggeredFileScanner<JEvt> JTriggeredFileScanner_t;
273  typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
274 
275  JTriggeredFileScanner_t inputFileA;
276  JTriggeredFileScanner_t inputFileB;
277  JLimit_t numberOfEvents;
278  string outputFile;
279  double angle_Deg;
280  int debug;
281 
282  try {
283 
284  JParser<> zap("Example program to compare fit results from two files.");
285 
286  zap['a'] = make_field(inputFileA);
287  zap['b'] = make_field(inputFileB);
288  zap['o'] = make_field(outputFile) = "postfit2f.root";
289  zap['n'] = make_field(numberOfEvents) = JLimit::max();
290  zap['A'] = make_field(angle_Deg) = 1.0;
291  zap['d'] = make_field(debug) = 2;
292 
293  zap(argc, argv);
294  }
295  catch(const exception& error) {
296  FATAL(error.what() << endl);
297  }
298 
299  JHead head;
300 
301  try {
302  head = getHeader(inputFileA);
303  }
304  catch(const JException& error) {
305  FATAL(error);
306  }
307  const double E_nu_min = head.cut_nu.Emin; //neutrino minimum energy
308  const double E_nu_max = head.cut_nu.Emax; //neutrino maximum energy
309 
310  inputFileA.setLimit(numberOfEvents);
311  inputFileB.setLimit(numberOfEvents);
312 
313 
314  TFile out(outputFile.c_str(), "recreate");
315 
316  JManager manager;
317 
318  manager.insert(make_key(JQUALITY), 101, 0.0, 250.0);
319  manager.insert(make_key(JGANDALF_BETA0_RAD), 51, 0.0, 2.0e-2);
320  manager.insert(make_key(JGANDALF_BETA1_RAD), 51, 0.0, 2.0e-2);
321  manager.insert(make_key(JGANDALF_NUMBER_OF_HITS), 51, 0.0, 100);
322  manager.insert(make_key(JSTART_NPE_MIP), 51, 0.0, 10.0);
323  manager.insert(make_key(JSTART_NPE_MIP_TOTAL), 51, 0.0, 10.0);
324  manager.insert(make_key(JSTART_LENGTH_METRES), 51, 0.0, 100.0);
325  manager.insert(make_key(JENERGY_ENERGY), 51, 1.0, 5.0, true);
326  manager.insert(make_key(JENERGY_CHI2), 51, 0.0, 200.0);
327 
328  TH1D hA("h[A]", NULL, 100, -3.0, +2.3); // [log(deg)]
329  TH1D hB("h[B]", NULL, 100, -3.0, +2.3); // [log(deg)]
330  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
331  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
332  TH2D h2("h2", NULL,
333  100, -100.0, +100.0, // quality
334  360, -180.0, +180.0); // deg
335 
336  while (inputFileA.hasNext() && inputFileB.hasNext()) {
337 
338  STATUS("event: " << setw(10) << inputFileA.getCounter() << '\r'); DEBUG(endl);
339 
340  multi_pointer_type psA = inputFileA.next();
341  multi_pointer_type psB = inputFileB.next();
342 
343  // find the same corresponding Monte Carlo true event based on the event identifier.
344 
345  while (psA.get<Evt>()->mc_id < psB.get<Evt>()->mc_id && inputFileA.hasNext()) { psA = inputFileA.next(); }
346  while (psB.get<Evt>()->mc_id < psA.get<Evt>()->mc_id && inputFileB.hasNext()) { psB = inputFileB.next(); }
347 
348  if (!psA.is_valid()) { continue; }
349  if (!psB.is_valid()) { continue; }
350 
351  if (psA.get<Evt>()->mc_id == psB.get<Evt>()->mc_id) {
352 
353  Evt* event = psA;
354  JEvt* evtA = psA;
355  JEvt* evtB = psB;
356 
357  const Trk neutrino = get_neutrino(*event);
358 
359  vector<Trk>::const_iterator muon = find_if(event->mc_trks.begin(), event->mc_trks.end(), is_muon);
360 
361  if (muon == event->mc_trks.end()) { continue; }
362 
363  if (evtA->empty()) { continue; }
364  if (evtB->empty()) { continue; }
365 
366  JEvt::const_iterator fitA = evtA->begin();
367  JEvt::const_iterator fitB = evtB->begin();
368 
369  const Double_t angleA = getAngle(getDirection(*muon), getDirection(*fitA));
370  const Double_t angleB = getAngle(getDirection(*muon), getDirection(*fitB));
371 
372  hA.Fill(log10(angleA));
373  hB.Fill(log10(angleB));
374 
375  h2.Fill(fitB->getQ() - fitA->getQ(), angleB - angleA);
376 
377  const double Enu = neutrino.E; //true neutrino E
378  hA_angle_E.Fill(Enu, angleA);
379  hB_angle_E.Fill(Enu, angleB);
380 
381  if (angleA > angle_Deg) {
382  manager.Fill(*fitA, *fitB, angleB < angle_Deg);
383  }
384  }
385  }
386  STATUS(endl);
387 
388  out.Write();
389  out.Close();
390 }
Utility class to parse command line options.
Definition: JParser.hh:1500
double getAngle(const JQuaternion3D &first, const JQuaternion3D &second)
Get space angle between quanternions.
General exception.
Definition: JException.hh:23
static const int JSTART_NPE_MIP_TOTAL
number of photo-electrons along the whole track from JStart.cc
static const int JENERGY_ENERGY
uncorrected energy [GeV] from JEnergy.cc
#define STATUS(A)
Definition: JMessage.hh:63
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
static const int JGANDALF_BETA1_RAD
angular resolution [rad] from JGandalf.cc
string outputFile
static const int JENERGY_CHI2
chi2 from JEnergy.cc
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
static const int JSTART_NPE_MIP
number of photo-electrons up to the barycentre from JStart.cc
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
#define make_key(PARAMETER)
Make key.
Definition: JPostfit2F.cc:72
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
static const int JGANDALF_NUMBER_OF_HITS
number of hits from JGandalf.cc
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
JDirection3D getDirection(const Vec &dir)
Get direction.
Acoustic event fit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition: Evt.hh:23
static const int JGANDALF_BETA0_RAD
KM3NeT Data Definitions v2.1.0-7-g97845ea https://git.km3net.de/common/km3net-dataformat.
int debug
debug level
Definition: JSirene.cc:63
Monte Carlo run header.
Definition: JHead.hh:1113
#define FATAL(A)
Definition: JMessage.hh:67
static const int JSTART_LENGTH_METRES
distance between first and last hits in metres from JStart.cc
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19