Skip to content
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

GenJetFlavourInfos in MiniAOD and Change in JetFlavour of LightJets to physicsPartons in CMSSW 92X #19048

Merged
merged 22 commits into from Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ca2abcf
GenJetFlavourInfoPreserver: Tool to transfer the JetFlavourInfos of t…
Andrej-CMS May 31, 2017
649dfa8
Changes made in order to write the slimmedGenJetsFlavourInfos into Mi…
Andrej-CMS May 31, 2017
0f4b578
If no heavy flavour hadron is associated with the gen-jet, the maxPt …
Andrej-CMS May 31, 2017
9a6d45d
physicsPartons now contain the full shower. As proposed by the QGL group
Andrej-CMS May 31, 2017
ea57cff
Cleaned up code
Andrej-CMS May 31, 2017
eeeaebd
option fullChainPhysPartons added. If set to True, the physicsPartons…
Andrej-CMS Jun 8, 2017
632b72e
cloning GenJetFlavourInfos from JetFlavourInfos
Andrej-CMS Jun 8, 2017
bdb574e
cleaning up code and renaming variables according to convention
Andrej-CMS Jun 8, 2017
3ee6d5c
Clones JetFlavourInfos
Andrej-CMS Jun 8, 2017
5355844
added ak4GenJetFlavourInfos and selectedHadronsAndPartons to MC task
Andrej-CMS Jun 8, 2017
f3768ff
added empty line at the end of file
Andrej-CMS Jun 19, 2017
f37b635
Moved variable to initializers
Andrej-CMS Jun 19, 2017
73ee068
improved readability and merged for loops
Andrej-CMS Jun 19, 2017
c783efc
New JetFlavour definition, adding also genJetFlavour
Andrej-CMS Jun 19, 2017
eecae16
added slimmedGenJetFlavourInfos to the event dropping things calculat…
Andrej-CMS Jul 19, 2017
1ea8433
PatGenJetSlimmer creates association of genJets to slimmedGenJets. Ge…
Andrej-CMS Jul 19, 2017
9a80eee
removed unnecessary lines
Andrej-CMS Aug 1, 2017
7d7b57f
moved definition of slimmedGenJetsFlavourInfos to its own cfi
Andrej-CMS Aug 1, 2017
9c0baa9
added genJetAssociation between genJets and slimmedGenJets
Andrej-CMS Aug 1, 2017
7914385
changed loop over genJets to be less verbose
Andrej-CMS Aug 8, 2017
c5ed70c
using algorithmicPartons for JetFLavour definition
Andrej-CMS Aug 11, 2017
19314ca
using algorithmicPartons for jetflavour definition
Andrej-CMS Aug 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions DQMOffline/RecoB/python/dqmAnalyzer_cff.py
Expand Up @@ -14,6 +14,7 @@
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
myak4JetFlavourInfos = ak4JetFlavourInfos.clone(
jets = cms.InputTag("ak4PFJetsCHS"),
partons = cms.InputTag("selectedHadronsAndPartons","algorithmicPartons"),
hadronFlavourHasPriority = cms.bool(True)
)

Expand Down
9 changes: 7 additions & 2 deletions PhysicsTools/JetMCAlgos/plugins/HadronAndPartonSelector.cc
Expand Up @@ -91,6 +91,7 @@ class HadronAndPartonSelector : public edm::stream::EDProducer<> {
const edm::EDGetTokenT<reco::GenParticleCollection> particlesToken_; // Input GenParticle collection

std::string partonMode_; // Parton selection mode
bool fullChainPhysPartons_;
bool partonSelectorSet_;
PartonSelectorPtr partonSelector_;
};
Expand All @@ -106,7 +107,8 @@ HadronAndPartonSelector::HadronAndPartonSelector(const edm::ParameterSet& iConfi

srcToken_(mayConsume<GenEventInfoProduct>( iConfig.getParameter<edm::InputTag>("src") )),
particlesToken_(consumes<reco::GenParticleCollection>( iConfig.getParameter<edm::InputTag>("particles") )),
partonMode_(iConfig.getParameter<std::string>("partonMode"))
partonMode_(iConfig.getParameter<std::string>("partonMode")),
fullChainPhysPartons_(iConfig.getParameter<bool>("fullChainPhysPartons"))

{
//register your products
Expand Down Expand Up @@ -254,7 +256,10 @@ HadronAndPartonSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSet
partonSelector_->run(particles,partons);
for(reco::GenParticleCollection::const_iterator it = particles->begin(); it != particles->end(); ++it)
{
if( !(it->status()==3 || (( partonMode_=="Pythia8" ) && (it->status()==23)))) continue;
if(!fullChainPhysPartons_)
{
if( !(it->status()==3 || (( partonMode_=="Pythia8" ) && (it->status()==23)))) continue;
}
if( !CandMCTagUtils::isParton( *it ) ) continue; // skip particle if not a parton
physicsPartons->push_back( reco::GenParticleRef( particles, it - particles->begin() ) );
}
Expand Down
5 changes: 5 additions & 0 deletions PhysicsTools/JetMCAlgos/python/AK4GenJetFlavourInfos_cfi.py
@@ -0,0 +1,5 @@
import FWCore.ParameterSet.Config as cms
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos

ak4GenJetFlavourInfos = ak4JetFlavourInfos.clone(jets = "ak4GenJetsNoNu")

Expand Up @@ -4,10 +4,11 @@
jets = cms.InputTag("ak4PFJets"),
bHadrons = cms.InputTag("selectedHadronsAndPartons","bHadrons"),
cHadrons = cms.InputTag("selectedHadronsAndPartons","cHadrons"),
partons = cms.InputTag("selectedHadronsAndPartons","algorithmicPartons"),
partons = cms.InputTag("selectedHadronsAndPartons","physicsPartons"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the same be applied to other available instances of JetFlavourClustering in this package?
There is one in AK5

leptons = cms.InputTag("selectedHadronsAndPartons","leptons"),
jetAlgorithm = cms.string("AntiKt"),
rParam = cms.double(0.4),
ghostRescaling = cms.double(1e-18),
hadronFlavourHasPriority = cms.bool(False)
)

Expand Up @@ -4,7 +4,7 @@
jets = cms.InputTag("ak5PFJets"),
bHadrons = cms.InputTag("selectedHadronsAndPartons","bHadrons"),
cHadrons = cms.InputTag("selectedHadronsAndPartons","cHadrons"),
partons = cms.InputTag("selectedHadronsAndPartons","algorithmicPartons"),
partons = cms.InputTag("selectedHadronsAndPartons","physicsPartons"),
leptons = cms.InputTag("selectedHadronsAndPartons","leptons"),
jetAlgorithm = cms.string("AntiKt"),
rParam = cms.double(0.5),
Expand Down
Expand Up @@ -4,5 +4,6 @@
selectedHadronsAndPartons = cms.EDProducer('HadronAndPartonSelector',
src = cms.InputTag("generator"),
particles = cms.InputTag("genParticles"),
partonMode = cms.string("Auto")
partonMode = cms.string("Auto"),
fullChainPhysPartons = cms.bool(True)
)
2 changes: 2 additions & 0 deletions PhysicsTools/PatAlgos/plugins/BuildFile.xml
Expand Up @@ -14,6 +14,7 @@
<use name="DataFormats/TrackReco"/>
<use name="DataFormats/Candidate"/>
<use name="DataFormats/HeavyIonEvent"/>
<use name="DataFormats/HepMCCandidate"/>
<use name="PhysicsTools/PatUtils"/>
<use name="CondFormats/JetMETObjects"/>
<use name="CommonTools/CandAlgos"/>
Expand All @@ -22,6 +23,7 @@
<use name="TrackingTools/TransientTrack"/>
<use name="SimDataFormats/Track"/>
<use name="SimDataFormats/Vertex"/>
<use name="SimDataFormats/JetMatching"/>
<use name="SimGeneral/HepPDTRecord"/>
<use name="RecoMET/METAlgorithms"/>
<use name="RecoEgamma/EgammaTools"/>
Expand Down
88 changes: 88 additions & 0 deletions PhysicsTools/PatAlgos/plugins/GenJetFlavourInfoPreserver.cc
@@ -0,0 +1,88 @@
/**
\class pat::GenJetFlavourInfoPreserver GenJetFlavourInfoPreserver.h "PhysicsTools/JetMCAlgos/interface/GenJetFlavourInfoPreserver.h"
\brief Transfers the JetFlavourInfos from the original GenJets to the slimmedGenJets in MiniAOD

\author Andrej Saibel, andrej.saibel@cern.ch
*/


#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Common/interface/Association.h"
#include "DataFormats/Common/interface/RefToPtr.h"

#include "DataFormats/JetReco/interface/Jet.h"
#include "DataFormats/JetReco/interface/JetCollection.h"
#include "SimDataFormats/JetMatching/interface/JetFlavourInfo.h"
#include "SimDataFormats/JetMatching/interface/JetFlavourInfoMatching.h"

#include "DataFormats/JetReco/interface/GenJet.h"
#include "DataFormats/JetReco/interface/GenJetCollection.h"


namespace pat {

class GenJetFlavourInfoPreserver : public edm::stream::EDProducer<> {
public:
explicit GenJetFlavourInfoPreserver(const edm::ParameterSet & iConfig);
virtual ~GenJetFlavourInfoPreserver() { }

virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;

private:
const edm::EDGetTokenT<edm::View<reco::GenJet> > genJetsToken_;
const edm::EDGetTokenT<edm::View<reco::Jet> > slimmedGenJetsToken_;

const edm::EDGetTokenT<reco::JetFlavourInfoMatchingCollection> genJetFlavourInfosToken_;
const edm::EDGetTokenT<edm::Association<std::vector<reco::GenJet> > > slimmedGenJetAssociationToken_;
};

} // namespace

pat::GenJetFlavourInfoPreserver::GenJetFlavourInfoPreserver(const edm::ParameterSet & iConfig) :
genJetsToken_(consumes<edm::View<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("genJets"))),
slimmedGenJetsToken_(consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("slimmedGenJets"))),
genJetFlavourInfosToken_(consumes<reco::JetFlavourInfoMatchingCollection>(iConfig.getParameter<edm::InputTag>("genJetFlavourInfos"))),
slimmedGenJetAssociationToken_(consumes<edm::Association<std::vector<reco::GenJet> > >(iConfig.getParameter<edm::InputTag>("slimmedGenJetAssociation")))
{
produces<reco::JetFlavourInfoMatchingCollection>();
}

void
pat::GenJetFlavourInfoPreserver::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
using namespace edm;
using namespace std;

Handle<View<reco::GenJet> > genJets;
iEvent.getByToken(genJetsToken_, genJets);

Handle<View<reco::Jet> > slimmedGenJets;
iEvent.getByToken(slimmedGenJetsToken_, slimmedGenJets);

Handle<reco::JetFlavourInfoMatchingCollection> genJetFlavourInfos;
iEvent.getByToken(genJetFlavourInfosToken_, genJetFlavourInfos);

Handle<edm::Association<std::vector<reco::GenJet> > > slimmedGenJetAssociation;
iEvent.getByToken(slimmedGenJetAssociationToken_, slimmedGenJetAssociation);

auto jetFlavourInfos = std::make_unique<reco::JetFlavourInfoMatchingCollection>(reco::JetRefBaseProd(slimmedGenJets));
assert(genJets->size() == genJetFlavourInfos->size());

edm::Ref<std::vector<reco::GenJet> > slimmedGenJetRef;

int i = -1;
for (auto const& genJet : *genJets){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Andrej-CMS @slava77 @perrotta - this brings a warning as genJet is not actually used. Please change to a loop over i if genJets->refAt(i) is not the same as genJet in the loop below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @davidlange6 ,

I just pushed the changes to the initial branch on my repository: https://github.com/Andrej-CMS/cmssw/tree/JetFlavourMiniAOD92X

Since the changes here are already merged, do I need to make a new PR?

Kind regards,
Andrej

i++;
slimmedGenJetRef = (*slimmedGenJetAssociation)[genJets->refAt(i)];
if(!slimmedGenJetRef) continue;
(*jetFlavourInfos)[reco::JetBaseRef(slimmedGenJetRef)] = (*genJetFlavourInfos)[i].second;
}

iEvent.put(std::move(jetFlavourInfos));
}

#include "FWCore/Framework/interface/MakerMacros.h"
using namespace pat;
DEFINE_FWK_MODULE(GenJetFlavourInfoPreserver);
37 changes: 29 additions & 8 deletions PhysicsTools/PatAlgos/plugins/PATGenJetSlimmer.cc
Expand Up @@ -9,7 +9,7 @@
\author Giovanni Petrucciani
*/


#include <vector>
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
Expand Down Expand Up @@ -43,6 +43,7 @@ namespace pat {

} // namespace


pat::PATGenJetSlimmer::PATGenJetSlimmer(const edm::ParameterSet & iConfig) :
src_(consumes<edm::View<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("src"))),
gp2pgp_(consumes<edm::Association<std::vector<pat::PackedGenParticle> > >(iConfig.getParameter<edm::InputTag>("packedGenParticles"))),
Expand All @@ -51,6 +52,7 @@ pat::PATGenJetSlimmer::PATGenJetSlimmer(const edm::ParameterSet & iConfig) :
dropSpecific_(iConfig.getParameter<bool>("dropSpecific"))
{
produces<std::vector<reco::GenJet> >();
produces< edm::Association<std::vector<reco::GenJet> > >("slimmedGenJetAssociation");
}

void
Expand All @@ -61,24 +63,34 @@ pat::PATGenJetSlimmer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
Handle<View<reco::GenJet> > src;
iEvent.getByToken(src_, src);

auto out = std::make_unique<vector<reco::GenJet>>();
auto out = std::make_unique<vector<reco::GenJet> >();
out->reserve(src->size());

Handle<edm::Association<std::vector<pat::PackedGenParticle> > > gp2pgp;
iEvent.getByToken(gp2pgp_,gp2pgp);


auto genJetSlimmedGenJetAssociation = make_unique< edm::Association<std::vector<reco::GenJet> > > ();

auto mapping = std::make_unique<std::vector<int> >();
mapping->reserve(src->size());

for (View<reco::GenJet>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
if (!cut_(*it)) continue;
if (!cut_(*it)) {
mapping->push_back(-1);
continue;
}

out->push_back(*it);
reco::GenJet & jet = out->back();

mapping->push_back(it-src->begin());


if (clearDaughters_) {
jet.clearDaughters();
}
else // rekey
{
}
else // rekey
{
//copy old
reco::CompositePtrCandidate::daughters old = jet.daughterPtrVector();
jet.clearDaughters();
Expand All @@ -100,9 +112,18 @@ pat::PATGenJetSlimmer::produce(edm::Event & iEvent, const edm::EventSetup & iSet
if (dropSpecific_) {
jet.setSpecific( reco::GenJet::Specific() );
}

}

iEvent.put(std::move(out));
edm::OrphanHandle<std::vector<reco::GenJet> > orphanHandle= iEvent.put(std::move(out));

auto asso = std::make_unique<edm::Association<std::vector<reco::GenJet> > >(orphanHandle);
edm::Association< std::vector<reco::GenJet> >::Filler slimmedAssoFiller(*asso);
slimmedAssoFiller.insert(src, mapping->begin(), mapping->end());
slimmedAssoFiller.fill();


iEvent.put(std::move(asso),"slimmedGenJetAssociation");
}

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
Expand Up @@ -19,14 +19,15 @@
patJetPartons = cms.EDProducer('HadronAndPartonSelector',
src = cms.InputTag("generator"),
particles = cms.InputTag("genParticles"),
partonMode = cms.string("Auto")
partonMode = cms.string("Auto"),
fullChainPhysPartons = cms.bool(True)
)

patJetFlavourAssociation = cms.EDProducer("JetFlavourClustering",
jets = cms.InputTag("ak4PFJetsCHS"),
bHadrons = cms.InputTag("patJetPartons","bHadrons"),
cHadrons = cms.InputTag("patJetPartons","cHadrons"),
partons = cms.InputTag("patJetPartons","algorithmicPartons"),
partons = cms.InputTag("patJetPartons","physicsPartons"),
leptons = cms.InputTag("patJetPartons","leptons"),
jetAlgorithm = cms.string("AntiKt"),
rParam = cms.double(0.4),
Expand Down
Expand Up @@ -79,8 +79,9 @@
)
MicroEventContentMC.outputCommands += [
#'keep *_slimmedGenJets*_*_*',
'keep *_slimmedGenJets_*_*',
'keep *_slimmedGenJetsAK8_*_*',
'keep *_slimmedGenJets__*',
'keep *_slimmedGenJetsFlavourInfos_*_*',
'keep *_slimmedGenJetsAK8__*',
'keep patPackedGenParticles_packedGenParticles_*_*',
'keep recoGenParticles_prunedGenParticles_*_*',
'keep LHEEventProduct_*_*_*',
Expand Down
12 changes: 11 additions & 1 deletion PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Expand Up @@ -322,9 +322,19 @@ def miniAOD_customizeCommon(process):


def miniAOD_customizeMC(process):
task = getPatAlgosToolsTask(process)
#GenJetFlavourInfos
process.load("PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi")
task.add(process.selectedHadronsAndPartons)

process.load("PhysicsTools.JetMCAlgos.AK4GenJetFlavourInfos_cfi")
task.add(process.ak4GenJetFlavourInfos)

process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJetsFlavourInfos_cfi')
task.add(process.slimmedGenJetsFlavourInfos)

#slimmed pileup information
process.load('PhysicsTools.PatAlgos.slimming.slimmedAddPileupInfo_cfi')
task = getPatAlgosToolsTask(process)
task.add(process.slimmedAddPileupInfo)

process.muonMatch.matched = "prunedGenParticles"
Expand Down
@@ -0,0 +1,8 @@
import FWCore.ParameterSet.Config as cms

slimmedGenJetsFlavourInfos = cms.EDProducer("GenJetFlavourInfoPreserver",
genJets = cms.InputTag("ak4GenJetsNoNu"),
slimmedGenJets = cms.InputTag("slimmedGenJets"),
genJetFlavourInfos = cms.InputTag("ak4GenJetFlavourInfos"),
slimmedGenJetAssociation = cms.InputTag("slimmedGenJets", "slimmedGenJetAssociation")
)
Expand Up @@ -8,7 +8,6 @@
dropSpecific = cms.bool(False),
)


slimmedGenJetsAK8 = cms.EDProducer("PATGenJetSlimmer",
src = cms.InputTag("ak8GenJetsNoNu"),
packedGenParticles = cms.InputTag("packedGenParticles"),
Expand Down
4 changes: 2 additions & 2 deletions PhysicsTools/PatAlgos/python/tools/jetTools.py
Expand Up @@ -983,7 +983,7 @@ def toolCode(self, process):
_newPatJetFlavourAssociation.rParam=rParam
_newPatJetFlavourAssociation.bHadrons=cms.InputTag("patJetPartons"+postfix,"bHadrons")
_newPatJetFlavourAssociation.cHadrons=cms.InputTag("patJetPartons"+postfix,"cHadrons")
_newPatJetFlavourAssociation.partons=cms.InputTag("patJetPartons"+postfix,"algorithmicPartons")
_newPatJetFlavourAssociation.partons=cms.InputTag("patJetPartons"+postfix,"physicsPartons")
_newPatJetFlavourAssociation.leptons=cms.InputTag("patJetPartons"+postfix,"leptons")
else :
addToProcessAndTask('patJetFlavourAssociation'+_labelName+postfix,
Expand All @@ -993,7 +993,7 @@ def toolCode(self, process):
rParam=rParam,
bHadrons = cms.InputTag("patJetPartons"+postfix,"bHadrons"),
cHadrons = cms.InputTag("patJetPartons"+postfix,"cHadrons"),
partons = cms.InputTag("patJetPartons"+postfix,"algorithmicPartons"),
partons = cms.InputTag("patJetPartons"+postfix,"physicsPartons"),
leptons = cms.InputTag("patJetPartons"+postfix,"leptons")),
process, task)

Expand Down