Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:16:05

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 // G4IonTable
0027 //
0028 // Class description:
0029 //
0030 // G4IonTable stores all pointers to G4ParticleDefinition.
0031 
0032 // Author: H.Kurashige, 27 June 1998
0033 // --------------------------------------------------------------------
0034 #ifndef G4IonTable_hh
0035 #define G4IonTable_hh 1
0036 
0037 #include "G4Ions.hh"
0038 #include "G4ParticleDefinition.hh"
0039 #include "G4ParticleTable.hh"
0040 #include "G4ios.hh"
0041 #include "globals.hh"
0042 
0043 #include <cmath>
0044 #include <map>
0045 #include <vector>
0046 
0047 class G4ParticleTable;
0048 class G4VIsotopeTable;
0049 class G4IsotopeProperty;
0050 class G4NuclideTable;
0051 
0052 class G4IonTable
0053 {
0054   public:
0055     using G4IonList = std::multimap<G4int, const G4ParticleDefinition*>;
0056     using G4IonListIterator = std::multimap<G4int, const G4ParticleDefinition*>::iterator;
0057 
0058     // Constructor, destructor
0059     G4IonTable();
0060     ~G4IonTable();
0061 
0062     // Forbidden copy constructor and assignment operator
0063     G4IonTable(const G4IonTable&) = delete;
0064     G4IonTable& operator=(const G4IonTable&) = delete;
0065 
0066     static G4IonTable* GetIonTable();
0067 
0068     // Method is used by each worker thread to copy the content
0069     // from the master thread.
0070     void WorkerG4IonTable();
0071 
0072     // Destructor for worker
0073     void DestroyWorkerG4IonTable();
0074 
0075     // Get number of elements defined in the IonTable
0076     G4int GetNumberOfElements() const;
0077 
0078     // Register Isotope table
0079     void RegisterIsotopeTable(G4VIsotopeTable* table);
0080 
0081     // G4IonTable asks properties of isotopes to G4VIsotopeTable
0082     // by using FindIsotope(G4IsotopeProperty* property) method
0083     G4VIsotopeTable* GetIsotopeTable(std::size_t idx = 0) const;
0084 
0085     // All ground state ions are created.
0086     // Stable ground states are defined in G4NuclearProperty
0087     void CreateAllIon();
0088 
0089     // All excited ions with long life time (>1.0*ns) are created.
0090     // Isomers are defined in G4VIsotopeTable
0091     void CreateAllIsomer();
0092 
0093     // All nuclide with a life time longer than certain value are created
0094     // prior to the event loop
0095     void PrepareNuclideTable();
0096     void PreloadNuclide();
0097 
0098     // --------------------------------------------------------------
0099     // FindIon/GetIon
0100     //   FindIon() methods return pointer of ion if it exists.
0101     //   GetIon() methods also return pointer of ion; the designated
0102     //   ion is created if it does not exist.
0103     //
0104     // !! PDGCharge in G4ParticleDefinition of ions is          !!
0105     // !! electric charge of nucleus (i.e. fully ionized ions)  !!
0106     // --------------------------------------------------------------
0107 
0108     // Find/Get "ground state" and "excited state"
0109     //
0110     G4ParticleDefinition* GetIon(G4int Z, G4int A, G4int lvl = 0);
0111     G4ParticleDefinition* GetIon(G4int Z, G4int A, G4int nL, G4int lvl);
0112     G4ParticleDefinition* GetIon(G4int Z, G4int A, G4double E, G4int J = 0);
0113     G4ParticleDefinition* GetIon(G4int Z, G4int A, G4double E, G4Ions::G4FloatLevelBase flb,
0114                                  G4int J = 0);
0115     G4ParticleDefinition* GetIon(G4int Z, G4int A, G4double E, char flbChar, G4int J = 0);
0116     G4ParticleDefinition* GetIon(G4int Z, G4int A, G4int nL, G4double E, G4int J = 0);
0117     G4ParticleDefinition* GetIon(G4int Z, G4int A, G4int nL, G4double E,
0118                                  G4Ions::G4FloatLevelBase flb, G4int J = 0);
0119     G4ParticleDefinition* GetIon(G4int Z, G4int A, G4int nL, G4double E, char flbChar, G4int J = 0);
0120     // Z: Atomic Number
0121     // A: Atomic Mass (nn + np +nlambda)
0122     // nL: Number of Lambda
0123     // E: Excitation energy
0124     // lvl:  Isomer Level 0: ground state)
0125     // flb:  Floating level base (enum defined in G4Ions.hh)
0126     // flbChar:  Floating level base denoted by a character
0127     //           (<null>,X,Y,Z,U,V,W,R,S,T,A,B,C,D,E)
0128     // J: Total Angular momentum (in unit of 1/2) : not used
0129 
0130     // The ion can be retrieved by using PDG encoding
0131     // !! Only ground state can be obtained .i.e. Isomer = 0
0132     G4ParticleDefinition* GetIon(G4int encoding);
0133 
0134     // Find/Get "excited state"
0135     //
0136     G4ParticleDefinition* FindIon(G4int Z, G4int A, G4int lvl = 0);
0137     G4ParticleDefinition* FindIon(G4int Z, G4int A, G4int nL, G4int lvl);
0138     G4ParticleDefinition* FindIon(G4int Z, G4int A, G4double E, G4int J = 0);
0139     G4ParticleDefinition* FindIon(G4int Z, G4int A, G4double E, G4Ions::G4FloatLevelBase flb,
0140                                   G4int J = 0);
0141     G4ParticleDefinition* FindIon(G4int Z, G4int A, G4double E, char flbChar, G4int J = 0);
0142     G4ParticleDefinition* FindIon(G4int Z, G4int A, G4int nL, G4double E, G4int J = 0);
0143     G4ParticleDefinition* FindIon(G4int Z, G4int A, G4int nL, G4double E,
0144                                   G4Ions::G4FloatLevelBase flb, G4int J = 0);
0145     G4ParticleDefinition* FindIon(G4int Z, G4int A, G4int nL, G4double E, char flbChar,
0146                                   G4int J = 0);
0147     // Z: Atomic Number
0148     // A: Atomic Mass (nn + np +nlambda)
0149     // nL: Number of Lambda
0150     // E: Excitaion energy
0151     // lvl:  Isomer Level 0: ground state)
0152     // flb:  Floating level base (enum defined in G4Ions.hh)
0153     // flbChar:  Floating level base denoted by a character
0154     //           (<null>,X,Y,Z,U,V,W,R,S,T,A,B,C,D,E)
0155     // J: Total Angular momentum (in unit of 1/2) : not used
0156 
0157     // Return true if the particle is ion
0158     static G4bool IsIon(const G4ParticleDefinition*);
0159 
0160     // Return true if the particle is anti_ion
0161     static G4bool IsAntiIon(const G4ParticleDefinition*);
0162 
0163     // Get ion name
0164     G4String GetIonName(G4int Z, G4int A, G4int lvl = 0) const;
0165     G4String GetIonName(G4int Z, G4int A, G4double E,
0166                         G4Ions::G4FloatLevelBase flb = G4Ions::G4FloatLevelBase::no_Float) const;
0167     G4String GetIonName(G4int Z, G4int A, G4int nL, G4double E,
0168                         G4Ions::G4FloatLevelBase flb = G4Ions::G4FloatLevelBase::no_Float) const;
0169     G4String GetIonName(G4int Z, G4int A, G4int nL, G4int lvl) const;
0170 
0171     // Get PDG code for Ions.
0172     // Nuclear codes are given as 10-digit numbers +-100ZZZAAAI.
0173     // For a nucleus consisting of np protons and nn neutrons
0174     // A = np + nn and Z = np.
0175     // I gives the isomer level, with I = 0 corresponding
0176     // to the ground state and I >0 to excitations
0177     static G4int GetNucleusEncoding(G4int Z, G4int A, G4double E = 0.0, G4int lvl = 0);
0178 
0179     // Get PDG code for Hyper-Nucleus Ions.
0180     // Nuclear codes are given as 10-digit numbers +-10LZZZAAAI.
0181     // For a nucleus consisting of np protons and nn neutrons
0182     // A = np + nn +nlambda and Z = np.
0183     // nL = nlambda
0184     // I gives the isomer level, with I = 0 corresponding
0185     // to the ground state and I >0 to excitations
0186     static G4int GetNucleusEncoding(G4int Z, G4int A, G4int nL, G4double E = 0.0, G4int lvl = 0);
0187 
0188     static G4bool GetNucleusByEncoding(G4int encoding, G4int& Z, G4int& A, G4double& E, G4int& lvl);
0189     static G4bool GetNucleusByEncoding(G4int encoding, G4int& Z, G4int& A, G4int& L, G4double& E,
0190                                        G4int& lvl);
0191     // Energy will not be given even for excited state!!
0192 
0193     // These methods returns Nucleus (i.e. full ionized atom) mass, where
0194     //  Z is Atomic Number (number of protons) and
0195     //  A is Atomic Number (number of nucleons and hyperons)
0196     //  nL is number of lambda (A= nn + np + nlambda)
0197     //  lvl is isomer level
0198     G4double GetIonMass(G4int Z, G4int A, G4int nL = 0, G4int lvl = 0) const;
0199     G4double GetNucleusMass(G4int Z, G4int A, G4int nL = 0, G4int lvl = 0) const;
0200     G4double GetIsomerMass(G4int Z, G4int A, G4int lvl = 0) const;
0201 
0202     // Returns a life time of an ion. -1 for stable ion, and -1001 for ion
0203     // that is not listed in G4NuclideTable
0204     G4double GetLifeTime(const G4ParticleDefinition*) const;
0205     G4double GetLifeTime(G4int Z, G4int A, G4double E,
0206                          G4Ions::G4FloatLevelBase flb = G4Ions::G4FloatLevelBase::no_Float) const;
0207     G4double GetLifeTime(G4int Z, G4int A, G4double E, char flbChar) const;
0208 
0209     G4ParticleDefinition* GetMuonicAtom(G4Ions const*);
0210     G4ParticleDefinition* GetMuonicAtom(G4int Z, G4int A);
0211 
0212     // Return number of ions in the table
0213     G4int Entries() const;
0214 
0215     // Return the pointer of index-th ion in the table
0216     G4ParticleDefinition* GetParticle(G4int index) const;
0217 
0218     // Return 'true' if the ion exists
0219     G4bool Contains(const G4ParticleDefinition* particle) const;
0220 
0221     // Insert/Remove an ion in the table
0222     void Insert(const G4ParticleDefinition* particle);
0223     void Remove(const G4ParticleDefinition* particle);
0224 
0225     // Erase all contents in the list (not delete just remove)
0226     void clear();
0227 
0228     // Return number of ions in the table
0229     G4int size() const;
0230 
0231     // Dump information of particles specified by name
0232     void DumpTable(const G4String& particle_name = "ALL") const;
0233 
0234   public:
0235     // Needed for MT
0236     void InitializeLightIons();
0237 
0238     // It is very important for multithreaded Geant4 to keep only one copy of
0239     // the particle table pointer and the ion table pointer. However, we try
0240     // to let each worker thread hold its own copy of the particle dictionary
0241     // and the ion list. This implementation is equivalent to make the ion
0242     // table thread private. The two shadow ponters are used by each worker
0243     // thread to copy the content from the master thread
0244     static G4ThreadLocal G4IonList* fIonList;
0245     static G4ThreadLocal std::vector<G4VIsotopeTable*>* fIsotopeTableList;
0246     static G4IonList* fIonListShadow;
0247     static std::vector<G4VIsotopeTable*>* fIsotopeTableListShadow;
0248 
0249     enum
0250     {
0251       numberOfElements = 118
0252     };
0253     static const G4String elementName[numberOfElements];
0254 
0255 #ifdef G4MULTITHREADED
0256     static G4Mutex ionTableMutex;
0257 #endif
0258 
0259   protected:
0260     G4ParticleDefinition* FindIonInMaster(G4int Z, G4int A, G4int lvl = 0);
0261     G4ParticleDefinition* FindIonInMaster(G4int Z, G4int A, G4int nL, G4int lvl);
0262     G4ParticleDefinition* FindIonInMaster(G4int Z, G4int A, G4double E,
0263                                           G4Ions::G4FloatLevelBase flb, G4int J = 0);
0264     G4ParticleDefinition* FindIonInMaster(G4int Z, G4int A, G4int nL, G4double E,
0265                                           G4Ions::G4FloatLevelBase flb, G4int J = 0);
0266 
0267     G4ParticleDefinition* CreateIon(G4int Z, G4int A, G4double E, G4Ions::G4FloatLevelBase flb);
0268     G4ParticleDefinition* CreateIon(G4int Z, G4int A, G4int nL, G4double E,
0269                                     G4Ions::G4FloatLevelBase flb);
0270     G4ParticleDefinition* CreateIon(G4int Z, G4int A, G4int lvl = 0);
0271     G4ParticleDefinition* CreateIon(G4int Z, G4int A, G4int nL, G4int lvl);
0272 
0273     void InsertWorker(const G4ParticleDefinition* particle);
0274 
0275     // Create Ion
0276 
0277     G4IsotopeProperty* FindIsotope(G4int Z, G4int A, G4double E,
0278                                    G4Ions::G4FloatLevelBase flb) const;
0279     G4IsotopeProperty* FindIsotope(G4int Z, G4int A, G4int lvl) const;
0280     // Ask properties of isotopes
0281 
0282     G4ParticleDefinition* GetLightIon(G4int Z, G4int A) const;
0283     G4ParticleDefinition* GetLightAntiIon(G4int Z, G4int A) const;
0284 
0285     // Return true if the particle is pre-defined ion
0286     G4bool IsLightIon(const G4ParticleDefinition*) const;
0287     G4bool IsLightAntiIon(const G4ParticleDefinition*) const;
0288 
0289     // Add process manager to ions with name of 'ionName'
0290     void AddProcessManager(G4ParticleDefinition*);
0291 
0292     // Get Verbose Level defined in G4ParticleTable
0293     G4int GetVerboseLevel() const;
0294 
0295   private:
0296     G4NuclideTable* pNuclideTable = nullptr;
0297 
0298     // Isomer table and flag of creation
0299     G4bool isIsomerCreated = false;
0300 };
0301 
0302 // ------------------------
0303 // Inline methods
0304 // ------------------------
0305 
0306 inline G4int G4IonTable::GetNumberOfElements() const
0307 {
0308   return numberOfElements;
0309 }
0310 
0311 #endif