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
Filtering genVisTaus breaks gen-level matching #118
Comments
Apparently, the same issue applies to gen-level jets as well (e.g. 9th reco jet in event cmssw/PhysicsTools/NanoAOD/python/jets_cff.py Line 310 in fb8502c
|
@ktht this is by design. You can think about it the same as when you check isAvailable for an edm::Ref, the fact that the Ref isNonnull doesn't guarantee that the pointed object is really stored. |
I agree, but clearly the If you still insist on the pT cut in finalGenVisTaus = cms.EDFilter("GenParticleSelector",
src = cms.InputTag("genVisTaus"),
cut = cms.string("pt > 10"),
)
# replace genVisTaus with finalGenVisTaus in subsequent code + update tauMC sequence |
the bug is the GenVisTau should pt sorted then (before they are taken for matching). For GenJet it is the case. |
Ah ok, I agree with this conclusion. The following solution worked for me, but I dunno where to submit the PR: diff --git a/PhysicsTools/HepMCCandAlgos/plugins/GenVisTauProducer.cc b/PhysicsTools/HepMCCandAlgos/plugins/GenVisTauProducer.cc
index 2da65fa1344..469344710d5 100644
--- a/PhysicsTools/HepMCCandAlgos/plugins/GenVisTauProducer.cc
+++ b/PhysicsTools/HepMCCandAlgos/plugins/GenVisTauProducer.cc
@@ -11,6 +11,7 @@
#include "PhysicsTools/JetMCUtils/interface/JetMCTag.h"
#include "DataFormats/TauReco/interface/PFTau.h"
#include "DataFormats/Math/interface/deltaR.h"
+#include "CommonTools/Utils/interface/PtComparator.h"
#include <vector>
#include <iostream>
@@ -21,6 +22,7 @@ class GenVisTauProducer : public edm::global::EDProducer<>
GenVisTauProducer(const edm::ParameterSet& params)
: src_(consumes<reco::GenJetCollection>(params.getParameter<edm::InputTag>("src")))
, srcGenParticles_(consumes<reco::GenParticleCollection>(params.getParameter<edm::InputTag>("srcGenParticles")))
+ , pTComparator_()
{
produces<reco::GenParticleCollection>();
}
@@ -77,6 +79,7 @@ class GenVisTauProducer : public edm::global::EDProducer<>
genVisTaus->push_back(genVisTau);
}
+ std::sort(genVisTaus->begin(), genVisTaus->end(), pTComparator_);
evt.put(std::move(genVisTaus));
}
@@ -91,6 +94,7 @@ class GenVisTauProducer : public edm::global::EDProducer<>
private:
const edm::EDGetTokenT<reco::GenJetCollection> src_;
const edm::EDGetTokenT<reco::GenParticleCollection> srcGenParticles_;
+ const GreaterByPt<reco::GenParticle> pTComparator_;
};
#include "FWCore/Framework/interface/MakerMacros.h" |
please submit here and on master for cmssw |
btw can't we do with some sorter in between, i.e. without modifying the original producer? |
The closest thing I could find is this: cmssw/CommonTools/CandAlgos/plugins/LargestPtCandSelector.cc Lines 22 to 27 in 2aa9689
But it's for reco::Candidate/Collection ; we could write a similar plugin to e.g. PhysicsTools/NanoAOD/plugins/LargestPtGenParticleSelector.cc :
typedef ObjectSelector<
SortCollectionSelector<
reco::GenParticleCollection,
GreaterByPt<reco::GenParticle>
>
> LargestPtGenParticleSelector; The plugin not only sorts by pT, but also filters out first genVisTausPtSorted = cms.EDFilter("LargestPtGenParticleSelector",
src = cms.InputTag("genVisTaus"),
maxNumber = cms.uint32(100),
) It's kind of a hack, imo. |
I prefer the version that modifies the GenVisTauProducer to do the sorting: a lot of other EDProducers do sort their outputs by pT already. I would suggest:
@fabiocos @slava77 @perrotta : do you want the 94X PR also to |
On 3/19/18 8:00 AM, Giovanni Petrucciani wrote:
I prefer the version that modifies the GenVisTauProducer to do the
sorting: a lot of other EDProducers do sort their outputs by pT already.
I would suggest:
* PR to |cms-sw/master| from whatever recent 10_1_X IB.
* PR to |cms-nanoAOD/master| from 94X
@fabiocos <https://github.com/fabiocos> @slava77
<https://github.com/slava77> @perrotta <https://github.com/perrotta> :
do you want the 94X PR also to |cms-sw/CMSSW_9_4_AN_X| since the change
is not in a NanoAOD package? (even if it's a minor change and the module
is used only in nanoAOD production)
If it's not used anywhere else and there's no concern of code quality,
can this go to the mainstream 94X?
|
Dear all,
let me recall that whatever enters 9_4_X is moved also to 9_4_AN_X (if there is no conflict).
Cheers
Fabio
… On 19 Mar 2018, at 16:28, Slava Krutelyov ***@***.***> wrote:
On 3/19/18 8:00 AM, Giovanni Petrucciani wrote:
> I prefer the version that modifies the GenVisTauProducer to do the
> sorting: a lot of other EDProducers do sort their outputs by pT already.
>
> I would suggest:
>
> * PR to |cms-sw/master| from whatever recent 10_1_X IB.
> * PR to |cms-nanoAOD/master| from 94X
>
> @fabiocos <https://github.com/fabiocos> @slava77
> <https://github.com/slava77> @perrotta <https://github.com/perrotta> :
> do you want the 94X PR also to |cms-sw/CMSSW_9_4_AN_X| since the change
> is not in a NanoAOD package? (even if it's a minor change and the module
> is used only in nanoAOD production)
>
If it's not used anywhere else and there's no concern of code quality,
can this go to the mainstream 94X?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#118 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AD3sUjU4pOXjQAkosY-cL2LQo537P0Tkks5tf86YgaJpZM4SoY80>.
|
@ktht can you please make the PRs then to master and 94X main branch (@slava77 concerning code quality is three lines here: #118 (comment)) |
On 3/20/18 1:22 AM, arizzi wrote:
@ktht <https://github.com/ktht> can you please make the PRs then to
master and 94X main branch
***@***.*** <https://github.com/slava77> concerning code quality is three
lines here: #118 (comment)
<#118 (comment)>)
OK, sounds like not an issue regarding quality
|
done in #135 |
GenVisTaus
are filtered before they're written to the Ntuple, but the matching is done w.r.t unfilteredgenVisTau
collection:cmssw/PhysicsTools/NanoAOD/python/taus_cff.py
Lines 84 to 86 in fb8502c
cmssw/PhysicsTools/NanoAOD/python/taus_cff.py
Lines 114 to 116 in fb8502c
cmssw/PhysicsTools/NanoAOD/python/taus_cff.py
Lines 126 to 129 in fb8502c
Example: event
1:5883:9975004
in/store/mc/RunIIFall17MiniAOD/ttHJetToNonbb_M125_TuneCP5_13TeV_amcatnloFXFX_madspin_pythia8/MINIAODSIM/94X_mc2017_realistic_v10-v1/00000/D4FE989C-2619-E811-9F24-002590D9D822.root
Unfiltered collection:
Filtered collection (that is written to the Ntuple):
Reco taus:
In practice, if
genPartFlav
equals to 5 (hadronic tau decay case), then the generator-level match should be found inGenVisTau
collection instead ofGenPart
collection; but in the above examplegenPartIdx
goes out of bounds in theGenVisTau
collection for two reco taus.The easiest fix is to just remove the pT cut on the
genVisTaus
when they're written to the Ntuple:cmssw/PhysicsTools/NanoAOD/python/taus_cff.py
Line 86 in fb8502c
The text was updated successfully, but these errors were encountered: