test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrescalerFHN.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HCALNoiseAlCaReco
4 // Class: HCALNoiseAlCaReco
5 //
13 //
14 // Original Author: Kenneth Case Rossato
15 // Created: Wed Mar 25 13:05:10 CET 2008
16 //
17 //
18 // modified to PrecalerFHN by Grigory Safronov 27/03/09
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
33 
37 
38 #include <string>
39 
40 //
41 // class declaration
42 //
43 
44 using namespace edm;
45 
46 class PrescalerFHN : public edm::EDFilter {
47  public:
48  explicit PrescalerFHN(const edm::ParameterSet&);
49  ~PrescalerFHN();
50 
51  private:
52  virtual void beginJob() override ;
53  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
54  virtual void endJob() override ;
55  // ----------member data ---------------------------
56 
57  void init(const edm::TriggerResults &,
58  const edm::TriggerNames & triggerNames);
59 
61 
63 
64  std::map<std::string, unsigned int> prescales;
65  std::map<std::string, unsigned int> prescale_counter;
66 
67  std::map<std::string, unsigned int> trigger_indices;
68 };
69 
70 //
71 // constants, enums and typedefs
72 //
73 
74 //
75 // static data member definitions
76 //
77 
78 //
79 // constructors and destructor
80 //
82 {
83  tok_trigger = consumes<TriggerResults>(iConfig.getParameter<edm::InputTag>("TriggerResultsTag"));
84  //now do what ever initialization is needed
85  std::vector<edm::ParameterSet> prescales_in(iConfig.getParameter<std::vector<edm::ParameterSet> >("Prescales"));
86 
87  for (std::vector<edm::ParameterSet>::const_iterator cit = prescales_in.begin();
88  cit != prescales_in.end(); cit++) {
89 
90  std::string name(cit->getParameter<std::string>("HLTName"));
91  unsigned int factor(cit->getParameter<unsigned int>("PrescaleFactor"));
92 
93  // does some exception get thrown if parameters aren't available? should test...
94 
96  prescale_counter[name] = 0;
97  }
98 
99 }
100 
101 
103 {
104 
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 
108 }
109 
110 
111 //
112 // member functions
113 //
114 
116  const edm::TriggerNames & triggerNames)
117 {
118  trigger_indices.clear();
119 
120  for (std::map<std::string, unsigned int>::const_iterator cit = prescales.begin();
121  cit != prescales.end(); cit++) {
122 
123  trigger_indices[cit->first] = triggerNames.triggerIndex(cit->first);
124 
125  if (trigger_indices[cit->first] >= result.size()) {
126  // trigger path not found
127  LogDebug("") << "requested HLT path does not exist: " << cit->first;
128  trigger_indices.erase(cit->first);
129  }
130 
131  }
132 }
133 
134 // ------------ method called on each new Event ------------
135 bool
137 {
138  using namespace edm;
139 
140  /* Goal for this skim:
141  Prescaling MET HLT paths
142  Option to turn off HSCP filter
143  - Doing that by treating it as an HLT with prescale 1
144  */
145 
146  // Trying to mirror HLTrigger/HLTfilters/src/HLTHighLevel.cc where possible
147 
149  iEvent.getByToken(tok_trigger, trh);
150 
151  if (trh.isValid()) {
152  LogDebug("") << "TriggerResults found, number of HLT paths: " << trh->size();
153  } else {
154  LogDebug("") << "TriggerResults product not found - returning result=false!";
155  return false;
156  }
157 
158  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*trh);
159  if (triggerNamesID_ != triggerNames.parameterSetID()) {
160  triggerNamesID_ = triggerNames.parameterSetID();
161  init(*trh, triggerNames);
162  }
163 
164  // Trigger indices are ready at this point
165  // - Begin checking for HLT bits
166 
167  bool accept_event = false;
168  for (std::map<std::string, unsigned int>::const_iterator cit = trigger_indices.begin();
169  cit != trigger_indices.end(); cit++) {
170  if (trh->accept(cit->second)) {
171  prescale_counter[cit->first]++;
172  if (prescale_counter[cit->first] >= prescales[cit->first]) {
173  accept_event = true;
174  prescale_counter[cit->first] = 0;
175  }
176  }
177  }
178 
179  return accept_event;
180 }
181 
182 // ------------ method called once each job just before starting event loop ------------
183 void
185 {
186 }
187 
188 // ------------ method called once each job just after ending the event loop ------------
189 void
191 }
192 
193 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:215
virtual void beginJob() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int init
Definition: HydjetWrapper.h:67
edm::ParameterSetID triggerNamesID_
Definition: PrescalerFHN.cc:60
void init(const edm::TriggerResults &, const edm::TriggerNames &triggerNames)
void beginJob()
Definition: Breakpoints.cc:15
tuple result
Definition: mps_fire.py:84
ParameterSetID const & parameterSetID() const
Definition: TriggerNames.cc:42
int iEvent
Definition: GenABIO.cc:230
std::map< std::string, unsigned int > prescales
Definition: PrescalerFHN.cc:64
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
std::map< std::string, unsigned int > prescale_counter
Definition: PrescalerFHN.cc:65
unsigned int size() const
Get number of paths stored.
virtual void endJob() override
std::map< std::string, unsigned int > trigger_indices
Definition: PrescalerFHN.cc:67
edm::EDGetTokenT< TriggerResults > tok_trigger
Definition: PrescalerFHN.cc:62
virtual bool filter(edm::Event &, const edm::EventSetup &) override
PrescalerFHN(const edm::ParameterSet &)
Definition: PrescalerFHN.cc:81