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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 
 34 #include "G4ParticleDefinition.hh"
 35 #include "G4ParticleTable.hh"
 36 #include "G4SystemOfUnits.hh"
 37 #include "G4VUserPrimaryParticleInformation.hh"
 38 #include "G4ios.hh"
 39 
 40 G4Allocator<G4PrimaryParticle>*& aPrimaryParticleAllocator()
 41 {
 42   G4ThreadLocalStatic G4Allocator<G4PrimaryParticle>* _instance = nullptr;
 43   return _instance;
 44 }
 45 
 46 G4PrimaryParticle::G4PrimaryParticle() : direction(0., 0., 1.) {}
 47 
 48 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode) : direction(0., 0., 1.), PDGcode(Pcode)
 49 {
 50   G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
 51   if (G4code != nullptr) {
 52     mass = G4code->GetPDGMass();
 53     charge = G4code->GetPDGCharge();
 54   }
 55 }
 56 
 57 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode, G4double px, G4double py, G4double pz)
 58   : direction(0., 0., 1.), PDGcode(Pcode)
 59 {
 60   G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
 61   if (G4code != nullptr) {
 62     mass = G4code->GetPDGMass();
 63     charge = G4code->GetPDGCharge();
 64   }
 65   SetMomentum(px, py, pz);
 66 }
 67 
 68 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode, G4double px, G4double py, G4double pz, G4double E)
 69   : direction(0., 0., 1.), PDGcode(Pcode)
 70 {
 71   G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
 72   if (G4code != nullptr) {
 73     mass = G4code->GetPDGMass();
 74     charge = G4code->GetPDGCharge();
 75   }
 76   Set4Momentum(px, py, pz, E);
 77 }
 78 
 79 G4PrimaryParticle::G4PrimaryParticle(const G4ParticleDefinition* Gcode)
 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 
 89 G4PrimaryParticle::G4PrimaryParticle(const G4ParticleDefinition* Gcode, G4double px, G4double py,
 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 
101 G4PrimaryParticle::G4PrimaryParticle(const G4ParticleDefinition* Gcode, G4double px, G4double py,
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 
113 G4PrimaryParticle::G4PrimaryParticle(const G4PrimaryParticle& right)
114 {
115   *this = right;
116 }
117 
118 G4PrimaryParticle& G4PrimaryParticle::operator=(const G4PrimaryParticle& right)
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 
155 G4bool G4PrimaryParticle::operator==(const G4PrimaryParticle& right) const
156 {
157   return (this == &right);
158 }
159 
160 G4bool G4PrimaryParticle::operator!=(const G4PrimaryParticle& right) const
161 {
162   return (this != &right);
163 }
164 
165 G4PrimaryParticle::~G4PrimaryParticle()
166 {
167   delete nextParticle;
168   nextParticle = nullptr;
169 
170   delete daughterParticle;
171   daughterParticle = nullptr;
172 
173   delete userInfo;
174   userInfo = nullptr;
175 }
176 
177 void G4PrimaryParticle::SetMomentum(G4double px, G4double py, G4double pz)
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 
191 void G4PrimaryParticle::Set4Momentum(G4double px, G4double py, G4double pz, G4double E)
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 
212 void G4PrimaryParticle::SetPDGcode(G4int Pcode)
213 {
214   PDGcode = Pcode;
215   G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
216   if (G4code != nullptr) {
217     mass = G4code->GetPDGMass();
218     charge = G4code->GetPDGCharge();
219   }
220 }
221 
222 void G4PrimaryParticle::SetParticleDefinition(const G4ParticleDefinition* Gcode)
223 {
224   G4code = Gcode;
225   if (G4code != nullptr) {
226     PDGcode = Gcode->GetPDGEncoding();
227     mass = G4code->GetPDGMass();
228     charge = G4code->GetPDGCharge();
229   }
230 }
231 
232 void G4PrimaryParticle::Print() const
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 }
271