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 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   G4String elmSymbol[maxNumElements];
0129   G4double atomicMass[maxNumElements];  // amu
0130   G4double bindingEnergy[maxNumElements];
0131   G4int nIsotopes[maxNumElements];
0132   G4int nFirstIsotope[maxNumElements];
0133   G4int idxIsotopes[maxNumElements];
0134 
0135   G4int elmIndex[maxNumElements];
0136 
0137   G4double massIsotopes[maxAbundance];  // G4 units
0138   G4double sigMass[maxAbundance];  // G4 units
0139   G4double relAbundance[maxAbundance];
0140 
0141   G4int index;
0142   G4int verbose;
0143 
0144   std::vector<G4String> elmNames;
0145 };
0146 
0147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0148 
0149 inline G4double G4NistElementBuilder::GetAtomicMassAmu(G4int Z) const
0150 {
0151   return (Z > 0 && Z < maxNumElements) ? atomicMass[Z] : 0.0;
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0155 
0156 inline G4double G4NistElementBuilder::GetIsotopeMass(G4int Z, G4int N) const
0157 {
0158   G4double mass = 0.0;
0159   if (Z > 0 && Z < maxNumElements) {
0160     G4int i = N - nFirstIsotope[Z];
0161     if (i >= 0 && i < nIsotopes[Z]) {
0162       mass = massIsotopes[i + idxIsotopes[Z]];
0163     }
0164   }
0165   return mass;
0166 }
0167 
0168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0169 
0170 inline G4double G4NistElementBuilder::GetAtomicMass(G4int Z, G4int N) const
0171 {
0172   G4double mass = 0.0;
0173   if (Z > 0 && Z < maxNumElements) {
0174     G4int i = N - nFirstIsotope[Z];
0175     if (i >= 0 && i < nIsotopes[Z]) {
0176       mass = massIsotopes[i + idxIsotopes[Z]] + Z * CLHEP::electron_mass_c2 - bindingEnergy[Z];
0177     }
0178   }
0179   return mass;
0180 }
0181 
0182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0183 
0184 inline G4double G4NistElementBuilder::GetTotalElectronBindingEnergy(G4int Z) const
0185 {
0186   return (Z > 0 && Z < maxNumElements) ? bindingEnergy[Z] : 0.0;
0187 }
0188 
0189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0190 
0191 inline G4double G4NistElementBuilder::GetIsotopeAbundance(G4int Z, G4int N) const
0192 {
0193   G4double x = 0.0;
0194   if (Z > 0 && Z < maxNumElements) {
0195     G4int i = N - nFirstIsotope[Z];
0196     if (i >= 0 && i < nIsotopes[Z]) {
0197       x = relAbundance[i + idxIsotopes[Z]];
0198     }
0199   }
0200   return x;
0201 }
0202 
0203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0204 
0205 inline G4int G4NistElementBuilder::GetNistFirstIsotopeN(G4int Z) const
0206 {
0207   return (Z > 0 && Z < maxNumElements) ? nFirstIsotope[Z] : 0;
0208 }
0209 
0210 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0211 
0212 inline G4int G4NistElementBuilder::GetNumberOfNistIsotopes(G4int Z) const
0213 {
0214   return (Z > 0 && Z < maxNumElements) ? nIsotopes[Z] : 0;
0215 }
0216 
0217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0218 
0219 inline const std::vector<G4String>& G4NistElementBuilder::GetElementNames() const
0220 {
0221   return elmNames;
0222 }
0223 
0224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0225 
0226 inline G4int G4NistElementBuilder::GetMaxNumElements() const { return maxNumElements - 1; }
0227 
0228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0229 
0230 inline void G4NistElementBuilder::SetVerbose(G4int val) { verbose = val; }
0231 
0232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0233 
0234 inline G4Element* G4NistElementBuilder::FindElement(G4int Z) const
0235 {
0236   const G4ElementTable* theElementTable = G4Element::GetElementTable();
0237   return (Z > 0 && Z < maxNumElements && elmIndex[Z] >= 0) ? (*theElementTable)[elmIndex[Z]]
0238                                                            : nullptr;
0239 }
0240 
0241 #endif