Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G4GlobalFastSimulationManager.cc,v 1.8 2001/10/26 14:43:37 mverderi Exp $ >> 25 // GEANT4 tag $Name: geant4-04-00 $ 27 // 26 // 28 // << 27 // 29 //-------------------------------------------- 28 //--------------------------------------------------------------- 30 // 29 // 31 // G4GlobalFastSimulationManager.cc 30 // G4GlobalFastSimulationManager.cc 32 // 31 // 33 // Description: 32 // Description: 34 // A singleton class which manages the Fast << 33 // A singleton class which manages the Fast Simulation managers 35 // attached to envelopes. Implementation. 34 // attached to envelopes. Implementation. 36 // 35 // 37 // History: 36 // History: 38 // June 98: Verderi && MoraDeFreitas - "G4P 37 // June 98: Verderi && MoraDeFreitas - "G4ParallelWorld" becomes 39 // "G4FlavoredParallelWorld"; some 38 // "G4FlavoredParallelWorld"; some method name changes; 40 // GetFlavoredWorldForThis now ret << 39 // GetFlavoredWorldForThis now returns a 41 // G4FlavoredParallelWorld pointer 40 // G4FlavoredParallelWorld pointer. 42 // Feb 98: Verderi && MoraDeFreitas - First 41 // Feb 98: Verderi && MoraDeFreitas - First Implementation. 43 // March 98: correction to instanciate dyna 42 // March 98: correction to instanciate dynamically the manager 44 // May 07: Move to parallel world scheme << 45 // 43 // 46 //-------------------------------------------- 44 //--------------------------------------------------------------- 47 45 48 #include "G4GlobalFastSimulationManager.hh" 46 #include "G4GlobalFastSimulationManager.hh" 49 << 50 #include "G4FastSimulationMessenger.hh" << 51 #include "G4Material.hh" << 52 #include "G4PVPlacement.hh" << 53 #include "G4ParticleDefinition.hh" << 54 #include "G4ParticleTable.hh" 47 #include "G4ParticleTable.hh" 55 #include "G4PhysicalVolumeStore.hh" << 48 #include "G4ParticleDefinition.hh" 56 #include "G4ProcessManager.hh" << 49 #include "G4Material.hh" 57 #include "G4ProcessVector.hh" << 58 #include "G4RegionStore.hh" << 59 #include "G4ThreadLocalSingleton.hh" << 60 #include "G4ThreeVector.hh" 50 #include "G4ThreeVector.hh" >> 51 #include "G4PVPlacement.hh" 61 #include "G4TransportationManager.hh" 52 #include "G4TransportationManager.hh" >> 53 #include "G4FastSimulationMessenger.hh" >> 54 >> 55 G4GlobalFastSimulationManager* >> 56 G4GlobalFastSimulationManager::fGlobalFastSimulationManager = 0; 62 57 63 // ------------------------------------------- << 64 // -- static methods to retrieve the manager p << 65 // ------------------------------------------- << 66 G4GlobalFastSimulationManager* G4GlobalFastSim << 67 { << 68 static G4ThreadLocalSingleton<G4GlobalFastSi << 69 return instance.Instance(); << 70 } << 71 58 72 G4GlobalFastSimulationManager* G4GlobalFastSim << 59 G4GlobalFastSimulationManager* >> 60 G4GlobalFastSimulationManager::GetGlobalFastSimulationManager() 73 { 61 { 74 return G4GlobalFastSimulationManager::GetGlo << 62 if(!fGlobalFastSimulationManager) >> 63 { >> 64 fGlobalFastSimulationManager = new G4GlobalFastSimulationManager; >> 65 fpConcreteInstance = fGlobalFastSimulationManager; >> 66 } >> 67 return fGlobalFastSimulationManager; 75 } 68 } 76 69 77 // --------------- << 70 78 // -- constructor << 79 // --------------- << 80 G4GlobalFastSimulationManager::G4GlobalFastSim 71 G4GlobalFastSimulationManager::G4GlobalFastSimulationManager() 81 { 72 { 82 fTheFastSimulationMessenger = new G4FastSimu << 73 // It starts closed. >> 74 fClosed=true; >> 75 // Initialises the G4FastSimulationMessenger >> 76 fTheFastSimulationMessenger=new G4FastSimulationMessenger(this); 83 } 77 } 84 78 85 // ------------- << 86 // -- destructor << 87 // ------------- << 88 G4GlobalFastSimulationManager::~G4GlobalFastSi 79 G4GlobalFastSimulationManager::~G4GlobalFastSimulationManager() 89 { 80 { 90 delete fTheFastSimulationMessenger; 81 delete fTheFastSimulationMessenger; >> 82 fTheFastSimulationMessenger = 0; 91 } 83 } 92 84 93 // ---------------------- << 85 void G4GlobalFastSimulationManager::FastSimulationNeedsToBeClosed() 94 // -- management methods: << 95 // ---------------------- << 96 void G4GlobalFastSimulationManager::AddFastSim << 97 { 86 { 98 ManagedManagers.push_back(fsmanager); << 87 fClosed=false; 99 } 88 } 100 89 101 void G4GlobalFastSimulationManager::RemoveFast << 90 void G4GlobalFastSimulationManager:: >> 91 AddFastSimulationManager(G4FastSimulationManager* fsmanager) 102 { 92 { 103 ManagedManagers.remove(fsmanager); << 93 ManagedManagers.push_back(fsmanager); 104 } 94 } 105 95 106 void G4GlobalFastSimulationManager::AddFSMP(G4 << 96 void G4GlobalFastSimulationManager:: >> 97 RemoveFastSimulationManager(G4FastSimulationManager* fsmanager) 107 { 98 { 108 fFSMPVector.push_back(fp); << 99 ManagedManagers.remove(fsmanager); 109 } 100 } 110 101 111 void G4GlobalFastSimulationManager::RemoveFSMP << 112 { << 113 fFSMPVector.remove(fp); << 114 } << 115 102 116 void G4GlobalFastSimulationManager::ActivateFa << 103 void G4GlobalFastSimulationManager::CloseFastSimulation() 117 { 104 { 118 G4bool result = false; << 105 if(fClosed) return; 119 for (auto& ManagedManager : ManagedManagers) << 120 result = result || ManagedManager->Activat << 121 106 122 G4cout << "Model " << aName << (result ? " a << 107 G4ParticleTable* theParticleTable; >> 108 >> 109 // Reset the NeededFlavoredWorlds List >> 110 NeededFlavoredWorlds.clearAndDestroy(); >> 111 >> 112 // We'll look for models for all particle types >> 113 theParticleTable=G4ParticleTable::GetParticleTable(); >> 114 >> 115 // Creates the first world volume clone. >> 116 G4VPhysicalVolume* aClone=GiveMeAWorldVolumeClone(); >> 117 >> 118 G4cout << "Closing FastSimulation\n"; >> 119 for (G4int iParticle=0; iParticle<theParticleTable->entries(); iParticle++) { >> 120 G4bool Needed = false; >> 121 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) >> 122 Needed = Needed || ManagedManagers[ifsm]-> >> 123 InsertGhostHereIfNecessary(aClone, >> 124 *(theParticleTable-> >> 125 GetParticle(iParticle))); >> 126 // if some FSM inserted a ghost, keep this clone. >> 127 if(Needed) { >> 128 NeededFlavoredWorlds.push_back(new >> 129 G4FlavoredParallelWorld(theParticleTable-> >> 130 GetParticle(iParticle), >> 131 aClone)); >> 132 // and prepare a new one. >> 133 aClone=GiveMeAWorldVolumeClone(); >> 134 } >> 135 } >> 136 fClosed=true; 123 } 137 } 124 138 125 void G4GlobalFastSimulationManager::InActivate << 139 G4VFlavoredParallelWorld* >> 140 G4GlobalFastSimulationManager:: >> 141 GetFlavoredWorldForThis(G4ParticleDefinition* particle) 126 { 142 { 127 G4bool result = false; << 143 for (size_t ipw=0; ipw<NeededFlavoredWorlds.size(); ipw++) 128 for (auto& ManagedManager : ManagedManagers) << 144 if(NeededFlavoredWorlds[ipw]->GetTheParticleType()==particle) 129 result = result || ManagedManager->InActiv << 145 return NeededFlavoredWorlds[ipw]; 130 << 146 return 0; 131 G4cout << "Model " << aName << (result ? " i << 132 } 147 } 133 148 134 void G4GlobalFastSimulationManager::Flush() << 149 void >> 150 G4GlobalFastSimulationManager::ActivateFastSimulationModel(const G4String& aName) 135 { 151 { 136 // loop over all models (that need flushing? << 152 G4bool result = false; 137 for (auto& ManagedManager : ManagedManagers) << 153 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 138 ManagedManager->FlushModels(); << 154 result = result || ManagedManagers[ifsm]->ActivateFastSimulationModel(aName); 139 } << 155 if(result) 140 << 156 G4cout << "Model " << aName << " activated."; 141 // --------------------------------- << 157 else 142 // -- display fast simulation setup: << 158 G4cout << "Model " << aName << " not found."; 143 // --------------------------------- << 159 G4cout << G4endl; 144 void G4GlobalFastSimulationManager::ShowSetup( << 145 { << 146 std::vector<G4VPhysicalVolume*> worldDone; << 147 G4VPhysicalVolume* world; << 148 G4RegionStore* regions = G4RegionStore::GetI << 149 // ----------------------------------------- << 150 // -- loop on regions to get the list of wor << 151 // ----------------------------------------- << 152 G4cout << "\nFast simulation setup:" << G4en << 153 for (auto& region : *regions) { << 154 world = region->GetWorldPhysical(); << 155 if (world == nullptr) // region does not << 156 { << 157 continue; << 158 } << 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 } 160 } 206 161 207 void G4GlobalFastSimulationManager::DisplayReg << 162 void 208 G4Region* region, G4int depth, std::vector<G << 163 G4GlobalFastSimulationManager::InActivateFastSimulationModel(const G4String& aName) 209 { 164 { 210 G4String indent = " "; << 165 G4bool result = false; 211 for (G4int I = 0; I < depth; I++) << 166 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 212 indent += " "; << 167 result = result || ManagedManagers[ifsm]->InActivateFastSimulationModel(aName); 213 G4cout << indent << "Region: `" << region->G << 168 if(result) 214 G4FastSimulationManager* fastSimManager = re << 169 G4cout << "Model " << aName << " inactivated."; 215 if (fastSimManager != nullptr) { << 170 else 216 indent += " "; << 171 G4cout << "Model " << aName << " not found."; 217 G4cout << indent << "Model(s):" << G4endl; << 172 G4cout << G4endl; 218 indent += " "; << 173 } 219 for (auto im : fastSimManager->GetFastSimu << 174 220 G4cout << indent << "`" << im->GetName() << 175 void 221 G4cout << " ; applicable to:"; << 176 G4GlobalFastSimulationManager::ListEnvelopes(const G4String& aName, 222 G4ParticleTable* particles = G4ParticleT << 177 listType theType) 223 for (G4int iParticle = 0; iParticle < pa << 178 { 224 if (im->IsApplicable(*(particles->GetP << 179 if(theType == ISAPPLICABLE) { 225 G4cout << " " << particles->GetParti << 180 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 226 G4bool known(false); << 181 ManagedManagers[ifsm]->ListModels(aName); 227 for (auto& l : particlesKnown) << 228 if (l == particles->GetParticle(iP << 229 known = true; << 230 break; << 231 } << 232 if (!known) G4cout << "[!!]"; << 233 } << 234 } << 235 G4cout << G4endl; << 236 } << 237 } << 238 << 239 // -- all that to check mothership of "regio << 240 G4PhysicalVolumeStore* physVolStore = G4Phys << 241 for (auto physVol : *physVolStore) { << 242 if (physVol->GetLogicalVolume()->IsRootReg << 243 if (physVol->GetMotherLogical() != nullp << 244 G4Region* thisVolMotherRegion = physVo << 245 if (thisVolMotherRegion == region) << 246 DisplayRegion(physVol->GetLogicalVol << 247 } << 248 } << 249 } << 250 << 251 // ---------------------------- << 252 // -- management methods : list << 253 // ---------------------------- << 254 << 255 void G4GlobalFastSimulationManager::ListEnvelo << 256 { << 257 if (theType == ISAPPLICABLE) { << 258 for (auto& ManagedManager : ManagedManager << 259 ManagedManager->ListModels(aName); << 260 return; 182 return; 261 } 183 } 262 << 184 263 if (aName == "all") { << 185 if(aName == "all") { 264 G4int titled = 0; 186 G4int titled = 0; 265 for (auto& ManagedManager : ManagedManager << 187 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) { 266 if (theType == NAMES_ONLY) { << 188 if(theType == NAMES_ONLY) { 267 if ((titled++) == 0) G4cout << "Curren << 189 if(!(titled++)) 268 G4cout << " "; << 190 G4cout << "Current Envelopes for Fast Simulation:\n"; 269 ManagedManager->ListTitle(); << 191 G4cout << " "; 270 G4cout << G4endl; << 192 ManagedManagers[ifsm]->ListTitle(); >> 193 G4cout << G4endl; 271 } 194 } 272 else << 195 else ManagedManagers[ifsm]->ListModels(); 273 ManagedManager->ListModels(); << 274 } 196 } 275 } 197 } 276 else { 198 else { 277 for (auto& ManagedManager : ManagedManager << 199 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 278 if (aName == ManagedManager->GetEnvelope << 200 if(aName == ManagedManagers[ifsm]-> 279 ManagedManager->ListModels(); << 201 GetEnvelope()->GetName()){ 280 break; << 202 ManagedManagers[ifsm]->ListModels(); >> 203 break; 281 } 204 } 282 } 205 } 283 } 206 } 284 207 285 void G4GlobalFastSimulationManager::ListEnvelo << 208 void >> 209 G4GlobalFastSimulationManager::ListEnvelopes(const G4ParticleDefinition* aPD) 286 { 210 { 287 for (auto& ManagedManager : ManagedManagers) << 211 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) 288 ManagedManager->ListModels(aPD); << 212 ManagedManagers[ifsm]->ListModels(aPD); 289 } 213 } 290 214 291 G4VFastSimulationModel* G4GlobalFastSimulation << 215 G4VPhysicalVolume* 292 const G4String& modelName, const G4VFastSimu << 216 G4GlobalFastSimulationManager::GiveMeAWorldVolumeClone() 293 { << 217 { 294 G4VFastSimulationModel* model = nullptr; << 218 G4VPhysicalVolume* theParallelWorldPhysical; 295 // -- flag used to navigate accross the vari << 219 296 bool foundPrevious(false); << 220 G4TransportationManager *transportationManager= 297 for (auto ManagedManager : ManagedManagers) << 221 G4TransportationManager::GetTransportationManager(); 298 model = ManagedManager->GetFastSimulationM << 222 299 if (model != nullptr) break; << 223 G4VSolid *parallelWorldSolid=transportationManager-> 300 } << 224 GetNavigatorForTracking()->GetWorldVolume()-> 301 return model; << 225 GetLogicalVolume()->GetSolid(); >> 226 >> 227 G4Material *parallelWorldMaterial=transportationManager-> >> 228 GetNavigatorForTracking()->GetWorldVolume()-> >> 229 GetLogicalVolume()->GetMaterial(); >> 230 >> 231 G4LogicalVolume *parallelWorldLog = >> 232 new G4LogicalVolume(parallelWorldSolid, >> 233 parallelWorldMaterial, >> 234 "ParallelWorldLogical", >> 235 0, 0, 0); >> 236 >> 237 theParallelWorldPhysical= new G4PVPlacement(0,G4ThreeVector(), >> 238 "ParallelWorldPhysical", >> 239 parallelWorldLog, >> 240 0,false,0); >> 241 >> 242 return theParallelWorldPhysical; >> 243 } >> 244 >> 245 G4bool >> 246 G4GlobalFastSimulationManager::Notify(G4ApplicationState requestedState) >> 247 { >> 248 G4StateManager * stateManager = G4StateManager::GetStateManager(); >> 249 if((stateManager->GetPreviousState()==Idle) && >> 250 (requestedState==GeomClosed) && >> 251 (!fClosed)) >> 252 G4Exception("G4GlobalFastSimulationManager fatal error : \n1) you are using ghost volumes;\n2) In this case the G4GlobalFastSimulationManager MUST be closed BEFORE\n closing the geometry;\n3) To do this put in your code the call \n G4GlobalFastSimulationManager::GetGlobalFastSimulationManager()->\n CloseFastSimulation();\n just before closing the geometry."); >> 253 return true; 302 } 254 } 303 255