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 5 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
2 changes: 1 addition & 1 deletion PhysicsTools/JetMCAlgos/plugins/HadronAndPartonSelector.cc
Expand Up @@ -254,7 +254,7 @@ 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( !(it->status()==3 || (( partonMode_=="Pythia8" ) && (it->status()==23)))) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Dear @Andrej-CMS,

I am wondering if commenting out this has any consequences not only in terms of file size but also in other places where HadronAndSelector is being used.
It is because if I understand correctly, without this condition, this will contain all partons including status 2 and also stable final particles. That will be a lot of particles. This will also introduce ambiguity issue.

Best Regards,
Taejeong

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 @monttj ,
These changes were requested by the QGL Group, i.e. Paolo Azzuri. Unfortunately, I cannot find him on GitHub to comment on this.

You are right, the physicspartons will contain the whole chain. I will provide RelVal comparisons as soon as possible.

Kind regards,
Andrej

Copy link
Contributor

Choose a reason for hiding this comment

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

can you make that configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I will do that.

Kind regards,
Andrej

Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like this part will be modified to become configurable.
If it would not, the following applies:
is this commented out code needed?
Please remove or add comments inline in the code why the commented out block is relevant

if( !CandMCTagUtils::isParton( *it ) ) continue; // skip particle if not a parton
physicsPartons->push_back( reco::GenParticleRef( particles, it - particles->begin() ) );
}
Expand Down
14 changes: 14 additions & 0 deletions PhysicsTools/JetMCAlgos/python/AK4GenJetFlavourInfos_cfi.py
@@ -0,0 +1,14 @@
import FWCore.ParameterSet.Config as cms


ak4GenJetFlavourInfos = cms.EDProducer("JetFlavourClustering",
Copy link
Contributor

Choose a reason for hiding this comment

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

it will be easier to maintain if this instead clones from ak4JetFlavourInfos

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

jets = cms.InputTag("ak4GenJetsNoNu"),
bHadrons = cms.InputTag("selectedHadronsAndPartons","bHadrons"),
cHadrons = cms.InputTag("selectedHadronsAndPartons","cHadrons"),
partons = cms.InputTag("selectedHadronsAndPartons","physicsPartons"),
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("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),
Expand Down
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
103 changes: 103 additions & 0 deletions PhysicsTools/PatAlgos/plugins/GenJetFlavourInfoPreserver.cc
@@ -0,0 +1,103 @@
//
// $Id: GenJetFlavourInfoPreserver.cc,v 1.0 2017/05/18 18:45:45 $
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove this line.
It's a vestige of CVS.

//

/**
\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
*/


#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 "CommonTools/Utils/interface/StringCutObjectSelector.h"
#include "DataFormats/Common/interface/Association.h"
#include "DataFormats/Common/interface/RefToPtr.h"
#include "DataFormats/PatCandidates/interface/PackedGenParticle.h"
#include "DataFormats/JetReco/interface/GenJet.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/HepMCCandidate/interface/GenParticle.h"
#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.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);
Copy link
Contributor

Choose a reason for hiding this comment

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

please add override at the end


private:
const edm::EDGetTokenT<edm::View<reco::GenJet> > GenJetsToken_;
Copy link
Contributor

Choose a reason for hiding this comment

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

start local variables and data members with lower case letter. Capitalization is reserved for class names.

const edm::EDGetTokenT<edm::View<reco::Jet> > slimmedGenJetsToken_;

const StringCutObjectSelector<reco::GenJet> cut_;

const edm::EDGetTokenT<reco::JetFlavourInfoMatchingCollection> ak4GenJetFlavourInfosToken_;
Copy link
Contributor

Choose a reason for hiding this comment

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

ak4 prefix should be removed here

};

} // 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"))),
cut_(iConfig.getParameter<std::string>("cut")),
ak4GenJetFlavourInfosToken_(consumes<reco::JetFlavourInfoMatchingCollection>(iConfig.getParameter<edm::InputTag>("GenJetFlavourInfos")))
{
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

start local variables and data members with lower case letter. Capitalization is reserved for class names.
the same applies to the rest of the file

iEvent.getByToken(GenJetsToken_, GenJets);

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

Handle<reco::JetFlavourInfoMatchingCollection> ak4GenJetFlavourInfos;
iEvent.getByToken(ak4GenJetFlavourInfosToken_,ak4GenJetFlavourInfos);

auto jetFlavourInfos = std::make_unique<reco::JetFlavourInfoMatchingCollection>(reco::JetRefBaseProd(slimmedGenJets));


uint slimmedId = 0;



for (View<reco::GenJet>::const_iterator it = GenJets->begin(), ed = GenJets->end(); it != ed; ++it) {
Copy link
Contributor

Choose a reason for hiding this comment

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

auto will make it shorter;
also the inner loop should be merged with this:

auto jetIt = genJets->begin(), jetEnd = genJets->end();
auto jetInfoIt = genJetFlavourInfos->begin();
assert(genJets.size() == genJetFlavourInfos.size());
for(; jetIt != jetEnd; ++jetIt, ++jetInfoIt){
...

if (!cut_(*it)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

The part related to this loop and synchronization with the slimmedJets still needs a rewrite

The following comments were not addressed:
#19048 (comment)
#19048 (comment)


for(reco::JetFlavourInfoMatchingCollection::const_iterator JetInfo = ak4GenJetFlavourInfos->begin(); JetInfo != ak4GenJetFlavourInfos->end();++JetInfo){

if((JetInfo - ak4GenJetFlavourInfos->begin()) < (it - GenJets->begin())) continue;
else if((JetInfo - ak4GenJetFlavourInfos->begin()) > (it - GenJets->begin())) continue;

(*jetFlavourInfos)[slimmedGenJets->refAt(slimmedId)] = reco::JetFlavourInfo(JetInfo->second.getbHadrons(), JetInfo->second.getcHadrons(), JetInfo->second.getPartons(), JetInfo->second.getLeptons(), JetInfo->second.getHadronFlavour(), JetInfo->second.getPartonFlavour());
Copy link
Contributor

Choose a reason for hiding this comment

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

please add newlines to improve readability.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that this synchronization with slimmed GenJet indexing via a copy-paste of if (!cut_(*it)) continue; can be a working solution.
This module should just make jetFlavourInfos for all genJets and then the PATGenJetSlimmer should re-key and make a slimmed version.


break;

}

slimmedId++;
}

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

#include "FWCore/Framework/interface/MakerMacros.h"
using namespace pat;
DEFINE_FWK_MODULE(GenJetFlavourInfoPreserver);
Expand Up @@ -26,7 +26,7 @@
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 @@ -80,6 +80,7 @@
MicroEventContentMC.outputCommands += [
#'keep *_slimmedGenJets*_*_*',
'keep *_slimmedGenJets_*_*',
'keep *_slimmedGenJetsFlavourInfos*_*_*',
Copy link
Contributor

Choose a reason for hiding this comment

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

it appears that *_slimmedGenJetsFlavourInfos_*_* is enough, without the unnecessary wildcard

'keep *_slimmedGenJetsAK8_*_*',
'keep patPackedGenParticles_packedGenParticles_*_*',
'keep recoGenParticles_prunedGenParticles_*_*',
Expand Down
6 changes: 6 additions & 0 deletions PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Expand Up @@ -322,6 +322,12 @@ def miniAOD_customizeCommon(process):


def miniAOD_customizeMC(process):
#GenJetFlavourInfos
process.load("PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi")

process.selectedHadronsAndPartons.particles = "prunedGenParticles"
process.load("PhysicsTools.JetMCAlgos.AK4GenJetFlavourInfos_cfi")
Copy link
Contributor

Choose a reason for hiding this comment

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

selectedHadronsAndPartons and ak4GenJetFlavourInfos should be added to the task (as done below)


#slimmed pileup information
process.load('PhysicsTools.PatAlgos.slimming.slimmedAddPileupInfo_cfi')
task = getPatAlgosToolsTask(process)
Expand Down
6 changes: 6 additions & 0 deletions PhysicsTools/PatAlgos/python/slimming/slimmedGenJets_cfi.py
Expand Up @@ -8,6 +8,12 @@
dropSpecific = cms.bool(False),
)

slimmedGenJetsFlavourInfos = cms.EDProducer("GenJetFlavourInfoPreserver",
Copy link
Contributor

Choose a reason for hiding this comment

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

cfi files are not meant for definitions of many types of module instances.
better create a slimmedGenJetsFlavourInfos_cfi and add this module definition there.

Better yet is to implement a fillDescriptions method and let the framework create this file
https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideConfigurationValidationAndHelp .

GenJets = cms.InputTag("ak4GenJetsNoNu"),
slimmedGenJets = cms.InputTag("slimmedGenJets"),
cut = cms.string("pt > 8"), #VERY IMPORTANT: cut needs to be the same as in slimmedGenJets above.
GenJetFlavourInfos = cms.InputTag("ak4GenJetFlavourInfos")
)

slimmedGenJetsAK8 = cms.EDProducer("PATGenJetSlimmer",
src = cms.InputTag("ak8GenJetsNoNu"),
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