Jpp  17.2.1-pre0
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 "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/offline/Trk.hh"
#include "JAAnet/JPDB.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JTools/JRange.hh"
#include "JGeometry2D/JCircle2D.hh"
#include "JGeometry3D/JCylinder3D.hh"
#include "JSirene/JSireneToolkit.hh"
#include "JSirene/JVisibleEnergyToolkit.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 44 of file JPizza.cc.

45 {
46  using namespace std;
47  using namespace JPP;
48 
49  JMultipleFileScanner<Evt> inputFile;
50  JLimit_t& numberOfEvents = inputFile.getLimit();
51  string outputFile;
53  int debug;
54 
55  try {
56 
57  JParser<> zap("Example program to verify generator data.");
58 
59  zap['f'] = make_field(inputFile);
60  zap['o'] = make_field(outputFile) = "pizza.root";
61  zap['n'] = make_field(numberOfEvents) = JLimit::max();
62  zap['R'] = make_field(range, "fractional energy and momentum conservation") = JRange<double>(-0.01, +0.01);
63  zap['d'] = make_field(debug) = 0;
64 
65  zap(argc, argv);
66  }
67  catch(const exception &error) {
68  FATAL(error.what() << endl);
69  }
70 
71  cout.tie(&cerr);
72 
73  TFile out(outputFile.c_str(), "recreate");
74 
75  TH1D h0 ("h0", "Fractional energy conservation",
76  1001, -1.0, +1.0);
77  TH1D h1 ("h1", "Fractional momentum conservation",
78  1001, -1.0, +1.0);
79  TH1D job("job", "Particle types",
80  10001, -5000.5, +5000.5);
81 
82  TH1D hv("hv", "Visible energy as fraction of initial state energy",
83  25, 0.0, 2.5);
84  TH1D ha("ha", "Angle between neutrino-direction and visible-energy-weighted direction",
85  200, -1.0, 1.0);
86 
87  TH1D hn("hn", "Number of muons per event",
88  2001, -0.5, +2000.5);
89  TH1D he("he", "Muon energies",
90  1000, 0.0, 10.0);
91  TH2D hp("hp", "Muon positions",
92  100, 0.0, 2.0e5,
93  200, 0.0, 1.5e3);
94 
95 
96  const JHead& head = getHeader(inputFile);
97 
98  const JCylinder3D can(JCircle2D(JVector2D(0.0, 0.0), head.can.r),
99  head.can.zmin,
100  head.can.zmax);
101 
102  while (inputFile.hasNext()) {
103 
104  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
105 
106  const Evt* event = inputFile.next();
107 
108  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
109  job.Fill((double) track->type);
110  }
111 
112  if (has_neutrino(*event) && is_neutrino(event->mc_trks[0])) {
113 
114  const Trk& neutrino = event->mc_trks[0];
115 
116  const Vec& P0 = getP0(*event);
117  const Vec& P1 = getP1(*event);
118 
119  const double E0 = getE0(*event);
120  const double E1 = getE1(*event);
121 
122  const Vec Evis = getVisibleEnergy(*event, can);
123 
124  if (!range((E0 - E1)/E0) || !range((P0 - P1).len()/P0.len()) || debug >= debug_t) {
125 
126  cout << endl << "--------------------------------------------------------" << endl;
127  cout << "event: " << setw(8) << event->mc_id << " energy [GeV] momentum (x, y, z) [GeV] distance [m]" << endl;
128 
129  for (size_t i = 0; i != event->mc_trks.size(); ++i) {
130 
131  const Trk& track = event->mc_trks[i];
132  const JParticle& particle = JPDB::getInstance().getPDG(track.type);
133 
134  cout << setw(32) << left << showpos << particle.name << ' ' << FIXED(7,3) << track.E << " " << FIXED(7,3) << track.E * track.dir << " " << FIXED(7,3) << (track.pos - neutrino.pos).len() << endl;
135  }
136  cout << setw(32) << left << "balance:" << ' ' << FIXED(7,3) << E0 - E1 << " " << FIXED(7,3) << P0 - P1 << endl;
137  }
138 
139  hv.Fill(Evis.len() / E0);
140  ha.Fill(getDirection(neutrino).getDot(getDirection(Evis / Evis.len())));
141 
142  h0.Fill((E0 - E1)/E0);
143  h1.Fill((P0 - P1).len()/P0.len());
144  }
145 
146 
147  int n = 0;
148 
149  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
150 
151  if (is_muon(*track)) {
152  ++n;
153  he.Fill(log10(track->E));
154  hp.Fill(track->pos.x*track->pos.x + track->pos.y*track->pos.y, track->pos.z);
155  }
156  }
157 
158  hn.Fill((Double_t) n);
159  }
160 
161  STATUS(endl);
162 
163  out.Write();
164  out.Close();
165 }
Vec getP1(const Evt &evt)
Get momentum vector of the final state of a neutrino interaction.
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
Utility class to parse command line options.
Definition: JParser.hh:1517
std::string name
name of particle
Definition: JPDB.hh:89
debug
Definition: JMessage.hh:29
double z
Definition: Vec.hh:14
Data structure for circle in two dimensions.
Definition: JCircle2D.hh:33
double getE0(const Evt &evt)
Get initial state energy of a neutrino interaction.
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
double getE1(const Evt &evt)
Get final state energy of a neutrino interaction.
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
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
bool is_neutrino(const Trk &track)
Test whether given track is a neutrino.
const int n
Definition: JPolint.hh:697
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
Cylinder object.
Definition: JCylinder3D.hh:39
JDirection3D getDirection(const Vec &dir)
Get direction.
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
set_variable E_E log10(E_{fit}/E_{#mu})"
Monte Carlo run header.
Definition: JHead.hh:1167
#define FATAL(A)
Definition: JMessage.hh:67
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
Auxiliary class to handle particle name, codes and mass.
Definition: JPDB.hh:37
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Vec pos
postion [m] of the track at time t
Definition: Trk.hh:17
then P1
General purpose class for object reading from a list of file names.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
Vec getP0(const Evt &evt)
Get momentum vector of the initial state of a neutrino interaction.
Vec getVisibleEnergy(const Trk &track, const JCylinder3D &can)
Get the visible energy of a track.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
The cylinder used for photon tracking.
Definition: JHead.hh:562