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