Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to MVA MET: Fullfills "consumes" call requirement, Bugfix for the calculation of the covariance matrix, updated path to weight files #13086

Merged
merged 6 commits into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ PFMETProducerMVA::PFMETProducerMVA(const edm::ParameterSet& cfg)
for(vInputTag::const_iterator it=srcLeptonsTags.begin();it!=srcLeptonsTags.end();it++) {
srcLeptons_.push_back( consumes<reco::CandidateView >( *it ) );
}

mJetCorrector_ = consumes<reco::JetCorrector>(cfg.getParameter<edm::InputTag>("corrector"));
minNumLeptons_ = cfg.getParameter<int>("minNumLeptons");
srcRho_ = consumes<edm::Handle<double> >(cfg.getParameter<edm::InputTag>("srcRho"));

globalThreshold_ = cfg.getParameter<double>("globalThreshold");

minCorrJetPt_ = cfg.getParameter<double> ("minCorrJetPt");
useType1_ = cfg.getParameter<bool> ("useType1");
correctorLabel_ = cfg.getParameter<std::string>("corrector");

verbosity_ = ( cfg.exists("verbosity") ) ?
cfg.getParameter<int>("verbosity") : 0;
Expand Down Expand Up @@ -73,8 +71,11 @@ void PFMETProducerMVA::produce(edm::Event& evt, const edm::EventSetup& es)
edm::Handle<reco::PFJetCollection> uncorrJets;
evt.getByToken(srcUncorrJets_, uncorrJets);

const JetCorrector* corrector = nullptr;
if( useType1_ ) corrector = JetCorrector::getJetCorrector(correctorLabel_, es);
edm::Handle<reco::JetCorrector> corrector;
if( useType1_ )
{
evt.getByToken(mJetCorrector_, corrector);
}

edm::Handle<reco::CandidateView> pfCandidates_view;
evt.getByToken(srcPFCandidatesView_, pfCandidates_view);
Expand Down Expand Up @@ -192,10 +193,9 @@ PFMETProducerMVA::computeJetInfo(const reco::PFJetCollection& uncorrJets,
const edm::ValueMap<float>& jetIds,
const reco::VertexCollection& vertices,
const reco::Vertex* hardScatterVertex,
const JetCorrector &iCorrector,edm::Event &iEvent,const edm::EventSetup &iSetup,
const reco::JetCorrector &iCorrector,edm::Event &iEvent,const edm::EventSetup &iSetup,
std::vector<reco::PUSubMETCandInfo> &iLeptons,std::vector<reco::PUSubMETCandInfo> &iCands)
{
const L1FastjetCorrector* lCorrector = dynamic_cast<const L1FastjetCorrector*>(&iCorrector);
std::vector<reco::PUSubMETCandInfo> retVal;
for ( reco::PFJetCollection::const_iterator uncorrJet = uncorrJets.begin();
uncorrJet != uncorrJets.end(); ++uncorrJet ) {
Expand All @@ -221,7 +221,7 @@ PFMETProducerMVA::computeJetInfo(const reco::PFJetCollection& uncorrJets,
jetInfo.setP4( corrJet->p4() );
double lType1Corr = 0;
if(useType1_) { //Compute the type 1 correction ===> This code is crap
double pCorr = lCorrector->correction(*uncorrJet,iEvent,iSetup);
double pCorr = iCorrector.correction(*uncorrJet);
lType1Corr = std::abs(corrJet->pt()-pCorr*uncorrJet->pt());
TLorentzVector pVec; pVec.SetPtEtaPhiM(lType1Corr,0,corrJet->phi(),0);
reco::Candidate::LorentzVector pType1Corr; pType1Corr.SetCoordinates(pVec.Px(),pVec.Py(),pVec.Pz(),pVec.E());
Expand Down
28 changes: 4 additions & 24 deletions RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,31 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/Exception.h"


#include "DataFormats/Candidate/interface/Candidate.h"
#include "DataFormats/Candidate/interface/CandidateFwd.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
#include "DataFormats/JetReco/interface/PFJet.h"
#include "DataFormats/JetReco/interface/PFJetCollection.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/Math/interface/LorentzVector.h"
#include "DataFormats/METReco/interface/CommonMETData.h"
#include "DataFormats/METReco/interface/PFMET.h"
#include "DataFormats/METReco/interface/PFMETCollection.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
#include "DataFormats/PatCandidates/interface/Tau.h"
#include "DataFormats/TauReco/interface/PFTau.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"

#include "JetMETCorrections/Algorithms/interface/L1FastjetCorrector.h"
#include "JetMETCorrections/Objects/interface/JetCorrector.h"
#include "JetMETCorrections/JetCorrector/interface/JetCorrector.h"

#include "RecoMET/METAlgorithms/interface/METAlgo.h"
#include "RecoMET/METAlgorithms/interface/PFSpecificAlgo.h"
#include "RecoMET/METPUSubtraction/interface/PFMETAlgorithmMVA.h"
#include "RecoMET/METPUSubtraction/interface/MvaMEtUtilities.h"

#include "RecoJets/JetProducers/interface/PileupJetIdAlgo.h"

#include <algorithm>
#include <vector>

#include "TLorentzVector.h"
#include <TLorentzVector.h>

namespace reco
{
Expand All @@ -80,7 +61,7 @@ namespace reco

std::vector<reco::PUSubMETCandInfo> computeJetInfo(const reco::PFJetCollection&, const edm::Handle<reco::PFJetCollection>&,
const edm::ValueMap<float>&, const reco::VertexCollection&,
const reco::Vertex*, const JetCorrector &iCorr,
const reco::Vertex*, const reco::JetCorrector &iCorr,
edm::Event & iEvent,const edm::EventSetup &iSetup,
std::vector<reco::PUSubMETCandInfo> &iLeptons,
std::vector<reco::PUSubMETCandInfo> &iCands);
Expand All @@ -100,12 +81,11 @@ namespace reco
//edm::EDGetTokenT<reco::PFCandidateCollection> srcPFCandidates_;
edm::EDGetTokenT<edm::View<reco::Candidate> > srcPFCandidatesView_;
edm::EDGetTokenT<reco::VertexCollection> srcVertices_;
edm::EDGetTokenT<reco::JetCorrector> mJetCorrector_;
typedef std::vector<edm::InputTag> vInputTag;
std::vector<edm::EDGetTokenT<reco::CandidateView > > srcLeptons_;
int minNumLeptons_; // CV: option to skip MVA MET computation in case there are less than specified number of leptons in the event
edm::EDGetTokenT<edm::Handle<double> > srcRho_;

std::string correctorLabel_;
bool useType1_;

double globalThreshold_;
Expand Down
21 changes: 9 additions & 12 deletions RecoMET/METPUSubtraction/python/mvaPFMET_cff.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import FWCore.ParameterSet.Config as cms

#from RecoMET.METProducers.PFMET_cfi import pfMet
from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import *
from JetMETCorrections.Configuration.DefaultJEC_cff import *
from JetMETCorrections.Configuration.JetCorrectors_cff import *
##from RecoMET.METPUSubtraction.mvaPFMET_leptons_cfi import *
## CV: importing mvaPFMET_leptons_cfi breaks produceAndDiscriminateHPSPFTaus sequence
## (hpsPFTauDiscriminationByDecayModeFinding module gets overwritten by None,
## in case RecoTauTag/Configuration/python/RecoPFTauTag_cff.py is loaded by
## by top-level cfg.py file before RecoMET/METPUSubtraction/python/mvaPFMET_cff.py gets loaded)
##from RecoJets.JetProducers.PileupJetIDCutParams_cfi import full_53x_wp

calibratedAK4PFJetsForPFMVAMEt = cms.EDProducer('PFJetCorrectionProducer',
calibratedAK4PFJetsForPFMVAMEt = cms.EDProducer('CorrectedPFJetProducer',
src = cms.InputTag('ak4PFJets'),
correctors = cms.vstring("ak4PFL1FastL2L3") # NOTE: use "ak5PFL1FastL2L3" for MC / "ak5PFL1FastL2L3Residual" for Data
correctors = cms.VInputTag("ak4PFL1FastL2L3Corrector") # NOTE: use "ak5PFL1FastL2L3" for MC / "ak5PFL1FastL2L3Residual" for Data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the comment should be updated. What are the correct tags for MC and data?

)

from JetMETCorrections.Configuration.JetCorrectionServices_cff import ak4PFL1Fastjet
from RecoJets.JetProducers.PileupJetID_cfi import pileupJetIdEvaluator
from RecoJets.JetProducers.PileupJetIDParams_cfi import JetIdParams
puJetIdForPFMVAMEt = pileupJetIdEvaluator.clone(
Expand Down Expand Up @@ -69,15 +68,13 @@
srcLeptons = cms.VInputTag(),#"isomuons","isoelectrons","isotaus") # NOTE: you need to set this to collections of electrons, muons and tau-jets
# passing the lepton reconstruction & identification criteria applied in your analysis
minNumLeptons = cms.int32(0),
srcRho = cms.InputTag('fixedGridRhoFastjetAll'),
globalThreshold = cms.double(-1.),#pfMet.globalThreshold,
minCorrJetPt = cms.double(-1.),
inputFileNames = cms.PSet(
U = cms.FileInPath('RecoMET/METPUSubtraction/data/gbrmet_7_2_X_MINIAOD_BX25PU20_Mar2015.root'),
DPhi = cms.FileInPath('RecoMET/METPUSubtraction/data/gbrphi_7_2_X_MINIAOD_BX25PU20_Mar2015.root'),
CovU1 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru1cov_7_2_X_MINIAOD_BX25PU20_Mar2015.root'),
CovU2 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru2cov_7_2_X_MINIAOD_BX25PU20_Mar2015.root')
),
U = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru_7_4_X_miniAOD_25NS_July2015.root'),
DPhi = cms.FileInPath('RecoMET/METPUSubtraction/data/gbrphi_7_4_X_miniAOD_25NS_July2015.root'),
CovU1 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru1cov_7_4_X_miniAOD_25NS_July2015.root'),
CovU2 = cms.FileInPath('RecoMET/METPUSubtraction/data/gbru2cov_7_4_X_miniAOD_25NS_July2015.root') ),
inputRecords = cms.PSet(
U = cms.string("RecoilCor"),
DPhi = cms.string("PhiCor"),
Expand All @@ -86,7 +83,7 @@
),
loadMVAfromDB = cms.bool(False),

corrector = cms.string("ak4PFL1Fastjet"),
corrector = cms.InputTag("ak4PFL1FastjetCorrector"),
useType1 = cms.bool(True),
dZcut = cms.double(0.1),

Expand Down
4 changes: 2 additions & 2 deletions RecoMET/METPUSubtraction/src/PFMETAlgorithmMVA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ void PFMETAlgorithmMVA::evaluateMVA()
mvaOutputU_ = GetResponse(mvaReaderU_, varForU_);
var_["RecoilCor_U"] = var_["particleFlow_U"] * mvaOutputU_;
var_["RecoilCor_UPhi"] = var_["PhiCor_UPhi"];
mvaOutputCovU1_ = GetResponse(mvaReaderCovU1_, varForCovU1_)* mvaOutputU_ * var_["particleFlow_U"];
mvaOutputCovU2_ = GetResponse(mvaReaderCovU2_, varForCovU2_)* mvaOutputU_ * var_["particleFlow_U"];
mvaOutputCovU1_ = std::pow(GetResponse(mvaReaderCovU1_, varForCovU1_)* mvaOutputU_ * var_["particleFlow_U"], 2);
mvaOutputCovU2_ = std::pow(GetResponse(mvaReaderCovU2_, varForCovU2_)* mvaOutputU_ * var_["particleFlow_U"], 2);


// compute MET(Photon check)
Expand Down
2 changes: 1 addition & 1 deletion RecoMET/METPUSubtraction/test/mvaMETOnMiniAOD_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Input source
process.source = cms.Source("PoolSource",
secondaryFileNames = cms.untracked.vstring(),
fileNames = cms.untracked.vstring('root://eoscms//eos/cms/store/relval/CMSSW_7_5_0_pre4/RelValZMM_13/MINIAODSIM/PU50ns_MCRUN2_75_V0-v1/00000/66CB72C0-70F8-E411-81DC-002590596468.root'),
fileNames = cms.untracked.vstring('/store/mc/RunIIFall15MiniAODv2/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/PU25nsData2015v1_76X_mcRun2_asymptotic_v12-v1/70000/DC327D28-D3B8-E511-9FB7-008CFA0A59C0.root '),
skipEvents = cms.untracked.uint32(0)
)

Expand Down