Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ElementData.hh
Go to the documentation of this file.
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
57
59{
60 public:
61 explicit G4ElementData(G4int length = 99);
62
64
65 // Assignment operator and copy constructor
66 G4ElementData& operator=(const G4ElementData& right) = delete;
67 G4ElementData(const G4ElementData&) = delete;
68
69 // reservation of memory for better data layout
70 void Reserve1D(std::size_t);
71 void Reserve2D(std::size_t);
72
73 // add cross section for the element
75
76 // add 2D cross section for the element
78
79 // reserve vector of components
80 void InitialiseForComponent(G4int Z, G4int nComponents = 0);
81
82 // reserve vector of 2D components
83 void InitialiseFor2DComponent(G4int Z, G4int nComponents = 0);
84
85 // prepare vector of components
87
88 // prepare vector of 2D components
90
91 // make new 1D free vector
93
94 // make new 2D vector
96
97 // set name of the dataset (optional)
98 inline void SetName(const G4String& nam);
99
100 //--------------------------------------------------------------
101 // run time const methods - no check on validity of input
102 // it is a responsibility of the consume code to check the input
103 //--------------------------------------------------------------
104
105 // get name of the dataset
106 inline const G4String& GetName() const;
107
108 // get vector for the element
109 inline G4PhysicsVector* GetElementData(G4int Z) const;
110
111 // get 2-D vector for the element
113
114 // get vector per shell or per isotope
115 inline G4PhysicsVector* GetComponentDataByID(G4int Z, G4int id) const;
116
117 // get vector per shell or per isotope
119
120 // return cross section per element
121 inline G4double GetValueForElement(G4int Z, G4double kinEnergy) const;
122
123 //--------------------------------------------------------------
124 // run time const methods with input parameters control
125 //--------------------------------------------------------------
126
127 // get number of components for the element
128 inline std::size_t GetNumberOfComponents(G4int Z) const;
129
130 // get number of 2D components for the element
131 inline std::size_t GetNumberOf2DComponents(G4int Z) const;
132
133 // get component ID which may be number of nucleons,
134 // or shell number, or any other integer
135 inline G4int GetComponentID(G4int Z, std::size_t idx) const;
136
137 // get vector per shell or per isotope
138 inline G4PhysicsVector*
139 GetComponentDataByIndex(G4int Z, std::size_t idx) const;
140
141 // get vector per shell or per isotope
142 inline G4Physics2DVector*
143 Get2DComponentDataByIndex(G4int Z, std::size_t idx) const;
144
145 // return cross section per element
146 // if not available return zero
147 inline G4double
148 GetValueForComponent(G4int Z, std::size_t idx, G4double kinEnergy) const;
149
150 private:
151
152 void DataError(G4int Z, const G4String&);
153
154 const G4int maxNumElm;
155
156 G4ElementDataRegistry* fRegistry{nullptr};
157
158 std::vector<G4PhysicsVector*> elmData;
159 std::vector<std::vector<std::pair<G4int, G4PhysicsVector*> >* > compData;
160
161 std::vector<G4Physics2DVector*> elm2Data;
162 std::vector<std::vector<std::pair<G4int, G4Physics2DVector*> >* > comp2D;
163
164 G4String name{""};
165};
166
167//--------------------------------------------------------------
168// run time const methods without check on validity of input
169//--------------------------------------------------------------
170
171inline void G4ElementData::SetName(const G4String& nam)
172{
173 name = nam;
174}
175
176inline const G4String& G4ElementData::GetName() const
177{
178 return name;
179}
180
182{
183 return elmData[Z];
184}
185
187{
188 return elm2Data[Z];
189}
190
191inline G4PhysicsVector*
193{
194 G4PhysicsVector* v = nullptr;
195 for (auto const & p : *(compData[Z])) {
196 if (id == p.first) {
197 v = p.second;
198 break;
199 }
200 }
201 return v;
202}
203
204inline G4Physics2DVector*
206{
207 G4Physics2DVector* v = nullptr;
208 for (auto const & p : *(comp2D[Z])) {
209 if (id == p.first) {
210 v = p.second;
211 break;
212 }
213 }
214 return v;
215}
216
217inline G4double
219{
220 return elmData[Z]->Value(kinEnergy);
221}
222
223//--------------------------------------------------------------
224// run time const methods with check on validity of input
225//--------------------------------------------------------------
226
228{
229 return (nullptr != compData[Z]) ? compData[Z]->size() : 0;
230}
231
233{
234 return (nullptr != comp2D[Z]) ? comp2D[Z]->size() : 0;
235}
236
237inline G4int G4ElementData::GetComponentID(G4int Z, std::size_t idx) const
238{
239 return (idx < GetNumberOfComponents(Z)) ? (*(compData[Z]))[idx].first : 0;
240}
241
242inline G4PhysicsVector*
244{
245 return
246 (idx < GetNumberOfComponents(Z)) ? (*(compData[Z]))[idx].second : nullptr;
247}
248
249inline G4Physics2DVector*
251{
252 return
253 (idx < GetNumberOf2DComponents(Z)) ? (*(comp2D[Z]))[idx].second : nullptr;
254}
255
256inline G4double
258{
259 return (idx < GetNumberOfComponents(Z)) ?
260 (*(compData[Z]))[idx].second->Value(e) : 0.0;
261}
262
263#endif
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
void InitialiseFor2DComponent(G4int Z, G4int nComponents=0)
void Reserve2D(std::size_t)
void Reserve1D(std::size_t)
G4PhysicsVector * GetElementData(G4int Z) const
const G4String & GetName() const
void Add2DComponent(G4int Z, G4int id, G4Physics2DVector *v)
G4double GetValueForElement(G4int Z, G4double kinEnergy) const
G4Physics2DVector * GetElement2DData(G4int Z) const
void InitialiseForComponent(G4int Z, G4int nComponents=0)
G4PhysicsVector * GetComponentDataByIndex(G4int Z, std::size_t idx) const
G4ElementData & operator=(const G4ElementData &right)=delete
void InitialiseForElement(G4int Z, G4PhysicsVector *v)
std::size_t GetNumberOf2DComponents(G4int Z) const
G4int GetComponentID(G4int Z, std::size_t idx) const
G4Physics2DVector * Get2DComponentDataByID(G4int Z, G4int id) const
G4double GetValueForComponent(G4int Z, std::size_t idx, G4double kinEnergy) const
G4ElementData(G4int length=99)
void AddComponent(G4int Z, G4int id, G4PhysicsVector *v)
G4PhysicsVector * GetComponentDataByID(G4int Z, G4int id) const
std::size_t GetNumberOfComponents(G4int Z) const
void SetName(const G4String &nam)
G4Physics2DVector * New2DVector(G4int Z, G4int ny, G4int ne)
G4PhysicsVector * New1DVector(G4int Z, G4int ne)
G4ElementData(const G4ElementData &)=delete
G4Physics2DVector * Get2DComponentDataByIndex(G4int Z, std::size_t idx) const