CMS 3D CMS Logo

FindDistCone.cc
Go to the documentation of this file.
3 
4 #include <iostream>
5 
6 //#define EDM_ML_DEBUG
7 
8 namespace spr {
9 
10  // Cone clustering core
11  double getDistInPlaneTrackDir(const GlobalPoint& caloPoint,
12  const GlobalVector& caloVector,
13  const GlobalPoint& rechitPoint, bool
14 #ifdef EDM_ML_DEBUG
15  debug
16 #endif
17  ) {
18 
19  const GlobalVector caloIntersectVector(caloPoint.x(),
20  caloPoint.y(),
21  caloPoint.z()); //p
22 
23  const GlobalVector caloUnitVector = caloVector.unit();
24  const GlobalVector rechitVector(rechitPoint.x(),
25  rechitPoint.y(),
26  rechitPoint.z());
27  const GlobalVector rechitUnitVector = rechitVector.unit();
28  double dotprod_denominator = caloUnitVector.dot(rechitUnitVector);
29  double dotprod_numerator = caloUnitVector.dot(caloIntersectVector);
30  double rechitdist = dotprod_numerator/dotprod_denominator;
31  const GlobalVector effectiveRechitVector = rechitdist*rechitUnitVector;
32  const GlobalPoint effectiveRechitPoint(effectiveRechitVector.x(),
33  effectiveRechitVector.y(),
34  effectiveRechitVector.z());
35  GlobalVector distance_vector = effectiveRechitPoint-caloPoint;
36 #ifdef EDM_ML_DEBUG
37  if (debug) {
38  std::cout << "getDistInPlaneTrackDir: point " << caloPoint << " dirn "
39  << caloVector << " numerator " << dotprod_numerator
40  << " denominator " << dotprod_denominator << " distance "
41  << distance_vector.mag() << std::endl;
42  }
43 #endif
44  if (dotprod_denominator > 0. && dotprod_numerator > 0.) {
45  return distance_vector.mag();
46  } else {
47  return 999999.;
48  }
49  }
50 
51  // Not used, but here for reference
52  double getDistInCMatEcal(double eta1, double phi1, double eta2, double phi2, bool
53 #ifdef EDM_ML_DEBUG
54  debug
55 #endif
56  ) {
57 
58  double dR, Rec;
59  if (fabs(eta1)<spr::etaBEEcal) Rec=spr::rFrontEB;
60  else Rec=spr::zFrontEE;
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 #ifdef EDM_ML_DEBUG
70  if (debug) std::cout << "getDistInCMatEcal: between (" << eta1 << ", "
71  << phi1 << ") and (" << eta2 << ", " << phi2 << " is "
72  << dR << std::endl;
73 #endif
74  return dR;
75  }
76 
77 
78  // Not used, but here for reference
79  double getDistInCMatHcal(double eta1, double phi1, double eta2, double phi2, bool
80 #ifdef EDM_ML_DEBUG
81  debug
82 #endif
83  ) {
84 
85  // Radii and eta from Geometry/HcalCommonData/data/hcalendcapalgo.xml
86  // and Geometry/HcalCommonData/data/hcalbarrelalgo.xml
87 
88  double dR, Rec;
89  if (fabs(eta1)<spr::etaBEHcal) Rec=spr::rFrontHB;
90  else Rec=spr::zFrontHE;
91  double ce1=cosh(eta1);
92  double ce2=cosh(eta2);
93  double te1=tanh(eta1);
94  double te2=tanh(eta2);
95 
96  double z=cos(phi1-phi2)/ce1/ce2+te1*te2;
97  if(z!=0) dR=fabs(Rec*ce1*sqrt(1./z/z-1.));
98  else dR=999999.;
99  return dR;
100 #ifdef EDM_ML_DEBUG
101  if (debug) std::cout << "getDistInCMatHcal: between (" << eta1 << ", "
102  << phi1 << ") and (" << eta2 << ", " << phi2 << " is "
103  << dR << std::endl;
104 #endif
105  }
106 
107  void getEtaPhi(HBHERecHitCollection::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene, bool ) {
108 
109  RH_ieta.push_back(hit->id().ieta());
110  RH_iphi.push_back(hit->id().iphi());
111  RH_ene.push_back(hit->energy());
112  }
113 
114  void getEtaPhi(edm::PCaloHitContainer::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene, bool) {
115  // SimHit function not yet implemented.
116  RH_ieta.push_back(-9);
117  RH_iphi.push_back(-9);
118  RH_ene.push_back(-9.);
119  }
120 
121  void getEtaPhi(EcalRecHitCollection::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene, bool) {
122  // Ecal function not yet implemented.
123  RH_ieta.push_back(-9);
124  RH_iphi.push_back(-9);
125  RH_ene.push_back(-9.);
126  }
127 
128  void getEtaPhi(HBHERecHitCollection::const_iterator hit,int& ieta,int& iphi,
129  bool) {
130  ieta = hit->id().ieta();
131  iphi = hit->id().iphi();
132  }
133 
134  void getEtaPhi(edm::PCaloHitContainer::const_iterator hit,int& ieta,int& iphi,
135  bool){
136  DetId id = DetId(hit->id());
137  if (id.det() == DetId::Hcal) {
138  ieta = ((HcalDetId)(hit->id())).ieta();
139  iphi = ((HcalDetId)(hit->id())).iphi();
140  } else if (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel) {
141  ieta = ((EBDetId)(id)).ieta();
142  iphi = ((EBDetId)(id)).iphi();
143  } else {
144  ieta = 999;
145  iphi = 999;
146  }
147  }
148 
149  void getEtaPhi(EcalRecHitCollection::const_iterator hit,int& ieta,int& iphi,
150  bool) {
151  DetId id = hit->id();
152  if (id.subdetId() == EcalBarrel) {
153  ieta = ((EBDetId)(id)).ieta();
154  iphi = ((EBDetId)(id)).iphi();
155  } else {
156  ieta = 999;
157  iphi = 999;
158  }
159  }
160 
161  double getEnergy(HBHERecHitCollection::const_iterator hit, bool useRaw, bool) {
162  double energy = (useRaw) ? hit->eraw() : hit->energy();
163  return energy;
164  }
165 
166  double getEnergy(EcalRecHitCollection::const_iterator hit, bool, bool) {
167  return hit->energy();
168  }
169 
170  double getEnergy(edm::PCaloHitContainer::const_iterator hit, bool, bool) {
171  // This will not yet handle Ecal CaloHits!!
172  double samplingWeight = 1.;
173  // Hard coded sampling weights from JFH analysis of iso tracks
174  // Sept 2009.
175  DetId id = hit->id();
176  if (id.det() == DetId::Hcal) {
177  HcalDetId detId(id);
178  if (detId.subdet() == HcalBarrel)
179  samplingWeight = 114.1;
180  else if (detId.subdet() == HcalEndcap)
181  samplingWeight = 167.3;
182  else {
183  // ONLY protection against summing HO, HF simhits
184  return 0.;
185  }
186  }
187 
188  return samplingWeight*hit->energy();
189  }
190 
192  DetId detId(hit->id());
193  return geo->getPosition(detId);
194  }
195 
196  GlobalPoint getGpos(const CaloGeometry* geo,edm::PCaloHitContainer::const_iterator hit, bool) {
197  DetId detId(hit->id());
198  return geo->getPosition(detId);
199  }
200 
202  // Not tested for EcalRecHits!!
203  if (hit->id().subdetId() == EcalEndcap) {
204  EEDetId EEid = EEDetId(hit->id());
205  return geo->getPosition(EEid);
206  } else { // (hit->id().subdetId() == EcalBarrel)
207  EBDetId EBid = EBDetId(hit->id());
208  return geo->getPosition(EBid);
209  }
210  }
211 
213  double energy = (useRaw) ? hit->eraw() : hit->energy();
214  return energy;
215  }
216 
218  return hit->energy();
219  }
220 
221  double getRawEnergy(edm::PCaloHitContainer::const_iterator hit, bool) {
222  return hit->energy();
223  }
224 }
static const double etaBEEcal
Definition: CaloConstants.h:12
double getDistInCMatHcal(double eta1, double phi1, double eta2, double phi2, bool debug=false)
Definition: FindDistCone.cc:79
double getDistInPlaneTrackDir(const GlobalPoint &caloPoint, const GlobalVector &caloVector, const GlobalPoint &rechitPoint, bool debug=false)
Definition: FindDistCone.cc:11
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
static const double etaBEHcal
Definition: CaloConstants.h:15
static const double zFrontHE
Definition: CaloConstants.h:13
std::vector< T >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:63
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
static const double rFrontHB
Definition: CaloConstants.h:14
double getEnergy(HBHERecHitCollection::const_iterator hit, bool useRaw=false, bool debug=false)
double getRawEnergy(HBHERecHitCollection::const_iterator hit, bool useRaw=false)
static const double zFrontEE
Definition: CaloConstants.h:9
T mag() const
Definition: PV3DBase.h:67
#define EDM_ML_DEBUG
Definition: MPUnpacker.cc:1
double getDistInCMatEcal(double eta1, double phi1, double eta2, double phi2, bool debug=false)
Definition: FindDistCone.cc:52
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
static const double rFrontEB
Definition: CaloConstants.h:10
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:70
Vector3DBase unit() const
Definition: Vector3DBase.h:57
Definition: DetId.h:18
#define debug
Definition: HDRShower.cc:19
void getEtaPhi(HBHERecHitCollection::const_iterator hit, std::vector< int > &RH_ieta, std::vector< int > &RH_iphi, std::vector< double > &RH_ene, bool debug=false)
GlobalPoint getGpos(const CaloGeometry *geo, HBHERecHitCollection::const_iterator hit, bool debug=false)
T x() const
Definition: PV3DBase.h:62