Jpp  17.3.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 "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 
72  TFile out(outputFile.c_str(), "recreate");
73 
74  TH1D h0 ("h0", "Fractional energy conservation",
75  1001, -1.0, +1.0);
76  TH1D h1 ("h1", "Fractional momentum conservation",
77  1001, -1.0, +1.0);
78  TH1D job("job", "Particle types",
79  10001, -5000.5, +5000.5);
80 
81  TH1D hv("hv", "Visible energy as fraction of initial state energy",
82  25, 0.0, 2.5);
83  TH1D ha("ha", "Angle between neutrino-direction and visible-energy-weighted direction",
84  200, -1.0, 1.0);
85 
86  TH1D hn("hn", "Number of muons per event",
87  2001, -0.5, +2000.5);
88  TH1D he("he", "Muon energies",
89  1000, 0.0, 10.0);
90  TH2D hp("hp", "Muon positions",
91  100, 0.0, 2.0e5,
92  200, 0.0, 1.5e3);
93 
94 
95  const JHead& head = getHeader(inputFile);
96 
97  const JCylinder3D can(JCircle2D(JVector2D(0.0, 0.0), head.can.r),
98  head.can.zmin,
99  head.can.zmax);
100 
101  while (inputFile.hasNext()) {
102 
103  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
104 
105  const Evt* event = inputFile.next();
106 
107  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
108  job.Fill((double) track->type);
109  }
110 
111  if (has_neutrino(*event) && is_neutrino(event->mc_trks[0])) {
112 
113  const Trk& neutrino = event->mc_trks[0];
114 
115  const Vec& P0 = getP0(*event);
116  const Vec& P1 = getP1(*event);
117 
118  const double E0 = getE0(*event);
119  const double E1 = getE1(*event);
120 
121  const Vec Evis = getVisibleEnergy(*event, can);
122 
123  if (!range((E0 - E1)/E0) || !range((P0 - P1).len()/P0.len()) || debug >= debug_t) {
124 
125  cout << endl << "--------------------------------------------------------" << endl;
126  cout << "event: " << setw(8) << event->mc_id << " energy [GeV] momentum (x, y, z) [GeV] distance [m]" << endl;
127 
128  for (size_t i = 0; i != event->mc_trks.size(); ++i) {
129 
130  const Trk& track = event->mc_trks[i];
131 
132  const string name = (JPDB::getInstance().hasPDG(track.type) ?
133  JPDB::getInstance().getPDG(track.type).name :
134  MAKE_STRING("unknown (type: " << track.type << ")"));
135 
136  cout << setw(32) << left << showpos << name << ' ' << FIXED(7,3) << track.E << " " << FIXED(7,3) << track.E * track.dir << " " << FIXED(7,3) << (track.pos - neutrino.pos).len() << endl;
137  }
138  cout << setw(32) << left << "balance:" << ' ' << FIXED(7,3) << E0 - E1 << " " << FIXED(7,3) << P0 - P1 << endl;
139  }
140 
141  hv.Fill(Evis.len() / E0);
142  ha.Fill(getDirection(neutrino).getDot(getDirection(Evis / Evis.len())));
143 
144  h0.Fill((E0 - E1)/E0);
145  h1.Fill((P0 - P1).len()/P0.len());
146  }
147 
148 
149  int n = 0;
150 
151  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
152 
153  if (is_muon(*track)) {
154  ++n;
155  he.Fill(log10(track->E));
156  hp.Fill(track->pos.x*track->pos.x + track->pos.y*track->pos.y, track->pos.z);
157  }
158  }
159 
160  hn.Fill((Double_t) n);
161  }
162 
163  STATUS(endl);
164 
165  out.Write();
166  out.Close();
167 }
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
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.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
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
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
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
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