Skip to content

Commit

Permalink
Merge pull request cms-sw#16435 from cms-met/MM_METSigAndJERUnc_81X_3…
Browse files Browse the repository at this point in the history
…11016

JER MET uncertainties and METSignifiance re-estimation
  • Loading branch information
davidlange6 authored Nov 17, 2016
2 parents b21b788 + 27b0a91 commit c66e425
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
4 changes: 2 additions & 2 deletions PhysicsTools/PatAlgos/plugins/PATMETSlimmer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ pat::PATMETSlimmer::OneMETShift::OneMETShift(pat::MET::METUncertainty shift_, pa
case pat::MET::NoShift : snprintf(buff, 1023, baseTagStr.c_str(), ""); break;
case pat::MET::JetEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetEnUp"); break;
case pat::MET::JetEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetEnDown"); break;
case pat::MET::JetResUp : snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResUp":""); break;
case pat::MET::JetResDown: snprintf(buff, 1023, baseTagStr.c_str(), isSmeared?"JetResDown":""); break;
case pat::MET::JetResUp : snprintf(buff, 1023, baseTagStr.c_str(), "JetResUp"); break;
case pat::MET::JetResDown: snprintf(buff, 1023, baseTagStr.c_str(), "JetResDown"); break;
case pat::MET::MuonEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnUp"); break;
case pat::MET::MuonEnDown: snprintf(buff, 1023, baseTagStr.c_str(), "MuonEnDown"); break;
case pat::MET::ElectronEnUp : snprintf(buff, 1023, baseTagStr.c_str(), "ElectronEnUp"); break;
Expand Down
17 changes: 14 additions & 3 deletions PhysicsTools/PatUtils/interface/SmearedJetProducerT.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,23 @@ class SmearedJetProducerT : public edm::stream::EDProducer<> {
m_genJetMatcher = std::make_shared<pat::GenJetMatcher>(cfg, consumesCollector());

std::int32_t variation = cfg.getParameter<std::int32_t>("variation");
m_nomVar=1;
if (variation == 0)
m_systematic_variation = Variation::NOMINAL;
else if (variation == 1)
m_systematic_variation = Variation::UP;
else if (variation == -1)
m_systematic_variation = Variation::DOWN;
else if (variation == 101) {
m_systematic_variation = Variation::NOMINAL;
m_nomVar=1;
}
else if (variation == -101) {
m_systematic_variation = Variation::NOMINAL;
m_nomVar=-1;
}
else
throw edm::Exception(edm::errors::ConfigFileReadError, "Invalid value for 'variation' parameter. Only -1, 0 or 1 are supported.");
throw edm::Exception(edm::errors::ConfigFileReadError, "Invalid value for 'variation' parameter. Only -1, 0, 1 or 101, -101 are supported.");
}

produces<JetCollection>();
Expand Down Expand Up @@ -234,7 +243,7 @@ class SmearedJetProducerT : public edm::stream::EDProducer<> {
}

double dPt = jet.pt() - genJet->pt();
smearFactor = 1 + (jer_sf - 1.) * dPt / jet.pt();
smearFactor = 1 + m_nomVar*(jer_sf - 1.) * dPt / jet.pt();

} else if (jer_sf > 1) {
/*
Expand All @@ -247,7 +256,7 @@ class SmearedJetProducerT : public edm::stream::EDProducer<> {
}

std::normal_distribution<> d(0, sigma);
smearFactor = 1. + d(m_random_generator);
smearFactor = 1. + m_nomVar*d(m_random_generator);
} else if (m_debug) {
std::cout << "Impossible to smear this jet" << std::endl;
}
Expand Down Expand Up @@ -298,5 +307,7 @@ class SmearedJetProducerT : public edm::stream::EDProducer<> {
std::mt19937 m_random_generator;

GreaterByPt<T> jetPtComparator;

int m_nomVar;
};
#endif
10 changes: 9 additions & 1 deletion PhysicsTools/PatUtils/plugins/CorrectedPATMETProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "DataFormats/METReco/interface/CorrMETData.h"

#include "JetMETCorrections/Type1MET/interface/AddCorrectionsToGenericMET.h"
#include "RecoMET/METAlgorithms/interface/METSignificance.h"

#include <vector>

Expand Down Expand Up @@ -49,7 +50,6 @@ class CorrectedPATMETProducer : public edm::stream::EDProducer<>

edm::EDGetTokenT<METCollection> token_;


void produce(edm::Event& evt, const edm::EventSetup& es) override
{
edm::Handle<METCollection> srcMETCollection;
Expand All @@ -62,6 +62,14 @@ class CorrectedPATMETProducer : public edm::stream::EDProducer<>
pat::MET outMET(corrMET, srcMET);

auto product = std::make_unique<METCollection>();

reco::METCovMatrix cov=srcMET.getSignificanceMatrix();
if( !(cov(0,0)==0 && cov(0,1)==0 && cov(1,0)==0 && cov(1,1)==0) ) {
outMET.setSignificanceMatrix(cov);
double metSig=metsig::METSignificance::getSignificance(cov, outMET);
outMET.setMETSignificance(metSig);
}

product->push_back(outMET);
evt.put(std::move(product));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,10 @@ def getVariations(self, process, metModName, identifier,preId, objectCollection,
smear=False
if "Smear" in metModName:
smear=True

else:
smear=True
varyByNsigmas=101

shiftedCollModules['Up'] = self.createShiftedJetResModule(process, smear, objectCollection, +1.*varyByNsigmas,
"Up", postfix)
shiftedCollModules['Down'] = self.createShiftedJetResModule(process, smear, objectCollection, -1.*varyByNsigmas,
Expand Down Expand Up @@ -1464,6 +1467,9 @@ def miniAODConfigurationPost(self, process, postfix):
if hasattr(process, "patPFMetTxyCorr"+postfix):
getattr(process, "patPFMetTxyCorr"+postfix).vertexCollection = cms.InputTag("offlineSlimmedPrimaryVertices")

if self._parameters['computeUncertainties'].value:
getattr(process, "shiftedPatJetResDown"+postfix).genJets = cms.InputTag("slimmedGenJets")
getattr(process, "shiftedPatJetResUp"+postfix).genJets = cms.InputTag("slimmedGenJets")


def miniAODConfiguration(self, process, pfCandCollection, jetCollection,
Expand Down
2 changes: 1 addition & 1 deletion RecoMET/METAlgorithms/interface/METSignificance.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace metsig {
JME::JetResolutionScaleFactor & resSFObj,
bool isRealData);

double getSignificance(const reco::METCovMatrix& cov, const reco::MET& met ) const;
static double getSignificance(const reco::METCovMatrix& cov, const reco::MET& met );

private:
bool cleanJet(const reco::Jet& jet,
Expand Down
4 changes: 2 additions & 2 deletions RecoMET/METAlgorithms/src/METSignificance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ metsig::METSignificance::METSignificance(const edm::ParameterSet& iConfig) {
jetEtas_ = cfgParams.getParameter<std::vector<double> >("jeta");
jetParams_ = cfgParams.getParameter<std::vector<double> >("jpar");
pjetParams_ = cfgParams.getParameter<std::vector<double> >("pjpar");

}

metsig::METSignificance::~METSignificance() {
Expand Down Expand Up @@ -172,7 +172,7 @@ metsig::METSignificance::getCovariance(const edm::View<reco::Jet>& jets,
}

double
metsig::METSignificance::getSignificance(const reco::METCovMatrix& cov, const reco::MET& met) const {
metsig::METSignificance::getSignificance(const reco::METCovMatrix& cov, const reco::MET& met) {

// covariance matrix determinant
double det = cov(0,0)*cov(1,1) - cov(0,1)*cov(1,0);
Expand Down

0 comments on commit c66e425

Please sign in to comment.