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 
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  //----------------------------------------------------------------------------
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
double E(const int i=0) const
Definition: MCParticle.h:233
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:218
int PdgCode() const
Definition: MCParticle.h:212
double Py(const int i=0) const
Definition: MCParticle.h:231
friend std::ostream & operator<<(std::ostream &output, const simb::MCParticle &)
Definition: MCParticle.cxx:151
double Weight() const
Definition: MCParticle.h:254
static const int s_uninitialized
Definition: MCParticle.h:28
TLorentzVector fGvtx
Definition: MCParticle.h:46
std::string string
Definition: nybbler.cc:12
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:253
int Mother() const
Definition: MCParticle.h:213
int fmother
Mother.
Definition: MCParticle.h:38
double Mass() const
Definition: MCParticle.h:239
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:230
std::string fendprocess
end process for the particle
Definition: MCParticle.h:40
STL namespace.
int StatusCode() const
Definition: MCParticle.h:211
intermediate_table::const_iterator const_iterator
std::string Process() const
Definition: MCParticle.h:215
TLorentzVector GetGvtx() const
Definition: MCParticle.h:245
Particle class.
int NumberDaughters() const
Definition: MCParticle.h:217
int ftrackId
TrackId.
Definition: MCParticle.h:36
int TrackId() const
Definition: MCParticle.h:210
int Daughter(const int i) const
Definition: MCParticle.cxx:112
def process(f, kind)
Definition: search.py:254
int frescatter
rescatter code
Definition: MCParticle.h:48
std::string EndProcess() const
Definition: MCParticle.h:216
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:224
p
Definition: test.py:223
std::string fprocess
Detector-simulation physics process that created the particle.
Definition: MCParticle.h:39
Base utilities and modules for event generation and detector simulation.
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:221
void SetGvtx(double *v)
Definition: MCParticle.cxx:120
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
double fWeight
Assigned weight to this particle for MC tests.
Definition: MCParticle.h:45
double Pz(const int i=0) const
Definition: MCParticle.h:232
int Rescatter() const
Definition: MCParticle.h:252
double Vz(const int i=0) const
Definition: MCParticle.h:223
int fstatus
Status code from generator, geant, etc.
Definition: MCParticle.h:35
list x
Definition: train.py:276
TVector3 fpolarization
Polarization.
Definition: MCParticle.h:43
static QCString * s
Definition: config.cpp:1042
double Vy(const int i=0) const
Definition: MCParticle.h:222
QTextStream & endl(QTextStream &s)