Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ShellData Class Reference

#include <G4ShellData.hh>

Public Member Functions

 G4ShellData (G4int minZ=1, G4int maxZ=100, G4bool isOccupancy=false)
 ~G4ShellData ()
std::size_t NumberOfShells (G4int Z) const
G4int ShellId (G4int Z, G4int shellIndex) const
G4double ShellOccupancyProbability (G4int Z, G4int shellIndex) const
const std::vector< G4double > & ShellIdVector (G4int Z) const
G4double BindingEnergy (G4int Z, G4int shellIndex) const
void SetOccupancyData ()
void LoadData (const G4String &fileName)
void PrintData () const
G4int SelectRandomShell (G4int Z) const
G4ShellDataoperator= (const G4ShellData &right)=delete
 G4ShellData (const G4ShellData &)=delete

Detailed Description

Definition at line 51 of file G4ShellData.hh.

Constructor & Destructor Documentation

◆ G4ShellData() [1/2]

G4ShellData::G4ShellData ( G4int minZ = 1,
G4int maxZ = 100,
G4bool isOccupancy = false )
explicit

Definition at line 50 of file G4ShellData.cc.

51 : zMin(minZ), zMax(maxZ), occupancyData(isOccupancy)
52{}

Referenced by G4ShellData(), and operator=().

◆ ~G4ShellData()

G4ShellData::~G4ShellData ( )

Definition at line 56 of file G4ShellData.cc.

57{
58 for (auto& pos : idMap)
59 {
60 std::vector<G4double>* dataSet = pos.second;
61 delete dataSet;
62 }
63 for (auto& pos2 : bindingMap)
64 {
65 G4DataVector* dataSet = pos2.second;
66 delete dataSet;
67 }
68
69 if (occupancyData)
70 {
71 for (auto& pos3 : occupancyPdfMap)
72 {
73 std::vector<G4double>* dataSet = pos3.second;
74 delete dataSet;
75 }
76 }
77}

◆ G4ShellData() [2/2]

G4ShellData::G4ShellData ( const G4ShellData & )
delete

Member Function Documentation

◆ BindingEnergy()

G4double G4ShellData::BindingEnergy ( G4int Z,
G4int shellIndex ) const

Definition at line 161 of file G4ShellData.cc.

162{
163 G4double value = 0.;
164
165 if (Z >= zMin && Z <= zMax)
166 {
167 auto pos = bindingMap.find(Z);
168 if (pos!= bindingMap.end())
169 {
170 G4DataVector dataSet = *((*pos).second);
171 G4int nData = (G4int)dataSet.size();
172 if (shellIndex >= 0 && shellIndex < nData)
173 {
174 value = dataSet[shellIndex];
175 }
176 }
177 }
178 return value;
179}
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85

Referenced by G4AtomicTransitionManager::Initialise().

◆ LoadData()

void G4ShellData::LoadData ( const G4String & fileName)

Definition at line 235 of file G4ShellData.cc.

236{
237 // Build the complete string identifying the file with the data set
238 std::ostringstream ost;
239 ost << fileName << ".dat";
240 G4String name(ost.str());
241
242 const char* path = G4FindDataDir("G4LEDATA");
243 if (!path)
244 {
245 G4String excep("G4ShellData::LoadData()");
246 G4Exception(excep,"em0006",FatalException,"Please set G4LEDATA");
247 return;
248 }
249
250 G4String pathString(path);
251 G4String dirFile = pathString + name;
252 std::ifstream file(dirFile);
253 std::filebuf* lsdp = file.rdbuf();
254
255 if (! (lsdp->is_open()) )
256 {
257
258 G4String excep = "G4ShellData::LoadData()";
259 G4String msg = "data file: " + dirFile + " not found";
260 G4Exception(excep, "em0003",FatalException, msg );
261 return;
262 }
263
264 G4double a = 0;
265 G4int k = 1;
266 G4int sLocal = 0;
267
268 G4int Z = 1;
269 G4DataVector* energies = new G4DataVector;
270 std::vector<G4double>* ids = new std::vector<G4double>;
271
272 do {
273 file >> a;
274 G4int nColumns = 2;
275 if (a == -1)
276 {
277 if (sLocal == 0)
278 {
279 // End of a shell data set
280 idMap[Z] = ids;
281 bindingMap[Z] = energies;
282 G4int n = (G4int)ids->size();
283 nShells.push_back(n);
284 // Start of new shell data set
285
286 ids = new std::vector<G4double>;
287 energies = new G4DataVector;
288 Z++;
289 }
290 sLocal++;
291 if (sLocal == nColumns)
292 {
293 sLocal = 0;
294 }
295 }
296
297 // moved out of the do-while since might go to a leak.
298 // else if (a == -2)
299 // {
300 // End of file; delete the empty vectors created when encountering the last -1 -1 row
301 // delete energies;
302 // delete ids;
303 //nComponents = components.size();
304 // }
305 else
306 {
307 // 1st column is shell id
308 if(k%nColumns != 0)
309 {
310 ids->push_back(a);
311 k++;
312 }
313 else if (k%nColumns == 0)
314 {
315 // 2nd column is binding energy
316 G4double e = a * MeV;
317 energies->push_back(e);
318 k = 1;
319 }
320 }
321 } while (a != -2); // end of file
322 file.close();
323 delete energies;
324 delete ids;
325
326 // For Doppler broadening: the data set contains shell occupancy and binding energy for each shell
327 // Build additional map with probability for each shell based on its occupancy
328
329 if (occupancyData)
330 {
331 // Build cumulative from raw shell occupancy
332 for (G4int ZLocal=zMin; ZLocal <= zMax; ++ZLocal)
333 {
334 std::vector<G4double> occupancy = ShellIdVector(ZLocal);
335
336 std::vector<G4double>* prob = new std::vector<G4double>;
337 G4double scale = 1. / G4double(ZLocal);
338
339 prob->push_back(occupancy[0] * scale);
340 for (std::size_t i=1; i<occupancy.size(); ++i)
341 {
342 prob->push_back(occupancy[i]*scale + (*prob)[i-1]);
343 }
344 occupancyPdfMap[ZLocal] = prob;
345 }
346 }
347}
const char * G4FindDataDir(const char *)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
const std::vector< G4double > & ShellIdVector(G4int Z) const
const char * name(G4int ptype)

Referenced by G4AtomicTransitionManager::Initialise().

◆ NumberOfShells()

std::size_t G4ShellData::NumberOfShells ( G4int Z) const

Definition at line 81 of file G4ShellData.cc.

82{
83 G4int z = Z - 1;
84 G4int n = 0;
85
86 if (Z>= zMin && Z <= zMax)
87 {
88 n = nShells[z];
89 }
90 return n;
91}

Referenced by G4AtomicTransitionManager::Initialise(), and SelectRandomShell().

◆ operator=()

G4ShellData & G4ShellData::operator= ( const G4ShellData & right)
delete

◆ PrintData()

void G4ShellData::PrintData ( ) const

Definition at line 183 of file G4ShellData.cc.

184{
185 for (G4int Z = zMin; Z <= zMax; Z++)
186 {
187 G4cout << "---- Shell data for Z = "
188 << Z
189 << " ---- "
190 << G4endl;
191 G4int nSh = nShells[Z-1];
192 auto posId = idMap.find(Z);
193 std::vector<G4double>* ids = (*posId).second;
194 auto posE = bindingMap.find(Z);
195 if (posE != bindingMap.end())
196 {
197 G4DataVector* energies = (*posE).second;
198 for (G4int i=0; i<nSh; ++i)
199 {
200 G4int id = (G4int) (*ids)[i];
201 G4double e = (*energies)[i] / keV;
202 G4cout << i << ") ";
203
204 if (occupancyData)
205 {
206 G4cout << " Occupancy: ";
207 }
208 else
209 {
210 G4cout << " Shell id: ";
211 }
212 G4cout << id << " - Binding energy = "
213 << e << " keV ";
214 if (occupancyData)
215 {
216 auto posOcc = occupancyPdfMap.find(Z);
217 G4double prob = 0.;
218 if (posOcc != occupancyPdfMap.end())
219 {
220 std::vector<G4double> probs = *((*posOcc).second);
221 prob = probs[i];
222 }
223 G4cout << "- Probability = " << prob;
224 }
225 G4cout << G4endl;
226 }
227 }
228 G4cout << "-------------------------------------------------"
229 << G4endl;
230 }
231}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

◆ SelectRandomShell()

G4int G4ShellData::SelectRandomShell ( G4int Z) const

Definition at line 351 of file G4ShellData.cc.

352{
353 if (Z < zMin || Z > zMax)
354 G4Exception("G4ShellData::SelectrandomShell","de0001",FatalErrorInArgument, "Z outside boundaries");
355
356 G4int shellIndex = 0;
357 std::vector<G4double> prob = ShellVector(Z);
358 G4double random = G4UniformRand();
359
360 // Binary search the shell with probability less or equal random
361 G4int nShellsLocal = (G4int)NumberOfShells(Z);
362 G4int upperBound = nShellsLocal;
363
364 while (shellIndex <= upperBound)
365 {
366 G4int midShell = (shellIndex + upperBound) / 2;
367 if ( random < prob[midShell] )
368 upperBound = midShell - 1;
369 else
370 shellIndex = midShell + 1;
371 }
372 if (shellIndex >= nShellsLocal) shellIndex = nShellsLocal - 1;
373
374 return shellIndex;
375}
@ FatalErrorInArgument
#define G4UniformRand()
Definition Randomize.hh:52
std::size_t NumberOfShells(G4int Z) const

◆ SetOccupancyData()

void G4ShellData::SetOccupancyData ( )
inline

Definition at line 62 of file G4ShellData.hh.

62{ occupancyData = true; }

◆ ShellId()

G4int G4ShellData::ShellId ( G4int Z,
G4int shellIndex ) const

Definition at line 118 of file G4ShellData.cc.

119{
120 G4int n = -1;
121
122 if (Z >= zMin && Z <= zMax)
123 {
124 auto pos = idMap.find(Z);
125 if (pos!= idMap.end())
126 {
127 std::vector<G4double> dataSet = *((*pos).second);
128 G4int nData = (G4int)dataSet.size();
129 if (shellIndex >= 0 && shellIndex < nData)
130 {
131 n = (G4int) dataSet[shellIndex];
132 }
133 }
134 }
135 return n;
136}

Referenced by G4AtomicTransitionManager::Initialise().

◆ ShellIdVector()

const std::vector< G4double > & G4ShellData::ShellIdVector ( G4int Z) const

Definition at line 95 of file G4ShellData.cc.

96{
97 if (Z < zMin || Z > zMax) {
98 G4Exception("G4ShellData::ShellIdVector","de0001",FatalErrorInArgument, "Z outside boundaries");
99 }
100 auto pos = idMap.find(Z);
101 std::vector<G4double>* dataSet = (*pos).second;
102 return *dataSet;
103}

Referenced by LoadData().

◆ ShellOccupancyProbability()

G4double G4ShellData::ShellOccupancyProbability ( G4int Z,
G4int shellIndex ) const

Definition at line 140 of file G4ShellData.cc.

141{
142 G4double prob = -1.;
143 if (Z >= zMin && Z <= zMax)
144 {
145 auto pos = idMap.find(Z);
146 if (pos!= idMap.end())
147 {
148 std::vector<G4double> dataSet = *((*pos).second);
149 G4int nData = (G4int)dataSet.size();
150 if (shellIndex >= 0 && shellIndex < nData)
151 {
152 prob = dataSet[shellIndex];
153 }
154 }
155 }
156 return prob;
157}

The documentation for this class was generated from the following files: