CMS 3D CMS Logo

NPUTablesProducer.cc
Go to the documentation of this file.
9 
10 #include <vector>
11 #include <iostream>
12 
13 
15  public:
17  npuTag_(consumes<std::vector<PileupSummaryInfo>>(params.getParameter<edm::InputTag>("src")))
18  {
19  produces<nanoaod::FlatTable>();
20  }
21 
22  ~NPUTablesProducer() override {}
23 
24  void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override {
25  auto npuTab = std::make_unique<nanoaod::FlatTable>(1, "Pileup", true);
26 
28  if (iEvent.getByToken(npuTag_, npuInfo)) {
29  fillNPUObjectTable(*npuInfo, *npuTab);
30  }
31 
32  iEvent.put(std::move(npuTab));
33  }
34 
35  void fillNPUObjectTable(const std::vector<PileupSummaryInfo> & npuProd, nanoaod::FlatTable & out) const {
36  // Get BX 0
37  unsigned int bx0 = 0;
38  unsigned int nt = 0;
39  unsigned int npu = 0;
40  for(unsigned int ibx=0; ibx<npuProd.size(); ibx++) {
41  if(npuProd[ibx].getBunchCrossing()==0) {
42  bx0 = ibx;
43  nt = npuProd[ibx].getTrueNumInteractions();
44  npu = npuProd[ibx].getPU_NumInteractions();
45  }
46  }
47  unsigned int eoot = 0;
48  for(unsigned int ipu=0; ipu<bx0; ipu++) {
49  eoot+=npuProd[ipu].getPU_NumInteractions();
50  }
51  unsigned int loot = 0;
52  for(unsigned int ipu=npuProd.size()-1; ipu>bx0; ipu--) {
53  loot+=npuProd[ipu].getPU_NumInteractions();
54  }
55  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);
56  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);
57  out.addColumnValue<int>("sumEOOT", eoot, "number of early out of time pileup" , nanoaod::FlatTable::IntColumn);
58  out.addColumnValue<int>("sumLOOT", loot, "number of late out of time pileup" , nanoaod::FlatTable::IntColumn);
59  }
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
63  desc.add<edm::InputTag>("src", edm::InputTag("slimmedAddPileupInfo"))->setComment("tag for the PU information (vector<PileupSummaryInfo>)");
64  descriptions.add("puTable", desc);
65  }
66 
67  protected:
69 };
70 
73 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void produce(edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
int iEvent
Definition: GenABIO.cc:230
NPUTablesProducer(edm::ParameterSet const &params)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void addColumnValue(const std::string &name, const C &value, const std::string &docString, ColumnType type=defaultColumnType< T >(), int mantissaBits=-1)
Definition: FlatTable.h:101
int nt
Definition: AMPTWrapper.h:32
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > npuTag_
void fillNPUObjectTable(const std::vector< PileupSummaryInfo > &npuProd, nanoaod::FlatTable &out) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
~NPUTablesProducer() override
def move(src, dest)
Definition: eostools.py:511