Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-06 22:22:15

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;
0023 
0024   void produce(edm::Event&, const edm::EventSetup&) final;
0025 
0026   static void fillDescriptions(edm::ConfigurationDescriptions&);
0027 
0028 private:
0029   edm::EDGetTokenT<int> bunchSpacing_;
0030   unsigned int bunchSpacingOverride_;
0031   bool overRide_;
0032 };
0033 
0034 //
0035 // constructors and destructor
0036 //
0037 
0038 BunchSpacingProducer::BunchSpacingProducer::BunchSpacingProducer(const edm::ParameterSet& iConfig) {
0039   // register your products
0040   produces<unsigned int>();
0041   bunchSpacing_ = consumes<int>(edm::InputTag("addPileupInfo", "bunchSpacing"));
0042   overRide_ = iConfig.getParameter<bool>("overrideBunchSpacing");
0043   bunchSpacingOverride_ = iConfig.getParameter<unsigned int>("bunchSpacingOverride");
0044 }
0045 
0046 BunchSpacingProducer::~BunchSpacingProducer() {}
0047 
0048 //
0049 // member functions
0050 //
0051 void BunchSpacingProducer::produce(edm::Event& e, const edm::EventSetup& iSetup) {
0052   if (overRide_) {
0053     e.put(std::make_unique<unsigned int>(bunchSpacingOverride_));
0054     return;
0055   }
0056 
0057   unsigned int bunchSpacing = 50;
0058   unsigned int run = e.run();
0059 
0060   if (e.isRealData()) {
0061     if ((run > 252126 && run != 254833) || run == 178003 || run == 178004 || run == 209089 || run == 209106 ||
0062         run == 209109 || run == 209146 || run == 209148 || run == 209151) {
0063       bunchSpacing = 25;
0064     }
0065   } else {
0066     edm::Handle<int> bunchSpacingH;
0067     e.getByToken(bunchSpacing_, bunchSpacingH);
0068     bunchSpacing = *bunchSpacingH;
0069   }
0070 
0071   e.put(std::make_unique<unsigned int>(bunchSpacing));
0072   return;
0073 }
0074 
0075 void BunchSpacingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0076   edm::ParameterSetDescription desc;
0077   desc.add<bool>("overrideBunchSpacing", false);       // true for prompt reco
0078   desc.add<unsigned int>("bunchSpacingOverride", 25);  // override value
0079 
0080   descriptions.add("BunchSpacingProducer", desc);
0081 }
0082 
0083 #include "FWCore/Framework/interface/MakerMacros.h"
0084 DEFINE_FWK_MODULE(BunchSpacingProducer);