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