File indexing completed on 2024-11-25 02:29:49
0001 import copy
0002 from PhysicsTools.HeppyCore.framework.analyzer import Analyzer
0003 from PhysicsTools.Heppy.analyzers.AutoHandle import AutoHandle
0004 import random
0005
0006 def pv(vc):
0007 print('x = {x:5.4f}, y = {y:5.4f}, z = {z:5.4f}'.format(x=vc.X(),
0008 y=vc.Y(),
0009 z=vc.Z()))
0010
0011 class MetAnalyzer( Analyzer ):
0012 '''Analyze MET in Z+jet events.
0013 Need a to provide a module creating event.diLepton
0014 earlier in the sequence.
0015 '''
0016
0017 def declareHandles(self):
0018 super(MetAnalyzer, self).declareHandles()
0019 self.handles['met'] = AutoHandle(
0020 self.cfg_ana.metCol,
0021 self.cfg_ana.metType
0022 )
0023
0024
0025 def beginLoop(self, setup):
0026 super(MetAnalyzer,self).beginLoop(setup)
0027
0028
0029 def process(self, iEvent, event):
0030 self.readCollections( iEvent )
0031 event.met = self.handles['met'].product()[0]
0032 met = event.met
0033
0034
0035 if not hasattr(event, 'diLepton'):
0036 return False
0037
0038 diL = event.diLepton
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 mVect = met.p4().Vect()
0049 mVect.SetZ(0.)
0050 vVect = diL.p4().Vect()
0051 vVect.SetZ(0.)
0052 recoilVect = copy.deepcopy(mVect)
0053 recoilVect -= vVect
0054
0055 uvVect = vVect.Unit()
0056 zAxis = type(vVect)(0,0,1)
0057 uvVectPerp = vVect.Cross(zAxis).Unit()
0058
0059 u1 = - recoilVect.Dot(uvVect)
0060 u2 = recoilVect.Dot(uvVectPerp)
0061
0062 event.u1 = u1
0063 event.u2 = u2
0064
0065 if self.cfg_ana.verbose:
0066 print('met', met.pt())
0067 print('diL', diL)
0068 print('vVect')
0069 pv(vVect)
0070 print('uvVect')
0071 pv(uvVect)
0072 print('uvVectPerp')
0073 pv(uvVectPerp)
0074 print(u1, u2)
0075
0076 return True
0077
0078
0079
0080
0081
0082