Analysis Software
Documentation for sPHENIX simulation 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{vertexingOptions.constraint};
34  return seedVec;
35  }
36  } else {
37  state.mainGrid = MainGridVector::Zero();
38  // Fill with track densities
39  for (auto trk : trackVector) {
40  const BoundTrackParameters& trkParams = m_extractParameters(*trk);
41  // Take only tracks that fulfill selection criteria
42  if (not doesPassTrackSelection(trkParams)) {
43  if (m_cfg.cacheGridStateForTrackRemoval) {
44  state.trackSelectionMap[trk] = false;
45  }
46  continue;
47  }
48  auto binAndTrackGrid =
49  m_cfg.gridDensity.addTrack(trkParams, state.mainGrid);
50  // Cache track density contribution to main grid if enabled
51  if (m_cfg.cacheGridStateForTrackRemoval) {
52  state.binAndTrackGridMap[trk] = binAndTrackGrid;
53  state.trackSelectionMap[trk] = true;
54  }
55  }
56  state.isInitialized = true;
57  }
58 
59  double z = 0;
60  double width = 0;
61  if (state.mainGrid != MainGridVector::Zero()) {
62  if (not m_cfg.estimateSeedWidth) {
63  // Get z value of highest density bin
64  auto maxZres = m_cfg.gridDensity.getMaxZPosition(state.mainGrid);
65 
66  if (!maxZres.ok()) {
67  return maxZres.error();
68  }
69  z = *maxZres;
70  } else {
71  // Get z value of highest density bin and width
72  auto maxZres = m_cfg.gridDensity.getMaxZPositionAndWidth(state.mainGrid);
73 
74  if (!maxZres.ok()) {
75  return maxZres.error();
76  }
77  z = (*maxZres).first;
78  width = (*maxZres).second;
79  }
80  }
81 
82  // Construct output vertex
83  Vector3 seedPos = vertexingOptions.constraint.position() + Vector3(0., 0., z);
84 
85  Vertex<InputTrack_t> returnVertex = Vertex<InputTrack_t>(seedPos);
86 
87  SquareMatrix4 seedCov = vertexingOptions.constraint.fullCovariance();
88 
89  if (width != 0.) {
90  // Use z-constraint from seed width
91  seedCov(2, 2) = width * width;
92  }
93 
94  returnVertex.setFullCovariance(seedCov);
95 
96  std::vector<Vertex<InputTrack_t>> seedVec{returnVertex};
97 
98  return seedVec;
99 }
100 
101 template <int mainGridSize, int trkGridSize, typename vfitter_t>
104  // Get required track parameters
105  const double d0 = trk.parameters()[BoundIndices::eBoundLoc0];
106  const double z0 = trk.parameters()[BoundIndices::eBoundLoc1];
107  // Get track covariance
108  if (not trk.covariance().has_value()) {
109  return false;
110  }
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 }