CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Attributes
NPUTablesProducer Class Reference
Inheritance diagram for NPUTablesProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

void fillNPUObjectTable (const std::vector< PileupSummaryInfo > &npuProd, nanoaod::FlatTable &out, double refpvz) const
 
 NPUTablesProducer (edm::ParameterSet const &params)
 
void produce (edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 
 ~NPUTablesProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Protected Attributes

const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > npuTag_
 
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvTag_
 
bool savePtHatMax_
 
const std::vector< double > vz_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 15 of file NPUTablesProducer.cc.

Constructor & Destructor Documentation

◆ NPUTablesProducer()

NPUTablesProducer::NPUTablesProducer ( edm::ParameterSet const &  params)
inline

Definition at line 17 of file NPUTablesProducer.cc.

18  : npuTag_(consumes<std::vector<PileupSummaryInfo>>(params.getParameter<edm::InputTag>("src"))),
19  pvTag_(consumes<std::vector<reco::Vertex>>(params.getParameter<edm::InputTag>("pvsrc"))),
20  vz_(params.getParameter<std::vector<double>>("zbins")),
21  savePtHatMax_(params.getParameter<bool>("savePtHatMax")) {
22  produces<nanoaod::FlatTable>();
23  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > npuTag_
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvTag_
const std::vector< double > vz_

◆ ~NPUTablesProducer()

NPUTablesProducer::~NPUTablesProducer ( )
inlineoverride

Definition at line 25 of file NPUTablesProducer.cc.

25 {}

Member Function Documentation

◆ fillDescriptions()

static void NPUTablesProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 104 of file NPUTablesProducer.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and ProducerED_cfi::InputTag.

104  {
106  desc.add<edm::InputTag>("src", edm::InputTag("slimmedAddPileupInfo"))
107  ->setComment("tag for the PU information (vector<PileupSummaryInfo>)");
108  desc.add<edm::InputTag>("pvsrc", edm::InputTag("offlineSlimmedPrimaryVertices"))->setComment("tag for the PVs");
109  desc.add<std::vector<double>>("zbins", {})
110  ->setComment("Z bins to compute the generator-level number of PU vertices per mm");
111  desc.add<bool>("savePtHatMax", false)->setComment("Store maximum pt-hat of PU");
112  descriptions.add("puTable", desc);
113  }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ fillNPUObjectTable()

void NPUTablesProducer::fillNPUObjectTable ( const std::vector< PileupSummaryInfo > &  npuProd,
nanoaod::FlatTable out,
double  refpvz 
) const
inline

Definition at line 41 of file NPUTablesProducer.cc.

References funct::abs(), newFWLiteAna::bin, mps_fire::end, dqmiolumiharvest::j, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, nt, MillePedeFileConverter_cfg::out, savePtHatMax_, and vz_.

Referenced by produce().

41  {
42  // Get BX 0
43  unsigned int bx0 = 0;
44  float nt = 0;
45  unsigned int npu = 0;
46 
47  auto zbin = std::lower_bound(vz_.begin(), vz_.end() - 1, std::abs(refpvz));
48  float pudensity = 0;
49  float gpudensity = 0;
50 
51  float pthatmax = 0;
52 
53  for (unsigned int ibx = 0; ibx < npuProd.size(); ibx++) {
54  if (npuProd[ibx].getBunchCrossing() == 0) {
55  bx0 = ibx;
56  nt = npuProd[ibx].getTrueNumInteractions();
57  npu = npuProd[ibx].getPU_NumInteractions();
58 
59  std::vector<float> zpositions;
60  unsigned int nzpositions = npuProd[ibx].getPU_zpositions().size();
61  for (unsigned int j = 0; j < nzpositions; ++j) {
62  zpositions.push_back(npuProd[ibx].getPU_zpositions()[j]);
63  if (std::abs(zpositions.back() - refpvz) < 0.1)
64  pudensity++; //N_PU/mm
65  auto bin = std::lower_bound(vz_.begin(), vz_.end() - 1, std::abs(zpositions.back()));
66  if (bin != vz_.end() && bin == zbin)
67  gpudensity++;
68  }
69  gpudensity /= (20.0 * (*(zbin) - *(zbin - 1)));
70 
71  if (savePtHatMax_) {
72  if (!npuProd[ibx].getPU_pT_hats().empty()) {
73  pthatmax = *max_element(npuProd[ibx].getPU_pT_hats().begin(), npuProd[ibx].getPU_pT_hats().end());
74  }
75  }
76  }
77  }
78  unsigned int eoot = 0;
79  for (unsigned int ipu = 0; ipu < bx0; ipu++) {
80  eoot += npuProd[ipu].getPU_NumInteractions();
81  }
82  unsigned int loot = 0;
83  for (unsigned int ipu = npuProd.size() - 1; ipu > bx0; ipu--) {
84  loot += npuProd[ipu].getPU_NumInteractions();
85  }
86  out.addColumnValue<float>("nTrueInt",
87  nt,
88  "the true mean number of the poisson distribution for this event from which the number "
89  "of interactions each bunch crossing has been sampled",
90  10);
91  out.addColumnValue<int>(
92  "nPU",
93  npu,
94  "the number of pileup interactions that have been added to the event in the current bunch crossing");
95  out.addColumnValue<int>("sumEOOT", eoot, "number of early out of time pileup");
96  out.addColumnValue<int>("sumLOOT", loot, "number of late out of time pileup");
97  out.addColumnValue<float>("pudensity", pudensity, "PU vertices / mm");
98  out.addColumnValue<float>("gpudensity", gpudensity, "Generator-level PU vertices / mm");
99  if (savePtHatMax_) {
100  out.addColumnValue<float>("pthatmax", pthatmax, "Maximum pt-hat", 10);
101  }
102  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int nt
Definition: AMPTWrapper.h:42
const std::vector< double > vz_

◆ produce()

void NPUTablesProducer::produce ( edm::StreamID  id,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
inlineoverridevirtual

Implements edm::global::EDProducerBase.

Definition at line 27 of file NPUTablesProducer.cc.

References fillNPUObjectTable(), iEvent, eostools::move(), npuTag_, and pvTag_.

27  {
28  auto npuTab = std::make_unique<nanoaod::FlatTable>(1, "Pileup", true);
29 
30  const auto& pvProd = iEvent.get(pvTag_);
31  const double refpvz = pvProd.at(0).position().z();
32 
34  if (iEvent.getByToken(npuTag_, npuInfo)) {
35  fillNPUObjectTable(*npuInfo, *npuTab, refpvz);
36  }
37 
38  iEvent.put(std::move(npuTab));
39  }
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > npuTag_
void fillNPUObjectTable(const std::vector< PileupSummaryInfo > &npuProd, nanoaod::FlatTable &out, double refpvz) const
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvTag_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ npuTag_

const edm::EDGetTokenT<std::vector<PileupSummaryInfo> > NPUTablesProducer::npuTag_
protected

Definition at line 116 of file NPUTablesProducer.cc.

Referenced by produce().

◆ pvTag_

const edm::EDGetTokenT<std::vector<reco::Vertex> > NPUTablesProducer::pvTag_
protected

Definition at line 117 of file NPUTablesProducer.cc.

Referenced by produce().

◆ savePtHatMax_

bool NPUTablesProducer::savePtHatMax_
protected

Definition at line 121 of file NPUTablesProducer.cc.

Referenced by fillNPUObjectTable().

◆ vz_

const std::vector<double> NPUTablesProducer::vz_
protected

Definition at line 119 of file NPUTablesProducer.cc.

Referenced by fillNPUObjectTable().