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

In This Package:

SpallB12.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # chao@bnl.gov, 2011-08-07
00003 '''
00004 Spallation B-12 Tagger
00005 Usage:
00006     nuwa.py --no-history -A "1*s" -n -1 -m"Tagger.MuonTagger.SpallB12" input.root
00007 '''
00008 
00009 from UserTagging.UserTaggingAlg import UserTaggingAlg
00010 from Tagger.DataHelpers import RecDataHelper, CalibDataHelper
00011 
00012 from GaudiPython import SUCCESS, FAILURE
00013 from GaudiPython import gbl
00014 import GaudiKernel.SystemOfUnits as units
00015 
00016 ServiceMode = gbl.ServiceMode
00017 
00018 # ===========================================
00019 class SpallB12Tagging(UserTaggingAlg):
00020     'Coincidence Data for AD coincidence events'
00021 
00022     def __init__(self, name):
00023         UserTaggingAlg.__init__(self, name)
00024         
00025         self.location = '/Events/Rec/AdSimple'
00026     # -------------------------------------------
00027     def initTagList(self):        
00028         self.daqDetailsSvc = self.svc('IDaqDetailsSvc','DetailsFromRecordSvc')
00029         
00030         if self.daqDetailsSvc == None: 
00031             self.error("Failed to get IDaqDetailsSvc") 
00032             return FAILURE 
00033         
00034         self.myTag = self.addTag('SpallB12', '/Event/Tag/SpallB12'
00035             ).setBaseHeader(self.location)
00036             
00037         self.myData = self.myTag.addData('SpallB12', '/Event/Data/SpallB12')
00038         self.myData.addInt('runNo', 'fileNo', 'nMuon'
00039             ).addFloatArray('dtLastMuon_ms', 'muon_nPESum')
00040         for paraName in RecDataHelper.DATA_SUMMARY_INT:
00041             self.myData.addInt(paraName)
00042         for paraName in RecDataHelper.DATA_SUMMARY_FLOAT:
00043             self.myData.addFloat(paraName)
00044 
00045         # add CalibStats info
00046         for paraName in CalibDataHelper.DATA_STATS_INT:
00047             self.myData.addInt('calib_'+paraName)
00048         for paraName in CalibDataHelper.DATA_STATS_FLOAT:
00049             self.myData.addFloat('calib_'+paraName)
00050                    
00051     # -------------------------------------------
00052     def check(self, evt):     
00053         recHdr = evt[self.location]
00054         if not recHdr:
00055             self.warning('cannot find header at ' + self.location)
00056             return FAILURE
00057 
00058         detId = recHdr.context().GetDetId()
00059         if not (detId == 1 or detId == 2):
00060             return False
00061         
00062         data = RecDataHelper.summary(recHdr)                  
00063         if not (4 < data['e'] < 20): 
00064             return False
00065 
00066         # self.info('energy ' + str(data['e']) + ', det ' + str(detId))
00067 
00068         timeStamp = recHdr.timeStamp()
00069         dtLastMuon_ms = []
00070         muon_nPESum = []
00071         aes = self.getAES('/Event/Data/CalibStats')
00072         for i in range(1, len(aes)):
00073             aes_header = aes[i]
00074             dt = gbl.TimeStamp(timeStamp)
00075             dt.Subtract(aes_header.timeStamp())
00076             
00077             # only save last 500 ms 
00078             if dt.GetSeconds()>0.5:
00079                 break  
00080             
00081             # veto 1 ms after an AD muon
00082             aes_detId = aes_header.context().GetDetId()    
00083             aes_nPESum = aes_header.getFloat('nPESum')
00084             if dt.GetSeconds()<1e-3 and aes_nPESum>3.5e4 and aes_detId == detId:
00085                 break
00086             
00087             # muon need to be on same AD
00088             if not (aes_detId == detId):
00089                 # self.info('skip aes: aesdet:%d det:%d' % (aes_detId, detId))
00090                 continue
00091                         
00092             # deposit muon energy in AD need to be large
00093             if (aes_nPESum < 3e5):
00094                 # self.info('skip: npe' + str(aes_nPESum))
00095                 continue
00096                 
00097             # found a related muon!
00098             dtLastMuon_ms.append(dt.GetSeconds()*1e3)
00099             muon_nPESum.append(aes_nPESum)
00100 
00101         
00102         nMuon = len(dtLastMuon_ms)
00103         if nMuon == 0: 
00104             # no related muon, skip tagging
00105             return False
00106         
00107         self.myTag.tagIt()
00108         
00109         # save User Data
00110         self.myData.set("nMuon", nMuon)
00111         for i in range(nMuon):
00112             self.myData.append("dtLastMuon_ms", dtLastMuon_ms[i])
00113             self.myData.append("muon_nPESum", muon_nPESum[i])
00114 
00115         for paraName in RecDataHelper.DATA_SUMMARY_INT + RecDataHelper.DATA_SUMMARY_FLOAT:
00116             self.myData.set(paraName, data[paraName])
00117         
00118         calibStats = evt['/Event/Data/CalibStats']
00119         if calibStats:
00120             for paraName in CalibDataHelper.DATA_STATS_INT:
00121                 self.myData.set('calib_'+paraName, calibStats.getInt(paraName))
00122             for paraName in CalibDataHelper.DATA_STATS_FLOAT:
00123                 self.myData.set('calib_'+paraName, calibStats.getFloat(paraName))
00124         else:
00125             self.warning("no calibStats at /Event/Data/CalibStats")
00126 
00127         svcMode = ServiceMode(recHdr.context(), 0)
00128         runDetails = self.daqDetailsSvc.runDetails(svcMode)
00129         if runDetails:
00130             runNo = runDetails.runNumber()
00131         else:
00132             runNo = -1
00133         fileDetails = self.daqDetailsSvc.fileDetails(svcMode)
00134         if fileDetails:
00135             fileNo = fileDetails.fileNumber()
00136         else:
00137             fileNo = -1
00138         self.myData.set("runNo", runNo)
00139         self.myData.set("fileNo", fileNo)
00140         
00141         
00142         
00143 #####  Job Configuration for nuwa.py ########################################
00144 options = None
00145 
00146 def configure(argv=[]):
00147     """Configuration with command line arguments"""   
00148     global options 
00149 
00150 
00151 def run(app):
00152     app.ExtSvc += ["DetailsFromRecordSvc"]
00153     
00154     myAlg = SpallB12Tagging("SpallB12Tagging")
00155     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