File indexing completed on 2023-03-17 11:15:46
0001 import copy
0002
0003 from PhysicsTools.HeppyCore.framework.analyzer import Analyzer
0004 from PhysicsTools.HeppyCore.statistics.counter import Counter, Counters
0005 from PhysicsTools.Heppy.analyzers.AutoHandle import AutoHandle
0006
0007 from PhysicsTools.Heppy.physicsobjects.RochesterCorrections import rochcor
0008 from PhysicsTools.Heppy.physicsobjects.Particle import Particle
0009 from PhysicsTools.Heppy.physicsobjects.Muon import Muon
0010
0011 from ROOT import gSystem
0012 gSystem.Load("libDataFormatsRecoCandidate.so")
0013 from ROOT import reco
0014
0015 class DiMuon( reco.LeafCandidate ):
0016 """ Simple DiMuon object
0017
0018 using the LeafCandidate (~simple particle ) dataformat from CMSSW as a base.
0019 this class is made in such a way that it behaves almost exactly
0020 as physicsobjects.DiObjects.DiMuon.
0021 """
0022
0023 def __init__(self, l1, l2, diLepton):
0024 '''l1 and l2 are the legs, possibly recalibrated.
0025 diLepton is the original diLepton, used only in the met function'''
0026 self.diLepton = diLepton
0027 self.l1 = l1
0028 self.l2 = l2
0029 self.sumpt = l1.pt() + l2.pt()
0030 super(DiMuon, self).__init__(0, l1.p4()+l2.p4())
0031
0032 def __str__(self):
0033 return 'DiMuon: mass={mass:5.2f}, sumpt={sumpt:5.2f}, pt={pt:5.2f}'.format(
0034 mass = self.mass(),
0035 sumpt = self.sumpt,
0036 pt = self.pt()
0037 )
0038
0039 def met(self):
0040 '''this is going to be needed to compute VBF related quantities.
0041 just giving the met associated to the original di-lepton
0042 '''
0043 return self.diLepton.met()
0044
0045 def leg1(self):
0046 return self.l1
0047
0048 def leg2(self):
0049 return self.l2
0050
0051
0052 class ZMuMuRochCorAnalyzer( Analyzer ):
0053
0054 def process(self, iEvent, event):
0055
0056 def correctDiLepton( diLepton ):
0057 '''Corrects a di-lepton.
0058
0059 This function is defined within the process function to have
0060 access to the variables available there, namely event.run.
0061 The goal of this function is to be able to call it with map,
0062 to get very compact code.
0063 '''
0064 p4_1 = rochcor.corrected_p4( diLepton.leg1(), event.run )
0065 p4_2 = rochcor.corrected_p4( diLepton.leg2(), event.run )
0066
0067
0068 l1 = diLepton.leg1()
0069 l2 = diLepton.leg2()
0070 l1.setP4(p4_1)
0071 l2.setP4(p4_2)
0072 diLeptonCor = DiMuon( l1, l2, diLepton)
0073 return diLeptonCor
0074
0075 event.diLeptonRaw = copy.copy(event.diLepton)
0076 event.diLepton = correctDiLepton( event.diLeptonRaw )