Skip to content

Commit

Permalink
Updating gpu density definition with vertices instead of gen particles
Browse files Browse the repository at this point in the history
  • Loading branch information
rappoccio committed Dec 14, 2018
1 parent 961dc9d commit 69c7dcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
24 changes: 8 additions & 16 deletions PhysicsTools/NanoAOD/plugins/NPUTablesProducer.cc
Expand Up @@ -4,9 +4,9 @@
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "DataFormats/NanoAOD/interface/FlatTable.h"
#include "DataFormats/PatCandidates/interface/PackedGenParticle.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 @@ -16,7 +16,7 @@ class NPUTablesProducer : public edm::global::EDProducer<> {
public:
NPUTablesProducer( edm::ParameterSet const & params ) :
npuTag_(consumes<std::vector<PileupSummaryInfo>>(params.getParameter<edm::InputTag>("src"))),
genTag_(consumes<edm::View<pat::PackedGenParticle>>(params.getParameter<edm::InputTag>("gensrc"))),
pvTag_(consumes<std::vector<reco::Vertex>>(params.getParameter<edm::InputTag>("pvsrc"))),
vz_(params.getParameter<std::vector<double>>("zbins"))
{
produces<nanoaod::FlatTable>();
Expand All @@ -27,17 +27,9 @@ 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<edm::View<pat::PackedGenParticle> > genParticles;
double refpvz = -1000.0;
if ( iEvent.getByToken(genTag_, genParticles) ) {
for ( auto genIt = genParticles->begin(); genIt != genParticles->end(); ++genIt ) {
if ( genIt->statusFlags().isHardProcess() ) {
refpvz = genIt->vz();
break;
}
}
}
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)) {
Expand Down Expand Up @@ -71,7 +63,7 @@ class NPUTablesProducer : public edm::global::EDProducer<> {
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+1) - *(zbin) ) ) ;
gpudensity/=(20.0*( *(zbin) - *(zbin - 1) )) ;
}
}
unsigned int eoot = 0;
Expand All @@ -93,14 +85,14 @@ class NPUTablesProducer : public edm::global::EDProducer<> {
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>("gensrc", edm::InputTag("packedGenParticles"))->setComment("tag for the packed GenParticles");
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<edm::View<pat::PackedGenParticle>> genTag_;
const edm::EDGetTokenT<std::vector<reco::Vertex>> pvTag_;

const std::vector<double> vz_;
};
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/NanoAOD/python/globals_cff.py
Expand Up @@ -13,7 +13,7 @@

puTable = cms.EDProducer("NPUTablesProducer",
src = cms.InputTag("slimmedAddPileupInfo"),
gensrc = cms.InputTag("packedGenParticles"),
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] )
)

Expand Down

0 comments on commit 69c7dcb

Please sign in to comment.