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