CMS 3D CMS Logo

NPUTablesProducer.cc
Go to the documentation of this file.
10 
11 #include <vector>
12 #include <iostream>
13 #include <algorithm>
14 
16 public:
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  }
24 
25  ~NPUTablesProducer() override {}
26 
27  void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override {
28  auto npuTab = std::make_unique<nanoaod::FlatTable>(1, "Pileup", true);
29 
31  iEvent.getByToken(pvTag_, pvsIn);
32  const double refpvz = (*pvsIn)[0].position().z();
33 
35  if (iEvent.getByToken(npuTag_, npuInfo)) {
36  fillNPUObjectTable(*npuInfo, *npuTab, refpvz);
37  }
38 
39  iEvent.put(std::move(npuTab));
40  }
41 
42  void fillNPUObjectTable(const std::vector<PileupSummaryInfo>& npuProd, nanoaod::FlatTable& out, double refpvz) const {
43  // Get BX 0
44  unsigned int bx0 = 0;
45  unsigned int nt = 0;
46  unsigned int npu = 0;
47 
48  auto zbin = std::lower_bound(vz_.begin(), vz_.end() - 1, std::abs(refpvz));
49  float pudensity = 0;
50  float gpudensity = 0;
51 
52  float pthatmax = 0;
53 
54  for (unsigned int ibx = 0; ibx < npuProd.size(); ibx++) {
55  if (npuProd[ibx].getBunchCrossing() == 0) {
56  bx0 = ibx;
57  nt = npuProd[ibx].getTrueNumInteractions();
58  npu = npuProd[ibx].getPU_NumInteractions();
59 
60  std::vector<float> zpositions;
61  unsigned int nzpositions = npuProd[ibx].getPU_zpositions().size();
62  for (unsigned int j = 0; j < nzpositions; ++j) {
63  zpositions.push_back(npuProd[ibx].getPU_zpositions()[j]);
64  if (std::abs(zpositions.back() - refpvz) < 0.1)
65  pudensity++; //N_PU/mm
66  auto bin = std::lower_bound(vz_.begin(), vz_.end() - 1, std::abs(zpositions.back()));
67  if (bin != vz_.end() && bin == zbin)
68  gpudensity++;
69  }
70  gpudensity /= (20.0 * (*(zbin) - *(zbin - 1)));
71 
72  if (savePtHatMax_) {
73  if (!npuProd[ibx].getPU_pT_hats().empty()) {
74  pthatmax = *max_element(npuProd[ibx].getPU_pT_hats().begin(), npuProd[ibx].getPU_pT_hats().end());
75  }
76  }
77  }
78  }
79  unsigned int eoot = 0;
80  for (unsigned int ipu = 0; ipu < bx0; ipu++) {
81  eoot += npuProd[ipu].getPU_NumInteractions();
82  }
83  unsigned int loot = 0;
84  for (unsigned int ipu = npuProd.size() - 1; ipu > bx0; ipu--) {
85  loot += npuProd[ipu].getPU_NumInteractions();
86  }
87  out.addColumnValue<float>("nTrueInt",
88  nt,
89  "the true mean number of the poisson distribution for this event from which the number "
90  "of interactions each bunch crossing has been sampled");
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");
101  }
102  }
103 
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  }
114 
115 protected:
118 
119  const std::vector<double> vz_;
120 
122 };
123 
ConfigurationDescriptions.h
NPUTablesProducer::savePtHatMax_
bool savePtHatMax_
Definition: NPUTablesProducer.cc:121
edm::StreamID
Definition: StreamID.h:30
PileupSummaryInfo.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
NPUTablesProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: NPUTablesProducer.cc:104
NPUTablesProducer::pvTag_
const edm::EDGetTokenT< std::vector< reco::Vertex > > pvTag_
Definition: NPUTablesProducer.cc:117
nt
int nt
Definition: AMPTWrapper.h:42
NPUTablesProducer::fillNPUObjectTable
void fillNPUObjectTable(const std::vector< PileupSummaryInfo > &npuProd, nanoaod::FlatTable &out, double refpvz) const
Definition: NPUTablesProducer.cc:42
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
NPUTablesProducer::NPUTablesProducer
NPUTablesProducer(edm::ParameterSet const &params)
Definition: NPUTablesProducer.cc:17
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
mps_fire.end
end
Definition: mps_fire.py:242
NPUTablesProducer
Definition: NPUTablesProducer.cc:15
ParameterSetDescription.h
NPUTablesProducer::produce
void produce(edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: NPUTablesProducer.cc:27
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
Vertex.h
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
NPUTablesProducer::vz_
const std::vector< double > vz_
Definition: NPUTablesProducer.cc:119
FlatTable.h
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
nanoaod::FlatTable
Definition: FlatTable.h:38
LHEEventProduct.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
NPUTablesProducer::npuTag_
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > npuTag_
Definition: NPUTablesProducer.cc:116
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:155
EDProducer.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
NPUTablesProducer::~NPUTablesProducer
~NPUTablesProducer() override
Definition: NPUTablesProducer.cc:25
PileupSummaryInfo
Definition: PileupSummaryInfo.h:22