Skip to content

Commit

Permalink
First pass at adding JERC-relevant variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rappoccio committed May 14, 2019
1 parent b37f79e commit 9807397
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 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
12 changes: 11 additions & 1 deletion 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("slimmedJets"),
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

0 comments on commit 9807397

Please sign in to comment.