Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:09

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Utilities/interface/InputTag.h"
0008 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
0009 
0010 #include <algorithm>
0011 #include <vector>
0012 
0013 class TestPreMixingPileupAnalyzer : public edm::global::EDAnalyzer<> {
0014 public:
0015 public:
0016   explicit TestPreMixingPileupAnalyzer(edm::ParameterSet const& iConfig);
0017   void analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const& iSetup) const override;
0018 
0019 private:
0020   edm::EDGetTokenT<std::vector<PileupSummaryInfo>> inputToken_;
0021   std::vector<unsigned int> allowedPileups_;
0022 };
0023 
0024 TestPreMixingPileupAnalyzer::TestPreMixingPileupAnalyzer(edm::ParameterSet const& iConfig)
0025     : inputToken_(consumes<std::vector<PileupSummaryInfo>>(iConfig.getUntrackedParameter<edm::InputTag>("src"))),
0026       allowedPileups_(iConfig.getUntrackedParameter<std::vector<unsigned int>>("allowedPileups")) {}
0027 
0028 void TestPreMixingPileupAnalyzer::analyze(edm::StreamID,
0029                                           edm::Event const& iEvent,
0030                                           edm::EventSetup const& iSetup) const {
0031   edm::Handle<std::vector<PileupSummaryInfo>> h;
0032   iEvent.getByToken(inputToken_, h);
0033   const auto& summary = *h;
0034 
0035   auto it = std::find_if(summary.begin(), summary.end(), [](const auto& s) { return s.getBunchCrossing() == 0; });
0036   if (it == summary.end()) {
0037     throw cms::Exception("LogicError") << "Did not find PileupSummaryInfo in bunch crossing 0";
0038   }
0039 
0040   float trueNumInteractions = it->getTrueNumInteractions();
0041   auto pubin = static_cast<unsigned int>(trueNumInteractions);
0042   auto it2 = std::find(allowedPileups_.begin(), allowedPileups_.end(), pubin);
0043   if (it2 == allowedPileups_.end()) {
0044     cms::Exception ex{"LogicError"};
0045     ex << "Got event with true number of interactions " << trueNumInteractions << ", pileup bin is thus " << pubin
0046        << ", that is not in the list of allowed values:";
0047     for (auto v : allowedPileups_) {
0048       ex << " " << v;
0049     }
0050     throw ex;
0051   }
0052 }
0053 
0054 DEFINE_FWK_MODULE(TestPreMixingPileupAnalyzer);