Back to home page

EIC code displayed by LXR

 
 

    


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

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 G4ElementData
0057 {
0058  public:
0059   explicit G4ElementData(G4int length = 99);
0060 
0061   ~G4ElementData();
0062 
0063   // Assignment operator and copy constructor
0064   G4ElementData& operator=(const G4ElementData& right) = delete;
0065   G4ElementData(const G4ElementData&) = delete;
0066 
0067   // add cross section for the element
0068   void InitialiseForElement(G4int Z, G4PhysicsVector* v);
0069 
0070   // add 2D cross section for the element
0071   void InitialiseForElement(G4int Z, G4Physics2DVector* v);
0072 
0073   // reserve vector of components
0074   void InitialiseForComponent(G4int Z, G4int nComponents = 0);
0075 
0076   // reserve vector of 2D components
0077   void InitialiseFor2DComponent(G4int Z, G4int nComponents = 0);
0078 
0079   // prepare vector of components
0080   void AddComponent(G4int Z, G4int id, G4PhysicsVector* v);
0081 
0082   // prepare vector of 2D components
0083   void Add2DComponent(G4int Z, G4int id, G4Physics2DVector* v);
0084 
0085   // set name of the dataset (optional)
0086   inline void SetName(const G4String& nam);
0087 
0088   //--------------------------------------------------------------
0089   // run time const methods - no check on validity of input
0090   // it is a responsibility of the consume code to check the input
0091   //--------------------------------------------------------------
0092 
0093   // get name of the dataset
0094   inline const G4String& GetName() const;
0095 
0096   // get vector for the element
0097   inline G4PhysicsVector* GetElementData(G4int Z) const;
0098 
0099   // get 2-D vector for the element
0100   inline G4Physics2DVector* GetElement2DData(G4int Z) const;
0101 
0102   // get vector per shell or per isotope
0103   inline G4PhysicsVector* GetComponentDataByID(G4int Z, G4int id) const;
0104 
0105   // get vector per shell or per isotope
0106   inline G4Physics2DVector* Get2DComponentDataByID(G4int Z, G4int id) const;
0107 
0108   // return cross section per element
0109   inline G4double GetValueForElement(G4int Z, G4double kinEnergy) const;
0110 
0111   //--------------------------------------------------------------
0112   // run time const methods with input parameters control
0113   //--------------------------------------------------------------
0114 
0115   // get number of components for the element
0116   inline std::size_t GetNumberOfComponents(G4int Z) const;
0117 
0118   // get number of 2D components for the element
0119   inline std::size_t GetNumberOf2DComponents(G4int Z) const;
0120 
0121   // get component ID which may be number of nucleons,
0122   // or shell number, or any other integer
0123   inline G4int GetComponentID(G4int Z, std::size_t idx) const;
0124 
0125   // get vector per shell or per isotope
0126   inline G4PhysicsVector*
0127   GetComponentDataByIndex(G4int Z, std::size_t idx) const;
0128 
0129   // get vector per shell or per isotope
0130   inline G4Physics2DVector*
0131   Get2DComponentDataByIndex(G4int Z, std::size_t idx) const;
0132 
0133   // return cross section per element
0134   // if not available return zero
0135   inline G4double
0136   GetValueForComponent(G4int Z, std::size_t idx, G4double kinEnergy) const;
0137 
0138  private:
0139 
0140   void DataError(G4int Z, const G4String&);
0141 
0142   const G4int maxNumElm;
0143 
0144   std::vector<G4PhysicsVector*> elmData;
0145   std::vector<G4Physics2DVector*> elm2Data;
0146   std::vector<std::vector<std::pair<G4int, G4PhysicsVector*> >* > compData;
0147   std::vector<std::vector<std::pair<G4int, G4Physics2DVector*> >* > comp2D;
0148 
0149   G4String name{""};
0150 };
0151 
0152 //--------------------------------------------------------------
0153 // run time const methods without check on validity of input
0154 //--------------------------------------------------------------
0155 
0156 inline void G4ElementData::SetName(const G4String& nam)
0157 {
0158   name = nam;
0159 }
0160 
0161 inline const G4String& G4ElementData::GetName() const
0162 {
0163   return name;
0164 }
0165 
0166 inline G4PhysicsVector* G4ElementData::GetElementData(G4int Z) const
0167 {
0168   return elmData[Z];
0169 }
0170 
0171 inline G4Physics2DVector* G4ElementData::GetElement2DData(G4int Z) const
0172 {
0173   return elm2Data[Z];
0174 }
0175 
0176 inline G4PhysicsVector*
0177 G4ElementData::GetComponentDataByID(G4int Z, G4int id) const
0178 {
0179   G4PhysicsVector* v = nullptr;
0180   for (auto const & p : *(compData[Z])) {
0181     if (id == p.first) {
0182       v = p.second;
0183       break;
0184     }
0185   }
0186   return v;
0187 }
0188 
0189 inline G4Physics2DVector*
0190 G4ElementData::Get2DComponentDataByID(G4int Z, G4int id) const
0191 {
0192   G4Physics2DVector* v = nullptr;
0193   for (auto const & p : *(comp2D[Z])) {
0194     if (id == p.first) {
0195       v = p.second;
0196       break;
0197     }
0198   }
0199   return v;
0200 }
0201 
0202 inline G4double
0203 G4ElementData::GetValueForElement(G4int Z, G4double kinEnergy) const
0204 {
0205   return elmData[Z]->Value(kinEnergy);
0206 }
0207 
0208 //--------------------------------------------------------------
0209 // run time const methods with check on validity of input
0210 //--------------------------------------------------------------
0211 
0212 inline std::size_t G4ElementData::GetNumberOfComponents(G4int Z) const
0213 {
0214   return (nullptr != compData[Z]) ? compData[Z]->size() : 0;
0215 }
0216 
0217 inline std::size_t G4ElementData::GetNumberOf2DComponents(G4int Z) const
0218 {
0219   return (nullptr != comp2D[Z]) ? comp2D[Z]->size() : 0;
0220 }
0221 
0222 inline G4int G4ElementData::GetComponentID(G4int Z, std::size_t idx) const
0223 {
0224   return (idx < GetNumberOfComponents(Z)) ? (*(compData[Z]))[idx].first : 0;
0225 }
0226 
0227 inline G4PhysicsVector*
0228 G4ElementData::GetComponentDataByIndex(G4int Z, std::size_t idx) const
0229 {
0230   return
0231     (idx < GetNumberOfComponents(Z)) ? (*(compData[Z]))[idx].second : nullptr;
0232 }
0233 
0234 inline G4Physics2DVector*
0235 G4ElementData::Get2DComponentDataByIndex(G4int Z, std::size_t idx) const
0236 {
0237   return
0238     (idx < GetNumberOf2DComponents(Z)) ? (*(comp2D[Z]))[idx].second : nullptr;
0239 }
0240 
0241 inline G4double
0242 G4ElementData::GetValueForComponent(G4int Z, std::size_t idx, G4double e) const
0243 {
0244   return (idx < GetNumberOfComponents(Z)) ?
0245       (*(compData[Z]))[idx].second->Value(e) : 0.0;
0246 }
0247 
0248 #endif