ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackDensity.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackDensity.hpp
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 #pragma once
10 
11 #include <map>
12 #include <set>
14 
15 namespace Acts {
16 
22 class TrackDensity {
23  public:
25  struct TrackEntry {
26  // Default constructor
27  TrackEntry() = default;
28  // Constructor initializing all members
29  TrackEntry(double z, double c0in, double c1in, double c2in, double zMin,
30  double zMax)
31  : z(z),
32  c0(c0in),
33  c1(c1in),
34  c2(c2in),
35  lowerBound(zMin),
36  upperBound(zMax) {}
37 
38  double z = 0;
39  // Cached information for a single track
40  // z-independent term in exponent
41  double c0 = 0;
42  // linear coefficient in exponent
43  double c1 = 0;
44  // quadratic coefficient in exponent
45  double c2 = 0;
46  // The lower bound
47  double lowerBound = 0;
48  // The upper bound
49  double upperBound = 0;
50  };
51 
53  struct Config {
54  // Assumed shape of density function:
55  // Gaussian (true) or parabolic (false)
56  bool isGaussianShaped = true;
57  };
58 
60  struct State {
61  // Constructor with size track map
62  State(unsigned int nTracks) { trackEntries.reserve(nTracks); }
63  // Vector to cache track information
64  std::vector<TrackEntry> trackEntries;
65  };
66 
68  TrackDensity() = default;
69 
71  TrackDensity(const Config& cfg) : m_cfg(cfg) {}
72 
79  void addTrack(State& state, const BoundParameters& trk,
80  double d0SignificanceCut, double z0SignificanceCut) const;
81 
98  std::pair<double, double> globalMaximumWithWidth(State& state) const;
99 
105  double globalMaximum(State& state) const;
106 
114  double trackDensity(State& state, double z) const;
115 
125  double trackDensity(State& state, double z, double& firstDerivative,
126  double& secondDerivative) const;
127 
128  private:
129  // Helper class to evaluate and store track density at specific position
131  public:
132  // Initialise at the z coordinate at which the density is to be evaluated
133  TrackDensityStore(double z_coordinate) : m_z(z_coordinate) {}
134 
135  // Add the contribution of a single track to the density
136  void addTrackToDensity(const TrackEntry& entry);
137 
138  // Retrieve the density and its derivatives
139  inline double density() const { return m_density; }
140  inline double firstDerivative() const { return m_firstDerivative; }
141  inline double secondDerivative() const { return m_secondDerivative; }
142 
143  private:
144  // Store density and derivatives for z position m_z
145  double m_z;
146  double m_density{0};
147  double m_firstDerivative{0};
149  };
150 
153 
162  void updateMaximum(double newZ, double newValue, double newSecondDerivative,
163  double& maxZ, double& maxValue,
164  double& maxSecondDerivative) const;
165 
173  double stepSize(double y, double dy, double ddy) const;
174 };
175 
176 } // namespace Acts