Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
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

◆ main()

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;
52  JRange<double> range;
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  const JHead& head = getHeader(inputFile);
73 
74  const JRange<double>& Erange = head.cut_nu.E;
75 
76  const JCylinder3D can = getCylinder(head);
77 
78  TFile out(outputFile.c_str(), "recreate");
79 
80  TH1D h0 ("h0", "Energy conservation",
81  2000, -100.0, 100.0);
82 
83  TH1D h1 ("h1", "Momentum conservation",
84  1000, 0.0, 100.0);
85 
86  TH1D job ("job", "Particle types",
87  10001, -5000.5, +5000.5);
88  TH2D hv ("hv", "Logarithmic visible energy as function of logarithmic initial state energy",
89  100, log10(Erange.getLowerLimit()), log10(Erange.getUpperLimit()),
90  100, log10(Erange.getLowerLimit()), log10(Erange.getUpperLimit()));
91  TH1D ha ("ha", "Angle between neutrino-direction and visible-energy-weighted direction",
92  200, -1.0, 1.0);
93 
94  TH1D hn ("hn", "Number of muons per event",
95  2001, -0.5, +2000.5);
96  TH1D he ("he", "Muon energies",
97  1000, 0.0, 10.0);
98  TH2D hp ("hp", "Muon positions",
99  100, 0.0, 2.0e5,
100  200, 0.0, 1.5e3);
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 double Evis = getVisibleEnergy (*event, can);
123  const Vec EvisVector = getVisibleEnergyVector(*event, can);
124 
125  if (!range((E0 - E1)/E0) || !range((P0 - P1).len()/P0.len()) || debug >= debug_t) {
126 
127  NOTICE(endl << FILL(57,'-') << '\n' << FILL());
128  NOTICE("event: " << RIGHT(8) << event->mc_id << RIGHT(67) << "energy [GeV] momentum (x, y, z) [GeV] distance [m]" << endl);
129 
130  for (size_t i = 0; i != event->mc_trks.size(); ++i) {
131 
132  const Trk& track = event->mc_trks[i];
133 
134  const string name = (JPDB::getInstance().hasPDG(track.type) ?
135  JPDB::getInstance().getPDG(track.type).name :
136  MAKE_STRING("unknown (type: " << track.type << ")"));
137 
138  NOTICE(LEFT(32) << showpos << name << ' ' << FIXED(7,3) << track.E << " " << FIXED(7,3) << track.E * track.dir << " " << FIXED(7,3) << (track.pos - neutrino.pos).len() << endl);
139  }
140  NOTICE(LEFT(32) << "balance:" << ' ' << FIXED(7,3) << E0 - E1 << " " << FIXED(7,3) << P0 - P1 << endl);
141  }
142 
143  h0.Fill( E0 - E1 );
144  h1.Fill((P0 - P1).len());
145 
146  hv.Fill(log10(E0), log10(Evis));
147  ha.Fill(getDirection(neutrino).getDot(getDirection(EvisVector)));
148  }
149 
150 
151  int n = 0;
152 
153  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
154 
155  if (is_muon(*track)) {
156  ++n;
157  he.Fill(log10(track->E));
158  hp.Fill(track->pos.x*track->pos.x + track->pos.y*track->pos.y, track->pos.z);
159  }
160  }
161 
162  hn.Fill((Double_t) n);
163  }
164 
165  STATUS(endl);
166 
167  out.Write();
168  out.Close();
169 
170  return 0;
171 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:63
Monte Carlo run header.
Definition: JHead.hh:1236
JAANET::cut_nu cut_nu
Definition: JHead.hh:1596
Cylinder object.
Definition: JCylinder3D.hh:41
Utility class to parse command line options.
Definition: JParser.hh:1698
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
JDirection3D getDirection(const Vec &dir)
Get direction.
Vec getP0(const Evt &evt)
Get momentum vector of the initial state of a neutrino interaction.
JCylinder3D getCylinder(const JHead &header)
Get cylinder corresponding to the positions of generated tracks (i.e.
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
bool is_neutrino(const Trk &track)
Test whether given track is a neutrino.
double getE1(const Evt &evt)
Get final state energy of a neutrino interaction.
double getE0(const Evt &evt)
Get initial state energy of a neutrino interaction.
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
Vec getP1(const Evt &evt)
Get momentum vector of the final state of a neutrino interaction.
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:676
@ debug_t
debug
Definition: JMessage.hh:29
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
@ LEFT
Definition: JTwosome.hh:18
@ RIGHT
Definition: JTwosome.hh:18
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double getVisibleEnergy(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy of a track.
Vec getVisibleEnergyVector(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy vector of a track.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
const int n
Definition: JPolint.hh:786
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
The cylinder used for photon tracking.
Definition: JHead.hh:575
JRange_t E
Energy range [GeV].
Definition: JHead.hh:419
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:15
int type
MC: particle type in PDG encoding.
Definition: Trk.hh:24
Vec dir
track direction
Definition: Trk.hh:18
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
Vec pos
postion [m] of the track at time t
Definition: Trk.hh:17
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:13
double len() const
Get length.
Definition: Vec.hh:145
double z
Definition: Vec.hh:14
double x
Definition: Vec.hh:14
double y
Definition: Vec.hh:14