Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:42

0001 // -*- C++ -*-
0002 //
0003 // Package:    RemovePileUpDominatedEventsGen/RemovePileUpDominatedEventsGen
0004 // Class:      RemovePileUpDominatedEventsGen
0005 //
0006 /**\class RemovePileUpDominatedEventsGen RemovePileUpDominatedEventsGen.cc RemovePileUpDominatedEventsGen/RemovePileUpDominatedEventsGen/plugins/RemovePileUpDominatedEventsGen.cc
0007 
0008  Description: [one line class summary]
0009 
0010 This EDFilter select events having the generator pt-hat greater than the pt-had of the pile-up collisions.
0011 This code is used by STEAM-TSG in order to estimate the HLT rate using MC sample, especially to avoid a rate double counting due to pile-up.
0012 For more information on the theory of this method see Appendix B of https://www.dropbox.com/home/TesiPhD_Silvio?preview=PhD_thesis.pdf .  
0013 
0014 
0015  Implementation:
0016      [Notes on implementation]
0017 */
0018 //
0019 // Original Author:  Silvio DONATO
0020 //         Created:  Fri, 12 Dec 2014 12:48:57 GMT
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   //find in-time pile-up
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   //   cout << "Using "<<bunchCrossing<<endl;
0085   //   cout << "pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing() "<<pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing()<<endl;
0086 
0087   //get the PU pt-hat max
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   //get the signal pt-hat
0097   signal_pT_hat = generatorInfo->qScale();
0098 
0099   //save PU - signal pt-hat
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   //filter the event
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);