test
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, bool debug) {
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 (debug) {
28  std::cout << "getDistInPlaneTrackDir: point " << caloPoint << " dirn "
29  << caloVector << " numerator " << dotprod_numerator
30  << " denominator " << dotprod_denominator << " distance "
31  << distance_vector.mag() << std::endl;
32  }
33  if (dotprod_denominator > 0. && dotprod_numerator > 0.) {
34  return distance_vector.mag();
35  } else {
36  return 999999.;
37  }
38  }
39 
40  // Not used, but here for reference
41  double getDistInCMatEcal(double eta1, double phi1, double eta2, double phi2,
42  bool debug) {
43 
44  double dR, Rec;
45  if (fabs(eta1)<1.479) Rec=129;
46  else Rec=317;
47  double ce1=cosh(eta1);
48  double ce2=cosh(eta2);
49  double te1=tanh(eta1);
50  double te2=tanh(eta2);
51 
52  double z=cos(phi1-phi2)/ce1/ce2+te1*te2;
53  if(z!=0) dR=fabs(Rec*ce1*sqrt(1./z/z-1.));
54  else dR=999999.;
55  if (debug) std::cout << "getDistInCMatEcal: between (" << eta1 << ", "
56  << phi1 << ") and (" << eta2 << ", " << phi2 << " is "
57  << dR << std::endl;
58  return dR;
59  }
60 
61 
62  // Not used, but here for reference
63  double getDistInCMatHcal(double eta1, double phi1, double eta2, double phi2,
64  bool debug) {
65 
66  // Radii and eta from Geometry/HcalCommonData/data/hcalendcapalgo.xml
67  // and Geometry/HcalCommonData/data/hcalbarrelalgo.xml
68 
69  double dR, Rec;
70  if (fabs(eta1)<1.392) Rec=177.5;
71  else Rec=391.95;
72  double ce1=cosh(eta1);
73  double ce2=cosh(eta2);
74  double te1=tanh(eta1);
75  double te2=tanh(eta2);
76 
77  double z=cos(phi1-phi2)/ce1/ce2+te1*te2;
78  if(z!=0) dR=fabs(Rec*ce1*sqrt(1./z/z-1.));
79  else dR=999999.;
80  return dR;
81  if (debug) std::cout << "getDistInCMatHcal: between (" << eta1 << ", "
82  << phi1 << ") and (" << eta2 << ", " << phi2 << " is "
83  << dR << std::endl;
84  }
85 
86  void getEtaPhi(HBHERecHitCollection::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene, bool ) {
87 
88  RH_ieta.push_back(hit->id().ieta());
89  RH_iphi.push_back(hit->id().iphi());
90  RH_ene.push_back(hit->energy());
91  }
92 
93  void getEtaPhi(edm::PCaloHitContainer::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene, bool) {
94  // SimHit function not yet implemented.
95  RH_ieta.push_back(-9);
96  RH_iphi.push_back(-9);
97  RH_ene.push_back(-9.);
98  }
99 
100  void getEtaPhi(EcalRecHitCollection::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene, bool) {
101  // Ecal function not yet implemented.
102  RH_ieta.push_back(-9);
103  RH_iphi.push_back(-9);
104  RH_ene.push_back(-9.);
105  }
106 
107  void getEtaPhi(HBHERecHitCollection::const_iterator hit,int& ieta,int& iphi,
108  bool) {
109  ieta = hit->id().ieta();
110  iphi = hit->id().iphi();
111  }
112 
113  void getEtaPhi(edm::PCaloHitContainer::const_iterator hit,int& ieta,int& iphi,
114  bool){
115  DetId id = DetId(hit->id());
116  if (id.det() == DetId::Hcal) {
117  ieta = ((HcalDetId)(hit->id())).ieta();
118  iphi = ((HcalDetId)(hit->id())).iphi();
119  } else if (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel) {
120  ieta = ((EBDetId)(id)).ieta();
121  iphi = ((EBDetId)(id)).iphi();
122  } else {
123  ieta = 999;
124  iphi = 999;
125  }
126  }
127 
128  void getEtaPhi(EcalRecHitCollection::const_iterator hit,int& ieta,int& iphi,
129  bool) {
130  DetId id = hit->id();
131  if (id.subdetId() == EcalBarrel) {
132  ieta = ((EBDetId)(id)).ieta();
133  iphi = ((EBDetId)(id)).iphi();
134  } else {
135  ieta = 999;
136  iphi = 999;
137  }
138  }
139 
141  return hit->energy();
142  }
143 
145  return hit->energy();
146  }
147 
148  double getEnergy(edm::PCaloHitContainer::const_iterator hit, bool) {
149  // This will not yet handle Ecal CaloHits!!
150  double samplingWeight = 1.;
151  // Hard coded sampling weights from JFH analysis of iso tracks
152  // Sept 2009.
153  HcalDetId detId(hit->id());
154  if (detId.subdet() == HcalBarrel)
155  samplingWeight = 114.1;
156  else if (detId.subdet() == HcalEndcap)
157  samplingWeight = 167.3;
158  else {
159  // ONLY protection against summing HO, HF simhits
160  return 0.;
161  }
162 
163  return samplingWeight*hit->energy();
164  }
165 
167  DetId detId(hit->id());
168  return geo->getPosition(detId);
169  }
170 
171  GlobalPoint getGpos(const CaloGeometry* geo,edm::PCaloHitContainer::const_iterator hit, bool) {
172  DetId detId(hit->id());
173  return geo->getPosition(detId);
174  }
175 
177  // Not tested for EcalRecHits!!
178  if (hit->id().subdetId() == EcalEndcap) {
179  EEDetId EEid = EEDetId(hit->id());
180  return geo->getPosition(EEid);
181  } else { // (hit->id().subdetId() == EcalBarrel)
182  EBDetId EBid = EBDetId(hit->id());
183  return geo->getPosition(EBid);
184  }
185  }
186 }
double getDistInCMatHcal(double eta1, double phi1, double eta2, double phi2, bool debug=false)
Definition: FindDistCone.cc:63
double getDistInPlaneTrackDir(const GlobalPoint &caloPoint, const GlobalVector &caloVector, const GlobalPoint &rechitPoint, bool debug=false)
Definition: FindDistCone.cc:8
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
T mag() const
Definition: PV3DBase.h:67
double getDistInCMatEcal(double eta1, double phi1, double eta2, double phi2, bool debug=false)
Definition: FindDistCone.cc:41
double getEnergy(HBHERecHitCollection::const_iterator hit, bool debug=false)
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
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
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:86
GlobalPoint getGpos(const CaloGeometry *geo, HBHERecHitCollection::const_iterator hit, bool debug=false)
tuple cout
Definition: gather_cfg.py:121
T x() const
Definition: PV3DBase.h:62