Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4PrimaryParticle class implementation << 27 // 26 // 28 // Authors: G.Cosmo, 2 December 1995 - Design, << 27 // $Id: G4PrimaryParticle.cc,v 1.5 2007/10/06 06:49:29 kurasige Exp $ 29 // M.Asai, 29 January 1996 - First im << 28 // GEANT4 tag $Name: geant4-09-02 $ 30 // ------------------------------------------- << 29 // 31 30 32 #include "G4PrimaryParticle.hh" 31 #include "G4PrimaryParticle.hh" 33 << 34 #include "G4ParticleDefinition.hh" 32 #include "G4ParticleDefinition.hh" 35 #include "G4ParticleTable.hh" 33 #include "G4ParticleTable.hh" 36 #include "G4SystemOfUnits.hh" << 37 #include "G4VUserPrimaryParticleInformation.hh << 38 #include "G4ios.hh" 34 #include "G4ios.hh" >> 35 #include "G4VUserPrimaryParticleInformation.hh" 39 36 40 G4Allocator<G4PrimaryParticle>*& aPrimaryParti << 37 G4Allocator<G4PrimaryParticle> aPrimaryParticleAllocator; 41 { << 42 G4ThreadLocalStatic G4Allocator<G4PrimaryPar << 43 return _instance; << 44 } << 45 << 46 G4PrimaryParticle::G4PrimaryParticle() : direc << 47 38 48 G4PrimaryParticle::G4PrimaryParticle(G4int Pco << 39 G4PrimaryParticle::G4PrimaryParticle() 49 { << 40 :PDGcode(0),G4code(0),Px(0.),Py(0.),Pz(0.), 50 G4code = G4ParticleTable::GetParticleTable() << 41 nextParticle(0),daughterParticle(0),trackID(-1), 51 if (G4code != nullptr) { << 42 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.), 52 mass = G4code->GetPDGMass(); << 43 Weight0(1.0),properTime(0.0),userInfo(0) 53 charge = G4code->GetPDGCharge(); << 44 {;} 54 } << 45 >> 46 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode) >> 47 :PDGcode(Pcode),Px(0.),Py(0.),Pz(0.), >> 48 nextParticle(0),daughterParticle(0),trackID(-1), >> 49 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.), >> 50 Weight0(1.0),properTime(0.0),userInfo(0) >> 51 { G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode); } >> 52 >> 53 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode, >> 54 G4double px,G4double py,G4double pz) >> 55 :PDGcode(Pcode),Px(px),Py(py),Pz(pz), >> 56 nextParticle(0),daughterParticle(0),trackID(-1), >> 57 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.), >> 58 Weight0(1.0),properTime(0.0),userInfo(0) >> 59 { G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode); } >> 60 >> 61 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode, >> 62 G4double px,G4double py,G4double pz,G4double E) >> 63 :PDGcode(Pcode),Px(px),Py(py),Pz(pz), >> 64 nextParticle(0),daughterParticle(0),trackID(-1), >> 65 charge(DBL_MAX),polX(0.),polY(0.),polZ(0.), >> 66 Weight0(1.0),properTime(0.0),userInfo(0) >> 67 { >> 68 G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode); >> 69 G4double mas2 = E*E - px*px - py*py - pz*pz; >> 70 if(mas2>=0.) >> 71 { mass = std::sqrt(mas2); } >> 72 else >> 73 { mass = -1.0; } >> 74 } >> 75 >> 76 G4PrimaryParticle::G4PrimaryParticle(G4ParticleDefinition* Gcode) >> 77 :G4code(Gcode),Px(0.),Py(0.),Pz(0.), >> 78 nextParticle(0),daughterParticle(0),trackID(-1), >> 79 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.), >> 80 Weight0(1.0),properTime(0.0),userInfo(0) >> 81 { PDGcode = Gcode->GetPDGEncoding(); } >> 82 >> 83 G4PrimaryParticle::G4PrimaryParticle(G4ParticleDefinition* Gcode, >> 84 G4double px,G4double py,G4double pz) >> 85 :G4code(Gcode),Px(px),Py(py),Pz(pz), >> 86 nextParticle(0),daughterParticle(0),trackID(-1), >> 87 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.), >> 88 Weight0(1.0),properTime(0.0),userInfo(0) >> 89 { PDGcode = Gcode->GetPDGEncoding(); } >> 90 >> 91 G4PrimaryParticle::G4PrimaryParticle(G4ParticleDefinition* Gcode, >> 92 G4double px,G4double py,G4double pz,G4double E) >> 93 :G4code(Gcode),Px(px),Py(py),Pz(pz), >> 94 nextParticle(0),daughterParticle(0),trackID(-1), >> 95 charge(DBL_MAX),polX(0.),polY(0.),polZ(0.), >> 96 Weight0(1.0),properTime(0.0),userInfo(0) >> 97 { >> 98 PDGcode = Gcode->GetPDGEncoding(); >> 99 G4double mas2 = E*E - px*px - py*py - pz*pz; >> 100 if(mas2>=0.) >> 101 { mass = std::sqrt(mas2); } >> 102 else >> 103 { mass = -1.0; } 55 } 104 } 56 105 57 G4PrimaryParticle::G4PrimaryParticle(G4int Pco << 106 G4PrimaryParticle::~G4PrimaryParticle() 58 : direction(0., 0., 1.), PDGcode(Pcode) << 59 { 107 { 60 G4code = G4ParticleTable::GetParticleTable() << 108 if(nextParticle != 0) 61 if (G4code != nullptr) { << 109 { delete nextParticle; } 62 mass = G4code->GetPDGMass(); << 110 if(daughterParticle != 0) 63 charge = G4code->GetPDGCharge(); << 111 { delete daughterParticle; } 64 } << 112 if(userInfo!=0) 65 SetMomentum(px, py, pz); << 113 { delete userInfo; } 66 } 114 } 67 115 68 G4PrimaryParticle::G4PrimaryParticle(G4int Pco << 116 void G4PrimaryParticle::SetPDGcode(G4int Pcode) 69 : direction(0., 0., 1.), PDGcode(Pcode) << 70 { 117 { >> 118 PDGcode = Pcode; 71 G4code = G4ParticleTable::GetParticleTable() 119 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 G4P << 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 G4P << 90 G4double << 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 G4P << 102 G4double << 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 } 120 } 112 121 113 G4PrimaryParticle::G4PrimaryParticle(const G4P << 122 void G4PrimaryParticle::SetG4code(G4ParticleDefinition* Gcode) 114 { 123 { 115 *this = right; << 124 G4code = Gcode; >> 125 PDGcode = Gcode->GetPDGEncoding(); 116 } 126 } 117 127 118 G4PrimaryParticle& G4PrimaryParticle::operator << 128 G4double G4PrimaryParticle::GetMass() const 119 { 129 { 120 if (this != &right) { << 130 if (mass <0.0 ) { 121 PDGcode = right.PDGcode; << 131 if (G4code != 0) { 122 G4code = right.G4code; << 132 // return PDG mass if dynamical mass has not be specified 123 direction = right.direction; << 133 return G4code->GetPDGMass(); 124 kinE = right.kinE; << 125 delete nextParticle; << 126 if (right.nextParticle == nullptr) { << 127 nextParticle = nullptr; << 128 } << 129 else { << 130 nextParticle = new G4PrimaryParticle(*ri << 131 } 134 } 132 delete daughterParticle; << 133 if (right.daughterParticle == nullptr) { << 134 daughterParticle = nullptr; << 135 } << 136 else { << 137 daughterParticle = new G4PrimaryParticle << 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 } 135 } 151 << 136 return mass; 152 return *this; << 153 } 137 } 154 138 155 G4bool G4PrimaryParticle::operator==(const G4P << 139 G4double G4PrimaryParticle::GetCharge() const 156 { 140 { 157 return (this == &right); << 141 if ( charge <DBL_MAX ) { 158 } << 142 return charge; 159 << 143 } else { 160 G4bool G4PrimaryParticle::operator!=(const G4P << 144 if (G4code != 0) { 161 { << 145 // return PDG charge if dynamical mass has not be specified 162 return (this != &right); << 146 return G4code->GetPDGCharge(); 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 p << 178 { << 179 if ((mass < 0.) && (G4code != nullptr)) { << 180 mass = G4code->GetPDGMass(); << 181 } << 182 G4double pmom = std::sqrt(px * px + py * py << 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 << 189 } << 190 << 191 void G4PrimaryParticle::Set4Momentum(G4double << 192 { << 193 G4double pmom = std::sqrt(px * px + py * py << 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 } 147 } 207 E = std::sqrt(pmom * pmom + mass * mass); << 208 } 148 } 209 kinE = E - mass; << 149 return charge; 210 } 150 } 211 151 212 void G4PrimaryParticle::SetPDGcode(G4int Pcode << 152 const G4PrimaryParticle & 213 { << 153 G4PrimaryParticle::operator=(const G4PrimaryParticle &) 214 PDGcode = Pcode; << 154 { return *this; } 215 G4code = G4ParticleTable::GetParticleTable() << 155 G4int G4PrimaryParticle::operator==(const G4PrimaryParticle &right) const 216 if (G4code != nullptr) { << 156 { return (this==&right); } 217 mass = G4code->GetPDGMass(); << 157 G4int G4PrimaryParticle::operator!=(const G4PrimaryParticle &right) const 218 charge = G4code->GetPDGCharge(); << 158 { return (this!=&right); } 219 } << 220 } << 221 << 222 void G4PrimaryParticle::SetParticleDefinition( << 223 { << 224 G4code = Gcode; << 225 if (G4code != nullptr) { << 226 PDGcode = Gcode->GetPDGEncoding(); << 227 mass = G4code->GetPDGMass(); << 228 charge = G4code->GetPDGCharge(); << 229 } << 230 } << 231 159 232 void G4PrimaryParticle::Print() const 160 void G4PrimaryParticle::Print() const 233 { 161 { 234 G4cout << "==== PDGcode " << PDGcode << " P 162 G4cout << "==== PDGcode " << PDGcode << " Particle name "; 235 if (G4code != nullptr) { << 163 if(G4code != 0) 236 G4cout << G4code->GetParticleName() << G4e << 164 { G4cout << G4code->GetParticleName() << G4endl; } 237 } << 165 else 238 else { << 166 { G4cout << " is not defined in G4." << G4endl; } 239 G4cout << " is not defined in G4." << G4en << 167 if(charge<DBL_MAX) 240 } << 168 { G4cout << " Assigned charge : " << charge/eplus << G4endl; } 241 G4cout << " Assigned charge : " << charge / << 169 else 242 G4cout << " Momentum ( " << GetTotalMome << 170 { G4cout << " Charge will be taken from PDG charge." << G4endl; } 243 << GetTotalMomentum() * direction.y() << 171 G4cout << " Momentum ( " 244 << GetTotalMomentum() * direction.z() << 172 << Px/GeV << "[GeV/c], " 245 G4cout << " kinetic Energy : " << kinE / << 173 << Py/GeV << "[GeV/c], " 246 if (mass >= 0.) { << 174 << Pz/GeV << "[GeV/c] )" << G4endl; 247 G4cout << " Mass : " << mass / GeV << << 175 if(mass>=0.) 248 } << 176 { G4cout << " Mass : " << mass/GeV << " [GeV]" << G4endl; } 249 else { << 177 else 250 G4cout << " Mass is not assigned " << << 178 { G4cout << " Nominal mass will be taken from particle definition." << G4endl; } 251 } << 179 G4cout << " Polarization ( " 252 G4cout << " Polarization ( " << polX << << 180 << polX << ", " >> 181 << polY << ", " >> 182 << polZ << " )" >> 183 << G4endl; 253 G4cout << " Weight : " << Weight0 << G4e 184 G4cout << " Weight : " << Weight0 << G4endl; 254 if (properTime >= 0.0) { << 185 if(properTime>0.0) 255 G4cout << " PreAssigned proper decay t << 186 { G4cout << " PreAssigned proper decay time : " << properTime/ns << " [ns] " << G4endl; } 256 } << 187 if(userInfo != 0) userInfo->Print(); 257 if (userInfo != nullptr) { << 188 if(daughterParticle != 0) 258 userInfo->Print(); << 189 { 259 } << 260 if (daughterParticle != nullptr) { << 261 G4cout << ">>>> Daughters" << G4endl; 190 G4cout << ">>>> Daughters" << G4endl; 262 daughterParticle->Print(); 191 daughterParticle->Print(); 263 } 192 } 264 if (nextParticle != nullptr) { << 193 if(nextParticle != 0) 265 nextParticle->Print(); << 194 { nextParticle->Print(); } 266 } << 195 else 267 else { << 196 { G4cout << "<<<< End of link" << G4endl; } 268 G4cout << "<<<< End of link" << G4endl; << 269 } << 270 } 197 } >> 198 >> 199 >> 200 >> 201 271 202