ATLAS Offline Software
CurvedCandidateFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "GaudiKernel/MsgStream.h"
9 
10 using namespace MuonCalib;
11 
13 
14 const std::vector<CurvedLine> &CurvedCandidateFinder::getCandidates(const double &road_width) {
15  Amg::Vector3D est_dir(0.0, 0.0, 1.0);
16  return getCandidates(road_width, est_dir);
17 }
18 
19 //*****************************************************************************
20 
21 //::::::::::::::::::::::::::
22 //:: METHOD getCandidates ::
23 //::::::::::::::::::::::::::
24 
25 const std::vector<CurvedLine> &CurvedCandidateFinder::getCandidates(const double &road_width, const Amg::Vector3D &est_dir) {
27  // RETURN IF THERE ARE NOT ENOUGH HITS //
29 
30  if (m_hits.size() < 3) {
31  MsgStream log(Athena::getMessageSvc(), "CurvedCandidateFinder");
32  log << MSG::WARNING << "Class CurvedCandidateFinder, method getCandidates: Not enough hits to determine a parabola!" << endmsg;
33  }
34 
36  // VARIABLES //
38 
39  std::array<MdtHitPtr, 3> hit; // three hits defining the candidate line
40  double min_z, max_z, dist(0.0); // auxialiary variables to define the points
41  std::vector<Amg::Vector3D> points(3); // points defining the curved candidate line
42  std::array<int,3> sign {}; // auxiliary sign array
43  Amg::Vector3D null(0.0, 0.0, 0.0); // auxiliary 0 vector
44  Amg::Vector3D xhat(1.0, 0.0, 0.0); // auxiliary unit vector
45  Amg::Vector3D shift_vec(0.0, est_dir.z(), -est_dir.y());
46  shift_vec = shift_vec.unit();
47 
49  // FIND THREE HITS WITH LARGEST SEPARATION //
51 
52  hit[0] = m_hits[0];
53  hit[2] = m_hits[0];
54 
55  min_z = hit[0]->localPosition().z();
56  max_z = hit[2]->localPosition().z();
57 
58  // get the points with the smallest and largest local z coordinate //
59  for (unsigned int k = 1; k < m_hits.size(); k++) {
60  if (m_hits[k]->localPosition().z() < min_z) {
61  min_z = m_hits[k]->localPosition().z();
62  hit[0] = m_hits[k];
63  }
64  if (m_hits[k]->localPosition().z() > max_z) {
65  max_z = m_hits[k]->localPosition().z();
66  hit[2] = m_hits[k];
67  }
68  }
69 
70  // find a third hit with large separation from these two points //
71  for (auto & ihit : m_hits) {
72  if (ihit != hit[0] && ihit != hit[2]) {
73  if (!hit[1]) {
74  hit[1] = ihit;
75  dist = (hit[2]->localPosition().z() - hit[1]->localPosition().z()) -
76  (hit[1]->localPosition().z() - hit[0]->localPosition().z());
77  } else {
78  if (dist < (hit[2]->localPosition().z() - ihit->localPosition().z()) -
79  (ihit->localPosition().z() - hit[0]->localPosition().z())) {
80  dist = (hit[2]->localPosition().z() - ihit->localPosition().z()) -
81  (ihit->localPosition().z() - hit[0]->localPosition().z());
82  hit[1] = ihit;
83  }
84  }
85  }
86  }
87 
89  // CALCULATE CANDIDATE LINES AND COUNT THE NUMBER OF HITS ON THEM //
91 
92  // clear candidate vector //
93  m_candidates.clear();
94 
95  // search for the candidates //
96  for (sign[0] = -1; sign[0] < 2; sign[0] = sign[0] + 2) {
97  for (sign[1] = -1; sign[1] < 2; sign[1] = sign[1] + 2) {
98  for (sign[2] = -1; sign[2] < 2; sign[2] = sign[2] + 2) {
99  // get a candidate //
100  unsigned int nb_hits(0);
101  for (unsigned int l = 0; l < 3; l++) { points[l] = hit[l]->localPosition() + sign[l] * hit[l]->driftRadius() * shift_vec; }
102  CurvedLine cand_line(points);
103 
104  // refine the candidate //
105  for (unsigned int l = 0; l < 3; l++) {
106  MTStraightLine tangent(cand_line.getTangent(hit[l]->localPosition().z()));
107  Amg::Vector3D delta(tangent.positionVector() - hit[l]->localPosition());
108  Amg::Vector3D aux_dir(delta + (delta.dot(tangent.directionVector().unit()) * tangent.directionVector().unit()));
109  aux_dir = hit[l]->driftRadius() * aux_dir.unit();
110  Amg::Vector3D mem(points[l]);
111  points[l][1] = (hit[l]->localPosition().y() + aux_dir.y());
112  points[l][2] = (hit[l]->localPosition().z() + aux_dir.z());
113  }
114 
115  // count the number of hits on the line within the given road width //
116  for (auto & ihit : m_hits) {
117  MTStraightLine w(Amg::Vector3D(0.0, ihit->localPosition().y(), ihit->localPosition().z()), xhat, null, null);
118  double d(std::abs((cand_line.getTangent(ihit->localPosition().z())).signDistFrom(w)));
119  if (std::abs(ihit->driftRadius() - d) < road_width) { nb_hits++; }
120  }
121 
122  // add the candidate line to list of candidates if there are enough hits //
123  if (nb_hits == m_hits.size()) { m_candidates.push_back(cand_line); }
124  }
125  }
126  }
127 
128  return m_candidates;
129 }
MuonCalib::CurvedCandidateFinder::CurvedCandidateFinder
CurvedCandidateFinder(const MdtHitVec &hits)
Constructor.
Definition: CurvedCandidateFinder.cxx:12
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
hist_file_dump.d
d
Definition: hist_file_dump.py:137
MuonCalib::CurvedLine::getTangent
MTStraightLine getTangent(const double &loc_z) const
get the tangent to the line a the local z coordinate "loc_z"
Definition: CurvedLine.cxx:114
MuonCalib::CurvedLine
Definition: CurvedLine.h:31
MuonCalib::MTStraightLine::directionVector
Amg::Vector3D directionVector() const
get the direction vector of the straight line
Definition: MTStraightLine.cxx:43
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonCalib::CurvedCandidateFinder::getCandidates
const std::vector< CurvedLine > & getCandidates(const double &road_width)
get all candidates connecting all hits within the given road width (mm)
Definition: CurvedCandidateFinder.cxx:14
CurvedCandidateFinder.h
z
#define z
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArG4ShowerLibProcessing.hits
hits
Definition: LArG4ShowerLibProcessing.py:136
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:127
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::CurvedCandidateFinder::MdtHitVec
MuonCalibSegment::MdtHitVec MdtHitVec
Definition: CurvedCandidateFinder.h:37
keylayer_zslicemap.max_z
max_z
Definition: keylayer_zslicemap.py:110
keylayer_zslicemap.min_z
min_z
Definition: keylayer_zslicemap.py:111
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonCalib::CurvedCandidateFinder::m_candidates
std::vector< CurvedLine > m_candidates
Definition: CurvedCandidateFinder.h:60
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::MTStraightLine
Definition: MTStraightLine.h:16
MuonCalib::CurvedCandidateFinder::m_hits
MdtHitVec m_hits
Definition: CurvedCandidateFinder.h:56
MuonCalib::MTStraightLine::positionVector
Amg::Vector3D positionVector() const
get the position vector of the straight line
Definition: MTStraightLine.cxx:42
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
fitman.k
k
Definition: fitman.py:528