Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:56:31

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 G4NistElementBuilder_h
0028 #define G4NistElementBuilder_h 1
0029 
0030 //---------------------------------------------------------------------------
0031 //
0032 // ClassName:   G4NistElementBuilder
0033 //
0034 // Description: Utility class to hold and manipulate G4Elements defined from
0035 //              Nist data base
0036 //
0037 // Author:      V.Ivanchenko 21.11.2004
0038 //
0039 // Modifications:
0040 // 27.02.06 V.Ivanchenko Return m=0 if Z&N combination is out of NIST
0041 // 27.02.06 V.Ivanchenko add GetAtomicMassAmu
0042 // 17.10.06 V.Ivanchenko add GetAtomicMass and GetNistElementNames methods
0043 // 02.05.07 V.Ivanchenko add GetNistFirstIsotopeN and GetNumberOfNistIsotopes
0044 // 06.08.08 V.Ivanchenko add binding energy parameterisation and use isotope
0045 //                       mass in G4 units
0046 //
0047 // Class Description:
0048 //
0049 // Element data from the NIST DB on Atomic Weights and Isotope Compositions
0050 // http://physics.nist.gov/PhysRefData/Compositions/index.html
0051 //
0052 
0053 #include "G4Element.hh"
0054 #include "globals.hh"
0055 
0056 #include <CLHEP/Units/PhysicalConstants.h>
0057 
0058 #include <vector>
0059 
0060 const G4int maxNumElements = 108;
0061 const G4int maxAbundance = 3500;
0062 
0063 class G4NistElementBuilder
0064 {
0065  public:
0066   explicit G4NistElementBuilder(G4int vb);
0067   ~G4NistElementBuilder() = default;
0068 
0069   // Find or build a G4Element by atomic number
0070   inline G4Element* FindElement(G4int Z) const;
0071   G4Element* FindOrBuildElement(G4int Z, G4bool buildIsotopes = true);
0072 
0073   // Find  or build a G4Element by symbol
0074   G4Element* FindOrBuildElement(const G4String& symb, G4bool buildIsotopes = true);
0075   // print element information
0076   void PrintElement(G4int Z) const;
0077 
0078   // Access to the vector of Geant4 predefined element names
0079   const std::vector<G4String>& GetElementNames() const;
0080 
0081   // Get atomic number by element symbol
0082   G4int GetZ(const G4String& symb) const;
0083 
0084   // Get atomic weight in atomic units by element symbol
0085   G4double GetAtomicMassAmu(const G4String& symb) const;
0086 
0087   // Get atomic weight in atomic units - mean mass in units of amu of an atom
0088   // with electron shell for the natural isotope composition
0089   inline G4double GetAtomicMassAmu(G4int Z) const;
0090 
0091   // Get mass of isotope without electron shell in Geant4 energy units
0092   inline G4double GetIsotopeMass(G4int Z, G4int N) const;
0093 
0094   // Get mass in Geant4 energy units of an atom of a particular isotope
0095   // with the electron shell
0096   inline G4double GetAtomicMass(G4int Z, G4int N) const;
0097 
0098   // Get total ionisation energy of an atom
0099   inline G4double GetTotalElectronBindingEnergy(G4int Z) const;
0100 
0101   // Get natural isotope abundance
0102   inline G4double GetIsotopeAbundance(G4int Z, G4int N) const;
0103 
0104   // Get N for the first natural isotope
0105   inline G4int GetNistFirstIsotopeN(G4int Z) const;
0106 
0107   // Get number of natural isotopes
0108   inline G4int GetNumberOfNistIsotopes(G4int Z) const;
0109 
0110   // Get max Z in the Geant4 element database
0111   inline G4int GetMaxNumElements() const;
0112 
0113   inline void SetVerbose(G4int);
0114 
0115  private:
0116   void Initialise();
0117 
0118   // Add element parameters to internal G4 database:
0119   // Z - atomic number, N - number of nucleons, A - atomic mass (amu),
0120   // sigmaA - accuracy of mass in last digits, W - natural abundances (percent)
0121   void AddElement(const G4String& symbol, G4int Z, G4int NumberOfIsotopes, const G4int& N,
0122     const G4double& A, const G4double& sigmaA, const G4double& W);
0123 
0124   // Build a G4Element from the G4 dataBase
0125   G4Element* BuildElement(G4int Z);
0126 
0127  private:
0128   G4double atomicMass[maxNumElements];  // amu
0129   G4double bindingEnergy[maxNumElements];
0130   G4int nIsotopes[maxNumElements];
0131   G4int nFirstIsotope[maxNumElements];
0132   G4int idxIsotopes[maxNumElements];
0133 
0134   G4int elmIndex[maxNumElements];
0135 
0136   G4double massIsotopes[maxAbundance];  // G4 units
0137   G4double sigMass[maxAbundance];  // G4 units
0138   G4double relAbundance[maxAbundance];
0139 
0140   G4int index;
0141   G4int verbose;
0142 
0143   std::vector<G4String> elmSymbol;
0144 };
0145 
0146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0147 
0148 inline G4double G4NistElementBuilder::GetAtomicMassAmu(G4int Z) const
0149 {
0150   return (Z > 0 && Z < maxNumElements) ? atomicMass[Z] : 0.0;
0151 }
0152 
0153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0154 
0155 inline G4double G4NistElementBuilder::GetIsotopeMass(G4int Z, G4int N) const
0156 {
0157   G4double mass = 0.0;
0158   if (Z > 0 && Z < maxNumElements) {
0159     G4int i = N - nFirstIsotope[Z];
0160     if (i >= 0 && i < nIsotopes[Z]) {
0161       mass = massIsotopes[i + idxIsotopes[Z]];
0162     }
0163   }
0164   return mass;
0165 }
0166 
0167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0168 
0169 inline G4double G4NistElementBuilder::GetAtomicMass(G4int Z, G4int N) const
0170 {
0171   G4double mass = 0.0;
0172   if (Z > 0 && Z < maxNumElements) {
0173     G4int i = N - nFirstIsotope[Z];
0174     if (i >= 0 && i < nIsotopes[Z]) {
0175       mass = massIsotopes[i + idxIsotopes[Z]] + Z * CLHEP::electron_mass_c2 - bindingEnergy[Z];
0176     }
0177   }
0178   return mass;
0179 }
0180 
0181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0182 
0183 inline G4double G4NistElementBuilder::GetTotalElectronBindingEnergy(G4int Z) const
0184 {
0185   return (Z > 0 && Z < maxNumElements) ? bindingEnergy[Z] : 0.0;
0186 }
0187 
0188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0189 
0190 inline G4double G4NistElementBuilder::GetIsotopeAbundance(G4int Z, G4int N) const
0191 {
0192   G4double x = 0.0;
0193   if (Z > 0 && Z < maxNumElements) {
0194     G4int i = N - nFirstIsotope[Z];
0195     if (i >= 0 && i < nIsotopes[Z]) {
0196       x = relAbundance[i + idxIsotopes[Z]];
0197     }
0198   }
0199   return x;
0200 }
0201 
0202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0203 
0204 inline G4int G4NistElementBuilder::GetNistFirstIsotopeN(G4int Z) const
0205 {
0206   return (Z > 0 && Z < maxNumElements) ? nFirstIsotope[Z] : 0;
0207 }
0208 
0209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0210 
0211 inline G4int G4NistElementBuilder::GetNumberOfNistIsotopes(G4int Z) const
0212 {
0213   return (Z > 0 && Z < maxNumElements) ? nIsotopes[Z] : 0;
0214 }
0215 
0216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0217 
0218 inline const std::vector<G4String>& G4NistElementBuilder::GetElementNames() const
0219 {
0220   return elmSymbol;
0221 }
0222 
0223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0224 
0225 inline G4int G4NistElementBuilder::GetMaxNumElements() const { return maxNumElements - 1; }
0226 
0227 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0228 
0229 inline void G4NistElementBuilder::SetVerbose(G4int val) { verbose = val; }
0230 
0231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0232 
0233 inline G4Element* G4NistElementBuilder::FindElement(G4int Z) const
0234 {
0235   const G4ElementTable* theElementTable = G4Element::GetElementTable();
0236   return (Z > 0 && Z < maxNumElements && elmIndex[Z] >= 0) ? (*theElementTable)[elmIndex[Z]]
0237                                                            : nullptr;
0238 }
0239 
0240 #endif