-
Notifications
You must be signed in to change notification settings - Fork 4.6k
[NanoAOD] Add PF constituents for AK8 jets #46012
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
Merged
cmsbuild
merged 8 commits into
cms-sw:master
from
nurfikri89:from1420pre1_nano_addAK8Cands
Sep 21, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
817cac6
Add PATPackedCandidateSelector
nurfikri89 9dc5dd5
Add PF candidates table for FatJet with abs(eta) <= 2.5
nurfikri89 b44e5ae
small update for PFCand pdgId
nurfikri89 f653ffc
Add PFCand in nanoDQM
nurfikri89 2e58c5b
Add SimpleJetConstituentTableProducer
nurfikri89 9bb7e36
Apple code-format patches
nurfikri89 973ce46
Fix typo
nurfikri89 7797075
Update for src consistency
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
136 changes: 136 additions & 0 deletions
136
PhysicsTools/NanoAOD/plugins/SimpleJetConstituentTableProducer.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,136 @@ | ||
| #include "FWCore/Framework/interface/Frameworkfwd.h" | ||
| #include "FWCore/Framework/interface/stream/EDProducer.h" | ||
|
|
||
| #include "FWCore/Framework/interface/Event.h" | ||
| #include "FWCore/Framework/interface/MakerMacros.h" | ||
|
|
||
| #include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
| #include "FWCore/Utilities/interface/StreamID.h" | ||
|
|
||
| #include "DataFormats/PatCandidates/interface/Jet.h" | ||
| #include "DataFormats/PatCandidates/interface/PackedCandidate.h" | ||
| #include "DataFormats/PatCandidates/interface/PackedGenParticle.h" | ||
|
|
||
| #include "DataFormats/Candidate/interface/CandidateFwd.h" | ||
|
|
||
| #include "CommonTools/Utils/interface/StringCutObjectSelector.h" | ||
| #include "DataFormats/NanoAOD/interface/FlatTable.h" | ||
|
|
||
| template <typename T> | ||
| class SimpleJetConstituentTableProducer : public edm::stream::EDProducer<> { | ||
| public: | ||
| explicit SimpleJetConstituentTableProducer(const edm::ParameterSet &); | ||
| ~SimpleJetConstituentTableProducer() override; | ||
|
|
||
| static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); | ||
|
|
||
| private: | ||
| void produce(edm::Event &, const edm::EventSetup &) override; | ||
|
|
||
| const std::string name_; | ||
| const std::string candIdxName_; | ||
| const std::string candIdxDoc_; | ||
|
|
||
| edm::EDGetTokenT<edm::View<T>> jet_token_; | ||
| edm::EDGetTokenT<reco::CandidateView> cand_token_; | ||
|
|
||
| const StringCutObjectSelector<T> jetCut_; | ||
|
|
||
| edm::Handle<reco::CandidateView> cands_; | ||
| }; | ||
|
|
||
| // | ||
| // constructors and destructor | ||
| // | ||
| template <typename T> | ||
| SimpleJetConstituentTableProducer<T>::SimpleJetConstituentTableProducer(const edm::ParameterSet &iConfig) | ||
| : name_(iConfig.getParameter<std::string>("name")), | ||
| candIdxName_(iConfig.getParameter<std::string>("candIdxName")), | ||
| candIdxDoc_(iConfig.getParameter<std::string>("candIdxDoc")), | ||
| jet_token_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("jets"))), | ||
| cand_token_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("candidates"))), | ||
| jetCut_(iConfig.getParameter<std::string>("jetCut")) { | ||
| produces<nanoaod::FlatTable>(name_); | ||
| produces<std::vector<reco::CandidatePtr>>(); | ||
| } | ||
|
|
||
| template <typename T> | ||
| SimpleJetConstituentTableProducer<T>::~SimpleJetConstituentTableProducer() {} | ||
|
|
||
| template <typename T> | ||
| void SimpleJetConstituentTableProducer<T>::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { | ||
| // elements in all these collections must have the same order! | ||
| auto outCands = std::make_unique<std::vector<reco::CandidatePtr>>(); | ||
|
|
||
| auto jets = iEvent.getHandle(jet_token_); | ||
|
|
||
| iEvent.getByToken(cand_token_, cands_); | ||
| auto candPtrs = cands_->ptrs(); | ||
|
|
||
| // | ||
| // First, select jets | ||
| // | ||
| std::vector<T> jetsPassCut; | ||
| for (unsigned jetIdx = 0; jetIdx < jets->size(); ++jetIdx) { | ||
| const auto &jet = jets->at(jetIdx); | ||
| if (!jetCut_(jet)) | ||
| continue; | ||
| jetsPassCut.push_back(jets->at(jetIdx)); | ||
| } | ||
|
|
||
| // | ||
| // Then loop over selected jets | ||
| // | ||
| std::vector<int> parentJetIdx; | ||
| std::vector<int> candIdx; | ||
| for (unsigned jetIdx = 0; jetIdx < jetsPassCut.size(); ++jetIdx) { | ||
| const auto &jet = jetsPassCut.at(jetIdx); | ||
|
|
||
| // | ||
| // Loop over jet constituents | ||
| // | ||
| std::vector<reco::CandidatePtr> const &daughters = jet.daughterPtrVector(); | ||
| for (const auto &cand : daughters) { | ||
| auto candInNewList = std::find(candPtrs.begin(), candPtrs.end(), cand); | ||
| if (candInNewList == candPtrs.end()) { | ||
| continue; | ||
| } | ||
| outCands->push_back(cand); | ||
| parentJetIdx.push_back(jetIdx); | ||
| candIdx.push_back(candInNewList - candPtrs.begin()); | ||
| } | ||
| } // end jet loop | ||
|
|
||
| auto candTable = std::make_unique<nanoaod::FlatTable>(outCands->size(), name_, false); | ||
| // We fill from here only stuff that cannot be created with the SimpleFlatTableProducer | ||
| candTable->addColumn<int>(candIdxName_, candIdx, candIdxDoc_); | ||
|
|
||
| std::string parentJetIdxName("jetIdx"); | ||
| std::string parentJetIdxDoc("Index of the parent jet"); | ||
| if constexpr (std::is_same<T, reco::GenJet>::value) { | ||
| parentJetIdxName = "genJetIdx"; | ||
| parentJetIdxDoc = "Index of the parent gen jet"; | ||
| } | ||
| candTable->addColumn<int>(parentJetIdxName, parentJetIdx, parentJetIdxDoc); | ||
|
|
||
| iEvent.put(std::move(candTable), name_); | ||
| iEvent.put(std::move(outCands)); | ||
| } | ||
|
|
||
| template <typename T> | ||
| void SimpleJetConstituentTableProducer<T>::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { | ||
| edm::ParameterSetDescription desc; | ||
| desc.add<std::string>("name", "FatJetPFCand"); | ||
| desc.add<std::string>("candIdxName", "PFCandIdx"); | ||
| desc.add<std::string>("candIdxDoc", "Index in PFCand table"); | ||
| desc.add<edm::InputTag>("jets", edm::InputTag("finalJetsAK8")); | ||
| desc.add<edm::InputTag>("candidates", edm::InputTag("packedPFCandidates")); | ||
| desc.add<std::string>("jetCut", ""); | ||
| descriptions.addWithDefaultLabel(desc); | ||
| } | ||
|
|
||
| typedef SimpleJetConstituentTableProducer<pat::Jet> SimplePatJetConstituentTableProducer; | ||
| typedef SimpleJetConstituentTableProducer<reco::GenJet> SimpleGenJetConstituentTableProducer; | ||
|
|
||
| DEFINE_FWK_MODULE(SimplePatJetConstituentTableProducer); | ||
| DEFINE_FWK_MODULE(SimpleGenJetConstituentTableProducer); |
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
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.
@nurfikri89 Would it make sense to add
FatJetPFCand_PFCandIdxandFatJetPFCand_jetIdxto DQM as well?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.
Looking at the indices that we store for other objects, we do not make DQM plots for them. I do not see a reason to do anything differently here.