Geant4 11.2.2
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
35#include "G4ParticleTable.hh"
36#include "G4SystemOfUnits.hh"
38#include "G4ios.hh"
39
45
46G4PrimaryParticle::G4PrimaryParticle() : direction(0., 0., 1.) {}
47
48G4PrimaryParticle::G4PrimaryParticle(G4int Pcode) : direction(0., 0., 1.), PDGcode(Pcode)
49{
51 if (G4code != nullptr) {
52 mass = G4code->GetPDGMass();
53 charge = G4code->GetPDGCharge();
54 }
55}
56
58 : direction(0., 0., 1.), PDGcode(Pcode)
59{
61 if (G4code != nullptr) {
62 mass = G4code->GetPDGMass();
63 charge = G4code->GetPDGCharge();
64 }
65 SetMomentum(px, py, pz);
66}
67
69 : direction(0., 0., 1.), PDGcode(Pcode)
70{
72 if (G4code != nullptr) {
73 mass = G4code->GetPDGMass();
74 charge = G4code->GetPDGCharge();
75 }
76 Set4Momentum(px, py, pz, E);
77}
78
80 : G4code(Gcode), direction(0., 0., 1.)
81{
82 if (G4code != nullptr) {
83 PDGcode = Gcode->GetPDGEncoding();
84 mass = G4code->GetPDGMass();
85 charge = G4code->GetPDGCharge();
86 }
87}
88
90 G4double pz)
91 : G4code(Gcode), direction(0., 0., 1.)
92{
93 if (G4code != nullptr) {
94 PDGcode = Gcode->GetPDGEncoding();
95 mass = G4code->GetPDGMass();
96 charge = G4code->GetPDGCharge();
97 }
98 SetMomentum(px, py, pz);
99}
100
102 G4double pz, G4double E)
103 : G4code(Gcode), direction(0., 0., 1.)
104{
105 if (G4code != nullptr) {
106 PDGcode = Gcode->GetPDGEncoding();
107 mass = G4code->GetPDGMass();
108 charge = G4code->GetPDGCharge();
109 }
110 Set4Momentum(px, py, pz, E);
111}
112
114{
115 *this = right;
116}
117
119{
120 if (this != &right) {
121 PDGcode = right.PDGcode;
122 G4code = right.G4code;
123 direction = right.direction;
124 kinE = right.kinE;
125 delete nextParticle;
126 if (right.nextParticle == nullptr) {
127 nextParticle = nullptr;
128 }
129 else {
130 nextParticle = new G4PrimaryParticle(*right.nextParticle);
131 }
132 delete daughterParticle;
133 if (right.daughterParticle == nullptr) {
134 daughterParticle = nullptr;
135 }
136 else {
137 daughterParticle = new G4PrimaryParticle(*right.daughterParticle);
138 }
139 trackID = right.trackID;
140 mass = right.mass;
141 charge = right.charge;
142 polX = right.polX;
143 polY = right.polY;
144 polZ = right.polZ;
145 Weight0 = right.Weight0;
146 properTime = right.properTime;
147
148 // userInfo cannot be copied
149 userInfo = nullptr;
150 }
151
152 return *this;
153}
154
156{
157 return (this == &right);
158}
159
161{
162 return (this != &right);
163}
164
166{
167 delete nextParticle;
168 nextParticle = nullptr;
169
170 delete daughterParticle;
171 daughterParticle = nullptr;
172
173 delete userInfo;
174 userInfo = nullptr;
175}
176
178{
179 if ((mass < 0.) && (G4code != nullptr)) {
180 mass = G4code->GetPDGMass();
181 }
182 G4double pmom = std::sqrt(px * px + py * py + pz * pz);
183 if (pmom > 0.0) {
184 direction.setX(px / pmom);
185 direction.setY(py / pmom);
186 direction.setZ(pz / pmom);
187 }
188 kinE = std::sqrt(px * px + py * py + pz * pz + mass * mass) - mass;
189}
190
192{
193 G4double pmom = std::sqrt(px * px + py * py + pz * pz);
194 if (pmom > 0.0) {
195 direction.setX(px / pmom);
196 direction.setY(py / pmom);
197 direction.setZ(pz / pmom);
198 }
199 G4double mas2 = E * E - pmom * pmom;
200 if (mas2 >= 0.) {
201 mass = std::sqrt(mas2);
202 }
203 else {
204 if (G4code != nullptr) {
205 mass = G4code->GetPDGMass();
206 }
207 E = std::sqrt(pmom * pmom + mass * mass);
208 }
209 kinE = E - mass;
210}
211
213{
214 PDGcode = Pcode;
216 if (G4code != nullptr) {
217 mass = G4code->GetPDGMass();
218 charge = G4code->GetPDGCharge();
219 }
220}
221
223{
224 G4code = Gcode;
225 if (G4code != nullptr) {
226 PDGcode = Gcode->GetPDGEncoding();
227 mass = G4code->GetPDGMass();
228 charge = G4code->GetPDGCharge();
229 }
230}
231
233{
234 G4cout << "==== PDGcode " << PDGcode << " Particle name ";
235 if (G4code != nullptr) {
236 G4cout << G4code->GetParticleName() << G4endl;
237 }
238 else {
239 G4cout << " is not defined in G4." << G4endl;
240 }
241 G4cout << " Assigned charge : " << charge / eplus << G4endl;
242 G4cout << " Momentum ( " << GetTotalMomentum() * direction.x() / GeV << "[GeV/c], "
243 << GetTotalMomentum() * direction.y() / GeV << "[GeV/c], "
244 << GetTotalMomentum() * direction.z() / GeV << "[GeV/c] )" << G4endl;
245 G4cout << " kinetic Energy : " << kinE / GeV << " [GeV]" << G4endl;
246 if (mass >= 0.) {
247 G4cout << " Mass : " << mass / GeV << " [GeV]" << G4endl;
248 }
249 else {
250 G4cout << " Mass is not assigned " << G4endl;
251 }
252 G4cout << " Polarization ( " << polX << ", " << polY << ", " << polZ << " )" << G4endl;
253 G4cout << " Weight : " << Weight0 << G4endl;
254 if (properTime >= 0.0) {
255 G4cout << " PreAssigned proper decay time : " << properTime / ns << " [ns] " << G4endl;
256 }
257 if (userInfo != nullptr) {
258 userInfo->Print();
259 }
260 if (daughterParticle != nullptr) {
261 G4cout << ">>>> Daughters" << G4endl;
262 daughterParticle->Print();
263 }
264 if (nextParticle != nullptr) {
265 nextParticle->Print();
266 }
267 else {
268 G4cout << "<<<< End of link" << G4endl;
269 }
270}
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:67
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
void setY(double)
double y() const
void setZ(double)
void setX(double)
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