Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AdaptiveGridDensityVertexFinder.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AdaptiveGridDensityVertexFinder.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 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 trackDensityMap = state.trackDensities.at(trk);
26  m_cfg.gridDensity.subtractTrack(trackDensityMap, state.mainDensityMap);
27  }
28  if (not couldRemoveTracks) {
29  // No tracks were removed anymore
30  // Return empty seed, i.e. vertex at constraint position
31  // (Note: Upstream finder should check for this break condition)
32  std::vector<Vertex<InputTrack_t>> seedVec{vertexingOptions.constraint};
33  return seedVec;
34  }
35  } else {
36  state.mainDensityMap.clear();
37  // Fill with track densities
38  for (auto trk : trackVector) {
39  const BoundTrackParameters& trkParams = m_extractParameters(*trk);
40  // Take only tracks that fulfill selection criteria
41  if (not doesPassTrackSelection(trkParams)) {
42  if (m_cfg.cacheGridStateForTrackRemoval) {
43  state.trackSelectionMap[trk] = false;
44  }
45  continue;
46  }
47  auto trackDensityMap =
48  m_cfg.gridDensity.addTrack(trkParams, state.mainDensityMap);
49  // Cache track density contribution to main grid if enabled
50  if (m_cfg.cacheGridStateForTrackRemoval) {
51  state.trackDensities[trk] = trackDensityMap;
52  state.trackSelectionMap[trk] = true;
53  }
54  }
55  state.isInitialized = true;
56  }
57 
58  double z = 0;
59  double width = 0;
60  if (not state.mainDensityMap.empty()) {
61  if (not m_cfg.estimateSeedWidth) {
62  // Get z value of highest density bin
63  auto maxZTRes = m_cfg.gridDensity.getMaxZTPosition(state.mainDensityMap);
64 
65  if (!maxZTRes.ok()) {
66  return maxZTRes.error();
67  }
68  z = (*maxZTRes).first;
69  } else {
70  // Get z value of highest density bin and width
71  auto maxZTResAndWidth =
72  m_cfg.gridDensity.getMaxZTPositionAndWidth(state.mainDensityMap);
73 
74  if (!maxZTResAndWidth.ok()) {
75  return maxZTResAndWidth.error();
76  }
77  z = (*maxZTResAndWidth).first.first;
78  width = (*maxZTResAndWidth).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 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 to check if track can easily
127  // be considered as 2-dim Gaussian distribution without causing problems
128  double constantTerm =
129  -(d0 * d0 * covZZ + z0 * z0 * covDD + 2. * d0 * z0 * covDZ) /
130  (2. * covDeterminant);
131  const double linearTerm = (d0 * covDZ + z0 * covDD) / covDeterminant;
132  const double quadraticTerm = -covDD / (2. * covDeterminant);
133  double discriminant =
134  linearTerm * linearTerm -
135  4. * quadraticTerm * (constantTerm + 2. * m_cfg.z0SignificanceCut);
136  if (discriminant < 0) {
137  return false;
138  }
139 
140  return true;
141 }