00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include "G4GlobalFastSimulationManager.hh"
00050 #include "G4ParticleTable.hh"
00051 #include "G4ParticleDefinition.hh"
00052 #include "G4Material.hh"
00053 #include "G4ThreeVector.hh"
00054 #include "G4PVPlacement.hh"
00055 #include "G4TransportationManager.hh"
00056 #include "G4FastSimulationMessenger.hh"
00057 #include "G4RegionStore.hh"
00058 #include "G4ProcessVector.hh"
00059 #include "G4ProcessManager.hh"
00060 #include "G4PhysicalVolumeStore.hh"
00061
00062
00063
00064
00065
00066 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::fGlobalFastSimulationManager = 0;
00067
00068
00069
00070
00071 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::GetGlobalFastSimulationManager()
00072 {
00073 if(!fGlobalFastSimulationManager)
00074 fGlobalFastSimulationManager = new G4GlobalFastSimulationManager;
00075
00076 return fGlobalFastSimulationManager;
00077 }
00078
00079
00080 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::GetInstance()
00081 {
00082 return G4GlobalFastSimulationManager::GetGlobalFastSimulationManager();
00083 }
00084
00085
00086
00087
00088 G4GlobalFastSimulationManager::G4GlobalFastSimulationManager()
00089 {
00090 fTheFastSimulationMessenger = new G4FastSimulationMessenger(this);
00091 }
00092
00093
00094
00095
00096 G4GlobalFastSimulationManager::~G4GlobalFastSimulationManager()
00097 {
00098 delete fTheFastSimulationMessenger;
00099 fTheFastSimulationMessenger = 0;
00100 }
00101
00102
00103
00104
00105 void G4GlobalFastSimulationManager::
00106 AddFastSimulationManager(G4FastSimulationManager* fsmanager)
00107 {
00108 ManagedManagers.push_back(fsmanager);
00109 }
00110
00111 void G4GlobalFastSimulationManager::
00112 RemoveFastSimulationManager(G4FastSimulationManager* fsmanager)
00113 {
00114 ManagedManagers.remove(fsmanager);
00115 }
00116
00117 void G4GlobalFastSimulationManager::AddFSMP(G4FastSimulationManagerProcess* fp)
00118 {
00119 fFSMPVector.push_back(fp);
00120 }
00121
00122 void G4GlobalFastSimulationManager::RemoveFSMP(G4FastSimulationManagerProcess* fp)
00123 {
00124 fFSMPVector.remove(fp);
00125 }
00126
00127 void G4GlobalFastSimulationManager::ActivateFastSimulationModel(const G4String& aName)
00128 {
00129 G4bool result = false;
00130 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
00131 result = result || ManagedManagers[ifsm]->
00132 ActivateFastSimulationModel(aName);
00133 if(result)
00134 G4cout << "Model " << aName << " activated.";
00135 else
00136 G4cout << "Model " << aName << " not found.";
00137 G4cout << G4endl;
00138 }
00139
00140 void G4GlobalFastSimulationManager::InActivateFastSimulationModel(const G4String& aName)
00141 {
00142 G4bool result = false;
00143 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
00144 result = result || ManagedManagers[ifsm]->
00145 InActivateFastSimulationModel(aName);
00146 if (result) G4cout << "Model " << aName << " inactivated.";
00147 else G4cout << "Model " << aName << " not found.";
00148 G4cout << G4endl;
00149 }
00150
00151
00152
00153
00154
00155 void G4GlobalFastSimulationManager::ShowSetup()
00156 {
00157 std::vector<G4VPhysicalVolume*> worldDone;
00158 G4VPhysicalVolume* world;
00159 G4RegionStore* regions = G4RegionStore::GetInstance();
00160
00161
00162
00163 G4cout << "\nFast simulation setup:" << G4endl;
00164 for (size_t i=0; i<regions->size(); i++)
00165 {
00166 world = (*regions)[i]->GetWorldPhysical();
00167 G4bool newWorld = true;
00168 for (size_t ii=0; ii<worldDone.size(); ii++) if (worldDone[ii] == world) {newWorld = false; break;}
00169 if (newWorld)
00170 {
00171 worldDone.push_back(world);
00172 G4Region* worldRegion = world->GetLogicalVolume()->GetRegion();
00173
00174 if (world == G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume())
00175 G4cout << "\n * Mass Geometry with ";
00176 else
00177 G4cout << "\n * Parallel Geometry with ";
00178 G4cout << "world volume: `" << world->GetName() << "' [region : `" << worldRegion->GetName() << "']" << G4endl;
00179
00180 G4bool findG4FSMP(false);
00181
00182 std::vector<G4ParticleDefinition*> particlesKnown;
00183 for (size_t ip=0; ip<fFSMPVector.size(); ip++)
00184 if (fFSMPVector[ip]->GetWorldVolume() == world)
00185 {
00186 G4cout << " o G4FastSimulationProcess: '" << fFSMPVector[ip]->GetProcessName() << "'" << G4endl;
00187 G4cout << " Attached to:";
00188 G4ParticleTable* particles = G4ParticleTable::GetParticleTable();
00189 for (G4int iParticle=0; iParticle<particles->entries(); iParticle++)
00190 {
00191 G4ParticleDefinition* particle = particles->GetParticle(iParticle);
00192 G4ProcessVector* processes = particle->GetProcessManager()->GetProcessList();
00193 if (processes->contains(fFSMPVector[ip])) {G4cout << " " << particle->GetParticleName(); findG4FSMP = true; particlesKnown.push_back(particle);}
00194 }
00195 G4cout << G4endl;
00196 }
00197 if (!findG4FSMP) G4cout << " o G4FastSimulationProcess: (none)" << G4endl;
00198
00199 G4cout << " o Region(s) and model(s) setup:" << G4endl;
00200 DisplayRegion(worldRegion, 1, particlesKnown);
00201 }
00202 }
00203 }
00204
00205
00206 void G4GlobalFastSimulationManager::DisplayRegion(G4Region* region, G4int depth, std::vector<G4ParticleDefinition*>& particlesKnown) const
00207 {
00208 G4String indent = " ";
00209 for (G4int I=0; I<depth; I++) indent += " ";
00210 G4cout << indent << "Region: `" << region->GetName() <<"'" << G4endl;
00211 G4FastSimulationManager* fastSimManager = region->GetFastSimulationManager();
00212 if (fastSimManager)
00213 {
00214 indent += " ";
00215 G4cout << indent << "Model(s):" << G4endl;
00216 indent += " ";
00217 for (size_t im=0; im<fastSimManager->GetFastSimulationModelList().size(); im++)
00218 {
00219 G4cout << indent << "`" << (fastSimManager->GetFastSimulationModelList())[im]->GetName() << "'";
00220 G4cout << " ; applicable to:";
00221 G4ParticleTable* particles = G4ParticleTable::GetParticleTable();
00222 for (G4int iParticle=0; iParticle<particles->entries(); iParticle++)
00223 {
00224 if ((fastSimManager->GetFastSimulationModelList())[im]->IsApplicable(*(particles->GetParticle(iParticle))))
00225 {
00226 G4cout << " " << particles->GetParticle(iParticle)->GetParticleName();
00227 G4bool known(false);
00228 for (size_t l=0; l<particlesKnown.size();l++) if(particlesKnown[l] == particles->GetParticle(iParticle)) {known = true; break;}
00229 if (!known) G4cout << "[!!]";
00230 }
00231 }
00232 G4cout << G4endl;
00233 }
00234 }
00235
00236
00237 G4PhysicalVolumeStore* physVolStore = G4PhysicalVolumeStore::GetInstance();
00238 for (size_t ip=0; ip<physVolStore->size(); ip++)
00239 {
00240 G4VPhysicalVolume* physVol = (*physVolStore)[ip];
00241 if (physVol->GetLogicalVolume()->IsRootRegion())
00242 if (physVol->GetMotherLogical())
00243 {
00244 G4Region* thisVolMotherRegion = physVol->GetMotherLogical()->GetRegion();
00245 if (thisVolMotherRegion == region)
00246 DisplayRegion(physVol->GetLogicalVolume()->GetRegion(), depth+1, particlesKnown);
00247 }
00248 }
00249 }
00250
00251
00252
00253
00254
00255
00256 void G4GlobalFastSimulationManager::ListEnvelopes(const G4String& aName,
00257 listType theType)
00258 {
00259 if (theType == ISAPPLICABLE)
00260 {
00261 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++) ManagedManagers[ifsm]->ListModels(aName);
00262 return;
00263 }
00264
00265 if(aName == "all")
00266 {
00267 G4int titled = 0;
00268 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
00269 {
00270 if(theType == NAMES_ONLY)
00271 {
00272 if(!(titled++))
00273 G4cout << "Current Envelopes for Fast Simulation:\n";
00274 G4cout << " ";
00275 ManagedManagers[ifsm]->ListTitle();
00276 G4cout << G4endl;
00277 }
00278 else ManagedManagers[ifsm]->ListModels();
00279 }
00280 }
00281 else
00282 {
00283 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
00284 if(aName == ManagedManagers[ifsm]-> GetEnvelope()->GetName())
00285 {
00286 ManagedManagers[ifsm]->ListModels();
00287 break;
00288 }
00289 }
00290 }
00291
00292 void G4GlobalFastSimulationManager::ListEnvelopes(const G4ParticleDefinition* aPD)
00293 {
00294 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
00295 ManagedManagers[ifsm]->ListModels(aPD);
00296 }
00297
00298
00299 G4VFastSimulationModel* G4GlobalFastSimulationManager::GetFastSimulationModel(const G4String& modelName,
00300 const G4VFastSimulationModel* previousFound) const
00301 {
00302 G4VFastSimulationModel* model = 0;
00303
00304 bool foundPrevious(false);
00305 for (size_t ifsm=0; ifsm<ManagedManagers.size(); ifsm++)
00306 {
00307 model = ManagedManagers[ifsm]->
00308 GetFastSimulationModel(modelName, previousFound, foundPrevious);
00309 if (model) break;
00310 }
00311 return model;
00312 }