Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 26 //--------------------------------------------------------------------------- 27 // 28 // GEANT4 Class file 29 // 30 // Description: Data structure for cross sections, shell cross sections, 31 // isotope cross sections. Data access via integer variable 32 // Z (atomic number in majority of applications), which may 33 // be in the interval 0 <= Z < length. For isotope like 34 // data a second parameter idx or data ID code are used. 35 // In most cases ID = A - atomic weight number. 36 // There are run time const methods, in which input is not checked 37 // assuming responsibility of consumer code. Another run time 38 // check input and may throwgh a fatal exception 39 // 40 // Author: V.Ivanchenko 10.03.2011 41 // 42 // Modifications: 30.09.2023 Extended functionality, data size defined in constructor 43 // 44 //---------------------------------------------------------------------------- 45 // 46 47 #ifndef G4ElementData_h 48 #define G4ElementData_h 1 49 50 #include "G4Physics2DVector.hh" 51 #include "G4PhysicsVector.hh" 52 #include "globals.hh" 53 54 #include <vector> 55 56 class G4ElementData 57 { 58 public: 59 explicit G4ElementData(G4int length = 99); 60 61 ~G4ElementData(); 62 63 // Assignment operator and copy constructor 64 G4ElementData& operator=(const G4ElementData& right) = delete; 65 G4ElementData(const G4ElementData&) = delete; 66 67 // add cross section for the element 68 void InitialiseForElement(G4int Z, G4PhysicsVector* v); 69 70 // add 2D cross section for the element 71 void InitialiseForElement(G4int Z, G4Physics2DVector* v); 72 73 // reserve vector of components 74 void InitialiseForComponent(G4int Z, G4int nComponents = 0); 75 76 // reserve vector of 2D components 77 void InitialiseFor2DComponent(G4int Z, G4int nComponents = 0); 78 79 // prepare vector of components 80 void AddComponent(G4int Z, G4int id, G4PhysicsVector* v); 81 82 // prepare vector of 2D components 83 void Add2DComponent(G4int Z, G4int id, G4Physics2DVector* v); 84 85 // set name of the dataset (optional) 86 inline void SetName(const G4String& nam); 87 88 //-------------------------------------------------------------- 89 // run time const methods - no check on validity of input 90 // it is a responsibility of the consume code to check the input 91 //-------------------------------------------------------------- 92 93 // get name of the dataset 94 inline const G4String& GetName() const; 95 96 // get vector for the element 97 inline G4PhysicsVector* GetElementData(G4int Z) const; 98 99 // get 2-D vector for the element 100 inline G4Physics2DVector* GetElement2DData(G4int Z) const; 101 102 // get vector per shell or per isotope 103 inline G4PhysicsVector* GetComponentDataByID(G4int Z, G4int id) const; 104 105 // get vector per shell or per isotope 106 inline G4Physics2DVector* Get2DComponentDataByID(G4int Z, G4int id) const; 107 108 // return cross section per element 109 inline G4double GetValueForElement(G4int Z, G4double kinEnergy) const; 110 111 //-------------------------------------------------------------- 112 // run time const methods with input parameters control 113 //-------------------------------------------------------------- 114 115 // get number of components for the element 116 inline std::size_t GetNumberOfComponents(G4int Z) const; 117 118 // get number of 2D components for the element 119 inline std::size_t GetNumberOf2DComponents(G4int Z) const; 120 121 // get component ID which may be number of nucleons, 122 // or shell number, or any other integer 123 inline G4int GetComponentID(G4int Z, std::size_t idx) const; 124 125 // get vector per shell or per isotope 126 inline G4PhysicsVector* 127 GetComponentDataByIndex(G4int Z, std::size_t idx) const; 128 129 // get vector per shell or per isotope 130 inline G4Physics2DVector* 131 Get2DComponentDataByIndex(G4int Z, std::size_t idx) const; 132 133 // return cross section per element 134 // if not available return zero 135 inline G4double 136 GetValueForComponent(G4int Z, std::size_t idx, G4double kinEnergy) const; 137 138 private: 139 140 void DataError(G4int Z, const G4String&); 141 142 const G4int maxNumElm; 143 144 std::vector<G4PhysicsVector*> elmData; 145 std::vector<G4Physics2DVector*> elm2Data; 146 std::vector<std::vector<std::pair<G4int, G4PhysicsVector*> >* > compData; 147 std::vector<std::vector<std::pair<G4int, G4Physics2DVector*> >* > comp2D; 148 149 G4String name{""}; 150 }; 151 152 //-------------------------------------------------------------- 153 // run time const methods without check on validity of input 154 //-------------------------------------------------------------- 155 156 inline void G4ElementData::SetName(const G4String& nam) 157 { 158 name = nam; 159 } 160 161 inline const G4String& G4ElementData::GetName() const 162 { 163 return name; 164 } 165 166 inline G4PhysicsVector* G4ElementData::GetElementData(G4int Z) const 167 { 168 return elmData[Z]; 169 } 170 171 inline G4Physics2DVector* G4ElementData::GetElement2DData(G4int Z) const 172 { 173 return elm2Data[Z]; 174 } 175 176 inline G4PhysicsVector* 177 G4ElementData::GetComponentDataByID(G4int Z, G4int id) const 178 { 179 G4PhysicsVector* v = nullptr; 180 for (auto const & p : *(compData[Z])) { 181 if (id == p.first) { 182 v = p.second; 183 break; 184 } 185 } 186 return v; 187 } 188 189 inline G4Physics2DVector* 190 G4ElementData::Get2DComponentDataByID(G4int Z, G4int id) const 191 { 192 G4Physics2DVector* v = nullptr; 193 for (auto const & p : *(comp2D[Z])) { 194 if (id == p.first) { 195 v = p.second; 196 break; 197 } 198 } 199 return v; 200 } 201 202 inline G4double 203 G4ElementData::GetValueForElement(G4int Z, G4double kinEnergy) const 204 { 205 return elmData[Z]->Value(kinEnergy); 206 } 207 208 //-------------------------------------------------------------- 209 // run time const methods with check on validity of input 210 //-------------------------------------------------------------- 211 212 inline std::size_t G4ElementData::GetNumberOfComponents(G4int Z) const 213 { 214 return (nullptr != compData[Z]) ? compData[Z]->size() : 0; 215 } 216 217 inline std::size_t G4ElementData::GetNumberOf2DComponents(G4int Z) const 218 { 219 return (nullptr != comp2D[Z]) ? comp2D[Z]->size() : 0; 220 } 221 222 inline G4int G4ElementData::GetComponentID(G4int Z, std::size_t idx) const 223 { 224 return (idx < GetNumberOfComponents(Z)) ? (*(compData[Z]))[idx].first : 0; 225 } 226 227 inline G4PhysicsVector* 228 G4ElementData::GetComponentDataByIndex(G4int Z, std::size_t idx) const 229 { 230 return 231 (idx < GetNumberOfComponents(Z)) ? (*(compData[Z]))[idx].second : nullptr; 232 } 233 234 inline G4Physics2DVector* 235 G4ElementData::Get2DComponentDataByIndex(G4int Z, std::size_t idx) const 236 { 237 return 238 (idx < GetNumberOf2DComponents(Z)) ? (*(comp2D[Z]))[idx].second : nullptr; 239 } 240 241 inline G4double 242 G4ElementData::GetValueForComponent(G4int Z, std::size_t idx, G4double e) const 243 { 244 return (idx < GetNumberOfComponents(Z)) ? 245 (*(compData[Z]))[idx].second->Value(e) : 0.0; 246 } 247 248 #endif 249