CMS 3D CMS Logo

BunchSpacingProducer.cc
Go to the documentation of this file.
9 #include <iostream>
10 
11 namespace edm {
12  class EventSetup;
13 }
14 
15 //
16 // class declaration
17 //
19 
20 public:
21 
22  explicit BunchSpacingProducer(const edm::ParameterSet&);
23 
24  ~BunchSpacingProducer() override;
25 
26  void produce(edm::Event&, const edm::EventSetup&) final;
27 
28  static void fillDescriptions( edm::ConfigurationDescriptions & ) ;
29 
30 private:
31 
33  unsigned int bunchSpacingOverride_;
34  bool overRide_;
35 };
36 
37 //
38 // constructors and destructor
39 //
40 
41 
42 BunchSpacingProducer::
43 BunchSpacingProducer::BunchSpacingProducer(const edm::ParameterSet& iConfig)
44 {
45  // register your products
46  produces<unsigned int>();
47  bunchSpacing_ = consumes<int>(edm::InputTag("addPileupInfo","bunchSpacing"));
48  overRide_=false;
49  if ( iConfig.exists("overrideBunchSpacing") ) {
50  overRide_= iConfig.getParameter<bool>("overrideBunchSpacing");
51  if ( overRide_) {
52  bunchSpacingOverride_=iConfig.getParameter<unsigned int>("bunchSpacingOverride");
53  }
54  }
55 }
56 
58 }
59 
60 //
61 // member functions
62 //
64 {
65  if ( overRide_ ) {
66  e.put(std::make_unique<unsigned int>(bunchSpacingOverride_));
67  return;
68  }
69 
70  unsigned int bunchSpacing=50;
71  unsigned int run=e.run();
72 
73  if ( e.isRealData()) {
74  if ( ( run > 252126 && run != 254833 )||
75  run == 178003 ||
76  run == 178004 ||
77  run == 209089 ||
78  run == 209106 ||
79  run == 209109 ||
80  run == 209146 ||
81  run == 209148 ||
82  run == 209151) {
83  bunchSpacing = 25;
84  }
85  }
86  else{
87  edm::Handle<int> bunchSpacingH;
88  e.getByToken(bunchSpacing_,bunchSpacingH);
89  bunchSpacing = *bunchSpacingH;
90  }
91 
92  e.put(std::make_unique<unsigned int>(bunchSpacing));
93  return;
94 }
95 
97 {
99  desc.add<bool>("overrideBunchSpacing",false); // true for prompt reco
100  desc.add<unsigned int>("bunchSpacingOverride",25); // override value
101 
102  descriptions.add("bunchSpacingProducer",desc) ;
103 }
104 
105 
106 
static void fillDescriptions(edm::ConfigurationDescriptions &)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
unsigned int bunchSpacingOverride_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool isRealData() const
Definition: EventBase.h:64
edm::EDGetTokenT< int > bunchSpacing_
RunNumber_t run() const
Definition: Event.h:99
void produce(edm::Event &, const edm::EventSetup &) final
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.