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