Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 09:14:00

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // -------------------------------------------------------------------
0027 //
0028 // GEANT4 Class header file
0029 //
0030 //
0031 // File name:     G4LossTableManager
0032 //
0033 // Author:        Vladimir Ivanchenko on base of G4LossTables class
0034 //                and Maria Grazia Pia ideas
0035 //
0036 // Creation date: 03.01.2002
0037 //
0038 // Modifications by V.Ivanchenko  
0039 //
0040 // Class Description:
0041 //
0042 // A utility static class, responsable for the energy loss tables
0043 // for each particle
0044 //
0045 // Energy loss processes have to register their tables with this
0046 // class. The responsibility of creating and deleting the tables
0047 // remains with the energy loss classes.
0048 
0049 // -------------------------------------------------------------------
0050 //
0051 
0052 #ifndef G4LossTableManager_h
0053 #define G4LossTableManager_h 1
0054 
0055 #include <map>
0056 #include <vector>
0057 #include "globals.hh"
0058 #include "G4ThreadLocalSingleton.hh"
0059 #include "G4VEnergyLossProcess.hh"
0060 #include "G4EmParameters.hh"
0061 
0062 class G4PhysicsTable;
0063 class G4MaterialCutsCouple;
0064 class G4ParticleDefinition;
0065 class G4Region;
0066 class G4EmSaturation;
0067 class G4EmConfigurator;
0068 class G4ElectronIonPair;
0069 class G4NIELCalculator;
0070 class G4VMultipleScattering;
0071 class G4VEmProcess;
0072 class G4EmCorrections;
0073 class G4LossTableBuilder;
0074 class G4VAtomDeexcitation;
0075 class G4VSubCutProducer;
0076 class G4VXRayModel;
0077 
0078 class G4LossTableManager
0079 {
0080 
0081 friend class G4ThreadLocalSingleton<G4LossTableManager>;
0082 
0083 public:
0084 
0085   static G4LossTableManager* Instance();
0086 
0087   ~G4LossTableManager();
0088 
0089   //-------------------------------------------------
0090   // initialisation before a new run
0091   //-------------------------------------------------
0092 
0093   void PreparePhysicsTable(const G4ParticleDefinition* aParticle,
0094                            G4VEnergyLossProcess* p);
0095 
0096   void PreparePhysicsTable(const G4ParticleDefinition* aParticle,
0097                            G4VEmProcess* p);
0098 
0099   void PreparePhysicsTable(const G4ParticleDefinition* aParticle,
0100                            G4VMultipleScattering* p);
0101 
0102   void BuildPhysicsTable(const G4ParticleDefinition* aParticle);
0103 
0104   void BuildPhysicsTable(const G4ParticleDefinition* aParticle, 
0105                          G4VEnergyLossProcess* p);
0106 
0107   void LocalPhysicsTables(const G4ParticleDefinition* aParticle, 
0108                           G4VEnergyLossProcess* p);
0109  
0110   void DumpHtml();
0111 
0112   //-------------------------------------------------
0113   // Run time access to DEDX, range, energy for a given particle, 
0114   // energy, and G4MaterialCutsCouple
0115   //-------------------------------------------------
0116 
0117   inline G4double GetDEDX(
0118     const G4ParticleDefinition *aParticle,
0119     G4double kineticEnergy,
0120     const G4MaterialCutsCouple *couple);
0121 
0122   inline G4double GetRange(
0123     const G4ParticleDefinition *aParticle,
0124     G4double kineticEnergy,
0125     const G4MaterialCutsCouple *couple);
0126 
0127   inline G4double GetCSDARange(
0128     const G4ParticleDefinition *aParticle,
0129     G4double kineticEnergy,
0130     const G4MaterialCutsCouple *couple);
0131 
0132   inline G4double GetRangeFromRestricteDEDX(
0133     const G4ParticleDefinition *aParticle,
0134     G4double kineticEnergy,
0135     const G4MaterialCutsCouple *couple);
0136 
0137   inline G4double GetEnergy(
0138     const G4ParticleDefinition *aParticle,
0139     G4double range,
0140     const G4MaterialCutsCouple *couple);
0141 
0142   inline G4double GetDEDXDispersion(
0143     const G4MaterialCutsCouple *couple,
0144     const G4DynamicParticle* dp,
0145           G4double& length);
0146 
0147   //-------------------------------------------------
0148   // Methods to be called only at initialisation
0149   // and at the end of the job
0150   //-------------------------------------------------
0151 
0152   void Register(G4VEnergyLossProcess* p);
0153 
0154   void DeRegister(G4VEnergyLossProcess* p);
0155 
0156   void Register(G4VMultipleScattering* p);
0157 
0158   void DeRegister(G4VMultipleScattering* p);
0159 
0160   void Register(G4VEmProcess* p);
0161 
0162   void DeRegister(G4VEmProcess* p);
0163 
0164   void Register(G4VProcess* p);
0165 
0166   void DeRegister(G4VProcess* p);
0167 
0168   void Register(G4VEmModel* p);
0169 
0170   void DeRegister(G4VEmModel* p);
0171 
0172   void Register(G4VEmFluctuationModel* p);
0173 
0174   void DeRegister(G4VEmFluctuationModel* p);
0175 
0176   void Register(G4VXRayModel* p);
0177 
0178   void DeRegister(G4VXRayModel* p);
0179 
0180   void RegisterExtraParticle(const G4ParticleDefinition* aParticle, 
0181                              G4VEnergyLossProcess* p);
0182 
0183   void SetVerbose(G4int val);
0184 
0185   void ResetParameters();
0186 
0187   void SetAtomDeexcitation(G4VAtomDeexcitation*);
0188 
0189   void SetSubCutProducer(G4VSubCutProducer*);
0190 
0191   void SetNIELCalculator(G4NIELCalculator*);
0192 
0193   //-------------------------------------------------
0194   // Access methods
0195   //-------------------------------------------------
0196 
0197   inline G4bool IsMaster() const;
0198 
0199   G4VEnergyLossProcess* GetEnergyLossProcess(const G4ParticleDefinition*);
0200  
0201   const std::vector<G4VEnergyLossProcess*>& GetEnergyLossProcessVector();
0202 
0203   const std::vector<G4VEmProcess*>& GetEmProcessVector();
0204 
0205   const std::vector<G4VMultipleScattering*>& GetMultipleScatteringVector();
0206 
0207   G4EmSaturation* EmSaturation();
0208 
0209   G4EmConfigurator* EmConfigurator();
0210 
0211   G4ElectronIonPair* ElectronIonPair();
0212 
0213   G4NIELCalculator* NIELCalculator();
0214 
0215   inline G4EmCorrections* EmCorrections();
0216 
0217   inline G4VAtomDeexcitation* AtomDeexcitation();
0218 
0219   inline G4VSubCutProducer* SubCutProducer();
0220 
0221   inline G4LossTableBuilder* GetTableBuilder();
0222 
0223   inline void SetGammaGeneralProcess(G4VEmProcess*); 
0224 
0225   inline G4VEmProcess* GetGammaGeneralProcess(); 
0226 
0227   inline void SetElectronGeneralProcess(G4VEmProcess*); 
0228 
0229   inline G4VEmProcess* GetElectronGeneralProcess(); 
0230 
0231   inline void SetPositronGeneralProcess(G4VEmProcess*); 
0232 
0233   inline G4VEmProcess* GetPositronGeneralProcess(); 
0234 
0235   G4LossTableManager(G4LossTableManager &) = delete;
0236   G4LossTableManager & operator=(const G4LossTableManager &right) = delete;
0237 
0238 private:
0239 
0240   //-------------------------------------------------
0241   // Private methods and members
0242   //-------------------------------------------------
0243 
0244   G4LossTableManager();
0245 
0246   void Clear();
0247 
0248   G4VEnergyLossProcess* BuildTables(const G4ParticleDefinition* aParticle);
0249 
0250   void CopyTables(const G4ParticleDefinition* aParticle, 
0251                   G4VEnergyLossProcess*);
0252 
0253   void ParticleHaveNoLoss(const G4ParticleDefinition* aParticle);
0254 
0255   void CopyDEDXTables();
0256 
0257   void PrintEWarning(G4String, G4double);
0258 
0259   static G4ThreadLocal G4LossTableManager* instance;
0260 
0261   typedef const G4ParticleDefinition* PD;
0262 
0263   // cache
0264   G4VEnergyLossProcess* currentLoss{nullptr};
0265   PD currentParticle{nullptr};
0266   PD theElectron;
0267   PD theGenericIon{nullptr};
0268   PD firstParticle{nullptr};
0269 
0270   G4LossTableBuilder* tableBuilder;
0271   G4EmCorrections* emCorrections;
0272   G4EmConfigurator* emConfigurator{nullptr};
0273   G4ElectronIonPair* emElectronIonPair{nullptr};
0274   G4NIELCalculator* nielCalculator{nullptr};
0275   G4VAtomDeexcitation* atomDeexcitation{nullptr};
0276   G4VSubCutProducer* subcutProducer{nullptr};
0277 
0278   G4EmParameters* theParameters;
0279   G4VEmProcess* gGeneral{nullptr};
0280   G4VEmProcess* eGeneral{nullptr};
0281   G4VEmProcess* pGeneral{nullptr};
0282 
0283   G4int verbose;
0284   G4int n_loss{0};
0285   G4int run{-1};
0286 
0287   G4bool all_tables_are_built{false};
0288   G4bool startInitialisation{false};
0289   G4bool resetParam{true};
0290   G4bool isMaster{false};
0291 
0292   std::vector<G4VEnergyLossProcess*> loss_vector;
0293   std::vector<PD> part_vector;
0294   std::vector<PD> base_part_vector;
0295   std::vector<G4PhysicsTable*> dedx_vector;
0296   std::vector<G4PhysicsTable*> range_vector;
0297   std::vector<G4PhysicsTable*> inv_range_vector;
0298   std::vector<G4bool> tables_are_built;
0299   std::vector<G4bool> isActive;
0300   std::vector<G4VMultipleScattering*> msc_vector;
0301   std::vector<G4VEmProcess*> emp_vector;
0302   std::vector<G4VEmModel*> mod_vector;
0303   std::vector<G4VEmFluctuationModel*> fmod_vector;
0304   std::vector<G4VXRayModel*> xray_vector;
0305   std::vector<G4VProcess*> p_vector;
0306 
0307   std::map<PD,G4VEnergyLossProcess*,std::less<PD> > loss_map;
0308 };
0309 
0310 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0311 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0312 
0313 inline
0314 G4double G4LossTableManager::GetDEDX(const G4ParticleDefinition *aParticle,
0315                                      G4double kineticEnergy,
0316                                      const G4MaterialCutsCouple *couple)
0317 {
0318   if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
0319   return currentLoss ? currentLoss->GetDEDX(kineticEnergy, couple) : 0.0;
0320 }
0321 
0322 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0323 
0324 inline
0325 G4double G4LossTableManager::GetCSDARange(const G4ParticleDefinition *aParticle,
0326                                           G4double kineticEnergy,
0327                                           const G4MaterialCutsCouple *couple)
0328 {
0329   if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
0330   return currentLoss ? currentLoss->GetCSDARange(kineticEnergy, couple) : DBL_MAX;
0331 }
0332 
0333 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0334 
0335 inline
0336 G4double G4LossTableManager::GetRangeFromRestricteDEDX(
0337                              const G4ParticleDefinition *aParticle,
0338                              G4double kineticEnergy,
0339                              const G4MaterialCutsCouple *couple)
0340 {
0341   if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
0342   return currentLoss ? currentLoss->GetRange(kineticEnergy, couple) : DBL_MAX;
0343 }
0344 
0345 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0346 
0347 inline
0348 G4double G4LossTableManager::GetRange(const G4ParticleDefinition *aParticle,
0349                                       G4double kineticEnergy,
0350                                       const G4MaterialCutsCouple *couple)
0351 {
0352   if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
0353   return currentLoss ? currentLoss->GetRange(kineticEnergy, couple) : DBL_MAX;
0354 }
0355 
0356 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0357 
0358 inline
0359 G4double G4LossTableManager::GetEnergy(const G4ParticleDefinition *aParticle,
0360                                        G4double range,
0361                                        const G4MaterialCutsCouple *couple)
0362 {
0363   if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
0364   return currentLoss ? currentLoss->GetKineticEnergy(range, couple) : 0.0;
0365 }
0366 
0367 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0368 
0369 inline
0370 G4double G4LossTableManager::GetDEDXDispersion(
0371                              const G4MaterialCutsCouple *couple,
0372                              const G4DynamicParticle* dp,
0373                              G4double& length)
0374 {
0375   const G4ParticleDefinition* aParticle = dp->GetParticleDefinition();
0376   if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
0377   return currentLoss ? currentLoss->GetDEDXDispersion(couple, dp, length) : 0.0;
0378 }
0379 
0380 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0381 
0382 inline G4bool G4LossTableManager::IsMaster() const
0383 {
0384   return isMaster;
0385 }
0386 
0387 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0388 
0389 inline G4EmCorrections* G4LossTableManager::EmCorrections() 
0390 {
0391   return emCorrections;
0392 }
0393 
0394 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0395 
0396 inline G4VAtomDeexcitation* G4LossTableManager::AtomDeexcitation()
0397 {
0398   return atomDeexcitation;
0399 }
0400 
0401 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0402 
0403 inline G4VSubCutProducer* G4LossTableManager::SubCutProducer()
0404 { 
0405   return subcutProducer;
0406 }
0407 
0408 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0409 
0410 inline G4LossTableBuilder* G4LossTableManager::GetTableBuilder()
0411 {
0412   return tableBuilder;
0413 }
0414 
0415 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0416 
0417 inline void G4LossTableManager::SetGammaGeneralProcess(G4VEmProcess* ptr)
0418 {
0419   gGeneral = ptr;
0420 } 
0421 
0422 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0423 
0424 inline G4VEmProcess* G4LossTableManager::GetGammaGeneralProcess()
0425 {
0426   return gGeneral;
0427 } 
0428 
0429 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0430 
0431 inline void G4LossTableManager::SetElectronGeneralProcess(G4VEmProcess* ptr)
0432 {
0433   eGeneral = ptr;
0434 } 
0435 
0436 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0437 
0438 inline G4VEmProcess* G4LossTableManager::GetElectronGeneralProcess()
0439 {
0440   return eGeneral;
0441 } 
0442 
0443 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0444 
0445 inline void G4LossTableManager::SetPositronGeneralProcess(G4VEmProcess* ptr)
0446 {
0447   pGeneral = ptr;
0448 } 
0449 
0450 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0451 
0452 inline G4VEmProcess* G4LossTableManager::GetPositronGeneralProcess()
0453 {
0454   return pGeneral;
0455 } 
0456 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0457 
0458 #endif