ATLAS Offline Software
Loading...
Searching...
No Matches
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
10namespace 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
#define M_PI
Scalar mag2() const
mag2 method - forward to squaredNorm()
Tracking class to hold the extrapolation through calorimeter Layers Both the caloEntryLayerIntersecti...
const std::vector< CurvilinearParameters > & caloLayerIntersections() const
access to the intersections with the calorimeter layers.
Eigen::Matrix< double, 3, 1 > Vector3D
double deltaR2(double eta1, double eta2, double phi1, double phi2)
double deltaR(double eta1, double eta2, double phi1, double phi2)
void findNearestPoint(const Amg::Vector3D &inputPos, const Trk::CaloExtension *caloExtension, int &nearestIdx, Amg::Vector3D &nearestPos, Amg::Vector3D &nearestMom)
double deltaPhi(double phi1, double phi2)
Definition dot.py:1
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)