/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

GenData.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 '''
00003 Usage:
00004 '''
00005 
00006 from UserTagging.UserTaggingAlg import UserTaggingAlg
00007 from UserTagging.Models import Tag, Data, Int, Float, IntArray, FloatArray
00008 from GaudiPython import SUCCESS, FAILURE
00009 from GaudiPython import gbl, loaddict
00010 from DybPython.Util import irange
00011 import GaudiKernel.SystemOfUnits as units
00012 import PyCintex
00013  
00014 loaddict("libCLHEPRflx")
00015 loaddict("libHepMCRflx")
00016 
00017 class GenData(UserTaggingAlg):
00018     '''Add Generator Info to UserData'''
00019         
00020     # ----------------------------------------    
00021     def initTagList(self):
00022         # for details see doc-6020
00023         #
00024         # generator info, size of nGen
00025         # positon from first vtx
00026         # nVtx is the number of 'real primary' particles of each generator
00027         # IBD event has nVtx = 1 : nu_e_bar
00028         # Radioactive event nVtx > 1 for correlated decay events
00029         # Muon event nVtx = 1 : one out-going muon
00030         #
00031         # the first incoming particles of each vtx info, size of nVtxTotal, or 0 (muon)
00032         # for IBD, pid = [-12] for nu_e
00033         #          KE = KE for nu_e
00034         # for radioactive event, pid = [parent nuclei]
00035         # for radioactive event, t[j] - t[i] tells the correlation time
00036         # nOut[i] is the number of out-going particles at each primary vertex
00037         # nOut[i] == 2 for IBD 
00038         # nIn[i] should be 1, but 0 for muons
00039         #
00040         # outgoing particles info, size of nOutTotal
00041         # for IBD, out_pid = [-11, 2112]
00042         # for radioactive event, out_pid = [daughter nucliei+decay particles]
00043         self.addTag('Dummy', ''
00044             ).addData('GenData', '/Event/UserData/General/GenData'
00045             ).addInt('nGen', 'nVtxTotal', 'nOutTotal'
00046             ).addIntArray('genType', 'nVtx'
00047             ).addFloatArray('genX', 'genY', 'genZ'
00048             ).addIntArray('nIn', 'nOut', 'in_pid', 'out_pid'
00049             ).addFloatArray('in_x', 'in_y', 'in_z', 'in_t', 'in_KE', 'in_px', 'in_py', 'in_pz'
00050             ).addFloatArray('out_x', 'out_y', 'out_z', 'out_t', 'out_KE', 'out_px', 'out_py', 'out_pz')
00051                
00052         self.target_de_name = '/dd/Structure/AD/db-ade1/db-sst1/db-oil1'
00053         
00054         self.genTypes = {
00055             "IBD_gds":11, "IBD_lso":12, "IBD_oil":13, "IBD_acrylic":14,           
00056             "U238_gds":21, "U238_lso":22, "U238_PMT":23, "U238_sst":24,
00057             "Th232_gds":31, "Th232_lso":32, "Th232_PMT":33, "Th232_sst":34,
00058             "K40_gds":41, "K40_lso":42, "K40_PMT":43, "K40_sst":44,
00059             "Co60_sst":54,
00060         }
00061         
00062     # ----------------------------------------
00063     def check(self, evt):
00064 
00065         readoutHdr = evt['/Event/Readout/ReadoutHeader']
00066         if not readoutHdr:
00067             self.warning('cannot find readoutHdr')
00068             return
00069         
00070         genHdrs = readoutHdr.findHeaders(gbl.DayaBay.GenHeader.classID())
00071         self.SaveGenData(genHdrs)
00072         
00073         self.tagIt('Dummy')
00074         
00075     # ----------------------------------------
00076     def SaveGenData(self, genHdrs):
00077 
00078         myData = self.getTag('Dummy').getData('GenData')
00079 
00080         de = self.getDet(self.target_de_name)
00081         if not de:
00082             self.info('Failed to get DE' + self.target_de_name)
00083             return FAILURE
00084         Gaudi = PyCintex.makeNamespace('Gaudi')
00085                                 
00086         # number of generators associated with this readout
00087         # nGen should be one except for pile-up events    
00088         nGen = len(genHdrs) 
00089         # total number of 'real primary' particles (vtx)
00090         nVtxTotal = 0
00091         # total number of outgoing particles
00092         nOutTotal = 0
00093  
00094         for genHdr in genHdrs:
00095             genName = genHdr.generatorName()
00096             self.debug("genName:" + genName)
00097             myData.append('genType', self.genTypes.get(genName, 0))
00098             
00099             nVtx = 0
00100             genEvt = genHdr.event()
00101             for vtx in irange(genEvt.vertices_begin(), genEvt.vertices_end()):
00102                 # do stuff with the vertex
00103                 nVtx += 1
00104                 nVtxTotal += 1
00105                 position = vtx.position()
00106                 genGlbPoint = Gaudi.XYZPoint(
00107                     position.x(), 
00108                     position.y(),
00109                     position.z()
00110                 )
00111                 genLclPoint = de.geometry().toLocal(genGlbPoint)
00112                 myData.append('in_x', genLclPoint.x()/units.mm)
00113                 myData.append('in_y', genLclPoint.y()/units.mm)
00114                 myData.append('in_z', genLclPoint.z()/units.mm)
00115                 myData.append('in_t', vtx.position().t()/units.microsecond)
00116                 
00117                 if nVtx == 1:
00118                     myData.append('genX', genLclPoint.x()/units.mm)
00119                     myData.append('genY', genLclPoint.y()/units.mm)
00120                     myData.append('genZ', genLclPoint.z()/units.mm)
00121                                 
00122                 nIn = 0    
00123                 for particle in irange(vtx.particles_in_const_begin(),
00124                                       vtx.particles_in_const_end()):
00125                     # do stuff with the incoming particles
00126                     nIn += 1
00127                     if nIn == 1:                  
00128                         myData.append('in_pid', particle.pdg_id())
00129                         momentum = particle.momentum()
00130                         myData.append('in_KE', (momentum.e() - momentum.m())/units.MeV)
00131                         myData.append('in_px', momentum.px()/units.MeV)
00132                         myData.append('in_py', momentum.py()/units.MeV)
00133                         myData.append('in_pz', momentum.pz()/units.MeV)
00134                 myData.append('nIn', nIn)
00135                 
00136                 nOut = 0
00137                 for particle in irange(vtx.particles_out_const_begin(),
00138                                        vtx.particles_out_const_end()):
00139                     # do stuff with the outgoing particles
00140                     nOut += 1
00141                     nOutTotal += 1
00142                     myData.append('out_pid', particle.pdg_id())
00143                     momentum = particle.momentum()
00144                     myData.append('out_KE', (momentum.e() - momentum.m())/units.MeV)
00145                     myData.append('out_px', momentum.px()/units.MeV)
00146                     myData.append('out_py', momentum.py()/units.MeV)
00147                     myData.append('out_pz', momentum.pz()/units.MeV)
00148                                  
00149                 myData.append('nOut', nOut)
00150                     
00151             myData.append('nVtx', nVtx)
00152 
00153         # set more user data
00154         myData.set("nGen", nGen
00155             ).set("nVtxTotal", nVtxTotal
00156             ).set("nOutTotal", nOutTotal)
00157         
00158         # print 'genX: ', myData.get('genX')
00159             
00160 #####  Job Configuration for nuwa.py ########################################
00161 
00162 def configure(argv=[]):
00163     pass
00164 
00165 def run(app):
00166     myAlg = GenData("UserData::GenData")
00167     app.addAlgorithm(myAlg)
00168     pass                    
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:02:01 for UserTagging by doxygen 1.7.4