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