LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCDumpers.h
Go to the documentation of this file.
1 
11 #ifndef LARDATAALG_MCDUMPERS_MCDUMPERS_H
12 #define LARDATAALG_MCDUMPERS_MCDUMPERS_H
13 
14 // LArSoft libraries
15 #include "larcorealg/CoreUtils/DumpUtils.h" // lar::dump namespace
16 #include "larcorealg/Geometry/geo_vectors_utils_TVector.h" // geo::vect::dump
18 
19 // nusimdata libraries
24 
25 // ROOT libraries
26 #include "TLorentzVector.h"
27 
28 // C/C++ standard libraries
29 #include <string>
30 #include <utility> // std::forward()
31 
32 namespace sim {
33 
35  namespace dump {
36 
37  //--------------------------------------------------------------------------
39 
52  template <typename Stream>
53  void DumpMCParticle(Stream&& out,
54  simb::MCParticle const& particle,
55  std::string indent,
56  std::string firstIndent);
57 
58  template <typename Stream>
59  void DumpMCParticle(Stream&& out, simb::MCParticle const& particle, std::string indent = "")
60  {
61  DumpMCParticle(std::forward<Stream>(out), particle, indent, indent);
62  }
63 
65 
66  //--------------------------------------------------------------------------
68 
85  template <typename Stream>
86  void DumpMCParticleTrajectory(Stream&& out,
87  simb::MCTrajectory const& trajectory,
88  unsigned int pointsPerLine,
89  std::string indent);
90 
91  template <typename Stream>
92  void DumpMCParticleTrajectory(Stream&& out, simb::MCTrajectory const& trajectory)
93  {
94  DumpMCParticleTrajectory(std::forward<Stream>(out), trajectory, 0U, "");
95  }
96 
97  // @}
98 
99  //--------------------------------------------------------------------------
100  // @{
115  template <typename Stream>
116  void DumpMCNeutrino(Stream&& out,
117  simb::MCNeutrino const& neutrino,
118  std::string indent,
119  std::string firstIndent);
120 
121  template <typename Stream>
122  void DumpMCNeutrino(Stream&& out, simb::MCNeutrino const& neutrino, std::string indent = "")
123  {
124  DumpMCNeutrino(std::forward<Stream>(out), neutrino, indent, indent);
125  }
126 
127  // @}
128 
129  //--------------------------------------------------------------------------
130  // @{
153  template <typename Stream>
154  void DumpMCTruth(Stream&& out,
155  simb::MCTruth const& truth,
156  unsigned int pointsPerLine,
157  std::string indent,
158  std::string firstIndent);
159 
160  template <typename Stream>
161  void DumpMCTruth(Stream&& out,
162  simb::MCTruth const& truth,
163  unsigned int pointsPerLine,
164  std::string indent = "")
165  {
166  DumpMCTruth(std::forward<Stream>(out), truth, pointsPerLine, indent, indent);
167  }
168 
169  template <typename Stream>
170  void DumpMCTruth(Stream&& out,
171  simb::MCTruth const& truth,
172  std::string indent,
173  std::string firstIndent)
174  {
175  DumpMCTruth(std::forward<Stream>(out), truth, 0, indent, firstIndent);
176  }
177 
178  template <typename Stream>
179  void DumpMCTruth(Stream&& out, simb::MCTruth const& truth, std::string indent = "")
180  {
181  DumpMCTruth(std::forward<Stream>(out), truth, indent, indent);
182  }
183 
184  // @}
185 
186  //--------------------------------------------------------------------------
187  // @{
202  template <typename Stream>
203  void DumpGTruth(Stream&& out,
204  simb::GTruth const& truth,
205  std::string indent,
206  std::string firstIndent);
207 
208  template <typename Stream>
209  void DumpGTruth(Stream&& out, simb::GTruth const& truth, std::string indent = "")
210  {
211  DumpGTruth(std::forward<Stream>(out), truth, indent, indent);
212  }
213 
214  // @}
215 
216  //--------------------------------------------------------------------------
217 
218  } // namespace dump
219 
220 } // namespace sim
221 
222 //------------------------------------------------------------------------------
223 //--- template implementation
224 //------------------------------------------------------------------------------
225 template <typename Stream>
226 void sim::dump::DumpMCParticle(Stream&& out,
227  simb::MCParticle const& particle,
228  std::string indent,
229  std::string firstIndent)
230 {
231  out << firstIndent << "ID=" << particle.TrackId() << ": " << ParticleName(particle.PdgCode())
232  << " mass=" << particle.Mass() << " GeV/c2 "
233  << " status=" << particle.StatusCode() << " (" << ParticleStatusName(particle.StatusCode())
234  << ")";
235  if (particle.Weight() != 1.0) out << " weight=" << particle.Weight();
236  if (particle.Rescatter() != simb::MCParticle::s_uninitialized) {
237  out << " rescattered (" << particle.Rescatter() << ")";
238  }
239  out << "; generator vertex " << particle.GetGvtx();
240  out << "\n"
241  << indent << "created via " << (particle.Process().empty() ? "magics" : particle.Process());
242  if (particle.Mother() == 0)
243  out << " by the gods";
244  else
245  out << " from ID=" << particle.Mother();
246 
247  const unsigned int nDaughters = particle.NumberDaughters();
248  const unsigned int nPoints = particle.NumberTrajectoryPoints();
249  if (nPoints > 0) {
250  TLorentzVector const& start = particle.Position();
251  TLorentzVector const& start_mom = particle.Momentum();
252  out << " at " << start << " cm with momentum " << start_mom << " GeV/c";
253  }
254  if (particle.Polarization().Mag2() != 0.) {
255  out << " with polarization " << lar::dump::vector3D(particle.Polarization());
256  }
257  // does this particle seem to stop? (by decay, or because of extended traj.)
258  if ((nPoints > 1) || (nDaughters > 0)) {
259  out << "\n"
260  << indent << ((nDaughters > 0) ? "ends" : "stops") << " by "
261  << (particle.EndProcess().empty() ? "magics" : particle.EndProcess());
262  if (nPoints > 1) {
263  TLorentzVector const& stop = particle.EndPosition();
264  TLorentzVector const& stop_mom = particle.EndMomentum();
265  out << " at " << stop << " cm with momentum " << stop_mom << " GeV/c";
266  }
267  if (nDaughters > 0) {
268  out << " into ";
269  if (nDaughters == 1)
270  out << "particle ID=" << particle.FirstDaughter();
271  else {
272  out << nDaughters << " particles from ID=" << particle.FirstDaughter()
273  << " to ID=" << particle.LastDaughter();
274  }
275  } // if daughters
276  } // if it stops
277  if (nPoints > 1) {
278  simb::MCTrajectory const& traj = particle.Trajectory();
279  out << "\n"
280  << indent << "comes with a trajectory " << traj.TotalLength() << " cm long in " << nPoints
281  << " points";
282  } // if has points
283 
284 } // sim::dump::DumpMCParticle()
285 
286 //------------------------------------------------------------------------------
287 template <typename Stream>
289  simb::MCTrajectory const& trajectory,
290  unsigned int pointsPerLine,
291  std::string indent)
292 {
293  unsigned int page = 0;
294  for (auto const& pair : trajectory) {
295  if ((pointsPerLine > 0) && (page-- == 0)) {
296  out << "\n" << indent << " ";
297  page = pointsPerLine - 1;
298  }
299  else
300  out << " -- ";
301 
302  TLorentzVector const& pos = pair.first;
303  out << pos;
304  } // for trajectory points
305 
306 } // sim::dump::DumpMCParticleTrajectory()
307 
308 //------------------------------------------------------------------------------
309 template <typename Stream>
310 void sim::dump::DumpMCNeutrino(Stream&& out,
311  simb::MCNeutrino const& nu,
312  std::string indent,
313  std::string firstIndent)
314 {
315 
316  out << firstIndent << "from " << TruthCCNCname(nu.CCNC()) << ", "
317  << TruthInteractionTypeName(nu.InteractionType()) << ", mode: " << nu.Mode() << " ("
318  << TruthReactionMode(nu.Mode()) << ")" << '\n'
319  << indent << "target: " << nu.Target() << " (" << ParticleName(nu.Target()) << ")";
320  if (nu.HitNuc() != 0) {
321  out << ", hit nucleon: " << nu.HitNuc() << " (" << ParticleName(nu.HitNuc()) << ")";
322  }
323  if (nu.HitQuark() != 0) {
324  out << ", hit quark: " << nu.HitQuark() << " (" << ParticleName(nu.HitQuark()) << ")";
325  }
326  out << '\n'
327  << indent << "x=" << nu.X() << " y=" << nu.Y() << " w=" << nu.W() << " Q^2=" << nu.QSqr()
328  << " GeV^2; theta=" << nu.Theta() << " rad pT=" << nu.Pt() << " GeV/c";
329  out << '\n' << indent << "neutrino: ";
330  DumpMCParticle(std::forward<Stream>(out), nu.Nu(), indent + " ", "");
331  out << '\n' << indent << "outgoing lepton: ";
332  DumpMCParticle(std::forward<Stream>(out), nu.Lepton(), indent + " ", "");
333 
334 } // sim::dump::DumpMCNeutrino()
335 
336 //------------------------------------------------------------------------------
337 template <typename Stream>
338 void sim::dump::DumpMCTruth(Stream&& out,
339  simb::MCTruth const& truth,
340  unsigned int pointsPerLine,
341  std::string indent,
342  std::string firstIndent)
343 {
344  // add a dumper of the generator info
345  auto genInfo = truth.GeneratorInfo();
346  out << "Generator ID: " << (int)genInfo.generator << "\n";
347  out << "Generator Version: " << genInfo.generatorVersion << "\n";
348  out << "Generator configuration string map. Pairs separated by colons. "
349  << "\n";
350  for (const auto& gci : genInfo.generatorConfig) {
351  out << " " << gci.first << " : " << gci.second << "\n";
352  }
353 
354  unsigned int const nParticles = truth.NParticles();
355  out << firstIndent << nParticles << " particles from " << TruthOriginName(truth.Origin());
356  if (truth.NeutrinoSet()) {
357  out << '\n' << indent << "neutrino information: ";
358  DumpMCNeutrino(std::forward<Stream>(out), truth.GetNeutrino(), indent + " ", "");
359  }
360  for (unsigned int i = 0; i < nParticles; ++i) {
361  out << '\n' << indent << "[#" << i << "] ";
362  simb::MCParticle const& particle = truth.GetParticle(i);
363  DumpMCParticle(std::forward<Stream>(out), particle, indent + " ", "");
364 
365  const unsigned int nPoints = particle.NumberTrajectoryPoints();
366  if ((nPoints > 0) && (pointsPerLine > 0)) {
367  out << ":";
369  std::forward<Stream>(out), particle.Trajectory(), pointsPerLine, indent + " ");
370  } // if has points
371  } // for all particles
372 
373 } // sim::dump::DumpMCTruth()
374 
375 //------------------------------------------------------------------------------
376 template <typename Stream>
377 void sim::dump::DumpGTruth(Stream&& out,
378  simb::GTruth const& truth,
379  std::string indent,
380  std::string firstIndent)
381 {
382 
383  unsigned int const nCharged = truth.fNumPiPlus + truth.fNumPiMinus + truth.fNumProton;
384  unsigned int const nNeutral = truth.fNumPi0 + truth.fNumNeutron;
385  unsigned int const nPions = truth.fNumPiPlus + truth.fNumPiMinus + truth.fNumPi0;
386  unsigned int const nNucleons = truth.fNumProton + truth.fNumNeutron;
387  unsigned int const nTotalParticles = nCharged + nNeutral;
388 
389  out << firstIndent << "interaction code: " << truth.fGint
390  << ", neutrino scattering code: " << truth.fGscatter << " at " << truth.fVertex << "\n"
391  << indent << "probe: " << ParticleName(truth.fProbePDG) << " with cp=" << truth.fProbeP4
392  << " hit nucleon with cp=" << truth.fHitNucP4 << " GeV"
393  << " (" << (truth.fIsSeaQuark ? "" : "not a ") << "sea quark)"
394  << " in target: " << ParticleName(truth.ftgtPDG) << " (Z: " << truth.ftgtZ
395  << ", A: " << truth.ftgtA << ")"
396  << "\n"
397  << indent << "event interaction weight (genie internal): " << truth.fweight
398  << ", interaction probability: " << truth.fprobability << ", cross section: " << truth.fXsec
399  << ", differential cross section: " << truth.fDiffXsec << "\n"
400  << indent << "particles after reaction, before FSI: " << truth.fNumPiPlus << " pi+"
401  << ", " << truth.fNumPiMinus << " pi-"
402  << ", " << truth.fNumPi0 << " pi0"
403  << ", " << truth.fNumProton << " p/pbar"
404  << ", " << truth.fNumNeutron << " n/nbar"
405  << "\n"
406  << indent << " total " << nTotalParticles
407  << " particles after reaction before FSI"
408  ": "
409  << nCharged << "/" << nNeutral
410  << " charged/neutral"
411  ", "
412  << nPions << " pions, " << nNucleons << " nucleons"
413  << "\n"
414  << indent << "process " << (truth.fIsCharm ? "with" : "without") << " charmed hadron";
415  if (truth.fResNum == -1)
416  out << ", no resonance";
417  else
418  out << ", resonance: #" << truth.fResNum;
419  out << "\n"
420  << indent << "internal (on shell) genie kinematics: Q^2: " << truth.fgQ2 << " GeV^2"
421  << " q^2: " << truth.fgq2 << " GeV^2"
422  << ", w: " << truth.fgW << " GeV^2"
423  << ", t: " << truth.fgT << " GeV^2"
424  << ", x: " << truth.fgX << ", y: " << truth.fgY << "\n"
425  << indent << "FShadSyst: " << truth.fFShadSystP4;
426 
427 } // sim::DumpGTruth::DumpTruth()
428 
429 //------------------------------------------------------------------------------
430 
431 #endif // LARDATAALG_MCDUMPERS_MCDUMPERS_H
double fgW
Definition: GTruth.h:64
int fGint
interaction code
Definition: GTruth.h:56
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:219
const TVector3 & Polarization() const
Definition: MCParticle.h:215
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:220
int PdgCode() const
Definition: MCParticle.h:213
int CCNC() const
Definition: MCNeutrino.h:148
Specializations of geo_vectors_utils.h for ROOT old vector types.
double fgq2
Definition: GTruth.h:63
double QSqr() const
Definition: MCNeutrino.h:157
double Theta() const
angle between incoming and outgoing leptons, in radians
Definition: MCNeutrino.cxx:63
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:77
double fgX
Definition: GTruth.h:66
int ftgtA
Definition: GTruth.h:46
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:326
void DumpGTruth(Stream &&out, simb::GTruth const &truth, std::string indent, std::string firstIndent)
Dumps the content of the GENIE truth in the output stream.
Definition: MCDumpers.h:377
Trajectory class.
std::string TruthInteractionTypeName(int type)
const TLorentzVector & EndPosition() const
Definition: MCParticle.h:226
double Weight() const
Definition: MCParticle.h:255
static const int s_uninitialized
Definition: MCParticle.h:28
int HitQuark() const
Definition: MCNeutrino.h:153
int FirstDaughter() const
Definition: MCParticle.h:251
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:254
int Mother() const
Definition: MCParticle.h:214
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:146
simb::Origin_t Origin() const
Definition: MCTruth.h:74
double Mass() const
Definition: MCParticle.h:240
double Pt() const
transverse momentum of interaction, in GeV/c
Definition: MCNeutrino.cxx:74
int fNumNeutron
number of neutrons after reaction, before FSI
Definition: GTruth.h:81
void DumpMCParticleTrajectory(Stream &&out, simb::MCTrajectory const &trajectory, unsigned int pointsPerLine, std::string indent)
Dumps the specified particle trajectory into the output stream.
Definition: MCDumpers.h:288
int HitNuc() const
Definition: MCNeutrino.h:152
int ftgtZ
Definition: GTruth.h:45
double fXsec
cross section of interaction
Definition: GTruth.h:30
for(Int_t i=0;i< nentries;i++)
Definition: comparison.C:30
int fNumPiPlus
number of pi pluses after reaction, before FSI
Definition: GTruth.h:83
int StatusCode() const
Definition: MCParticle.h:212
int fNumPiMinus
number of pi minuses after reaction, before FSI
Definition: GTruth.h:84
std::string TruthCCNCname(int ccnc)
int NParticles() const
Definition: MCTruth.h:75
std::string Process() const
Definition: MCParticle.h:216
TLorentzVector GetGvtx() const
Definition: MCParticle.h:246
Particle class.
int NumberDaughters() const
Definition: MCParticle.h:218
int TrackId() const
Definition: MCParticle.h:211
TLorentzVector fProbeP4
Definition: GTruth.h:41
int fResNum
resonance number
Definition: GTruth.h:89
int fNumProton
number of protons after reaction, before FSI
Definition: GTruth.h:80
int InteractionType() const
Definition: MCNeutrino.h:150
double fprobability
interaction probability
Definition: GTruth.h:29
std::string TruthReactionMode(int mode)
Returns the "mode" of the reaction (a lesser version of interaction type).
const simb::MCParticle & Lepton() const
Definition: MCNeutrino.h:147
Utilities to dump objects into a stream.
double W() const
Definition: MCNeutrino.h:154
int fProbePDG
Definition: GTruth.h:39
std::string EndProcess() const
Definition: MCParticle.h:217
double Y() const
Definition: MCNeutrino.h:156
int fGscatter
neutrino scattering code
Definition: GTruth.h:55
int fNumPi0
number of pi0 after reaction, before FSI
Definition: GTruth.h:82
simb::Generator_t generator
event generator that generated this event
std::string indent(std::size_t const i)
std::string ParticleName(int pigid)
Returns a string with the name of particle the specified with PDG ID.
void DumpMCTruth(Stream &&out, simb::MCTruth const &truth, unsigned int pointsPerLine, std::string indent, std::string firstIndent)
Dumps the content of the specified MC truth in the output stream.
Definition: MCDumpers.h:338
bool fIsCharm
did the interaction produce a charmed hadron?
Definition: GTruth.h:76
double fweight
event interaction weight (genie internal)
Definition: GTruth.h:28
double X() const
Definition: MCNeutrino.h:155
Monte Carlo Simulation.
TLorentzVector fHitNucP4
Definition: GTruth.h:51
Collection of utilities for dumping data on screen.
Definition: DumperBase.h:28
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:76
int Target() const
Definition: MCNeutrino.h:151
std::string TruthOriginName(simb::Origin_t origin)
Returns a string representing the specified process origin.
double TotalLength() const
int ftgtPDG
PDG of Target Nucleus, nucleon only if free.
Definition: GTruth.h:47
double fgQ2
Definition: GTruth.h:62
Utility functions to print MC truth information.
int LastDaughter() const
Definition: MCParticle.h:252
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:221
TLorentzVector fFShadSystP4
generated final state hadronic system (LAB frame)
Definition: GTruth.h:73
int Rescatter() const
Definition: MCParticle.h:253
double fgT
Definition: GTruth.h:65
void DumpMCNeutrino(Stream &&out, simb::MCNeutrino const &neutrino, std::string indent, std::string firstIndent)
Dumps the content of the specified neutrino in the output stream.
Definition: MCDumpers.h:310
bool NeutrinoSet() const
Definition: MCTruth.h:78
Event generator information.
Definition: MCTruth.h:32
Event generator information.
Definition: MCNeutrino.h:18
int Mode() const
Definition: MCNeutrino.h:149
bool fIsSeaQuark
Definition: GTruth.h:50
std::string ParticleStatusName(int code)
Describes the status of a particle (simb::MCParticle::StatusCode()).
TLorentzVector fVertex
Definition: GTruth.h:26
const TLorentzVector & EndMomentum() const
Definition: MCParticle.h:241
double fgY
a common running variable to be recorded
Definition: GTruth.h:67
double fDiffXsec
differential cross section of interaction
Definition: GTruth.h:31
void DumpMCParticle(Stream &&out, simb::MCParticle const &particle, std::string indent, std::string firstIndent)
Dumps the content of the specified particle in the output stream.
Definition: MCDumpers.h:226
const simb::MCGeneratorInfo & GeneratorInfo() const
Definition: MCTruth.h:73