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 // 26 // 27 // 27 // 28 // << 28 // 29 //-------------------------------------------- 29 //--------------------------------------------------------------- 30 // 30 // 31 // G4GlobalFastSimulationManager.cc 31 // G4GlobalFastSimulationManager.cc 32 // 32 // 33 // Description: 33 // Description: 34 // A singleton class which manages the Fast << 34 // A singleton class which manages the Fast Simulation managers 35 // attached to envelopes. Implementation. 35 // attached to envelopes. Implementation. 36 // 36 // 37 // History: 37 // History: 38 // June 98: Verderi && MoraDeFreitas - "G4P 38 // June 98: Verderi && MoraDeFreitas - "G4ParallelWorld" becomes 39 // "G4FlavoredParallelWorld"; some 39 // "G4FlavoredParallelWorld"; some method name changes; 40 // GetFlavoredWorldForThis now ret << 40 // GetFlavoredWorldForThis now returns a 41 // G4FlavoredParallelWorld pointer 41 // G4FlavoredParallelWorld pointer. 42 // Feb 98: Verderi && MoraDeFreitas - First 42 // Feb 98: Verderi && MoraDeFreitas - First Implementation. 43 // March 98: correction to instanciate dyna 43 // March 98: correction to instanciate dynamically the manager 44 // May 07: Move to parallel world scheme 44 // May 07: Move to parallel world scheme 45 // 45 // 46 //-------------------------------------------- 46 //--------------------------------------------------------------- 47 47 48 #include "G4GlobalFastSimulationManager.hh" 48 #include "G4GlobalFastSimulationManager.hh" 49 << 50 #include "G4FastSimulationMessenger.hh" << 51 #include "G4Material.hh" << 52 #include "G4PVPlacement.hh" << 53 #include "G4ParticleDefinition.hh" << 54 #include "G4ParticleTable.hh" 49 #include "G4ParticleTable.hh" 55 #include "G4PhysicalVolumeStore.hh" << 50 #include "G4ParticleDefinition.hh" 56 #include "G4ProcessManager.hh" << 51 #include "G4Material.hh" 57 #include "G4ProcessVector.hh" << 58 #include "G4RegionStore.hh" << 59 #include "G4ThreadLocalSingleton.hh" << 60 #include "G4ThreeVector.hh" 52 #include "G4ThreeVector.hh" >> 53 #include "G4PVPlacement.hh" 61 #include "G4TransportationManager.hh" 54 #include "G4TransportationManager.hh" >> 55 #include "G4FastSimulationMessenger.hh" >> 56 #include "G4RegionStore.hh" >> 57 #include "G4ProcessVector.hh" >> 58 #include "G4ProcessManager.hh" >> 59 #include "G4PhysicalVolumeStore.hh" >> 60 >> 61 >> 62 // ------------------------------------------ >> 63 // -- static instance pointer initialisation: >> 64 // ------------------------------------------ >> 65 G4ThreadLocal G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::fGlobalFastSimulationManager = 0; 62 66 63 // ------------------------------------------- 67 // -------------------------------------------------- 64 // -- static methods to retrieve the manager p 68 // -- static methods to retrieve the manager pointer: 65 // ------------------------------------------- 69 // -------------------------------------------------- 66 G4GlobalFastSimulationManager* G4GlobalFastSim 70 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::GetGlobalFastSimulationManager() 67 { 71 { 68 static G4ThreadLocalSingleton<G4GlobalFastSi << 72 if(!fGlobalFastSimulationManager) 69 return instance.Instance(); << 73 fGlobalFastSimulationManager = new G4GlobalFastSimulationManager; >> 74 >> 75 return fGlobalFastSimulationManager; 70 } 76 } 71 77 >> 78 72 G4GlobalFastSimulationManager* G4GlobalFastSim 79 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::GetInstance() 73 { 80 { 74 return G4GlobalFastSimulationManager::GetGlo 81 return G4GlobalFastSimulationManager::GetGlobalFastSimulationManager(); 75 } 82 } 76 83 77 // --------------- 84 // --------------- 78 // -- constructor 85 // -- constructor 79 // --------------- 86 // --------------- 80 G4GlobalFastSimulationManager::G4GlobalFastSim 87 G4GlobalFastSimulationManager::G4GlobalFastSimulationManager() 81 { 88 { 82 fTheFastSimulationMessenger = new G4FastSimu 89 fTheFastSimulationMessenger = new G4FastSimulationMessenger(this); 83 } 90 } 84 91 85 // ------------- 92 // ------------- 86 // -- destructor 93 // -- destructor 87 // ------------- 94 // ------------- 88 G4GlobalFastSimulationManager::~G4GlobalFastSi 95 G4GlobalFastSimulationManager::~G4GlobalFastSimulationManager() 89 { 96 { 90 delete fTheFastSimulationMessenger; 97 delete fTheFastSimulationMessenger; >> 98 fTheFastSimulationMessenger = 0; 91 } 99 } 92 100 93 // ---------------------- 101 // ---------------------- 94 // -- management methods: 102 // -- management methods: 95 // ---------------------- 103 // ---------------------- 96 void G4GlobalFastSimulationManager::AddFastSim << 104 void G4GlobalFastSimulationManager:: >> 105 AddFastSimulationManager(G4FastSimulationManager* fsmanager) 97 { 106 { 98 ManagedManagers.push_back(fsmanager); 107 ManagedManagers.push_back(fsmanager); 99 } 108 } 100 109 101 void G4GlobalFastSimulationManager::RemoveFast << 110 void G4GlobalFastSimulationManager:: >> 111 RemoveFastSimulationManager(G4FastSimulationManager* fsmanager) 102 { 112 { 103 ManagedManagers.remove(fsmanager); 113 ManagedManagers.remove(fsmanager); 104 } 114 } 105 115 106 void G4GlobalFastSimulationManager::AddFSMP(G4 116 void G4GlobalFastSimulationManager::AddFSMP(G4FastSimulationManagerProcess* fp) 107 { 117 { 108 fFSMPVector.push_back(fp); 118 fFSMPVector.push_back(fp); 109 } 119 } 110 120 111 void G4GlobalFastSimulationManager::RemoveFSMP 121 void G4GlobalFastSimulationManager::RemoveFSMP(G4FastSimulationManagerProcess* fp) 112 { 122 { 113 fFSMPVector.remove(fp); 123 fFSMPVector.remove(fp); 114 } 124 } 115 125 116 void G4GlobalFastSimulationManager::ActivateFa 126 void G4GlobalFastSimulationManager::ActivateFastSimulationModel(const G4String& aName) 117 { 127 { 118 G4bool result = false; 128 G4bool result = false; 119 for (auto& ManagedManager : ManagedManagers) << 129 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 120 result = result || ManagedManager->Activat << 130 result = result || ManagedManagers[ifsm]-> 121 << 131 ActivateFastSimulationModel(aName); 122 G4cout << "Model " << aName << (result ? " a << 132 if(result) >> 133 G4cout << "Model " << aName << " activated."; >> 134 else >> 135 G4cout << "Model " << aName << " not found."; >> 136 G4cout << G4endl; 123 } 137 } 124 138 125 void G4GlobalFastSimulationManager::InActivate 139 void G4GlobalFastSimulationManager::InActivateFastSimulationModel(const G4String& aName) 126 { 140 { 127 G4bool result = false; 141 G4bool result = false; 128 for (auto& ManagedManager : ManagedManagers) << 142 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 129 result = result || ManagedManager->InActiv << 143 result = result || ManagedManagers[ifsm]-> 130 << 144 InActivateFastSimulationModel(aName); 131 G4cout << "Model " << aName << (result ? " i << 145 if (result) G4cout << "Model " << aName << " inactivated."; >> 146 else G4cout << "Model " << aName << " not found."; >> 147 G4cout << G4endl; 132 } 148 } 133 149 134 void G4GlobalFastSimulationManager::Flush() << 135 { << 136 // loop over all models (that need flushing? << 137 for (auto& ManagedManager : ManagedManagers) << 138 ManagedManager->FlushModels(); << 139 } << 140 150 141 // --------------------------------- 151 // --------------------------------- 142 // -- display fast simulation setup: 152 // -- display fast simulation setup: 143 // --------------------------------- 153 // --------------------------------- 144 void G4GlobalFastSimulationManager::ShowSetup( 154 void G4GlobalFastSimulationManager::ShowSetup() 145 { 155 { 146 std::vector<G4VPhysicalVolume*> worldDone; 156 std::vector<G4VPhysicalVolume*> worldDone; 147 G4VPhysicalVolume* world; 157 G4VPhysicalVolume* world; 148 G4RegionStore* regions = G4RegionStore::GetI 158 G4RegionStore* regions = G4RegionStore::GetInstance(); 149 // ----------------------------------------- 159 // ---------------------------------------------------- 150 // -- loop on regions to get the list of wor 160 // -- loop on regions to get the list of world volumes: 151 // ----------------------------------------- 161 // ---------------------------------------------------- 152 G4cout << "\nFast simulation setup:" << G4en 162 G4cout << "\nFast simulation setup:" << G4endl; 153 for (auto& region : *regions) { << 163 for (size_t i=0; i<regions->size(); i++) 154 world = region->GetWorldPhysical(); << 155 if (world == nullptr) // region does not << 156 { 164 { 157 continue; << 165 world = (*regions)[i]->GetWorldPhysical(); 158 } << 166 if (world == nullptr) // region does not belong to any (existing) world 159 G4bool newWorld = true; << 167 { 160 for (auto& ii : worldDone) << 168 continue; 161 if (ii == world) { << 162 newWorld = false; << 163 break; << 164 } << 165 if (newWorld) { << 166 worldDone.push_back(world); << 167 G4Region* worldRegion = world->GetLogica << 168 // -- preambule: print physical volume a << 169 if (world << 170 == G4TransportationManager::GetTrans << 171 ->GetNavigatorForTracking() << 172 ->GetWorldVolume()) << 173 G4cout << "\n * Mass Geometry with << 174 else << 175 G4cout << "\n * Parallel Geometry w << 176 G4cout << "world volume: `" << world->Ge << 177 << "']" << G4endl; << 178 // -- ... and print G4FSMP(s) attached t << 179 G4bool findG4FSMP(false); << 180 // -- show to what particles this G4FSMP << 181 std::vector<G4ParticleDefinition*> parti << 182 for (auto& ip : fFSMPVector) << 183 if (ip->GetWorldVolume() == world) { << 184 G4cout << " o G4FastSimulatio << 185 G4cout << " Att << 186 G4ParticleTable* particles = G4Parti << 187 for (G4int iParticle = 0; iParticle << 188 G4ParticleDefinition* particle = p << 189 G4ProcessVector* processes = parti << 190 if (processes->contains(ip)) { << 191 G4cout << " " << particle->GetPa << 192 findG4FSMP = true; << 193 particlesKnown.push_back(particl << 194 } << 195 } << 196 G4cout << G4endl; << 197 } 169 } 198 if (!findG4FSMP) G4cout << " o G4 << 170 G4bool newWorld = true; 199 // -- now display the regions in this wo << 171 for (size_t ii=0; ii<worldDone.size(); ii++) if (worldDone[ii] == world) {newWorld = false; break;} 200 // indentation: << 172 if (newWorld) 201 G4cout << " o Region(s) and model << 173 { 202 DisplayRegion(worldRegion, 1, particlesK << 174 worldDone.push_back(world); >> 175 G4Region* worldRegion = world->GetLogicalVolume()->GetRegion(); >> 176 // -- preambule: print physical volume and region names... >> 177 if (world == G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()) >> 178 G4cout << "\n * Mass Geometry with "; >> 179 else >> 180 G4cout << "\n * Parallel Geometry with "; >> 181 G4cout << "world volume: `" << world->GetName() << "' [region : `" << worldRegion->GetName() << "']" << G4endl; >> 182 // -- ... and print G4FSMP(s) attached to this world volume: >> 183 G4bool findG4FSMP(false); >> 184 // -- show to what particles this G4FSMP is attached to: >> 185 std::vector<G4ParticleDefinition*> particlesKnown; >> 186 for (size_t ip=0; ip<fFSMPVector.size(); ip++) >> 187 if (fFSMPVector[ip]->GetWorldVolume() == world) >> 188 { >> 189 G4cout << " o G4FastSimulationProcess: '" << fFSMPVector[ip]->GetProcessName() << "'" << G4endl; >> 190 G4cout << " Attached to:"; >> 191 G4ParticleTable* particles = G4ParticleTable::GetParticleTable(); >> 192 for (G4int iParticle=0; iParticle<particles->entries(); iParticle++) >> 193 { >> 194 G4ParticleDefinition* particle = particles->GetParticle(iParticle); >> 195 G4ProcessVector* processes = particle->GetProcessManager()->GetProcessList(); >> 196 if (processes->contains(fFSMPVector[ip])) {G4cout << " " << particle->GetParticleName(); findG4FSMP = true; particlesKnown.push_back(particle);} >> 197 } >> 198 G4cout << G4endl; >> 199 } >> 200 if (!findG4FSMP) G4cout << " o G4FastSimulationProcess: (none)" << G4endl; >> 201 // -- now display the regions in this world volume, with mother<->daughter link shown by indentation: >> 202 G4cout << " o Region(s) and model(s) setup:" << G4endl; >> 203 DisplayRegion(worldRegion, 1, particlesKnown); >> 204 } 203 } 205 } 204 } << 205 } 206 } 206 207 207 void G4GlobalFastSimulationManager::DisplayReg << 208 208 G4Region* region, G4int depth, std::vector<G << 209 void G4GlobalFastSimulationManager::DisplayRegion(G4Region* region, G4int depth, std::vector<G4ParticleDefinition*>& particlesKnown) const 209 { 210 { 210 G4String indent = " "; 211 G4String indent = " "; 211 for (G4int I = 0; I < depth; I++) << 212 for (G4int I=0; I<depth; I++) indent += " "; 212 indent += " "; << 213 G4cout << indent << "Region: `" << region->GetName() <<"'" << G4endl; 213 G4cout << indent << "Region: `" << region->G << 214 G4FastSimulationManager* fastSimManager = re 214 G4FastSimulationManager* fastSimManager = region->GetFastSimulationManager(); 215 if (fastSimManager != nullptr) { << 215 if (fastSimManager) 216 indent += " "; << 216 { 217 G4cout << indent << "Model(s):" << G4endl; << 217 indent += " "; 218 indent += " "; << 218 G4cout << indent << "Model(s):" << G4endl; 219 for (auto im : fastSimManager->GetFastSimu << 219 indent += " "; 220 G4cout << indent << "`" << im->GetName() << 220 for (size_t im=0; im<fastSimManager->GetFastSimulationModelList().size(); im++) 221 G4cout << " ; applicable to:"; << 221 { 222 G4ParticleTable* particles = G4ParticleT << 222 G4cout << indent << "`" << (fastSimManager->GetFastSimulationModelList())[im]->GetName() << "'"; 223 for (G4int iParticle = 0; iParticle < pa << 223 G4cout << " ; applicable to:"; 224 if (im->IsApplicable(*(particles->GetP << 224 G4ParticleTable* particles = G4ParticleTable::GetParticleTable(); 225 G4cout << " " << particles->GetParti << 225 for (G4int iParticle=0; iParticle<particles->entries(); iParticle++) 226 G4bool known(false); << 226 { 227 for (auto& l : particlesKnown) << 227 if ((fastSimManager->GetFastSimulationModelList())[im]->IsApplicable(*(particles->GetParticle(iParticle)))) 228 if (l == particles->GetParticle(iP << 228 { 229 known = true; << 229 G4cout << " " << particles->GetParticle(iParticle)->GetParticleName(); 230 break; << 230 G4bool known(false); 231 } << 231 for (size_t l=0; l<particlesKnown.size();l++) if(particlesKnown[l] == particles->GetParticle(iParticle)) {known = true; break;} 232 if (!known) G4cout << "[!!]"; << 232 if (!known) G4cout << "[!!]"; 233 } << 233 } 234 } << 234 } 235 G4cout << G4endl; << 235 G4cout << G4endl; >> 236 } 236 } 237 } 237 } << 238 238 << 239 // -- all that to check mothership of "regio 239 // -- all that to check mothership of "region" 240 G4PhysicalVolumeStore* physVolStore = G4Phys 240 G4PhysicalVolumeStore* physVolStore = G4PhysicalVolumeStore::GetInstance(); 241 for (auto physVol : *physVolStore) { << 241 for (size_t ip=0; ip<physVolStore->size(); ip++) 242 if (physVol->GetLogicalVolume()->IsRootReg << 242 { 243 if (physVol->GetMotherLogical() != nullp << 243 G4VPhysicalVolume* physVol = (*physVolStore)[ip]; 244 G4Region* thisVolMotherRegion = physVo << 244 if (physVol->GetLogicalVolume()->IsRootRegion()) 245 if (thisVolMotherRegion == region) << 245 if (physVol->GetMotherLogical()) 246 DisplayRegion(physVol->GetLogicalVol << 246 { 247 } << 247 G4Region* thisVolMotherRegion = physVol->GetMotherLogical()->GetRegion(); 248 } << 248 if (thisVolMotherRegion == region) >> 249 DisplayRegion(physVol->GetLogicalVolume()->GetRegion(), depth+1, particlesKnown); >> 250 } >> 251 } 249 } 252 } 250 253 >> 254 251 // ---------------------------- 255 // ---------------------------- 252 // -- management methods : list 256 // -- management methods : list 253 // ---------------------------- 257 // ---------------------------- 254 258 255 void G4GlobalFastSimulationManager::ListEnvelo << 259 void G4GlobalFastSimulationManager::ListEnvelopes(const G4String& aName, >> 260 listType theType) 256 { 261 { 257 if (theType == ISAPPLICABLE) { << 262 if (theType == ISAPPLICABLE) 258 for (auto& ManagedManager : ManagedManager << 263 { 259 ManagedManager->ListModels(aName); << 264 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) ManagedManagers[ifsm]->ListModels(aName); 260 return; << 265 return; 261 } << 266 } 262 << 267 263 if (aName == "all") { << 268 if(aName == "all") 264 G4int titled = 0; << 269 { 265 for (auto& ManagedManager : ManagedManager << 270 G4int titled = 0; 266 if (theType == NAMES_ONLY) { << 271 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 267 if ((titled++) == 0) G4cout << "Curren << 272 { 268 G4cout << " "; << 273 if(theType == NAMES_ONLY) 269 ManagedManager->ListTitle(); << 274 { 270 G4cout << G4endl; << 275 if(!(titled++)) 271 } << 276 G4cout << "Current Envelopes for Fast Simulation:\n"; 272 else << 277 G4cout << " "; 273 ManagedManager->ListModels(); << 278 ManagedManagers[ifsm]->ListTitle(); >> 279 G4cout << G4endl; >> 280 } >> 281 else ManagedManagers[ifsm]->ListModels(); >> 282 } >> 283 } >> 284 else >> 285 { >> 286 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) >> 287 if(aName == ManagedManagers[ifsm]-> GetEnvelope()->GetName()) >> 288 { >> 289 ManagedManagers[ifsm]->ListModels(); >> 290 break; >> 291 } 274 } 292 } 275 } << 276 else { << 277 for (auto& ManagedManager : ManagedManager << 278 if (aName == ManagedManager->GetEnvelope << 279 ManagedManager->ListModels(); << 280 break; << 281 } << 282 } << 283 } 293 } 284 294 285 void G4GlobalFastSimulationManager::ListEnvelo 295 void G4GlobalFastSimulationManager::ListEnvelopes(const G4ParticleDefinition* aPD) 286 { 296 { 287 for (auto& ManagedManager : ManagedManagers) << 297 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 288 ManagedManager->ListModels(aPD); << 298 ManagedManagers[ifsm]->ListModels(aPD); 289 } 299 } 290 300 291 G4VFastSimulationModel* G4GlobalFastSimulation << 301 292 const G4String& modelName, const G4VFastSimu << 302 G4VFastSimulationModel* G4GlobalFastSimulationManager::GetFastSimulationModel(const G4String& modelName, >> 303 const G4VFastSimulationModel* previousFound) const 293 { 304 { 294 G4VFastSimulationModel* model = nullptr; << 305 G4VFastSimulationModel* model = 0; 295 // -- flag used to navigate accross the vari 306 // -- flag used to navigate accross the various managers; 296 bool foundPrevious(false); 307 bool foundPrevious(false); 297 for (auto ManagedManager : ManagedManagers) << 308 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 298 model = ManagedManager->GetFastSimulationM << 309 { 299 if (model != nullptr) break; << 310 model = ManagedManagers[ifsm]-> 300 } << 311 GetFastSimulationModel(modelName, previousFound, foundPrevious); >> 312 if (model) break; >> 313 } 301 return model; 314 return model; 302 } 315 } 303 316