EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GridDensityVertexFinder.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GridDensityVertexFinder.ipp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 template <int mainGridSize, int trkGridSize, typename vfitter_t>
11  const std::vector<const InputTrack_t*>& trackVector,
12  const VertexingOptions<InputTrack_t>& vertexingOptions, State& state) const
14  // Remove density contributions from tracks removed from track collection
15  if (m_cfg.cacheGridStateForTrackRemoval && state.isInitialized &&
16  !state.tracksToRemove.empty()) {
17  // Bool to check if removable tracks, that pass selection, still exist
18  bool couldRemoveTracks = false;
19  for (auto trk : state.tracksToRemove) {
20  if (not state.trackSelectionMap.at(trk)) {
21  // Track was never added to grid, so cannot remove it
22  continue;
23  }
24  couldRemoveTracks = true;
25  auto binAndTrackGrid = state.binAndTrackGridMap.at(trk);
26  m_cfg.gridDensity.removeTrackGridFromMainGrid(
27  binAndTrackGrid.first, binAndTrackGrid.second, state.mainGrid);
28  }
29  if (not couldRemoveTracks) {
30  // No tracks were removed anymore
31  // Return empty seed, i.e. vertex at constraint position
32  // (Note: Upstream finder should check for this break condition)
33  std::vector<Vertex<InputTrack_t>> seedVec{
34  vertexingOptions.vertexConstraint};
35  return seedVec;
36  }
37  } else {
38  state.mainGrid = ActsVectorF<mainGridSize>::Zero();
39  // Fill with track densities
40  for (auto trk : trackVector) {
41  const BoundTrackParameters& trkParams = m_extractParameters(*trk);
42  // Take only tracks that fulfill selection criteria
43  if (not doesPassTrackSelection(trkParams)) {
44  if (m_cfg.cacheGridStateForTrackRemoval) {
45  state.trackSelectionMap[trk] = false;
46  }
47  continue;
48  }
49  auto binAndTrackGrid =
50  m_cfg.gridDensity.addTrack(trkParams, state.mainGrid);
51  // Cache track density contribution to main grid if enabled
52  if (m_cfg.cacheGridStateForTrackRemoval) {
53  state.binAndTrackGridMap[trk] = binAndTrackGrid;
54  state.trackSelectionMap[trk] = true;
55  }
56  }
57  state.isInitialized = true;
58  }
59 
60  double z = 0;
61  double width = 0;
62  if (state.mainGrid != ActsVectorF<mainGridSize>::Zero()) {
63  if (not m_cfg.estimateSeedWidth) {
64  // Get z value of highest density bin
65  auto maxZres = m_cfg.gridDensity.getMaxZPosition(state.mainGrid);
66 
67  if (!maxZres.ok()) {
68  return maxZres.error();
69  }
70  z = *maxZres;
71  } else {
72  // Get z value of highest density bin and width
73  auto maxZres = m_cfg.gridDensity.getMaxZPositionAndWidth(state.mainGrid);
74 
75  if (!maxZres.ok()) {
76  return maxZres.error();
77  }
78  z = (*maxZres).first;
79  width = (*maxZres).second;
80  }
81  }
82 
83  // Construct output vertex
84  Vector3D seedPos =
85  vertexingOptions.vertexConstraint.position() + Vector3D(0., 0., z);
86 
87  Vertex<InputTrack_t> returnVertex = Vertex<InputTrack_t>(seedPos);
88 
89  ActsSymMatrixD<4> seedCov =
90  vertexingOptions.vertexConstraint.fullCovariance();
91 
92  if (width != 0.) {
93  // Use z-constraint from seed width
94  seedCov(2, 2) = width * width;
95  }
96 
97  returnVertex.setFullCovariance(seedCov);
98 
99  std::vector<Vertex<InputTrack_t>> seedVec{returnVertex};
100 
101  return seedVec;
102 }
103 
104 template <int mainGridSize, int trkGridSize, typename vfitter_t>
107  // Get required track parameters
108  const double d0 = trk.parameters()[BoundIndices::eBoundLoc0];
109  const double z0 = trk.parameters()[BoundIndices::eBoundLoc1];
110  // Get track covariance
111  const auto perigeeCov = *(trk.covariance());
112  const double covDD =
114  const double covZZ =
116  const double covDZ =
118  const double covDeterminant = covDD * covZZ - covDZ * covDZ;
119 
120  // Do track selection based on track cov matrix and d0SignificanceCut
121  if ((covDD <= 0) || (d0 * d0 / covDD > m_cfg.d0SignificanceCut) ||
122  (covZZ <= 0) || (covDeterminant <= 0)) {
123  return false;
124  }
125 
126  // Calculate track density quantities
127  double constantTerm =
128  -(d0 * d0 * covZZ + z0 * z0 * covDD + 2. * d0 * z0 * covDZ) /
129  (2. * covDeterminant);
130  const double linearTerm = (d0 * covDZ + z0 * covDD) / covDeterminant;
131  const double quadraticTerm = -covDD / (2. * covDeterminant);
132  double discriminant =
133  linearTerm * linearTerm -
134  4. * quadraticTerm * (constantTerm + 2. * m_cfg.z0SignificanceCut);
135  if (discriminant < 0) {
136  return false;
137  }
138 
139  return true;
140 }