Skip to content

Commit

Permalink
Merge pull request #246 from rappoccio/rappoccio_nanoaodjerc_102x
Browse files Browse the repository at this point in the history
Adding a few jet and event variables to prepare for automatic JEC workflows
  • Loading branch information
peruzzim committed May 15, 2019
2 parents 3f603c6 + 0e48744 commit 18046ad
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
39 changes: 34 additions & 5 deletions PhysicsTools/NanoAOD/plugins/NPUTablesProducer.cc
Expand Up @@ -6,6 +6,7 @@
#include "DataFormats/NanoAOD/interface/FlatTable.h"
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
#include "DataFormats/VertexReco/interface/Vertex.h"

#include <vector>
#include <iostream>
Expand All @@ -14,7 +15,9 @@
class NPUTablesProducer : public edm::global::EDProducer<> {
public:
NPUTablesProducer( edm::ParameterSet const & params ) :
npuTag_(consumes<std::vector<PileupSummaryInfo>>(params.getParameter<edm::InputTag>("src")))
npuTag_(consumes<std::vector<PileupSummaryInfo>>(params.getParameter<edm::InputTag>("src"))),
pvTag_(consumes<std::vector<reco::Vertex>>(params.getParameter<edm::InputTag>("pvsrc"))),
vz_(params.getParameter<std::vector<double>>("zbins"))
{
produces<nanoaod::FlatTable>();
}
Expand All @@ -24,24 +27,43 @@ class NPUTablesProducer : public edm::global::EDProducer<> {
void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override {
auto npuTab = std::make_unique<nanoaod::FlatTable>(1, "Pileup", true);

edm::Handle<std::vector<PileupSummaryInfo> > npuInfo;
edm::Handle<std::vector<reco::Vertex>> pvsIn;
iEvent.getByToken(pvTag_, pvsIn);
const double refpvz = (*pvsIn)[0].position().z();

edm::Handle<std::vector<PileupSummaryInfo> > npuInfo;
if (iEvent.getByToken(npuTag_, npuInfo)) {
fillNPUObjectTable(*npuInfo, *npuTab);
fillNPUObjectTable(*npuInfo, *npuTab, refpvz);
}

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

void fillNPUObjectTable(const std::vector<PileupSummaryInfo> & npuProd, nanoaod::FlatTable & out) const {
void fillNPUObjectTable(const std::vector<PileupSummaryInfo> & npuProd, nanoaod::FlatTable & out, double refpvz) const {
// Get BX 0
unsigned int bx0 = 0;
unsigned int nt = 0;
unsigned int npu = 0;

auto zbin = std::lower_bound( vz_.begin(), vz_.end()-1, std::abs(refpvz) );
float pudensity = 0;
float gpudensity = 0;

for(unsigned int ibx=0; ibx<npuProd.size(); ibx++) {
if(npuProd[ibx].getBunchCrossing()==0) {
bx0 = ibx;
nt = npuProd[ibx].getTrueNumInteractions();
npu = npuProd[ibx].getPU_NumInteractions();

std::vector<float> zpositions;
unsigned int nzpositions = npuProd[ibx].getPU_zpositions().size();
for (unsigned int j=0; j<nzpositions; ++j) {
zpositions.push_back(npuProd[ibx].getPU_zpositions()[j]);
if (std::abs(zpositions.back()- refpvz)<0.1) pudensity++; //N_PU/mm
auto bin = std::lower_bound( vz_.begin(), vz_.end()-1, std::abs(zpositions.back()) );
if ( bin != vz_.end() && bin==zbin) gpudensity++;
}
gpudensity/=(20.0*( *(zbin) - *(zbin - 1) )) ;
}
}
unsigned int eoot = 0;
Expand All @@ -52,20 +74,27 @@ class NPUTablesProducer : public edm::global::EDProducer<> {
for(unsigned int ipu=npuProd.size()-1; ipu>bx0; ipu--) {
loot+=npuProd[ipu].getPU_NumInteractions();
}
out.addColumnValue<float>("nTrueInt", nt, "the true mean number of the poisson distribution for this event from which the number of interactions each bunch crossing has been sampled", nanoaod::FlatTable::FloatColumn);
out.addColumnValue<float>("nTrueInt", nt, "the true mean number of the poisson distribution for this event from which the number of interactions each bunch crossing has been sampled", nanoaod::FlatTable::FloatColumn);
out.addColumnValue<int>("nPU", npu, "the number of pileup interactions that have been added to the event in the current bunch crossing", nanoaod::FlatTable::IntColumn);
out.addColumnValue<int>("sumEOOT", eoot, "number of early out of time pileup" , nanoaod::FlatTable::IntColumn);
out.addColumnValue<int>("sumLOOT", loot, "number of late out of time pileup" , nanoaod::FlatTable::IntColumn);
out.addColumnValue<float>("pudensity", pudensity, "PU vertices / mm", nanoaod::FlatTable::FloatColumn);
out.addColumnValue<float>("gpudensity", gpudensity, "Generator-level PU vertices / mm", nanoaod::FlatTable::FloatColumn);
}

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("src", edm::InputTag("slimmedAddPileupInfo"))->setComment("tag for the PU information (vector<PileupSummaryInfo>)");
desc.add<edm::InputTag>("pvsrc", edm::InputTag("offlineSlimmedPrimaryVertices"))->setComment("tag for the PVs");
desc.add<std::vector<double>> ("zbins", {})->setComment("Z bins to compute the generator-level number of PU vertices per mm");
descriptions.add("puTable", desc);
}

protected:
const edm::EDGetTokenT<std::vector<PileupSummaryInfo>> npuTag_;
const edm::EDGetTokenT<std::vector<reco::Vertex>> pvTag_;

const std::vector<double> vz_;
};

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
4 changes: 4 additions & 0 deletions PhysicsTools/NanoAOD/python/globals_cff.py
Expand Up @@ -6,11 +6,15 @@
fixedGridRhoFastjetAll = ExtVar( cms.InputTag("fixedGridRhoFastjetAll"), "double", doc = "rho from all PF Candidates, used e.g. for JECs" ),
fixedGridRhoFastjetCentralNeutral = ExtVar( cms.InputTag("fixedGridRhoFastjetCentralNeutral"), "double", doc = "rho from neutral PF Candidates with |eta| < 2.5, used e.g. for rho corrections of some lepton isolations" ),
fixedGridRhoFastjetCentralCalo = ExtVar( cms.InputTag("fixedGridRhoFastjetCentralCalo"), "double", doc = "rho from calo towers with |eta| < 2.5, used e.g. egamma PFCluster isolation" ),
fixedGridRhoFastjetCentral = ExtVar( cms.InputTag("fixedGridRhoFastjetCentral"), "double", doc = "rho from all PF Candidates for central region, used e.g. for JECs" ),
fixedGridRhoFastjetCentralChargedPileUp = ExtVar( cms.InputTag("fixedGridRhoFastjetCentralChargedPileUp"), "double", doc = "rho from charged PF Candidates for central region, used e.g. for JECs" ),
)
)

puTable = cms.EDProducer("NPUTablesProducer",
src = cms.InputTag("slimmedAddPileupInfo"),
pvsrc = cms.InputTag("offlineSlimmedPrimaryVertices"),
zbins = cms.vdouble( [0.0,1.7,2.6,3.0,3.5,4.2,5.2,6.0,7.5,9.0,12.0] )
)

genTable = cms.EDProducer("SimpleGenEventFlatTableProducer",
Expand Down
14 changes: 12 additions & 2 deletions PhysicsTools/NanoAOD/python/jets_cff.py
Expand Up @@ -3,7 +3,7 @@
from Configuration.Eras.Modifier_run2_nanoAOD_94X2016_cff import run2_nanoAOD_94X2016

from PhysicsTools.NanoAOD.common_cff import *

from RecoJets.JetProducers.ak4PFJetsBetaStar_cfi import *


##################### User floats producers, selectors ##########################
Expand Down Expand Up @@ -111,6 +111,12 @@
#elesrc = cms.InputTag("slimmedElectrons")
)

jercVars = cms.EDProducer("BetaStarPackedCandidateVarProducer",
srcJet = cms.InputTag("updatedJets"),
srcPF = cms.InputTag("packedPFCandidates"),
maxDR = cms.double(0.4)
)


updatedJetsWithUserData = cms.EDProducer("PATJetUserDataEmbedder",
src = cms.InputTag("updatedJets"),
Expand All @@ -131,6 +137,8 @@
ptD = cms.InputTag("bJetVars:ptD"),
genPtwNu = cms.InputTag("bJetVars:genPtwNu"),
qgl = cms.InputTag('qgtagger:qgLikelihood'),
jercCHPUF = cms.InputTag("jercVars:chargedHadronPUEnergyFraction"),
jercCHF = cms.InputTag("jercVars:chargedHadronCHSEnergyFraction"),
),
userInts = cms.PSet(
tightId = cms.InputTag("tightJetId"),
Expand Down Expand Up @@ -214,6 +222,8 @@
chEmEF = Var("chargedEmEnergyFraction()", float, doc="charged Electromagnetic Energy Fraction", precision= 6),
neEmEF = Var("neutralEmEnergyFraction()", float, doc="neutral Electromagnetic Energy Fraction", precision= 6),
muEF = Var("muonEnergyFraction()", float, doc="muon Energy Fraction", precision= 6),
jercCHPUF = Var("userFloat('jercCHPUF')", float, doc="Pileup Charged Hadron Energy Fraction with the JERC group definition", precision= 6),
jercCHF = Var("userFloat('jercCHF')", float, doc="Charged Hadron Energy Fraction with the JERC group definition", precision= 6),
)
)

Expand Down Expand Up @@ -548,7 +558,7 @@
qgtagger=QGTagger.clone(srcJets="updatedJets",srcVertexCollection="offlineSlimmedPrimaryVertices")

#before cross linking
jetSequence = cms.Sequence(jetCorrFactorsNano+updatedJets+tightJetId+tightJetIdLepVeto+bJetVars+qgtagger+updatedJetsWithUserData+jetCorrFactorsAK8+updatedJetsAK8+tightJetIdAK8+tightJetIdLepVetoAK8+updatedJetsAK8WithUserData+chsForSATkJets+softActivityJets+softActivityJets2+softActivityJets5+softActivityJets10+finalJets+finalJetsAK8)
jetSequence = cms.Sequence(jetCorrFactorsNano+updatedJets+tightJetId+tightJetIdLepVeto+bJetVars+jercVars+qgtagger+updatedJetsWithUserData+jetCorrFactorsAK8+updatedJetsAK8+tightJetIdAK8+tightJetIdLepVetoAK8+updatedJetsAK8WithUserData+chsForSATkJets+softActivityJets+softActivityJets2+softActivityJets5+softActivityJets10+finalJets+finalJetsAK8)

_jetSequence_2016 = jetSequence.copy()
_jetSequence_2016.insert(_jetSequence_2016.index(tightJetId), looseJetId)
Expand Down
4 changes: 4 additions & 0 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Expand Up @@ -290,6 +290,8 @@
Plot1D('eta', 'eta', 20, -6, 6, 'eta'),
NoPlot('genJetIdx'),
Plot1D('hadronFlavour', 'hadronFlavour', 6, -0.5, 5.5, 'flavour from hadron ghost clustering'),
Plot1D('jercCHF', 'jercCHF', 20, 0, 1, 'Charged Hadron Energy Fraction with the JERC group definition'),
Plot1D('jercCHPUF', 'jercCHPUF', 20, 0, 2, 'Pileup Charged Hadron Energy Fraction with the JERC group definition'),
Plot1D('jetId', 'jetId', 8, -0.5, 7.5, 'Jet ID flags bit1 is loose (always false in 2017 since it does not exist), bit2 is tight, bit3 is tightLepVeto'),
Plot1D('mass', 'mass', 20, 0, 200, 'mass'),
Plot1D('muEF', 'muEF', 20, 0, 1, 'muon Energy Fraction'),
Expand Down Expand Up @@ -439,8 +441,10 @@
Pileup = cms.PSet(
sels = cms.PSet(),
plots = cms.VPSet(
Plot1D('gpudensity', 'gpudensity', 20, 0, 0.9, 'Generator-level PU vertices / mm'),
Plot1D('nPU', 'nPU', 20, 0, 60, 'the number of pileup interactions that have been added to the event in the current bunch crossing'),
Plot1D('nTrueInt', 'nTrueInt', 20, 0, 60, 'the true mean number of the poisson distribution for this event from which the number of interactions each bunch crossing has been sampled'),
Plot1D('pudensity', 'pudensity', 5, -0.5, 4.5, 'PU vertices / mm'),
Plot1D('sumEOOT', 'sumEOOT', 20, 0, 800, 'number of early out of time pileup'),
Plot1D('sumLOOT', 'sumLOOT', 20, 0, 300, 'number of late out of time pileup'),
)
Expand Down

0 comments on commit 18046ad

Please sign in to comment.