Jpp
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 
13 #include "evt/Evt.hh"
14 #include "JAAnet/JAAnetToolkit.hh"
15 #include "JAAnet/JPDB.hh"
16 
19 #include "JSupport/JSupport.hh"
20 #include "JTools/JRange.hh"
21 #include "JPhysics/JGeane.hh"
22 
23 #include "Jeep/JPrint.hh"
24 #include "Jeep/JParser.hh"
25 #include "Jeep/JMessage.hh"
26 
27 namespace {
28 
29  using namespace JPP;
30 
31  /**
32  * Particle Data Book.
33  */
34  const JPDB pdb = JPDB::getInstance();
35 
36 
37  /**
38  * Get energy of initial state.\n
39  * This method includes baryon number conservation.
40  *
41  * \param evt event
42  * \return energy [GeV]
43  */
44  inline double getE0(const Evt& evt)
45  {
46  double E0 = 0.0;
47 
48  if (!evt.mc_trks.empty() && is_neutrino(evt.mc_trks[0])) {
49 
50  const Trk& neutrino = evt.mc_trks[0];
51 
52  E0 += neutrino.E;
53 
54  for (size_t i = 1; i != evt.mc_trks.size(); ++i) {
55 
56  const Trk& track = evt.mc_trks[i];
57 
58  if (track.type == TRACK_TYPE_NEUTRON ||
59  track.type == TRACK_TYPE_SIGMA_MINUS) {
60  E0 += MASS_NEUTRON;
61  }
62 
63  if (track.type == TRACK_TYPE_PROTON ||
64  track.type == TRACK_TYPE_LAMBDA ||
65  track.type == TRACK_TYPE_SIGMA_PLUS) {
66  E0 += MASS_PROTON;
67  }
68 
69  if (track.type == TRACK_TYPE_ANTINEUTRON) {
70  E0 -= MASS_NEUTRON;
71  }
72 
73  if (track.type == TRACK_TYPE_ANTIPROTON ||
74  track.type == TRACK_TYPE_ANTILAMBDA) {
75  E0 -= MASS_PROTON;
76  }
77  }
78  }
79 
80  return E0;
81  }
82 
83 
84  /**
85  * Get energy of final state.\n
86  * This method includes muon energy loss.
87  *
88  * \param evt event
89  * \return energy [GeV]
90  */
91  inline double getE1(const Evt& evt)
92  {
93  double E1 = 0.0;
94 
95  if (!evt.mc_trks.empty() && is_neutrino(evt.mc_trks[0])) {
96 
97  const Trk& neutrino = evt.mc_trks[0];
98 
99  for (size_t i = 1; i != evt.mc_trks.size(); ++i) {
100 
101  const Trk& track = evt.mc_trks[i];
102 
103  if (track.type == TRACK_TYPE_MUON ||
104  track.type == TRACK_TYPE_ANTIMUON) {
105 
106  E1 += gWater(track.E, -(track.pos - neutrino.pos).len());
107 
108  } else {
109 
110  E1 += track.E;
111  }
112  }
113  }
114 
115  return E1;
116  }
117 }
118 
119 
120 /**
121  * \file
122  *
123  * Example program to verify generator data.
124  * \author mdejong
125  */
126 int main(int argc, char **argv)
127 {
128  using namespace std;
129  using namespace JPP;
130 
131  JMultipleFileScanner<Evt> inputFile;
132  JLimit_t& numberOfEvents = inputFile.getLimit();
133  string outputFile;
134  JRange<double> range;
135  int debug;
136 
137  try {
138 
139  JParser<> zap("Example program to verify generator data.");
140 
141  zap['f'] = make_field(inputFile);
142  zap['o'] = make_field(outputFile) = "pizza.root";
143  zap['n'] = make_field(numberOfEvents) = JLimit::max();
144  zap['R'] = make_field(range, "fractional energy conservation") = JRange<double>(-0.01, +0.01);
145  zap['d'] = make_field(debug) = 0;
146 
147  zap(argc, argv);
148  }
149  catch(const exception &error) {
150  FATAL(error.what() << endl);
151  }
152 
153  cout.tie(&cerr);
154 
155  TFile out(outputFile.c_str(), "recreate");
156 
157  TH1D h0 ("h0", NULL, 1001, -1.0, +1.0);
158  TH1D job("job", NULL, 10001, -5000.5, +5000.5);
159 
160  TH1D hn ("hn", NULL, 2001, -0.5, +2000.5);
161  TH1D he ("he", NULL, 1000, 0.0, 10.0);
162 
163  TH2D h2 ("h2", NULL,
164  100, 0.0, 2.0e5,
165  200, 0.0, 1.5e3);
166 
167 
168  while (inputFile.hasNext()) {
169 
170  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
171 
172  const Evt* event = inputFile.next();
173 
174  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
175  job.Fill((double) track->type);
176  }
177 
178  if (has_neutrino(*event) && is_neutrino(event->mc_trks[0])) {
179 
180  const double E0 = getE0(*event);
181  const double E1 = getE1(*event);
182 
183  if (!range((E0 - E1)/E0) || debug >= debug_t) {
184 
185  const Trk& neutrino = event->mc_trks[0];
186 
187  cout << endl << "--------------------------------------------------------" << endl;
188  cout << "event: " << setw(8) << event->mc_id << " energy [GeV] distance [m]" << endl;
189 
190  for (size_t i = 0; i != event->mc_trks.size(); ++i) {
191 
192  const Trk& track = event->mc_trks[i];
193  const JParticle& particle = pdb.getPDG(track.type);
194 
195  cout << setw(32) << left << particle.name << ' ' << FIXED(7,3) << track.E << " " << FIXED(7,3) << (track.pos - neutrino.pos).len() << endl;
196  }
197  cout << setw(32) << left << "balance" << ' ' << FIXED(7,3) << E0 - E1 << endl;
198  }
199 
200  h0.Fill((E0 - E1)/E0);
201  }
202 
203 
204  int n = 0;
205 
206  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
207 
208  if (is_muon(*track)) {
209  ++n;
210  he.Fill(log10(track->E));
211  h2.Fill(track->pos.x*track->pos.x + track->pos.y*track->pos.y, track->pos.z);
212  }
213  }
214 
215  hn.Fill((Double_t) n);
216  }
217  STATUS(endl);
218 
219  out.Write();
220  out.Close();
221 }
JAANET::TRACK_TYPE_LAMBDA
Definition: JParticleTypes.hh:79
JGeane.hh
JAANET::TRACK_TYPE_ANTIPROTON
Definition: JParticleTypes.hh:99
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JMessage.hh
JPHYSICS::gWater
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:328
JPrint.hh
JAANET::TRACK_TYPE_PROTON
Definition: JParticleTypes.hh:77
JTOOLS::MASS_PROTON
static const double MASS_PROTON
proton mass [GeV]
Definition: JConstants.hh:67
JAANET::JPDB::getInstance
static const JPDB & getInstance()
Get particle data book.
Definition: JPDB.hh:121
JTOOLS::n
const int n
Definition: JPolint.hh:628
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::JRange< double >
JAANET::JPDB
Collection of particles.
Definition: JPDB.hh:105
JAANET::JParticle::name
std::string name
name of particle
Definition: JPDB.hh:85
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JAANET::TRACK_TYPE_ANTINEUTRON
Definition: JParticleTypes.hh:100
JAANET::is_muon
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
Definition: JAAnetToolkit.hh:367
JAANET::TRACK_TYPE_SIGMA_PLUS
Definition: JParticleTypes.hh:80
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
main
int main(int argc, char **argv)
Definition: JPizza.cc:126
JRange.hh
JSUPPORT::JMultipleFileScanner::getCounter
counter_type getCounter() const
Get counter.
Definition: JMultipleFileScanner.hh:323
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JMultipleFileScanner::next
virtual const pointer_type & next()
Get next element.
Definition: JMultipleFileScanner.hh:398
JAAnetToolkit.hh
JAANET::has_neutrino
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
Definition: JAAnetToolkit.hh:427
JMultipleFileScanner.hh
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JSUPPORT::JMultipleFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JMultipleFileScanner.hh:350
JAANET::TRACK_TYPE_ANTILAMBDA
Definition: JParticleTypes.hh:101
JParser.hh
JAANET::JPDB::getPDG
const JParticle & getPDG(const int pdg) const
Get particle corresponding to given PDG code.
Definition: JPDB.hh:227
JAANET::JParticle
Auxiliary class to handle particle name, codes and mass.
Definition: JPDB.hh:33
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
JAANET::is_neutrino
bool is_neutrino(const Trk &track)
Test whether given track is a neutrino.
Definition: JAAnetToolkit.hh:349
JAANET::TRACK_TYPE_ANTIMUON
Definition: JParticleTypes.hh:89
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JPDB.hh
JMonteCarloFileSupportkit.hh
JAANET::TRACK_TYPE_MUON
Definition: JParticleTypes.hh:66
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JAANET::TRACK_TYPE_NEUTRON
Definition: JParticleTypes.hh:78
JEEP::debug_t
debug
Definition: JMessage.hh:29
JTOOLS::MASS_NEUTRON
static const double MASS_NEUTRON
neutron mass [GeV]
Definition: JConstants.hh:68
JAANET::TRACK_TYPE_SIGMA_MINUS
Definition: JParticleTypes.hh:82