Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:58

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 // G4ProductionCutsTable
0027 //
0028 // Class description:
0029 //
0030 // G4ProductionCutsTable is a singleton class for a table of
0031 // G4ProductionCuts objects. This class manages tables of production
0032 // cuts and energy cuts for each particle type.
0033 
0034 // Author: M.Asai, 5 October 2002 - First implementation
0035 // Modifications: H.Kurashige, 2004-2008
0036 // --------------------------------------------------------------------
0037 #ifndef G4ProductionCutsTable_hh 
0038 #define G4ProductionCutsTable_hh 1
0039 
0040 #include <cmath>
0041 #include <vector>
0042 
0043 #include "globals.hh"
0044 #include "G4ios.hh"
0045 #include "G4MaterialCutsCouple.hh"
0046 #include "G4MCCIndexConversionTable.hh"
0047 #include "G4Region.hh"
0048 
0049 class G4RegionStore;
0050 class G4VRangeToEnergyConverter;
0051 class G4LogicalVolume;
0052 class G4VPhysicalVolume;
0053 class G4ProductionCuts;
0054 class G4ProductionCutsTableMessenger;
0055 
0056 class G4ProductionCutsTable  
0057 {
0058   public:
0059 
0060     static G4ProductionCutsTable* GetProductionCutsTable();
0061       // This static method returns the singleton pointer of this class object.
0062       // At first invocation, the singleton object is instantiated
0063 
0064     G4ProductionCutsTable(const G4ProductionCutsTable&) = delete;
0065     G4ProductionCutsTable& operator=(const G4ProductionCutsTable&) = delete;
0066 
0067     virtual ~G4ProductionCutsTable();
0068 
0069     void CreateCoupleTables();
0070       // Creates material cuts couples table and allocate the other tables
0071 
0072     void UpdateCoupleTable(G4VPhysicalVolume* currentWorld);
0073       // Triggers an update of the table of G4ProductionCuts objects
0074 
0075     void SetEnergyRange(G4double lowedge, G4double highedge);
0076       // Sets the limits of energy cuts for all particles
0077 
0078     G4double GetLowEdgeEnergy() const;
0079     G4double GetHighEdgeEnergy() const;
0080       // Get the limits of energy cuts for all particles
0081 
0082     G4double GetMaxEnergyCut();
0083     void SetMaxEnergyCut(G4double value);
0084       // Get/set max cut energy of RangeToEnergy converter
0085       // for all particle types
0086 
0087     void DumpCouples() const;
0088       // Displays a list of registered couples
0089 
0090     const G4MCCIndexConversionTable* GetMCCIndexConversionTable() const;
0091       // Gives the pointer to the MCCIndexConversionTable
0092 
0093     const std::vector<G4double>* GetRangeCutsVector(std::size_t pcIdx) const;
0094     const std::vector<G4double>* GetEnergyCutsVector(std::size_t pcIdx) const;
0095   
0096     std::size_t GetTableSize() const;
0097       // Returns the size of the couple table
0098 
0099     const G4MaterialCutsCouple* GetMaterialCutsCouple(G4int i) const;
0100       // Returns the pointer to the couple
0101 
0102     const G4MaterialCutsCouple* GetMaterialCutsCouple(const G4Material* aMat,
0103                                             const G4ProductionCuts* aCut) const;
0104      // Returns the pointer to the couple
0105 
0106     G4int GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const;
0107     G4int GetCoupleIndex(const G4Material* aMat,
0108                          const G4ProductionCuts* aCut) const;
0109       // Return the index of the couple.
0110       // -1 is returned if index is not found
0111 
0112     G4bool IsModified() const;
0113       // Returns TRUE if at least one production cut value is modified
0114   
0115     void PhysicsTableUpdated();
0116       // Resets the status of IsModified(). This method must be exclusively
0117       // used by the RunManager when physics tables are built
0118 
0119     G4ProductionCuts* GetDefaultProductionCuts() const;
0120       // Returns the default production cuts
0121  
0122     G4double ConvertRangeToEnergy(const G4ParticleDefinition* particle,
0123                                   const G4Material* material, 
0124                                         G4double range);
0125       // Gives energy corresponding to range value.
0126       // -1 is returned if particle or material is not found
0127 
0128     void ResetConverters();
0129       // Resets all range to energy converters  
0130 
0131     G4bool StoreCutsTable(const G4String& directory, 
0132                           G4bool ascii = false);
0133       // Stores cuts and material information in files under the
0134       // the specified directory
0135 
0136     G4bool RetrieveCutsTable(const G4String& directory,
0137                              G4bool ascii = false);
0138       // Retrieve material cut couple information 
0139       // in files under the specified directory
0140 
0141     G4bool CheckForRetrieveCutsTable(const G4String& directory, 
0142                                      G4bool ascii = false);
0143       // Checks stored material and cut values are consistent
0144       // with the current detector setup
0145 
0146     G4double* GetRangeCutsDoubleVector(std::size_t pcIdx) const;
0147     G4double* GetEnergyCutsDoubleVector(std::size_t pcIdx) const;
0148       // Methods for backward compatibility
0149 
0150     void SetEnergyCutVector(const std::vector<G4double>& cutE, std::size_t idx);
0151       // User defined cut vectors (idx < 4) range cut should be defined
0152       // to avoid inconsistency in physics
0153 
0154     void  SetVerboseLevel(G4int value);
0155     G4int GetVerboseLevel() const;
0156       // Control flag for output message
0157       //  0: Silent
0158       //  1: Warning message
0159       //  2: More
0160 
0161   protected:
0162 
0163     G4ProductionCutsTable();
0164 
0165     virtual G4bool StoreMaterialInfo(const G4String& directory, 
0166                                      G4bool ascii = false);
0167       // Stores material information in files under the specified directory
0168 
0169     virtual G4bool CheckMaterialInfo(const G4String& directory, 
0170                                      G4bool ascii = false);
0171       // Checks stored material is consistent with the current detector setup
0172 
0173     virtual G4bool StoreMaterialCutsCoupleInfo(const G4String& directory, 
0174                                                G4bool ascii = false);
0175       // Stores materialCutsCouple information in files under the
0176       // specified directory
0177 
0178     virtual G4bool CheckMaterialCutsCoupleInfo(const G4String& directory, 
0179                                                G4bool ascii = false);
0180       // Checks stored materialCutsCouple is consistent with
0181       // the current detector setup
0182 
0183     virtual G4bool StoreCutsInfo(const G4String& directory, 
0184                                  G4bool ascii = false);
0185       // Stores cut values information in files under the specified directory
0186 
0187     virtual G4bool  RetrieveCutsInfo(const G4String& directory,
0188                                      G4bool ascii = false);
0189       // Retrieves cut values information in files under the
0190       // specified directory
0191 
0192   private:
0193 
0194     void ScanAndSetCouple(G4LogicalVolume* aLV,
0195                           G4MaterialCutsCouple* aCouple,
0196                           G4Region* aRegion);
0197 
0198     G4bool IsCoupleUsedInTheRegion(const G4MaterialCutsCouple* aCouple,
0199                                    const G4Region* aRegion) const;
0200 
0201 
0202   private:
0203 
0204     static G4ProductionCutsTable* fProductionCutsTable;
0205 
0206     std::vector<G4MaterialCutsCouple*> coupleTable;
0207     std::vector<std::vector<G4double>*> rangeCutTable;
0208     std::vector<std::vector<G4double>*> energyCutTable;
0209 
0210     std::vector<G4double>* userEnergyCuts[4] = {nullptr, nullptr, nullptr, nullptr};
0211 
0212     G4RegionStore* fG4RegionStore = nullptr;
0213     G4VRangeToEnergyConverter* converters[NumberOfG4CutIndex]; 
0214 
0215     G4ProductionCuts* defaultProductionCuts = nullptr;
0216 
0217     G4MCCIndexConversionTable mccConversionTable;
0218 
0219     // These two vectors are for backward compatibility
0220     G4double* rangeDoubleVector[NumberOfG4CutIndex];
0221     G4double* energyDoubleVector[NumberOfG4CutIndex];
0222 
0223     enum { FixedStringLengthForStore = 32 }; 
0224 
0225     G4ProductionCutsTableMessenger* fMessenger = nullptr;
0226     G4int verboseLevel = 1;
0227     G4bool firstUse = true;
0228 };
0229 
0230 // ------------------
0231 // Inline methods
0232 // ------------------
0233 
0234 inline 
0235 const std::vector<G4double>*
0236 G4ProductionCutsTable::GetRangeCutsVector(std::size_t pcIdx) const
0237 { 
0238   return rangeCutTable[pcIdx]; 
0239 }
0240 
0241 inline 
0242 const std::vector<G4double>*
0243 G4ProductionCutsTable::GetEnergyCutsVector(std::size_t pcIdx) const
0244 {
0245   return energyCutTable[pcIdx]; 
0246 }
0247 
0248 inline 
0249 std::size_t G4ProductionCutsTable::GetTableSize() const
0250 {
0251   return coupleTable.size(); 
0252 }
0253 
0254 inline 
0255 const G4MaterialCutsCouple*
0256 G4ProductionCutsTable::GetMaterialCutsCouple(G4int i) const
0257 { 
0258   return coupleTable[std::size_t(i)]; 
0259 }
0260 
0261 inline 
0262 G4bool G4ProductionCutsTable::IsModified() const
0263 { 
0264   if(firstUse) return true;
0265   for(auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr)
0266   { 
0267     if((*itr)->IsRecalcNeeded())
0268     {
0269       return true; 
0270     }
0271   }
0272   return false;
0273 }
0274   
0275 inline 
0276 void G4ProductionCutsTable::PhysicsTableUpdated()
0277 { 
0278   for(auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr)
0279   { 
0280     (*itr)->PhysicsTableUpdated(); 
0281   }
0282 }
0283 
0284 inline
0285 G4double*
0286 G4ProductionCutsTable::GetRangeCutsDoubleVector(std::size_t pcIdx) const
0287 {
0288   return rangeDoubleVector[pcIdx];
0289 }
0290 
0291 inline
0292 G4double*
0293 G4ProductionCutsTable::GetEnergyCutsDoubleVector(std::size_t pcIdx) const
0294 {
0295   return energyDoubleVector[pcIdx];
0296 }
0297 
0298 inline
0299 G4ProductionCuts* G4ProductionCutsTable::GetDefaultProductionCuts() const
0300 {
0301   return defaultProductionCuts;
0302 }
0303 
0304 inline
0305 G4bool G4ProductionCutsTable::IsCoupleUsedInTheRegion(
0306                                  const G4MaterialCutsCouple* aCouple,
0307                                  const G4Region* aRegion) const
0308 {
0309   G4ProductionCuts* fProductionCut = aRegion->GetProductionCuts();
0310   auto mItr = aRegion->GetMaterialIterator();
0311   std::size_t nMaterial = aRegion->GetNumberOfMaterials();
0312   for(std::size_t iMate=0;iMate<nMaterial; ++iMate, ++mItr)
0313   {
0314     if(aCouple->GetMaterial()==(*mItr) &&
0315        aCouple->GetProductionCuts()==fProductionCut)
0316     {
0317       return true;
0318     }
0319   }
0320   return false;
0321 }
0322 
0323 inline
0324 const G4MaterialCutsCouple* 
0325 G4ProductionCutsTable::GetMaterialCutsCouple(const G4Material* aMat,
0326                                              const G4ProductionCuts* aCut) const
0327 {
0328   for(auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
0329   { 
0330     if((*cItr)->GetMaterial()!=aMat) continue;
0331     if((*cItr)->GetProductionCuts()==aCut) return (*cItr);
0332   }
0333   return nullptr;
0334 }
0335 
0336 inline
0337 G4int
0338 G4ProductionCutsTable::GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const
0339 { 
0340   G4int idx = 0;
0341   for(auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
0342   {
0343     if((*cItr)==aCouple) return idx;
0344     ++idx;
0345   }
0346   return -1;
0347 }
0348 
0349 inline
0350 G4int G4ProductionCutsTable::GetCoupleIndex(const G4Material* aMat,
0351                                             const G4ProductionCuts* aCut) const
0352 {
0353   const G4MaterialCutsCouple* aCouple = GetMaterialCutsCouple(aMat,aCut);
0354   return GetCoupleIndex(aCouple);
0355 }
0356 
0357 inline 
0358 G4int G4ProductionCutsTable::GetVerboseLevel() const
0359 {
0360   return verboseLevel;
0361 }
0362 
0363 inline
0364 const G4MCCIndexConversionTable* 
0365 G4ProductionCutsTable::GetMCCIndexConversionTable() const
0366 {
0367   return &mccConversionTable;
0368 }
0369 
0370 #endif