Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4ShellData Class Reference

#include <G4ShellData.hh>

Public Member Functions

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

Private Member Functions

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

Private Attributes

std::map< G4int, G4DataVector *, std::less< G4int > > bindingMap
 
std::map< G4int, std::vector< G4double > *, std::less< G4int > > idMap
 
std::vector< G4intnShells
 
G4bool occupancyData
 
std::map< G4int, std::vector< G4double > *, std::less< G4int > > occupancyPdfMap
 
G4int zMax
 
G4int zMin
 

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{ }
static const G4int maxZ
G4bool occupancyData
Definition: G4ShellData.hh:83

◆ ~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}
static const G4double pos
std::map< G4int, G4DataVector *, std::less< G4int > > bindingMap
Definition: G4ShellData.hh:77
std::map< G4int, std::vector< G4double > *, std::less< G4int > > idMap
Definition: G4ShellData.hh:76
std::map< G4int, std::vector< G4double > *, std::less< G4int > > occupancyPdfMap
Definition: G4ShellData.hh:79

References bindingMap, idMap, occupancyData, occupancyPdfMap, and pos.

◆ 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 = 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
const G4int Z[17]

References bindingMap, pos, Z, zMax, and zMin.

Referenced by G4AtomicTransitionManager::Initialise(), G4LivermoreComptonModel::SampleSecondaries(), G4LivermorePolarizedComptonModel::SampleSecondaries(), G4LowEPComptonModel::SampleSecondaries(), and G4LowEPPolarizedComptonModel::SampleSecondaries().

◆ LoadData()

void G4ShellData::LoadData ( const G4String fileName)

Definition at line 228 of file G4ShellData.cc.

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

References bindingMap, FatalException, geant4_check_module_cycles::file, G4Exception(), idMap, MeV, CLHEP::detail::n, G4InuclParticleNames::name(), nShells, occupancyData, occupancyPdfMap, ShellIdVector(), Z, zMax, and zMin.

Referenced by G4AtomicTransitionManager::Initialise(), G4LivermoreComptonModel::Initialise(), G4LivermorePolarizedComptonModel::Initialise(), G4LowEPComptonModel::Initialise(), and G4LowEPPolarizedComptonModel::Initialise().

◆ NumberOfShells()

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}

References CLHEP::detail::n, nShells, Z, zMax, and zMin.

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

◆ operator=()

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

◆ PrintData()

void G4ShellData::PrintData ( void  ) 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 G4DataVector* energies = (*posE).second;
196 for (G4int i=0; i<nSh; ++i)
197 {
198 G4int id = (G4int) (*ids)[i];
199 G4double e = (*energies)[i] / keV;
200 G4cout << i << ") ";
201
202 if (occupancyData)
203 {
204 G4cout << " Occupancy: ";
205 }
206 else
207 {
208 G4cout << " Shell id: ";
209 }
210 G4cout << id << " - Binding energy = "
211 << e << " keV ";
212 if (occupancyData)
213 {
214 auto posOcc = occupancyPdfMap.find(Z);
215 std::vector<G4double> probs = *((*posOcc).second);
216 G4double prob = probs[i];
217 G4cout << "- Probability = " << prob;
218 }
219 G4cout << G4endl;
220 }
221 G4cout << "-------------------------------------------------"
222 << G4endl;
223 }
224}
static constexpr double keV
Definition: G4SIunits.hh:202
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout

References bindingMap, G4cout, G4endl, idMap, keV, nShells, occupancyData, occupancyPdfMap, Z, zMax, and zMin.

◆ SelectRandomShell()

G4int G4ShellData::SelectRandomShell ( G4int  Z) const

Definition at line 345 of file G4ShellData.cc.

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

References FatalErrorInArgument, G4Exception(), G4UniformRand, NumberOfShells(), ShellVector(), Z, and zMax.

Referenced by G4LivermoreComptonModel::SampleSecondaries(), G4LivermorePolarizedComptonModel::SampleSecondaries(), G4LowEPComptonModel::SampleSecondaries(), and G4LowEPPolarizedComptonModel::SampleSecondaries().

◆ SetOccupancyData()

void G4ShellData::SetOccupancyData ( )
inline

◆ 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 = dataSet.size();
129 if (shellIndex >= 0 && shellIndex < nData)
130 {
131 n = (G4int) dataSet[shellIndex];
132 }
133 }
134 }
135 return n;
136}

References idMap, CLHEP::detail::n, pos, Z, zMax, and zMin.

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}

References FatalErrorInArgument, G4Exception(), idMap, pos, Z, and zMax.

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 = dataSet.size();
150 if (shellIndex >= 0 && shellIndex < nData)
151 {
152 prob = dataSet[shellIndex];
153 }
154 }
155 }
156 return prob;
157}

References idMap, pos, Z, zMax, and zMin.

◆ ShellVector()

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

Definition at line 107 of file G4ShellData.cc.

108{
109 if (Z < zMin || Z > zMax)
110 G4Exception("G4ShellData::ShellVector()","de0001",JustWarning,"Z outside boundaries");
111 auto pos = occupancyPdfMap.find(Z);
112 std::vector<G4double>* dataSet = (*pos).second;
113 return *dataSet;
114}
@ JustWarning

References G4Exception(), JustWarning, occupancyPdfMap, pos, Z, and zMax.

Referenced by SelectRandomShell().

Field Documentation

◆ bindingMap

std::map<G4int,G4DataVector*,std::less<G4int> > G4ShellData::bindingMap
private

Definition at line 77 of file G4ShellData.hh.

Referenced by BindingEnergy(), LoadData(), PrintData(), and ~G4ShellData().

◆ idMap

std::map<G4int,std::vector<G4double>*,std::less<G4int> > G4ShellData::idMap
private

◆ nShells

std::vector<G4int> G4ShellData::nShells
private

Definition at line 78 of file G4ShellData.hh.

Referenced by LoadData(), NumberOfShells(), and PrintData().

◆ occupancyData

G4bool G4ShellData::occupancyData
private

Definition at line 83 of file G4ShellData.hh.

Referenced by LoadData(), PrintData(), SetOccupancyData(), and ~G4ShellData().

◆ occupancyPdfMap

std::map<G4int,std::vector<G4double>*,std::less<G4int> > G4ShellData::occupancyPdfMap
private

Definition at line 79 of file G4ShellData.hh.

Referenced by LoadData(), PrintData(), ShellVector(), and ~G4ShellData().

◆ zMax

G4int G4ShellData::zMax
private

◆ zMin

G4int G4ShellData::zMin
private

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