File indexing completed on 2024-04-06 12:18:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include <memory>
0025
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/stream/EDFilter.h"
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 #include <iostream>
0031 #include <SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h>
0032 #include <SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h>
0033
0034 class RemovePileUpDominatedEventsGen : public edm::stream::EDFilter<> {
0035 public:
0036 explicit RemovePileUpDominatedEventsGen(const edm::ParameterSet&);
0037 ~RemovePileUpDominatedEventsGen() override;
0038 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0039
0040 private:
0041 bool filter(edm::Event&, const edm::EventSetup&) override;
0042
0043 const edm::EDGetTokenT<std::vector<PileupSummaryInfo> > pileupSummaryInfos_;
0044 const edm::EDGetTokenT<GenEventInfoProduct> generatorInfo_;
0045 unsigned int bunchCrossing;
0046 };
0047
0048 RemovePileUpDominatedEventsGen::RemovePileUpDominatedEventsGen(const edm::ParameterSet& iConfig)
0049 : pileupSummaryInfos_(
0050 consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("pileupSummaryInfos"))),
0051 generatorInfo_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("generatorInfo"))) {
0052 bunchCrossing = 0;
0053 produces<float>();
0054 }
0055
0056 RemovePileUpDominatedEventsGen::~RemovePileUpDominatedEventsGen() = default;
0057
0058 bool RemovePileUpDominatedEventsGen::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0059 using namespace edm;
0060 using namespace std;
0061
0062 edm::Handle<GenEventInfoProduct> generatorInfo;
0063 iEvent.getByToken(generatorInfo_, generatorInfo);
0064
0065 edm::Handle<std::vector<PileupSummaryInfo> > pileupSummaryInfos;
0066 iEvent.getByToken(pileupSummaryInfos_, pileupSummaryInfos);
0067
0068
0069 if (bunchCrossing >= pileupSummaryInfos.product()->size() ||
0070 pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing() != 0) {
0071 bool found = false;
0072 for (bunchCrossing = 0; bunchCrossing < pileupSummaryInfos.product()->size() && !found; ++bunchCrossing) {
0073 if (pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing() == 0) {
0074 found = true;
0075 bunchCrossing--;
0076 }
0077 }
0078 if (!found) {
0079 edm::LogInfo("RemovePileUpDominatedEventsGen") << "In-time pile-up not found!" << endl;
0080 return true;
0081 }
0082 }
0083
0084
0085
0086
0087
0088 float signal_pT_hat = -1;
0089 float pu_pT_hat_max = -1;
0090
0091 PileupSummaryInfo puSummary_onTime = pileupSummaryInfos.product()->at(bunchCrossing);
0092 for (const auto& pu_pT_hat : puSummary_onTime.getPU_pT_hats())
0093 if (pu_pT_hat > pu_pT_hat_max)
0094 pu_pT_hat_max = pu_pT_hat;
0095
0096
0097 signal_pT_hat = generatorInfo->qScale();
0098
0099
0100 std::unique_ptr<float> pOut(new float());
0101 *pOut = signal_pT_hat - pu_pT_hat_max;
0102 iEvent.put(std::move(pOut));
0103
0104
0105 if (signal_pT_hat > pu_pT_hat_max)
0106 return true;
0107 return false;
0108 }
0109
0110 void RemovePileUpDominatedEventsGen::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0111 edm::ParameterSetDescription desc;
0112 desc.add<edm::InputTag>("pileupSummaryInfos", edm::InputTag("addPileupInfo"));
0113 desc.add<edm::InputTag>("generatorInfo", edm::InputTag("generator"));
0114 descriptions.addDefault(desc);
0115 }
0116
0117 DEFINE_FWK_MODULE(RemovePileUpDominatedEventsGen);