CMS 3D CMS Logo

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