Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:55

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/global/EDProducer.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 
0006 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
0007 
0008 #include <iostream>
0009 
0010 class PileupSummaryInfoSlimmer : public edm::global::EDProducer<> {
0011 public:
0012   PileupSummaryInfoSlimmer(const edm::ParameterSet& conf)
0013       : src_(consumes<std::vector<PileupSummaryInfo>>(conf.getParameter<edm::InputTag>("src"))),
0014         keepDetailedInfoFor_(conf.getParameter<std::vector<int32_t>>("keepDetailedInfoFor")) {
0015     produces<std::vector<PileupSummaryInfo>>();
0016   }
0017 
0018   void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const final;
0019 
0020 private:
0021   const edm::EDGetTokenT<std::vector<PileupSummaryInfo>> src_;
0022   const std::vector<int> keepDetailedInfoFor_;
0023 };
0024 
0025 void PileupSummaryInfoSlimmer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
0026   edm::Handle<std::vector<PileupSummaryInfo>> input;
0027   auto output = std::make_unique<std::vector<PileupSummaryInfo>>();
0028 
0029   evt.getByToken(src_, input);
0030 
0031   for (const auto& psu : *input) {
0032     const int bunchCrossing = psu.getBunchCrossing();
0033     const int bunchSpacing = psu.getBunchSpacing();
0034     const int num_PU_vertices = psu.getPU_NumInteractions();
0035     const float TrueNumInteractions = psu.getTrueNumInteractions();
0036 
0037     std::vector<float> zpositions;
0038     std::vector<float> times;
0039     std::vector<float> sumpT_lowpT;
0040     std::vector<float> sumpT_highpT;
0041     std::vector<int> ntrks_lowpT;
0042     std::vector<int> ntrks_highpT;
0043     std::vector<edm::EventID> eventInfo;
0044     std::vector<float> pT_hats;
0045 
0046     const bool keep_details = std::find(keepDetailedInfoFor_.begin(), keepDetailedInfoFor_.end(), bunchCrossing) !=
0047                               keepDetailedInfoFor_.end();
0048 
0049     if (keep_details) {
0050       zpositions = psu.getPU_zpositions();
0051       times = psu.getPU_times();
0052       sumpT_lowpT = psu.getPU_sumpT_lowpT();
0053       sumpT_highpT = psu.getPU_sumpT_highpT();
0054       ntrks_lowpT = psu.getPU_ntrks_lowpT();
0055       ntrks_highpT = psu.getPU_ntrks_highpT();
0056       eventInfo = psu.getPU_EventID();
0057       pT_hats = psu.getPU_pT_hats();
0058     }
0059     // insert the slimmed vertex info
0060     output->emplace_back(num_PU_vertices,
0061                          zpositions,
0062                          times,
0063                          sumpT_lowpT,
0064                          sumpT_highpT,
0065                          ntrks_lowpT,
0066                          ntrks_highpT,
0067                          eventInfo,
0068                          pT_hats,
0069                          bunchCrossing,
0070                          TrueNumInteractions,
0071                          bunchSpacing);
0072   }
0073 
0074   evt.put(std::move(output));
0075 }
0076 
0077 #include "FWCore/Framework/interface/MakerMacros.h"
0078 DEFINE_FWK_MODULE(PileupSummaryInfoSlimmer);