ATLAS Offline Software
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Trk::GaussianTrackDensity::TrackDensity Class Referencefinal
Inheritance diagram for Trk::GaussianTrackDensity::TrackDensity:
Collaboration diagram for Trk::GaussianTrackDensity::TrackDensity:

Classes

struct  pred_entry_by_max
 
struct  pred_perigee
 

Public Member Functions

 TrackDensity (bool gaussStep)
 
virtual ~TrackDensity ()=default
 
virtual double trackDensity (double z) const override final
 Evaluate the density function at the specified coordinate along the beamline. More...
 
virtual void trackDensity (double z, double &density, double &firstDerivative, double &secondDerivative) const override final
 Evaluate the density and its first two derivatives at the specified coordinate. More...
 
double globalMaximum () const
 Return position of global maximum for density function. More...
 
std::pair< double, double > globalMaximumWithWidth () const
 Return position of global maximum with Gaussian width for density function. More...
 
void addTrack (const Perigee &itrk, const double d0SignificanceCut, const double z0SignificanceCut)
 Add a track to the set being considered. More...
 

Private Types

using trackMap = std::map< Perigee, GaussianTrackDensity::TrackEntry, pred_perigee, SG::ArenaPoolSTLAllocator< std::pair< const Perigee, GaussianTrackDensity::TrackEntry > >>
 
using lowerMap = std::map< GaussianTrackDensity::TrackEntry, Perigee, pred_entry_by_max, SG::ArenaPoolSTLAllocator< std::pair< const GaussianTrackDensity::TrackEntry, Perigee > >>
 

Private Member Functions

void updateMaximum (double trialZ, double trialValue, double secondDerivative, double &maxZ, double &maxValue, double &maxSecondDerivative) const
 
double stepSize (double y, double dy, double ddy) const
 

Private Attributes

bool m_gaussStep
 
double m_maxRange = 0
 
trackMap m_trackMap
 
lowerMap m_lowerMap
 

Detailed Description

Definition at line 114 of file GaussianTrackDensity.h.

Member Typedef Documentation

◆ lowerMap

Definition at line 189 of file GaussianTrackDensity.h.

◆ trackMap

Definition at line 184 of file GaussianTrackDensity.h.

Constructor & Destructor Documentation

◆ TrackDensity()

Trk::GaussianTrackDensity::TrackDensity::TrackDensity ( bool  gaussStep)
inlineexplicit

Definition at line 116 of file GaussianTrackDensity.h.

116 : m_gaussStep(gaussStep) {}

◆ ~TrackDensity()

virtual Trk::GaussianTrackDensity::TrackDensity::~TrackDensity ( )
virtualdefault

Member Function Documentation

◆ addTrack()

void Trk::GaussianTrackDensity::TrackDensity::addTrack ( const Perigee itrk,
const double  d0SignificanceCut,
const double  z0SignificanceCut 
)

Add a track to the set being considered.

Parameters
itrkTrack parameters.
d0SignificanceCutSignificance cut on d0.
z0SignificanceCutSignificance cut on z0.

Definition at line 222 of file GaussianTrackDensity.cxx.

225  {
226  if (m_trackMap.count(itrk) != 0) return;
227  const double d0 = itrk.parameters()[Trk::d0];
228  const double z0 = itrk.parameters()[Trk::z0];
229  const AmgSymMatrix(5) & perigeeCov = *(itrk.covariance());
230  const double cov_dd = perigeeCov(Trk::d0, Trk::d0);
231  if ( cov_dd <= 0 ) return;
232  if ( d0*d0/cov_dd > d0SignificanceCut ) return;
233  const double cov_zz = perigeeCov(Trk::z0, Trk::z0);
234  if (cov_zz <= 0 ) return;
235  const double cov_dz = perigeeCov(Trk::d0, Trk::z0);
236  const double covDeterminant = cov_dd*cov_zz - cov_dz*cov_dz;
237  if ( covDeterminant <= 0 ) return;
238  double constantTerm = -(d0*d0*cov_zz + z0*z0*cov_dd + 2*d0*z0*cov_dz) / (2*covDeterminant);
239  const double linearTerm = (d0*cov_dz + z0*cov_dd) / covDeterminant ; // minus signs and factors of 2 cancel...
240  const double quadraticTerm = -cov_dd / (2*covDeterminant);
241  double discriminant = linearTerm*linearTerm - 4*quadraticTerm*(constantTerm + 2*z0SignificanceCut);
242  if (discriminant < 0) return;
243  discriminant = std::sqrt(discriminant);
244  const double zMax = (-linearTerm - discriminant)/(2*quadraticTerm);
245  const double zMin = (-linearTerm + discriminant)/(2*quadraticTerm);
246  m_maxRange = std::max(m_maxRange, std::max(zMax-z0, z0-zMin));
247  constantTerm -= std::log(2*M_PI*std::sqrt(covDeterminant));
248  m_trackMap.emplace(std::piecewise_construct,
249  std::forward_as_tuple(itrk),
250  std::forward_as_tuple(constantTerm, linearTerm, quadraticTerm, zMin, zMax));
251  m_lowerMap.emplace(std::piecewise_construct,
252  std::forward_as_tuple(constantTerm, linearTerm, quadraticTerm, zMin, zMax),
253  std::forward_as_tuple(itrk));
254  }

◆ globalMaximum()

double Trk::GaussianTrackDensity::TrackDensity::globalMaximum ( ) const

Return position of global maximum for density function.

Parameters
msgMessage stream.

Definition at line 210 of file GaussianTrackDensity.cxx.

211  {
213  }

◆ globalMaximumWithWidth()

std::pair< double, double > Trk::GaussianTrackDensity::TrackDensity::globalMaximumWithWidth ( ) const

Return position of global maximum with Gaussian width for density function.

Definition at line 160 of file GaussianTrackDensity.cxx.

161  {
162  // strategy:
163  // the global maximum must be somewhere near a track...
164  // since we can calculate the first and second derivatives, at each point we can determine
165  // a) whether the function is curved up (minimum) or down (maximum)
166  // b) the distance to nearest maximum, assuming either Newton (parabolic) or Gaussian local behavior
167  //
168  // For each track where the second derivative is negative, find step to nearest maximum
169  // Take that step, and then do one final refinement
170  // The largest density encountered in this procedure (after checking all tracks) is considered the maximum
171  //
172  double maximumPosition = 0.0;
173  double maximumDensity = 0.0;
174  double maxCurvature = 0. ;
175  const std::pair<double,double> invalidResult(0.,std::numeric_limits<double>::quiet_NaN());
176  if (m_trackMap.empty()) return invalidResult;
177  for (const auto& entry : m_trackMap)
178  {
179  double trialZ = entry.first.parameters()[Trk::z0];
180  double density = 0.0;
181  double slope = 0.0;
182  double curvature = 0.0;
183  trackDensity( trialZ, density, slope, curvature );
184  if ( curvature >= 0.0 || density <= 0.0 ) {
185  continue;
186  }
187  updateMaximum( trialZ, density, curvature, maximumPosition, maximumDensity, maxCurvature);
188  trialZ += stepSize( density, slope, curvature );
189  trackDensity( trialZ, density, slope, curvature );
190  if ( curvature >= 0.0 || density <= 0.0 ) {
191  continue;
192  }
193  updateMaximum( trialZ, density, curvature, maximumPosition, maximumDensity, maxCurvature);
194  trialZ += stepSize( density, slope, curvature );
195  trackDensity( trialZ, density, slope, curvature );
196  if ( curvature >= 0.0 || density <= 0.0) {
197  continue;
198  }
199  updateMaximum( trialZ, density, curvature, maximumPosition, maximumDensity, maxCurvature);
200  }
201  if (maxCurvature == 0.) return invalidResult;
202  return {maximumPosition,std::sqrt(-maximumDensity/maxCurvature)};
203  }

◆ stepSize()

double Trk::GaussianTrackDensity::TrackDensity::stepSize ( double  y,
double  dy,
double  ddy 
) const
inlineprivate

Definition at line 162 of file GaussianTrackDensity.h.

162  {
163  return (m_gaussStep ? (y * dy) / (dy * dy - y * ddy) : -dy / ddy);
164  }

◆ trackDensity() [1/2]

double Trk::GaussianTrackDensity::TrackDensity::trackDensity ( double  z) const
finaloverridevirtual

Evaluate the density function at the specified coordinate along the beamline.

Definition at line 130 of file GaussianTrackDensity.cxx.

131  {
132  double firstDeriv, secondDeriv = 0; // unused in this case
133  double density = 0;
134  // use the existing trackDensity method to avoid duplication of logic
135  trackDensity(z,density,firstDeriv,secondDeriv);
136  return density;
137  }

◆ trackDensity() [2/2]

void Trk::GaussianTrackDensity::TrackDensity::trackDensity ( double  z,
double &  density,
double &  firstDerivative,
double &  secondDerivative 
) const
finaloverridevirtual

Evaluate the density and its first two derivatives at the specified coordinate.

Definition at line 145 of file GaussianTrackDensity.cxx.

149  {
150  TrackDensityEval densityResult(z);
151  for (const auto & trackAndPerigeePair : m_lowerMap){
152  densityResult.addTrack(trackAndPerigeePair.first);
153  }
154  density = densityResult.density();
155  firstDerivative = densityResult.firstDerivative();
156  secondDerivative = densityResult.secondDerivative();
157  }

◆ updateMaximum()

void Trk::GaussianTrackDensity::TrackDensity::updateMaximum ( double  trialZ,
double  trialValue,
double  secondDerivative,
double &  maxZ,
double &  maxValue,
double &  maxSecondDerivative 
) const
inlineprivate

Definition at line 151 of file GaussianTrackDensity.h.

154  {
155  if (trialValue > maxValue) {
156  maxZ = trialZ;
157  maxValue = trialValue;
158  maxSecondDerivative = secondDerivative;
159  }
160  }

Member Data Documentation

◆ m_gaussStep

bool Trk::GaussianTrackDensity::TrackDensity::m_gaussStep
private

Definition at line 165 of file GaussianTrackDensity.h.

◆ m_lowerMap

lowerMap Trk::GaussianTrackDensity::TrackDensity::m_lowerMap
private

Definition at line 195 of file GaussianTrackDensity.h.

◆ m_maxRange

double Trk::GaussianTrackDensity::TrackDensity::m_maxRange = 0
private

Definition at line 166 of file GaussianTrackDensity.h.

◆ m_trackMap

trackMap Trk::GaussianTrackDensity::TrackDensity::m_trackMap
private

Definition at line 194 of file GaussianTrackDensity.h.


The documentation for this class was generated from the following files:
Trk::y
@ y
Definition: ParamDefs.h:56
maxValue
#define maxValue(current, test)
Definition: CompoundLayerMaterialCreator.h:22
Trk::z
@ z
global position (cartesian)
Definition: ParamDefs.h:57
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
Trk::GaussianTrackDensity::TrackDensity::trackDensity
virtual double trackDensity(double z) const override final
Evaluate the density function at the specified coordinate along the beamline.
Definition: GaussianTrackDensity.cxx:130
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::z0
@ z0
Definition: ParamDefs.h:64
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
Trk::GaussianTrackDensity::TrackDensity::globalMaximumWithWidth
std::pair< double, double > globalMaximumWithWidth() const
Return position of global maximum with Gaussian width for density function.
Definition: GaussianTrackDensity.cxx:160
Trk::GaussianTrackDensity::TrackDensity::m_gaussStep
bool m_gaussStep
Definition: GaussianTrackDensity.h:165
Trk::GaussianTrackDensity::TrackDensity::m_trackMap
trackMap m_trackMap
Definition: GaussianTrackDensity.h:194
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
TauJetParameters::discriminant
@ discriminant
Definition: TauJetParameters.h:166
Trk::GaussianTrackDensity::TrackDensity::stepSize
double stepSize(double y, double dy, double ddy) const
Definition: GaussianTrackDensity.h:162
Trk::d0
@ d0
Definition: ParamDefs.h:63
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
Trk::GaussianTrackDensity::TrackDensity::m_lowerMap
lowerMap m_lowerMap
Definition: GaussianTrackDensity.h:195
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Trk::GaussianTrackDensity::TrackDensity::updateMaximum
void updateMaximum(double trialZ, double trialValue, double secondDerivative, double &maxZ, double &maxValue, double &maxSecondDerivative) const
Definition: GaussianTrackDensity.h:151
Trk::GaussianTrackDensity::TrackDensity::m_maxRange
double m_maxRange
Definition: GaussianTrackDensity.h:166