LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ArtG4tkParticle.cc
Go to the documentation of this file.
1 
3 
4 #include "Geant4/G4ParticleTable.hh"
5 
6 #include <assert.h>
7 
9 {
10 
11  fPDG = 0;
12 }
13 
14 artg4tk::ArtG4tkParticle::ArtG4tkParticle(const int pdg, const CLHEP::HepLorentzVector& mom)
15 {
16 
17  fPDG = pdg;
18  fMomentum = mom;
19 }
20 
21 artg4tk::ArtG4tkParticle::ArtG4tkParticle(const int pdg, const CLHEP::Hep3Vector& mom)
22 {
23 
24  SetPDG(pdg);
25  SetMomentum(mom);
26 }
27 
29  : fPDG(other.fPDG), fMomentum(other.fMomentum)
30 {}
31 
32 // artg4tk::ArtG4tkParticle& ArtG4tkParticle::operator=( const ArtG4tkParticle& other )
33 //{
34 //
35 // fPDG = other.fPDG;
36 // fMomentum = other.fMomentum;
37 // return *this;
38 //
39 //}
40 
41 void
43 {
44 
45  fPDG = pdg;
46  return;
47 }
48 
49 void
50 artg4tk::ArtG4tkParticle::SetMomentum(const CLHEP::HepLorentzVector& mom)
51 {
52 
53  fMomentum = mom;
54  return;
55 }
56 
57 void
58 artg4tk::ArtG4tkParticle::SetMomentum(const CLHEP::Hep3Vector& mom)
59 {
60 
61  // NOTE(JVY): A bit of "risky business" in case of ions (apart from
62  // the 6 most basic ones) because they're added "on the fly"
63  // during Geant4 simulation... so if used in the job where
64  // Geant4 sim is also running, it's OK; otherwse better avoid.
65  //
66  assert(fPDG != 0);
67  G4ParticleTable* ptable = G4ParticleTable::GetParticleTable();
68  G4ParticleDefinition* g4pd = ptable->FindParticle(fPDG);
69  assert(g4pd);
70  double mass = g4pd->GetPDGMass();
71  double e = std::sqrt(mom.mag2() + mass * mass);
72  fMomentum.setX(mom.x());
73  fMomentum.setY(mom.y());
74  fMomentum.setZ(mom.z());
75  fMomentum.setE(e);
76 
77  return;
78 }
79 
80 std::string
82 {
83 
84  // NOTE(JVY): again, this a bit of "risky business" when it comes
85  // to ions/nuclei that can be produced during Geant4 sim.
86  // It all works fine if the analyzer runs in the same job
87  // as Geant4 app because G4IonTable gets populated with
88  // newly produced ions as they appears (on-the-fly).
89  // (Elementary) Particles can be added to the table at the
90  // very start of the job, that's no problem.
91  // But when reading back evt.products, it's NOT the case.
92  // And somehow even G4IonTable::CreateAll<...> doesn't help.
93  //
94  // Maybe better to just store the name as a data member ???
95 
96  assert(fPDG != 0);
97  G4ParticleTable* ptable = G4ParticleTable::GetParticleTable();
98  G4ParticleDefinition* g4pd = ptable->FindParticle(fPDG);
99 
100  // assert(g4pd);
101 
102  if (fPDG > 1000000000 && !g4pd) {
103  return "GenericIon";
104  } else {
105  return std::string(g4pd->GetParticleName().c_str());
106  }
107 }
CLHEP::HepLorentzVector fMomentum
void SetMomentum(const CLHEP::HepLorentzVector &)
Float_t e
Definition: plot.C:35
std::string GetName() const