| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

chain.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 '''
00004 Assemble radioactive decay chains.
00005 '''
00006 
00007 from g4data import G4RadData
00008 
00009 class G4DataChain(object):
00010     'A radioactive decay chain built from G4RadioActivity data files'
00011 
00012     # cache data.Isotope instantiations.  Look up via (z,a) tuple,
00013     # return list of that Isotope and different excitation energies
00014     _isotopes = {}
00015 
00016     # Precision by which to judge equality of nuclear excited state
00017     # energies
00018     energyPrecision = 0.01
00019 
00020     def __init__(self,z,a,correlation_time = None):
00021         ''' Build a decay chain starting from the given (ground state)
00022         nuclide with Z and A.  If a correlation time is given it will
00023         be used to separate the chain into sub-chains that start at
00024         nuclides with half lives greater than the correlation time.'''
00025 
00026         self.corrTime = correlation_time
00027         
00028         self.subChain = []
00029         self.groundStates = []
00030         self.head = self.chain(z,a)
00031         return
00032 
00033     def __str__(self):
00034         return str(self.head)
00035 
00036     def getIsotope(self,z,a,nucexenergy):
00037         'Retrieve isotope, return (iso,BOOL), BOOL is True if iso is freshly constructed'
00038 
00039         from data import Isotope
00040 
00041         try:
00042             isos = G4DataChain._isotopes[(z,a)]
00043         except KeyError:
00044             iso = Isotope(z,a,level=nucexenergy)
00045             G4DataChain._isotopes[(z,a)] = [iso]
00046             #print 'Making first seen: %s'%iso
00047             return iso,True
00048 
00049         for iso in isos:
00050             import math
00051             if math.fabs(nucexenergy - iso.level) <= G4DataChain.energyPrecision*nucexenergy:
00052                 #print 'Found in cache: %s'%iso
00053                 return iso,False # cache hit
00054             continue
00055 
00056         # found cached isotopes but wrong energy level
00057         iso = Isotope(z,a,level=nucexenergy)
00058         G4DataChain._isotopes[(z,a)].append(iso)
00059         assert len(G4DataChain._isotopes[(z,a)]) > 1
00060         #print 'In cache, new energy: %s'%iso
00061         return iso,True
00062         
00063 
00064     def chain(self,z,a,nucexenergy = 0.0):
00065         'Return Isotope coresponding to given inputs'
00066         import math, decay
00067         from data import units, Transition
00068 
00069         iso,new = self.getIsotope(z,a,nucexenergy)
00070         
00071         if new and nucexenergy == 0.0: self.groundStates.append(iso)
00072         
00073         if not new:                  # been there, done that
00074             #print "Already chained: %s"%iso
00075             return iso
00076         #print 'Chaining: %s'%iso
00077 
00078         # If nucleous is excited, deal with it promptly
00079         if nucexenergy > G4DataChain.energyPrecision*units.keV:
00080             daughter = self.chain(z,a)
00081             tran = Transition(iso,daughter,decay.GammaDecay(nucexenergy))
00082             return iso
00083 
00084         try:
00085             rd = G4RadData()
00086             nuc = rd.nuclideData(z,a)
00087         except ValueError,err:
00088             print 'No data for z=%d, a=%d, assuming stable (%s)'%(z,a,err)
00089             return iso
00090 
00091         state = nuc.excitedState(nucexenergy)
00092         if state is None: 
00093             print 'No excited state for z=%d, a=%d, E = %f, assuming stable'%(z,a,nucexenergy)
00094             return iso
00095         iso.halflife = state.halflife
00096         if new and iso.halflife > self.corrTime:
00097             self.subChain.append(iso)
00098 
00099         for dk in state.decays:
00100             daughter = self.chain(dk.daughterZ,dk.daughterA,dk.daughterExcitation)
00101             tran = Transition(iso,daughter,dk.radiation,fraction=dk.fraction)
00102 
00103         return iso
00104 
00105 if '__main__' == __name__:
00106     import sys, data
00107     d = G4DataChain(int(sys.argv[1]),int(sys.argv[2]))
00108     print 'Built chain'
00109     pp = data.PrettyPrint(d.head)
00110     print pp 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 21:01:08 2011 for GenDecay by doxygen 1.4.7