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