CMS 3D CMS Logo

HBHEIsolatedNoiseAlgos.cc
Go to the documentation of this file.
1 /*
2 Description: Isolation algorithms used to identify anomalous noise in the HB/HE.
3  These algorithms will be used to reflag HB/HE rechits as noise.
4 
5  There are 4 objects implemented here:
6  1) ObjectValidator
7  2) PhysicsTowerOrganizer
8  3) HBHEHitMap
9  4) HBHEHitMapOrganizer
10  See comments below for details.
11 
12 Original Author: John Paul Chou (Brown University)
13  Thursday, September 2, 2010
14 */
15 
17 
20 
29 
36 
38 //
39 // ObjectValidator
40 //
42 
44 {
45  HBThreshold_ = iConfig.getParameter<double>("HBThreshold");
46  HESThreshold_ = iConfig.getParameter<double>("HESThreshold");
47  HEDThreshold_ = iConfig.getParameter<double>("HEDThreshold");
48  EBThreshold_ = iConfig.getParameter<double>("EBThreshold");
49  EEThreshold_ = iConfig.getParameter<double>("EEThreshold");
50 
51  HcalAcceptSeverityLevel_ = iConfig.getParameter<uint32_t>("HcalAcceptSeverityLevel");
52  EcalAcceptSeverityLevel_ = iConfig.getParameter<uint32_t>("EcalAcceptSeverityLevel");
53  UseHcalRecoveredHits_ = iConfig.getParameter<bool>("UseHcalRecoveredHits");
54  UseEcalRecoveredHits_ = iConfig.getParameter<bool>("UseEcalRecoveredHits");
55  UseAllCombinedRechits_ = iConfig.getParameter<bool>("UseAllCombinedRechits");
56 
57  MinValidTrackPt_ = iConfig.getParameter<double>("MinValidTrackPt");
58  MinValidTrackPtBarrel_ = iConfig.getParameter<double>("MinValidTrackPtBarrel");
59  MinValidTrackNHits_ = iConfig.getParameter<int>("MinValidTrackNHits");
60 
61  theHcalChStatus_=nullptr;
62  theEcalChStatus_=nullptr;
63  theHcalSevLvlComputer_=nullptr;
64  theEcalSevLvlAlgo_=nullptr;
65  theEBRecHitCollection_=nullptr;
66  theEERecHitCollection_=nullptr;
67 
68  return;
69 }
70 
72 {
73 }
74 
76 {
77  assert(theHcalSevLvlComputer_!=nullptr && theHcalChStatus_!=nullptr);
78 
81  return true;
82 
83  // require the hit to pass a certain energy threshold
84  if(hit.id().subdet()==HcalBarrel && hit.energy()<HBThreshold_) return false;
85  else if(hit.id().subdet()==HcalEndcap && hit.id().ietaAbs()<=20 && hit.energy()<HESThreshold_) return false;
86  else if(hit.id().subdet()==HcalEndcap && hit.id().ietaAbs()>20 && hit.energy()<HEDThreshold_) return false;
87 
88  // determine if the hit is good, bad, or recovered
89  const DetId id = hit.detid();
90  const uint32_t recHitFlag = hit.flags();
91  const uint32_t dbStatusFlag = theHcalChStatus_->getValues(id)->getValue();
92  int severityLevel = theHcalSevLvlComputer_->getSeverityLevel(id, recHitFlag, dbStatusFlag);
93  bool isRecovered = theHcalSevLvlComputer_->recoveredRecHit(id, recHitFlag);
94 
95  if(severityLevel==0) return true;
96  if(isRecovered) return UseHcalRecoveredHits_;
97  if(severityLevel>static_cast<int>(HcalAcceptSeverityLevel_)) return false;
98  else return true;
99 }
100 
102 {
103  assert(theEcalSevLvlAlgo_!=nullptr && theEcalChStatus_!=nullptr);
104 
105  // require the hit to pass a certain energy threshold
106  const DetId id = hit.detid();
107  if(id.subdetId()==EcalBarrel && hit.energy()<EBThreshold_) return false;
108  else if(id.subdetId()==EcalEndcap && hit.energy()<EEThreshold_) return false;
109 
110  // determine if the hit is good, bad, or recovered
111  int severityLevel = 999;
112  if (id.subdetId() == EcalBarrel && theEBRecHitCollection_!=nullptr) severityLevel = theEcalSevLvlAlgo_->severityLevel(hit);//id, *theEBRecHitCollection_, *theEcalChStatus_, 5., EcalSeverityLevelAlgo::kSwissCross, 0.95, 2., 15., 0.999);
113  else if(id.subdetId() == EcalEndcap && theEERecHitCollection_!=nullptr) severityLevel = theEcalSevLvlAlgo_->severityLevel(hit);//id, *theEERecHitCollection_, *theEcalChStatus_, 5., EcalSeverityLevelAlgo::kSwissCross, 0.95, 2., 15., 0.999);
114  else return false;
115 
116  if(severityLevel == EcalSeverityLevel::kGood) return true;
117  if(severityLevel == EcalSeverityLevel::kRecovered) return UseEcalRecoveredHits_;
118  if(severityLevel > static_cast<int>(EcalAcceptSeverityLevel_)) return false;
119  else return true;
120 }
121 
123 {
124  if(trk.pt()<MinValidTrackPt_) return false;
125  if(trk.pt()<MinValidTrackPtBarrel_ && std::fabs(trk.momentum().eta())<1.479) return false;
126  if(trk.numberOfValidHits()<MinValidTrackNHits_) return false;
127  return true;
128 }
129 
131 //
132 // PhysicsTowerOrganizer
133 //
135 
137  const edm::EventSetup& evSetup,
138  const edm::Handle<HBHERecHitCollection>& hbhehitcoll_h,
139  const edm::Handle<EcalRecHitCollection>& ebhitcoll_h,
140  const edm::Handle<EcalRecHitCollection>& eehitcoll_h,
141  const edm::Handle<std::vector<reco::TrackExtrapolation> >& trackextrapcoll_h,
142  const ObjectValidatorAbs& objectvalidator,
143  const CaloTowerConstituentsMap& ctcm)
144 {
145  // get some geometries
147  evSetup.get<CaloGeometryRecord>().get(pG);
148  const CaloGeometry* geo = pG.product();
151 
152  // do the HCAL hits
153  for(HBHERecHitCollection::const_iterator it=hbhehitcoll_h->begin(); it!=hbhehitcoll_h->end(); ++it) {
154  const HBHERecHit* hit=&(*it);
155 
156  // check that the hit is valid
157  if(!objectvalidator.validHit(*hit)) continue;
158 
159  // add the hit to the organizer
160  CaloTowerDetId tid = ctcm.towerOf(hit->id());
161  insert_(tid, hit);
162  }
163 
164  // do the EB hits
165  for(EcalRecHitCollection::const_iterator it=ebhitcoll_h->begin(); it!=ebhitcoll_h->end(); ++it) {
166  const EcalRecHit* hit=&(*it);
167 
168  if(!objectvalidator.validHit(*hit)) continue;
169  CaloTowerDetId tid = ctcm.towerOf(hit->id());
170  insert_(tid, hit);
171  }
172 
173  // do the EE hits
174  for(EcalRecHitCollection::const_iterator it=eehitcoll_h->begin(); it!=eehitcoll_h->end(); ++it) {
175  const EcalRecHit* hit=&(*it);
176 
177  if(!objectvalidator.validHit(*hit)) continue;
178  CaloTowerDetId tid = ctcm.towerOf(hit->id());
179  insert_(tid, hit);
180  }
181 
182  // do the tracks
183  for(std::vector<reco::TrackExtrapolation>::const_iterator it=trackextrapcoll_h->begin(); it!=trackextrapcoll_h->end(); ++it) {
184  const reco::TrackExtrapolation* extrap=&(*it);
185  const reco::Track* track = &(*(extrap->track()));
186 
187  // validate track
188  if(!objectvalidator.validTrack(*track)) continue;
189 
190  // get the point
191  if ( extrap->positions().empty() ) continue;
192  const GlobalPoint point(extrap->positions().front().x(),
193  extrap->positions().front().y(),
194  extrap->positions().front().z());
195 
196 
197  if(std::fabs(point.eta())<1.479) {
198  EBDetId cell = gEB->getClosestCell(point);
199  CaloTowerDetId tid = ctcm.towerOf(cell);
200  insert_(tid, track);
201  } else {
202  EEDetId cell = gEE->getClosestCell(point);
203  CaloTowerDetId tid = ctcm.towerOf(cell);
204  insert_(tid, track);
205  }
206  }
207 
208  return;
209 }
210 
212 {
213  // create dummy PhysicsTower
215 
216  // correct for the merging of the |ieta|=28-29 towers
217  if(id.ietaAbs()==29) dummy.id = CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi());
218  else dummy.id=id;
219 
220  // search on the dummy
221  std::set<PhysicsTower, towercmp>::iterator it=towers_.find(dummy);
222 
223  if(it==towers_.end()) return nullptr;
224 
225  // for whatever reason, I can't get a non-const out of the find method
226  PhysicsTower &twr = const_cast<PhysicsTower&>(*it);
227  return &twr;
228 }
229 
231 {
232  // create dummy PhysicsTower
234 
235  // correct for the merging of the |ieta|=28-29 towers
236  if(id.ietaAbs()==29) dummy.id = CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi());
237  else dummy.id=id;
238 
239  // search on the dummy
240  std::set<PhysicsTower, towercmp>::iterator it=towers_.find(dummy);
241 
242  if(it==towers_.end()) return nullptr;
243  return &(*it);
244 }
245 
246 const PhysicsTower* PhysicsTowerOrganizer::findTower(int ieta, int iphi) const
247 {
248  CaloTowerDetId tid(ieta, iphi);
249  return findTower(tid);
250 }
251 
253 {
254  CaloTowerDetId tid(ieta, iphi);
255  return findTower(tid);
256 }
257 
258 void PhysicsTowerOrganizer::findNeighbors(const CaloTowerDetId& tempid, std::set<const PhysicsTower*>& neighbors) const
259 {
260  // correct for the merging of the |ieta|=28-29 towers
261  CaloTowerDetId id(tempid);
262  if(tempid.ietaAbs()==29) id = CaloTowerDetId((tempid.ietaAbs()-1)*tempid.zside(), tempid.iphi());
263 
264  std::vector<CaloTowerDetId> ids;
265  // get the neighbor with higher iphi
266  if(id.ietaAbs()<=20) {
267  if(id.iphi()==72) ids.push_back(CaloTowerDetId(id.ieta(), 1));
268  else ids.push_back(CaloTowerDetId(id.ieta(), id.iphi()+1));
269  } else {
270  if(id.iphi()==71) ids.push_back(CaloTowerDetId(id.ieta(), 1));
271  else ids.push_back(CaloTowerDetId(id.ieta(), id.iphi()+2));
272  }
273 
274  // get the neighbor with the lower iphi
275  if(id.ietaAbs()<=20) {
276  if(id.iphi()==1) ids.push_back(CaloTowerDetId(id.ieta(), 72));
277  else ids.push_back(CaloTowerDetId(id.ieta(), id.iphi()-1));
278  } else {
279  if(id.iphi()==1) ids.push_back(CaloTowerDetId(id.ieta(), 71));
280  else ids.push_back(CaloTowerDetId(id.ieta(), id.iphi()-2));
281  }
282 
283  // get the neighbor with the higher ietaAbs
284  if(id.ietaAbs()==20 && (id.iphi()%2)==0)
285  ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), id.iphi()-1));
286  else
287  ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), id.iphi()));
288 
289  // get the neighbor(s) with the lower ietaAbs
290  if(id.ietaAbs()==21) {
291  ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi()));
292  ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi()+1));
293  } else if(id.ietaAbs()==1) {
294  ids.push_back(CaloTowerDetId(-id.ieta(), id.iphi()));
295  } else {
296  ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi()));
297  }
298 
299  // get the neighbor with higher ieta and higher iphi
300  if(id.ietaAbs()<=19 || (id.ietaAbs()==20 && (id.iphi()%2)==0)) {
301  if(id.iphi()==72) ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), 1));
302  else ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), id.iphi()+1));
303  } else if(id.ietaAbs()>=21) {
304  if(id.iphi()==71) ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), 1));
305  else ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), id.iphi()+2));
306  }
307 
308  // get the neighbor with higher ieta and lower iphi
309  if(id.ietaAbs()<=19) {
310  if(id.iphi()==1) ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), 72));
311  else ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), id.iphi()-1));
312  } else if(id.ietaAbs()>=21 || (id.ietaAbs()==20 && (id.iphi()%2)==1)) {
313  if(id.iphi()==1) ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), 71));
314  else ids.push_back(CaloTowerDetId((id.ietaAbs()+1)*id.zside(), id.iphi()-2));
315  }
316 
317  // get the neighbor with lower ieta and higher iphi
318  if(id.ietaAbs()==1) {
319  if(id.iphi()==72) ids.push_back(CaloTowerDetId(-id.ieta(), 1));
320  else ids.push_back(CaloTowerDetId(-id.ieta(), id.iphi()+1));
321  } else if(id.ietaAbs()<=20) {
322  if(id.iphi()==72) ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), 1));
323  else ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi()+1));
324  } else if(id.ietaAbs()>=21) {
325  if(id.iphi()==71) ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), 1));
326  else ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi()+2));
327  }
328 
329  // get the neighbor with lower ieta and lower iphi
330  if(id.ietaAbs()==1) {
331  if(id.iphi()==1) ids.push_back(CaloTowerDetId(-id.ieta(), 72));
332  else ids.push_back(CaloTowerDetId(-id.ieta(), id.iphi()-1));
333  } else if(id.ietaAbs()<=20) {
334  if(id.iphi()==1) ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), 72));
335  else ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi()-1));
336  } else if(id.ietaAbs()>=22) {
337  if(id.iphi()==1) ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), 71));
338  else ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi()-2));
339  } else if(id.ietaAbs()==21) {
340  if(id.iphi()==1) ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), 72));
341  else ids.push_back(CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi()-1));
342  }
343 
344  // clear neighbors
345  neighbors.clear();
346 
347  // find the neighbors and add them to the eponymous set
348  for(std::vector<CaloTowerDetId>::const_iterator it=ids.begin(); it!=ids.end(); ++it) {
349  const PhysicsTower* twr=findTower(*it);
350  if(twr) neighbors.insert(twr);
351  }
352 
353  return;
354 }
355 
356 void PhysicsTowerOrganizer::findNeighbors(const PhysicsTower* twr, std::set<const PhysicsTower*>& neighbors) const
357 {
358  findNeighbors(twr->id, neighbors);
359  return;
360 }
361 
362 void PhysicsTowerOrganizer::findNeighbors(int ieta, int iphi, std::set<const PhysicsTower*>& neighbors) const
363 {
364  findNeighbors(CaloTowerDetId(ieta, iphi), neighbors);
365  return;
366 }
367 
369 {
370  PhysicsTower* twr=findTower(id);
371  if(twr==nullptr) {
373  if(id.ietaAbs()==29)
374  dummy.id = CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi());
375  else
376  dummy.id = id;
377  dummy.hcalhits.insert(hit);
378  towers_.insert(dummy);
379  } else {
380  twr->hcalhits.insert(hit);
381  }
382  return;
383 }
384 
386 {
387  PhysicsTower* twr=findTower(id);
388  if(twr==nullptr) {
390  if(id.ietaAbs()==29)
391  dummy.id = CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi());
392  else
393  dummy.id = id;
394  dummy.ecalhits.insert(hit);
395  towers_.insert(dummy);
396  } else {
397  twr->ecalhits.insert(hit);
398  }
399  return;
400 }
401 
403 {
404  PhysicsTower* twr=findTower(id);
405  if(twr==nullptr) {
407  if(id.ietaAbs()==29)
408  dummy.id = CaloTowerDetId((id.ietaAbs()-1)*id.zside(), id.iphi());
409  else
410  dummy.id = id;
411  dummy.tracks.insert(track);
412  towers_.insert(dummy);
413  } else {
414  twr->tracks.insert(track);
415  }
416  return;
417 }
418 
419 
421 //
422 // HBHEHitMap
423 //
425 
427 {
428  hitEnergy_=hitEnergyTrkFid_=-999.;
429  nHits_=-999;
430  hcalEnergySameTowers_=ecalEnergySameTowers_=trackEnergySameTowers_=-999.;
431  nHcalHitsSameTowers_=nEcalHitsSameTowers_=nTracksSameTowers_=-999;
432  hcalEnergyNeighborTowers_=ecalEnergyNeighborTowers_=trackEnergyNeighborTowers_=-999.;
433  nHcalHitsNeighborTowers_=nEcalHitsNeighborTowers_=nTracksNeighborTowers_=-999;
434 
435 }
436 
437 double HBHEHitMap::hitEnergy(void) const
438 {
439  if(hitEnergy_<-900) calcHits_();
440  return hitEnergy_;
441 }
442 
443 int HBHEHitMap::nHits(void) const
444 {
445  if(nHits_<-900) calcHits_();
446  return nHits_;
447 }
448 
450 {
451  if(hitEnergyTrkFid_<-900) calcHits_();
452  return hitEnergyTrkFid_;
453 }
454 
455 
457 {
458  if(hcalEnergySameTowers_<-900) calcHcalSameTowers_();
459  return hcalEnergySameTowers_;
460 }
461 
463 {
464  if(nHcalHitsSameTowers_<-900) calcHcalSameTowers_();
465  return nHcalHitsSameTowers_;
466 }
467 
469 {
470  if(ecalEnergySameTowers_<-900) calcEcalSameTowers_();
471  return ecalEnergySameTowers_;
472 }
473 
475 {
476  if(nEcalHitsSameTowers_<-900) calcEcalSameTowers_();
477  return nEcalHitsSameTowers_;
478 }
479 
481 {
482  if(trackEnergySameTowers_<-900) calcTracksSameTowers_();
483  return trackEnergySameTowers_;
484 }
485 
487 {
488  if(nTracksSameTowers_<-900) calcTracksSameTowers_();
489  return nTracksSameTowers_;
490 }
491 
492 void HBHEHitMap::hcalHitsSameTowers(std::set<const HBHERecHit*>& v) const
493 {
494  v.clear();
495  for(hitmap_const_iterator it1=beginHits(); it1!=endHits(); ++it1) {
496  for(std::set<const HBHERecHit*>::const_iterator it2=it1->second->hcalhits.begin(); it2!=it1->second->hcalhits.end(); ++it2) {
497  const HBHERecHit* hit=(*it2);
498  // if the hit in the tower is already in the hitmap, don't include it
499  if(findHit(hit)==endHits()) v.insert(hit);
500  }
501  }
502  return;
503 }
504 
505 void HBHEHitMap::ecalHitsSameTowers(std::set<const EcalRecHit*>& v) const
506 {
507  v.clear();
508  for(hitmap_const_iterator it1=beginHits(); it1!=endHits(); ++it1) {
509  v.insert(it1->second->ecalhits.begin(), it1->second->ecalhits.end());
510  }
511  return;
512 }
513 
514 void HBHEHitMap::tracksSameTowers(std::set<const reco::Track*>& v) const
515 {
516  v.clear();
517  for(hitmap_const_iterator it1=beginHits(); it1!=endHits(); ++it1) {
518  v.insert(it1->second->tracks.begin(), it1->second->tracks.end());
519  }
520  return;
521 }
522 
524 {
525  if(hcalEnergyNeighborTowers_<-900) calcHcalNeighborTowers_();
526  return hcalEnergyNeighborTowers_;
527 }
528 
530 {
531  if(nHcalHitsNeighborTowers_<-900) calcHcalNeighborTowers_();
532  return nHcalHitsNeighborTowers_;
533 }
534 
536 {
537  if(ecalEnergyNeighborTowers_<-900) calcEcalNeighborTowers_();
538  return ecalEnergyNeighborTowers_;
539 }
540 
542 {
543  if(nEcalHitsNeighborTowers_<-900) calcEcalNeighborTowers_();
544  return nEcalHitsNeighborTowers_;
545 }
546 
548 {
549  if(trackEnergyNeighborTowers_<-900) calcTracksNeighborTowers_();
550  return trackEnergyNeighborTowers_;
551 }
552 
554 {
555  if(nTracksNeighborTowers_<-900) calcTracksNeighborTowers_();
556  return nTracksNeighborTowers_;
557 }
558 
559 void HBHEHitMap::hcalHitsNeighborTowers(std::set<const HBHERecHit*>& v) const
560 {
561  v.clear();
562  for(neighbor_const_iterator it1=beginNeighbors(); it1!=endNeighbors(); ++it1) {
563  const PhysicsTower* twr=(*it1);
564  v.insert(twr->hcalhits.begin(), twr->hcalhits.end());
565  }
566  return;
567 }
568 
569 void HBHEHitMap::ecalHitsNeighborTowers(std::set<const EcalRecHit*>& v) const
570 {
571  v.clear();
572  for(neighbor_const_iterator it1=beginNeighbors(); it1!=endNeighbors(); ++it1) {
573  const PhysicsTower* twr=(*it1);
574  v.insert(twr->ecalhits.begin(), twr->ecalhits.end());
575  }
576 
577  return;
578 }
579 
580 void HBHEHitMap::tracksNeighborTowers(std::set<const reco::Track*>& v) const
581 {
582  v.clear();
583  for(neighbor_const_iterator it1=beginNeighbors(); it1!=endNeighbors(); ++it1) {
584  const PhysicsTower* twr=(*it1);
585  v.insert(twr->tracks.begin(), twr->tracks.end());
586  }
587  return;
588 }
589 
590 void HBHEHitMap::byTowers(std::vector<twrinfo>& v) const
591 {
592  assert(false);
593 }
594 
595 void HBHEHitMap::insert(const HBHERecHit* hit, const PhysicsTower* twr, std::set<const PhysicsTower*>& neighbors)
596 {
597  hits_[hit]=twr;
598  neighbors_.insert(neighbors.begin(), neighbors.end());
599 
600  // make sure none of the neighbors are also are part of the hitmap
601  for(hitmap_const_iterator it=beginHits(); it!=endHits(); ++it) {
602  const PhysicsTower* t=it->second;
603  neighbor_const_iterator find=findNeighbor(t);
604 
605  // if a hit is also a neighbor, remove the neighbor
606  if(find!=endNeighbors()) neighbors_.erase(find);
607  }
608  return;
609 }
610 
611 
612 void HBHEHitMap::calcHits_(void) const
613 {
614  hitEnergy_=0;
615  nHits_=0;
616  hitEnergyTrkFid_=0;
617  for(hitmap_const_iterator it=hits_.begin(); it!=hits_.end(); ++it) {
618  const HBHERecHit* hit=it->first;
619  if(hit->id().ietaAbs()<=26) hitEnergyTrkFid_+=hit->energy();
620  hitEnergy_+=hit->energy();
621  ++nHits_;
622  }
623  return;
624 }
625 
627 {
628  hcalEnergySameTowers_=0;
629  nHcalHitsSameTowers_=0;
630  std::set<const HBHERecHit*> v;
631  hcalHitsSameTowers(v);
632  for(std::set<const HBHERecHit*>::const_iterator it=v.begin(); it!=v.end(); ++it) {
633  const HBHERecHit* hit=(*it);
634  hcalEnergySameTowers_+=hit->energy();
635  ++nHcalHitsSameTowers_;
636  }
637  return;
638 }
639 
641 {
642  ecalEnergySameTowers_=0;
643  nEcalHitsSameTowers_=0;
644  std::set<const EcalRecHit*> v;
645  ecalHitsSameTowers(v);
646  for(std::set<const EcalRecHit*>::const_iterator it=v.begin(); it!=v.end(); ++it) {
647  const EcalRecHit* hit=(*it);
648  ecalEnergySameTowers_+=hit->energy();
649  ++nEcalHitsSameTowers_;
650  }
651  return;
652 }
653 
655 {
656  trackEnergySameTowers_=0;
657  nTracksSameTowers_=0;
658  std::set<const reco::Track*> v;
659  tracksSameTowers(v);
660  for(std::set<const reco::Track*>::const_iterator it=v.begin(); it!=v.end(); ++it) {
661  const reco::Track* trk=(*it);
662  trackEnergySameTowers_+=trk->p();
663  ++nTracksSameTowers_;
664  }
665  return;
666 }
667 
669 {
670  hcalEnergyNeighborTowers_=0;
671  nHcalHitsNeighborTowers_=0;
672  std::set<const HBHERecHit*> v;
673  hcalHitsNeighborTowers(v);
674  for(std::set<const HBHERecHit*>::const_iterator it=v.begin(); it!=v.end(); ++it) {
675  const HBHERecHit* hit=(*it);
676  hcalEnergyNeighborTowers_+=hit->energy();
677  ++nHcalHitsNeighborTowers_;
678  }
679  return;
680 }
681 
683 {
684  ecalEnergyNeighborTowers_=0;
685  nEcalHitsNeighborTowers_=0;
686  std::set<const EcalRecHit*> v;
687  ecalHitsNeighborTowers(v);
688  for(std::set<const EcalRecHit*>::const_iterator it=v.begin(); it!=v.end(); ++it) {
689  const EcalRecHit* hit=(*it);
690  ecalEnergyNeighborTowers_+=hit->energy();
691  ++nEcalHitsNeighborTowers_;
692  }
693  return;
694 }
695 
697 {
698  trackEnergyNeighborTowers_=0;
699  nTracksNeighborTowers_=0;
700  std::set<const reco::Track*> v;
701  tracksNeighborTowers(v);
702  for(std::set<const reco::Track*>::const_iterator it=v.begin(); it!=v.end(); ++it) {
703  const reco::Track* trk=(*it);
704  trackEnergyNeighborTowers_+=trk->p();
705  ++nTracksNeighborTowers_;
706  }
707  return;
708 }
709 
711 //
712 // HBHEHitMapOrganizer
713 //
715 
716 
718  const ObjectValidatorAbs& objvalidator,
719  const PhysicsTowerOrganizer& pto,
720  const HcalFrontEndMap* hfemap)
721  : hfemap_(hfemap)
722 {
723  // loop over the hits
724  for(HBHERecHitCollection::const_iterator it=hbhehitcoll_h->begin(); it!=hbhehitcoll_h->end(); ++it) {
725  const HBHERecHit *hit=&(*it);
726  if(!objvalidator.validHit(*hit)) continue;
727 
728  // get the Physics Tower and the neighbors
729  const PhysicsTower* tower=pto.findTower(hit->id().ieta(), hit->id().iphi());
730 
731  std::set<const PhysicsTower*> neighbors;
732  pto.findNeighbors(hit->id().ieta(), hit->id().iphi(), neighbors);
733 
734  // organize the RBXs
735  int rbxidnum = hfemap_->lookupRBXIndex(hit->id());
736  rbxs_[rbxidnum].insert(hit, tower, neighbors);
737 
738  // organize the HPDs
739  int hpdidnum = hfemap_->lookupRMIndex(hit->id());
740  hpds_[hpdidnum].insert(hit, tower, neighbors);
741 
742 
743  // organize the dihits
744  std::vector<const HBHERecHit*> hpdneighbors;
745  getHPDNeighbors(hit, hpdneighbors, pto);
746 
747  if(hpdneighbors.size()==1) {
748  std::vector<const HBHERecHit*> hpdneighborsneighbors;
749  getHPDNeighbors(hpdneighbors[0], hpdneighborsneighbors, pto);
750 
751  if(hpdneighborsneighbors.size()==1 && hpdneighborsneighbors[0]==hit && hit->energy()>hpdneighbors[0]->energy()) {
752  // we've found two hits who are neighbors in the same HPD, but who have no other
753  // neighbors (in the same HPD) in common. In order not to double-count, we
754  // require that the first hit has more energy
755 
756  const PhysicsTower* tower2=pto.findTower(hpdneighbors[0]->id().ieta(), hpdneighbors[0]->id().iphi());
757  std::set<const PhysicsTower*> neighbors2;
758  pto.findNeighbors(hpdneighbors[0]->id().ieta(), hpdneighbors[0]->id().iphi(), neighbors2);
759 
760  HBHEHitMap dihit;
761  dihit.insert(hit, tower, neighbors);
762  dihit.insert(hpdneighbors[0], tower2, neighbors2);
763  dihits_.push_back(dihit);
764  }
765  } else if(hpdneighbors.empty()) {
766 
767  // organize the monohits
768  HBHEHitMap monohit;
769  monohit.insert(hit, tower, neighbors);
770  monohits_.push_back(monohit);
771  }
772 
773  } // finished looping over HBHERecHits
774  return;
775 }
776 
777 void HBHEHitMapOrganizer::getRBXs(std::vector<HBHEHitMap>& v, double energy) const
778 {
779  for(std::map<int, HBHEHitMap>::const_iterator it=rbxs_.begin(); it!=rbxs_.end(); ++it) {
780  const HBHEHitMap &map=it->second;
781  if(map.hitEnergy()>energy) v.push_back(map);
782  }
783  return;
784 }
785 
786 void HBHEHitMapOrganizer::getHPDs(std::vector<HBHEHitMap>& v, double energy) const
787 {
788  for(std::map<int, HBHEHitMap>::const_iterator it=hpds_.begin(); it!=hpds_.end(); ++it) {
789  const HBHEHitMap &map=it->second;
790  if(map.hitEnergy()>energy) v.push_back(map);
791  }
792  return;
793 }
794 
795 void HBHEHitMapOrganizer::getDiHits(std::vector<HBHEHitMap>& v, double energy) const
796 {
797  for(std::vector<HBHEHitMap>::const_iterator it=dihits_.begin(); it!=dihits_.end(); ++it) {
798  if(it->hitEnergy()>energy) v.push_back(*it);
799  }
800  return;
801 }
802 
803 void HBHEHitMapOrganizer::getMonoHits(std::vector<HBHEHitMap>& v, double energy) const
804 {
805  for(std::vector<HBHEHitMap>::const_iterator it=monohits_.begin(); it!=monohits_.end(); ++it) {
806  if(it->hitEnergy()>energy) v.push_back(*it);
807  }
808  return;
809 }
810 
811 
812 
813 void HBHEHitMapOrganizer::getHPDNeighbors(const HBHERecHit* hit, std::vector<const HBHERecHit*>& neighbors, const PhysicsTowerOrganizer& pto)
814 {
815  std::set<const PhysicsTower*> temp;
816  pto.findNeighbors(hit->id().ieta(), hit->id().iphi(), temp);
817 
818  // make sure to include the same tower that the hit is in
819  temp.insert(pto.findTower(hit->id().ieta(), hit->id().iphi()));
820 
821  // loop over the rechits in the temp neighbors
822  for(std::set<const PhysicsTower*>::const_iterator it1=temp.begin(); it1!=temp.end(); ++it1) {
823  for(std::set<const HBHERecHit*>::const_iterator it2=(*it1)->hcalhits.begin(); it2!=(*it1)->hcalhits.end(); ++it2) {
824  const HBHERecHit* hit2(*it2);
825  if(hit!=hit2 && hfemap_->lookupRMIndex(hit->id())==hfemap_->lookupRMIndex(hit2->id())) {
826  neighbors.push_back(hit2);
827  }
828  }
829  }
830  return;
831 }
832 
833 
834 
constexpr float energy() const
Definition: CaloRecHit.h:31
void getHPDNeighbors(const HBHERecHit *hit, std::vector< const HBHERecHit * > &neighbors, const PhysicsTowerOrganizer &pto)
double p() const
momentum vector magnitude
Definition: TrackBase.h:648
double hcalEnergySameTowers(void) const
std::set< const HBHERecHit * > hcalhits
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
void tracksNeighborTowers(std::set< const reco::Track * > &v) const
int nHcalHitsSameTowers(void) const
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:146
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
std::vector< typename T::const_iterator > findHit(edm::Handle< T > &hits, DetId thisDet, bool debug=false)
std::map< const HBHERecHit *, const PhysicsTower * >::const_iterator hitmap_const_iterator
int ietaAbs() const
get the absolute value of the tower ieta
std::vector< HBHEHitMap > dihits_
constexpr const DetId & detid() const
Definition: CaloRecHit.h:35
void getHPDs(std::vector< HBHEHitMap > &v, double energy) const
HBHEHitMapOrganizer(const edm::Handle< HBHERecHitCollection > &hbhehitcoll_h, const ObjectValidatorAbs &objvalidator, const PhysicsTowerOrganizer &pto, const HcalFrontEndMap *hfemap)
HcalDetId id() const
get the id
Definition: HBHERecHit.h:42
uint32_t auxPhase1() const
Definition: HBHERecHit.h:57
const int lookupRMIndex(DetId fId) const
const DetId & detid() const
Definition: EcalRecHit.h:72
std::vector< T >::const_iterator const_iterator
virtual bool validTrack(const reco::Track &) const =0
int nEcalHitsNeighborTowers(void) const
const Item * getValues(DetId fId, bool throwOnFail=true) const
int zside(DetId const &)
void getRBXs(std::vector< HBHEHitMap > &v, double energy) const
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:708
ObjectValidator(const edm::ParameterSet &)
void ecalHitsNeighborTowers(std::set< const EcalRecHit * > &v) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void getMonoHits(std::vector< HBHEHitMap > &v, double energy) const
void ecalHitsSameTowers(std::set< const EcalRecHit * > &v) const
PhysicsTowerOrganizer(const edm::Event &iEvent, const edm::EventSetup &evSetup, const edm::Handle< HBHERecHitCollection > &hbhehitcoll_h, const edm::Handle< EcalRecHitCollection > &ebhitcoll_h, const edm::Handle< EcalRecHitCollection > &eehitcoll_h, const edm::Handle< std::vector< reco::TrackExtrapolation > > &trackextrapcoll_h, const ObjectValidatorAbs &objectvalidator, const CaloTowerConstituentsMap &ctcm)
void calcTracksSameTowers_(void) const
double ecalEnergyNeighborTowers(void) const
void insert(const HBHERecHit *hit, const PhysicsTower *twr, std::set< const PhysicsTower * > &neighbors)
const PhysicsTower * findTower(const CaloTowerDetId &id) const
void tracksSameTowers(std::set< const reco::Track * > &v) const
int iEvent
Definition: GenABIO.cc:224
const int lookupRBXIndex(DetId fId) const
int nHcalHitsNeighborTowers(void) const
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
void calcHcalSameTowers_(void) const
std::map< int, HBHEHitMap > rbxs_
double pt() const
track transverse momentum
Definition: TrackBase.h:654
const EcalChannelStatus * theEcalChStatus_
virtual bool validHit(const HBHERecHit &) const =0
bool recoveredRecHit(const DetId &myid, const uint32_t &myflag) const
const EcalRecHitCollection * theEERecHitCollection_
int ieta() const
get the cell ieta
Definition: HcalDetId.h:159
double hcalEnergyNeighborTowers(void) const
int iphi() const
get the tower iphi
double trackEnergySameTowers(void) const
void insert_(CaloTowerDetId &id, const HBHERecHit *hit)
float energy() const
Definition: EcalRecHit.h:68
bool validTrack(const reco::Track &) const override
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:889
const EcalRecHitCollection * theEBRecHitCollection_
std::set< const PhysicsTower * >::const_iterator neighbor_const_iterator
constexpr bool getBit(const uint32_t u, const unsigned bitnum)
std::map< int, HBHEHitMap > hpds_
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:154
const_iterator end() const
virtual DetId getClosestCell(const GlobalPoint &r) const
int iphi() const
get the cell iphi
Definition: HcalDetId.h:161
Definition: DetId.h:18
double hitEnergy(void) const
void calcEcalSameTowers_(void) const
DetId id() const
get the id
Definition: EcalRecHit.h:77
void calcTracksNeighborTowers_(void) const
void calcHcalNeighborTowers_(void) const
int zside() const
get the z-side of the tower (1/-1)
const EcalSeverityLevelAlgo * theEcalSevLvlAlgo_
int getSeverityLevel(const DetId &myid, const uint32_t &myflag, const uint32_t &mystatus) const
std::set< const EcalRecHit * > ecalhits
reco::TrackRef const & track() const
int nHits(void) const
double trackEnergyNeighborTowers(void) const
double hitEnergyTrackFiducial(void) const
T get() const
Definition: EventSetup.h:71
void calcHits_(void) const
std::set< const reco::Track * > tracks
void calcEcalNeighborTowers_(void) const
static const unsigned OFF_COMBINED
std::vector< HBHEHitMap > monohits_
bool validHit(const HBHERecHit &) const override
int nTracksSameTowers(void) const
void getDiHits(std::vector< HBHEHitMap > &v, double energy) const
std::vector< Point > const & positions() const
double ecalEnergySameTowers(void) const
const HcalChannelQuality * theHcalChStatus_
int nEcalHitsSameTowers(void) const
int nTracksNeighborTowers(void) const
uint32_t getValue() const
const HcalFrontEndMap * hfemap_
void hcalHitsSameTowers(std::set< const HBHERecHit * > &v) const
const HcalSeverityLevelComputer * theHcalSevLvlComputer_
T const * product() const
Definition: ESHandle.h:86
constexpr uint32_t flags() const
Definition: CaloRecHit.h:36
void byTowers(std::vector< twrinfo > &v) const
void findNeighbors(const CaloTowerDetId &id, std::set< const PhysicsTower * > &neighbors) const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
const_iterator begin() const
void hcalHitsNeighborTowers(std::set< const HBHERecHit * > &v) const