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