CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDeadCellBoundaryEnergyFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalDeadCellBoundaryEnergyFilter
4 // Class: EcalDeadCellBoundaryEnergyFilter
5 //
20 //
21 // Original Author: Konstantinos Theofilatos, Ulla Gebbert and Christian Sander
22 // Created: Sat Nov 14 18:43:21 CET 2009
23 // $Id: EcalDeadCellBoundaryEnergyFilter.cc,v 1.1 2012/03/21 14:43:35 lhx Exp $
24 //
25 //
26 
27 
28 // system include files
29 #include <memory>
30 #include <fstream>
31 
32 // user include files
35 
38 
40 
46 
49 
57 
60 
62  public:
65 
66  private:
67  virtual void beginJob();
68  virtual bool filter(edm::Event&, const edm::EventSetup&);
69  virtual void endJob();
70 
71  // ----------member data ---------------------------
72  const int kMAX;
73 
76 
77  const std::string FilterAlgo_;
78  const bool taggingMode_;
79 
80  const bool skimGap_;
81  const bool skimDead_;
82 
84 
88 
89  vector<BoundaryInformation> v_enNeighboursGap_EB;
90  vector<BoundaryInformation> v_enNeighboursGap_EE;
91 
92  vector<BoundaryInformation> v_boundaryInfoDeadCells_EB;
93  vector<BoundaryInformation> v_boundaryInfoDeadCells_EE;
94 
97 
99 
103 
104  const bool enableGap_;
105  const bool debug_;
106 
107 };
108 
109 //
110 // static data member definitions
111 //
112 
113 //
114 // constructors and destructor
115 //
117  : kMAX (50)
118  //now do what ever initialization is needed
119  , EBRecHitsLabel_ (iConfig.getParameter<edm::InputTag> ("recHitsEB"))
120  , EERecHitsLabel_ (iConfig.getParameter<edm::InputTag> ("recHitsEE"))
121 
122  , FilterAlgo_ (iConfig.getUntrackedParameter<std::string> ("FilterAlgo", "TuningMode"))
123  , taggingMode_ (iConfig.getParameter<bool>("taggingMode"))
124  , skimGap_ (iConfig.getUntrackedParameter<bool> ("skimGap", false))
125  , skimDead_ (iConfig.getUntrackedParameter<bool> ("skimDead", false))
126  , cutBoundEnergyGapEE (iConfig.getUntrackedParameter<double> ("cutBoundEnergyGapEE"))
127  , cutBoundEnergyGapEB (iConfig.getUntrackedParameter<double> ("cutBoundEnergyGapEB"))
128  , cutBoundEnergyDeadCellsEB (iConfig.getUntrackedParameter<double> ("cutBoundEnergyDeadCellsEB"))
129  , cutBoundEnergyDeadCellsEE (iConfig.getUntrackedParameter<double> ("cutBoundEnergyDeadCellsEE"))
130 
131  , limitFilterToEB_ (iConfig.getUntrackedParameter<bool> ("limitFilterToEB", false))
132  , limitFilterToEE_ (iConfig.getUntrackedParameter<bool> ("limitFilterToEE", false))
133  , limitDeadCellToChannelStatusEB_ (iConfig.getParameter<vector<int> > ("limitDeadCellToChannelStatusEB"))
134  , limitDeadCellToChannelStatusEE_ (iConfig.getParameter<vector<int> > ("limitDeadCellToChannelStatusEE"))
135 
136  , enableGap_ (iConfig.getUntrackedParameter<bool> ("enableGap", false))
137  , debug_ (iConfig.getParameter<bool>("debug"))
138 {
139 
141 
142  i_EBDead = 0;
143  i_EEDead = 0;
144  i_EBGap = 0;
145  i_EEGap = 0;
146 
147  v_enNeighboursGap_EB.clear();
148  v_enNeighboursGap_EE.clear();
149  v_enNeighboursGap_EB.reserve(50);
150  v_enNeighboursGap_EE.reserve(50);
151 
152  v_boundaryInfoDeadCells_EB.reserve(50);
153  v_boundaryInfoDeadCells_EE.reserve(50);
156 
157  if (skimGap_ && debug_ ) cout << "Skim Gap!" << endl;
158  if (skimDead_ && debug_ ) cout << "Skim Dead!" << endl;
159 
160  if( debug_ ) cout << "Constructor EcalAnomalousEvent" << endl;
161 
162  produces<bool>();
163 
164  produces<AnomalousECALVariables> ("anomalousECALVariables");
165 }
166 
168  //cout << "destructor Filter" << endl;
169 }
170 
171 // ------------ method called on each new Event ------------
173  using namespace edm;
174 
175  //int eventno = (int) iEvent.eventAuxiliary().event();
176 
177  v_enNeighboursGap_EB.clear();
178  v_enNeighboursGap_EE.clear();
179 
182 
183  // Get the Ecal RecHits
188 
189  edm::ESHandle<CaloTopology> theCaloTopology;
190  iSetup.get<CaloTopologyRecord> ().get(theCaloTopology);
191 
193  iSetup.get<EcalChannelStatusRcd> ().get(ecalStatus);
194 
196  iSetup.get<CaloGeometryRecord> ().get(geometry);
197 
198 // int DeadChannelsCounterEB = 0;
199 // int DeadChannelsCounterEE = 0;
200 
201  i_EBDead = 0;
202  i_EEDead = 0;
203  i_EBGap = 0;
204  i_EEGap = 0;
205 
206  vector<DetId> sameFlagDetIds;
207 
208  bool pass = true;
209 
210  if (!limitFilterToEE_) {
211 
212  if (debug_)
213  cout << "process EB" << endl;
214 
215  for (EcalRecHitCollection::const_iterator hit = EBRecHits->begin(); hit != EBRecHits->end(); ++hit) {
216 
217  bool detIdAlreadyChecked = false;
218  DetId currDetId = (DetId) hit->id();
219  //add limitation to channel stati
220  EcalChannelStatus::const_iterator chit = ecalStatus->find(currDetId);
221  int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1;
222  if (status != 0)
223  continue;
224  bool passChannelLimitation = false;
225 
226  // check if hit has a dead neighbour
227  vector<int> deadNeighbourStati;
228  ebBoundaryCalc.checkRecHitHasDeadNeighbour(*hit, ecalStatus, deadNeighbourStati);
229 
230  for (int cs = 0; cs < (int) limitDeadCellToChannelStatusEB_.size(); ++cs) {
231  int channelAllowed = limitDeadCellToChannelStatusEB_[cs];
232 
233  for (vector<int>::iterator sit = deadNeighbourStati.begin(); sit != deadNeighbourStati.end(); ++sit) {
234  //cout << "Neighbouring dead channel with status: " << *sit << endl;
235  if (channelAllowed == *sit || (channelAllowed < 0 && abs(channelAllowed) <= *sit)) {
236  passChannelLimitation = true;
237  break;
238  }
239  }
240  }
241 
242  for (vector<DetId>::iterator it = sameFlagDetIds.begin(); it != sameFlagDetIds.end(); it++) {
243  if (currDetId == *it)
244  detIdAlreadyChecked = true;
245  }
246 
247  // RecHit is at EB boundary and should be processed
248  if (!detIdAlreadyChecked && deadNeighbourStati.size() == 0 && ebBoundaryCalc.checkRecHitHasInvalidNeighbour(
249  *hit, ecalStatus)) {
250 
251  if (debug_)
254  (const edm::Handle<EcalRecHitCollection>&) EBRecHits, (const EcalRecHit *) &(*hit), theCaloTopology,
255  ecalStatus, geometry);
256 
257  // get rechits along gap cluster
258  for (vector<DetId>::iterator it = gapinfo.detIds.begin(); it != gapinfo.detIds.end(); it++) {
259  sameFlagDetIds.push_back(*it);
260  }
261 
262  if (gapinfo.boundaryEnergy > cutBoundEnergyGapEB) {
263 
264  i_EBGap++;
265  v_enNeighboursGap_EB.push_back(gapinfo);
266 
267  if (debug_)
268  cout << "EB: gap cluster energy: " << gapinfo.boundaryEnergy << " deadCells: "
269  << gapinfo.detIds.size() << endl;
270  }
271  }
272 
273  // RecHit is member of boundary and should be processed
274  if (!detIdAlreadyChecked && (passChannelLimitation || (limitDeadCellToChannelStatusEB_.size() == 0
275  && deadNeighbourStati.size() > 0))) {
276 
277  if (debug_)
280  (const edm::Handle<EcalRecHitCollection>&) EBRecHits, (const EcalRecHit *) &(*hit), theCaloTopology,
281  ecalStatus, geometry);
282 
283  // get boundary of !kDead rechits arround the dead cluster
284  for (vector<DetId>::iterator it = boundinfo.detIds.begin(); it != boundinfo.detIds.end(); it++) {
285  sameFlagDetIds.push_back(*it);
286  }
287 
288  if (boundinfo.boundaryEnergy > cutBoundEnergyDeadCellsEB) {
289 
290  i_EBDead++;
291  v_boundaryInfoDeadCells_EB.push_back(boundinfo);
292 
293  if (debug_)
294  cout << "EB: boundary Energy dead RecHit: " << boundinfo.boundaryEnergy << " ET: "
295  << boundinfo.boundaryET << " deadCells: " << boundinfo.detIds.size() << endl;
296  }
297 
298  }
299  }
300 
301  }
302 
303  sameFlagDetIds.clear();
304 
305  if (!limitFilterToEB_) {
306 
307  if (debug_)
308  cout << "process EE" << endl;
309 
310  for (EcalRecHitCollection::const_iterator hit = EERecHits->begin(); hit != EERecHits->end(); ++hit) {
311 
312  bool detIdAlreadyChecked = false;
313  DetId currDetId = (DetId) hit->id();
314  //add limitation to channel stati
315  EcalChannelStatus::const_iterator chit = ecalStatus->find(currDetId);
316  int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1;
317  if (status != 0)
318  continue;
319  bool passChannelLimitation = false;
320 
321  // check if hit has a dead neighbour
322  vector<int> deadNeighbourStati;
323  eeBoundaryCalc.checkRecHitHasDeadNeighbour(*hit, ecalStatus, deadNeighbourStati);
324 
325  for (int cs = 0; cs < (int) limitDeadCellToChannelStatusEE_.size(); ++cs) {
326  int channelAllowed = limitDeadCellToChannelStatusEE_[cs];
327 
328  for (vector<int>::iterator sit = deadNeighbourStati.begin(); sit != deadNeighbourStati.end(); ++sit) {
329  //cout << "Neighbouring dead channel with status: " << *sit << endl;
330  if (channelAllowed == *sit || (channelAllowed < 0 && abs(channelAllowed) <= *sit)) {
331  passChannelLimitation = true;
332  break;
333  }
334  }
335  }
336 
337  for (vector<DetId>::iterator it = sameFlagDetIds.begin(); it != sameFlagDetIds.end(); it++) {
338  if (currDetId == *it)
339  detIdAlreadyChecked = true;
340  }
341 
342  // RecHit is at EE boundary and should be processed
343  const CaloSubdetectorGeometry* subGeom = geometry->getSubdetectorGeometry(currDetId);
344  const CaloCellGeometry* cellGeom = subGeom->getGeometry(currDetId);
345  double eta = cellGeom->getPosition().eta();
346 
347  if (!detIdAlreadyChecked && deadNeighbourStati.size() == 0 && eeBoundaryCalc.checkRecHitHasInvalidNeighbour(
348  *hit, ecalStatus) && abs(eta) < 1.6) {
349 
350  if (debug_)
353  (const edm::Handle<EcalRecHitCollection>&) EERecHits, (const EcalRecHit *) &(*hit), theCaloTopology,
354  ecalStatus, geometry);
355 
356  // get rechits along gap cluster
357  for (vector<DetId>::iterator it = gapinfo.detIds.begin(); it != gapinfo.detIds.end(); it++) {
358  sameFlagDetIds.push_back(*it);
359  }
360 
361  if (gapinfo.boundaryEnergy > cutBoundEnergyGapEE) {
362 
363  i_EEGap++;
364  v_enNeighboursGap_EE.push_back(gapinfo);
365 
366  if (debug_)
367  cout << "EE: gap cluster energy: " << gapinfo.boundaryEnergy << " deadCells: "
368  << gapinfo.detIds.size() << endl;
369  }
370  }
371 
372  // RecHit is member of boundary and should be processed
373  if (!detIdAlreadyChecked && (passChannelLimitation || (limitDeadCellToChannelStatusEE_.size() == 0
374  && deadNeighbourStati.size() > 0))) {
375 
376  if (debug_)
379  (const edm::Handle<EcalRecHitCollection>&) EERecHits, (const EcalRecHit *) &(*hit), theCaloTopology,
380  ecalStatus, geometry);
381 
382  // get boundary of !kDead rechits arround the dead cluster
383  for (vector<DetId>::iterator it = boundinfo.detIds.begin(); it != boundinfo.detIds.end(); it++) {
384  sameFlagDetIds.push_back(*it);
385  }
386 
387  if (boundinfo.boundaryEnergy > cutBoundEnergyDeadCellsEE) {
388 
389  i_EEDead++;
390  v_boundaryInfoDeadCells_EE.push_back(boundinfo);
391 
392  if (debug_)
393  cout << "EE: boundary Energy dead RecHit: " << boundinfo.boundaryEnergy << " ET: "
394  << boundinfo.boundaryET << " deadCells: " << boundinfo.detIds.size() << endl;
395 
396  // for (vector<DetId>::iterator it = boundinfo.detIds.begin(); it != boundinfo.detIds.end(); it++) {
397  // cout << (EEDetId) * it << endl;
398  // }
399 
400  }
401 
402  }
403  }
404 
405  }
406 
407  sameFlagDetIds.clear();
408 
409  std::auto_ptr<AnomalousECALVariables> pAnomalousECALVariables(new AnomalousECALVariables(v_enNeighboursGap_EB,
411 
412 
413  bool isGap = pAnomalousECALVariables->isGapEcalCluster(cutBoundEnergyGapEB, cutBoundEnergyGapEE);
414  bool isBoundary = pAnomalousECALVariables->isDeadEcalCluster(maxBoundaryEnergy_, limitDeadCellToChannelStatusEB_,
416  pass = (!isBoundary && ((!isGap && enableGap_) || !enableGap_));
417 
418  iEvent.put(pAnomalousECALVariables, "anomalousECALVariables");
419 
420  iEvent.put( std::auto_ptr<bool>(new bool(pass)) );
421 
422  if( taggingMode_ ){
423  if (skimDead_ && (i_EBDead >= 1 || i_EEDead >= 1)) {
424  return true;
425  } else if (skimGap_ && (i_EBGap >= 1 || i_EEGap >= 1)) {
426  return true;
427  } else if (!skimDead_ && !skimGap_)
428  return true;
429  else {
430  return false;
431  }
432  }
433  else return pass;
434 
435 /*
436  if (FilterAlgo_ == "TuningMode") {
437  std::auto_ptr<AnomalousECALVariables> pAnomalousECALVariables(new AnomalousECALVariables(v_enNeighboursGap_EB,
438  v_enNeighboursGap_EE, v_boundaryInfoDeadCells_EB, v_boundaryInfoDeadCells_EE));
439  iEvent.put(pAnomalousECALVariables, "anomalousECALVariables");
440 
441  if (skimDead_ && (i_EBDead >= 1 || i_EEDead >= 1)) {
442  return true;
443  } else if (skimGap_ && (i_EBGap >= 1 || i_EEGap >= 1)) {
444  return true;
445  } else if (!skimDead_ && !skimGap_)
446  return true;
447  else {
448  return false;
449  }
450  }
451 
452  if (FilterAlgo_ == "FilterMode") {
453  std::auto_ptr<AnomalousECALVariables> pAnomalousECALVariables(new AnomalousECALVariables(v_enNeighboursGap_EB,
454  v_enNeighboursGap_EE, v_boundaryInfoDeadCells_EB, v_boundaryInfoDeadCells_EE));
455 
456  bool isGap = pAnomalousECALVariables->isGapEcalCluster(cutBoundEnergyGapEB, cutBoundEnergyGapEE);
457  bool isBoundary = pAnomalousECALVariables->isDeadEcalCluster(maxBoundaryEnergy_, limitDeadCellToChannelStatusEB_,
458  limitDeadCellToChannelStatusEE_);
459 
460  bool result = (!isBoundary && ((!isGap && enableGap_) || !enableGap_));
461  if (!result) {
462  }
463  return result;
464  }
465 */
466 
467 // return true;
468 }
469 
470 // ------------ method called once each job just before starting event loop ------------
472 }
473 
474 // ------------ method called once each job just after ending the event loop ------------
476 }
477 
478 //define this as a plug-in
EcalBoundaryInfoCalculator< EBDetId > ebBoundaryCalc
auto_ptr< ClusterSequence > cs
BoundaryInformation gapRecHits(const edm::Handle< EcalRecHitCollection > &, const EcalRecHit *, const edm::ESHandle< CaloTopology > theCaloTopology, const edm::ESHandle< EcalChannelStatus > ecalStatus, const edm::ESHandle< CaloGeometry > geometry)
vector< BoundaryInformation > v_enNeighboursGap_EB
BoundaryInformation boundaryRecHits(const edm::Handle< EcalRecHitCollection > &, const EcalRecHit *, const edm::ESHandle< CaloTopology > theCaloTopology, const edm::ESHandle< EcalChannelStatus > ecalStatus, const edm::ESHandle< CaloGeometry > geometry)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< EcalRecHit >::const_iterator const_iterator
vector< BoundaryInformation > v_enNeighboursGap_EE
#define abs(x)
Definition: mlp_lapack.h:159
vector< BoundaryInformation > v_boundaryInfoDeadCells_EB
T eta() const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
EcalBoundaryInfoCalculator< EEDetId > eeBoundaryCalc
bool checkRecHitHasInvalidNeighbour(const EcalRecHit hit, const edm::ESHandle< EcalChannelStatus > ecalStatus)
int iEvent
Definition: GenABIO.cc:243
EcalDeadCellBoundaryEnergyFilter(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
std::vector< DetId > detIds
bool checkRecHitHasDeadNeighbour(const EcalRecHit hit, const edm::ESHandle< EcalChannelStatus > ecalStatus, vector< int > &stati)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
unsigned int id
Definition: DetId.h:20
vector< BoundaryInformation > v_boundaryInfoDeadCells_EE
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
virtual bool filter(edm::Event &, const edm::EventSetup &)
T eta() const
Definition: PV3DBase.h:75
ESHandle< TrackerGeometry > geometry
tuple cout
Definition: gather_cfg.py:121
tuple status
Definition: ntuplemaker.py:245