Geant4 Cross Reference |
1 // ******************************************* 1 2 // * License and Disclaimer 3 // * 4 // * The Geant4 software is copyright of th 5 // * the Geant4 Collaboration. It is provided 6 // * conditions of the Geant4 Software License 7 // * LICENSE and available at http://cern.ch/ 8 // * include a list of copyright holders. 9 // * 10 // * Neither the authors of this software syst 11 // * institutes,nor the agencies providing fin 12 // * work make any representation or warran 13 // * regarding this software system or assum 14 // * use. Please see the license in the file 15 // * for the full disclaimer and the limitatio 16 // * 17 // * This code implementation is the result 18 // * technical work of the GEANT4 collaboratio 19 // * By using, copying, modifying or distri 20 // * any work based on the software) you ag 21 // * use in resulting scientific publicati 22 // * acceptance of all terms of the Geant4 Sof 23 // ******************************************* 24 // 25 // 26 // ------------------------------------------- 27 // GEANT 4 class header file 28 // 29 // History: first implementation, based on G4 30 // New dependency : G4VUserTrackInfo 31 // 32 // ---------------- G4Molecule --------- 33 // first design&implementation by Alfonso 34 // New developments Alfonso Mantero & Mat 35 // Oct/Nov 2009 Class Name changed to G4M 36 // Removed dependency from G 37 // New constructors : 38 // copy constructor 39 // direct ionized/excited m 40 // New methods : 41 // Get : name,atoms' number 42 // PrintState //To get the 43 // correspondi 44 // Kinematic : 45 // BuildTrack,GetKineticEne 46 // Change the way dynCharge 47 // ------------------------------------------- 48 49 #include "G4Molecule.hh" 50 #include "G4MolecularConfiguration.hh" 51 #include "Randomize.hh" 52 #include "G4PhysicalConstants.hh" 53 #include "G4SystemOfUnits.hh" 54 #include "G4Track.hh" 55 #include "G4VMoleculeCounter.hh" 56 57 using namespace std; 58 59 G4Allocator<G4Molecule>*& aMoleculeAllocator() 60 { 61 G4ThreadLocalStatic G4Allocator<G4Molecule 62 return _instance; 63 } 64 65 //____________________________________________ 66 67 template<> 68 G4KDNode<G4Molecule>::~G4KDNode() { 69 fPoint->SetNode(nullptr); 70 } 71 72 //____________________________________________ 73 74 G4Molecule* GetMolecule(const G4Track& track) 75 { 76 return (G4Molecule*)(GetIT(track)); 77 } 78 79 //____________________________________________ 80 81 G4Molecule* GetMolecule(const G4Track* track) 82 { 83 return (G4Molecule*)(GetIT(track)); 84 } 85 86 //____________________________________________ 87 88 G4Molecule* G4Molecule::GetMolecule(const G4Tr 89 { 90 return (G4Molecule*)(GetIT(track)); 91 } 92 93 //____________________________________________ 94 95 void G4Molecule::Print() const 96 { 97 G4cout << "The user track information is a 98 } 99 100 //____________________________________________ 101 102 G4Molecule::G4Molecule(const G4Molecule& right 103 : G4VUserTrackInformation("G4Molecule") 104 , G4IT(right) 105 { 106 fpMolecularConfiguration = right.fpMolecul 107 } 108 109 //____________________________________________ 110 111 G4Molecule& G4Molecule::operator=(const G4Mole 112 { 113 if (&right == this) return *this; 114 fpMolecularConfiguration = right.fpMolecul 115 return *this; 116 } 117 118 //____________________________________________ 119 120 G4bool G4Molecule::operator==(const G4Molecule 121 { 122 return fpMolecularConfiguration == right.f 123 } 124 125 //____________________________________________ 126 127 G4bool G4Molecule::operator!=(const G4Molecule 128 { 129 return !(*this == right); 130 } 131 132 //____________________________________________ 133 /** The two methods below are the most called 134 * compare molecules in the MoleculeStackMana 135 * the InteractionTable 136 */ 137 138 G4bool G4Molecule::operator<(const G4Molecule& 139 { 140 return fpMolecularConfiguration < right.fp 141 } 142 143 //____________________________________________ 144 145 G4Molecule::G4Molecule() 146 : G4VUserTrackInformation("G4Molecule") 147 { 148 fpMolecularConfiguration = nullptr; 149 } 150 151 //____________________________________________ 152 153 G4Molecule::~G4Molecule() 154 { 155 if (fpTrack != nullptr) 156 { 157 if (G4VMoleculeCounter::Instance()->In 158 { 159 G4VMoleculeCounter::Instance()-> 160 RemoveAMoleculeAtTime(fpMolecu 161 fpTrack- 162 &(fpTrac 163 } 164 fpTrack = nullptr; 165 } 166 fpMolecularConfiguration = nullptr; 167 } 168 169 //____________________________________________ 170 /** Build a molecule at ground state according 171 * G4MoleculeDefinition that can be obtained 172 */ 173 G4Molecule::G4Molecule(G4MoleculeDefinition* p 174 : G4VUserTrackInformation("G4Molecule") 175 { 176 fpMolecularConfiguration = G4MolecularConf 177 } 178 179 //____________________________________________ 180 181 G4Molecule::G4Molecule(G4MoleculeDefinition* p 182 { 183 fpMolecularConfiguration = G4MolecularConf 184 185 } 186 187 //____________________________________________ 188 /** Build a molecule at a specific excitation/ 189 * to a ground state that can be obtained fro 190 * Put 0 in the second option if this is a io 191 */ 192 G4Molecule::G4Molecule(G4MoleculeDefinition* p 193 G4int OrbitalToFree, 194 G4int OrbitalToFill) 195 : G4VUserTrackInformation("G4Molecule") 196 { 197 if (pMoleculeDefinition->GetGroundStateEle 198 { 199 G4ElectronOccupancy dynElectronOccupan 200 201 if (OrbitalToFill != 0) 202 { 203 dynElectronOccupancy.RemoveElectro 204 dynElectronOccupancy.AddElectron(O 205 // dynElectronOccupancy.DumpInfo() 206 } 207 208 if (OrbitalToFill == 0) 209 { 210 dynElectronOccupancy.RemoveElectro 211 // dynElectronOccupancy.DumpInfo() 212 } 213 214 fpMolecularConfiguration = 215 G4MolecularConfiguration::GetOrCre 216 pMoleculeDefinition, dynElectr 217 } 218 else 219 { 220 fpMolecularConfiguration = nullptr; 221 G4Exception( 222 "G4Molecule::G4Molecule(G4Molecule 223 "G4int OrbitalToFree, G4int Orbita 224 "G4Molecule_wrong_usage_of_constru 225 FatalErrorInArgument, 226 "If you want to use this construct 227 "first defined with electron occup 228 } 229 } 230 231 //____________________________________________ 232 /** Specific builder for water molecules to be 233 * the last option Excitation is true if the m 234 * false is the molecule is ionized. 235 */ 236 G4Molecule::G4Molecule(G4MoleculeDefinition* p 237 G4int level, 238 G4bool excitation) 239 : G4VUserTrackInformation("G4Molecule") 240 { 241 if (pMoleculeDefinition->GetGroundStateEle 242 { 243 G4ElectronOccupancy dynElectronOccupan 244 245 if (excitation) 246 { 247 dynElectronOccupancy.RemoveElectro 248 dynElectronOccupancy.AddElectron(5 249 // dynElectronOccupancy.DumpInfo() 250 } 251 else 252 { 253 dynElectronOccupancy.RemoveElectro 254 // dynElectronOccupancy.DumpInfo() 255 } 256 257 fpMolecularConfiguration = G4Molecular 258 dynElectronOccupancy); 259 } 260 else 261 { 262 fpMolecularConfiguration = nullptr; 263 G4Exception( 264 "G4Molecule::G4Molecule(G4Molecule 265 "G4int OrbitalToFree, G4int Orbita 266 "G4Molecule_wrong_usage_of_constru 267 FatalErrorInArgument, 268 "If you want to use this construct 269 "first defined with electron occup 270 } 271 } 272 273 //____________________________________________ 274 275 G4Molecule::G4Molecule(const G4MolecularConfig 276 { 277 fpMolecularConfiguration = pMolecularConfi 278 } 279 280 //____________________________________________ 281 282 void G4Molecule::SetElectronOccupancy(const G4 283 { 284 fpMolecularConfiguration = 285 G4MolecularConfiguration::GetOrCreateM 286 287 } 288 289 //____________________________________________ 290 291 void G4Molecule::ExciteMolecule(G4int excitati 292 { 293 fpMolecularConfiguration = fpMolecularConf 294 } 295 296 //____________________________________________ 297 298 void G4Molecule::IonizeMolecule(G4int ionizati 299 { 300 fpMolecularConfiguration = fpMolecularConf 301 } 302 303 //____________________________________________ 304 305 void G4Molecule::AddElectron(G4int orbit, G4in 306 { 307 fpMolecularConfiguration = fpMolecularConf 308 } 309 310 //____________________________________________ 311 312 void G4Molecule::RemoveElectron(G4int orbit, G 313 { 314 fpMolecularConfiguration = 315 fpMolecularConfiguration->RemoveElectr 316 } 317 318 //____________________________________________ 319 320 void G4Molecule::MoveOneElectron(G4int orbitTo 321 { 322 fpMolecularConfiguration = 323 fpMolecularConfiguration->MoveOneElect 324 } 325 326 //____________________________________________ 327 328 const G4String& G4Molecule::GetName() const 329 { 330 return fpMolecularConfiguration->GetName() 331 } 332 333 //____________________________________________ 334 335 const G4String& G4Molecule::GetFormatedName() 336 { 337 return fpMolecularConfiguration->GetFormat 338 } 339 340 //____________________________________________ 341 342 G4int G4Molecule::GetAtomsNumber() const 343 { 344 return fpMolecularConfiguration->GetAtomsN 345 } 346 347 //____________________________________________ 348 349 G4double G4Molecule::GetNbElectrons() const 350 { 351 return fpMolecularConfiguration->GetNbElec 352 } 353 354 //____________________________________________ 355 356 void G4Molecule::PrintState() const 357 { 358 fpMolecularConfiguration->PrintState(); 359 } 360 361 //____________________________________________ 362 363 G4Track* G4Molecule::BuildTrack(G4double globa 364 const G4Three 365 { 366 if (fpTrack != nullptr) 367 { 368 G4Exception("G4Molecule::BuildTrack", 369 "A track was already assig 370 } 371 372 // Kinetic Values 373 // Set a random direction to the molecule 374 G4double costheta = (2 * G4UniformRand() - 375 G4double theta = acos(costheta); 376 G4double phi = 2 * pi * G4UniformRand(); 377 378 G4double xMomentum = cos(phi) * sin(theta) 379 G4double yMomentum = sin(theta) * sin(phi) 380 G4double zMomentum = costheta; 381 382 G4ThreeVector MomentumDirection(xMomentum, 383 G4double KineticEnergy = GetKineticEnergy( 384 385 auto dynamicParticle = new G4DynamicParti 386 fpMolecularConfiguration->GetDefinitio 387 KineticEnergy); 388 389 if (G4VMoleculeCounter::Instance()->InUse( 390 { 391 G4VMoleculeCounter::Instance()-> 392 AddAMoleculeAtTime(fpMolecularConf 393 globalTime, 394 &(fpTrack->GetP 395 } 396 397 //Set the Track 398 fpTrack = new G4Track(dynamicParticle, glo 399 fpTrack->SetUserInformation(this); 400 401 return fpTrack; 402 } 403 404 //____________________________________________ 405 406 G4double G4Molecule::GetKineticEnergy() const 407 { 408 //// 409 // Ideal Gaz case 410 double v = GetDiffusionVelocity(); 411 double E = (fpMolecularConfiguration->GetM 412 //// 413 return E; 414 } 415 416 //____________________________________________ 417 418 G4double G4Molecule::GetDiffusionVelocity() co 419 { 420 double moleculeMass = fpMolecularConfigura 421 422 //// 423 // Different possibilities 424 //// 425 // Ideal Gaz case : Maxwell Boltzmann Dist 426 // double sigma = k_Boltzmann * fgTempe 427 // return G4RandGauss::shoot( 0, sigma 428 //// 429 // Ideal Gaz case : mean velocity from equ 430 return sqrt(3 * k_Boltzmann * 431 G4MolecularConfiguration::GetG 432 //// 433 // Using this approximation for liquid is 434 // However the brownian process avoid taki 435 // care of energy consideration and plays 436 // with positions 437 } 438 439 //____________________________________________ 440 441 // added - to be transformed in a "Decay metho 442 const vector<const G4MolecularDissociationChan 443 G4Molecule::GetDissociationChannels() const 444 { 445 return fpMolecularConfiguration->GetDissoc 446 } 447 448 //____________________________________________ 449 450 G4int G4Molecule::GetFakeParticleID() const 451 { 452 return fpMolecularConfiguration->GetFakePa 453 } 454 455 //____________________________________________ 456 457 G4int G4Molecule::GetMoleculeID() const 458 { 459 return fpMolecularConfiguration->GetMolecu 460 } 461 462 //____________________________________________ 463 464 G4double G4Molecule::GetDecayTime() const 465 { 466 return fpMolecularConfiguration->GetDecayT 467 } 468 469 //____________________________________________ 470 471 G4double G4Molecule::GetVanDerVaalsRadius() co 472 { 473 return fpMolecularConfiguration->GetVanDer 474 } 475 476 //____________________________________________ 477 478 G4int G4Molecule::GetCharge() const 479 { 480 return fpMolecularConfiguration->GetCharge 481 } 482 483 //____________________________________________ 484 485 G4double G4Molecule::GetMass() const 486 { 487 return fpMolecularConfiguration->GetMass() 488 } 489 490 //____________________________________________ 491 492 const G4ElectronOccupancy* G4Molecule::GetElec 493 { 494 return fpMolecularConfiguration->GetElectr 495 } 496 497 //____________________________________________ 498 499 const G4MoleculeDefinition* G4Molecule::GetDef 500 { 501 return fpMolecularConfiguration->GetDefini 502 } 503 504 //____________________________________________ 505 506 G4double G4Molecule::GetDiffusionCoefficient() 507 { 508 return fpMolecularConfiguration->GetDiffus 509 } 510 511 //____________________________________________ 512 513 G4double G4Molecule::GetDiffusionCoefficient(c 514 d 515 { 516 return fpMolecularConfiguration->GetDiffus 517 518 } 519 520 //____________________________________________ 521 522 const G4MolecularConfiguration* G4Molecule::Ge 523 { 524 return fpMolecularConfiguration; 525 } 526 527 //____________________________________________ 528 529 const G4String& G4Molecule::GetLabel() const 530 { 531 return fpMolecularConfiguration->GetLabel( 532 } 533 534 //____________________________________________ 535 536 void G4Molecule::ChangeConfigurationToLabel(co 537 { 538 // TODO check fpMolecularConfiguration alr 539 // and new one as well 540 // TODO notify for stack change 541 fpMolecularConfiguration = G4MolecularConf 542 fpMolecularConfiguration->GetDefinitio 543 544 assert(fpMolecularConfiguration != nullptr 545 } 546