G4GlobalFastSimulationManager.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 //  
00030 //---------------------------------------------------------------
00031 //
00032 //  G4GlobalFastSimulationManager.cc
00033 //
00034 //  Description:
00035 //    A singleton class which manages the Fast Simulation managers 
00036 //    attached to envelopes. Implementation.
00037 //
00038 //  History:
00039 //    June 98: Verderi && MoraDeFreitas - "G4ParallelWorld" becomes
00040 //             "G4FlavoredParallelWorld"; some method name changes;
00041 //             GetFlavoredWorldForThis now returns a 
00042 //             G4FlavoredParallelWorld pointer.
00043 //    Feb 98: Verderi && MoraDeFreitas - First Implementation.
00044 //    March 98: correction to instanciate dynamically the manager
00045 //    May 07: Move to parallel world scheme
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 // -- static instance pointer initialisation:
00065 // ------------------------------------------
00066 G4GlobalFastSimulationManager* G4GlobalFastSimulationManager::fGlobalFastSimulationManager = 0;
00067 
00068 // --------------------------------------------------
00069 // -- static methods to retrieve the manager pointer:
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 // -- constructor
00087 // ---------------
00088 G4GlobalFastSimulationManager::G4GlobalFastSimulationManager()
00089 {
00090   fTheFastSimulationMessenger = new G4FastSimulationMessenger(this);
00091 }
00092 
00093 // -------------
00094 // -- destructor
00095 // -------------
00096 G4GlobalFastSimulationManager::~G4GlobalFastSimulationManager()
00097 {
00098   delete fTheFastSimulationMessenger;
00099   fTheFastSimulationMessenger = 0;
00100 }
00101 
00102 // ----------------------
00103 // -- management methods:
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 // -- display fast simulation setup:
00154 // ---------------------------------
00155 void G4GlobalFastSimulationManager::ShowSetup()
00156 {
00157   std::vector<G4VPhysicalVolume*> worldDone;
00158   G4VPhysicalVolume* world;
00159   G4RegionStore* regions = G4RegionStore::GetInstance();
00160   // ----------------------------------------------------
00161   // -- loop on regions to get the list of world volumes:
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           // -- preambule: print physical volume and region names...
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           // -- ... and print G4FSMP(s) attached to this world volume:
00180           G4bool findG4FSMP(false);
00181           // -- show to what particles this G4FSMP is attached to:
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           // -- now display the regions in this world volume, with mother<->daughter link shown by indentation:
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   // -- all that to check mothership of "region"
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 // -- management methods : list
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   // -- flag used to navigate accross the various managers;
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 }

Generated on Mon May 27 17:48:23 2013 for Geant4 by  doxygen 1.4.7