CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FindDistCone.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 namespace spr {
6 
7  // Cone clustering core
8  double getDistInPlaneTrackDir(const GlobalPoint& caloPoint, const GlobalVector& caloVector, const GlobalPoint& rechitPoint) {
9 
10  const GlobalVector caloIntersectVector(caloPoint.x(),
11  caloPoint.y(),
12  caloPoint.z()); //p
13 
14  const GlobalVector caloUnitVector = caloVector.unit();
15  const GlobalVector rechitVector(rechitPoint.x(),
16  rechitPoint.y(),
17  rechitPoint.z());
18  const GlobalVector rechitUnitVector = rechitVector.unit();
19  double dotprod_denominator = caloUnitVector.dot(rechitUnitVector);
20  double dotprod_numerator = caloUnitVector.dot(caloIntersectVector);
21  double rechitdist = dotprod_numerator/dotprod_denominator;
22  const GlobalVector effectiveRechitVector = rechitdist*rechitUnitVector;
23  const GlobalPoint effectiveRechitPoint(effectiveRechitVector.x(),
24  effectiveRechitVector.y(),
25  effectiveRechitVector.z());
26  GlobalVector distance_vector = effectiveRechitPoint-caloPoint;
27  if (dotprod_denominator > 0. && dotprod_numerator > 0.) {
28  return distance_vector.mag();
29  } else {
30  return 999999.;
31  }
32  }
33 
34  // Not used, but here for reference
35  double getDistInCMatEcal(double eta1, double phi1, double eta2, double phi2){
36 
37  double dR, Rec;
38  if (fabs(eta1)<1.479) Rec=129;
39  else Rec=317;
40  double ce1=cosh(eta1);
41  double ce2=cosh(eta2);
42  double te1=tanh(eta1);
43  double te2=tanh(eta2);
44 
45  double z=cos(phi1-phi2)/ce1/ce2+te1*te2;
46  if(z!=0) dR=fabs(Rec*ce1*sqrt(1./z/z-1.));
47  else dR=999999.;
48  return dR;
49  }
50 
51 
52  // Not used, but here for reference
53  double getDistInCMatHcal(double eta1, double phi1, double eta2, double phi2){
54 
55  // Radii and eta from Geometry/HcalCommonData/data/hcalendcapalgo.xml
56  // and Geometry/HcalCommonData/data/hcalbarrelalgo.xml
57 
58  double dR, Rec;
59  if (fabs(eta1)<1.392) Rec=177.5;
60  else Rec=391.95;
61  double ce1=cosh(eta1);
62  double ce2=cosh(eta2);
63  double te1=tanh(eta1);
64  double te2=tanh(eta2);
65 
66  double z=cos(phi1-phi2)/ce1/ce2+te1*te2;
67  if(z!=0) dR=fabs(Rec*ce1*sqrt(1./z/z-1.));
68  else dR=999999.;
69  return dR;
70  }
71 
72  void getEtaPhi(HBHERecHitCollection::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene) {
73 
74  RH_ieta.push_back(hit->id().ieta());
75  RH_iphi.push_back(hit->id().iphi());
76  RH_ene.push_back(hit->energy());
77  }
78 
79  void getEtaPhi(edm::PCaloHitContainer::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene) {
80  // SimHit function not yet implemented.
81  RH_ieta.push_back(-9);
82  RH_iphi.push_back(-9);
83  RH_ene.push_back(-9.);
84  }
85 
86  void getEtaPhi(EcalRecHitCollection::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene) {
87  // Ecal function not yet implemented.
88  RH_ieta.push_back(-9);
89  RH_iphi.push_back(-9);
90  RH_ene.push_back(-9.);
91  }
92 
93  void getEtaPhi(HBHERecHitCollection::const_iterator hit,int& ieta,int& iphi){
94  ieta = hit->id().ieta();
95  iphi = hit->id().iphi();
96  }
97 
98  void getEtaPhi(edm::PCaloHitContainer::const_iterator hit,int& ieta,int& iphi){
99  DetId id = DetId(hit->id());
100  if (id.det() == DetId::Hcal) {
101  ieta = ((HcalDetId)(hit->id())).ieta();
102  iphi = ((HcalDetId)(hit->id())).iphi();
103  } else if (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel) {
104  ieta = ((EBDetId)(id)).ieta();
105  iphi = ((EBDetId)(id)).iphi();
106  } else {
107  ieta = 999;
108  iphi = 999;
109  }
110  }
111 
112  void getEtaPhi(EcalRecHitCollection::const_iterator hit,int& ieta,int& iphi){
113  DetId id = hit->id();
114  if (id.subdetId() == EcalBarrel) {
115  ieta = ((EBDetId)(id)).ieta();
116  iphi = ((EBDetId)(id)).iphi();
117  } else {
118  ieta = 999;
119  iphi = 999;
120  }
121  }
122 
124  return hit->energy();
125  }
126 
128  return hit->energy();
129  }
130 
131  double getEnergy(edm::PCaloHitContainer::const_iterator hit) {
132  // This will not yet handle Ecal CaloHits!!
133  double samplingWeight = 1.;
134  // Hard coded sampling weights from JFH analysis of iso tracks
135  // Sept 2009.
136  HcalDetId detId(hit->id());
137  if (detId.subdet() == HcalBarrel)
138  samplingWeight = 114.1;
139  else if (detId.subdet() == HcalEndcap)
140  samplingWeight = 167.3;
141  else {
142  // ONLY protection against summing HO, HF simhits
143  return 0.;
144  }
145 
146  return samplingWeight*hit->energy();
147  }
148 
150  DetId detId(hit->id());
151  return geo->getPosition(detId);
152  }
153 
154  GlobalPoint getGpos(const CaloGeometry* geo,edm::PCaloHitContainer::const_iterator hit) {
155  DetId detId(hit->id());
156  return geo->getPosition(detId);
157  }
158 
160  // Not tested for EcalRecHits!!
161  if (hit->id().subdetId() == EcalEndcap) {
162  EEDetId EEid = EEDetId(hit->id());
163  return geo->getPosition(EEid);
164  } else { // (hit->id().subdetId() == EcalBarrel)
165  EBDetId EBid = EBDetId(hit->id());
166  return geo->getPosition(EBid);
167  }
168  }
169 }
double getDistInPlaneTrackDir(const GlobalPoint &caloPoint, const GlobalVector &caloVector, const GlobalPoint &rechitPoint)
Definition: FindDistCone.cc:8
double getEnergy(HBHERecHitCollection::const_iterator hit)
std::vector< T >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:62
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
double double double z
double getDistInCMatHcal(double eta1, double phi1, double eta2, double phi2)
Definition: FindDistCone.cc:53
T mag() const
Definition: PV3DBase.h:66
T sqrt(T t)
Definition: SSEVec.h:46
T z() const
Definition: PV3DBase.h:63
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:68
GlobalPoint getGpos(const CaloGeometry *geo, HBHERecHitCollection::const_iterator hit)
Vector3DBase unit() const
Definition: Vector3DBase.h:57
Definition: DetId.h:20
double getDistInCMatEcal(double eta1, double phi1, double eta2, double phi2)
Definition: FindDistCone.cc:35
T x() const
Definition: PV3DBase.h:61
void getEtaPhi(HBHERecHitCollection::const_iterator hit, std::vector< int > &RH_ieta, std::vector< int > &RH_iphi, std::vector< double > &RH_ene)
Definition: FindDistCone.cc:72