-
Notifications
You must be signed in to change notification settings - Fork 4.6k
[ReMiniFromMini] Add modules for updating puppi weights in pat::PackedCandidate and rekeying PAT object candidates #48988
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
Closed
nurfikri89
wants to merge
6
commits into
cms-sw:master
from
nurfikri89:from1510pre6_miniFromMiniSetup_v2
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b5d0e83
Add modules to rekey PF candidates of PATObjects and VertexCompositeC…
nurfikri89 026c148
Explicitly use packedPFCandidates created in previous process
nurfikri89 b299d7f
First customization configurations for reMiniFromMini workflow
nurfikri89 70f135a
Specify packedPFCandidates collection for MET recomputation
nurfikri89 574643a
Revert modification in setupPuppiForPackedPF(), set Puppi producers t…
nurfikri89 1ba913b
Apply code-format patches
nurfikri89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
78 changes: 78 additions & 0 deletions
78
PhysicsTools/PatAlgos/plugins/PATElectronCandidatesRekeyer.cc
This file contains hidden or 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,78 @@ | ||
| #include "FWCore/Framework/interface/stream/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/Electron.h" | ||
| #include "DataFormats/PatCandidates/interface/PackedCandidate.h" | ||
|
|
||
| #include "DataFormats/Candidate/interface/CandidateFwd.h" | ||
|
|
||
| namespace pat { | ||
| class PATElectronCandidatesRekeyer : public edm::stream::EDProducer<> { | ||
| public: | ||
| explicit PATElectronCandidatesRekeyer(const edm::ParameterSet &iConfig); | ||
| ~PATElectronCandidatesRekeyer() override; | ||
|
|
||
| void produce(edm::Event &, const edm::EventSetup &) override; | ||
|
|
||
| private: | ||
| // configurables | ||
| edm::EDGetTokenT<std::vector<pat::Electron>> src_; | ||
| edm::EDGetTokenT<reco::CandidateView> pcNewCandViewToken_; | ||
| edm::EDGetTokenT<pat::PackedCandidateCollection> pcNewToken_; | ||
| }; | ||
|
|
||
| } // namespace pat | ||
|
|
||
| using namespace pat; | ||
|
|
||
| PATElectronCandidatesRekeyer::PATElectronCandidatesRekeyer(const edm::ParameterSet &iConfig) | ||
| : | ||
|
|
||
| src_(consumes<std::vector<pat::Electron>>(iConfig.getParameter<edm::InputTag>("src"))), | ||
| pcNewCandViewToken_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("packedPFCandidatesNew"))), | ||
| pcNewToken_( | ||
| consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidatesNew"))) { | ||
| produces<std::vector<pat::Electron>>(); | ||
| } | ||
|
|
||
| PATElectronCandidatesRekeyer::~PATElectronCandidatesRekeyer() {} | ||
|
|
||
| void PATElectronCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup const &) { | ||
| edm::Handle<std::vector<pat::Electron>> src; | ||
| iEvent.getByToken(src_, src); | ||
|
|
||
| edm::Handle<reco::CandidateView> pcNewCandViewHandle; | ||
| iEvent.getByToken(pcNewCandViewToken_, pcNewCandViewHandle); | ||
|
|
||
| edm::Handle<pat::PackedCandidateCollection> pcNewHandle; | ||
| iEvent.getByToken(pcNewToken_, pcNewHandle); | ||
|
|
||
| auto outPtrP = std::make_unique<std::vector<pat::Electron>>(); | ||
| outPtrP->reserve(src->size()); | ||
|
|
||
| for (size_t i = 0; i < src->size(); ++i) { | ||
| // copy original pat object and append to vector | ||
| outPtrP->emplace_back((*src)[i]); | ||
|
|
||
| std::vector<unsigned int> keys; | ||
| for (const edm::Ref<pat::PackedCandidateCollection> &ref : outPtrP->back().associatedPackedPFCandidates()) { | ||
| keys.push_back(ref.key()); | ||
| }; | ||
| outPtrP->back().setAssociatedPackedPFCandidates( | ||
| edm::RefProd<pat::PackedCandidateCollection>(pcNewHandle), keys.begin(), keys.end()); | ||
| if (keys.size() == 1) { | ||
| outPtrP->back().refToOrig_ = outPtrP->back().sourceCandidatePtr(0); | ||
| } else { | ||
| outPtrP->back().refToOrig_ = reco::CandidatePtr(pcNewHandle.id()); | ||
| } | ||
| } | ||
| iEvent.put(std::move(outPtrP)); | ||
| } | ||
|
|
||
| #include "FWCore/Framework/interface/MakerMacros.h" | ||
| DEFINE_FWK_MODULE(PATElectronCandidatesRekeyer); | ||
110 changes: 110 additions & 0 deletions
110
PhysicsTools/PatAlgos/plugins/PATJetCandidatesRekeyer.cc
This file contains hidden or 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,110 @@ | ||
| #include "FWCore/Framework/interface/stream/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/Jet.h" | ||
| #include "DataFormats/PatCandidates/interface/PackedCandidate.h" | ||
|
|
||
| #include "DataFormats/Candidate/interface/CandidateFwd.h" | ||
|
|
||
| namespace pat { | ||
| class PATJetCandidatesRekeyer : public edm::stream::EDProducer<> { | ||
| public: | ||
| explicit PATJetCandidatesRekeyer(const edm::ParameterSet &iConfig); | ||
| ~PATJetCandidatesRekeyer() override; | ||
|
|
||
| void produce(edm::Event &, const edm::EventSetup &) override; | ||
|
|
||
| private: | ||
| // configurables | ||
| edm::EDGetTokenT<std::vector<pat::Jet>> src_; | ||
| edm::EDGetTokenT<reco::CandidateView> pcNewCandViewToken_; | ||
| edm::EDGetTokenT<pat::PackedCandidateCollection> pcNewToken_; | ||
| // std::string subjetLabel_; | ||
| }; | ||
| } // namespace pat | ||
|
|
||
| using namespace pat; | ||
|
|
||
| PATJetCandidatesRekeyer::PATJetCandidatesRekeyer(const edm::ParameterSet &iConfig) | ||
| : src_(consumes<std::vector<pat::Jet>>(iConfig.getParameter<edm::InputTag>("src"))), | ||
| pcNewCandViewToken_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("packedPFCandidatesNew"))), | ||
| pcNewToken_( | ||
| consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidatesNew"))) { | ||
| produces<std::vector<pat::Jet>>(); | ||
| produces<edm::OwnVector<reco::BaseTagInfo>>("tagInfos"); | ||
| } | ||
|
|
||
| PATJetCandidatesRekeyer::~PATJetCandidatesRekeyer() {} | ||
|
|
||
| void PATJetCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup const &) { | ||
| edm::Handle<std::vector<pat::Jet>> src; | ||
| iEvent.getByToken(src_, src); | ||
|
|
||
| edm::Handle<reco::CandidateView> pcNewCandViewHandle; | ||
| iEvent.getByToken(pcNewCandViewToken_, pcNewCandViewHandle); | ||
|
|
||
| edm::Handle<pat::PackedCandidateCollection> pcNewHandle; | ||
| iEvent.getByToken(pcNewToken_, pcNewHandle); | ||
|
|
||
| edm::RefProd<edm::OwnVector<reco::BaseTagInfo>> h_tagInfosOut = | ||
| iEvent.getRefBeforePut<edm::OwnVector<reco::BaseTagInfo>>("tagInfos"); | ||
| auto tagInfosOut = std::make_unique<edm::OwnVector<reco::BaseTagInfo>>(); | ||
|
|
||
| auto outPtrP = std::make_unique<std::vector<pat::Jet>>(); | ||
| outPtrP->reserve(src->size()); | ||
|
|
||
| // | ||
| // | ||
| // | ||
| for (std::vector<pat::Jet>::const_iterator ibegin = (*src).begin(), iend = (*src).end(), ijet = ibegin; ijet != iend; | ||
| ++ijet) { | ||
| for (TagInfoFwdPtrCollection::const_iterator iinfoBegin = ijet->tagInfosFwdPtr().begin(), | ||
| iinfoEnd = ijet->tagInfosFwdPtr().end(), | ||
| iinfo = iinfoBegin; | ||
| iinfo != iinfoEnd; | ||
| ++iinfo) { | ||
| tagInfosOut->push_back(**iinfo); | ||
| } | ||
| } | ||
|
|
||
| edm::OrphanHandle<edm::OwnVector<reco::BaseTagInfo>> oh_tagInfosOut = iEvent.put(std::move(tagInfosOut), "tagInfos"); | ||
|
|
||
| // | ||
| // | ||
| // | ||
| unsigned int tagInfoIndex = 0; | ||
|
|
||
| for (size_t i = 0; i < src->size(); ++i) { | ||
| // copy original pat object and append to vector | ||
| outPtrP->emplace_back((*src)[i]); | ||
|
|
||
| reco::CompositePtrCandidate::daughters old = outPtrP->back().daughterPtrVector(); | ||
| outPtrP->back().clearDaughters(); | ||
| for (const auto &dauItr : old) { | ||
| outPtrP->back().addDaughter(edm::Ptr<reco::Candidate>(pcNewHandle, dauItr.key())); | ||
| } | ||
|
|
||
| // Copy the tag infos | ||
| for (TagInfoFwdPtrCollection::const_iterator iinfoBegin = outPtrP->back().tagInfosFwdPtr().begin(), | ||
| iinfoEnd = outPtrP->back().tagInfosFwdPtr().end(), | ||
| iinfo = iinfoBegin; | ||
| iinfo != iinfoEnd; | ||
| ++iinfo) { | ||
| // Update the "forward" bit of the FwdPtr to point at the new collection. | ||
| // ptr to "this" info in the global list | ||
| edm::Ptr<reco::BaseTagInfo> outPtr(oh_tagInfosOut, tagInfoIndex); | ||
| outPtrP->back().updateFwdTagInfoFwdPtr(iinfo - iinfoBegin, outPtr); | ||
| ++tagInfoIndex; | ||
| } | ||
| } | ||
|
|
||
| iEvent.put(std::move(outPtrP)); | ||
| } | ||
|
|
||
| #include "FWCore/Framework/interface/MakerMacros.h" | ||
| DEFINE_FWK_MODULE(PATJetCandidatesRekeyer); |
This file contains hidden or 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,77 @@ | ||
| #include "FWCore/Framework/interface/stream/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/PackedCandidate.h" | ||
|
|
||
| #include "DataFormats/Candidate/interface/CandidateFwd.h" | ||
|
|
||
| namespace pat { | ||
| class PATMuonCandidatesRekeyer : public edm::stream::EDProducer<> { | ||
| public: | ||
| explicit PATMuonCandidatesRekeyer(const edm::ParameterSet &iConfig); | ||
| ~PATMuonCandidatesRekeyer() override; | ||
|
|
||
| void produce(edm::Event &, const edm::EventSetup &) override; | ||
|
|
||
| private: | ||
| // configurables | ||
| edm::EDGetTokenT<std::vector<pat::Muon>> src_; | ||
| edm::EDGetTokenT<reco::CandidateView> pcNewCandViewToken_; | ||
| edm::EDGetTokenT<pat::PackedCandidateCollection> pcNewToken_; | ||
| }; | ||
|
|
||
| } // namespace pat | ||
|
|
||
| using namespace pat; | ||
|
|
||
| PATMuonCandidatesRekeyer::PATMuonCandidatesRekeyer(const edm::ParameterSet &iConfig) | ||
| : src_(consumes<std::vector<pat::Muon>>(iConfig.getParameter<edm::InputTag>("src"))), | ||
| pcNewCandViewToken_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("packedPFCandidatesNew"))), | ||
| pcNewToken_( | ||
| consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("packedPFCandidatesNew"))) { | ||
| produces<std::vector<pat::Muon>>(); | ||
| } | ||
|
|
||
| PATMuonCandidatesRekeyer::~PATMuonCandidatesRekeyer() {} | ||
|
|
||
| void PATMuonCandidatesRekeyer::produce(edm::Event &iEvent, edm::EventSetup const &) { | ||
| edm::Handle<std::vector<pat::Muon>> src; | ||
| iEvent.getByToken(src_, src); | ||
|
|
||
| edm::Handle<reco::CandidateView> pcNewCandViewHandle; | ||
| iEvent.getByToken(pcNewCandViewToken_, pcNewCandViewHandle); | ||
|
|
||
| edm::Handle<pat::PackedCandidateCollection> pcNewHandle; | ||
| iEvent.getByToken(pcNewToken_, pcNewHandle); | ||
|
|
||
| auto outPtrP = std::make_unique<std::vector<pat::Muon>>(); | ||
| outPtrP->reserve(src->size()); | ||
|
|
||
| for (size_t i = 0; i < src->size(); ++i) { | ||
| // copy original pat object and append to vector | ||
| outPtrP->emplace_back((*src)[i]); | ||
|
|
||
| // | ||
| std::vector<unsigned int> keys; | ||
| for (size_t ic = 0; ic < outPtrP->back().numberOfSourceCandidatePtrs(); ++ic) { | ||
| const reco::CandidatePtr &candPtr = outPtrP->back().sourceCandidatePtr(ic); | ||
| if (candPtr.isNonnull()) { | ||
| keys.push_back(candPtr.key()); | ||
| } | ||
| } | ||
| if (keys.size() == 1) { | ||
| outPtrP->back().refToOrig_ = reco::CandidatePtr(pcNewCandViewHandle, keys[0]); | ||
| } | ||
| } | ||
|
|
||
| iEvent.put(std::move(outPtrP)); | ||
| } | ||
|
|
||
| #include "FWCore/Framework/interface/MakerMacros.h" | ||
| DEFINE_FWK_MODULE(PATMuonCandidatesRekeyer); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there might be a way to template that PATObjectCandidatesRekeyer to the pat::Electron, leaving a rekey method that is specialised in the loop ; food for thoughts for code improvement if there's time to get this in