LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 
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  , 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  //----------------------------------------------------------------------------
105  void MCParticle::SetEndProcess(std::string s)
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  {
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
Float_t x
Definition: compare.C:6
double E(const int i=0) const
Definition: MCParticle.h:237
Float_t s
Definition: plot.C:23
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:222
int PdgCode() const
Definition: MCParticle.h:216
double Py(const int i=0) const
Definition: MCParticle.h:235
friend std::ostream & operator<<(std::ostream &output, const simb::MCParticle &)
Definition: MCParticle.cxx:151
double Weight() const
Definition: MCParticle.h:258
static const int s_uninitialized
Definition: MCParticle.h:28
TLorentzVector fGvtx
Definition: MCParticle.h:46
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:257
int Mother() const
Definition: MCParticle.h:217
int fmother
Mother.
Definition: MCParticle.h:38
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
double Mass() const
Definition: MCParticle.h:243
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:234
std::string fendprocess
end process for the particle
Definition: MCParticle.h:40
STL namespace.
int StatusCode() const
Definition: MCParticle.h:215
std::string Process() const
Definition: MCParticle.h:219
TLorentzVector GetGvtx() const
Definition: MCParticle.h:249
Particle class.
int NumberDaughters() const
Definition: MCParticle.h:221
int ftrackId
TrackId.
Definition: MCParticle.h:36
int TrackId() const
Definition: MCParticle.h:214
int Daughter(const int i) const
Definition: MCParticle.cxx:112
intermediate_table::const_iterator const_iterator
int frescatter
rescatter code
Definition: MCParticle.h:48
std::string EndProcess() const
Definition: MCParticle.h:220
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:228
std::string fprocess
Detector-simulation physics process that created the particle.
Definition: MCParticle.h:39
Framework includes.
void SetEndProcess(std::string s)
Definition: MCParticle.cxx:105
simb::MCTrajectory ftrajectory
particle trajectory (position,momentum)
Definition: MCParticle.h:41
double Vx(const int i=0) const
Definition: MCParticle.h:225
void SetGvtx(double *v)
Definition: MCParticle.cxx:120
Int_t min
Definition: plot.C:26
double fWeight
Assigned weight to this particle for MC tests.
Definition: MCParticle.h:45
double Pz(const int i=0) const
Definition: MCParticle.h:236
int Rescatter() const
Definition: MCParticle.h:256
double Vz(const int i=0) const
Definition: MCParticle.h:227
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:226