7 def __init__(self,globalTag,jetFlavour,doResidualJECs,jecPath,upToLevel=3):
8 """Create a corrector object that reads the payloads from the text dumps of a global tag under
9 CMGTools/RootTools/data/jec (see the getJec.py there to make the dumps).
10 It will apply the L1,L2,L3 and possibly the residual corrections to the jets."""
13 self.
L1JetPar = ROOT.JetCorrectorParameters(
"%s/%s_L1FastJet_%s.txt" % (path,globalTag,jetFlavour),
"");
14 self.
L2JetPar = ROOT.JetCorrectorParameters(
"%s/%s_L2Relative_%s.txt" % (path,globalTag,jetFlavour),
"");
15 self.
L3JetPar = ROOT.JetCorrectorParameters(
"%s/%s_L3Absolute_%s.txt" % (path,globalTag,jetFlavour),
"");
16 self.
vPar = ROOT.vector(ROOT.JetCorrectorParameters)()
18 if upToLevel >= 2: self.vPar.push_back(self.
L2JetPar);
19 if upToLevel >= 3: self.vPar.push_back(self.
L3JetPar);
22 self.
ResJetPar = ROOT.JetCorrectorParameters(
"%s/%s_L2L3Residual_%s.txt" % (path,globalTag,jetFlavour))
26 self.
JetUncertainty = ROOT.JetCorrectionUncertainty(
"%s/%s_Uncertainty_%s.txt" % (path,globalTag,jetFlavour));
28 """Applies 'correct' to all the jets, discard the ones that have bad corrections (corrected pt <= 0)"""
31 ok = self.
correct(j,rho,delta,metShift)
32 if not ok: badJets.append(j)
34 print "Warning: %d out of %d jets flagged bad by JEC." % (len(badJets), len(jets))
37 def correct(self,jet,rho,delta=0,metShift=[0,0]):
38 """Corrects a jet energy (optionally shifting it also by delta times the JEC uncertainty)
39 If a two-component list is passes as 'metShift', it will be modified adding to the first and second
40 component the change to the MET along x and y due to the JEC, defined as the negative difference
41 between the new and old jet 4-vectors, for jets with corrected pt > 10."""
42 self.JetCorrector.setJetEta(jet.eta())
43 self.JetCorrector.setJetPt(jet.pt() * jet.rawFactor())
44 self.JetCorrector.setJetA(jet.jetArea())
45 self.JetCorrector.setRho(rho)
46 corr = self.JetCorrector.getCorrection()
47 self.JetUncertainty.setJetEta(jet.eta())
48 self.JetUncertainty.setJetPt(corr * jet.pt() * jet.rawFactor())
50 jet.jetEnergyCorrUncertainty = self.JetUncertainty.getUncertainty(
True)
51 except RuntimeError, r:
52 print "Caught %s when getting uncertainty for jet of pt %.1f, eta %.2f\n" % (r,corr * jet.pt() * jet.rawFactor(),jet.eta())
53 jet.jetEnergyCorrUncertainty = 0.5
54 if jet.component(4).fraction() < 0.9
and jet.pt()*corr*jet.rawFactor() > 10:
55 metShift[0] -= jet.px()*(corr*jet.rawFactor() - 1)*(1-jet.component(3).fraction())
56 metShift[1] -= jet.py()*(corr*jet.rawFactor() - 1)*(1-jet.component(3).fraction())
59 corr *=
max(0, 1+delta*jet.jetEnergyCorrUncertainty)
60 if jet.pt()*jet.rawFactor()*corr > 10:
61 metShift[0] -= jet.px()*jet.rawFactor()*corr*delta*jet.jetEnergyCorrUncertainty
62 metShift[1] -= jet.py()*jet.rawFactor()*corr*delta*jet.jetEnergyCorrUncertainty
66 jet.setP4(jet.p4() * (corr * jet.rawFactor()))
67 jet.setRawFactor(1.0/corr)
71 def __init__(self,globalTag,jetFlavour,doResidualJECs):
72 """Create a corrector object that reads the payloads from the text dumps of a global tag under
73 CMGTools/RootTools/data/jec (see the getJec.py there to make the dumps).
74 It will make the Type1 MET."""
76 path =
"%s/src/CMGTools/RootTools/data/jec" % os.environ[
'CMSSW_BASE'];
77 self.
L1JetPar = ROOT.JetCorrectorParameters(
"%s/%s_L1FastJet_%s.txt" % (path,globalTag,jetFlavour));
78 self.
L2JetPar = ROOT.JetCorrectorParameters(
"%s/%s_L2Relative_%s.txt" % (path,globalTag,jetFlavour));
79 self.
L3JetPar = ROOT.JetCorrectorParameters(
"%s/%s_L3Absolute_%s.txt" % (path,globalTag,jetFlavour));
80 self.
vPar = ROOT.vector(ROOT.JetCorrectorParameters)()
86 self.
ResJetPar = ROOT.JetCorrectorParameters(
"%s/%s_L2L3Residual_%s.txt" % (path,globalTag,jetFlavour))
90 self.
JetUncertainty = ROOT.JetCorrectionUncertainty(
"%s/%s_Uncertainty_%s.txt" % (path,globalTag,jetFlavour));
91 self.
vPar1 = ROOT.vector(ROOT.JetCorrectorParameters)()
97 if j.component(4).fraction() > 0.9:
continue
102 if mu.sourcePtr().track().isNonnull()
and (mu.sourcePtr().isGlobalMuon()
or mu.sourcePtr().isStandAloneMuon())
and deltaR(mu.eta(),mu.phi(),j.eta(),j.phi()) < 0.5:
105 self.JetCorrector.setJetEta(j.eta())
106 self.JetCorrector.setJetPt(j.pt()*j.rawFactor())
107 self.JetCorrector.setJetA(j.jetArea())
108 self.JetCorrector.setRho(rho)
109 corr3 = self.JetCorrector.getCorrection()
110 self.JetCorrectorL1.setJetEta(j.eta())
111 self.JetCorrectorL1.setJetPt(j.pt()*j.rawFactor())
112 self.JetCorrectorL1.setJetA(j.jetArea())
113 self.JetCorrectorL1.setRho(rho)
114 corr1 = self.JetCorrectorL1.getCorrection()
115 if jp4.pt() * corr3 < 10:
119 px0 -= jp4.X()*(corr3-corr1)
120 py0 -= jp4.Y()*(corr3-corr1)
double deltaR(double eta1, double eta2, double phi1, double phi2)