Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:22

0001 // system include files
0002 #include <memory>
0003 
0004 // user include files
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/global/EDFilter.h"
0007 
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
0014 
0015 //
0016 // class declaration
0017 //
0018 
0019 class PileUpFilter : public edm::global::EDFilter<> {
0020 public:
0021   explicit PileUpFilter(const edm::ParameterSet&);
0022   ~PileUpFilter() override = default;
0023 
0024   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0025 
0026 private:
0027   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0028 
0029   // ----------member data ---------------------------
0030 private:
0031   edm::EDGetTokenT<std::vector<PileupSummaryInfo>> puSummaryInfoToken_;
0032   double minPU_;
0033   double maxPU_;
0034   bool useTrueNumInteraction_;
0035 };
0036 
0037 //
0038 // constants, enums and typedefs
0039 //
0040 
0041 //
0042 // static data member definitions
0043 //
0044 
0045 //
0046 // constructors and destructor
0047 //
0048 PileUpFilter::PileUpFilter(const edm::ParameterSet& iConfig)
0049     : puSummaryInfoToken_(
0050           consumes<std::vector<PileupSummaryInfo>>(iConfig.getParameter<edm::InputTag>("pileupInfoSummaryInputTag"))),
0051       minPU_(iConfig.getParameter<double>("minPU")),
0052       maxPU_(iConfig.getParameter<double>("maxPU")),
0053       useTrueNumInteraction_(iConfig.getUntrackedParameter<bool>("useTrueNumInteraction", true)) {
0054   // now do what ever initialization is needed
0055 }
0056 
0057 //
0058 // member functions
0059 //
0060 
0061 // ------------ method called on each new Event  ------------
0062 bool PileUpFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0063   bool pass = false;
0064 
0065   edm::Handle<std::vector<PileupSummaryInfo>> puSummaryInfoHandle;
0066   if (iEvent.getByToken(puSummaryInfoToken_, puSummaryInfoHandle)) {
0067     for (PileupSummaryInfo const& pileup : *puSummaryInfoHandle) {
0068       // only use the in-time pileup
0069       if (pileup.getBunchCrossing() == 0) {
0070         // use the per-event in-time pileup
0071         double pu = (useTrueNumInteraction_ ? pileup.getTrueNumInteractions() : pileup.getPU_NumInteractions());
0072         if (pu >= minPU_ and pu < maxPU_)
0073           pass = true;
0074       }
0075     }
0076   }
0077 
0078   return pass;
0079 }
0080 
0081 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0082 void PileUpFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0083   //The following says we do not know what parameters are allowed so do no validation
0084   // Please change this to state exactly what you do use, even if it is no parameters
0085   edm::ParameterSetDescription desc;
0086   desc.add<edm::InputTag>("pileupInfoSummaryInputTag", edm::InputTag("PileupSummaryInfo"));
0087   desc.add<double>("minPU", 0.);
0088   desc.add<double>("maxPU", 80.);
0089   desc.addUntracked<bool>("useTrueNumInteraction", true);
0090 
0091   descriptions.add("pileupFilter", desc);
0092 }
0093 //define this as a plug-in
0094 DEFINE_FWK_MODULE(PileUpFilter);