Jpp  16.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPizza.cc File Reference

Example program to verify generator data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TProfile.h"
#include "TDatabasePDG.h"
#include "TParticlePDG.h"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JTools/JRange.hh"
#include "JPhysics/JGeane.hh"
#include "JSirene/JPythia.hh"
#include "Jeep/JPrint.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 verify generator data.

Author
mdejong

Definition in file JPizza.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 332 of file JPizza.cc.

333 {
334  using namespace std;
335  using namespace JPP;
336 
337  JMultipleFileScanner<Evt> inputFile;
338  JLimit_t& numberOfEvents = inputFile.getLimit();
339  string outputFile;
341  int debug;
342 
343  try {
344 
345  JParser<> zap("Example program to verify generator data.");
346 
347  zap['f'] = make_field(inputFile);
348  zap['o'] = make_field(outputFile) = "pizza.root";
349  zap['n'] = make_field(numberOfEvents) = JLimit::max();
350  zap['R'] = make_field(range, "fractional energy and momentum conservation") = JRange<double>(-0.01, +0.01);
351  zap['d'] = make_field(debug) = 0;
352 
353  zap(argc, argv);
354  }
355  catch(const exception &error) {
356  FATAL(error.what() << endl);
357  }
358 
359  cout.tie(&cerr);
360 
361  TFile out(outputFile.c_str(), "recreate");
362 
363  TH1D h0 ("h0", "Fractional energy conservation",
364  1001, -1.0, +1.0);
365  TH1D h1 ("h1", "Fractional momentum conservation",
366  1001, -1.0, +1.0);
367  TH1D job("job", "Particle types",
368  10001, -5000.5, +5000.5);
369 
370  TH1D hv("hv", "Visible energy as fraction of initial state energy",
371  25, 0.0, 2.5);
372  TH1D ha("ha", "Angle between neutrino-direction and visible-energy-weighted direction",
373  200, -1.0, 1.0);
374  TH1D ht("ht", "Square-root of summed squared transverse visible energy as fraction of initial state energy",
375  120, 0.0, 1.2);
376 
377  TH1D hn("hn", "Number of muons per event",
378  2001, -0.5, +2000.5);
379  TH1D he("he", "Muon energies",
380  1000, 0.0, 10.0);
381  TH2D hp("hp", "Muon positions",
382  100, 0.0, 2.0e5,
383  200, 0.0, 1.5e3);
384 
385 
386  while (inputFile.hasNext()) {
387 
388  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
389 
390  const Evt* event = inputFile.next();
391 
392  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
393  job.Fill((double) track->type);
394  }
395 
396  if (has_neutrino(*event) && is_neutrino(event->mc_trks[0])) {
397 
398  const Trk& neutrino = event->mc_trks[0];
399 
400  const Vec& P0 = getP0(*event);
401  const Vec& P1 = getP1(*event);
402 
403  const double E0 = getE0(*event);
404  const double E1 = getE1(*event);
405 
406  const double Evis = getVisibleEnergy (*event);
407  const Vec& EvisDir = getVisibleEnergyDirection (*event);
408  const double EvisT = getTransverseVisibleEnergy(*event, EvisDir);
409 
410  if (!range((E0 - E1)/E0) || !range((P0 - P1).len()/P0.len()) || debug >= debug_t) {
411 
412  cout << endl << "--------------------------------------------------------" << endl;
413  cout << "event: " << setw(8) << event->mc_id << " energy [GeV] momentum (x, y, z) [GeV] distance [m]" << endl;
414 
415  for (size_t i = 0; i != event->mc_trks.size(); ++i) {
416 
417  const Trk& track = event->mc_trks[i];
418 
419  const TDatabasePDG pdg;
420  const TParticlePDG* particle = pdg.GetParticle(track.type);
421 
422  cout << setw(32) << left << showpos << particle->GetName() << ' ' << FIXED(7,3) << track.E << " " << FIXED(7,3) << track.E * track.dir << " " << FIXED(7,3) << (track.pos - neutrino.pos).len() << endl;
423  }
424  cout << setw(32) << left << "balance:" << ' ' << FIXED(7,3) << E0 - E1 << " " << FIXED(7,3) << P0 - P1 << endl;
425  }
426 
427  hv.Fill(Evis/E0);
428  ht.Fill(EvisT/E0);
429  ha.Fill(getDirection(neutrino).getDot(getDirection(EvisDir)));
430 
431  h0.Fill((E0 - E1)/E0);
432  h1.Fill((P0 - P1).len()/P0.len());
433  }
434 
435 
436  int n = 0;
437 
438  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
439 
440  if (is_muon(*track)) {
441  ++n;
442  he.Fill(log10(track->E));
443  hp.Fill(track->pos.x*track->pos.x + track->pos.y*track->pos.y, track->pos.z);
444  }
445  }
446 
447  hn.Fill((Double_t) n);
448  }
449  STATUS(endl);
450 
451  out.Write();
452  out.Close();
453 }
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
double z
Definition: Vec.hh:14
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:409
#define STATUS(A)
Definition: JMessage.hh:63
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.
Vec dir
track direction
Definition: Trk.hh:18
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
double y
Definition: Vec.hh:14
double len() const
Get length.
Definition: Vec.hh:145
bool is_neutrino(const Trk &track)
Test whether given track is a neutrino.
const int n
Definition: JPolint.hh:676
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
double x
Definition: Vec.hh:14
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
JDirection3D getDirection(const Vec &dir)
Get direction.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
set_variable E_E log10(E_{fit}/E_{#mu})"
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:17
then P1
General purpose class for object reading from a list of file names.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
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