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