CMS 3D CMS Logo

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