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 // $Id: G4GlobalFastSimulationManager.cc,v 1.20 2007/05/11 13:50:20 mverderi Exp $ >> 28 // GEANT4 tag $Name: geant4-09-02-patch-03 $ 27 // 29 // 28 // << 30 // 29 //-------------------------------------------- 31 //--------------------------------------------------------------- 30 // 32 // 31 // G4GlobalFastSimulationManager.cc 33 // G4GlobalFastSimulationManager.cc 32 // 34 // 33 // Description: 35 // Description: 34 // A singleton class which manages the Fast << 36 // A singleton class which manages the Fast Simulation managers 35 // attached to envelopes. Implementation. 37 // attached to envelopes. Implementation. 36 // 38 // 37 // History: 39 // History: 38 // June 98: Verderi && MoraDeFreitas - "G4P 40 // June 98: Verderi && MoraDeFreitas - "G4ParallelWorld" becomes 39 // "G4FlavoredParallelWorld"; some 41 // "G4FlavoredParallelWorld"; some method name changes; 40 // GetFlavoredWorldForThis now ret << 42 // GetFlavoredWorldForThis now returns a 41 // G4FlavoredParallelWorld pointer 43 // G4FlavoredParallelWorld pointer. 42 // Feb 98: Verderi && MoraDeFreitas - First 44 // Feb 98: Verderi && MoraDeFreitas - First Implementation. 43 // March 98: correction to instanciate dyna 45 // March 98: correction to instanciate dynamically the manager 44 // May 07: Move to parallel world scheme 46 // May 07: Move to parallel world scheme 45 // 47 // 46 //-------------------------------------------- 48 //--------------------------------------------------------------- 47 49 48 #include "G4GlobalFastSimulationManager.hh" 50 #include "G4GlobalFastSimulationManager.hh" 49 << 50 #include "G4FastSimulationMessenger.hh" << 51 #include "G4Material.hh" << 52 #include "G4PVPlacement.hh" << 53 #include "G4ParticleDefinition.hh" << 54 #include "G4ParticleTable.hh" 51 #include "G4ParticleTable.hh" 55 #include "G4PhysicalVolumeStore.hh" << 52 #include "G4ParticleDefinition.hh" 56 #include "G4ProcessManager.hh" << 53 #include "G4Material.hh" 57 #include "G4ProcessVector.hh" << 58 #include "G4RegionStore.hh" << 59 #include "G4ThreadLocalSingleton.hh" << 60 #include "G4ThreeVector.hh" 54 #include "G4ThreeVector.hh" >> 55 #include "G4PVPlacement.hh" 61 #include "G4TransportationManager.hh" 56 #include "G4TransportationManager.hh" >> 57 #include "G4FastSimulationMessenger.hh" >> 58 #include "G4RegionStore.hh" >> 59 #include "G4ProcessVector.hh" >> 60 #include "G4ProcessManager.hh" >> 61 #include "G4PhysicalVolumeStore.hh" >> 62 >> 63 >> 64 // ------------------------------------------ >> 65 // -- static instance pointer initialisation: >> 66 // ------------------------------------------ >> 67 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::fGlobalFastSimulationManager = 0; 62 68 63 // ------------------------------------------- 69 // -------------------------------------------------- 64 // -- static methods to retrieve the manager p 70 // -- static methods to retrieve the manager pointer: 65 // ------------------------------------------- 71 // -------------------------------------------------- 66 G4GlobalFastSimulationManager* G4GlobalFastSim 72 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::GetGlobalFastSimulationManager() 67 { 73 { 68 static G4ThreadLocalSingleton<G4GlobalFastSi << 74 if(!fGlobalFastSimulationManager) 69 return instance.Instance(); << 75 fGlobalFastSimulationManager = new G4GlobalFastSimulationManager; >> 76 >> 77 return fGlobalFastSimulationManager; 70 } 78 } 71 79 >> 80 72 G4GlobalFastSimulationManager* G4GlobalFastSim 81 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::GetInstance() 73 { 82 { 74 return G4GlobalFastSimulationManager::GetGlo 83 return G4GlobalFastSimulationManager::GetGlobalFastSimulationManager(); 75 } 84 } 76 85 77 // --------------- 86 // --------------- 78 // -- constructor 87 // -- constructor 79 // --------------- 88 // --------------- 80 G4GlobalFastSimulationManager::G4GlobalFastSim 89 G4GlobalFastSimulationManager::G4GlobalFastSimulationManager() 81 { 90 { 82 fTheFastSimulationMessenger = new G4FastSimu 91 fTheFastSimulationMessenger = new G4FastSimulationMessenger(this); 83 } 92 } 84 93 85 // ------------- 94 // ------------- 86 // -- destructor 95 // -- destructor 87 // ------------- 96 // ------------- 88 G4GlobalFastSimulationManager::~G4GlobalFastSi 97 G4GlobalFastSimulationManager::~G4GlobalFastSimulationManager() 89 { 98 { 90 delete fTheFastSimulationMessenger; 99 delete fTheFastSimulationMessenger; >> 100 fTheFastSimulationMessenger = 0; 91 } 101 } 92 102 93 // ---------------------- 103 // ---------------------- 94 // -- management methods: 104 // -- management methods: 95 // ---------------------- 105 // ---------------------- 96 void G4GlobalFastSimulationManager::AddFastSim << 106 void G4GlobalFastSimulationManager:: >> 107 AddFastSimulationManager(G4FastSimulationManager* fsmanager) 97 { 108 { 98 ManagedManagers.push_back(fsmanager); 109 ManagedManagers.push_back(fsmanager); 99 } 110 } 100 111 101 void G4GlobalFastSimulationManager::RemoveFast << 112 void G4GlobalFastSimulationManager:: >> 113 RemoveFastSimulationManager(G4FastSimulationManager* fsmanager) 102 { 114 { 103 ManagedManagers.remove(fsmanager); 115 ManagedManagers.remove(fsmanager); 104 } 116 } 105 117 106 void G4GlobalFastSimulationManager::AddFSMP(G4 118 void G4GlobalFastSimulationManager::AddFSMP(G4FastSimulationManagerProcess* fp) 107 { 119 { 108 fFSMPVector.push_back(fp); 120 fFSMPVector.push_back(fp); 109 } 121 } 110 122 111 void G4GlobalFastSimulationManager::RemoveFSMP 123 void G4GlobalFastSimulationManager::RemoveFSMP(G4FastSimulationManagerProcess* fp) 112 { 124 { 113 fFSMPVector.remove(fp); 125 fFSMPVector.remove(fp); 114 } 126 } 115 127 116 void G4GlobalFastSimulationManager::ActivateFa 128 void G4GlobalFastSimulationManager::ActivateFastSimulationModel(const G4String& aName) 117 { 129 { 118 G4bool result = false; 130 G4bool result = false; 119 for (auto& ManagedManager : ManagedManagers) << 131 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 120 result = result || ManagedManager->Activat << 132 result = result || ManagedManagers[ifsm]-> 121 << 133 ActivateFastSimulationModel(aName); 122 G4cout << "Model " << aName << (result ? " a << 134 if(result) >> 135 G4cout << "Model " << aName << " activated."; >> 136 else >> 137 G4cout << "Model " << aName << " not found."; >> 138 G4cout << G4endl; 123 } 139 } 124 140 125 void G4GlobalFastSimulationManager::InActivate 141 void G4GlobalFastSimulationManager::InActivateFastSimulationModel(const G4String& aName) 126 { 142 { 127 G4bool result = false; 143 G4bool result = false; 128 for (auto& ManagedManager : ManagedManagers) << 144 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 129 result = result || ManagedManager->InActiv << 145 result = result || ManagedManagers[ifsm]-> 130 << 146 InActivateFastSimulationModel(aName); 131 G4cout << "Model " << aName << (result ? " i << 147 if(result) >> 148 G4cout << "Model " << aName << " inactivated."; >> 149 else >> 150 G4cout << "Model " << aName << " not found."; >> 151 G4cout << G4endl; 132 } 152 } 133 153 134 void G4GlobalFastSimulationManager::Flush() << 135 { << 136 // loop over all models (that need flushing? << 137 for (auto& ManagedManager : ManagedManagers) << 138 ManagedManager->FlushModels(); << 139 } << 140 154 141 // --------------------------------- 155 // --------------------------------- 142 // -- display fast simulation setup: 156 // -- display fast simulation setup: 143 // --------------------------------- 157 // --------------------------------- 144 void G4GlobalFastSimulationManager::ShowSetup( 158 void G4GlobalFastSimulationManager::ShowSetup() 145 { 159 { 146 std::vector<G4VPhysicalVolume*> worldDone; 160 std::vector<G4VPhysicalVolume*> worldDone; 147 G4VPhysicalVolume* world; 161 G4VPhysicalVolume* world; 148 G4RegionStore* regions = G4RegionStore::GetI 162 G4RegionStore* regions = G4RegionStore::GetInstance(); 149 // ----------------------------------------- 163 // ---------------------------------------------------- 150 // -- loop on regions to get the list of wor 164 // -- loop on regions to get the list of world volumes: 151 // ----------------------------------------- 165 // ---------------------------------------------------- 152 G4cout << "\nFast simulation setup:" << G4en 166 G4cout << "\nFast simulation setup:" << G4endl; 153 for (auto& region : *regions) { << 167 for (size_t i=0; i<regions->size(); i++) 154 world = region->GetWorldPhysical(); << 155 if (world == nullptr) // region does not << 156 { 168 { 157 continue; << 169 world = (*regions)[i]->GetWorldPhysical(); >> 170 G4bool newWorld = true; >> 171 for (size_t ii=0; ii<worldDone.size(); ii++) if (worldDone[ii] == world) {newWorld = false; break;} >> 172 if (newWorld) >> 173 { >> 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 } 158 } 205 } 159 G4bool newWorld = true; << 160 for (auto& ii : worldDone) << 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 } << 198 if (!findG4FSMP) G4cout << " o G4 << 199 // -- now display the regions in this wo << 200 // indentation: << 201 G4cout << " o Region(s) and model << 202 DisplayRegion(worldRegion, 1, particlesK << 203 } << 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++) 260 return; << 265 ManagedManagers[ifsm]->ListModels(aName); 261 } << 266 return; 262 << 267 } 263 if (aName == "all") { << 268 264 G4int titled = 0; << 269 if(aName == "all") 265 for (auto& ManagedManager : ManagedManager << 270 { 266 if (theType == NAMES_ONLY) { << 271 G4int titled = 0; 267 if ((titled++) == 0) G4cout << "Curren << 272 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 268 G4cout << " "; << 273 { 269 ManagedManager->ListTitle(); << 274 if(theType == NAMES_ONLY) 270 G4cout << G4endl; << 275 { 271 } << 276 if(!(titled++)) 272 else << 277 G4cout << "Current Envelopes for Fast Simulation:\n"; 273 ManagedManager->ListModels(); << 278 G4cout << " "; >> 279 ManagedManagers[ifsm]->ListTitle(); >> 280 G4cout << G4endl; >> 281 } >> 282 else ManagedManagers[ifsm]->ListModels(); >> 283 } >> 284 } >> 285 else >> 286 { >> 287 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) >> 288 if(aName == ManagedManagers[ifsm]-> GetEnvelope()->GetName()) >> 289 { >> 290 ManagedManagers[ifsm]->ListModels(); >> 291 break; >> 292 } 274 } 293 } 275 } << 276 else { << 277 for (auto& ManagedManager : ManagedManager << 278 if (aName == ManagedManager->GetEnvelope << 279 ManagedManager->ListModels(); << 280 break; << 281 } << 282 } << 283 } 294 } 284 295 285 void G4GlobalFastSimulationManager::ListEnvelo 296 void G4GlobalFastSimulationManager::ListEnvelopes(const G4ParticleDefinition* aPD) 286 { 297 { 287 for (auto& ManagedManager : ManagedManagers) << 298 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 288 ManagedManager->ListModels(aPD); << 299 ManagedManagers[ifsm]->ListModels(aPD); 289 } 300 } 290 301 291 G4VFastSimulationModel* G4GlobalFastSimulation << 302 292 const G4String& modelName, const G4VFastSimu << 303 G4VFastSimulationModel* G4GlobalFastSimulationManager::GetFastSimulationModel(const G4String& modelName, >> 304 const G4VFastSimulationModel* previousFound) const 293 { 305 { 294 G4VFastSimulationModel* model = nullptr; << 306 G4VFastSimulationModel* model = 0; 295 // -- flag used to navigate accross the vari 307 // -- flag used to navigate accross the various managers; 296 bool foundPrevious(false); 308 bool foundPrevious(false); 297 for (auto ManagedManager : ManagedManagers) << 309 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 298 model = ManagedManager->GetFastSimulationM << 310 { 299 if (model != nullptr) break; << 311 model = ManagedManagers[ifsm]-> 300 } << 312 GetFastSimulationModel(modelName, previousFound, foundPrevious); >> 313 if (model) break; >> 314 } 301 return model; 315 return model; 302 } 316 } 303 317