forked from cms-sw/cmssw
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cms-sw#621 from gpetruc/heppy_KaMuCa_76X
Heppy Kalman Muon Corrections for 76X
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
PhysicsTools/Heppy/python/physicsutils/KalmanMuonCorrector.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import PhysicsTools.Heppy.loadlibs | ||
import ROOT | ||
|
||
class KalmanMuonCorrector: | ||
def __init__(self, calibration, isMC, isSync=False, smearMode="none"): | ||
self.kamuca = ROOT.KalmanMuonCalibrator(calibration) | ||
self.isMC = isMC | ||
self.isSync = isSync | ||
self.smearMode = smearMode | ||
def correct(self, mu, run): | ||
newPt = self.kamuca.getCorrectedPt(mu.pt(), mu.eta(), mu.phi(), mu.charge()) | ||
newPtErr = newPt * self.kamuca.getCorrectedError(newPt, mu.eta(), mu.ptErr()/newPt) | ||
if self.isMC: # new we do the smearing | ||
if self.isSync: | ||
newPt = self.kamuca.smearForSync(newPt, mu.eta()) | ||
newPtErr = newPt * self.kamuca.getCorrectedErrorAfterSmearing(newPt, mu.eta(), newPtErr/newPt) | ||
elif self.smearMode == "none" or self.smearMode == None: | ||
pass | ||
elif self.smearMode == "basic": | ||
newPt = self.kamuca.smear(newPt, mu.eta()) | ||
newPtErr = newPt * self.kamuca.getCorrectedErrorAfterSmearing(newPt, mu.eta(), newPtErr/newPt) | ||
else: | ||
newPt = self.kamuca.smearUsingEbE(newPt, mu.eta(), newPtErr/newPt) | ||
newPtErr = newPt * self.kamuca.getCorrectedErrorAfterSmearing(newPt, mu.eta(), newPtErr/newPt) | ||
newP4 = ROOT.math.PtEtaPhiMLorentzVector(newPt, mu.eta(), mu.phi(), mu.mass()) | ||
mu.setP4(newP4) | ||
mu._ptErr = newPtErr | ||
|
||
def correct_all(self, mus, run): | ||
for mu in mus: | ||
self.correct(mu, run) | ||
|
||
if __name__ == '__main__': | ||
kamuka = KalmanMuonCorrector("MC_76X_13TeV", True) |