CMS 3D CMS Logo

HcalLaserEventFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalLaserEventFilter
4 // Class: HcalLaserEventFilter
5 //
15 //
16 // Original Author: Jeff Temple (temple@cern.ch)
17 // Created: Thu Nov 17 12:44:22 EST 2011
18 //
19 //
20 
21 
22 // system include files
23 #include <memory>
24 #include <sstream>
25 #include <iostream>
26 #include <string>
27 
28 
29 // user include files
33 
36 
39 
40 // Use for HBHERecHitCollection
42 
44 
46 //
47 // class declaration
48 //
49 
51  public:
52  explicit HcalLaserEventFilter(const edm::ParameterSet&);
53  ~HcalLaserEventFilter() override;
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57  private:
58  bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
59 
60  std::vector<int> GetCMSSWVersion(std::string const&) const;
61  bool IsGreaterThanMinCMSSWVersion(std::vector<int> const&) const;
62 
63  // ----------member data ---------------------------
64 
65  // Filter option 1: veto events by run, event number
67  std::vector<std::pair<edm::RunNumber_t,edm::EventNumber_t> > RunEventData_;
68 
69  // Filter option 2: veto events by HBHE occupancy
71  const unsigned int minOccupiedHBHE_;
72 
73  const bool vetoByLaserMonitor_;
74  const double minLaserMonitorCharge_;
75 
76  // Allow for debugging information to be printed
77  const bool debug_;
78  // Reverse the filter decision (so instead of selecting only good events, it
79  // will select only events that fail the filter conditions -- useful for studying
80  // bad events.)
81  const bool reverseFilter_;
82 
83  // InputTag for HBHE rechits
88 
89  const bool taggingMode_;
90 
91  // Decide whether to use the HcalNoiseSummary to get the RecHit info, or to use the RecHit Collection itself
95  std::vector<int> minVersion_;
96 };
97 
98 //
99 // constants, enums and typedefs
100 //
101 
102 //
103 // static data member definitions
104 //
105 
106 //
107 // constructors and destructor
108 //
110 
111  // Get values from python cfg file
112  : vetoByRunEventNumber_ (iConfig.getParameter<bool>("vetoByRunEventNumber"))
113  , vetoByHBHEOccupancy_ (iConfig.getParameter<bool>("vetoByHBHEOccupancy"))
114  , minOccupiedHBHE_ (iConfig.getParameter<unsigned int>("minOccupiedHBHE"))
115  , vetoByLaserMonitor_ (iConfig.getParameter<bool>("vetoByLaserMonitor"))
116  , minLaserMonitorCharge_ (iConfig.getParameter<double>("minLaserMonitorCharge"))
117  , debug_ (iConfig.getParameter<bool>("debug"))
118  , reverseFilter_ (iConfig.getParameter<bool>("reverseFilter"))
119  , hbheInputLabel_ (iConfig.getUntrackedParameter<edm::InputTag>("hbheInputLabel",edm::InputTag("hbhereco")))
121  , hcalNoiseSummaryLabel_ (iConfig.getUntrackedParameter<edm::InputTag>("hcalNoiseSummaryLabel",edm::InputTag("hcalnoise")))
123  , taggingMode_ (iConfig.getParameter<bool>("taggingMode"))
124  , forceUseRecHitCollection_ (iConfig.getParameter<bool>("forceUseRecHitCollection"))
125  , forceUseHcalNoiseSummary_ (iConfig.getParameter<bool>("forceUseHcalNoiseSummary"))
126 
127 {
128 
129  std::vector<unsigned int> temprunevt = iConfig.getParameter<std::vector<unsigned int> >("BadRunEventNumbers");
130 
131  // Make (run,evt) pairs for storing bad events
132  // Make this a map for better search performance?
133  for (unsigned int i=0;i+1<temprunevt.size();i+=2)
134  {
135  edm::RunNumber_t run=temprunevt[i];
136  edm::EventNumber_t evt=temprunevt[i+1];
137  RunEventData_.push_back(std::make_pair(run,evt));
138  }
139  produces<bool>();
140 
141  // Specify the minimum release that has the rechit counts in the HcalNoiseSummary object.
142  // If current release >= that release, then HcalNoiseSummary will be used. Otherwise, Rechit collection will be used.
143  std::string minRelease="\"CMSSW_5_2_0\"";
144 
145  minVersion_=GetCMSSWVersion(minRelease);
146  std::vector <int> currentVersion=GetCMSSWVersion(edm::getReleaseVersion());
147 
148  if (IsGreaterThanMinCMSSWVersion(currentVersion)) // current Version is >= minVersion_
150  else
151  useHcalNoiseSummary_=false;
152 }
153 
154 
156 {
157 
158  // do anything here that needs to be done at desctruction time
159  // (e.g. close files, deallocate resources etc.)
160 
161 }
162 
163 
164 //
165 // member functions
166 //
167 
168 // ------------ method called on each new Event ------------
169 bool
171 {
172  using namespace edm;
173 
174  bool filterDecision=true;
175 
176  if (debug_) edm::LogInfo("HcalLaserEventFilter") <<"<HcalLaserEventFilter> Run = "<<iEvent.id().run()<<" Event = "<<iEvent.id().event();
177 
178  // Veto events by run/event numbers
180  {
181  for (unsigned int i=0;i<RunEventData_.size();++i)
182  {
183  if (iEvent.id().run()==RunEventData_[i].first &&
184  iEvent.id().event()==RunEventData_[i].second)
185  {
186  if (debug_) edm::LogInfo("HcalLaserEventFilter")<<"\t<HcalLaserEventFilter> Filtering bad event; Run "<<iEvent.id().run()<<" Event = "<<iEvent.id().event();
187  filterDecision=false;
188  break;
189  }
190  }
191  } // if (vetoByRunEventNumber_)
192 
193  //Veto events by HBHE rechit collection size
195  {
196  // The decision on whether or not to use the noise summary is made based on the CMSSW version.
197  // As of CMSSW_5_2_0, the HcalNoiseSummary contains the total number of HBHE hits, as well as number of hits > 1.5 GeV and some other info.
198  // The boolean 'forceUseRecHitCollection_' can be used to override this automatic behavior, and to use the RecHit collection itself, regardless of CMSSW version.
199 
200 
202  //
203  // Apply Filtering based on RecHit information in HBHERecHitcollection
204  //
206 
207 
209  {
211  if (iEvent.getByToken(hbheToken_,hbheRecHits))
212  {
213  if (debug_) edm::LogInfo("HcalLaserEventFilter") <<"Rechit size = "<<hbheRecHits->size()<<" threshold = "<<minOccupiedHBHE_;
214  if (hbheRecHits->size()>=minOccupiedHBHE_)
215  {
216  if (debug_) edm::LogInfo("HcalLaserEventFilter") <<"<HcalLaserEventFilter> Filtering because of large HBHE rechit size; "<<hbheRecHits->size()<<" rechits is greater than or equal to the allowed maximum of "<<minOccupiedHBHE_;
217  filterDecision=false;
218  }
219  }
220  else
221  {
222  if (debug_) edm::LogInfo("HcalLaserEventFilter") <<"<HcalLaserEventFilter::Error> No valid HBHERecHitCollection with label '"<<hbheInputLabel_<<"' found";
223  }
224  }
225 
227  //
228  // Apply Filtering based on RecHit information in HcalNoiseSummary object
229  //
231  else if (useHcalNoiseSummary_==true || forceUseHcalNoiseSummary_==true)
232  {
233  Handle<HcalNoiseSummary> hSummary;
234  if (iEvent.getByToken(hcalNoiseSummaryToken_,hSummary)) // get by label, usually with label 'hcalnoise'
235  {
236  if (debug_) edm::LogInfo("HcalLaserEventFilter") << " RECHIT SIZE (from HcalNoiseSummary) = "<<hSummary->GetRecHitCount()<<" threshold = "<<minOccupiedHBHE_;
237  if (hSummary->GetRecHitCount() >= (int)minOccupiedHBHE_)
238  {
239  if (debug_) edm::LogInfo("HcalLaserEventFilter") <<"<HcalLaserEventFilter> Filtering because of large HBHE rechit size in HcalNoiseSummary; "<<hSummary->GetRecHitCount()<<" rechits is greater than or equal to the allowed maximum of "<<minOccupiedHBHE_;
240  filterDecision=false;
241  }
242  }
243  else
244  {
245  if (debug_) edm::LogInfo("HcalLaserEventFilter") <<"<HcalLaserEventFilter::Error> No valid HcalNoiseSummary with label '"<<hcalNoiseSummaryLabel_<<"' found";
246  }
247  }
248  }// if (vetoByHBHEOccupancy_)
249  if( vetoByLaserMonitor_ )
250  {
252  //
253  // Apply Filtering based on laser monitor information in HcalNoiseSummary object
254  //
256  Handle<HcalNoiseSummary> hSummary;
257  if (iEvent.getByToken(hcalNoiseSummaryToken_,hSummary)) // get by label, usually with label 'hcalnoise'
258  {
259  if (debug_) edm::LogInfo("HcalLaserEventFilter") << " LASERMON CHARGE (from HcalNoiseSummary) = "<<hSummary->GetLaserMonitorCharge()<<" threshold = "<<minLaserMonitorCharge_;
260  if( hSummary->GetLaserMonitorCharge() > minLaserMonitorCharge_ )
261  {
262  if (debug_) edm::LogInfo("HcalLaserEventFilter") <<"<HcalLaserEventFilter> Filtering because of large Laser monitor charge in HcalNoiseSummary; "<<hSummary->GetLaserMonitorCharge()<<" charge is greater than or equal to the allowed maximum of "<<minLaserMonitorCharge_;
263  filterDecision=false;
264  }
265  }
266  else
267  {
268  if (debug_) edm::LogInfo("HcalLaserEventFilter") <<"<HcalLaserEventFilter::Error> No valid HcalNoiseSummary with label '"<<hcalNoiseSummaryLabel_<<"' found";
269  }
270  }
271 
272  // Reverse decision, if specified by user
273  if (reverseFilter_)
274  filterDecision=!filterDecision;
275 
276  iEvent.put(std::make_unique<bool>(filterDecision));
277 
278  return taggingMode_ || filterDecision;
279 }
280 
281 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
282 void
284  //The following says we do not know what parameters are allowed so do no validation
285  // Please change this to state exactly what you do use, even if it is no parameters
287 
288  desc.add<bool>("vetoByRunEventNumber",false)->
289  setComment("Enable filtering by run number");
290  desc.add<bool>("vetoByHBHEOccupancy",true)->
291  setComment("Enable occupancy filtering");
292  desc.add<unsigned int>("minOccupiedHBHE",4000)->
293  setComment("Minimum occupancy to filter events");
294  desc.add<bool>("vetoByLaserMonitor",true)->
295  setComment("Enable Laser monitoring filtering");
296  desc.add<double>("minLaserMonitorCharge",5000.)->
297  setComment("Set minimum laser monitor charge to filter events");
298  desc.add<bool>("debug",false)->
299  setComment("Enable debugging messages");
300  desc.add<bool>("reverseFilter",false)->
301  setComment("Invert filter decision");
302  desc.add<bool>("taggingMode", false)->
303  setComment("do not filter, just tag the event");
304  desc.add<bool>("forceUseRecHitCollection",false)->
305  setComment("force the evaluation using RecHit collection");
306  desc.add<bool>("forceUseHcalNoiseSummary",false)->
307  setComment("force the evaluation using Noise Summary");
308  desc.add<std::vector<unsigned int> >("BadRunEventNumbers",{})->
309  setComment("vector of bad events to filter");
310 
311  descriptions.add("hcallaserevent", desc);
312 }
313 
314 std::vector<int> HcalLaserEventFilter::GetCMSSWVersion(std::string const& instring) const
315 {
316  std::vector <int> temp;
317 
318 
320  std::string v1, v2, v3;
321 
322  std::istringstream oss(instring);
323  getline(oss, prefix,'_');
324  getline(oss, v1,'_');
325  getline(oss, v2,'_');
326  getline(oss, v3,'_');
327 
328  std::stringstream buffer(v1);
329  int t;
330  buffer>>t;
331  temp.push_back(t);
332  buffer.str();
333  buffer<<v2;
334  buffer>>t;
335  temp.push_back(t);
336  buffer.str();
337  buffer<<v3;
338  buffer>>t;
339  temp.push_back(t);
340 
341  //std::cout <<"PREFIX = "<<prefix<<" "<<temp[0]<<" "<<temp[1]<<" "<<temp[2]<<std::endl;
342  //( ex: PREFIX = "CMSSW 5 5 5 )
343  return temp;
344 }
345 
346 bool HcalLaserEventFilter::IsGreaterThanMinCMSSWVersion(std::vector<int> const& currentVersion) const
347 {
348  // Returns false if current version is less than min version
349  // Otherwise, returns true
350  // Assumes CMSSW versioning X_Y_Z
351 
352 
353 
354  // Compare X
355  if (currentVersion[0]<minVersion_[0]) return false;
356  if (currentVersion[0]>minVersion_[0]) return true;
357  // If neither is true, first value of CMSSW versions are the same
358 
359  // Compare Y
360  if (currentVersion[1]<minVersion_[1]) return false;
361  if (currentVersion[1]>minVersion_[1]) return true;
362 
363  // Compare Z
364  if (currentVersion[2]<minVersion_[2]) return false;
365  if (currentVersion[2]>minVersion_[2]) return true;
366 
367  return true; // versions are identical
368 }
369 
370 
371 //define this as a plug-in
edm::EDGetTokenT< HBHERecHitCollection > hbheToken_
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::EDGetTokenT< HcalNoiseSummary > hcalNoiseSummaryToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const edm::InputTag hcalNoiseSummaryLabel_
const edm::InputTag hbheInputLabel_
HcalLaserEventFilter(const edm::ParameterSet &)
unsigned long long EventNumber_t
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const double minLaserMonitorCharge_
bool IsGreaterThanMinCMSSWVersion(std::vector< int > const &) const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::string getReleaseVersion()
std::vector< int > minVersion_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:59
std::vector< std::pair< edm::RunNumber_t, edm::EventNumber_t > > RunEventData_
HLT enums.
double GetLaserMonitorCharge(void) const
const unsigned int minOccupiedHBHE_
size_type size() const
unsigned int RunNumber_t
std::vector< int > GetCMSSWVersion(std::string const &) const
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
int GetRecHitCount(void) const