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  unsigned short parseSpin(int startPos, int endPos);
169  bool parseParity(int startPos, int endPos);
170  double parseStdUncertainty(string value, string stdUncertainty);
171  string getStringAfter(string searchString, size_t len);
172 
173  // All the lines corresponding to this record type
174  vector<string> lines;
175 };
176 
177 // Comment Record
178 class CommentRecord : public Record {
179 public:
180  CommentRecord(vector<string> ensdf);
181  vector<string> getComments();
182 
183 private:
184  vector<string> comments;
185  void processEnsdf();
186 };
187 
188 // Parent Record
189 class ParentRecord : public Record, public Branch<Leaf<ParentRecord> > {
190 public:
191  ParentRecord(vector<string> ensdf);
192  double getHalfLife() const;
193  double getQ() const;
194 
195 protected:
196  double halfLife,
197  Q;
198 
199 private:
200  void processEnsdf();
201 };
202 
203 class ParentRecordLeaf : public Leaf<ParentRecord> {
204 public:
205  ParentRecordLeaf(ParentRecord *myRecord);
206  virtual ParentRecord *getParentRecord() const;
207 };
208 
209 // Normalization Record
210 class NormalizationRecord : public Record, public
211  Branch<Leaf<NormalizationRecord> >, public ParentRecordLeaf {
212 public:
213  NormalizationRecord(vector<string> ensdf, ParentRecord *parent);
214  double getRelativeMultiplier() const;
215  double getTransitionMultiplier() const;
216  double getBranchMultiplier() const;
217  double getBetaMultiplier() const;
218  EGS_AtomicRelaxations *getRelaxations() const;
219  double getBindingEnergy(int shell) const;
220  int getNShell() const;
221  void relax(int shell,
222  EGS_Float ecut, EGS_Float pcut,
223  EGS_RandomGenerator *rndm, double &edep,
225 
226 protected:
227  double normalizeRelative;
228  double normalizeTransition;
229  double normalizeBeta;
230  double normalizeBranch;
231 
232 private:
233  void processEnsdf();
234  EGS_AtomicRelaxations *relaxations;
235  int nshell, Z;
236 };
237 
238 class NormalizationRecordLeaf : public Leaf<NormalizationRecord> {
239 public:
241  virtual NormalizationRecord *getNormalizationRecord() const;
242 };
243 
244 // Level Record
245 class EGS_EXPORT LevelRecord : public Record, public Branch<Leaf<LevelRecord> > {
246 public:
247  LevelRecord();
248  LevelRecord(vector<string> ensdf);
249  void resetDisintegrationIntensity();
250  void cumulDisintegrationIntensity(double disintIntensity);
251  double getDisintegrationIntensity() const;
252  void setLevelCanDecay(bool canDecay);
253  bool levelCanDecay() const;
254  double getEnergy() const;
255  double getHalfLife() const;
256  unsigned short getSpin() const;
257  bool getParity() const;
258 
259 protected:
260  double disintegrationIntensity;
261  double energy;
262  double halfLife;
263  unsigned short spin;
264  bool parity;
265  bool canDecay;
266 
267 private:
268  void processEnsdf();
269 };
270 
271 class LevelRecordLeaf : public Leaf<LevelRecord> {
272 public:
273  LevelRecordLeaf(LevelRecord *myRecord);
274  virtual LevelRecord *getLevelRecord() const;
275 };
276 
277 // Generic beta record
278 class EGS_EXPORT BetaRecordLeaf : public Record, public ParentRecordLeaf, public
280 public:
281  BetaRecordLeaf(vector<string> ensdf, ParentRecord *myParent,
282  NormalizationRecord *myNormalization, LevelRecord *myLevel);
283 
284  virtual double getFinalEnergy() const = 0;
285  virtual double getBetaIntensity() const = 0;
286  virtual double getPositronIntensity() const {
287  return 0;
288  };
289  virtual double getECIntensity() const {
290  return 0;
291  };
292  virtual void relax(int shell,
293  EGS_Float ecut, EGS_Float pcut,
294  EGS_RandomGenerator *rndm, double &edep,
296  (void)shell;
297  (void)ecut;
298  (void)pcut;
299  (void)rndm;
300  (void)edep;
301  (void)particles;
302  };
303  virtual void setBetaIntensity(double newIntensity) = 0;
304  int getCharge() const;
305  void incrNumSampled();
306  EGS_I64 getNumSampled() const;
307  unsigned short int getZ() const;
308  unsigned short int getAtomicWeight() const;
309  unsigned short int getForbidden() const;
310  void setSpectrum(EGS_AliasTable *bspec);
311  EGS_AliasTable *getSpectrum() const;
312  vector<double> ecShellIntensity;
313 
314 protected:
315  EGS_I64 numSampled;
316  double finalEnergy;
317  double betaIntensity;
318  int q;
319  unsigned short int Z;
320  unsigned short int A;
321  unsigned short int forbidden;
322  EGS_AliasTable *spectrum;
323 };
324 
325 // Beta- record
327 public:
328  BetaMinusRecord(vector<string> ensdf, ParentRecord *myParent,
329  NormalizationRecord *myNormalization, LevelRecord *myLevel);
330 
331  double getFinalEnergy() const;
332  double getBetaIntensity() const;
333  double getBetaIntensityUnc() const;
334  void setBetaIntensity(double newIntensity);
335 
336 private:
337  void processEnsdf();
338  double betaIntensityUnc;
339 };
340 
341 // Beta+ Record (and Electron Capture)
343 public:
344  BetaPlusRecord(vector<string> ensdf, ParentRecord *myParent,
345  NormalizationRecord *myNormalization, LevelRecord *myLevel);
346 
347  double getFinalEnergy() const;
348  double getBetaIntensity() const;
349  double getPositronIntensity() const;
350  double getPositronIntensityUnc() const;
351  double getECIntensityUnc() const;
352  void setBetaIntensity(double newIntensity);
353  void setPositronIntensity(double newIntensity);
354  void relax(int shell,
355  EGS_Float ecut, EGS_Float pcut,
356  EGS_RandomGenerator *rndm, double &edep,
358 
359 protected:
360  double ecIntensity,
361  positronIntensity,
362  ecIntensityUnc,
363  positronIntensityUnc;
364 
365 private:
366  void processEnsdf();
367 };
368 
369 // Gamma record
372 public:
373  GammaRecord(vector<string> ensdf, ParentRecord *myParent,
374  NormalizationRecord *myNormalization,
375  LevelRecord *myLevel);
376  GammaRecord(GammaRecord *gamma);
377 
378  double getDecayEnergy() const;
379  double getTransitionIntensity() const;
380  double getGammaIntensity() const;
381  double getGammaIntensityUnc() const;
382  double getICIntensity() const;
383  double getICIntensityUnc() const;
384  double getIPIntensity() const;
385  double getIPIntensityUnc() const;
386  void setTransitionIntensity(double newIntensity);
387  void setGammaIntensity(double newIntensity);
388  void setICIntensity(double newIntensity);
389  double getMultiTransitionProb() const;
390  void setMultiTransitionProb(double newIntensity);
391  int getCharge() const;
392  LevelRecord *getFinalLevel() const;
393  void setFinalLevel(LevelRecord *newLevel);
394  void incrGammaSampled();
395  void incrICSampled();
396  void incrIPSampled();
397  EGS_I64 getGammaSampled() const;
398  EGS_I64 getICSampled() const;
399  EGS_I64 getIPSampled() const;
400  vector<double> icIntensity;
401  double getBindingEnergy(int shell) const;
402  void relax(int shell,
403  EGS_Float ecut, EGS_Float pcut,
404  EGS_RandomGenerator *rndm, double &edep,
406 
407 protected:
408  EGS_I64 numGammaSampled, numICSampled, numIPSampled;
409  double decayEnergy;
410  double transitionIntensity,
411  multipleTransitionProb,
412  gammaIntensity,
413  gammaIntensityUnc,
414  icCoeff,
415  icCoeffUnc,
416  ipCoeff,
417  ipCoeffUnc;
418  int q;
419  LevelRecord *finalLevel;
420 
421 private:
422  void processEnsdf();
423 };
424 
425 // Alpha record
426 class EGS_EXPORT AlphaRecord : public Record, public ParentRecordLeaf, public
428 public:
429  AlphaRecord(vector<string> ensdf, ParentRecord *myParent,
430  NormalizationRecord *myNormalization, LevelRecord *myLevel);
431 
432  double getFinalEnergy() const;
433  double getAlphaIntensity() const;
434  double getAlphaIntensityUnc() const;
435  int getCharge() const;
436  void setAlphaIntensity(double newIntensity);
437  void incrNumSampled();
438  EGS_I64 getNumSampled() const;
439 
440 protected:
441  EGS_I64 numSampled;
442  double finalEnergy,
443  alphaIntensity,
444  alphaIntensityUnc;
445  int q;
446 
447 private:
448  void processEnsdf();
449 };
450 
506 
507 public:
508 
512  EGS_Ensdf(const string nuclide, const string ensdf_filename="",
513  const string relaxType="eadl", const bool allowMultiTrans=false, int verbosity=1);
514 
516  ~EGS_Ensdf();
517 
518  vector<Record * > getRecords() const;
519  vector<BetaRecordLeaf *> getBetaRecords() const;
520  vector<ParentRecord * > getParentRecords() const;
521  vector<LevelRecord * > getLevelRecords() const;
522  vector<AlphaRecord * > getAlphaRecords() const;
523  vector<GammaRecord * > getGammaRecords() const;
524  vector<GammaRecord * > getMetastableGammaRecords() const;
525  vector<GammaRecord * > getUncorrelatedGammaRecords() const;
526  vector<double > getXRayIntensities() const;
527  vector<double > getXRayEnergies() const;
528  vector<double > getAugerIntensities() const;
529  vector<double > getAugerEnergies() const;
530 
531  string radionuclide;
532  int verbose;
533  string relaxationType;
534  unsigned short int Z;
535  double decayDiscrepancy;
536  bool allowMultiTransition;
537 
538  void normalizeIntensities();
539 
540 protected:
541 
542  unsigned short int findAtomicWeight(string element);
543  void parseEnsdf(vector<string> ensdf);
544  void buildRecords();
545 
546  void getEmissionsFromComments();
547 
548  ifstream ensdf_file;
549  unsigned short int A;
550 
551  vector<Record * > myRecords;
552  vector<CommentRecord * > myCommentRecords;
553  vector<ParentRecord * > myParentRecords;
554  vector<NormalizationRecord * > myNormalizationRecords;
555  vector<LevelRecord * > myLevelRecords;
556  vector<BetaRecordLeaf *> myBetaRecords;
557  vector<BetaMinusRecord * > myBetaMinusRecords;
558  vector<BetaPlusRecord * > myBetaPlusRecords;
559  vector<AlphaRecord * > myAlphaRecords;
560  vector<GammaRecord * > myGammaRecords;
561  vector<GammaRecord * > myMetastableGammaRecords;
562  vector<GammaRecord * > myUncorrelatedGammaRecords;
563 
564 private:
565 
566  vector<vector<string> > recordStack;
567  vector<string> commentLines;
568  vector<double> xrayEnergies,
569  xrayIntensities,
570  augerEnergies,
571  augerIntensities;
572  ParentRecord *previousParent;
573 
574  // The ENSDF format defines an isomeric transition as having a half-life of greater than 0.1 seconds
575  float isomerCutoff = 0.1;
576 };
577 
578 
579 
580 
581 #endif
A class for sampling random values from a given probability distribution using the alias table techni...
The ensdf class for reading ensdf format data files.
Definition: egs_ensdf.h:505
Base random number generator class. All random number generators should be derived from this class.
Definition: egs_rndm.h:90
EGS_AliasTable class header file.
EGS_AtomicRelaxations class header file.
Global egspp functions header file.
Defines the EGS_EXPORT and EGS_LOCAL macros.
#define EGS_EXPORT
Export symbols from the egspp library.
Definition: egs_libconfig.h:90
Attempts to fix broken math header files.