EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_ensdf.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ ensdf headers
5 # Copyright (C) 2015 National Research Council Canada
6 #
7 # This file is part of EGSnrc.
8 #
9 # EGSnrc is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU Affero General Public License as published by the
11 # Free Software Foundation, either version 3 of the License, or (at your
12 # option) any later version.
13 #
14 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17 # more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ###############################################################################
23 #
24 # Author: Reid Townson, 2016
25 #
26 # Contributors:
27 #
28 ###############################################################################
29 */
30 
31 
38 #ifndef EGS_ENSDF_
39 #define EGS_ENSDF_
40 
41 #include "egs_libconfig.h"
42 #include "egs_functions.h"
43 #include "egs_math.h"
44 #include "egs_alias_table.h"
45 #include "egs_atomic_relaxations.h"
46 
47 #include <iostream>
48 #include <fstream>
49 #include <algorithm>
50 #include <vector>
51 #include <map>
52 
53 using namespace std;
54 
55 template <class T> class Branch {
56 public:
57 
58  Branch() {}
59 
60  ~Branch() {
61  for (typename vector<T *>::iterator it = branchLeaves.begin();
62  it!=branchLeaves.end(); it++) {
63  (*it)->removeBranch();
64  }
65  branchLeaves.clear();
66  }
67 
68  void addLeaf(T *leaf) {
69  branchLeaves.push_back(leaf);
70  }
71 
72  void removeLeaf(T *leaf) {
73  branchLeaves.erase(std::remove(branchLeaves.begin(),
74  branchLeaves.end(),
75  leaf), branchLeaves.end());
76  }
77 
78  vector<T *> getLeaves() const {
79  return branchLeaves;
80  }
81 
82  // A new == operator for this class
83  bool operator==(const Branch<T> &rhs) const {
84  for (typename vector<T *>::const_iterator it = branchLeaves.begin();
85  it!=branchLeaves.end(); it++) {
86 
87  bool foundLeaf = false;
88  for (typename vector<T *>::const_iterator irhs =
89  rhs.branchLeaves.begin();
90  irhs!=rhs.branchLeaves.end(); irhs++) {
91 
92  if (*irhs != 0 && *it != 0) {
93  if (*irhs == *it) {
94  foundLeaf = true;
95  }
96  }
97  }
98 
99  if (!foundLeaf) {
100  return false;
101  }
102  }
103  return true;
104  }
105 
106 protected:
107  vector<T *> branchLeaves;
108 };
109 
110 template <class T> class Leaf {
111 public:
112 
113  Leaf(T *existingBranch) {
114  branch = existingBranch;
115  if (branch) {
116  branch->addLeaf(this);
117  }
118  }
119 
120  ~Leaf() {
121  if (branch) {
122  branch->removeLeaf(this);
123  }
124  branch = 0;
125  }
126 
127  virtual T *getBranch() const {
128  return branch;
129  }
130 
131  void removeBranch() {
132  branch = 0;
133  }
134 
135  // A new == operator for this class
136  bool operator== (const T &rhs) const {
137  if (branch==0 && rhs.branch==0) {
138  return true;
139  }
140  else if ((branch==0) && rhs.branch!=0) {
141  return false;
142  }
143  else if ((branch!=0) && rhs.branch==0) {
144  return false;
145  }
146  else if (branch!=0 && rhs.branch!=0) {
147  return *branch == *(rhs.branch);
148  }
149  }
150 
151 private:
152  T *branch;
153 };
154 
155 // The Record class
156 class Record {
157 public:
158  Record();
159  Record(vector<string> ensdf);
160  virtual ~Record();
161  vector<string> getRecords() const;
162 
163 protected:
164  double recordToDouble(int startPos, int endPos);
165  string recordToString(int startPos, int endPos);
166  double getTag(string searchString, string notAfter);
167  double parseHalfLife(int startPos, int endPos);
168  double parseStdUncertainty(string value, string stdUncertainty);
169  string getStringAfter(string searchString, size_t len);
170 
171  // All the lines corresponding to this record type
172  vector<string> lines;
173 };
174 
175 // Comment Record
176 class CommentRecord : public Record {
177 public:
178  CommentRecord(vector<string> ensdf);
179  string getComment();
180 
181 private:
182  string comment;
183  void processEnsdf();
184 };
185 
186 // Parent Record
187 class ParentRecord : public Record, public Branch<Leaf<ParentRecord> > {
188 public:
189  ParentRecord(vector<string> ensdf);
190  double getHalfLife() const;
191  double getQ() const;
192 
193 protected:
194  double halfLife,
195  Q;
196 
197 private:
198  void processEnsdf();
199 };
200 
201 class ParentRecordLeaf : public Leaf<ParentRecord> {
202 public:
203  ParentRecordLeaf(ParentRecord *myRecord);
204  virtual ParentRecord *getParentRecord() const;
205 };
206 
207 // Normalization Record
208 class NormalizationRecord : public Record, public
209  Branch<Leaf<NormalizationRecord> >, public ParentRecordLeaf {
210 public:
211  NormalizationRecord(vector<string> ensdf, ParentRecord *parent);
212  double getRelativeMultiplier() const;
213  double getTransitionMultiplier() const;
214  double getBranchMultiplier() const;
215  double getBetaMultiplier() const;
216  EGS_AtomicRelaxations *getRelaxations() const;
217  double getBindingEnergy(int shell) const;
218  int getNShell() const;
219  void relax(int shell,
220  EGS_Float ecut, EGS_Float pcut,
221  EGS_RandomGenerator *rndm, double &edep,
223 
224 protected:
225  double normalizeRelative;
226  double normalizeTransition;
227  double normalizeBeta;
228  double normalizeBranch;
229 
230 private:
231  void processEnsdf();
232  EGS_AtomicRelaxations *relaxations;
233  int nshell, Z;
234 };
235 
236 class NormalizationRecordLeaf : public Leaf<NormalizationRecord> {
237 public:
239  virtual NormalizationRecord *getNormalizationRecord() const;
240 };
241 
242 // Level Record
243 class EGS_EXPORT LevelRecord : public Record, public Branch<Leaf<LevelRecord> > {
244 public:
245  LevelRecord();
246  LevelRecord(vector<string> ensdf);
247  void resetDisintegrationIntensity();
248  void cumulDisintegrationIntensity(double disintIntensity);
249  double getDisintegrationIntensity() const;
250  void setLevelCanDecay(bool canDecay);
251  bool levelCanDecay() const;
252  double getEnergy() const;
253  double getHalfLife() const;
254 
255 protected:
256  double disintegrationIntensity;
257  double energy;
258  double halfLife;
259  bool canDecay;
260 
261 private:
262  void processEnsdf();
263 };
264 
265 class LevelRecordLeaf : public Leaf<LevelRecord> {
266 public:
267  LevelRecordLeaf(LevelRecord *myRecord);
268  virtual LevelRecord *getLevelRecord() const;
269 };
270 
271 // Generic beta record
272 class EGS_EXPORT BetaRecordLeaf : public Record, public ParentRecordLeaf, public
274 public:
275  BetaRecordLeaf(vector<string> ensdf, ParentRecord *myParent,
276  NormalizationRecord *myNormalization, LevelRecord *myLevel);
277 
278  virtual double getFinalEnergy() const = 0;
279  virtual double getBetaIntensity() const = 0;
280  virtual double getPositronIntensity() const {
281  return 0;
282  };
283  virtual double getECIntensity() const {
284  return 0;
285  };
286  virtual void relax(int shell,
287  EGS_Float ecut, EGS_Float pcut,
288  EGS_RandomGenerator *rndm, double &edep,
290  virtual void setBetaIntensity(double newIntensity) = 0;
291  int getCharge() const;
292  void incrNumSampled();
293  EGS_I64 getNumSampled() const;
294  unsigned short int getZ() const;
295  unsigned short int getAtomicWeight() const;
296  unsigned short int getForbidden() const;
297  void setSpectrum(EGS_AliasTable *bspec);
298  EGS_AliasTable *getSpectrum() const;
299  vector<double> ecShellIntensity;
300 
301 protected:
302  EGS_I64 numSampled;
303  double finalEnergy;
304  double betaIntensity;
305  int q;
306  unsigned short int Z;
307  unsigned short int A;
308  unsigned short int forbidden;
309  EGS_AliasTable *spectrum;
310 };
311 
312 // Beta- record
314 public:
315  BetaMinusRecord(vector<string> ensdf, ParentRecord *myParent,
316  NormalizationRecord *myNormalization, LevelRecord *myLevel);
317 
318  double getFinalEnergy() const;
319  double getBetaIntensity() const;
320  double getBetaIntensityUnc() const;
321  void setBetaIntensity(double newIntensity);
322 
323 private:
324  void processEnsdf();
325  double betaIntensityUnc;
326 };
327 
328 // Beta+ Record (and Electron Capture)
330 public:
331  BetaPlusRecord(vector<string> ensdf, ParentRecord *myParent,
332  NormalizationRecord *myNormalization, LevelRecord *myLevel);
333 
334  double getFinalEnergy() const;
335  double getBetaIntensity() const;
336  double getPositronIntensity() const;
337  double getPositronIntensityUnc() const;
338  double getECIntensityUnc() const;
339  void setBetaIntensity(double newIntensity);
340  void setPositronIntensity(double newIntensity);
341  void relax(int shell,
342  EGS_Float ecut, EGS_Float pcut,
343  EGS_RandomGenerator *rndm, double &edep,
345 
346 protected:
347  double ecIntensity,
348  positronIntensity,
349  ecIntensityUnc,
350  positronIntensityUnc;
351 
352 private:
353  void processEnsdf();
354 };
355 
356 // Gamma record
359 public:
360  GammaRecord(vector<string> ensdf, ParentRecord *myParent,
361  NormalizationRecord *myNormalization,
362  LevelRecord *myLevel);
363  GammaRecord(GammaRecord *gamma);
364 
365  double getDecayEnergy() const;
366  double getTransitionIntensity() const;
367  double getGammaIntensity() const;
368  double getGammaIntensityUnc() const;
369  double getICIntensity() const;
370  double getICIntensityUnc() const;
371  double getIPIntensity() const;
372  double getIPIntensityUnc() const;
373  void setTransitionIntensity(double newIntensity);
374  void setGammaIntensity(double newIntensity);
375  void setICIntensity(double newIntensity);
376  double getMultiTransitionProb() const;
377  void setMultiTransitionProb(double newIntensity);
378  int getCharge() const;
379  LevelRecord *getFinalLevel() const;
380  void setFinalLevel(LevelRecord *newLevel);
381  void incrGammaSampled();
382  void incrICSampled();
383  void incrIPSampled();
384  EGS_I64 getGammaSampled() const;
385  EGS_I64 getICSampled() const;
386  EGS_I64 getIPSampled() const;
387  vector<double> icIntensity;
388  double getBindingEnergy(int shell) const;
389  void relax(int shell,
390  EGS_Float ecut, EGS_Float pcut,
391  EGS_RandomGenerator *rndm, double &edep,
393 
394 protected:
395  EGS_I64 numGammaSampled, numICSampled, numIPSampled;
396  double decayEnergy;
397  double transitionIntensity,
398  multipleTransitionProb,
399  gammaIntensity,
400  gammaIntensityUnc,
401  icCoeff,
402  icCoeffUnc,
403  ipCoeff,
404  ipCoeffUnc;
405  int q;
406  LevelRecord *finalLevel;
407 
408 private:
409  void processEnsdf();
410 };
411 
412 // Alpha record
413 class EGS_EXPORT AlphaRecord : public Record, public ParentRecordLeaf, public
415 public:
416  AlphaRecord(vector<string> ensdf, ParentRecord *myParent,
417  NormalizationRecord *myNormalization, LevelRecord *myLevel);
418 
419  double getFinalEnergy() const;
420  double getAlphaIntensity() const;
421  double getAlphaIntensityUnc() const;
422  int getCharge() const;
423  void setAlphaIntensity(double newIntensity);
424  void incrNumSampled();
425  EGS_I64 getNumSampled() const;
426 
427 protected:
428  EGS_I64 numSampled;
429  double finalEnergy,
430  alphaIntensity,
431  alphaIntensityUnc;
432  int q;
433 
434 private:
435  void processEnsdf();
436 };
437 
493 
494 public:
495 
499  EGS_Ensdf(const string nuclide, const string ensdf_filename="",
500  const string relaxType="eadl", const bool allowMultiTrans=false, int verbosity=1);
501 
503  ~EGS_Ensdf();
504 
505  vector<Record * > getRecords() const;
506  vector<BetaRecordLeaf *> getBetaRecords() const;
507  vector<ParentRecord * > getParentRecords() const;
508  vector<LevelRecord * > getLevelRecords() const;
509  vector<AlphaRecord * > getAlphaRecords() const;
510  vector<GammaRecord * > getGammaRecords() const;
511  vector<GammaRecord * > getMetastableGammaRecords() const;
512  vector<GammaRecord * > getUncorrelatedGammaRecords() const;
513  vector<double > getXRayIntensities() const;
514  vector<double > getXRayEnergies() const;
515  vector<double > getAugerIntensities() const;
516  vector<double > getAugerEnergies() const;
517 
518  string radionuclide;
519  int verbose;
520  string relaxationType;
521  unsigned short int Z;
522  double decayDiscrepancy;
523  bool allowMultiTransition;
524 
525  void normalizeIntensities();
526 
527 protected:
528 
529  unsigned short int findAtomicWeight(string element);
530  void parseEnsdf(vector<string> ensdf);
531  void buildRecords();
532 
533  void getEmissionsFromComments();
534 
535  ifstream ensdf_file;
536  unsigned short int A;
537 
538  vector<Record * > myRecords;
539  vector<CommentRecord * > myCommentRecords;
540  vector<ParentRecord * > myParentRecords;
541  vector<NormalizationRecord * > myNormalizationRecords;
542  vector<LevelRecord * > myLevelRecords;
543  vector<BetaRecordLeaf *> myBetaRecords;
544  vector<BetaMinusRecord * > myBetaMinusRecords;
545  vector<BetaPlusRecord * > myBetaPlusRecords;
546  vector<AlphaRecord * > myAlphaRecords;
547  vector<GammaRecord * > myGammaRecords;
548  vector<GammaRecord * > myMetastableGammaRecords;
549  vector<GammaRecord * > myUncorrelatedGammaRecords;
550 
551 private:
552 
553  vector<vector<string> > recordStack;
554  vector<string> commentLines;
555  vector<double> xrayEnergies,
556  xrayIntensities,
557  augerEnergies,
558  augerIntensities;
559  ParentRecord *previousParent;
560 };
561 
562 
563 
564 
565 #endif
#define EGS_EXPORT
Export symbols from the egspp library.
Definition: egs_libconfig.h:90
EGS_AliasTable class header file.
A class for sampling random values from a given probability distribution using the alias table techni...
EGS_AtomicRelaxations class header file.
Global egspp functions header file.
Base random number generator class. All random number generators should be derived from this class...
Definition: egs_rndm.h:67
The ensdf class for reading ensdf format data files.
Definition: egs_ensdf.h:492
Attempts to fix broken math header files.
Defines the EGS_EXPORT and EGS_LOCAL macros.