Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4PrimaryParticle class implementation
27//
28// Authors: G.Cosmo, 2 December 1995 - Design, based on object model
29// M.Asai, 29 January 1996 - First implementation
30// --------------------------------------------------------------------
31
32#include "G4PrimaryParticle.hh"
33#include "G4SystemOfUnits.hh"
35#include "G4ParticleTable.hh"
36#include "G4ios.hh"
38
40{
42 return _instance;
43}
44
45// --------------------------------------------------------------------
47 : direction(0.,0.,1.)
48{
49}
50
51// --------------------------------------------------------------------
53 : direction(0.,0.,1.), PDGcode(Pcode)
54{
56 if (G4code != nullptr)
57 {
58 mass = G4code->GetPDGMass();
59 charge = G4code->GetPDGCharge();
60 }
61}
62
63// --------------------------------------------------------------------
66 : direction(0.,0.,1.), PDGcode(Pcode)
67{
69 if (G4code != nullptr)
70 {
71 mass = G4code->GetPDGMass();
72 charge = G4code->GetPDGCharge();
73 }
74 SetMomentum( px, py, pz);
75}
76
77// --------------------------------------------------------------------
80 G4double px, G4double py, G4double pz, G4double E)
81 : direction(0.,0.,1.), PDGcode(Pcode)
82{
84 if (G4code != nullptr)
85 {
86 mass = G4code->GetPDGMass();
87 charge = G4code->GetPDGCharge();
88 }
89 Set4Momentum( px, py, pz, E);
90}
91
92// --------------------------------------------------------------------
94 : G4code(Gcode), direction(0.,0.,1.)
95{
96 if (G4code != nullptr)
97 {
98 PDGcode = Gcode->GetPDGEncoding();
99 mass = G4code->GetPDGMass();
100 charge = G4code->GetPDGCharge();
101 }
102}
103
104// --------------------------------------------------------------------
106 G4double px, G4double py, G4double pz)
107 : G4code(Gcode), direction(0.,0.,1.)
108{
109 if (G4code != nullptr)
110 {
111 PDGcode = Gcode->GetPDGEncoding();
112 mass = G4code->GetPDGMass();
113 charge = G4code->GetPDGCharge();
114 }
115 SetMomentum( px, py, pz);
116}
117
118// --------------------------------------------------------------------
120 G4double px, G4double py, G4double pz, G4double E)
121 : G4code(Gcode), direction(0.,0.,1.)
122{
123 if (G4code != nullptr)
124 {
125 PDGcode = Gcode->GetPDGEncoding();
126 mass = G4code->GetPDGMass();
127 charge = G4code->GetPDGCharge();
128 }
129 Set4Momentum( px, py, pz, E);
130}
131
132// --------------------------------------------------------------------
134{
135 *this = right;
136}
137
138// --------------------------------------------------------------------
141{
142 if (this != &right)
143 {
144 PDGcode = right.PDGcode;
145 G4code = right.G4code;
146 direction = right.direction;
147 kinE = right.kinE;
148 if (nextParticle != nullptr) delete nextParticle;
149 if ( right.nextParticle == nullptr )
150 {
151 nextParticle = nullptr;
152 }
153 else
154 {
155 nextParticle = new G4PrimaryParticle(*right.nextParticle);
156 }
157 if (daughterParticle != nullptr) delete daughterParticle;
158 if ( right.daughterParticle == nullptr )
159 {
160 daughterParticle = nullptr;
161 }
162 else
163 {
164 daughterParticle = new G4PrimaryParticle(*right.daughterParticle);
165 }
166 trackID = right.trackID;
167 mass = right.mass;
168 charge = right.charge;
169 polX = right.polX;
170 polY = right.polY;
171 polZ = right.polZ;
172 Weight0 = right.Weight0;
173 properTime = right.properTime;
174
175 // userInfo cannot be copied
176 userInfo = nullptr;
177 }
178
179 return *this;
180}
181
182// --------------------------------------------------------------------
184{
185 return (this==&right);
186}
187
188// --------------------------------------------------------------------
190{
191 return (this!=&right);
192}
193
194// --------------------------------------------------------------------
196{
197 delete nextParticle;
198 nextParticle = nullptr;
199
200 delete daughterParticle;
201 daughterParticle = nullptr;
202
203 delete userInfo;
204 userInfo = nullptr;
205}
206
207// --------------------------------------------------------------------
209{
210 if ((mass<0.)&&(G4code!=0))
211 {
212 mass = G4code->GetPDGMass();
213 }
214 G4double pmom = std::sqrt(px*px+py*py+pz*pz);
215 if (pmom>0.0)
216 {
217 direction.setX(px/pmom);
218 direction.setY(py/pmom);
219 direction.setZ(pz/pmom);
220 }
221 kinE = std::sqrt(px*px+py*py+pz*pz+mass*mass)-mass;
222}
223
224// --------------------------------------------------------------------
227{
228 G4double pmom = std::sqrt(px*px+py*py+pz*pz);
229 if (pmom>0.0)
230 {
231 direction.setX(px/pmom);
232 direction.setY(py/pmom);
233 direction.setZ(pz/pmom);
234 }
235 G4double mas2 = E*E - pmom*pmom;
236 if(mas2>=0.)
237 {
238 mass = std::sqrt(mas2);
239 }
240 else
241 {
242 if (G4code != nullptr)
243 {
244 mass = G4code->GetPDGMass();
245 }
246 E = std::sqrt(pmom*pmom+mass*mass);
247 }
248 kinE = E - mass;
249}
250
251// --------------------------------------------------------------------
253{
254 PDGcode = Pcode;
256 if (G4code != nullptr)
257 {
258 mass = G4code->GetPDGMass();
259 charge = G4code->GetPDGCharge();
260 }
261}
262
263// --------------------------------------------------------------------
264void
266{
267 G4code = Gcode;
268 if (G4code != nullptr)
269 {
270 PDGcode = Gcode->GetPDGEncoding();
271 mass = G4code->GetPDGMass();
272 charge = G4code->GetPDGCharge();
273 }
274}
275
276// --------------------------------------------------------------------
278{
279 G4cout << "==== PDGcode " << PDGcode << " Particle name ";
280 if(G4code != nullptr)
281 {
282 G4cout << G4code->GetParticleName() << G4endl;
283 }
284 else
285 {
286 G4cout << " is not defined in G4." << G4endl;
287 }
288 G4cout << " Assigned charge : " << charge/eplus << G4endl;
289 G4cout << " Momentum ( "
290 << GetTotalMomentum()*direction.x()/GeV << "[GeV/c], "
291 << GetTotalMomentum()*direction.y()/GeV << "[GeV/c], "
292 << GetTotalMomentum()*direction.z()/GeV << "[GeV/c] )" << G4endl;
293 G4cout << " kinetic Energy : " << kinE/GeV << " [GeV]" << G4endl;
294 if(mass>=0.)
295 {
296 G4cout << " Mass : " << mass/GeV << " [GeV]" << G4endl;
297 }
298 else
299 {
300 G4cout << " Mass is not assigned " << G4endl;
301 }
302 G4cout << " Polarization ( "
303 << polX << ", "
304 << polY << ", "
305 << polZ << " )"
306 << G4endl;
307 G4cout << " Weight : " << Weight0 << G4endl;
308 if(properTime>=0.0)
309 {
310 G4cout << " PreAssigned proper decay time : "
311 << properTime/ns << " [ns] " << G4endl;
312 }
313 if(userInfo != 0) { userInfo->Print(); }
314 if(daughterParticle != nullptr)
315 {
316 G4cout << ">>>> Daughters" << G4endl;
317 daughterParticle->Print();
318 }
319 if(nextParticle != nullptr)
320 {
321 nextParticle->Print();
322 }
323 else
324 {
325 G4cout << "<<<< End of link" << G4endl;
326 }
327}
G4Allocator< G4PrimaryParticle > *& aPrimaryParticleAllocator()
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
void setY(double)
double y() const
void setZ(double)
void setX(double)
G4double GetPDGCharge() const
const G4String & GetParticleName() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
void SetPDGcode(G4int Pcode)
G4bool operator==(const G4PrimaryParticle &right) const
G4PrimaryParticle & operator=(const G4PrimaryParticle &right)
G4bool operator!=(const G4PrimaryParticle &right) const
void Set4Momentum(G4double px, G4double py, G4double pz, G4double E)
void SetMomentum(G4double px, G4double py, G4double pz)
G4double GetTotalMomentum() const
void SetParticleDefinition(const G4ParticleDefinition *pdef)
virtual void Print() const =0
#define G4ThreadLocalStatic
Definition: tls.hh:76
#define ns(x)
Definition: xmltok.c:1649