Skip to content
Snippets Groups Projects

TrkVertexSeedFinderUtils/GaussianTrackDensity try to tidy a bit and use STLPool allocators

Files
3
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRKVERTEXSEEDFINDERUTILIS_GAUSSIANTRACKDENSITY_H
@@ -10,6 +10,7 @@
#include <map>
#include "AthAllocators/ArenaPoolSTLAllocator.h"
namespace Trk
{
@@ -22,11 +23,9 @@ namespace Trk
Implementation of IVertexTrackDensityEstimator modeling reconstructed tracks as
two-dimensional Gaussian distributions in (d0, z0) space and sampling
the aggregate density distribution at user-requested points along the beam axis.
@author Dave Casper <dcasper@uci.edu>
------------------------------------
Changes:
@author Christos Anastopoulos (Athena MT)
*/
class GaussianTrackDensity final: public extends<AthAlgTool, IVertexTrackDensityEstimator>
@@ -35,7 +34,6 @@ namespace Trk
/// Inherit constructor.
using base_class::base_class;
/**
* @brief Find position of global maximum for density function.
* @param vectorTrk List of input tracks.
@@ -43,7 +41,6 @@ namespace Trk
virtual double
globalMaximum (const std::vector<const Track*>& vectorTrk) const override final;
/**
* @brief Find position of global maximum for density function.
* @param vectorTrk List of input tracks.
@@ -53,7 +50,6 @@ namespace Trk
globalMaximum (const std::vector<const Track*>& vectorTrk,
std::unique_ptr<ITrackDensity>& density) const override final;
/**
* @brief Find position of global maximum for density function.
* @param perigeeList List of input tracks.
@@ -61,7 +57,6 @@ namespace Trk
virtual double
globalMaximum (const std::vector<const TrackParameters*>& perigeeList) const override final;
/**
* @brief Find position of global maximum for density function.
* @param perigeeList List of input tracks.
@@ -71,74 +66,33 @@ namespace Trk
globalMaximum (const std::vector<const TrackParameters*>& perigeeList,
std::unique_ptr<ITrackDensity>& density) const override final;
virtual
std::pair<double,double> globalMaximumWithWidth (const std::vector<const TrackParameters*>& perigeeList/*,
std::unique_ptr<ITrackDensity>& density*/) const override final;
private:
class TrackDensity;
/**
* @brief Find position of global maximum for density function.
* @param pergigeeList List of input tracks.
* @param density Helper density object.
*/
double
globalMaximumImpl (const std::vector<const TrackParameters*>& perigeeList,
TrackDensity& density) const;
/**
* @brief Find position of global maximum with Gaussian width for density function.
* @param pergigeeList List of input tracks.
* @param density Helper density object.
*/
std::pair<double,double>
globalMaximumWithWidthImpl (const std::vector<const TrackParameters*>& perigeeList,
TrackDensity& density) const;
/**
* @brief Add a set of tracks to a density object.
* @param perigeeList Set of track parameters to add.
* @param density Density object to which to add.
*/
void addTracks(const std::vector<const TrackParameters*>& perigeeList,
TrackDensity& density) const;
// functor to compare two Perigee values
struct pred_perigee {
bool operator()(const Perigee& left, const Perigee& right) const
{
return left.parameters()[Trk::z0] < right.parameters()[Trk::z0];
}
};
struct TrackEntry
{
TrackEntry() { c_0 = 0; c_1 = 0; c_2 = 0; lowerBound = 0; upperBound = 0; }
TrackEntry(double c0, double c1, double c2, double zMin, double zMax);
TrackEntry(double zProbe);
virtual std::pair<double, double> globalMaximumWithWidth(
const std::vector<const TrackParameters*>& perigeeList)
const override final;
private:
struct TrackEntry {
TrackEntry() = default;
TrackEntry(const TrackEntry&) = default;
TrackEntry(TrackEntry&&) = default;
TrackEntry& operator=(const TrackEntry&) = default;
TrackEntry& operator=(TrackEntry&&) = default;
~TrackEntry() = default;
TrackEntry(double c0, double c1, double c2, double zMin, double zMax)
: c_0(c0), c_1(c1), c_2(c2), lowerBound(zMin), upperBound(zMax) {}
explicit TrackEntry(double z)
: c_0(0), c_1(0), c_2(0), lowerBound(z), upperBound(z) {}
// Cached information for a single track
double c_0; // z-independent term in exponent
double c_1; // linear coefficient in exponent
double c_2; // quadratic coefficient in exponent
double lowerBound;
double upperBound;
};
// functor to compare two TrackEntry values based on their upper limits (low to high)
struct pred_entry_by_max {
bool operator()(const TrackEntry& left, const TrackEntry& right) const
{
return left.upperBound < right.upperBound;
}
double c_0 = 0; // z-independent term in exponent
double c_1 = 1; // linear coefficient in exponent
double c_2 = 0; // quadratic coefficient in exponent
double lowerBound = 0;
double upperBound = 0;
};
// helper to handle the evaluation of the parametrised track density
class TrackDensityEval{
struct TrackDensityEval{
public:
// initialise with the z coordinate at which the density is to be evaluated
TrackDensityEval(double z_coordinate): m_z(z_coordinate){}
@@ -155,104 +109,121 @@ namespace Trk
double m_density{0};
double m_firstDerivative{0};
double m_secondDerivative{0};
};
typedef std::map< Perigee,
GaussianTrackDensity::TrackEntry,
GaussianTrackDensity::pred_perigee > trackMap;
typedef std::map< Perigee,
GaussianTrackDensity::TrackEntry,
GaussianTrackDensity::pred_perigee >::const_iterator trackMapIterator;
typedef std::map< GaussianTrackDensity::TrackEntry,
Perigee,
GaussianTrackDensity::pred_entry_by_max > lowerMap;
typedef std::map< GaussianTrackDensity::TrackEntry,
Perigee,
GaussianTrackDensity::pred_entry_by_max >::const_iterator lowerMapIterator;
class TrackDensity final: public ITrackDensity
{
public:
TrackDensity (bool gaussStep) : m_gaussStep (gaussStep) {}
virtual ~TrackDensity() = default;
/**
* Evaluate the density function at the specified coordinate
* along the beamline.
*/
virtual double trackDensity (double z) const override final;
/**
* Evaluate the density and its first two derivatives
* at the specified coordinate.
*/
virtual void trackDensity (double z,
double& density,
double& firstDerivative,
double& secondDerivative) const override final;
/**
* @brief Return position of global maximum for density function.
* @param msg Message stream.
*/
double globalMaximum (MsgStream& msg) const;
/**
* @brief Return position of global maximum with Gaussian width for density function.
* @param msg Message stream.
*/
std::pair<double,double> globalMaximumWithWidth (MsgStream& msg) const;
/**
* @brief Add a track to the set being considered.
* @param itrk Track parameters.
* @param d0SignificanceCut Significance cut on d0.
* @param z0SignificanceCut Significance cut on z0.
*/
void addTrack (const Perigee& itrk,
const double d0SignificanceCut,
const double z0SignificanceCut);
};
private:
inline void updateMaximum(double trialZ,
double trialValue,
double secondDerivative,
double& maxZ,
double& maxValue,
double& maxSecondDerivative) const
{
class TrackDensity final : public ITrackDensity {
public:
explicit TrackDensity(bool gaussStep) : m_gaussStep(gaussStep) {}
virtual ~TrackDensity() = default;
/**
* Evaluate the density function at the specified coordinate
* along the beamline.
*/
virtual double trackDensity(double z) const override final;
/**
* Evaluate the density and its first two derivatives
* at the specified coordinate.
*/
virtual void trackDensity(
double z, double& density, double& firstDerivative,
double& secondDerivative) const override final;
/**
* @brief Return position of global maximum for density function.
*/
double globalMaximum() const;
/**
* @brief Return position of global maximum with Gaussian width for
* density function.
*/
std::pair<double, double> globalMaximumWithWidth() const;
/**
* @brief Add a track to the set being considered.
* @param itrk Track parameters.
* @param d0SignificanceCut Significance cut on d0.
* @param z0SignificanceCut Significance cut on z0.
*/
void addTrack(const Perigee& itrk, const double d0SignificanceCut,
const double z0SignificanceCut);
private:
inline void updateMaximum(double trialZ, double trialValue,
double secondDerivative, double& maxZ,
double& maxValue,
double& maxSecondDerivative) const {
if (trialValue > maxValue) {
maxZ = trialZ;
maxValue = trialValue;
maxSecondDerivative = secondDerivative;
}
}
}
inline double stepSize(double y, double dy, double ddy) const
{
inline double stepSize(double y, double dy, double ddy) const {
return (m_gaussStep ? (y * dy) / (dy * dy - y * ddy) : -dy / ddy);
}
}
bool m_gaussStep;
double m_maxRange = 0;
// Cache for track information
// functor to compare two Perigee values
struct pred_perigee {
inline bool operator()(const Perigee& left,
const Perigee& right) const {
return left.parameters()[Trk::z0] < right.parameters()[Trk::z0];
}
};
// functor to compare two TrackEntry values based on their upper limits (low
// to high)
struct pred_entry_by_max {
inline bool operator()(const TrackEntry& left,
const TrackEntry& right) const {
return left.upperBound < right.upperBound;
}
};
bool m_gaussStep;
using trackMap =
std::map<Perigee, GaussianTrackDensity::TrackEntry, pred_perigee,
SG::ArenaPoolSTLAllocator<std::pair<
const Perigee, GaussianTrackDensity::TrackEntry>>>;
// Cache for track information
trackMap m_trackMap;
lowerMap m_lowerMap;
using lowerMap = std::map<
GaussianTrackDensity::TrackEntry, Perigee, pred_entry_by_max,
SG::ArenaPoolSTLAllocator<
std::pair<const GaussianTrackDensity::TrackEntry, Perigee>>>;
double m_maxRange = 0;
trackMap m_trackMap;
lowerMap m_lowerMap;
};
/**
* @brief Find position of global maximum for density function.
* @param pergigeeList List of input tracks.
* @param density Helper density object.
*/
double
globalMaximumImpl (const std::vector<const TrackParameters*>& perigeeList,
TrackDensity& density) const;
/**
* @brief Find position of global maximum with Gaussian width for density function.
* @param pergigeeList List of input tracks.
* @param density Helper density object.
*/
std::pair<double,double>
globalMaximumWithWidthImpl (const std::vector<const TrackParameters*>& perigeeList,
TrackDensity& density) const;
/**
* @brief Add a set of tracks to a density object.
* @param perigeeList Set of track parameters to add.
* @param density Density object to which to add.
*/
void addTracks(const std::vector<const TrackParameters*>& perigeeList,
TrackDensity& density) const;
// Cuts set by configurable properties
// Maximum allowed d0 significance to use (in sigma)
Loading