Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-02 09:04:28

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 //
0028 // GEANT4 Class file
0029 //
0030 // Description: Data structure for cross sections, shell cross sections,
0031 //              isotope cross sections. Data access via integer variable
0032 //              Z (atomic number in majority of applications), which may
0033 //              be in the interval 0 <= Z < length. For isotope like
0034 //              data a second parameter idx or data ID code are used.
0035 //              In most cases ID = A - atomic weight number.
0036 //              There are run time const methods, in which input is not checked
0037 //              assuming responsibility of consumer code. Another run time
0038 //              check input and may throwgh a fatal exception
0039 //
0040 // Author:      V.Ivanchenko 10.03.2011
0041 //
0042 // Modifications: 30.09.2023 Extended functionality, data size defined in constructor
0043 //
0044 //----------------------------------------------------------------------------
0045 //
0046 
0047 #ifndef G4ElementData_h
0048 #define G4ElementData_h 1
0049 
0050 #include "G4Physics2DVector.hh"
0051 #include "G4PhysicsVector.hh"
0052 #include "globals.hh"
0053 
0054 #include <vector>
0055 
0056 class G4ElementDataRegistry;
0057 
0058 class G4ElementData
0059 {
0060  public:
0061   explicit G4ElementData(G4int length = 99);
0062 
0063   ~G4ElementData();
0064 
0065   // Assignment operator and copy constructor
0066   G4ElementData& operator=(const G4ElementData& right) = delete;
0067   G4ElementData(const G4ElementData&) = delete;
0068 
0069   // reservation of memory for better data layout
0070   void Reserve1D(std::size_t);
0071   void Reserve2D(std::size_t);
0072   
0073   // add cross section for the element
0074   void InitialiseForElement(G4int Z, G4PhysicsVector* v);
0075 
0076   // add 2D cross section for the element
0077   void InitialiseForElement(G4int Z, G4Physics2DVector* v);
0078 
0079   // reserve vector of components
0080   void InitialiseForComponent(G4int Z, G4int nComponents = 0);
0081 
0082   // reserve vector of 2D components
0083   void InitialiseFor2DComponent(G4int Z, G4int nComponents = 0);
0084 
0085   // prepare vector of components
0086   void AddComponent(G4int Z, G4int id, G4PhysicsVector* v);
0087 
0088   // prepare vector of 2D components
0089   void Add2DComponent(G4int Z, G4int id, G4Physics2DVector* v);
0090 
0091   // make new 1D free vector
0092   G4PhysicsVector* New1DVector(G4int Z, G4int ne);
0093 
0094   // make new 2D vector
0095   G4Physics2DVector* New2DVector(G4int Z, G4int ny, G4int ne);
0096 
0097   // set name of the dataset (optional)
0098   inline void SetName(const G4String& nam);
0099 
0100   //--------------------------------------------------------------
0101   // run time const methods - no check on validity of input
0102   // it is a responsibility of the consume code to check the input
0103   //--------------------------------------------------------------
0104 
0105   // get name of the dataset
0106   inline const G4String& GetName() const;
0107 
0108   // get vector for the element
0109   inline G4PhysicsVector* GetElementData(G4int Z) const;
0110 
0111   // get 2-D vector for the element
0112   inline G4Physics2DVector* GetElement2DData(G4int Z) const;
0113 
0114   // get vector per shell or per isotope
0115   inline G4PhysicsVector* GetComponentDataByID(G4int Z, G4int id) const;
0116 
0117   // get vector per shell or per isotope
0118   inline G4Physics2DVector* Get2DComponentDataByID(G4int Z, G4int id) const;
0119 
0120   // return cross section per element
0121   inline G4double GetValueForElement(G4int Z, G4double kinEnergy) const;
0122 
0123   //--------------------------------------------------------------
0124   // run time const methods with input parameters control
0125   //--------------------------------------------------------------
0126 
0127   // get number of components for the element
0128   inline std::size_t GetNumberOfComponents(G4int Z) const;
0129 
0130   // get number of 2D components for the element
0131   inline std::size_t GetNumberOf2DComponents(G4int Z) const;
0132 
0133   // get component ID which may be number of nucleons,
0134   // or shell number, or any other integer
0135   inline G4int GetComponentID(G4int Z, std::size_t idx) const;
0136 
0137   // get vector per shell or per isotope
0138   inline G4PhysicsVector*
0139   GetComponentDataByIndex(G4int Z, std::size_t idx) const;
0140 
0141   // get vector per shell or per isotope
0142   inline G4Physics2DVector*
0143   Get2DComponentDataByIndex(G4int Z, std::size_t idx) const;
0144 
0145   // return cross section per element
0146   // if not available return zero
0147   inline G4double
0148   GetValueForComponent(G4int Z, std::size_t idx, G4double kinEnergy) const;
0149 
0150  private:
0151 
0152   void DataError(G4int Z, const G4String&);
0153 
0154   const G4int maxNumElm;
0155 
0156   G4ElementDataRegistry* fRegistry{nullptr};
0157 
0158   std::vector<G4PhysicsVector*> elmData;
0159   std::vector<std::vector<std::pair<G4int, G4PhysicsVector*> >* > compData;
0160 
0161   std::vector<G4Physics2DVector*> elm2Data;
0162   std::vector<std::vector<std::pair<G4int, G4Physics2DVector*> >* > comp2D;
0163 
0164   G4String name{""};
0165 };
0166 
0167 //--------------------------------------------------------------
0168 // run time const methods without check on validity of input
0169 //--------------------------------------------------------------
0170 
0171 inline void G4ElementData::SetName(const G4String& nam)
0172 {
0173   name = nam;
0174 }
0175 
0176 inline const G4String& G4ElementData::GetName() const
0177 {
0178   return name;
0179 }
0180 
0181 inline G4PhysicsVector* G4ElementData::GetElementData(G4int Z) const
0182 {
0183   return elmData[Z];
0184 }
0185 
0186 inline G4Physics2DVector* G4ElementData::GetElement2DData(G4int Z) const
0187 {
0188   return elm2Data[Z];
0189 }
0190 
0191 inline G4PhysicsVector*
0192 G4ElementData::GetComponentDataByID(G4int Z, G4int id) const
0193 {
0194   G4PhysicsVector* v = nullptr;
0195   for (auto const & p : *(compData[Z])) {
0196     if (id == p.first) {
0197       v = p.second;
0198       break;
0199     }
0200   }
0201   return v;
0202 }
0203 
0204 inline G4Physics2DVector*
0205 G4ElementData::Get2DComponentDataByID(G4int Z, G4int id) const
0206 {
0207   G4Physics2DVector* v = nullptr;
0208   for (auto const & p : *(comp2D[Z])) {
0209     if (id == p.first) {
0210       v = p.second;
0211       break;
0212     }
0213   }
0214   return v;
0215 }
0216 
0217 inline G4double
0218 G4ElementData::GetValueForElement(G4int Z, G4double kinEnergy) const
0219 {
0220   return elmData[Z]->Value(kinEnergy);
0221 }
0222 
0223 //--------------------------------------------------------------
0224 // run time const methods with check on validity of input
0225 //--------------------------------------------------------------
0226 
0227 inline std::size_t G4ElementData::GetNumberOfComponents(G4int Z) const
0228 {
0229   return (nullptr != compData[Z]) ? compData[Z]->size() : 0;
0230 }
0231 
0232 inline std::size_t G4ElementData::GetNumberOf2DComponents(G4int Z) const
0233 {
0234   return (nullptr != comp2D[Z]) ? comp2D[Z]->size() : 0;
0235 }
0236 
0237 inline G4int G4ElementData::GetComponentID(G4int Z, std::size_t idx) const
0238 {
0239   return (idx < GetNumberOfComponents(Z)) ? (*(compData[Z]))[idx].first : 0;
0240 }
0241 
0242 inline G4PhysicsVector*
0243 G4ElementData::GetComponentDataByIndex(G4int Z, std::size_t idx) const
0244 {
0245   return
0246     (idx < GetNumberOfComponents(Z)) ? (*(compData[Z]))[idx].second : nullptr;
0247 }
0248 
0249 inline G4Physics2DVector*
0250 G4ElementData::Get2DComponentDataByIndex(G4int Z, std::size_t idx) const
0251 {
0252   return
0253     (idx < GetNumberOf2DComponents(Z)) ? (*(comp2D[Z]))[idx].second : nullptr;
0254 }
0255 
0256 inline G4double
0257 G4ElementData::GetValueForComponent(G4int Z, std::size_t idx, G4double e) const
0258 {
0259   return (idx < GetNumberOfComponents(Z)) ?
0260       (*(compData[Z]))[idx].second->Value(e) : 0.0;
0261 }
0262 
0263 #endif