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, bool useRaw, bool) {
163  double energy = (useRaw) ? hit->eraw() : hit->energy();
164  return energy;
165  }
166 
167  double getEnergy(EcalRecHitCollection::const_iterator hit, bool, bool) {
168  return hit->energy();
169  }
170 
171  double getEnergy(edm::PCaloHitContainer::const_iterator hit, bool, bool) {
172  // This will not yet handle Ecal CaloHits!!
173  double samplingWeight = 1.;
174  // Hard coded sampling weights from JFH analysis of iso tracks
175  // Sept 2009.
176  DetId id = hit->id();
177  if (id.det() == DetId::Hcal) {
178  HcalDetId detId(id);
179  if (detId.subdet() == HcalBarrel)
180  samplingWeight = 114.1;
181  else if (detId.subdet() == HcalEndcap)
182  samplingWeight = 167.3;
183  else {
184  // ONLY protection against summing HO, HF simhits
185  return 0.;
186  }
187  }
188 
189  return samplingWeight*hit->energy();
190  }
191 
193  DetId detId(hit->id());
194  return ((HcalGeometry*)(geo->getSubdetectorGeometry(detId)))->getPosition(detId);
195  }
196 
197  GlobalPoint getGpos(const CaloGeometry* geo,edm::PCaloHitContainer::const_iterator hit, bool) {
198  DetId detId(hit->id());
199  GlobalPoint point = (detId.det() == DetId::Hcal) ?
200  ((HcalGeometry*)(geo->getSubdetectorGeometry(detId)))->getPosition(detId) :
201  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) ? hit->eraw() : hit->energy();
218  return energy;
219  }
220 
222  return hit->energy();
223  }
224 
225  double getRawEnergy(edm::PCaloHitContainer::const_iterator hit, bool) {
226  return hit->energy();
227  }
228 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
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: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
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
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)
#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