MCParticle.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file MCParticle.cxx
3 /// \brief Description of a particle passed to Geant4
4 ///
5 /// \version $Id: MCParticle.cxx,v 1.12 2012-11-20 17:39:38 brebel Exp $
6 /// \author seligman@nevis.columbia.edu
7 ////////////////////////////////////////////////////////////////////////
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 
23  /// How do we indicate an uninitialized variable? I don't want to
24  /// use "0" for PDG, because that's potentially a valid value.
25  /// Instead, let the compiler give us a value. The following
26  /// template (from climits) evaluates the lower possible negative
27  /// number that you can store in an int.
28 
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  //------------------------------------------------------------
49  /// Standard constructor.
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 
87  : fstatus(p.StatusCode())
88  , ftrackId(p.TrackId()+offset)
89  , fpdgCode(p.PdgCode())
90  , fmother(p.Mother()+offset)
91  , fprocess(p.Process())
92  , fendprocess(p.EndProcess())
93  , ftrajectory(p.Trajectory())
94  , fmass(p.Mass())
95  , fWeight(p.Weight())
96  , fGvtx(p.GetGvtx())
97  , frescatter(p.Rescatter())
98  {
99  for(int i=0; i<p.NumberDaughters(); i++)
100  fdaughters.insert(p.Daughter(i)+offset);
101  }
102 
103 
104  //----------------------------------------------------------------------------
106  {
107  fendprocess = s;
108  }
109 
110  //------------------------------------------------------------
111  // Return the "index-th' daughter in the list.
112  int MCParticle::Daughter( const int index ) const
113  {
114  daughters_type::const_iterator i = fdaughters.begin();
115  std::advance( i, index );
116  return *i;
117  }
118 
119  //----------------------------------------------------------------------------
120  void MCParticle::SetGvtx(double *v)
121  {
122  for(int i = 0; i < 4; i++) {
123  fGvtx[i] = v[i];
124  }
125  }
126 
127  //----------------------------------------------------------------------------
128  void MCParticle::SetGvtx(float *v)
129  {
130  for(int i = 0; i < 4; i++) {
131  fGvtx[i] = v[i];
132  }
133  }
134 
135  //----------------------------------------------------------------------------
136  void MCParticle::SetGvtx(TLorentzVector v)
137  {
138  fGvtx = v;
139  }
140 
141  //----------------------------------------------------------------------------
142  void MCParticle::SetGvtx(double x, double y, double z, double t)
143  {
144  fGvtx.SetX(x);
145  fGvtx.SetY(y);
146  fGvtx.SetZ(z);
147  fGvtx.SetT(t);
148  }
149 
150  //------------------------------------------------------------
151  std::ostream& operator<< ( std::ostream& output, const MCParticle& particle )
152  {
153  output << "ID=" << particle.TrackId() << ", ";
154  int pdg = particle.PdgCode();
155 
156  // Try to translate the PDG code into text.
157  const TDatabasePDG* databasePDG = TDatabasePDG::Instance();
158  const TParticlePDG* definition = databasePDG->GetParticle( pdg );
159  // Check that the particle is known to ROOT. If not, this is
160  // not a major error; Geant4 has an internal particle coding
161  // scheme for nuclei that ROOT doesn't recognize.
162  if ( definition != 0 ) output << definition->GetName();
163  else output << "PDG=" << pdg;
164 
165  output << ", mass=" << particle.Mass()
166  << ", Mother ID=" << particle.Mother()
167  << ", Process=" << particle.Process()
168  << ", Status=" << particle.StatusCode()
169  << "\nthere are " << particle.NumberTrajectoryPoints() << " trajectory points";
170 
171  if(particle.NumberTrajectoryPoints() > 0 )
172  output << "\nInitial vtx (x,y,z,t)=(" << particle.Vx()
173  << "," << particle.Vy()
174  << "," << particle.Vz()
175  << "," << particle.T()
176  << "),\n Initial mom (Px,Py,Pz,E)=(" << particle.Px()
177  << "," << particle.Py()
178  << "," << particle.Pz()
179  << "," << particle.E()
180  << ")" << std::endl;
181  else
182  output << std::endl;
183 
184  return output;
185  }
186 
187 } // namespace sim
double E(const int i=0) const
Definition: MCParticle.h:232
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:217
ofstream output
int PdgCode() const
Definition: MCParticle.h:211
double Py(const int i=0) const
Definition: MCParticle.h:230
int status
Definition: fabricate.py:1613
friend std::ostream & operator<<(std::ostream &output, const simb::MCParticle &)
Definition: MCParticle.cxx:151
static const int s_uninitialized
Definition: MCParticle.h:28
TLorentzVector fGvtx
Definition: MCParticle.h:46
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:252
int Mother() const
Definition: MCParticle.h:212
int fmother
Mother.
Definition: MCParticle.h:38
const char * p
Definition: xmltok.h:285
double Mass() const
Definition: MCParticle.h:238
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:229
std::string fendprocess
end process for the particle
Definition: MCParticle.h:40
int StatusCode() const
Definition: MCParticle.h:210
std::string Process() const
Definition: MCParticle.h:214
TLorentzVector GetGvtx() const
Definition: MCParticle.h:244
Particle class.
int NumberDaughters() const
Definition: MCParticle.h:216
int ftrackId
TrackId.
Definition: MCParticle.h:36
int TrackId() const
Definition: MCParticle.h:209
int Daughter(const int i) const
Definition: MCParticle.cxx:112
const XML_Char * s
Definition: expat.h:262
int frescatter
rescatter code
Definition: MCParticle.h:48
std::string EndProcess() const
Definition: MCParticle.h:215
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:223
std::string fprocess
Detector-simulation physics process that created the particle.
Definition: MCParticle.h:39
z
Definition: test.py:28
This class describes a particle created in the detector Monte Carlo simulation.
void SetEndProcess(std::string s)
Definition: MCParticle.cxx:105
simb::MCTrajectory ftrajectory
particle trajectory (position,momentum)
Definition: MCParticle.h:41
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
double Vx(const int i=0) const
Definition: MCParticle.h:220
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void SetGvtx(double *v)
Definition: MCParticle.cxx:120
double fWeight
Assigned weight to this particle for MC tests.
Definition: MCParticle.h:45
double Pz(const int i=0) const
Definition: MCParticle.h:231
int Rescatter() const
Definition: MCParticle.h:251
double Vz(const int i=0) const
Definition: MCParticle.h:222
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:221