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 // G4VUserPhysicsList implementation 26 // G4VUserPhysicsList implementation 27 // 27 // 28 // Original author: H.Kurashige (Kobe Universi 28 // Original author: H.Kurashige (Kobe University), 9 January 1998 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 31 #include "G4VUserPhysicsList.hh" 31 #include "G4VUserPhysicsList.hh" 32 32 33 #include "G4Material.hh" 33 #include "G4Material.hh" 34 #include "G4MaterialCutsCouple.hh" 34 #include "G4MaterialCutsCouple.hh" 35 #include "G4ParticleDefinition.hh" 35 #include "G4ParticleDefinition.hh" 36 #include "G4ParticleTable.hh" 36 #include "G4ParticleTable.hh" 37 #include "G4PhysicsListHelper.hh" 37 #include "G4PhysicsListHelper.hh" 38 #include "G4ProcessManager.hh" 38 #include "G4ProcessManager.hh" 39 #include "G4ProductionCuts.hh" 39 #include "G4ProductionCuts.hh" 40 #include "G4ProductionCutsTable.hh" 40 #include "G4ProductionCutsTable.hh" 41 #include "G4Region.hh" 41 #include "G4Region.hh" 42 #include "G4RegionStore.hh" 42 #include "G4RegionStore.hh" 43 #include "G4SystemOfUnits.hh" 43 #include "G4SystemOfUnits.hh" 44 #include "G4UImanager.hh" 44 #include "G4UImanager.hh" 45 #include "G4UnitsTable.hh" 45 #include "G4UnitsTable.hh" 46 #include "G4UserPhysicsListMessenger.hh" 46 #include "G4UserPhysicsListMessenger.hh" 47 #include "G4VTrackingManager.hh" 47 #include "G4VTrackingManager.hh" 48 #include "G4ios.hh" 48 #include "G4ios.hh" 49 #include "globals.hh" 49 #include "globals.hh" 50 50 51 #include <fstream> 51 #include <fstream> 52 #include <iomanip> 52 #include <iomanip> 53 #include <unordered_set> 53 #include <unordered_set> 54 54 55 // This static member is thread local. For eac 55 // This static member is thread local. For each thread, it holds the array 56 // size of G4VUPLData instances. 56 // size of G4VUPLData instances. 57 // 57 // 58 #define G4MT_theMessenger ((this->subInstanceM 58 #define G4MT_theMessenger ((this->subInstanceManager.offset[this->g4vuplInstanceID])._theMessenger) 59 #define G4MT_thePLHelper ((this->subInstanceMa 59 #define G4MT_thePLHelper ((this->subInstanceManager.offset[this->g4vuplInstanceID])._thePLHelper) 60 #define fIsPhysicsTableBuilt \ 60 #define fIsPhysicsTableBuilt \ 61 ((this->subInstanceManager.offset[this->g4vu 61 ((this->subInstanceManager.offset[this->g4vuplInstanceID])._fIsPhysicsTableBuilt) 62 #define fDisplayThreshold \ 62 #define fDisplayThreshold \ 63 ((this->subInstanceManager.offset[this->g4vu 63 ((this->subInstanceManager.offset[this->g4vuplInstanceID])._fDisplayThreshold) 64 #define theParticleIterator \ 64 #define theParticleIterator \ 65 ((this->subInstanceManager.offset[this->g4vu 65 ((this->subInstanceManager.offset[this->g4vuplInstanceID])._theParticleIterator) 66 66 67 // This field helps to use the class G4VUPLMan 67 // This field helps to use the class G4VUPLManager 68 // 68 // 69 G4VUPLManager G4VUserPhysicsList::subInstanceM 69 G4VUPLManager G4VUserPhysicsList::subInstanceManager; 70 70 71 // ------------------------------------------- 71 // -------------------------------------------------------------------- 72 void G4VUPLData::initialize() 72 void G4VUPLData::initialize() 73 { 73 { 74 _theParticleIterator = G4ParticleTable::GetP 74 _theParticleIterator = G4ParticleTable::GetParticleTable()->GetIterator(); 75 _theMessenger = nullptr; 75 _theMessenger = nullptr; 76 _thePLHelper = G4PhysicsListHelper::GetPhysi 76 _thePLHelper = G4PhysicsListHelper::GetPhysicsListHelper(); 77 _fIsPhysicsTableBuilt = false; 77 _fIsPhysicsTableBuilt = false; 78 _fDisplayThreshold = 0; 78 _fDisplayThreshold = 0; 79 } 79 } 80 80 81 // ------------------------------------------- 81 // -------------------------------------------------------------------- 82 G4VUserPhysicsList::G4VUserPhysicsList() 82 G4VUserPhysicsList::G4VUserPhysicsList() 83 { 83 { 84 g4vuplInstanceID = subInstanceManager.Create 84 g4vuplInstanceID = subInstanceManager.CreateSubInstance(); // AND 85 // default cut value (1.0mm) 85 // default cut value (1.0mm) 86 defaultCutValue = 1.0 * mm; 86 defaultCutValue = 1.0 * mm; 87 87 88 // pointer to the particle table 88 // pointer to the particle table 89 theParticleTable = G4ParticleTable::GetParti 89 theParticleTable = G4ParticleTable::GetParticleTable(); 90 90 91 // pointer to the cuts table 91 // pointer to the cuts table 92 fCutsTable = G4ProductionCutsTable::GetProdu 92 fCutsTable = G4ProductionCutsTable::GetProductionCutsTable(); 93 93 94 // set energy range for SetCut calcuration 94 // set energy range for SetCut calcuration 95 fCutsTable->SetEnergyRange(0.99 * keV, 100 * 95 fCutsTable->SetEnergyRange(0.99 * keV, 100 * TeV); 96 96 97 // UI Messenger 97 // UI Messenger 98 G4MT_theMessenger = new G4UserPhysicsListMes 98 G4MT_theMessenger = new G4UserPhysicsListMessenger(this); // AND 99 99 100 // PhysicsListHelper 100 // PhysicsListHelper 101 G4MT_thePLHelper->SetVerboseLevel(verboseLev 101 G4MT_thePLHelper->SetVerboseLevel(verboseLevel); // AND 102 102 103 fIsPhysicsTableBuilt = false; 103 fIsPhysicsTableBuilt = false; 104 fDisplayThreshold = 0; 104 fDisplayThreshold = 0; 105 } 105 } 106 106 107 // ------------------------------------------- 107 // -------------------------------------------------------------------- 108 void G4VUserPhysicsList::InitializeWorker() 108 void G4VUserPhysicsList::InitializeWorker() 109 { 109 { 110 // Remember messengers are per-thread, so th 110 // Remember messengers are per-thread, so this needs to be done by each 111 // worker and due to the presence of "this" 111 // worker and due to the presence of "this" cannot be done in 112 // G4VUPLData::initialize() 112 // G4VUPLData::initialize() 113 G4MT_theMessenger = new G4UserPhysicsListMes 113 G4MT_theMessenger = new G4UserPhysicsListMessenger(this); 114 } 114 } 115 115 116 // ------------------------------------------- 116 // -------------------------------------------------------------------- 117 void G4VUserPhysicsList::TerminateWorker() 117 void G4VUserPhysicsList::TerminateWorker() 118 { 118 { 119 RemoveProcessManager(); 119 RemoveProcessManager(); 120 RemoveTrackingManager(); 120 RemoveTrackingManager(); 121 delete G4MT_theMessenger; 121 delete G4MT_theMessenger; 122 G4MT_theMessenger = nullptr; 122 G4MT_theMessenger = nullptr; 123 } 123 } 124 124 125 // ------------------------------------------- 125 // -------------------------------------------------------------------- 126 G4VUserPhysicsList::~G4VUserPhysicsList() 126 G4VUserPhysicsList::~G4VUserPhysicsList() 127 { 127 { 128 delete G4MT_theMessenger; 128 delete G4MT_theMessenger; 129 G4MT_theMessenger = nullptr; 129 G4MT_theMessenger = nullptr; 130 130 131 RemoveProcessManager(); 131 RemoveProcessManager(); 132 RemoveTrackingManager(); 132 RemoveTrackingManager(); 133 133 134 // invoke DeleteAllParticle 134 // invoke DeleteAllParticle 135 theParticleTable->DeleteAllParticles(); 135 theParticleTable->DeleteAllParticles(); 136 } 136 } 137 137 138 // ------------------------------------------- 138 // -------------------------------------------------------------------- 139 G4VUserPhysicsList::G4VUserPhysicsList(const G 139 G4VUserPhysicsList::G4VUserPhysicsList(const G4VUserPhysicsList& right) 140 : verboseLevel(right.verboseLevel), 140 : verboseLevel(right.verboseLevel), 141 defaultCutValue(right.defaultCutValue), 141 defaultCutValue(right.defaultCutValue), 142 isSetDefaultCutValue(right.isSetDefaultCut 142 isSetDefaultCutValue(right.isSetDefaultCutValue), 143 fRetrievePhysicsTable(right.fRetrievePhysi 143 fRetrievePhysicsTable(right.fRetrievePhysicsTable), 144 fStoredInAscii(right.fStoredInAscii), 144 fStoredInAscii(right.fStoredInAscii), 145 fIsCheckedForRetrievePhysicsTable(right.fI 145 fIsCheckedForRetrievePhysicsTable(right.fIsCheckedForRetrievePhysicsTable), 146 fIsRestoredCutValues(right.fIsRestoredCutV 146 fIsRestoredCutValues(right.fIsRestoredCutValues), 147 directoryPhysicsTable(right.directoryPhysi 147 directoryPhysicsTable(right.directoryPhysicsTable), 148 fDisableCheckParticleList(right.fDisableCh 148 fDisableCheckParticleList(right.fDisableCheckParticleList) 149 { 149 { 150 g4vuplInstanceID = subInstanceManager.Create 150 g4vuplInstanceID = subInstanceManager.CreateSubInstance(); 151 // pointer to the particle table 151 // pointer to the particle table 152 theParticleTable = G4ParticleTable::GetParti 152 theParticleTable = G4ParticleTable::GetParticleTable(); 153 theParticleIterator = theParticleTable->GetI 153 theParticleIterator = theParticleTable->GetIterator(); 154 // pointer to the cuts table 154 // pointer to the cuts table 155 fCutsTable = G4ProductionCutsTable::GetProdu 155 fCutsTable = G4ProductionCutsTable::GetProductionCutsTable(); 156 156 157 // UI Messenger 157 // UI Messenger 158 G4MT_theMessenger = new G4UserPhysicsListMes 158 G4MT_theMessenger = new G4UserPhysicsListMessenger(this); 159 159 160 // PhysicsListHelper 160 // PhysicsListHelper 161 G4MT_thePLHelper = G4PhysicsListHelper::GetP 161 G4MT_thePLHelper = G4PhysicsListHelper::GetPhysicsListHelper(); 162 G4MT_thePLHelper->SetVerboseLevel(verboseLev 162 G4MT_thePLHelper->SetVerboseLevel(verboseLevel); 163 163 164 fIsPhysicsTableBuilt = 164 fIsPhysicsTableBuilt = 165 right.GetSubInstanceManager().offset[right 165 right.GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt; 166 fDisplayThreshold = 166 fDisplayThreshold = 167 right.GetSubInstanceManager().offset[right 167 right.GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold; 168 } 168 } 169 169 170 // ------------------------------------------- 170 // -------------------------------------------------------------------- 171 G4VUserPhysicsList& G4VUserPhysicsList::operat 171 G4VUserPhysicsList& G4VUserPhysicsList::operator=(const G4VUserPhysicsList& right) 172 { 172 { 173 if (this != &right) { 173 if (this != &right) { 174 verboseLevel = right.verboseLevel; 174 verboseLevel = right.verboseLevel; 175 defaultCutValue = right.defaultCutValue; 175 defaultCutValue = right.defaultCutValue; 176 isSetDefaultCutValue = right.isSetDefaultC 176 isSetDefaultCutValue = right.isSetDefaultCutValue; 177 fRetrievePhysicsTable = right.fRetrievePhy 177 fRetrievePhysicsTable = right.fRetrievePhysicsTable; 178 fStoredInAscii = right.fStoredInAscii; 178 fStoredInAscii = right.fStoredInAscii; 179 fIsCheckedForRetrievePhysicsTable = right. 179 fIsCheckedForRetrievePhysicsTable = right.fIsCheckedForRetrievePhysicsTable; 180 fIsRestoredCutValues = right.fIsRestoredCu 180 fIsRestoredCutValues = right.fIsRestoredCutValues; 181 directoryPhysicsTable = right.directoryPhy 181 directoryPhysicsTable = right.directoryPhysicsTable; 182 fIsPhysicsTableBuilt = 182 fIsPhysicsTableBuilt = 183 right.GetSubInstanceManager().offset[rig 183 right.GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt; 184 fDisplayThreshold = 184 fDisplayThreshold = 185 right.GetSubInstanceManager().offset[rig 185 right.GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold; 186 fDisableCheckParticleList = right.fDisable 186 fDisableCheckParticleList = right.fDisableCheckParticleList; 187 } 187 } 188 return *this; 188 return *this; 189 } 189 } 190 190 191 // ------------------------------------------- 191 // -------------------------------------------------------------------- 192 void G4VUserPhysicsList::AddProcessManager(G4P 192 void G4VUserPhysicsList::AddProcessManager(G4ParticleDefinition* newParticle, G4ProcessManager*) 193 { 193 { 194 if (newParticle == nullptr) return; 194 if (newParticle == nullptr) return; 195 G4Exception("G4VUserPhysicsList::AddProcessM 195 G4Exception("G4VUserPhysicsList::AddProcessManager", "Run0252", JustWarning, 196 "This method is obsolete"); 196 "This method is obsolete"); 197 } 197 } 198 198 199 // ------------------------------------------- 199 // -------------------------------------------------------------------- 200 void G4VUserPhysicsList::InitializeProcessMana 200 void G4VUserPhysicsList::InitializeProcessManager() 201 { 201 { 202 // Request lock for particle table access. S 202 // Request lock for particle table access. Some changes are inside 203 // this critical region. 203 // this critical region. 204 #ifdef G4MULTITHREADED 204 #ifdef G4MULTITHREADED 205 G4MUTEXLOCK(&G4ParticleTable::particleTableM 205 G4MUTEXLOCK(&G4ParticleTable::particleTableMutex()); 206 G4ParticleTable::lockCount()++; 206 G4ParticleTable::lockCount()++; 207 #endif 207 #endif 208 G4ParticleDefinition* gion = G4ParticleTable 208 G4ParticleDefinition* gion = G4ParticleTable::GetParticleTable()->GetGenericIon(); 209 209 210 // loop over all particles in G4ParticleTabl 210 // loop over all particles in G4ParticleTable 211 theParticleIterator->reset(); 211 theParticleIterator->reset(); 212 while ((*theParticleIterator)()) { 212 while ((*theParticleIterator)()) { 213 G4ParticleDefinition* particle = thePartic 213 G4ParticleDefinition* particle = theParticleIterator->value(); 214 G4ProcessManager* pmanager = particle->Get 214 G4ProcessManager* pmanager = particle->GetProcessManager(); 215 215 216 if (pmanager == nullptr) { 216 if (pmanager == nullptr) { 217 // create process manager if the particl 217 // create process manager if the particle does not have its own. 218 pmanager = new G4ProcessManager(particle 218 pmanager = new G4ProcessManager(particle); 219 particle->SetProcessManager(pmanager); 219 particle->SetProcessManager(pmanager); 220 if (particle->GetMasterProcessManager() 220 if (particle->GetMasterProcessManager() == nullptr) 221 particle->SetMasterProcessManager(pman 221 particle->SetMasterProcessManager(pmanager); 222 #ifdef G4VERBOSE 222 #ifdef G4VERBOSE 223 if (verboseLevel > 2) { 223 if (verboseLevel > 2) { 224 G4cout << "G4VUserPhysicsList::Initial 224 G4cout << "G4VUserPhysicsList::InitializeProcessManager: creating " 225 "ProcessManager to " 225 "ProcessManager to " 226 << particle->GetParticleName() 226 << particle->GetParticleName() << G4endl; 227 } 227 } 228 #endif 228 #endif 229 } 229 } 230 } 230 } 231 231 232 if (gion != nullptr) { 232 if (gion != nullptr) { 233 G4ProcessManager* gionPM = gion->GetProces 233 G4ProcessManager* gionPM = gion->GetProcessManager(); 234 // loop over all particles once again (thi 234 // loop over all particles once again (this time, with all general ions) 235 theParticleIterator->reset(false); 235 theParticleIterator->reset(false); 236 while ((*theParticleIterator)()) { 236 while ((*theParticleIterator)()) { 237 G4ParticleDefinition* particle = thePart 237 G4ParticleDefinition* particle = theParticleIterator->value(); 238 if (particle->IsGeneralIon()) { 238 if (particle->IsGeneralIon()) { 239 particle->SetProcessManager(gionPM); 239 particle->SetProcessManager(gionPM); 240 #ifdef G4VERBOSE 240 #ifdef G4VERBOSE 241 if (verboseLevel > 2) { 241 if (verboseLevel > 2) { 242 G4cout << "G4VUserPhysicsList::Initi 242 G4cout << "G4VUserPhysicsList::InitializeProcessManager: copying " 243 "ProcessManager to " 243 "ProcessManager to " 244 << particle->GetParticleName( 244 << particle->GetParticleName() << G4endl; 245 } 245 } 246 #endif 246 #endif 247 } 247 } 248 } 248 } 249 } 249 } 250 250 251 // release lock for particle table access 251 // release lock for particle table access 252 #ifdef G4MULTITHREADED 252 #ifdef G4MULTITHREADED 253 G4MUTEXUNLOCK(&G4ParticleTable::particleTabl 253 G4MUTEXUNLOCK(&G4ParticleTable::particleTableMutex()); 254 #endif 254 #endif 255 } 255 } 256 256 257 // ------------------------------------------- 257 // -------------------------------------------------------------------- 258 void G4VUserPhysicsList::RemoveProcessManager( 258 void G4VUserPhysicsList::RemoveProcessManager() 259 { 259 { 260 // Request lock for particle table access. S 260 // Request lock for particle table access. Some changes are inside 261 // this critical region. 261 // this critical region. 262 #ifdef G4MULTITHREADED 262 #ifdef G4MULTITHREADED 263 G4MUTEXLOCK(&G4ParticleTable::particleTableM 263 G4MUTEXLOCK(&G4ParticleTable::particleTableMutex()); 264 G4ParticleTable::lockCount()++; 264 G4ParticleTable::lockCount()++; 265 #endif 265 #endif 266 266 267 // loop over all particles in G4ParticleTabl 267 // loop over all particles in G4ParticleTable 268 theParticleIterator->reset(); 268 theParticleIterator->reset(); 269 while ((*theParticleIterator)()) { 269 while ((*theParticleIterator)()) { 270 G4ParticleDefinition* particle = thePartic 270 G4ParticleDefinition* particle = theParticleIterator->value(); 271 if (particle->GetInstanceID() < G4Particle 271 if (particle->GetInstanceID() < G4ParticleDefinitionSubInstanceManager::slavetotalspace()) { 272 if (particle->GetParticleSubType() != "g 272 if (particle->GetParticleSubType() != "generic" 273 || particle->GetParticleName() == "G 273 || particle->GetParticleName() == "GenericIon") 274 { 274 { 275 G4ProcessManager* pmanager = particle- 275 G4ProcessManager* pmanager = particle->GetProcessManager(); 276 276 277 delete pmanager; 277 delete pmanager; 278 #ifdef G4VERBOSE 278 #ifdef G4VERBOSE 279 if (verboseLevel > 2) { 279 if (verboseLevel > 2) { 280 G4cout << "G4VUserPhysicsList::Remov 280 G4cout << "G4VUserPhysicsList::RemoveProcessManager: "; 281 G4cout << "remove ProcessManager fro 281 G4cout << "remove ProcessManager from "; 282 G4cout << particle->GetParticleName( 282 G4cout << particle->GetParticleName() << G4endl; 283 } 283 } 284 #endif 284 #endif 285 } 285 } 286 particle->SetProcessManager(nullptr); 286 particle->SetProcessManager(nullptr); 287 } 287 } 288 } 288 } 289 289 290 // release lock for particle table access 290 // release lock for particle table access 291 #ifdef G4MULTITHREADED 291 #ifdef G4MULTITHREADED 292 G4MUTEXUNLOCK(&G4ParticleTable::particleTabl 292 G4MUTEXUNLOCK(&G4ParticleTable::particleTableMutex()); 293 #endif 293 #endif 294 } 294 } 295 295 296 // ------------------------------------------- 296 // -------------------------------------------------------------------- 297 void G4VUserPhysicsList::RemoveTrackingManager 297 void G4VUserPhysicsList::RemoveTrackingManager() 298 { 298 { 299 // One tracking manager may be registered fo 299 // One tracking manager may be registered for multiple particles, make sure 300 // to delete every object only once. 300 // to delete every object only once. 301 std::unordered_set<G4VTrackingManager*> trac 301 std::unordered_set<G4VTrackingManager*> trackingManagers; 302 302 303 // loop over all particles in G4ParticleTabl 303 // loop over all particles in G4ParticleTable 304 theParticleIterator->reset(); 304 theParticleIterator->reset(); 305 while ((*theParticleIterator)()) { 305 while ((*theParticleIterator)()) { 306 G4ParticleDefinition* particle = thePartic 306 G4ParticleDefinition* particle = theParticleIterator->value(); 307 if (auto* trackingManager = particle->GetT 307 if (auto* trackingManager = particle->GetTrackingManager()) { 308 #ifdef G4VERBOSE 308 #ifdef G4VERBOSE 309 if (verboseLevel > 2) { 309 if (verboseLevel > 2) { 310 G4cout << "G4VUserPhysicsList::RemoveT 310 G4cout << "G4VUserPhysicsList::RemoveTrackingManager: "; 311 G4cout << "remove TrackingManager from 311 G4cout << "remove TrackingManager from "; 312 G4cout << particle->GetParticleName() 312 G4cout << particle->GetParticleName() << G4endl; 313 } 313 } 314 #endif 314 #endif 315 trackingManagers.insert(trackingManager) 315 trackingManagers.insert(trackingManager); 316 particle->SetTrackingManager(nullptr); 316 particle->SetTrackingManager(nullptr); 317 } 317 } 318 } 318 } 319 319 320 for (G4VTrackingManager* tm : trackingManage 320 for (G4VTrackingManager* tm : trackingManagers) { 321 delete tm; 321 delete tm; 322 } 322 } 323 } 323 } 324 324 325 // ------------------------------------------- 325 // -------------------------------------------------------------------- 326 void G4VUserPhysicsList::SetCuts() 326 void G4VUserPhysicsList::SetCuts() 327 { 327 { 328 if (!isSetDefaultCutValue) { 328 if (!isSetDefaultCutValue) { 329 SetDefaultCutValue(defaultCutValue); 329 SetDefaultCutValue(defaultCutValue); 330 } 330 } 331 331 332 #ifdef G4VERBOSE 332 #ifdef G4VERBOSE 333 if (verboseLevel > 1) { 333 if (verboseLevel > 1) { 334 G4cout << "G4VUserPhysicsList::SetCuts: 334 G4cout << "G4VUserPhysicsList::SetCuts: " << G4endl; 335 G4cout << "Cut for gamma: " << GetCutValue 335 G4cout << "Cut for gamma: " << GetCutValue("gamma") / mm << "[mm]" << G4endl; 336 G4cout << "Cut for e-: " << GetCutValue(" 336 G4cout << "Cut for e-: " << GetCutValue("e-") / mm << "[mm]" << G4endl; 337 G4cout << "Cut for e+: " << GetCutValue(" 337 G4cout << "Cut for e+: " << GetCutValue("e+") / mm << "[mm]" << G4endl; 338 G4cout << "Cut for proton: " << GetCutVal 338 G4cout << "Cut for proton: " << GetCutValue("proton") / mm << "[mm]" << G4endl; 339 } 339 } 340 #endif 340 #endif 341 341 342 // dump Cut values if verboseLevel==3 342 // dump Cut values if verboseLevel==3 343 if (verboseLevel > 2) { 343 if (verboseLevel > 2) { 344 DumpCutValuesTable(); 344 DumpCutValuesTable(); 345 } 345 } 346 } 346 } 347 347 348 // ------------------------------------------- 348 // -------------------------------------------------------------------- 349 void G4VUserPhysicsList::SetDefaultCutValue(G4 349 void G4VUserPhysicsList::SetDefaultCutValue(G4double value) 350 { 350 { 351 if (value < 0.0) { 351 if (value < 0.0) { 352 #ifdef G4VERBOSE 352 #ifdef G4VERBOSE 353 if (verboseLevel > 0) { 353 if (verboseLevel > 0) { 354 G4cout << "G4VUserPhysicsList::SetDefaul 354 G4cout << "G4VUserPhysicsList::SetDefaultCutValue: negative cut values" 355 << " :" << value / mm << "[mm]" 355 << " :" << value / mm << "[mm]" << G4endl; 356 } 356 } 357 #endif 357 #endif 358 return; 358 return; 359 } 359 } 360 360 361 defaultCutValue = value; 361 defaultCutValue = value; 362 isSetDefaultCutValue = true; 362 isSetDefaultCutValue = true; 363 363 364 // set cut values for gamma at first and for 364 // set cut values for gamma at first and for e- and e+ 365 SetCutValue(defaultCutValue, "gamma"); 365 SetCutValue(defaultCutValue, "gamma"); 366 SetCutValue(defaultCutValue, "e-"); 366 SetCutValue(defaultCutValue, "e-"); 367 SetCutValue(defaultCutValue, "e+"); 367 SetCutValue(defaultCutValue, "e+"); 368 SetCutValue(defaultCutValue, "proton"); 368 SetCutValue(defaultCutValue, "proton"); 369 369 370 #ifdef G4VERBOSE 370 #ifdef G4VERBOSE 371 if (verboseLevel > 1) { 371 if (verboseLevel > 1) { 372 G4cout << "G4VUserPhysicsList::SetDefaultC 372 G4cout << "G4VUserPhysicsList::SetDefaultCutValue:" 373 << "default cut value is changed to 373 << "default cut value is changed to :" << defaultCutValue / mm << "[mm]" << G4endl; 374 } 374 } 375 #endif 375 #endif 376 } 376 } 377 377 378 // ------------------------------------------- 378 // -------------------------------------------------------------------- 379 G4double G4VUserPhysicsList::GetCutValue(const 379 G4double G4VUserPhysicsList::GetCutValue(const G4String& name) const 380 { 380 { 381 std::size_t nReg = (G4RegionStore::GetInstan 381 std::size_t nReg = (G4RegionStore::GetInstance())->size(); 382 if (nReg == 0) { 382 if (nReg == 0) { 383 #ifdef G4VERBOSE 383 #ifdef G4VERBOSE 384 if (verboseLevel > 0) { 384 if (verboseLevel > 0) { 385 G4cout << "G4VUserPhysicsList::GetCutVal 385 G4cout << "G4VUserPhysicsList::GetCutValue " 386 << " : No Default Region " << G4e 386 << " : No Default Region " << G4endl; 387 } 387 } 388 #endif 388 #endif 389 G4Exception("G4VUserPhysicsList::GetCutVal 389 G4Exception("G4VUserPhysicsList::GetCutValue", "Run0253", FatalException, "No Default Region"); 390 return -1. * mm; 390 return -1. * mm; 391 } 391 } 392 G4Region* region = G4RegionStore::GetInstanc 392 G4Region* region = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", false); 393 return region->GetProductionCuts()->GetProdu 393 return region->GetProductionCuts()->GetProductionCut(name); 394 } 394 } 395 395 396 // ------------------------------------------- 396 // -------------------------------------------------------------------- 397 void G4VUserPhysicsList::SetCutValue(G4double 397 void G4VUserPhysicsList::SetCutValue(G4double aCut, const G4String& name) 398 { 398 { 399 SetParticleCuts(aCut, name); 399 SetParticleCuts(aCut, name); 400 } 400 } 401 401 402 // ------------------------------------------- 402 // -------------------------------------------------------------------- 403 void G4VUserPhysicsList::SetCutValue(G4double 403 void G4VUserPhysicsList::SetCutValue(G4double aCut, const G4String& pname, const G4String& rname) 404 { 404 { 405 G4Region* region = G4RegionStore::GetInstanc 405 G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname); 406 if (region != nullptr) { 406 if (region != nullptr) { 407 // set cut value 407 // set cut value 408 SetParticleCuts(aCut, pname, region); 408 SetParticleCuts(aCut, pname, region); 409 } 409 } 410 else { 410 else { 411 #ifdef G4VERBOSE 411 #ifdef G4VERBOSE 412 if (verboseLevel > 0) { 412 if (verboseLevel > 0) { 413 G4cout << "G4VUserPhysicsList::SetCutVal 413 G4cout << "G4VUserPhysicsList::SetCutValue " 414 << " : No Region of " << rname << 414 << " : No Region of " << rname << G4endl; 415 } 415 } 416 #endif 416 #endif 417 } 417 } 418 } 418 } 419 419 420 // ------------------------------------------- 420 // -------------------------------------------------------------------- 421 void G4VUserPhysicsList::SetCutsWithDefault() 421 void G4VUserPhysicsList::SetCutsWithDefault() 422 { 422 { 423 SetDefaultCutValue(defaultCutValue); 423 SetDefaultCutValue(defaultCutValue); 424 G4VUserPhysicsList::SetCuts(); 424 G4VUserPhysicsList::SetCuts(); 425 } 425 } 426 426 427 // ------------------------------------------- 427 // -------------------------------------------------------------------- 428 void G4VUserPhysicsList::SetCutsForRegion(G4do 428 void G4VUserPhysicsList::SetCutsForRegion(G4double aCut, const G4String& rname) 429 { 429 { 430 // set cut values for gamma at first and for 430 // set cut values for gamma at first and for e- and e+ 431 SetCutValue(aCut, "gamma", rname); 431 SetCutValue(aCut, "gamma", rname); 432 SetCutValue(aCut, "e-", rname); 432 SetCutValue(aCut, "e-", rname); 433 SetCutValue(aCut, "e+", rname); 433 SetCutValue(aCut, "e+", rname); 434 SetCutValue(aCut, "proton", rname); 434 SetCutValue(aCut, "proton", rname); 435 } 435 } 436 436 437 // ------------------------------------------- 437 // -------------------------------------------------------------------- 438 void G4VUserPhysicsList::SetParticleCuts(G4dou 438 void G4VUserPhysicsList::SetParticleCuts(G4double cut, G4ParticleDefinition* particle, 439 G4Reg 439 G4Region* region) 440 { 440 { 441 SetParticleCuts(cut, particle->GetParticleNa 441 SetParticleCuts(cut, particle->GetParticleName(), region); 442 } 442 } 443 443 444 // ------------------------------------------- 444 // -------------------------------------------------------------------- 445 void G4VUserPhysicsList::SetParticleCuts(G4dou 445 void G4VUserPhysicsList::SetParticleCuts(G4double cut, const G4String& particleName, 446 G4Reg 446 G4Region* region) 447 { 447 { 448 if (cut < 0.0) { 448 if (cut < 0.0) { 449 #ifdef G4VERBOSE 449 #ifdef G4VERBOSE 450 if (verboseLevel > 0) { 450 if (verboseLevel > 0) { 451 G4cout << "G4VUserPhysicsList::SetPartic 451 G4cout << "G4VUserPhysicsList::SetParticleCuts: negative cut values" 452 << " :" << cut / mm << "[mm]" 452 << " :" << cut / mm << "[mm]" 453 << " for " << particleName << G4e 453 << " for " << particleName << G4endl; 454 } 454 } 455 #endif 455 #endif 456 return; 456 return; 457 } 457 } 458 458 459 G4Region* world_region = 459 G4Region* world_region = 460 G4RegionStore::GetInstance()->GetRegion("D 460 G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld", false); 461 if (region == nullptr) { 461 if (region == nullptr) { 462 std::size_t nReg = G4RegionStore::GetInsta 462 std::size_t nReg = G4RegionStore::GetInstance()->size(); 463 if (nReg == 0) { 463 if (nReg == 0) { 464 #ifdef G4VERBOSE 464 #ifdef G4VERBOSE 465 if (verboseLevel > 0) { 465 if (verboseLevel > 0) { 466 G4cout << "G4VUserPhysicsList::SetPart 466 G4cout << "G4VUserPhysicsList::SetParticleCuts " 467 << " : No Default Region " << G 467 << " : No Default Region " << G4endl; 468 } 468 } 469 #endif 469 #endif 470 G4Exception("G4VUserPhysicsList::SetPart 470 G4Exception("G4VUserPhysicsList::SetParticleCuts ", "Run0254", FatalException, 471 "No Default Region"); 471 "No Default Region"); 472 return; 472 return; 473 } 473 } 474 region = world_region; 474 region = world_region; 475 } 475 } 476 476 477 if (!isSetDefaultCutValue) { 477 if (!isSetDefaultCutValue) { 478 SetDefaultCutValue(defaultCutValue); 478 SetDefaultCutValue(defaultCutValue); 479 } 479 } 480 480 481 G4ProductionCuts* pcuts = region->GetProduct 481 G4ProductionCuts* pcuts = region->GetProductionCuts(); 482 if (region != world_region 482 if (region != world_region 483 && pcuts == G4ProductionCutsTable::GetPr 483 && pcuts == G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts()) 484 { // This region had no unique cuts yet but 484 { // This region had no unique cuts yet but shares the default cuts. 485 // Need to create a new object before set 485 // Need to create a new object before setting the value. 486 pcuts = new G4ProductionCuts( 486 pcuts = new G4ProductionCuts( 487 *(G4ProductionCutsTable::GetProductionCu 487 *(G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts())); 488 region->SetProductionCuts(pcuts); 488 region->SetProductionCuts(pcuts); 489 } 489 } 490 pcuts->SetProductionCut(cut, particleName); 490 pcuts->SetProductionCut(cut, particleName); 491 #ifdef G4VERBOSE 491 #ifdef G4VERBOSE 492 if (verboseLevel > 2) { 492 if (verboseLevel > 2) { 493 G4cout << "G4VUserPhysicsList::SetParticle 493 G4cout << "G4VUserPhysicsList::SetParticleCuts: " 494 << " :" << cut / mm << "[mm]" 494 << " :" << cut / mm << "[mm]" 495 << " for " << particleName << G4end 495 << " for " << particleName << G4endl; 496 } 496 } 497 #endif 497 #endif 498 } 498 } 499 499 500 // ------------------------------------------- 500 // -------------------------------------------------------------------- 501 void G4VUserPhysicsList::BuildPhysicsTable() 501 void G4VUserPhysicsList::BuildPhysicsTable() 502 { 502 { 503 // Prepare Physics table for all particles 503 // Prepare Physics table for all particles 504 theParticleIterator->reset(); 504 theParticleIterator->reset(); 505 while ((*theParticleIterator)()) { 505 while ((*theParticleIterator)()) { 506 G4ParticleDefinition* particle = thePartic 506 G4ParticleDefinition* particle = theParticleIterator->value(); 507 PreparePhysicsTable(particle); 507 PreparePhysicsTable(particle); 508 } 508 } 509 509 510 // ask processes to prepare physics table 510 // ask processes to prepare physics table 511 if (fRetrievePhysicsTable) { 511 if (fRetrievePhysicsTable) { 512 fIsRestoredCutValues = fCutsTable->Retriev 512 fIsRestoredCutValues = fCutsTable->RetrieveCutsTable(directoryPhysicsTable, fStoredInAscii); 513 // check if retrieve Cut Table successfull 513 // check if retrieve Cut Table successfully 514 if (!fIsRestoredCutValues) { 514 if (!fIsRestoredCutValues) { 515 #ifdef G4VERBOSE 515 #ifdef G4VERBOSE 516 if (verboseLevel > 0) { 516 if (verboseLevel > 0) { 517 G4cout << "G4VUserPhysicsList::BuildPh 517 G4cout << "G4VUserPhysicsList::BuildPhysicsTable" 518 << " Retrieve Cut Table failed 518 << " Retrieve Cut Table failed !!" << G4endl; 519 } 519 } 520 #endif 520 #endif 521 G4Exception("G4VUserPhysicsList::BuildPh 521 G4Exception("G4VUserPhysicsList::BuildPhysicsTable", "Run0255", RunMustBeAborted, 522 "Fail to retrieve Production 522 "Fail to retrieve Production Cut Table"); 523 } 523 } 524 else { 524 else { 525 #ifdef G4VERBOSE 525 #ifdef G4VERBOSE 526 if (verboseLevel > 2) { 526 if (verboseLevel > 2) { 527 G4cout << "G4VUserPhysicsList::BuildPh 527 G4cout << "G4VUserPhysicsList::BuildPhysicsTable" 528 << " Retrieve Cut Table succes 528 << " Retrieve Cut Table successfully " << G4endl; 529 } 529 } 530 #endif 530 #endif 531 } 531 } 532 } 532 } 533 else { 533 else { 534 #ifdef G4VERBOSE 534 #ifdef G4VERBOSE 535 if (verboseLevel > 2) { 535 if (verboseLevel > 2) { 536 G4cout << "G4VUserPhysicsList::BuildPhys 536 G4cout << "G4VUserPhysicsList::BuildPhysicsTable" 537 << " does not retrieve Cut Table 537 << " does not retrieve Cut Table but calculate " << G4endl; 538 } 538 } 539 #endif 539 #endif 540 } 540 } 541 541 542 // Sets a value to particle 542 // Sets a value to particle 543 // set cut values for gamma at first and for 543 // set cut values for gamma at first and for e- and e+ 544 G4String particleName; 544 G4String particleName; 545 G4ParticleDefinition* GammaP = theParticleTa 545 G4ParticleDefinition* GammaP = theParticleTable->FindParticle("gamma"); 546 if (GammaP != nullptr) BuildPhysicsTable(Gam 546 if (GammaP != nullptr) BuildPhysicsTable(GammaP); 547 G4ParticleDefinition* EMinusP = theParticleT 547 G4ParticleDefinition* EMinusP = theParticleTable->FindParticle("e-"); 548 if (EMinusP != nullptr) BuildPhysicsTable(EM 548 if (EMinusP != nullptr) BuildPhysicsTable(EMinusP); 549 G4ParticleDefinition* EPlusP = theParticleTa 549 G4ParticleDefinition* EPlusP = theParticleTable->FindParticle("e+"); 550 if (EPlusP != nullptr) BuildPhysicsTable(EPl 550 if (EPlusP != nullptr) BuildPhysicsTable(EPlusP); 551 G4ParticleDefinition* ProtonP = theParticleT 551 G4ParticleDefinition* ProtonP = theParticleTable->FindParticle("proton"); 552 if (ProtonP != nullptr) BuildPhysicsTable(Pr 552 if (ProtonP != nullptr) BuildPhysicsTable(ProtonP); 553 553 554 theParticleIterator->reset(); 554 theParticleIterator->reset(); 555 while ((*theParticleIterator)()) { 555 while ((*theParticleIterator)()) { 556 G4ParticleDefinition* particle = thePartic 556 G4ParticleDefinition* particle = theParticleIterator->value(); 557 if (particle != GammaP && particle != EMin 557 if (particle != GammaP && particle != EMinusP && particle != EPlusP && particle != ProtonP) { 558 BuildPhysicsTable(particle); 558 BuildPhysicsTable(particle); 559 } 559 } 560 } 560 } 561 561 562 // Set flag 562 // Set flag 563 fIsPhysicsTableBuilt = true; 563 fIsPhysicsTableBuilt = true; 564 } 564 } 565 565 566 // ------------------------------------------- 566 // -------------------------------------------------------------------- 567 void G4VUserPhysicsList::BuildPhysicsTable(G4P 567 void G4VUserPhysicsList::BuildPhysicsTable(G4ParticleDefinition* particle) 568 { 568 { 569 if (auto* trackingManager = particle->GetTra 569 if (auto* trackingManager = particle->GetTrackingManager()) { 570 #ifdef G4VERBOSE 570 #ifdef G4VERBOSE 571 if (verboseLevel > 2) { 571 if (verboseLevel > 2) { 572 G4cout << "G4VUserPhysicsList::BuildPhys 572 G4cout << "G4VUserPhysicsList::BuildPhysicsTable " 573 << "Calculate Physics Table for " 573 << "Calculate Physics Table for " << particle->GetParticleName() 574 << " via custom TrackingManager" 574 << " via custom TrackingManager" << G4endl; 575 } 575 } 576 #endif 576 #endif 577 trackingManager->BuildPhysicsTable(*partic 577 trackingManager->BuildPhysicsTable(*particle); 578 return; 578 return; 579 } 579 } 580 580 581 // Change in order to share physics tables f 581 // Change in order to share physics tables for two kind of process. 582 582 583 if (particle->GetMasterProcessManager() == n 583 if (particle->GetMasterProcessManager() == nullptr) { 584 #ifdef G4VERBOSE 584 #ifdef G4VERBOSE 585 if (verboseLevel > 0) { 585 if (verboseLevel > 0) { 586 G4cout << "#### G4VUserPhysicsList::Buil 586 G4cout << "#### G4VUserPhysicsList::BuildPhysicsTable() - BuildPhysicsTable(" 587 << particle->GetParticleName() << 587 << particle->GetParticleName() << ") skipped..." << G4endl; 588 } 588 } 589 #endif 589 #endif 590 return; 590 return; 591 } 591 } 592 if (fRetrievePhysicsTable) { 592 if (fRetrievePhysicsTable) { 593 if (!fIsRestoredCutValues) { 593 if (!fIsRestoredCutValues) { 594 // fail to retrieve cut tables 594 // fail to retrieve cut tables 595 #ifdef G4VERBOSE 595 #ifdef G4VERBOSE 596 if (verboseLevel > 0) { 596 if (verboseLevel > 0) { 597 G4cout << "G4VUserPhysicsList::BuildPh 597 G4cout << "G4VUserPhysicsList::BuildPhysicsTable " 598 << "Physics table can not be re 598 << "Physics table can not be retrieved and will be calculated " << G4endl; 599 } 599 } 600 #endif 600 #endif 601 fRetrievePhysicsTable = false; 601 fRetrievePhysicsTable = false; 602 } 602 } 603 else { 603 else { 604 #ifdef G4VERBOSE 604 #ifdef G4VERBOSE 605 if (verboseLevel > 2) { 605 if (verboseLevel > 2) { 606 G4cout << "G4VUserPhysicsList::BuildPh 606 G4cout << "G4VUserPhysicsList::BuildPhysicsTable " 607 << " Retrieve Physics Table for 607 << " Retrieve Physics Table for " << particle->GetParticleName() << G4endl; 608 } 608 } 609 #endif 609 #endif 610 // Retrieve PhysicsTable from files for 610 // Retrieve PhysicsTable from files for proccesses 611 RetrievePhysicsTable(particle, directory 611 RetrievePhysicsTable(particle, directoryPhysicsTable, fStoredInAscii); 612 } 612 } 613 } 613 } 614 614 615 #ifdef G4VERBOSE 615 #ifdef G4VERBOSE 616 if (verboseLevel > 2) { 616 if (verboseLevel > 2) { 617 G4cout << "G4VUserPhysicsList::BuildPhysic 617 G4cout << "G4VUserPhysicsList::BuildPhysicsTable " 618 << "Calculate Physics Table for " < 618 << "Calculate Physics Table for " << particle->GetParticleName() << G4endl; 619 } 619 } 620 #endif 620 #endif 621 // Rebuild the physics tables for every proc 621 // Rebuild the physics tables for every process for this particle type 622 // if particle is not ShortLived 622 // if particle is not ShortLived 623 if (!particle->IsShortLived()) { 623 if (!particle->IsShortLived()) { 624 G4ProcessManager* pManager = particle->Get 624 G4ProcessManager* pManager = particle->GetProcessManager(); 625 if (pManager == nullptr) { 625 if (pManager == nullptr) { 626 #ifdef G4VERBOSE 626 #ifdef G4VERBOSE 627 if (verboseLevel > 0) { 627 if (verboseLevel > 0) { 628 G4cout << "G4VUserPhysicsList::BuildPh 628 G4cout << "G4VUserPhysicsList::BuildPhysicsTable " 629 << " : No Process Manager for " 629 << " : No Process Manager for " << particle->GetParticleName() << G4endl; 630 G4cout << particle->GetParticleName() 630 G4cout << particle->GetParticleName() << " should be created in your PhysicsList" << G4endl; 631 } 631 } 632 #endif 632 #endif 633 G4Exception("G4VUserPhysicsList::BuildPh 633 G4Exception("G4VUserPhysicsList::BuildPhysicsTable", "Run0271", FatalException, 634 "No process manager"); 634 "No process manager"); 635 return; 635 return; 636 } 636 } 637 637 638 // Get processes from master thread; 638 // Get processes from master thread; 639 G4ProcessManager* pManagerShadow = particl 639 G4ProcessManager* pManagerShadow = particle->GetMasterProcessManager(); 640 640 641 G4ProcessVector* pVector = pManager->GetPr 641 G4ProcessVector* pVector = pManager->GetProcessList(); 642 if (pVector == nullptr) { 642 if (pVector == nullptr) { 643 #ifdef G4VERBOSE 643 #ifdef G4VERBOSE 644 if (verboseLevel > 0) { 644 if (verboseLevel > 0) { 645 G4cout << "G4VUserPhysicsList::BuildPh 645 G4cout << "G4VUserPhysicsList::BuildPhysicsTable " 646 << " : No Process Vector for " 646 << " : No Process Vector for " << particle->GetParticleName() << G4endl; 647 } 647 } 648 #endif 648 #endif 649 G4Exception("G4VUserPhysicsList::BuildPh 649 G4Exception("G4VUserPhysicsList::BuildPhysicsTable", "Run0272", FatalException, 650 "No process Vector"); 650 "No process Vector"); 651 return; 651 return; 652 } 652 } 653 #ifdef G4VERBOSE 653 #ifdef G4VERBOSE 654 if (verboseLevel > 2) { 654 if (verboseLevel > 2) { 655 G4cout << "G4VUserPhysicsList::BuildPhys 655 G4cout << "G4VUserPhysicsList::BuildPhysicsTable %%%%%% " << particle->GetParticleName() 656 << G4endl; 656 << G4endl; 657 G4cout << " ProcessManager : " << pManag 657 G4cout << " ProcessManager : " << pManager << " ProcessManagerShadow : " << pManagerShadow 658 << G4endl; 658 << G4endl; 659 for (G4int iv1 = 0; iv1 < (G4int)pVector 659 for (G4int iv1 = 0; iv1 < (G4int)pVector->size(); ++iv1) { 660 G4cout << " " << iv1 << " - " << (*pV 660 G4cout << " " << iv1 << " - " << (*pVector)[iv1]->GetProcessName() << G4endl; 661 } 661 } 662 G4cout << "----------------------------- 662 G4cout << "--------------------------------------------------------------" << G4endl; 663 G4ProcessVector* pVectorShadow = pManage 663 G4ProcessVector* pVectorShadow = pManagerShadow->GetProcessList(); 664 664 665 for (G4int iv2 = 0; iv2 < (G4int)pVector 665 for (G4int iv2 = 0; iv2 < (G4int)pVectorShadow->size(); ++iv2) { 666 G4cout << " " << iv2 << " - " << (*pV 666 G4cout << " " << iv2 << " - " << (*pVectorShadow)[iv2]->GetProcessName() << G4endl; 667 } 667 } 668 } 668 } 669 #endif 669 #endif 670 for (G4int j = 0; j < (G4int)pVector->size 670 for (G4int j = 0; j < (G4int)pVector->size(); ++j) { 671 // Andrea July 16th 2013 : migration to 671 // Andrea July 16th 2013 : migration to new interface... 672 // Infer if we are in a worker thread or 672 // Infer if we are in a worker thread or master thread 673 // Master thread is the one in which the 673 // Master thread is the one in which the process manager 674 // and process manager shadow pointers a 674 // and process manager shadow pointers are the same 675 if (pManagerShadow == pManager) { 675 if (pManagerShadow == pManager) { 676 (*pVector)[j]->BuildPhysicsTable(*part 676 (*pVector)[j]->BuildPhysicsTable(*particle); 677 } 677 } 678 else { 678 else { 679 (*pVector)[j]->BuildWorkerPhysicsTable 679 (*pVector)[j]->BuildWorkerPhysicsTable(*particle); 680 } 680 } 681 681 682 } // End loop on processes vector 682 } // End loop on processes vector 683 } // End if short-lived 683 } // End if short-lived 684 } 684 } 685 685 686 // ------------------------------------------- 686 // -------------------------------------------------------------------- 687 void G4VUserPhysicsList::PreparePhysicsTable(G 687 void G4VUserPhysicsList::PreparePhysicsTable(G4ParticleDefinition* particle) 688 { 688 { 689 if (auto* trackingManager = particle->GetTra 689 if (auto* trackingManager = particle->GetTrackingManager()) { 690 trackingManager->PreparePhysicsTable(*part 690 trackingManager->PreparePhysicsTable(*particle); 691 return; 691 return; 692 } 692 } 693 693 694 if ((particle->GetMasterProcessManager()) == 694 if ((particle->GetMasterProcessManager()) == nullptr) { 695 return; 695 return; 696 } 696 } 697 // Prepare the physics tables for every proc 697 // Prepare the physics tables for every process for this particle type 698 // if particle is not ShortLived 698 // if particle is not ShortLived 699 if (!particle->IsShortLived()) { 699 if (!particle->IsShortLived()) { 700 G4ProcessManager* pManager = particle->Get 700 G4ProcessManager* pManager = particle->GetProcessManager(); 701 if (pManager == nullptr) { 701 if (pManager == nullptr) { 702 #ifdef G4VERBOSE 702 #ifdef G4VERBOSE 703 if (verboseLevel > 0) { 703 if (verboseLevel > 0) { 704 G4cout << "G4VUserPhysicsList::Prepare 704 G4cout << "G4VUserPhysicsList::PreparePhysicsTable " 705 << ": No Process Manager for " 705 << ": No Process Manager for " << particle->GetParticleName() << G4endl; 706 G4cout << particle->GetParticleName() 706 G4cout << particle->GetParticleName() << " should be created in your PhysicsList" << G4endl; 707 } 707 } 708 #endif 708 #endif 709 G4Exception("G4VUserPhysicsList::Prepare 709 G4Exception("G4VUserPhysicsList::PreparePhysicsTable", "Run0273", FatalException, 710 "No process manager"); 710 "No process manager"); 711 return; 711 return; 712 } 712 } 713 713 714 // Get processes from master thread 714 // Get processes from master thread 715 G4ProcessManager* pManagerShadow = particl 715 G4ProcessManager* pManagerShadow = particle->GetMasterProcessManager(); 716 716 717 G4ProcessVector* pVector = pManager->GetPr 717 G4ProcessVector* pVector = pManager->GetProcessList(); 718 if (pVector == nullptr) { 718 if (pVector == nullptr) { 719 #ifdef G4VERBOSE 719 #ifdef G4VERBOSE 720 if (verboseLevel > 0) { 720 if (verboseLevel > 0) { 721 G4cout << "G4VUserPhysicsList::Prepare 721 G4cout << "G4VUserPhysicsList::PreparePhysicsTable " 722 << ": No Process Vector for " < 722 << ": No Process Vector for " << particle->GetParticleName() << G4endl; 723 } 723 } 724 #endif 724 #endif 725 G4Exception("G4VUserPhysicsList::Prepare 725 G4Exception("G4VUserPhysicsList::PreparePhysicsTable", "Run0274", FatalException, 726 "No process Vector"); 726 "No process Vector"); 727 return; 727 return; 728 } 728 } 729 for (G4int j = 0; j < (G4int)pVector->size 729 for (G4int j = 0; j < (G4int)pVector->size(); ++j) { 730 // Andrea July 16th 2013 : migration to 730 // Andrea July 16th 2013 : migration to new interface... 731 // Infer if we are in a worker thread or 731 // Infer if we are in a worker thread or master thread 732 // Master thread is the one in which the 732 // Master thread is the one in which the process manager 733 // and process manager shadow pointers a 733 // and process manager shadow pointers are the same 734 if (pManagerShadow == pManager) { 734 if (pManagerShadow == pManager) { 735 (*pVector)[j]->PreparePhysicsTable(*pa 735 (*pVector)[j]->PreparePhysicsTable(*particle); 736 } 736 } 737 else { 737 else { 738 (*pVector)[j]->PrepareWorkerPhysicsTab 738 (*pVector)[j]->PrepareWorkerPhysicsTable(*particle); 739 } 739 } 740 } // End loop on processes vector 740 } // End loop on processes vector 741 } // End if pn ShortLived 741 } // End if pn ShortLived 742 } 742 } 743 743 744 // ------------------------------------------- 744 // -------------------------------------------------------------------- 745 void G4VUserPhysicsList::BuildIntegralPhysicsT 745 void G4VUserPhysicsList::BuildIntegralPhysicsTable(G4VProcess* process, 746 746 G4ParticleDefinition* particle) 747 { 747 { 748 // TODO Should we change this function? 748 // TODO Should we change this function? 749 //****************************************** 749 //******************************************************************* 750 // Temporary addition to make the integral s 750 // Temporary addition to make the integral schema of electromagnetic 751 // processes work. 751 // processes work. 752 752 753 if ((process->GetProcessName() == "Imsc") || 753 if ((process->GetProcessName() == "Imsc") || (process->GetProcessName() == "IeIoni") 754 || (process->GetProcessName() == "IeBrem 754 || (process->GetProcessName() == "IeBrems") || (process->GetProcessName() == "Iannihil") 755 || (process->GetProcessName() == "IhIoni 755 || (process->GetProcessName() == "IhIoni") || (process->GetProcessName() == "IMuIoni") 756 || (process->GetProcessName() == "IMuBre 756 || (process->GetProcessName() == "IMuBrems") || (process->GetProcessName() == "IMuPairProd")) 757 { 757 { 758 #ifdef G4VERBOSE 758 #ifdef G4VERBOSE 759 if (verboseLevel > 2) { 759 if (verboseLevel > 2) { 760 G4cout << "G4VUserPhysicsList::BuildInte 760 G4cout << "G4VUserPhysicsList::BuildIntegralPhysicsTable " 761 << " BuildPhysicsTable is invoked 761 << " BuildPhysicsTable is invoked for " << process->GetProcessName() << "(" 762 << particle->GetParticleName() << 762 << particle->GetParticleName() << ")" << G4endl; 763 } 763 } 764 #endif 764 #endif 765 process->BuildPhysicsTable(*particle); 765 process->BuildPhysicsTable(*particle); 766 } 766 } 767 } 767 } 768 768 769 // ------------------------------------------- 769 // -------------------------------------------------------------------- 770 void G4VUserPhysicsList::DumpList() const 770 void G4VUserPhysicsList::DumpList() const 771 { 771 { 772 theParticleIterator->reset(); 772 theParticleIterator->reset(); 773 G4int idx = 0; 773 G4int idx = 0; 774 while ((*theParticleIterator)()) { 774 while ((*theParticleIterator)()) { 775 G4ParticleDefinition* particle = thePartic 775 G4ParticleDefinition* particle = theParticleIterator->value(); 776 G4cout << particle->GetParticleName(); 776 G4cout << particle->GetParticleName(); 777 if ((idx++ % 4) == 3) { 777 if ((idx++ % 4) == 3) { 778 G4cout << G4endl; 778 G4cout << G4endl; 779 } 779 } 780 else { 780 else { 781 G4cout << ", "; 781 G4cout << ", "; 782 } 782 } 783 } 783 } 784 G4cout << G4endl; 784 G4cout << G4endl; 785 } 785 } 786 786 787 // ------------------------------------------- 787 // -------------------------------------------------------------------- 788 void G4VUserPhysicsList::DumpCutValuesTable(G4 788 void G4VUserPhysicsList::DumpCutValuesTable(G4int flag) 789 { 789 { 790 fDisplayThreshold = flag; 790 fDisplayThreshold = flag; 791 } 791 } 792 792 793 // ------------------------------------------- 793 // -------------------------------------------------------------------- 794 void G4VUserPhysicsList::DumpCutValuesTableIfR 794 void G4VUserPhysicsList::DumpCutValuesTableIfRequested() 795 { 795 { 796 if (fDisplayThreshold == 0) return; 796 if (fDisplayThreshold == 0) return; 797 G4ProductionCutsTable::GetProductionCutsTabl 797 G4ProductionCutsTable::GetProductionCutsTable()->DumpCouples(); 798 fDisplayThreshold = 0; 798 fDisplayThreshold = 0; 799 } 799 } 800 800 801 // ------------------------------------------- 801 // -------------------------------------------------------------------- 802 G4bool G4VUserPhysicsList::StorePhysicsTable(c 802 G4bool G4VUserPhysicsList::StorePhysicsTable(const G4String& directory) 803 { 803 { 804 G4bool ascii = fStoredInAscii; 804 G4bool ascii = fStoredInAscii; 805 G4String dir = directory; 805 G4String dir = directory; 806 if (dir.empty()) 806 if (dir.empty()) 807 dir = directoryPhysicsTable; 807 dir = directoryPhysicsTable; 808 else 808 else 809 directoryPhysicsTable = dir; 809 directoryPhysicsTable = dir; 810 810 811 // store CutsTable info 811 // store CutsTable info 812 if (!fCutsTable->StoreCutsTable(dir, ascii)) 812 if (!fCutsTable->StoreCutsTable(dir, ascii)) { 813 G4Exception("G4VUserPhysicsList::StorePhys 813 G4Exception("G4VUserPhysicsList::StorePhysicsTable", "Run0281", JustWarning, 814 "Fail to store Cut Table"); 814 "Fail to store Cut Table"); 815 return false; 815 return false; 816 } 816 } 817 #ifdef G4VERBOSE 817 #ifdef G4VERBOSE 818 if (verboseLevel > 2) { 818 if (verboseLevel > 2) { 819 G4cout << "G4VUserPhysicsList::StorePhysic 819 G4cout << "G4VUserPhysicsList::StorePhysicsTable " 820 << " Store material and cut values 820 << " Store material and cut values successfully" << G4endl; 821 } 821 } 822 #endif 822 #endif 823 823 824 G4bool success = true; 824 G4bool success = true; 825 825 826 // loop over all particles in G4ParticleTabl 826 // loop over all particles in G4ParticleTable 827 theParticleIterator->reset(); 827 theParticleIterator->reset(); 828 while ((*theParticleIterator)()) { 828 while ((*theParticleIterator)()) { 829 G4ParticleDefinition* particle = thePartic 829 G4ParticleDefinition* particle = theParticleIterator->value(); 830 // Store physics tables for every process 830 // Store physics tables for every process for this particle type 831 G4ProcessVector* pVector = (particle->GetP 831 G4ProcessVector* pVector = (particle->GetProcessManager())->GetProcessList(); 832 for (G4int j = 0; j < (G4int)pVector->size 832 for (G4int j = 0; j < (G4int)pVector->size(); ++j) { 833 if (!(*pVector)[j]->StorePhysicsTable(pa 833 if (!(*pVector)[j]->StorePhysicsTable(particle, dir, ascii)) { 834 G4String comment = "Fail to store phys 834 G4String comment = "Fail to store physics table for "; 835 comment += (*pVector)[j]->GetProcessNa 835 comment += (*pVector)[j]->GetProcessName(); 836 comment += "(" + particle->GetParticle 836 comment += "(" + particle->GetParticleName() + ")"; 837 G4Exception("G4VUserPhysicsList::Store 837 G4Exception("G4VUserPhysicsList::StorePhysicsTable", "Run0282", JustWarning, comment); 838 success = false; 838 success = false; 839 } 839 } 840 } 840 } 841 // end loop over processes 841 // end loop over processes 842 } 842 } 843 // end loop over particles 843 // end loop over particles 844 return success; 844 return success; 845 } 845 } 846 846 847 // ------------------------------------------- 847 // -------------------------------------------------------------------- 848 void G4VUserPhysicsList::SetPhysicsTableRetrie 848 void G4VUserPhysicsList::SetPhysicsTableRetrieved(const G4String& directory) 849 { 849 { 850 fRetrievePhysicsTable = true; 850 fRetrievePhysicsTable = true; 851 if (!directory.empty()) { 851 if (!directory.empty()) { 852 directoryPhysicsTable = directory; 852 directoryPhysicsTable = directory; 853 } 853 } 854 fIsCheckedForRetrievePhysicsTable = false; 854 fIsCheckedForRetrievePhysicsTable = false; 855 fIsRestoredCutValues = false; 855 fIsRestoredCutValues = false; 856 } 856 } 857 857 858 // ------------------------------------------- 858 // -------------------------------------------------------------------- 859 void G4VUserPhysicsList::RetrievePhysicsTable( 859 void G4VUserPhysicsList::RetrievePhysicsTable(G4ParticleDefinition* particle, 860 860 const G4String& directory, G4bool ascii) 861 { 861 { 862 G4bool success[100]; 862 G4bool success[100]; 863 // Retrieve physics tables for every process 863 // Retrieve physics tables for every process for this particle type 864 G4ProcessVector* pVector = (particle->GetPro 864 G4ProcessVector* pVector = (particle->GetProcessManager())->GetProcessList(); 865 for (G4int j = 0; j < (G4int)pVector->size() 865 for (G4int j = 0; j < (G4int)pVector->size(); ++j) { 866 success[j] = (*pVector)[j]->RetrievePhysic 866 success[j] = (*pVector)[j]->RetrievePhysicsTable(particle, directory, ascii); 867 867 868 if (!success[j]) { 868 if (!success[j]) { 869 #ifdef G4VERBOSE 869 #ifdef G4VERBOSE 870 if (verboseLevel > 2) { 870 if (verboseLevel > 2) { 871 G4cout << "G4VUserPhysicsList::Retriev 871 G4cout << "G4VUserPhysicsList::RetrievePhysicsTable " 872 << " Fail to retrieve Physics T 872 << " Fail to retrieve Physics Table for " << (*pVector)[j]->GetProcessName() 873 << G4endl; 873 << G4endl; 874 G4cout << "Calculate Physics Table for 874 G4cout << "Calculate Physics Table for " << particle->GetParticleName() << G4endl; 875 } 875 } 876 #endif 876 #endif 877 (*pVector)[j]->BuildPhysicsTable(*partic 877 (*pVector)[j]->BuildPhysicsTable(*particle); 878 } 878 } 879 } 879 } 880 for (G4int j = 0; j < (G4int)pVector->size() 880 for (G4int j = 0; j < (G4int)pVector->size(); ++j) { 881 // temporary addition to make the integral 881 // temporary addition to make the integral schema 882 if (!success[j]) BuildIntegralPhysicsTable 882 if (!success[j]) BuildIntegralPhysicsTable((*pVector)[j], particle); 883 } 883 } 884 } 884 } 885 885 886 // ------------------------------------------- 886 // -------------------------------------------------------------------- 887 void G4VUserPhysicsList::SetApplyCuts(G4bool v 887 void G4VUserPhysicsList::SetApplyCuts(G4bool value, const G4String& name) 888 { 888 { 889 #ifdef G4VERBOSE 889 #ifdef G4VERBOSE 890 if (verboseLevel > 2) { 890 if (verboseLevel > 2) { 891 G4cout << "G4VUserPhysicsList::SetApplyCut 891 G4cout << "G4VUserPhysicsList::SetApplyCuts for " << name << G4endl; 892 } 892 } 893 #endif 893 #endif 894 if (name == "all") { 894 if (name == "all") { 895 theParticleTable->FindParticle("gamma")->S 895 theParticleTable->FindParticle("gamma")->SetApplyCutsFlag(value); 896 theParticleTable->FindParticle("e-")->SetA 896 theParticleTable->FindParticle("e-")->SetApplyCutsFlag(value); 897 theParticleTable->FindParticle("e+")->SetA 897 theParticleTable->FindParticle("e+")->SetApplyCutsFlag(value); 898 theParticleTable->FindParticle("proton")-> 898 theParticleTable->FindParticle("proton")->SetApplyCutsFlag(value); 899 } 899 } 900 else { 900 else { 901 theParticleTable->FindParticle(name)->SetA 901 theParticleTable->FindParticle(name)->SetApplyCutsFlag(value); 902 } 902 } 903 } 903 } 904 904 905 // ------------------------------------------- 905 // -------------------------------------------------------------------- 906 G4bool G4VUserPhysicsList::GetApplyCuts(const 906 G4bool G4VUserPhysicsList::GetApplyCuts(const G4String& name) const 907 { 907 { 908 return theParticleTable->FindParticle(name)- 908 return theParticleTable->FindParticle(name)->GetApplyCutsFlag(); 909 } 909 } 910 910 911 // ------------------------------------------- 911 // -------------------------------------------------------------------- 912 void G4VUserPhysicsList::CheckParticleList() 912 void G4VUserPhysicsList::CheckParticleList() 913 { 913 { 914 if (!fDisableCheckParticleList) { 914 if (!fDisableCheckParticleList) { 915 G4MT_thePLHelper->CheckParticleList(); 915 G4MT_thePLHelper->CheckParticleList(); 916 } 916 } 917 } 917 } 918 918 919 // ------------------------------------------- 919 // -------------------------------------------------------------------- 920 void G4VUserPhysicsList::AddTransportation() 920 void G4VUserPhysicsList::AddTransportation() 921 { 921 { 922 G4MT_thePLHelper->AddTransportation(); 922 G4MT_thePLHelper->AddTransportation(); 923 } 923 } 924 924 925 // ------------------------------------------- 925 // -------------------------------------------------------------------- 926 void G4VUserPhysicsList::UseCoupledTransportat 926 void G4VUserPhysicsList::UseCoupledTransportation(G4bool vl) 927 { 927 { 928 G4MT_thePLHelper->UseCoupledTransportation(v 928 G4MT_thePLHelper->UseCoupledTransportation(vl); 929 } 929 } 930 930 931 // ------------------------------------------- 931 // -------------------------------------------------------------------- 932 G4bool G4VUserPhysicsList::RegisterProcess(G4V 932 G4bool G4VUserPhysicsList::RegisterProcess(G4VProcess* process, G4ParticleDefinition* particle) 933 { 933 { 934 return G4MT_thePLHelper->RegisterProcess(pro 934 return G4MT_thePLHelper->RegisterProcess(process, particle); 935 } 935 } 936 936 937 // ------------------------------------------- 937 // -------------------------------------------------------------------- 938 G4ParticleTable::G4PTblDicIterator* G4VUserPhy 938 G4ParticleTable::G4PTblDicIterator* G4VUserPhysicsList::GetParticleIterator() const 939 { 939 { 940 return (subInstanceManager.offset[g4vuplInst 940 return (subInstanceManager.offset[g4vuplInstanceID])._theParticleIterator; 941 } 941 } 942 942 943 // ------------------------------------------- 943 // -------------------------------------------------------------------- 944 void G4VUserPhysicsList::SetVerboseLevel(G4int 944 void G4VUserPhysicsList::SetVerboseLevel(G4int value) 945 { 945 { 946 verboseLevel = value; 946 verboseLevel = value; 947 // set verboseLevel for G4ProductionCutsTabl 947 // set verboseLevel for G4ProductionCutsTable same as one for 948 // G4VUserPhysicsList: 948 // G4VUserPhysicsList: 949 fCutsTable->SetVerboseLevel(verboseLevel); 949 fCutsTable->SetVerboseLevel(verboseLevel); 950 950 951 G4MT_thePLHelper->SetVerboseLevel(verboseLev 951 G4MT_thePLHelper->SetVerboseLevel(verboseLevel); 952 952 953 #ifdef G4VERBOSE 953 #ifdef G4VERBOSE 954 if (verboseLevel > 1) { 954 if (verboseLevel > 1) { 955 G4cout << "G4VUserPhysicsList::SetVerboseL 955 G4cout << "G4VUserPhysicsList::SetVerboseLevel :" 956 << " Verbose level is set to " << v 956 << " Verbose level is set to " << verboseLevel << G4endl; 957 } 957 } 958 #endif 958 #endif 959 } 959 } 960 960