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