G4FastSimulationManager.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 //  G4FastSimulationManager.cc
00032 //
00033 //  Description:
00034 //    Manages the Fast Simulation models attached to a envelope.
00035 //
00036 //  History:
00037 //    Oct 97: Verderi && MoraDeFreitas - First Implementation.
00038 //    ...
00039 //    May 07: Move to parallel world scheme
00040 //
00041 //---------------------------------------------------------------
00042 
00043 #include "G4FastSimulationManager.hh"
00044 #include "G4GlobalFastSimulationManager.hh"
00045 #include "G4PVPlacement.hh"
00046 #include "G4TransportationManager.hh"
00047 
00048 // --------------------------------------------------
00049 // Constructor with envelope and IsUnique flag :
00050 // --------------------------------------------------
00051 //
00052 G4FastSimulationManager::
00053 G4FastSimulationManager(G4Envelope *anEnvelope,
00054                         G4bool IsUnique) :
00055   fFastTrack(anEnvelope,IsUnique),fTriggedFastSimulationModel(0),
00056   fLastCrossedParticle(0)
00057 {
00058   // Communicates to the region that it becomes a
00059   // envelope and with this fast simulation manager.
00060   anEnvelope->SetFastSimulationManager(this);
00061 
00062   // Add itself to the GlobalFastSimulationManager 
00063   G4GlobalFastSimulationManager::GetGlobalFastSimulationManager()->
00064     AddFastSimulationManager(this);
00065 }
00066 
00067 // -----------
00068 // Destructor:
00069 // -----------
00070 G4FastSimulationManager::~G4FastSimulationManager()
00071 {
00072   //
00073   // Check out the Envelope about this pointer. If in use, 
00074   // resets the Logical Volume IsEnvelope flag to avoid clash.
00075   //
00076   if(fFastTrack.GetEnvelope()->GetFastSimulationManager()==this)
00077     fFastTrack.GetEnvelope()->ClearFastSimulationManager();
00078   // Remove itself from the GlobalFastSimulationManager 
00079   G4GlobalFastSimulationManager::GetGlobalFastSimulationManager()->
00080     RemoveFastSimulationManager(this);
00081 }
00082 
00083 // ---------------------------------------
00084 // Methods to activate/inactivate models
00085 //----------------------------------------
00086 
00087 G4bool
00088 G4FastSimulationManager::ActivateFastSimulationModel(const G4String& aName) 
00089 {
00090   size_t iModel;
00091 
00092   // If the model is already active, do nothing.
00093   for (iModel=0; iModel<ModelList.size(); iModel++)
00094     if(ModelList[iModel]->GetName() == aName)
00095       return true;
00096   
00097   // Look for in the fInactivatedModels list, if found push_back it back to 
00098   // the ModelList
00099   for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
00100     if(fInactivatedModels[iModel]->GetName() == aName) {
00101       ModelList.
00102         push_back (fInactivatedModels.removeAt(iModel));
00103       // forces the fApplicableModelList to be rebuild
00104       fLastCrossedParticle=0;
00105       return true;
00106     }
00107   return false;
00108 }
00109 
00110 G4bool
00111 G4FastSimulationManager::InActivateFastSimulationModel(const G4String& aName)
00112 {
00113   // Look for in the ModelList, if found remove from it and keep the pointer 
00114   // on the fInactivatedModels list.
00115   for (size_t iModel=0; iModel<ModelList.size(); iModel++)
00116     if(ModelList[iModel]->GetName() == aName) {
00117       fInactivatedModels.
00118         push_back (ModelList.removeAt(iModel));
00119       // forces the fApplicableModelList to be rebuild
00120       fLastCrossedParticle=0;
00121       return true;
00122     }
00123   return false;
00124 }
00125 
00126 G4VFastSimulationModel* 
00127 G4FastSimulationManager::GetFastSimulationModel(const G4String& modelName,
00128                                                 const G4VFastSimulationModel* previousFound,
00129                                                 bool &foundPrevious) const
00130 {
00131   G4VFastSimulationModel* model = 0;
00132   for (size_t iModel=0; iModel<ModelList.size(); iModel++)
00133     {
00134       if(ModelList[iModel]->GetName() == modelName)
00135         {
00136           if (previousFound == 0)
00137             {
00138               model = ModelList[iModel];
00139               break;
00140             }
00141           else
00142             {
00143               if (ModelList[iModel] == previousFound)
00144                 {
00145                   foundPrevious = true;
00146                   continue;
00147                 }
00148               if (foundPrevious)
00149                 {
00150                   model = ModelList[iModel];
00151                   break;
00152                 }
00153             }
00154         }
00155     }
00156   return model;
00157 }
00158 
00159 
00160 //------------------------------------------------------------------
00161 // Interface trigger method for the G4ParameterisationManagerProcess
00162 //------------------------------------------------------------------
00163 //   G4bool GetFastSimulationManagerTrigger(const G4Track &);
00164 //
00165 //    This method is used to interface the G4FastSimulationManagerProcess
00166 //    with the user Fast Simulation Models. It's called when the particle 
00167 //    is inside the envelope.
00168 //
00169 //    It :
00170 //
00171 //      1) initialises the private members (fFastTrack and so
00172 //         on);
00173 //      2) loops on the IsApplicable() methods to find out the
00174 //         ones should be applied.
00175 //      2) for these, loops on the ModelTrigger() methods to find out 
00176 //         perhaps one that must be applied just now.
00177 //
00178 //    If the a Fast Simulation Model is triggered then it returns 
00179 //    true, false otherwise.
00180 //
00181 //-----------------------------------------------------------
00182 G4bool 
00183 G4FastSimulationManager::
00184 PostStepGetFastSimulationManagerTrigger(const G4Track& track,
00185                                         const G4Navigator* theNavigator)
00186 {
00187   size_t iModel;
00188   
00189   // If particle type changed re-build the fApplicableModelList.
00190   if(fLastCrossedParticle!=track.GetDefinition()) {
00191     fLastCrossedParticle=track.GetDefinition();
00192     fApplicableModelList.clear();
00193     // If Model List is empty, do nothing !
00194     if(ModelList.size()==0) return false;
00195     for (iModel=0; iModel<ModelList.size(); iModel++)
00196       if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
00197         fApplicableModelList.push_back (ModelList[iModel]);
00198   }
00199 
00200   // If Applicable Model List is empty, do nothing !
00201   if(fApplicableModelList.size()==0) return false;
00202 
00203   // -- Register current track
00204   fFastTrack.SetCurrentTrack(track,theNavigator);
00205 
00206   // tests if particle are on the boundary and leaving,
00207   // in this case do nothing !
00208   if(fFastTrack.OnTheBoundaryButExiting()) return false;
00209   
00210   // Loops on the ModelTrigger() methods
00211   for (iModel=0; iModel<fApplicableModelList.size(); iModel++)
00212     
00213     //---------------------------------------------------
00214     // Asks the ModelTrigger method if it must be trigged now.
00215     //---------------------------------------------------
00216     
00217     if(fApplicableModelList[iModel]->ModelTrigger(fFastTrack)) {
00218       //--------------------------------------------------
00219       // The model will be applied. Initializes the G4FastStep 
00220       // with the current state of the G4Track and 
00221       // same usefull parameters.
00222       // In particular it does SetLocalEnergyDeposit(0.0).
00223       //--------------------------------------------------      
00224       fFastStep.Initialize(fFastTrack);
00225       
00226       // Keeps the FastSimulationModel pointer to call the
00227       // DoIt() method.
00228       fTriggedFastSimulationModel=fApplicableModelList[iModel];
00229       return true;
00230     }
00231 
00232   //--------------------------------------------
00233   // Nobody asks to gain control, returns false
00234   //--------------------------------------------
00235   return false;
00236 }
00237 
00238 G4VParticleChange* G4FastSimulationManager::InvokePostStepDoIt() 
00239 {
00240   //  const G4FastTrack& parFastTrack=fFastTrack;
00241   fTriggedFastSimulationModel->DoIt(fFastTrack,fFastStep);
00242   return &fFastStep;
00243 }
00244 
00245 // -------------------------------------------------------------
00246 // -- Mostly the same as above, in the case of AtRest particles:
00247 // -------------------------------------------------------------
00248 G4bool 
00249 G4FastSimulationManager::AtRestGetFastSimulationManagerTrigger(const G4Track& track,
00250                                                                const G4Navigator* theNavigator)
00251 {
00252   size_t iModel;
00253   
00254   // If particle type changed re-build the fApplicableModelList.
00255   if(fLastCrossedParticle!=track.GetDefinition()) {
00256     fLastCrossedParticle=track.GetDefinition();
00257     fApplicableModelList.clear();
00258     // If Model List is empty, do nothing !
00259     if(ModelList.size()==0) return false;
00260     for (iModel=0; iModel<ModelList.size(); iModel++)
00261       if(ModelList[iModel]->IsApplicable(*(track.GetDefinition())))
00262         fApplicableModelList.push_back (ModelList[iModel]);
00263   }
00264   
00265   // If Applicable Model List is empty, do nothing !
00266   if(fApplicableModelList.size()==0) return false;
00267 
00268   // -- Register current track
00269   fFastTrack.SetCurrentTrack(track,theNavigator);
00270   
00271   // -- (note: compared to the PostStepGetFastSimulationManagerTrigger,
00272   // --  the test to see if the particle is on the boundary but leaving
00273   // --  is irrelevant here)
00274   
00275   // Loops on the models to see if one of them wants to trigger:
00276   for (iModel=0; iModel < fApplicableModelList.size(); iModel++)
00277     if(fApplicableModelList[iModel]->AtRestModelTrigger(fFastTrack))
00278       {
00279         fFastStep.Initialize(fFastTrack);
00280         fTriggedFastSimulationModel=fApplicableModelList[iModel];
00281         return true;
00282       }
00283   
00284   //--------------------------------------------
00285   // Nobody asks to gain control, returns false
00286   //--------------------------------------------
00287   return false;
00288 }
00289 
00290 G4VParticleChange* G4FastSimulationManager::InvokeAtRestDoIt() 
00291 {
00292   fTriggedFastSimulationModel->AtRestDoIt(fFastTrack,fFastStep);
00293   return &fFastStep;
00294 }
00295 
00296 void 
00297 G4FastSimulationManager::ListTitle() const
00298 {
00299   G4cout << fFastTrack.GetEnvelope()->GetName();
00300   //  if(GhostPlacements.size()!=0) G4cout << " (ghost)";
00301   if (fFastTrack.GetEnvelope()->GetWorldPhysical() == G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()) G4cout << " (mass geom.)";
00302   else G4cout << " (// geom.)";
00303                                                                                                                                                           
00304 }
00305 
00306 void 
00307 G4FastSimulationManager::ListModels() const
00308 {
00309   size_t iModel;
00310 
00311   G4cout << "Current Models for the ";
00312   ListTitle();
00313   G4cout << " envelope:\n";
00314 
00315   for (iModel=0; iModel<ModelList.size(); iModel++) 
00316     G4cout << "   " << ModelList[iModel]->GetName() << "\n";
00317 
00318   for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
00319     G4cout << "   " << fInactivatedModels[iModel]->GetName() 
00320            << "(inactivated)\n";
00321 }
00322 
00323 void 
00324 G4FastSimulationManager::ListModels(const G4String& aName) const
00325 {
00326   size_t iModel;
00327   G4int titled = 0;
00328   G4ParticleTable* theParticleTable=
00329     G4ParticleTable::GetParticleTable();
00330   
00331   // Active Models
00332   for (iModel=0; iModel<ModelList.size(); iModel++)
00333     if(ModelList[iModel]->GetName() == aName ||
00334        aName == "all" ) {
00335       if(!(titled++)){
00336         G4cout << "In the envelope ";
00337         ListTitle();
00338         G4cout << ",\n";
00339       }
00340       G4cout << "  the model " << ModelList[iModel]->GetName()
00341              << " is applicable for :\n     ";
00342       
00343       G4int list_started=0;
00344       for (G4int iParticle=0; iParticle<theParticleTable->entries(); 
00345            iParticle++)
00346         if(ModelList[iModel]->
00347            IsApplicable(*(theParticleTable->
00348                           GetParticle(iParticle)))) {
00349           if(list_started++) G4cout << ", ";
00350           G4cout << theParticleTable->
00351             GetParticle(iParticle)->GetParticleName();
00352         }
00353       G4cout <<G4endl;
00354     }
00355   
00356   // Inactive Models
00357   for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
00358     if(fInactivatedModels[iModel]->GetName() == aName ||
00359        aName == "all" ) {
00360       if(!(titled++)){
00361         G4cout << "In the envelope ";
00362         ListTitle();
00363         G4cout << ",\n";
00364       }
00365       G4cout << "  the model " << fInactivatedModels[iModel]->GetName()
00366              << " (inactivated) is applicable for :\n     ";
00367       
00368       G4int list_started=0;
00369       for (G4int iParticle=0; iParticle<theParticleTable->entries(); 
00370            iParticle++)
00371         if(fInactivatedModels[iModel]->
00372            IsApplicable(*(theParticleTable->
00373                           GetParticle(iParticle)))) {
00374           if(list_started++) G4cout << ", ";
00375           G4cout << theParticleTable->
00376             GetParticle(iParticle)->GetParticleName();
00377         }
00378       G4cout <<G4endl;
00379     }
00380 }
00381 
00382 void 
00383 G4FastSimulationManager::ListModels(const G4ParticleDefinition* aPD) const
00384 {
00385   size_t iModel;
00386   G4bool unique=true;
00387   
00388   // Active Models
00389   for (iModel=0; iModel<ModelList.size(); iModel++)
00390     if(ModelList[iModel]->IsApplicable(*aPD)) {
00391       G4cout << "Envelope ";
00392       ListTitle();
00393       G4cout << ", Model " 
00394              << ModelList[iModel]->GetName() 
00395              << "." << G4endl;
00396     }
00397   // inactive Models
00398   for (iModel=0; iModel<fInactivatedModels.size(); iModel++)
00399     if(fInactivatedModels[iModel]->IsApplicable(*aPD)) {
00400       G4cout << "Envelope ";
00401       ListTitle();
00402       G4cout << ", Model " 
00403              << fInactivatedModels[iModel]->GetName() 
00404              << " (inactivated)." << G4endl;
00405     }
00406   
00407   if( !unique )
00408     {
00409       G4ExceptionDescription ed;
00410       ed << "Two or more Models are available for the same particle type, in the same envelope/region." << G4endl;
00411       G4Exception("G4FastSimulationManager::ListModels(const G4ParticleDefinition* aPD) const",
00412                   "FastSim001",
00413                   JustWarning, ed,
00414                   "Models risk to exclude each other.");
00415     }
00416   unique=false;
00417 }

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