Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-31 02:19:55

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/LuminosityBlock.h"
0005 #include "FWCore/Framework/interface/Run.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include <iostream>
0010 
0011 namespace edm {
0012   class EventSetup;
0013 }
0014 
0015 //
0016 // class declaration
0017 //
0018 class BunchSpacingProducer : public edm::stream::EDProducer<> {
0019 public:
0020   explicit BunchSpacingProducer(const edm::ParameterSet&);
0021 
0022   ~BunchSpacingProducer() override = default;
0023 
0024   void produce(edm::Event&, const edm::EventSetup&) final;
0025 
0026   static void fillDescriptions(edm::ConfigurationDescriptions&);
0027 
0028 private:
0029   const edm::EDGetTokenT<int> bunchSpacing_;
0030   const bool overRide_;
0031   const unsigned int bunchSpacingOverride_;
0032 };
0033 
0034 //
0035 // constructors and destructor
0036 //
0037 
0038 BunchSpacingProducer::BunchSpacingProducer::BunchSpacingProducer(const edm::ParameterSet& iConfig)
0039     : bunchSpacing_(consumes<int>(edm::InputTag("addPileupInfo", "bunchSpacing"))),
0040       overRide_(iConfig.getParameter<bool>("overrideBunchSpacing")),
0041       bunchSpacingOverride_(iConfig.getParameter<unsigned int>("bunchSpacingOverride")) {
0042   // register your products
0043   produces<unsigned int>();
0044 }
0045 
0046 //
0047 // member functions
0048 //
0049 void BunchSpacingProducer::produce(edm::Event& e, const edm::EventSetup& iSetup) {
0050   if (overRide_) {
0051     e.put(std::make_unique<unsigned int>(bunchSpacingOverride_));
0052     return;
0053   }
0054 
0055   unsigned int bunchSpacing = 50;
0056   unsigned int run = e.run();
0057 
0058   if (e.isRealData()) {
0059     if ((run > 252126 && run != 254833) || run == 178003 || run == 178004 || run == 209089 || run == 209106 ||
0060         run == 209109 || run == 209146 || run == 209148 || run == 209151) {
0061       bunchSpacing = 25;
0062     }
0063   } else {
0064     edm::Handle<int> bunchSpacingH;
0065     e.getByToken(bunchSpacing_, bunchSpacingH);
0066     bunchSpacing = *bunchSpacingH;
0067   }
0068 
0069   e.put(std::make_unique<unsigned int>(bunchSpacing));
0070   return;
0071 }
0072 
0073 void BunchSpacingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0074   edm::ParameterSetDescription desc;
0075   desc.add<bool>("overrideBunchSpacing", false);       // true for prompt reco
0076   desc.add<unsigned int>("bunchSpacingOverride", 25);  // override value
0077   descriptions.add("default_bunchSpacingProducer", desc);
0078 }
0079 
0080 #include "FWCore/Framework/interface/MakerMacros.h"
0081 DEFINE_FWK_MODULE(BunchSpacingProducer);