LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCParticle.cxx
Go to the documentation of this file.
9 
10 #include <TDatabasePDG.h>
11 #include <TParticlePDG.h>
12 #include <TLorentzVector.h>
13 #include <TVector3.h>
14 
15 #include <iterator>
16 #include <iostream>
17 #include <climits>
18 
19 namespace simb {
20 
21  // static variables
22 
28 
29  const int MCParticle::s_uninitialized = std::numeric_limits<int>::min();
30 
31  //------------------------------------------------------------
33  : fstatus(s_uninitialized)
34  , ftrackId(s_uninitialized)
35  , fpdgCode(s_uninitialized)
36  , fmother(s_uninitialized)
37  , fprocess()
38  , fendprocess()
39  , fmass(s_uninitialized)
40  , fpolarization()
41  , fdaughters()
42  , fWeight(s_uninitialized)
43  , fGvtx()
44  , frescatter(s_uninitialized)
45  {
46  }
47 
48  //------------------------------------------------------------
50  MCParticle::MCParticle(const int trackId,
51  const int pdg,
52  const std::string process,
53  const int mother,
54  const double mass,
55  const int status)
56  : fstatus(status)
57  , ftrackId(trackId)
58  , fpdgCode(pdg)
59  , fmother(mother)
60  , fprocess(process)
61  , fendprocess(std::string())
62  , fmass(mass)
63  , fpolarization()
64  , fdaughters()
65  , fWeight(0.)
66  , fGvtx()
68  {
69  // If the user has supplied a mass, use it. Otherwise, get the
70  // particle mass from the PDG table.
71  if ( mass < 0 ){
72  const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
73  const TParticlePDG* definition = databasePDG->GetParticle( pdg );
74  // Check that the particle is known to ROOT. If not, this is
75  // not a major error; Geant4 has an internal particle coding
76  // scheme for nuclei that ROOT doesn't recognize.
77  if ( definition != 0 ){
78  fmass = definition->Mass();
79  }
80  }
81  else fmass = mass;
82  SetGvtx(0, 0, 0, 0);
83  }
84 
85 
86  MCParticle::MCParticle(MCParticle const& p, int offset)
87  : fstatus(p.StatusCode())
88  , fpdgCode(p.PdgCode())
89  , fprocess(p.Process())
90  , fendprocess(p.EndProcess())
91  , ftrajectory(p.Trajectory())
92  , fmass(p.Mass())
93  , fWeight(p.Weight())
94  , fGvtx(p.GetGvtx())
95  , frescatter(p.Rescatter())
96  {
97 
98  ftrackId = p.TrackId()>=0? p.TrackId()+offset : p.TrackId()-offset;
99  fmother = p.Mother()>=0? p.Mother()+offset : p.Mother()-offset;
100 
101  for(int i=0; i<p.NumberDaughters(); i++){
102  if(p.Daughter(i)>=0)
103  fdaughters.insert(p.Daughter(i)+offset);
104  else
105  fdaughters.insert(p.Daughter(i)-offset);
106  }
107  }
108 
109 
110  //----------------------------------------------------------------------------
111  void MCParticle::SetEndProcess(std::string s)
112  {
113  fendprocess = s;
114  }
115 
116  //------------------------------------------------------------
117  // Return the "index-th' daughter in the list.
118  int MCParticle::Daughter( const int index ) const
119  {
121  std::advance( i, index );
122  return *i;
123  }
124 
125  //----------------------------------------------------------------------------
126  void MCParticle::SetGvtx(double *v)
127  {
128  for(int i = 0; i < 4; i++) {
129  fGvtx[i] = v[i];
130  }
131  }
132 
133  //----------------------------------------------------------------------------
134  void MCParticle::SetGvtx(float *v)
135  {
136  for(int i = 0; i < 4; i++) {
137  fGvtx[i] = v[i];
138  }
139  }
140 
141  //----------------------------------------------------------------------------
142  void MCParticle::SetGvtx(TLorentzVector v)
143  {
144  fGvtx = v;
145  }
146 
147  //----------------------------------------------------------------------------
148  void MCParticle::SetGvtx(double x, double y, double z, double t)
149  {
150  fGvtx.SetX(x);
151  fGvtx.SetY(y);
152  fGvtx.SetZ(z);
153  fGvtx.SetT(t);
154  }
155 
156  //------------------------------------------------------------
157  std::ostream& operator<< ( std::ostream& output, const MCParticle& particle )
158  {
159  output << "ID=" << particle.TrackId() << ", ";
160  int pdg = particle.PdgCode();
161 
162  // Try to translate the PDG code into text.
163  const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
164  const TParticlePDG* definition = databasePDG->GetParticle( pdg );
165  // Check that the particle is known to ROOT. If not, this is
166  // not a major error; Geant4 has an internal particle coding
167  // scheme for nuclei that ROOT doesn't recognize.
168  if ( definition != 0 ) output << definition->GetName();
169  else output << "PDG=" << pdg;
170 
171  output << ", mass=" << particle.Mass()
172  << ", Mother ID=" << particle.Mother()
173  << ", Process=" << particle.Process()
174  << ", Status=" << particle.StatusCode()
175  << "\nthere are " << particle.NumberTrajectoryPoints() << " trajectory points";
176 
177  if(particle.NumberTrajectoryPoints() > 0 )
178  output << "\nInitial vtx (x,y,z,t)=(" << particle.Vx()
179  << "," << particle.Vy()
180  << "," << particle.Vz()
181  << "," << particle.T()
182  << "),\n Initial mom (Px,Py,Pz,E)=(" << particle.Px()
183  << "," << particle.Py()
184  << "," << particle.Pz()
185  << "," << particle.E()
186  << ")" << std::endl;
187  else
188  output << std::endl;
189 
190  return output;
191  }
192 
193 } // namespace sim
Float_t x
Definition: compare.C:6
double E(const int i=0) const
Definition: MCParticle.h:234
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:219
int PdgCode() const
Definition: MCParticle.h:213
double Py(const int i=0) const
Definition: MCParticle.h:232
friend std::ostream & operator<<(std::ostream &output, const simb::MCParticle &)
Definition: MCParticle.cxx:157
double Weight() const
Definition: MCParticle.h:255
static const int s_uninitialized
Definition: MCParticle.h:28
TLorentzVector fGvtx
Definition: MCParticle.h:46
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:254
int Mother() const
Definition: MCParticle.h:214
int fmother
Mother.
Definition: MCParticle.h:38
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
double Mass() const
Definition: MCParticle.h:240
double fmass
Mass; from PDG unless overridden Should be in GeV.
Definition: MCParticle.h:42
double Px(const int i=0) const
Definition: MCParticle.h:231
std::string fendprocess
end process for the particle
Definition: MCParticle.h:40
STL namespace.
int StatusCode() const
Definition: MCParticle.h:212
intermediate_table::const_iterator const_iterator
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 ftrackId
TrackId.
Definition: MCParticle.h:36
int TrackId() const
Definition: MCParticle.h:211
int Daughter(const int i) const
Definition: MCParticle.cxx:118
int frescatter
rescatter code
Definition: MCParticle.h:48
std::string EndProcess() const
Definition: MCParticle.h:217
int fpdgCode
PDG code.
Definition: MCParticle.h:37
MCParticle()
Don&#39;t write this as ROOT output.
Definition: MCParticle.cxx:32
daughters_type fdaughters
Sorted list of daughters of this particle.
Definition: MCParticle.h:44
double T(const int i=0) const
Definition: MCParticle.h:225
std::string fprocess
Detector-simulation physics process that created the particle.
Definition: MCParticle.h:39
ART objects.
void SetEndProcess(std::string s)
Definition: MCParticle.cxx:111
simb::MCTrajectory ftrajectory
particle trajectory (position,momentum)
Definition: MCParticle.h:41
double Vx(const int i=0) const
Definition: MCParticle.h:222
void SetGvtx(double *v)
Definition: MCParticle.cxx:126
double fWeight
Assigned weight to this particle for MC tests.
Definition: MCParticle.h:45
double Pz(const int i=0) const
Definition: MCParticle.h:233
int Rescatter() const
Definition: MCParticle.h:253
double Vz(const int i=0) const
Definition: MCParticle.h:224
int fstatus
Status code from generator, geant, etc.
Definition: MCParticle.h:35
TVector3 fpolarization
Polarization.
Definition: MCParticle.h:43
double Vy(const int i=0) const
Definition: MCParticle.h:223