ATLAS Offline Software
CaloCellSelectorUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <algorithm>
8 #include <cmath>
9 
10 namespace Utils {
11  double deltaPhi(double phi1, double phi2) {
12  double dPhi = std::fabs(phi1 - phi2);
13  if (dPhi > M_PI) dPhi = 2 * M_PI - dPhi;
14  return dPhi;
15  }
16 
17  double deltaR2(double eta1, double eta2, double phi1, double phi2) {
18  double dPhi = deltaPhi(phi1, phi2);
19  double dEta = std::fabs(eta1 - eta2);
20  return dEta * dEta + dPhi * dPhi;
21  }
22 
23  double deltaR(double eta1, double eta2, double phi1, double phi2) { return std::sqrt(deltaR2(eta1, eta2, phi1, phi2)); }
24 
25  void findNearestPoint(const Amg::Vector3D& inputPos, const Trk::CaloExtension* caloExtension, int& nearestIdx,
26  Amg::Vector3D& nearestPos, Amg::Vector3D& nearestMom) {
27  const std::vector<Trk::CurvilinearParameters>& intersections = caloExtension->caloLayerIntersections();
28  int nPts = intersections.size();
29 
30  int idxL, idxR, idxMid;
31  Amg::Vector3D pos(0, 0, 0), mom(0, 0, 0); // initialization should be(?) unnecessary, just to suppress scary warning msg...
32  Amg::Vector3D posL(0, 0, 0), momL(0, 0, 0);
33  Amg::Vector3D posR(0, 0, 0), momR(0, 0, 0);
34 
35  // find nearest crossing point
36  idxL = 0;
37  idxR = nPts - 1;
38  while ((idxR - idxL) > 1) {
39  idxMid = (idxL + idxR) / 2;
40  pos = intersections[idxMid].position();
41  mom = intersections[idxMid].momentum();
42 
43  if ((inputPos - pos).dot(mom) > 0) {
44  idxL = idxMid;
45  std::swap(posL, pos);
46  std::swap(momL, mom);
47  } else {
48  idxR = idxMid;
49  std::swap(posR, pos);
50  std::swap(momR, mom);
51  }
52  }
53 
54  if (idxL == 0) {
55  posL = intersections[0].position();
56  momL = intersections[0].momentum();
57  }
58  if (idxR == (nPts - 1)) {
59  posR = intersections[nPts - 1].position();
60  momR = intersections[nPts - 1].momentum();
61  }
62 
63  float mag2L = (inputPos - posL).mag2();
64  float mag2R = (inputPos - posR).mag2();
65  nearestIdx = (mag2L < mag2R) ? idxL : idxR;
66  nearestPos = (mag2L < mag2R) ? posL : posR;
67  nearestMom = (mag2L < mag2R) ? momL : momR;
68  }
69 } // namespace Utils
ParticleGun_SamplingFraction.eta2
eta2
Definition: ParticleGun_SamplingFraction.py:96
Utils::deltaPhi
double deltaPhi(double phi1, double phi2)
Definition: CaloCellSelectorUtils.cxx:11
Trk::CaloExtension
Tracking class to hold the extrapolation from a particle from the ID to the muon system (or the other...
Definition: CaloExtension.h:18
M_PI
#define M_PI
Definition: ActiveFraction.h:11
xAOD::eta1
setEt setPhi setE277 setWeta2 eta1
Definition: TrigEMCluster_v1.cxx:41
CaloCellSelectorUtils.h
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:530
Utils::deltaR
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: CaloCellSelectorUtils.cxx:23
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::CaloExtension::caloLayerIntersections
const std::vector< CurvilinearParameters > & caloLayerIntersections() const
access to the intersections with the calorimeter layers.
Definition: CaloExtension.h:76
Utils
Definition: CaloCellSelectorUtils.cxx:10
TauGNNUtils::Variables::Track::dEta
bool dEta(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:525
mag2
Scalar mag2() const
mag2 method - forward to squaredNorm()
Definition: AmgMatrixBasePlugin.h:30
Utils::findNearestPoint
void findNearestPoint(const Amg::Vector3D &inputPos, const Trk::CaloExtension *caloExtension, int &nearestIdx, Amg::Vector3D &nearestPos, Amg::Vector3D &nearestMom)
Definition: CaloCellSelectorUtils.cxx:25
Utils::deltaR2
double deltaR2(double eta1, double eta2, double phi1, double phi2)
Definition: CaloCellSelectorUtils.cxx:17