Jpp  18.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPizza.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <cmath>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 #include "TH2D.h"
11 #include "TProfile.h"
12 
15 
16 #include "JAAnet/JPDB.hh"
17 #include "JAAnet/JHead.hh"
18 #include "JAAnet/JAAnetToolkit.hh"
19 
22 #include "JSupport/JSupport.hh"
23 
24 #include "JTools/JRange.hh"
25 
26 #include "JGeometry2D/JCircle2D.hh"
27 
29 
32 
33 #include "Jeep/JPrint.hh"
34 #include "Jeep/JParser.hh"
35 #include "Jeep/JMessage.hh"
36 
37 
38 /**
39  * \file
40  *
41  * Example program to verify generator data.
42  * \author mdejong
43  */
44 int main(int argc, char **argv)
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  const JHead& head = getHeader(inputFile);
73 
74  const JRange<double>& Erange = head.cut_nu.E;
75 
76  const JCylinder3D can(JCircle2D(JVector2D(0.0, 0.0), head.can.r),
77  head.can.zmin,
78  head.can.zmax);
79 
80  TFile out(outputFile.c_str(), "recreate");
81 
82  TH1D h0 ("h0", "Energy conservation",
83  2000, -100.0, 100.0);
84 
85  TH1D h1 ("h1", "Momentum conservation",
86  1000, 0.0, 100.0);
87 
88  TH1D job ("job", "Particle types",
89  10001, -5000.5, +5000.5);
90  TH2D hv ("hv", "Logarithmic visible energy as function of logarithmic initial state energy",
91  100, log10(Erange.getLowerLimit()), log10(Erange.getUpperLimit()),
92  100, log10(Erange.getLowerLimit()), log10(Erange.getUpperLimit()));
93  TH1D ha ("ha", "Angle between neutrino-direction and visible-energy-weighted direction",
94  200, -1.0, 1.0);
95 
96  TH1D hn ("hn", "Number of muons per event",
97  2001, -0.5, +2000.5);
98  TH1D he ("he", "Muon energies",
99  1000, 0.0, 10.0);
100  TH2D hp ("hp", "Muon positions",
101  100, 0.0, 2.0e5,
102  200, 0.0, 1.5e3);
103 
104  while (inputFile.hasNext()) {
105 
106  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
107 
108  const Evt* event = inputFile.next();
109 
110  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
111  job.Fill((double) track->type);
112  }
113 
114  if (has_neutrino(*event) && is_neutrino(event->mc_trks[0])) {
115 
116  const Trk& neutrino = event->mc_trks[0];
117 
118  const Vec& P0 = getP0(*event);
119  const Vec& P1 = getP1(*event);
120 
121  const double E0 = getE0(*event);
122  const double E1 = getE1(*event);
123 
124  const double Evis = getVisibleEnergy (*event, can);
125  const Vec EvisVector = getVisibleEnergyVector(*event, can);
126 
127  if (!range((E0 - E1)/E0) || !range((P0 - P1).len()/P0.len()) || debug >= debug_t) {
128 
129  NOTICE(endl << FILL(57,'-') << '\n' << FILL());
130  NOTICE("event: " << RIGHT(8) << event->mc_id << RIGHT(67) << "energy [GeV] momentum (x, y, z) [GeV] distance [m]" << endl);
131 
132  for (size_t i = 0; i != event->mc_trks.size(); ++i) {
133 
134  const Trk& track = event->mc_trks[i];
135 
136  const string name = (JPDB::getInstance().hasPDG(track.type) ?
137  JPDB::getInstance().getPDG(track.type).name :
138  MAKE_STRING("unknown (type: " << track.type << ")"));
139 
140  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);
141  }
142  NOTICE(LEFT(32) << "balance:" << ' ' << FIXED(7,3) << E0 - E1 << " " << FIXED(7,3) << P0 - P1 << endl);
143  }
144 
145  h0.Fill( E0 - E1 );
146  h1.Fill((P0 - P1).len());
147 
148  hv.Fill(log10(E0), log10(Evis));
149  ha.Fill(getDirection(neutrino).getDot(getDirection(EvisVector)));
150  }
151 
152 
153  int n = 0;
154 
155  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
156 
157  if (is_muon(*track)) {
158  ++n;
159  he.Fill(log10(track->E));
160  hp.Fill(track->pos.x*track->pos.x + track->pos.y*track->pos.y, track->pos.z);
161  }
162  }
163 
164  hn.Fill((Double_t) n);
165  }
166 
167  STATUS(endl);
168 
169  out.Write();
170  out.Close();
171 
172  return 0;
173 }
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:1514
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
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:674
#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
Vec getVisibleEnergyVector(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy vector of a track.
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
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
double len() const
Get length.
Definition: Vec.hh:145
Auxiliary methods for evaluating visible energies.
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:786
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
I/O formatting auxiliaries.
Cylinder object.
Definition: JCylinder3D.hh:39
JDirection3D getDirection(const Vec &dir)
Get direction.
Monte Carlo run header.
Definition: JHead.hh:1234
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:1989
set_variable E_E log10(E_{fit}/E_{#mu})"
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
#define NOTICE(A)
Definition: JMessage.hh:64
double getVisibleEnergy(const Trk &track, const JCylinder3D &can=getMaximumContainmentVolume())
Get the visible energy of a track.
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
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
Auxiliary class to define a range between two values.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
Vec getP0(const Evt &evt)
Get momentum vector of the initial state of a neutrino interaction.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
Toolkit for JSirene.
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:575