CMS 3D CMS Logo

FindCaloHitCone.cc
Go to the documentation of this file.
6 #include <iostream>
7 
8 namespace spr {
9 
10 
11  //Ecal Endcap OR Barrel RecHits
12  std::vector<EcalRecHitCollection::const_iterator> findCone(const CaloGeometry* geo, edm::Handle<EcalRecHitCollection>& hits, const GlobalPoint& hpoint1, const GlobalPoint& point1, double dR, const GlobalVector& trackMom, bool debug) {
13 
14  std::vector<EcalRecHitCollection::const_iterator> hit;
15 
17  j!=hits->end(); j++) {
18 
19  bool keepHit = false;
20 
21  if (j->id().subdetId() == EcalEndcap) {
22  EEDetId EEid = EEDetId(j->id());
23  const GlobalPoint & rechitPoint = geo->getPosition(EEid);
24  if (spr::getDistInPlaneTrackDir(point1, trackMom, rechitPoint, debug) < dR) keepHit = true;
25  } else if (j->id().subdetId() == EcalBarrel) {
26  EBDetId EBid = EBDetId(j->id());
27  const GlobalPoint & rechitPoint = geo->getPosition(EBid);
28  if (spr::getDistInPlaneTrackDir(point1, trackMom, rechitPoint, debug) < dR) keepHit = true;
29  }
30 
31  if (keepHit) hit.push_back(j);
32  }
33  return hit;
34  }
35 
36  // Ecal Endcap AND Barrel RecHits
37  std::vector<EcalRecHitCollection::const_iterator> findCone(const CaloGeometry* geo, edm::Handle<EcalRecHitCollection>& barrelhits, edm::Handle<EcalRecHitCollection>& endcaphits, const GlobalPoint& hpoint1, const GlobalPoint& point1, double dR, const GlobalVector& trackMom, bool debug) {
38 
39  std::vector<EcalRecHitCollection::const_iterator> hit;
40 
41  // Only check both barrel and endcap when track is near transition
42  // region: 1.479-2*0.087 < trkEta < 1.479+2*0.087
43 
44  bool doBarrel=false, doEndcap=false;
45  if ( std::abs(point1.eta()) < (spr::etaBEEcal+2*spr::deltaEta)) doBarrel=true; // 1.479+2*0.087
46  if ( std::abs(point1.eta()) > (spr::etaBEEcal-2*spr::deltaEta)) doEndcap=true; // 1.479-2*0.087
47 
48  if (doBarrel) {
49  for (EcalRecHitCollection::const_iterator j=barrelhits->begin();
50  j!=barrelhits->end(); j++) {
51 
52  bool keepHit = false;
53  if (j->id().subdetId() == EcalBarrel) {
54  EBDetId EBid = EBDetId(j->id());
55  const GlobalPoint & rechitPoint = geo->getPosition(EBid);
56  if (spr::getDistInPlaneTrackDir(point1, trackMom, rechitPoint, debug) < dR) keepHit = true;
57  } else {
58  std::cout << "PROBLEM : Endcap RecHits in Barrel Collection!?"
59  << std::endl;
60  }
61  if (keepHit) hit.push_back(j);
62  }
63  } // doBarrel
64 
65  if (doEndcap) {
66 
67  for (EcalRecHitCollection::const_iterator j=endcaphits->begin();
68  j!=endcaphits->end(); j++) {
69 
70  bool keepHit = false;
71 
72  if (j->id().subdetId() == EcalEndcap) {
73  EEDetId EEid = EEDetId(j->id());
74  const GlobalPoint & rechitPoint = geo->getPosition(EEid);
75  if (spr::getDistInPlaneTrackDir(point1, trackMom, rechitPoint, debug) < dR) keepHit = true;
76  } else {
77  std::cout << "PROBLEM : Barrel RecHits in Endcap Collection!?"
78  << std::endl;
79  }
80  if (keepHit) hit.push_back(j);
81  }
82  } // doEndcap
83 
84  return hit;
85  }
86 
87 
88  //HBHE RecHits
89  std::vector<HBHERecHitCollection::const_iterator> findCone(const CaloGeometry* geo, edm::Handle<HBHERecHitCollection>& hits, const GlobalPoint& hpoint1, const GlobalPoint& point1, double dR, const GlobalVector& trackMom, bool debug) {
90 
91  std::vector<HBHERecHitCollection::const_iterator> hit;
92  // Loop over Hcal RecHits
94  j!=hits->end(); j++) {
95  DetId detId(j->id());
96  const GlobalPoint rechitPoint =
97  (static_cast<const HcalGeometry*>(geo->getSubdetectorGeometry(detId)))->getPosition(detId);
98  if (spr::getDistInPlaneTrackDir(hpoint1, trackMom, rechitPoint, debug) < dR) hit.push_back(j);
99  }
100  return hit;
101  }
102 
103  // PCalo SimHits
104  std::vector<edm::PCaloHitContainer::const_iterator> findCone(const CaloGeometry* geo, edm::Handle<edm::PCaloHitContainer>& hits, const GlobalPoint& hpoint1, const GlobalPoint& point1, double dR, const GlobalVector& trackMom, bool debug) {
105 
106  std::vector<edm::PCaloHitContainer::const_iterator> hit;
107  edm::PCaloHitContainer::const_iterator ihit;
108  for (ihit=hits->begin(); ihit!=hits->end(); ihit++) {
109  DetId detId(ihit->id());
110  const GlobalPoint rechitPoint = (detId.det() == DetId::Hcal) ?
111  (static_cast<const HcalGeometry*>(geo->getSubdetectorGeometry(detId)))->getPosition(detId) : geo->getPosition(detId);
112  if (spr::getDistInPlaneTrackDir(hpoint1, trackMom, rechitPoint, debug) < dR) {
113  hit.push_back(ihit);
114  }
115  }
116  return hit;
117  }
118 
119 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:44
static const double etaBEEcal
Definition: CaloConstants.h:12
double getDistInPlaneTrackDir(const GlobalPoint &caloPoint, const GlobalVector &caloVector, const GlobalPoint &rechitPoint, bool debug=false)
Definition: FindDistCone.cc:12
std::vector< EcalRecHit >::const_iterator const_iterator
static const double deltaEta
Definition: CaloConstants.h:8
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:69
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const_iterator end() const
Definition: DetId.h:18
#define debug
Definition: HDRShower.cc:19
T eta() const
Definition: PV3DBase.h:76
std::vector< EcalRecHitCollection::const_iterator > findCone(const CaloGeometry *geo, edm::Handle< EcalRecHitCollection > &hits, const GlobalPoint &hpoint1, const GlobalPoint &point1, double dR, bool debug=false)
const_iterator begin() const