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

In This Package:

ADCoincTag.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 '''
00003 Coincidence Tagger for AD events
00004 Usage:
00005     nuwa.py --no-history -A "1*s" -n -1 -m"Tagger.CoincTagger.ADCoincTag" input.root
00006 Help:
00007     nuwa.py -m"Tagger.CoincTagger.ADCoincTag -h"
00008     
00009 zhang@caltech.edu, 2011-05-03
00010 '''
00011 
00012 from UserTagging.UserTaggingAlg import UserTaggingAlg
00013 from GaudiPython import SUCCESS, FAILURE
00014 from GaudiPython import gbl
00015 import GaudiKernel.SystemOfUnits as units
00016 
00017 # ===========================================
00018 class ADCoincTag(UserTaggingAlg):
00019     'Coincidence Tagger for AD events'
00020 
00021     def __init__(self, name):
00022         UserTaggingAlg.__init__(self, name)
00023         
00024         self.dTCut = 300*units.microsecond
00025         self.location = "/Event/Rec/AdSimple"
00026             
00027     # -------------------------------------------
00028     def initTagList(self):
00029         self.info("Coincidence window: %.3f microsecond" % (
00030             self.dTCut/units.microsecond,))
00031             
00032         self.ADTagNames = { 
00033             gbl.DetectorId.kAD1 : 'AD1',
00034             gbl.DetectorId.kAD2 : 'AD2',
00035             gbl.DetectorId.kAD3 : 'AD3',
00036             gbl.DetectorId.kAD4 : 'AD4',
00037         }
00038         self.inputHeaders = {}
00039         self.lastTimeStamp = {} # hold the last timestamp of sub detectors (inluding IWS, OWS, RPC)
00040         
00041         # initialize AD Coincidence Tags
00042         # initialize inputHeaders to hold the recHeaders of multiplets
00043         for tagName in self.ADTagNames.values():
00044             self.addTag(tagName , '/Event/Tag/Coinc/'+tagName+'CoincTag'
00045                 ).setBaseHeader(self.location)
00046             self.inputHeaders[tagName] = []
00047         
00048     # -------------------------------------------
00049     def check(self, evt):
00050         header = evt[self.location]
00051         if not header:
00052             self.warning('cannot find header at ' + self.location)
00053             return FAILURE
00054 
00055         timeStamp = header.timeStamp()
00056         detectorId = header.context().GetDetId()        
00057         self.debug("executing #%d, Det=%d, TS=%.6f ms" % (
00058             self.execNumber, detectorId, timeStamp.GetSeconds()*1e3))
00059         lastTimeStamp = self.lastTimeStamp.get(detectorId, timeStamp)
00060         self.lastTimeStamp[detectorId] = timeStamp
00061         
00062         tagName = self.ADTagNames.get(detectorId, '')
00063         if not tagName: return  # IWS/OWS/RPC
00064         
00065         dt = gbl.TimeStamp(timeStamp)
00066         dt.Subtract(lastTimeStamp)
00067         if dt.GetSeconds()*units.second > self.dTCut:
00068             multiplicity = len(self.inputHeaders[tagName])
00069             if multiplicity < 2:
00070                 # found singles, clear the inputHeaders
00071                 self.inputHeaders[tagName] = []
00072             else:
00073                 # found a gap, save last conincidence's multiplets         
00074                 # self.info('#%d: found one coinc event in %s, multiplicity %d' % 
00075                 #     (self.execNumber, tagName, multiplicity))
00076                 myTag = self.getTag(tagName)
00077                 myTag.setInputHeaders(self.inputHeaders[tagName])
00078                  
00079                 # clear the inputHeaders
00080                 self.inputHeaders[tagName] = []
00081                 
00082                 # trigger the actual saving process
00083                 myTag.tagIt()
00084         
00085         self.inputHeaders[tagName].append(header)        
00086         
00087 #####  Job Configuration for nuwa.py ########################################
00088 options = None
00089 
00090 def configure(argv=[]):
00091     """Configuration with command line arguments"""   
00092     global options 
00093     from optparse import OptionParser
00094     
00095     parser = OptionParser()
00096     parser.add_option("-c", "--coincidence-dt", type="string",
00097         default="300*microsecond",
00098         help="AD coincidence time window")
00099     parser.add_option("-l", "--location", type="string",
00100         default="/Event/Rec/AdSimple",
00101         help="Target for AD coincidence tagging")
00102     (options, args) = parser.parse_args(args=argv)
00103 
00104 def run(app):
00105     from DybPython.Tools import unitify
00106     
00107     myAlg = ADCoincTag("ADCoincTag")
00108     myAlg.dTCut = unitify(options.coincidence_dt)
00109     myAlg.location = options.location
00110     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