Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workaround for dz on 92X (requires a 94X IB with cms-sw/cmssw#20367)
- Loading branch information
Showing
5 changed files
with
111 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "FWCore/Framework/interface/global/EDProducer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "FWCore/Utilities/interface/InputTag.h" | ||
#include "DataFormats/Common/interface/View.h" | ||
|
||
#include "DataFormats/PatCandidates/interface/Muon.h" | ||
#include "DataFormats/PatCandidates/interface/Electron.h" | ||
|
||
namespace pat { | ||
|
||
|
||
template<typename T> | ||
class LeptonUpdater : public edm::global::EDProducer<> { | ||
|
||
public: | ||
|
||
explicit LeptonUpdater(const edm::ParameterSet & iConfig) : | ||
src_(consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("src"))), | ||
vertices_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertices"))) | ||
{ | ||
produces<std::vector<T>>(); | ||
} | ||
|
||
~LeptonUpdater() {} | ||
|
||
void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const ; | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("src")->setComment("Lepton collection"); | ||
desc.add<edm::InputTag>("vertices")->setComment("Vertex collection"); | ||
if (typeid(T) == typeid(pat::Muon)) descriptions.add("muonsUpdated", desc); | ||
else if (typeid(T) == typeid(pat::Electron)) descriptions.add("electronsUpdated", desc); | ||
} | ||
|
||
void setDZ(T & lep, const reco::Vertex & pv) const {} | ||
|
||
private: | ||
// configurables | ||
edm::EDGetTokenT<std::vector<T>> src_; | ||
edm::EDGetTokenT<std::vector<reco::Vertex>> vertices_; | ||
}; | ||
|
||
// must do the specialization within the namespace otherwise gcc complains | ||
// | ||
template<> | ||
void LeptonUpdater<pat::Electron>::setDZ(pat::Electron & anElectron, const reco::Vertex & pv) const { | ||
auto track = anElectron.gsfTrack(); | ||
anElectron.setDB( track->dz(pv.position()), std::hypot(track->dzError(), pv.zError()), pat::Electron::PVDZ ); | ||
} | ||
|
||
template<> | ||
void LeptonUpdater<pat::Muon>::setDZ(pat::Muon & aMuon, const reco::Vertex & pv) const { | ||
auto track = aMuon.muonBestTrack(); | ||
aMuon.setDB( track->dz(pv.position()), std::hypot(track->dzError(), pv.zError()), pat::Muon::PVDZ ); | ||
} | ||
|
||
} // namespace | ||
|
||
template<typename T> | ||
void pat::LeptonUpdater<T>::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const { | ||
edm::Handle<std::vector<T>> src; | ||
iEvent.getByToken(src_, src); | ||
|
||
edm::Handle<std::vector<reco::Vertex>> vertices; | ||
iEvent.getByToken(vertices_, vertices); | ||
const reco::Vertex & pv = vertices->front(); | ||
|
||
std::unique_ptr<std::vector<T>> out(new std::vector<T>(*src)); | ||
|
||
for (unsigned int i = 0, n = src->size(); i < n; ++i) { | ||
T & lep = (*out)[i]; | ||
setDZ(lep, pv); | ||
} | ||
|
||
iEvent.put(std::move(out)); | ||
} | ||
|
||
|
||
|
||
typedef pat::LeptonUpdater<pat::Electron> PATElectronUpdater; | ||
typedef pat::LeptonUpdater<pat::Muon> PATMuonUpdater; | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(PATElectronUpdater); | ||
DEFINE_FWK_MODULE(PATMuonUpdater); |
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,16 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
slimmedMuons = cms.EDProducer("PATMuonUpdater", | ||
src = cms.InputTag("slimmedMuons", processName = cms.InputTag.skipCurrentProcess()), | ||
vertices = cms.InputTag("offlineSlimmedPrimaryVertices") | ||
) | ||
slimmedElectrons = cms.EDProducer("PATElectronUpdater", | ||
src = cms.InputTag("slimmedElectrons", processName = cms.InputTag.skipCurrentProcess()), | ||
vertices = cms.InputTag("offlineSlimmedPrimaryVertices") | ||
) | ||
|
||
adapt_nano = cms.Sequence( slimmedMuons + slimmedElectrons ) | ||
|
||
# this part below is not elegant, but probably electronMVAValueMapProducer.srcMiniAOD should not have a 'skipCurrentProcess' by default! | ||
import RecoEgamma.ElectronIdentification.ElectronMVAValueMapProducer_cfi | ||
RecoEgamma.ElectronIdentification.ElectronMVAValueMapProducer_cfi.electronMVAValueMapProducer.srcMiniAOD = cms.InputTag("slimmedElectrons") |
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
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