Jpp
 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 #include "TDatabasePDG.h"
13 #include "TParticlePDG.h"
14 
16 #include "JAAnet/JAAnetToolkit.hh"
17 
20 #include "JSupport/JSupport.hh"
21 
22 #include "JTools/JRange.hh"
23 
24 #include "JPhysics/JGeane.hh"
25 
26 #include "JSirene/JPythia.hh"
27 
28 #include "Jeep/JPrint.hh"
29 #include "Jeep/JParser.hh"
30 #include "Jeep/JMessage.hh"
31 
32 namespace {
33 
34  using namespace JPP;
35 
36  /**
37  * Get track energy.\n
38  * This method includes ionization and radiative energy losses for muons.
39  *
40  * \param trk track
41  * \param start starting position of track [m]
42  * \return energy [GeV]
43  */
44  inline double getE(const Trk& trk, const Vec& start)
45  {
46  return (is_muon(trk) ? gWater(trk.E, -(trk.pos - start).len()) : trk.E);
47  }
48 
49 
50  /**
51  * Get track kinetic energy.
52  * This method includes ionization and radiative energy losses for muons.
53  *
54  * \param trk track
55  * \param start starting position of track [m]
56  * \return kinetic energy [GeV]
57  */
58  inline double getEkin(const Trk& trk, const Vec& start)
59  {
60  const TDatabasePDG pdb;
61 
62  const double energy = getE(trk, start);
63  const double mass = pdb.GetParticle(trk.type)->Mass();
64 
65  if (energy > mass) {
66 
67  return sqrt((energy - mass) * (energy + mass));
68 
69  } else {
70 
71  return 0.0;
72  }
73  }
74 
75 
76  /**
77  * Get energy of initial state.\n
78  * This method includes baryon number conservation.
79  *
80  * \param evt event
81  * \return energy [GeV]
82  */
83  inline double getE0(const Evt& evt)
84  {
85  double E0 = 0.0;
86 
87  if (!evt.mc_trks.empty() && is_neutrino(evt.mc_trks[0])) {
88 
89  const Trk& neutrino = evt.mc_trks[0];
90 
91  E0 += neutrino.E;
92 
93  for (size_t i = 1; i != evt.mc_trks.size(); ++i) {
94 
95  const Trk& track = evt.mc_trks[i];
96 
97  if (track.type == TRACK_TYPE_NEUTRON ||
98  track.type == TRACK_TYPE_SIGMA_MINUS) {
99  E0 += MASS_NEUTRON;
100  }
101 
102  if (track.type == TRACK_TYPE_PROTON ||
103  track.type == TRACK_TYPE_LAMBDA ||
104  track.type == TRACK_TYPE_SIGMA_PLUS) {
105  E0 += MASS_PROTON;
106  }
107 
108  if (track.type == TRACK_TYPE_ANTINEUTRON) {
109  E0 -= MASS_NEUTRON;
110  }
111 
112  if (track.type == TRACK_TYPE_ANTIPROTON ||
113  track.type == TRACK_TYPE_ANTILAMBDA) {
114  E0 -= MASS_PROTON;
115  }
116  }
117  }
118 
119  return E0;
120  }
121 
122 
123  /**
124  * Get energy of final state.\n
125  * This method includes muon energy loss.
126  *
127  * \param evt event
128  * \return energy [GeV]
129  */
130  inline double getE1(const Evt& evt)
131  {
132  double E1 = 0.0;
133 
134  if (has_neutrino(evt) && is_neutrino(evt.mc_trks[0])) {
135 
136  const Trk& neutrino = evt.mc_trks[0];
137 
138  for (size_t i = 1; i != evt.mc_trks.size(); ++i) {
139 
140  const Trk& track = evt.mc_trks[i];
141 
142  E1 += getE(track, neutrino.pos);
143  }
144  }
145 
146  return E1;
147  }
148 
149 
150  /**
151  * Get visible energy of final state track.\n
152  * This method includes ionization and radiative energy losses for muons.
153  *
154  * \param track track
155  * \param start starting position of track [m]
156  * \return visible energy [GeV]
157  */
158  inline double getVisibleEnergy(const Trk& track, const Vec& start) {
159 
160  if (is_muon(track)) {
161 
162  const double muMeters = gWater.getX(getE(track, start), MASS_MUON);
163 
164  return muMeters / geanc();
165 
166  } else {
167 
168  return pythia(track.type, getEkin(track, start));
169  }
170  }
171 
172 
173  /**
174  * Get visible energy of final state.\n
175  * This method includes muon energy loss.
176  *
177  * \param evt event
178  * \return visible energy [GeV]
179  */
180  inline double getVisibleEnergy(const Evt& evt)
181  {
182  double Evis = 0.0;
183 
184  if (has_neutrino(evt) && is_neutrino(evt.mc_trks[0])) {
185 
186  const Trk& neutrino = evt.mc_trks[0];
187 
188  for (size_t i = 1; i != evt.mc_trks.size(); ++i) {
189 
190  Evis += getVisibleEnergy(evt.mc_trks[i], neutrino.pos);
191  }
192  }
193 
194  return Evis;
195  }
196 
197 
198  /**
199  * Get visible-energy-weighted mean of the track directions.
200  *
201  * \param evt event
202  * \return visible energy [GeV]
203  */
204  inline Vec getVisibleEnergyDirection(const Evt& evt)
205  {
206  Vec EvisDir;
207 
208  const double EvisTotal = getVisibleEnergy(evt);
209 
210  if (has_neutrino(evt) && is_neutrino(evt.mc_trks[0])) {
211 
212  const Trk& neutrino = evt.mc_trks[0];
213 
214  for (size_t i = 1; i < evt.mc_trks.size(); ++i) {
215 
216  const Trk& track = evt.mc_trks[i];
217  const double EvisFrac = getVisibleEnergy(track, neutrino.pos) / EvisTotal;
218 
219  EvisDir += EvisFrac * track.dir;
220  }
221  }
222 
223  return EvisDir.normalize();
224  }
225 
226 
227  /**
228  * Get the transverse component of the visible energy of a track\n
229  * with respect to a reference direction.
230  *
231  * \param track particle track
232  * \param start starting position of track [m]
233  * \param refDir reference direction
234  * \return transverse component of visible energy [GeV]
235  */
236  inline double getTransverseVisibleEnergy(const Trk& track,
237  const Vec& start,
238  const Vec& refDir)
239  {
240  const double costh = getDirection(refDir).getDot(getDirection(track));
241  const double sinth = (1 + costh) * (1 - costh);
242 
243  return sinth * getVisibleEnergy(track, start);
244  }
245 
246 
247  /**
248  * Get the square-root of the summed square transverse visible energy of all final state tracks\n
249  * defined with respect to a reference direction.
250  *
251  * \param track particle track
252  * \param refDir reference direction
253  * \return transverse component of visible energy [GeV]
254  */
255  inline double getTransverseVisibleEnergy(const Evt& evt, const Vec& refDir)
256  {
257  double EvisT2 = 0.0;
258 
259  if (has_neutrino(evt) && is_neutrino(evt.mc_trks[0])) {
260 
261  const Trk& neutrino = evt.mc_trks[0];
262 
263  for (size_t i = 1; i < evt.mc_trks.size(); ++i) {
264 
265  const double EvisT = getTransverseVisibleEnergy(evt.mc_trks[i], neutrino.dir, refDir);
266 
267  EvisT2 += EvisT * EvisT;
268  }
269  }
270 
271  return sqrt(EvisT2);
272  }
273 
274 
275  /**
276  * Get momentum vector of initial state.\n
277  * This method assumes neutrino DIS on a stationary nucleus
278  *
279  * \param evt event
280  * \return energy [GeV]
281  */
282  inline Vec getP0(const Evt& evt)
283  {
284  Vec P0;
285 
286  if (has_neutrino(evt) && is_neutrino(evt.mc_trks[0])) {
287 
288  const Trk& neutrino = evt.mc_trks[0];
289 
290  P0 = neutrino.E * neutrino.dir;
291  }
292 
293  return P0;
294  }
295 
296 
297  /**
298  * Get momentum vector of final state.\n
299  * This method includes muon energy loss.
300  *
301  * \param evt event
302  * \return final state momentum vector [GeV]
303  */
304  inline Vec getP1(const Evt& evt)
305  {
306  Vec P1;
307 
308  if (has_neutrino(evt) && is_neutrino(evt.mc_trks[0])) {
309 
310  const Trk& neutrino = evt.mc_trks[0];
311 
312  for (size_t i = 1; i != evt.mc_trks.size(); ++i) {
313 
314  const Trk& track = evt.mc_trks[i];
315  const double trackEk = getEkin(track, neutrino.pos);
316 
317  P1 += trackEk * track.dir;
318  }
319  }
320 
321  return P1;
322  }
323 }
324 
325 
326 /**
327  * \file
328  *
329  * Example program to verify generator data.
330  * \author mdejong
331  */
332 int main(int argc, char **argv)
333 {
334  using namespace std;
335  using namespace JPP;
336 
337  JMultipleFileScanner<Evt> inputFile;
338  JLimit_t& numberOfEvents = inputFile.getLimit();
339  string outputFile;
341  int debug;
342 
343  try {
344 
345  JParser<> zap("Example program to verify generator data.");
346 
347  zap['f'] = make_field(inputFile);
348  zap['o'] = make_field(outputFile) = "pizza.root";
349  zap['n'] = make_field(numberOfEvents) = JLimit::max();
350  zap['R'] = make_field(range, "fractional energy and momentum conservation") = JRange<double>(-0.01, +0.01);
351  zap['d'] = make_field(debug) = 0;
352 
353  zap(argc, argv);
354  }
355  catch(const exception &error) {
356  FATAL(error.what() << endl);
357  }
358 
359  cout.tie(&cerr);
360 
361  TFile out(outputFile.c_str(), "recreate");
362 
363  TH1D h0 ("h0", "Fractional energy conservation",
364  1001, -1.0, +1.0);
365  TH1D h1 ("h1", "Fractional momentum conservation",
366  1001, -1.0, +1.0);
367  TH1D job("job", "Particle types",
368  10001, -5000.5, +5000.5);
369 
370  TH1D hv("hv", "Visible energy as fraction of initial state energy",
371  25, 0.0, 2.5);
372  TH1D ha("ha", "Angle between neutrino-direction and visible-energy-weighted direction",
373  200, -1.0, 1.0);
374  TH1D ht("ht", "Square-root of summed squared transverse visible energy as fraction of initial state energy",
375  120, 0.0, 1.2);
376 
377  TH1D hn("hn", "Number of muons per event",
378  2001, -0.5, +2000.5);
379  TH1D he("he", "Muon energies",
380  1000, 0.0, 10.0);
381  TH2D hp("hp", "Muon positions",
382  100, 0.0, 2.0e5,
383  200, 0.0, 1.5e3);
384 
385 
386  while (inputFile.hasNext()) {
387 
388  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
389 
390  const Evt* event = inputFile.next();
391 
392  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
393  job.Fill((double) track->type);
394  }
395 
396  if (has_neutrino(*event) && is_neutrino(event->mc_trks[0])) {
397 
398  const Trk& neutrino = event->mc_trks[0];
399 
400  const Vec& P0 = getP0(*event);
401  const Vec& P1 = getP1(*event);
402 
403  const double E0 = getE0(*event);
404  const double E1 = getE1(*event);
405 
406  const double Evis = getVisibleEnergy (*event);
407  const Vec& EvisDir = getVisibleEnergyDirection (*event);
408  const double EvisT = getTransverseVisibleEnergy(*event, EvisDir);
409 
410  if (!range((E0 - E1)/E0) || !range((P0 - P1).len()/P0.len()) || debug >= debug_t) {
411 
412  cout << endl << "--------------------------------------------------------" << endl;
413  cout << "event: " << setw(8) << event->mc_id << " energy [GeV] momentum (x, y, z) [GeV] distance [m]" << endl;
414 
415  for (size_t i = 0; i != event->mc_trks.size(); ++i) {
416 
417  const Trk& track = event->mc_trks[i];
418 
419  const TDatabasePDG pdg;
420  const TParticlePDG* particle = pdg.GetParticle(track.type);
421 
422  cout << setw(32) << left << showpos << particle->GetName() << ' ' << FIXED(7,3) << track.E << " " << FIXED(7,3) << track.E * track.dir << " " << FIXED(7,3) << (track.pos - neutrino.pos).len() << endl;
423  }
424  cout << setw(32) << left << "balance:" << ' ' << FIXED(7,3) << E0 - E1 << " " << FIXED(7,3) << P0 - P1 << endl;
425  }
426 
427  hv.Fill(Evis/E0);
428  ht.Fill(EvisT/E0);
429  ha.Fill(getDirection(neutrino).getDot(getDirection(EvisDir)));
430 
431  h0.Fill((E0 - E1)/E0);
432  h1.Fill((P0 - P1).len()/P0.len());
433  }
434 
435 
436  int n = 0;
437 
438  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
439 
440  if (is_muon(*track)) {
441  ++n;
442  he.Fill(log10(track->E));
443  hp.Fill(track->pos.x*track->pos.x + track->pos.y*track->pos.y, track->pos.z);
444  }
445  }
446 
447  hn.Fill((Double_t) n);
448  }
449  STATUS(endl);
450 
451  out.Write();
452  out.Close();
453 }
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
ROOT TTree parameter settings of various packages.
double z
Definition: Vec.hh:14
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:409
double geanc()
Equivalent muon track length per unit shower energy.
Definition: JGeane.hh:26
Energy loss of muon.
#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:17
static const double MASS_MUON
muon mass [GeV]
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:323
virtual double getX(const double E0, const double E1) const override
Get distance traveled by muon.
Definition: JGeane.hh:291
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
static const JPythia pythia
Function object for relative light yield as a function of GEANT particle code.
Definition: JPythia.hh:96
string outputFile
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:19
double y
Definition: Vec.hh:14
double getDot(const JAngle3D &angle) const
Get dot product.
double len() const
Get length.
Definition: Vec.hh:145
static const double MASS_NEUTRON
neutron mass [GeV]
bool is_neutrino(const Trk &track)
Test whether given track is a neutrino.
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
I/O formatting auxiliaries.
JDirection3D getDirection(const Vec &dir)
Get direction.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
Vec & normalize()
Normalise this vector.
Definition: Vec.hh:159
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi mv $WORKDIR/fit.root $MODULE_ROOT typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Definition: module-Z:fit.sh:84
#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:23
then for APP in event gandalf start energy
Definition: JMuonMCEvt.sh:42
Vec pos
postion of the track at time t [m]
Definition: Trk.hh:16
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.
alias put_queue eval echo n
Definition: qlib.csh:19
static const double MASS_PROTON
proton mass [GeV]
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:13
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:46
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15