Geant4  10.01.p03
G4PrimaryParticle.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4PrimaryParticle.cc 81373 2014-05-27 13:06:32Z gcosmo $
28 //
29 
30 #include "G4PrimaryParticle.hh"
31 #include "G4SystemOfUnits.hh"
32 #include "G4ParticleDefinition.hh"
33 #include "G4ParticleTable.hh"
34 #include "G4ios.hh"
36 
38 
40 :PDGcode(0),G4code(0),
41  direction(0.,0.,1.),kinE(0.),
42  nextParticle(0),daughterParticle(0),trackID(-1),
43  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
44  Weight0(1.0),properTime(0.0),userInfo(0)
45 {;}
46 
48 :PDGcode(Pcode),
49  direction(0.,0.,1.),kinE(0.),
50  nextParticle(0),daughterParticle(0),trackID(-1),
51  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
52  Weight0(1.0),properTime(0.0),userInfo(0)
53 {
55  if (G4code !=0) {
56  mass = G4code->GetPDGMass();
58  }
59 }
60 
62  G4double px,G4double py,G4double pz)
63 :PDGcode(Pcode),
64  direction(0.,0.,1.),kinE(0.),
65  nextParticle(0),daughterParticle(0),trackID(-1),
66  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
67  Weight0(1.0),properTime(0.0),userInfo(0)
68 {
70  if (G4code !=0) {
71  mass = G4code->GetPDGMass();
73  }
74  SetMomentum( px, py, pz);
75 }
76 
79 :PDGcode(Pcode),
80  direction(0.,0.,1.),kinE(0.),
81  nextParticle(0),daughterParticle(0),trackID(-1),
82  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
83  Weight0(1.0),properTime(0.0),userInfo(0)
84 {
86  if (G4code !=0) {
87  mass = G4code->GetPDGMass();
89  }
90  Set4Momentum( px, py, pz, E);
91 }
92 
94 :PDGcode(0),G4code(Gcode),
95  direction(0.,0.,1.),kinE(0.),
96  nextParticle(0),daughterParticle(0),trackID(-1),
97  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
98  Weight0(1.0),properTime(0.0),userInfo(0)
99 {
100  if (G4code !=0) {
101  PDGcode = Gcode->GetPDGEncoding();
102  mass = G4code->GetPDGMass();
104  }
105 }
106 
108  G4double px,G4double py,G4double pz)
109 :PDGcode(0),G4code(Gcode),
110  direction(0.,0.,1.),kinE(0.),
111  nextParticle(0),daughterParticle(0),trackID(-1),
112  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
113  Weight0(1.0),properTime(0.0),userInfo(0)
114 {
115  if (G4code !=0) {
116  PDGcode = Gcode->GetPDGEncoding();
117  mass = G4code->GetPDGMass();
119  }
120  SetMomentum( px, py, pz);
121 }
122 
124  G4double px,G4double py,G4double pz,G4double E)
125 :PDGcode(0),G4code(Gcode),
126  direction(0.,0.,1.),kinE(0.),
127  nextParticle(0),daughterParticle(0),trackID(-1),
128  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
129  Weight0(1.0),properTime(0.0),userInfo(0)
130 {
131  if (G4code !=0) {
132  PDGcode = Gcode->GetPDGEncoding();
133  mass = G4code->GetPDGMass();
135  }
136  Set4Momentum( px, py, pz, E);
137 }
138 
140 :PDGcode(0),G4code(0),
141  direction(0.,0.,1.),kinE(0.),
142  nextParticle(0),daughterParticle(0),trackID(-1),
143  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
144  Weight0(1.0),properTime(0.0),userInfo(0)
145 {
146  *this = right;
147 }
148 
150 {
151  if (this != &right) {
152  PDGcode = right.PDGcode;
153  G4code = right.G4code;
154  direction = right.direction;
155  kinE = right.kinE;
156  if (nextParticle !=0) delete nextParticle;
157  if ( right.nextParticle ==0 ){
158  nextParticle = 0;
159  } else {
161  }
162  if (daughterParticle !=0) delete daughterParticle;
163  if ( right.daughterParticle ==0 ){
164  daughterParticle = 0;
165  } else {
167  }
168  trackID = right.trackID;
169  mass = right.mass;
170  charge = right.charge;
171  polX = right.polX;
172  polY = right.polY;
173  polZ = right.polZ;
174  Weight0 = right.Weight0;
175  properTime = right.properTime;
176 
177  // userInfo can not be copied
178  userInfo = 0;
179  }
180 
181  return *this;
182 }
183 
185 { return (this==&right); }
186 
188 { return (this!=&right); }
189 
191 {
192  if(nextParticle != 0){
193  delete nextParticle;
194  nextParticle = 0;
195  }
196  if(daughterParticle != 0){
197  delete daughterParticle;
198  daughterParticle =0;
199  }
200  if(userInfo!=0) {
201  delete userInfo;
202  userInfo=0;
203  }
204 }
205 
207 {
208  if ((mass<0.)&&(G4code!=0)){
209  mass = G4code->GetPDGMass();
210  }
211  G4double pmom = std::sqrt(px*px+py*py+pz*pz);
212  if (pmom>0.0) {
213  direction.setX(px/pmom);
214  direction.setY(py/pmom);
215  direction.setZ(pz/pmom);
216  }
217  kinE = std::sqrt(px*px+py*py+pz*pz+mass*mass)-mass;
218 }
219 
221 {
222  G4double pmom = std::sqrt(px*px+py*py+pz*pz);
223  if (pmom>0.0) {
224  direction.setX(px/pmom);
225  direction.setY(py/pmom);
226  direction.setZ(pz/pmom);
227  }
228  G4double mas2 = E*E - pmom*pmom;
229  if(mas2>=0.){
230  mass = std::sqrt(mas2);
231  } else {
232  if (G4code!=0){
233  mass = G4code->GetPDGMass();
234  }
235  E = std::sqrt(pmom*pmom+mass*mass);
236  }
237  kinE = E - mass;
238 }
239 
241 {
242  PDGcode = Pcode;
244  if (G4code!=0){
245  mass = G4code->GetPDGMass();
247  }
248 }
249 
251 {
252  G4code = Gcode;
253  if (G4code!=0){
254  PDGcode = Gcode->GetPDGEncoding();
255  mass = G4code->GetPDGMass();
257  }
258 }
259 
261 {
262  G4cout << "==== PDGcode " << PDGcode << " Particle name ";
263  if(G4code != 0)
264  { G4cout << G4code->GetParticleName() << G4endl; }
265  else
266  { G4cout << " is not defined in G4." << G4endl; }
267  G4cout << " Assigned charge : " << charge/eplus << G4endl;
268  G4cout << " Momentum ( "
269  << GetTotalMomentum()*direction.x()/GeV << "[GeV/c], "
270  << GetTotalMomentum()*direction.y()/GeV << "[GeV/c], "
271  << GetTotalMomentum()*direction.z()/GeV << "[GeV/c] )" << G4endl;
272  G4cout << " kinetic Energy : " << kinE/GeV << " [GeV]" << G4endl;
273  if(mass>=0.){
274  G4cout << " Mass : " << mass/GeV << " [GeV]" << G4endl;
275  } else {
276  G4cout << " Mass is not assigned " << G4endl;
277  }
278  G4cout << " Polarization ( "
279  << polX << ", "
280  << polY << ", "
281  << polZ << " )"
282  << G4endl;
283  G4cout << " Weight : " << Weight0 << G4endl;
284  if(properTime>0.0) {
285  G4cout << " PreAssigned proper decay time : " << properTime/ns << " [ns] " << G4endl;
286  }
287  if(userInfo != 0) { userInfo->Print(); }
288  if(daughterParticle != 0) {
289  G4cout << ">>>> Daughters" << G4endl;
291  }
292  if(nextParticle != 0) {
293  nextParticle->Print();
294  } else {
295  G4cout << "<<<< End of link" << G4endl;
296  }
297 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4PrimaryParticle * daughterParticle
G4ThreadLocal G4Allocator< G4PrimaryParticle > * aPrimaryParticleAllocator
const G4ParticleDefinition * G4code
G4double GetTotalMomentum() const
G4PrimaryParticle * nextParticle
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
void SetPDGcode(G4int Pcode)
G4GLOB_DLL std::ostream G4cout
virtual void Print() const =0
static const double GeV
Definition: G4SIunits.hh:196
G4double GetPDGMass() const
static G4ParticleTable * GetParticleTable()
G4ThreeVector direction
void SetParticleDefinition(const G4ParticleDefinition *pdef)
G4int operator==(const G4PrimaryParticle &right) const
G4VUserPrimaryParticleInformation * userInfo
#define G4endl
Definition: G4ios.hh:61
void Set4Momentum(G4double px, G4double py, G4double pz, G4double E)
G4PrimaryParticle & operator=(const G4PrimaryParticle &right)
double G4double
Definition: G4Types.hh:76
static const double eplus
Definition: G4SIunits.hh:178
G4double GetPDGCharge() const
void SetMomentum(G4double px, G4double py, G4double pz)
#define ns
Definition: xmlparse.cc:597
G4int operator!=(const G4PrimaryParticle &right) const