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

In This Package:

ADSingleData.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # xiadm@ihep.ac.cn, 2011-07-03
00003 '''
00004 Single Data for AD single events
00005 Usage:
00006     nuwa.py --no-history -A "1*s" -n -1 -m"Tagger.SingleTagger.ADSingleData" input.root
00007 Help:
00008     nuwa.py -m"Tagger.SingleTagger.ADSingleData -h"
00009 '''
00010 
00011 from UserTagging.UserTaggingAlg import UserTaggingAlg
00012 from Tagger.DataHelpers import RecDataHelper, CalibDataHelper
00013 from Tagger.DataHelpers import GenDataHelper, SimDataHelper
00014 
00015 from GaudiPython import SUCCESS, FAILURE
00016 from GaudiPython import gbl
00017 import GaudiKernel.SystemOfUnits as units
00018 
00019 # ===========================================
00020 class ADSingleData(UserTaggingAlg):
00021     'single Data for AD single events'
00022 
00023     def __init__(self, name):
00024         UserTaggingAlg.__init__(self, name)
00025         
00026         self.tag_data_locations = {
00027             '/Event/Tag/Single/AD1SingleTag' : '/Event/Data/SingleData/AD1SingleData',
00028             '/Event/Tag/Single/AD2SingleTag' : '/Event/Data/SingleData/AD2SingleData',
00029         }
00030         self.location = '/Event/Rec/AdSimple'
00031         self.isSimulation = False
00032 
00033     # -------------------------------------------
00034     def initTagList(self):        
00035         self.coordSvc = self.svc('ICoordSysSvc','CoordSysSvc')
00036         if self.coordSvc == None:
00037             self.error("Failed to get ICoordSysSvc")
00038             return FAILURE
00039         
00040         # create ADSingleData for each predefined tag
00041         for tagName, dataName in self.tag_data_locations.items():
00042          #   make it simple by using path as name as well
00043             myTag = self.addTag(tagName, '').setBaseHeader(self.location)
00044             myData = myTag.addData(dataName , dataName)
00045             myData.addInt('multiplicity'
00046                ).addIntArray('dt_ns', 'I', 'J')
00047             
00048             # add RecHeader info
00049             for paraName in RecDataHelper.DATA_SUMMARY_INT:
00050                 myData.addIntArray(paraName)
00051             for paraName in RecDataHelper.DATA_SUMMARY_FLOAT:
00052                 myData.addFloatArray(paraName)
00053             '''
00054             # add CalibStats info
00055             for paraName in CalibDataHelper.DATA_STATS_INT:
00056                 myData.addIntArray('calib_'+paraName)
00057             for paraName in CalibDataHelper.DATA_STATS_FLOAT:
00058                 myData.addFloatArray('calib_'+paraName)
00059             for paraName in CalibDataHelper.DATA_DTLAST_FLOAT:
00060                 myData.addFloatArray(paraName) 
00061             
00062             if self.isSimulation:
00063                 # add GenHeader info
00064                 for paraName in GenDataHelper.DATA_SUMMARY_INT:
00065                     myData.addIntArray(paraName)
00066                 for paraName in GenDataHelper.DATA_SUMMARY_FLOAT:
00067                     myData.addFloatArray(paraName)
00068 
00069                 # add SimHeader Info
00070                 for paraName in SimDataHelper.DATA_SUMMARY_INT:
00071                     myData.addIntArray(paraName)
00072                 for paraName in SimDataHelper.DATA_NCAP_INT:
00073                     myData.addIntArray(paraName)
00074                 for paraName in SimDataHelper.DATA_NCAP_FLOAT:
00075                     myData.addFloatArray(paraName)
00076               '''       
00077     # -------------------------------------------
00078     def check(self, evt):                
00079         for tagName, dataName in self.tag_data_locations.items():
00080             tagHeader = evt[tagName]  # tagName == tagPath
00081             if not tagHeader:
00082                 continue  # skip non-single events
00083             else:
00084                 myData = self.getTag(tagName).getData(dataName)
00085                 self.SaveADSingleData(myData, tagHeader)
00086                 self.tagIt(tagName)
00087                 break  # the AD single tags are exclusive
00088     
00089     # -------------------------------------------
00090     def SaveADSingleData(self, myData, tagHeader):
00091         '''
00092         Keyword arguments:
00093             myData -- the Data object defined in UserTagging.Models
00094             tagHeader -- the AD single UserTag object
00095         '''
00096 
00097         singleRecHdrs = tagHeader.inputHeaders()
00098         firstHdr = True
00099         for recHdr in singleRecHdrs:
00100             data = RecDataHelper.summary(recHdr)
00101             # save RecHeader info
00102             for paraName in RecDataHelper.DATA_SUMMARY_INT:
00103                 myData.append(paraName, data[paraName])
00104             for paraName in RecDataHelper.DATA_SUMMARY_FLOAT:
00105                 myData.append(paraName, data[paraName])
00106             if firstHdr:
00107                 t0_s = data["t_s"]
00108                 t0_ns = data["t_ns"]
00109                 firstHdr = False
00110             myData.append('dt_ns', (data["t_s"]-t0_s)*1e9 + data["t_ns"] - t0_ns)
00111             '''   
00112             # save calib stats
00113             calibStatsHdrs = recHdr.findHeaders(gbl.DayaBay.UserDataHeader.classID())
00114             if calibStatsHdrs and len(calibStatsHdrs) == 1:
00115                 calibStats = calibStatsHdrs[0]
00116                 for paraName in CalibDataHelper.DATA_STATS_INT:
00117                     myData.append('calib_'+paraName, calibStats.getInt(paraName))
00118                 for paraName in CalibDataHelper.DATA_STATS_FLOAT:
00119                     myData.append('calib_'+paraName, calibStats.getFloat(paraName))
00120                 for paraName in CalibDataHelper.DATA_DTLAST_FLOAT:
00121                     myData.append(paraName, calibStats.getFloat(paraName))
00122             else:
00123                 self.warning("no calibStats in recHeader's inputHeaders")
00124 
00125             
00126             # save some gen/sim info for simualtion files
00127             if self.isSimulation:
00128                 # save GenHeader info
00129                 genHdrs = recHdr.findHeaders(gbl.DayaBay.GenHeader.classID())
00130                 data = GenDataHelper.summary(self, recHdr, genHdrs)
00131                 for paraName in GenDataHelper.DATA_SUMMARY_INT:
00132                     myData.append(paraName, data[paraName])
00133                 for paraName in GenDataHelper.DATA_SUMMARY_FLOAT:
00134                     myData.append(paraName, data[paraName])
00135 
00136                 # save SimHeader info
00137                 simHdrs = recHdr.findHeaders(gbl.DayaBay.SimHeader.classID())
00138                 data = SimDataHelper.summary(simHdrs)
00139                 for paraName in SimDataHelper.DATA_SUMMARY_INT:
00140                     myData.append(paraName, data[paraName])
00141                 data = SimDataHelper.nCapture(self, recHdr)
00142                 for paraName in SimDataHelper.DATA_NCAP_INT:
00143                     myData.append(paraName, data[paraName])
00144                 for paraName in SimDataHelper.DATA_NCAP_FLOAT:
00145                     myData.append(paraName, data[paraName])
00146             '''          
00147         multiplicity = len(singleRecHdrs)
00148         myData.set("multiplicity", multiplicity)
00149         # add the pairing array trick to allow easy TTree::Draw() such as
00150         # tree.Draw("e[J]:e[I]")
00151         for i in range(0, multiplicity-1):
00152             for j in range(i+1, multiplicity):
00153                 myData.append('I', i).append('J', j)
00154                 
00155         
00156 #####  Job Configuration for nuwa.py ########################################
00157 options = None
00158 
00159 def configure(argv=[]):
00160     """Configuration with command line arguments"""   
00161     global options 
00162     from optparse import OptionParser
00163     
00164     defaultLocations = ''
00165     for detname in ['AD1', 'AD2']:
00166         defaultLocations += '/Event/Tag/Single/%sSingleTag:/Event/Data/Single/%sSingleData ' % (detname, detname)
00167 
00168     parser = OptionParser()
00169     parser.add_option("-l", "--location", type="string",
00170         default='/Event/Rec/AdSimple',
00171         help="the TES path of target event header location")
00172     parser.add_option("-t", "--tag-data-locations", type="string",
00173         default=defaultLocations.rstrip(), 
00174         help="tagPath:dataPath pairs for AD single events")
00175     parser.add_option('--simulation',
00176         dest='isSimulation',
00177         action='store_true', default=False,
00178         help='flag for simulation files (save extra gen/truth info)')
00179     (options, args) = parser.parse_args(args=argv)
00180 
00181 def run(app):
00182     from DybPython.Tools import mapify
00183     app.ExtSvc += ["CoordSysSvc"]
00184     
00185     myAlg = ADSingleData("ADSingleData")
00186     myAlg.location = options.location
00187     myAlg.tag_data_locations = mapify(options.tag_data_locations)
00188     myAlg.isSimulation = options.isSimulation
00189     app.addAlgorithm(myAlg)
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:54:18 for Tagger by doxygen 1.7.4