-
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
Changes from 7 commits
817cac6
9dc5dd5
b44e5ae
f653ffc
2e58c5b
9bb7e36
973ce46
7797075
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -317,10 +317,50 @@ def nanoAOD_addDeepInfoAK8(process, addDeepBTag, addDeepBoostedJet, addDeepDoubl | |||||
| fatJetTable.variables.pt.precision=10 | ||||||
| subJetTable.variables.pt.precision=10 | ||||||
|
|
||||||
| ############################################################## | ||||||
| # AK8 constituents | ||||||
| ############################################################### | ||||||
| finalJetsAK8PFConstituents = cms.EDProducer("PatJetConstituentPtrSelector", | ||||||
| src = cms.InputTag("finalJetsAK8"), | ||||||
| cut = cms.string("abs(eta) <= 2.5") | ||||||
| ) | ||||||
|
|
||||||
| finalJetsPFConstituents = cms.EDProducer("PackedCandidatePtrMerger", | ||||||
| src = cms.VInputTag(cms.InputTag("finalJetsAK8PFConstituents", "constituents")), | ||||||
| skipNulls = cms.bool(True), | ||||||
| warnOnSkip = cms.bool(True) | ||||||
| ) | ||||||
|
|
||||||
| pfCandidatesTable = cms.EDProducer("SimplePATCandidateFlatTableProducer", | ||||||
| src = cms.InputTag("finalJetsPFConstituents"), | ||||||
| cut = cms.string(""), | ||||||
| name = cms.string("PFCand"), | ||||||
| doc = cms.string("PF candidate constituents of AK8 puppi jets (FatJet) with |eta| <= 2.5."), | ||||||
| singleton = cms.bool(False), | ||||||
| extension = cms.bool(False), | ||||||
| variables = cms.PSet( | ||||||
| pt = Var("pt * puppiWeight()", float, doc="Puppi-weighted pt", precision=10), | ||||||
| mass = Var("mass * puppiWeight()", float, doc="Puppi-weighted mass", precision=10), | ||||||
| eta = Var("eta", float, precision=12), | ||||||
| phi = Var("phi", float, precision=12), | ||||||
| pdgId = Var("pdgId", int, doc="PF candidate type (+/-211 = ChgHad, 130 = NeuHad, 22 = Photon, +/-11 = Electron, +/-13 = Muon, 1 = HFHad, 2 = HFEM)") | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
| finalJetsAK8ConstituentsTable = cms.EDProducer("SimplePatJetConstituentTableProducer", | ||||||
| name = cms.string(fatJetTable.name.value()+"PFCand"), | ||||||
| candIdxName = cms.string("PFCandIdx"), | ||||||
| candIdxDoc = cms.string("Index in the PFCand table"), | ||||||
| jets = fatJetTable.src, | ||||||
| candidates = pfCandidatesTable.src, | ||||||
| jetCut = cms.string("") | ||||||
|
||||||
| jetCut = cms.string("") | |
| jetCut = fatJetTable.cut |
to ensure consistency? It does not matter now as both finalJetsAK8 and fatJetTable apply pt > 170, but just to be on the safe side.
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.
I will correct this also.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,17 @@ | |
| Plot1D('tau4', 'tau4', 20, 0, 1, 'Nsubjettiness (4 axis)'), | ||
| ) | ||
| ), | ||
| PFCand = cms.PSet( | ||
| sels = cms.PSet(), | ||
| plots = cms.VPSet( | ||
| Count1D('_size', 10, 0, 100, 'PF candidates'), | ||
| Plot1D('pt', 'pt', 20, 0, 50, 'Puppi-weighted pt'), | ||
| Plot1D('eta', 'eta', 20, -4, 4., 'eta'), | ||
| Plot1D('phi', 'phi', 20, -3.14159, 3.14159, 'phi'), | ||
| Plot1D('mass', 'mass', 10, 0, 1., 'Puppi-weighted mass'), | ||
| Plot1D('pdgId', 'pdgId', 44, -220, 220, 'PF candidate type (+/-211 = ChgHad, 130 = NeuHad, 22 = Photon, +/-11 = Electron, +/-13 = Muon, 1 = HFHad, 2 = HFEM)'), | ||
| ) | ||
| ), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nurfikri89 Would it make sense to add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| Flag = cms.PSet( | ||
| sels = cms.PSet(), | ||
| plots = cms.VPSet( | ||
|
|
||
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.
Would it be better to use the following to ensure consistency?
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.
For
src, you are right. I will correct it but forcut, we explicitly set"abs(eta) <= 2.5"to only store the PF candidates for AK8 jets within that eta range.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.
Why explicitly requiring
abs(eta) <= 2.5? IIRC in MiniAOD it's alreadyrapidity<2.4, so it's largely similar but there could be some edge cases?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 is a selection on the jets which we retrieve the their constituents to run soft-drop grooming:
cmssw/PhysicsTools/PatAlgos/python/slimming/applySubstructure_cff.py
Lines 36 to 37 in 6f9d2fd
and then a
pt > 100selection to store slimmedJetsAK8:cmssw/PhysicsTools/PatAlgos/python/slimming/applySubstructure_cff.py
Line 131 in 6f9d2fd
so we can still have AK8 jets in the forward region as I cannot find any explicit eta cut for AK8 puppi jets in CMSSW.
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.
OK I see -- then please keep this
abs(eta) <= 2.5cut.Thanks a lot for the clarification, @nurfikri89 !