Back to home page

EIC code displayed by LXR

 
 

    


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

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 #ifndef G4NistMaterialBuilder_h
0028 #define G4NistMaterialBuilder_h 1
0029 
0030 //---------------------------------------------------------------------------
0031 //
0032 // ClassName:   G4NistMaterialBuilder
0033 //
0034 // Description: Utility class to hold and manipulate G4Materials
0035 //
0036 // Author:      V.Ivanchenko 21.11.2004
0037 //
0038 // Modifications:
0039 // 31.10.05 Add chemical effect and gas properties (V.Ivanchenko)
0040 // 27.02.06 V.Ivanchneko add ConstructNewGasMaterial
0041 // 11.05.06 V.Ivanchneko add warning flag to FindOrBuildMaterial method
0042 // 27.07.06 V.Ivanchneko set defaul warning=true for FindOrBuildMaterial
0043 // 27.07.07 V.Ivanchneko add matIndex vector to control built materials
0044 // 28.07.07 V.Ivanchneko add BuildMaterial method using Nist index
0045 // 29.04.10 V.Ivanchneko add GetMeanIonisationEnergy method using Nist index
0046 // 09.02.12 P.Gumplinger add ConstructNewIdealGasMaterial
0047 //
0048 //----------------------------------------------------------------------------
0049 //
0050 // Class Description:
0051 //
0052 // Element data from the NIST DB on Atomic Weights and Isotope Compositions
0053 // http://physics.nist.gov/PhysRefData/Compositions/index.html
0054 //
0055 
0056 #include "G4Material.hh"
0057 #include "globals.hh"
0058 
0059 #include <CLHEP/Units/PhysicalConstants.h>
0060 
0061 #include <vector>
0062 
0063 class G4NistElementBuilder;
0064 
0065 class G4NistMaterialBuilder
0066 {
0067  public:
0068   G4NistMaterialBuilder(G4NistElementBuilder*, G4int verb = 0);
0069 
0070   ~G4NistMaterialBuilder() = default;
0071 
0072   // Find or build a G4Material by name, from dataBase
0073   inline G4Material* FindMaterial(const G4String& name) const;
0074   G4Material* FindOrBuildMaterial(const G4String& name, G4bool warning = true);
0075 
0076   // Find or build a simple material via atomic number
0077   inline G4Material* FindSimpleMaterial(G4int Z) const;
0078   G4Material* FindOrBuildSimpleMaterial(G4int Z, G4bool warning);
0079 
0080   // construct a G4Material from scratch by atome count
0081   G4Material* ConstructNewMaterial(const G4String& name, const std::vector<G4String>& elm,
0082     const std::vector<G4int>& nbAtoms, G4double dens, G4State state = kStateSolid,
0083     G4double temp = NTP_Temperature, G4double pressure = CLHEP::STP_Pressure);
0084 
0085   // construct a G4Material from scratch by fraction mass
0086   G4Material* ConstructNewMaterial(const G4String& name, const std::vector<G4String>& elm,
0087     const std::vector<G4double>& weight, G4double dens, G4State state = kStateSolid,
0088     G4double temp = NTP_Temperature, G4double pressure = CLHEP::STP_Pressure);
0089 
0090   // construct a gas G4Material from scratch by atome count
0091   G4Material* ConstructNewGasMaterial(
0092     const G4String& name, const G4String& nameDB, G4double temp, G4double pres);
0093 
0094   // Construct an ideal gas G4Material from scratch by atom count
0095   G4Material* ConstructNewIdealGasMaterial(const G4String& name, const std::vector<G4String>& elm,
0096     const std::vector<G4int>& nbAtoms, G4double temp = NTP_Temperature,
0097     G4double pressure = CLHEP::STP_Pressure);
0098 
0099   // verbosity level defined by G4NistManager
0100   void SetVerbose(G4int val);
0101 
0102   // cout predefined materials:
0103   // "simple" - only pure materials in basic state (Z = 1, ..., 98)
0104   // "compound" - NIST compounds
0105   // "hep" - HEP materials and compounds
0106   // "biochemical" - bio-chemical materials
0107   // "all" - all
0108   void ListMaterials(const G4String&) const;
0109 
0110   // cout lists of predefined materials
0111   void ListNistSimpleMaterials() const;
0112   void ListNistCompoundMaterials() const;
0113   void ListHepMaterials() const;
0114   void ListSpaceMaterials() const;
0115   void ListBioChemicalMaterials() const;
0116 
0117   // access to the list of names of Geant4 predefined materials
0118   const std::vector<G4String>& GetMaterialNames() const;
0119 
0120   // access to the NIST mean ionisation potentials and nominal densities
0121   inline G4double GetMeanIonisationEnergy(G4int index) const;
0122   inline G4double GetNominalDensity(G4int index) const;
0123 
0124   G4bool operator==(const G4NistMaterialBuilder&) const = delete;
0125   G4bool operator!=(const G4NistMaterialBuilder&) const = delete;
0126   G4NistMaterialBuilder(const G4NistMaterialBuilder&) = delete;
0127   const G4NistMaterialBuilder& operator=(const G4NistMaterialBuilder&) = delete;
0128 
0129  private:
0130   void Initialise();
0131   void NistSimpleMaterials();
0132   void NistCompoundMaterials();
0133   void NistCompoundMaterials2();
0134   void HepAndNuclearMaterials();
0135   void SpaceMaterials();
0136   void BioChemicalMaterials();
0137 
0138   // add parameters of material from NIST DB to internal vectors
0139   // density in g/cm3, mean ionisation potential in eV
0140   //
0141   void AddMaterial(const G4String& nameMat, G4double dens, G4int Z = 0, G4double pot = 0.0,
0142     G4int ncomp = 1, G4State = kStateSolid, G4bool stp = true);
0143 
0144   void AddGas(const G4String& nameMat, G4double T, G4double P);
0145 
0146   void AddElementByWeightFraction(G4int Z, G4double);
0147   void AddElementByAtomCount(G4int Z, G4int);
0148 
0149   void AddElementByWeightFraction(const G4String& name, G4double);
0150   void AddElementByAtomCount(const G4String& name, G4int);
0151 
0152   // build a G4Material from dataBase
0153   G4Material* BuildNistMaterial(const G4String& matname, G4bool warning);
0154   G4Material* BuildMaterial(G4int idx);
0155 
0156   void DumpElm(G4int) const;
0157   void DumpMix(G4int) const;
0158 
0159  private:
0160   G4NistElementBuilder* elmBuilder;
0161 
0162   G4int verbose;
0163   G4int nMaterials{0};
0164   G4int nComponents{0};
0165   G4int nCurrent{0};
0166   G4int nElementary;
0167   G4int nNIST;
0168   G4int nHEP;
0169   G4int nSpace;
0170 
0171   std::vector<G4String> names;
0172   std::vector<G4String> chFormulas;
0173 
0174   std::vector<G4double> densities;
0175   std::vector<G4double> ionPotentials;
0176   std::vector<G4State> states;
0177   std::vector<G4double> fractions;
0178   std::vector<G4bool> atomCount;
0179   std::vector<G4int> components;
0180   std::vector<G4int> indexes;
0181   std::vector<G4int> elements;
0182   std::vector<G4int> matIndex;
0183   std::vector<G4bool> STP;
0184 
0185   std::vector<G4int> idxGas;
0186   std::vector<G4double> gasTemperature;
0187   std::vector<G4double> gasPressure;
0188 };
0189 
0190 inline const std::vector<G4String>& G4NistMaterialBuilder::GetMaterialNames() const
0191 {
0192   return names;
0193 }
0194 
0195 inline G4double G4NistMaterialBuilder::GetMeanIonisationEnergy(G4int index) const
0196 {
0197   return (index >= 0 && index < nMaterials) ? ionPotentials[index] : 10.0 * index;
0198 }
0199 
0200 inline G4double G4NistMaterialBuilder::GetNominalDensity(G4int index) const
0201 {
0202   return (index >= 0 && index < nMaterials) ? densities[index] : 0.0;
0203 }
0204 
0205 inline G4Material* G4NistMaterialBuilder::FindMaterial(const G4String& name) const
0206 {
0207   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
0208   G4Material* ptr = nullptr;
0209   for (auto& mat : *theMaterialTable) {
0210     if (name == mat->GetName()) {
0211       ptr = mat;
0212       break;
0213     }
0214   }
0215   return ptr;
0216 }
0217 
0218 inline G4Material* G4NistMaterialBuilder::FindSimpleMaterial(G4int Z) const
0219 {
0220   return (Z > 0 && Z < nElementary) ? FindMaterial(names[Z]) : nullptr;
0221 }
0222 
0223 #endif