Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MdtSegmentFitter.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef MUONPATTERNHELPERS_MDTSEGMENTFITTER_H
5 #define MUONPATTERNHELPERS_MDTSEGMENTFITTER_H
6 
8 
14 #include <GaudiKernel/SystemOfUnits.h>
15 
16 
17 namespace MuonR4{
18  class ISpacePointCalibrator;
20  public:
23  using HitType = std::unique_ptr<CalibratedSpacePoint>;
24  using HitVec = std::vector<HitType>;
25 
26  struct Config{
28  unsigned int nMaxCalls{100};
30  double tolerance{1.e-7};
32  bool doTimeFit{true};
34  bool reCalibrate{false};
36  bool useSecOrderDeriv{false};
38  unsigned int nParsOutOfBounds{1};
42  unsigned int noMoveIter{2};
44  using RangeArray = std::array<std::array<double,2>, SegmentFit::toInt(ParamDefs::nPars)>;
46  static RangeArray defaultRanges();
47 
49 
50  };
56  static constexpr unsigned nPars{4};
62  std::array<Amg::Vector3D, nPars> gradient{make_array<Amg::Vector3D, nPars>(Amg::Vector3D::Zero())};
64  std::array<Amg::Vector3D, sumUp(nPars)> hessian{make_array<Amg::Vector3D, sumUp(nPars)>(Amg::Vector3D::Zero())};
65  };
69  static constexpr unsigned nLinePars = LineWithPartials::nPars;
73  std::array<Amg::Vector3D, nLinePars> partProjDir{make_array<Amg::Vector3D, nLinePars>(Amg::Vector3D::Zero())};
75  std::array<double, nLinePars> partWirePlaneProj{make_array<double, nLinePars>(0.)};
77  double projIntoWirePlane{0.};
79  double projDirLenSq{0.};
81  double invProjLenSq{0.};
83  double invProjLen{0.};
84 
85  };
89  static constexpr unsigned nPars{toInt(ParamDefs::nPars)};
93  std::array<Amg::Vector3D, nPars> gradient{make_array<Amg::Vector3D, nPars>(Amg::Vector3D::Zero())};
95  std::array<Amg::Vector3D, sumUp(nPars)> hessian{make_array<Amg::Vector3D, sumUp(nPars)>(Amg::Vector3D::Zero())};
97  bool evalPhiPars{true};
98  };
99 
103  MdtSegmentFitter(const std::string& name,
104  Config&& config);
105 
106  SegmentFitResult fitSegment(const EventContext& ctx,
107  HitVec&& calibHits,
108  const Parameters& startPars,
109  const Amg::Transform3D& localToGlobal) const;
110  private:
120  bool recalibrate(const EventContext& ctx,
121  SegmentFitResult& fitResult) const;
124  bool updateHitSummary(SegmentFitResult& fitResult) const;
125  public:
130  static void updateLinePartials(const Parameters& fitPars,
131  LineWithPartials& line);
138  void calculateWireResiduals(const LineWithPartials& line,
139  const CalibratedSpacePoint& spacePoint,
140  ResidualWithPartials& residual) const;
148  void calculateStripResiduals(const LineWithPartials& line,
149  const CalibratedSpacePoint& spacePoint,
150  ResidualWithPartials& residual) const;
151  private:
153  void updateDriftSigns(const Amg::Vector3D& segPos, const Amg::Vector3D& segDir,
154  SegmentFitResult& fitRes)const;
164  void updateDerivatives(const ResidualWithPartials& fitMeas,
165  const MeasCov_t& measCovariance,
166  AmgVector(5)& gradient,
167  AmgSymMatrix(5)& hessian,
168  double& chi2,
169  int startPar) const;
170 
171 
172  enum class UpdateStatus{
173  allOkay = 0,
174  outOfBounds = 1,
175  noChange = 2,
176  };
187  template <unsigned int nDim>
189  Parameters& previousPars,
190  Parameters& currGrad,
191  Parameters& prevGrad,
192  const AmgSymMatrix(5)& hessian) const;
193 
194  template <unsigned int nDim>
195  void blockCovariance(const AmgSymMatrix(5)& hessian,
196  SegmentFit::Covariance& covariance) const;
197 
198 
199  };
200 }
201 
202 
203 #endif
MuonR4::MdtSegmentFitter::ResidualWithPartials::residual
Amg::Vector3D residual
Vector carrying the residual.
Definition: MdtSegmentFitter.h:91
MuonR4::MdtSegmentFitter::ResidualAuxillaries::invProjLen
double invProjLen
inverse of the unormalized dir porjection
Definition: MdtSegmentFitter.h:83
MuonR4::MdtSegmentFitter::updateDriftSigns
void updateDriftSigns(const Amg::Vector3D &segPos, const Amg::Vector3D &segDir, SegmentFitResult &fitRes) const
Update the signs of the measurement.
Definition: MdtSegmentFitter.cxx:55
MuonR4::MdtSegmentFitter
Definition: MdtSegmentFitter.h:19
MuonR4::SegmentFit::ParamDefs
ParamDefs
This file defines the parameter enums in the Trk namespace.
Definition: MuonHoughDefs.h:29
checkFileSG.line
line
Definition: checkFileSG.py:75
MuonR4::MdtSegmentFitter::blockCovariance
void blockCovariance(const AmgSymMatrix(5)&hessian, SegmentFit::Covariance &covariance) const
Definition: MdtSegmentFitter.cxx:600
MuonR4::MdtSegmentFitter::updateHitSummary
bool updateHitSummary(SegmentFitResult &fitResult) const
Brief updates the hit summary from the contributing hits.
Definition: MdtSegmentFitter.cxx:89
MuonR4::MdtSegmentFitter::calculateStripResiduals
void calculateStripResiduals(const LineWithPartials &line, const CalibratedSpacePoint &spacePoint, ResidualWithPartials &residual) const
Calculates the residual together with hte correspdonding derivatives for strip measurements.
Definition: MdtSegmentFitter.cxx:291
MuonR4::MdtSegmentFitter::LineWithPartials::nPars
static constexpr unsigned nPars
Free parameters of the line (x0,y0,theta,phi)
Definition: MdtSegmentFitter.h:56
MuonR4::SegmentFit::Parameters
AmgVector(toInt(ParamDefs::nPars)) Parameters
Definition: MuonHoughDefs.h:48
MuonR4::MdtSegmentFitter::ResidualWithPartials
Helper struct carrying the residual with its derivatives.
Definition: MdtSegmentFitter.h:87
MuonR4::MdtSegmentFitter::UpdateStatus
UpdateStatus
Definition: MdtSegmentFitter.h:172
MuonR4::MdtSegmentFitter::ResidualAuxillaries::partProjDir
std::array< Amg::Vector3D, nLinePars > partProjDir
Partial derivatives of the dir projection w.r.t.
Definition: MdtSegmentFitter.h:73
ClusterSeg::residual
@ residual
Definition: ClusterNtuple.h:20
MuonR4::MdtSegmentFitter::ResidualAuxillaries::nLinePars
static constexpr unsigned nLinePars
Definition: MdtSegmentFitter.h:69
MuonR4::MdtSegmentFitter::Parameters
SegmentFit::Parameters Parameters
Definition: MdtSegmentFitter.h:22
SegmentSeed.h
MuonR4::MdtSegmentFitter::UpdateStatus::outOfBounds
@ outOfBounds
MuonR4::MdtSegmentFitter::ResidualAuxillaries::partWirePlaneProj
std::array< double, nLinePars > partWirePlaneProj
Partial derivatives of the dir projection lengths w.r.t line parameters.
Definition: MdtSegmentFitter.h:75
MuonR4::MdtSegmentFitter::LineWithPartials::dir
Amg::Vector3D dir
Segment direction
Definition: MdtSegmentFitter.h:60
MuonR4::HitVec
SpacePointPerLayerSorter::HitVec HitVec
Definition: SpacePointPerLayerSorter.cxx:9
MuonR4::MdtSegmentFitter::LineWithPartials::gradient
std::array< Amg::Vector3D, nPars > gradient
First order derivatives.
Definition: MdtSegmentFitter.h:62
MuonR4::MdtSegmentFitter::Config::noMoveIter
unsigned int noMoveIter
How many iterations with changes below tolerance.
Definition: MdtSegmentFitter.h:42
MatrixUtils.h
MuonR4::MdtSegmentFitter::fitSegment
SegmentFitResult fitSegment(const EventContext &ctx, HitVec &&calibHits, const Parameters &startPars, const Amg::Transform3D &localToGlobal) const
Definition: MdtSegmentFitter.cxx:365
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
MuonR4::MdtSegmentFitter::Config::calibrator
const ISpacePointCalibrator * calibrator
Pointer to the calibrator tool.
Definition: MdtSegmentFitter.h:40
MuonR4::MdtSegmentFitter::ResidualAuxillaries::projDirLenSq
double projDirLenSq
Length squared of the projected direction.
Definition: MdtSegmentFitter.h:79
MuonR4::MdtSegmentFitter::ResidualWithPartials::gradient
std::array< Amg::Vector3D, nPars > gradient
First order derivatives.
Definition: MdtSegmentFitter.h:93
CalibratedSpacePoint.h
MuonR4::MdtSegmentFitter::Config::ranges
RangeArray ranges
Definition: MdtSegmentFitter.h:48
GeoPrimitives.h
MuonR4::sumUp
constexpr unsigned int sumUp(unsigned k)
Calculates the sum of 1 + 2 +3 +4 +...
Definition: MatrixUtils.h:15
MuonR4::MdtSegmentFitter::ResidualWithPartials::evalPhiPars
bool evalPhiPars
Flag whether the the residuals w.r.t phi shall be evaluated.
Definition: MdtSegmentFitter.h:97
MuonR4::MdtSegmentFitter::ResidualAuxillaries::invProjLenSq
double invProjLenSq
inverse squared of the unnormalized dir projection
Definition: MdtSegmentFitter.h:81
MuonR4::MdtSegmentFitter::UpdateStatus::noChange
@ noChange
MuonR4::MdtSegmentFitter::ResidualWithPartials::nPars
static constexpr unsigned nPars
Number of parameters.
Definition: MdtSegmentFitter.h:89
MuonR4::MdtSegmentFitter::MeasCov_t
CalibratedSpacePoint::Covariance_t MeasCov_t
Updates the chi2, its Gradient & Hessian from the measurement residual.
Definition: MdtSegmentFitter.h:163
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
MuonR4::MdtSegmentFitter::LineWithPartials::hessian
std::array< Amg::Vector3D, sumUp(nPars)> hessian
Second order derivatives.
Definition: MdtSegmentFitter.h:64
MuonR4::MdtSegmentFitter::HitType
std::unique_ptr< CalibratedSpacePoint > HitType
Definition: MdtSegmentFitter.h:23
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:525
MuonR4::MdtSegmentFitter::Config
Definition: MdtSegmentFitter.h:26
MuonR4::MdtSegmentFitter::Config::useSecOrderDeriv
bool useSecOrderDeriv
Switch toggling whether the second order derivative shall be included.
Definition: MdtSegmentFitter.h:36
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
MuonR4::MdtSegmentFitter::Config::nParsOutOfBounds
unsigned int nParsOutOfBounds
Abort the fit as soon as more than n parameters leave the fit range.
Definition: MdtSegmentFitter.h:38
MuonR4::MdtSegmentFitter::ResidualAuxillaries::projIntoWirePlane
double projIntoWirePlane
projection of the segment direction along the wire
Definition: MdtSegmentFitter.h:77
MuonR4::MdtSegmentFitter::calculateWireResiduals
void calculateWireResiduals(const LineWithPartials &line, const CalibratedSpacePoint &spacePoint, ResidualWithPartials &residual) const
Calculates the residuals together with the corresponding derivatives for a drift-circle measurement.
Definition: MdtSegmentFitter.cxx:161
Config
Definition: dumpNPs.cxx:47
MuonR4::MdtSegmentFitter::ResidualAuxillaries
Helper struct carrying the space for all auxillary variables needed to calculate the residual from wi...
Definition: MdtSegmentFitter.h:68
MuonR4::MdtSegmentFitter::updateDerivatives
void updateDerivatives(const ResidualWithPartials &fitMeas, const MeasCov_t &measCovariance, AmgVector(5)&gradient, AmgSymMatrix(5)&hessian, double &chi2, int startPar) const
Definition: MdtSegmentFitter.cxx:578
lumiFormat.array
array
Definition: lumiFormat.py:91
tolerance
Definition: suep_shower.h:17
MuonR4::MdtSegmentFitter::m_cfg
Config m_cfg
Definition: MdtSegmentFitter.h:111
MuonR4::MdtSegmentFitter::MdtSegmentFitter
MdtSegmentFitter(const std::string &name, Config &&config)
Standard constructor.
Definition: MdtSegmentFitter.cxx:51
MuonR4::MdtSegmentFitter::Config::nMaxCalls
unsigned int nMaxCalls
How many calls shall be executed.
Definition: MdtSegmentFitter.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonR4::SegmentFit::toInt
constexpr int toInt(const ParamDefs p)
Definition: MuonHoughDefs.h:42
MuonR4::MdtSegmentFitter::Config::reCalibrate
bool reCalibrate
Switch toggling whether the calibrator shall be called at each iteration.
Definition: MdtSegmentFitter.h:34
MuonR4::MdtSegmentFitter::UpdateStatus::allOkay
@ allOkay
MuonR4::ISpacePointCalibrator
Interface class to refine the space point calibration with an external seed.
Definition: ISpacePointCalibrator.h:19
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4::MdtSegmentFitter::LineWithPartials
Store the partial derivative of the line w.r.t.
Definition: MdtSegmentFitter.h:54
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::MdtSegmentFitter::Config::RangeArray
std::array< std::array< double, 2 >, SegmentFit::toInt(ParamDefs::nPars)> RangeArray
Allowed parameter ranges.
Definition: MdtSegmentFitter.h:44
MuonR4::SegmentFit::Covariance
AmgSymMatrix(toInt(ParamDefs::nPars)) Covariance
Definition: MuonHoughDefs.h:49
SegmentFitterEventData.h
MuonR4::MdtSegmentFitter::Config::doTimeFit
bool doTimeFit
Switch toggling whether the T0 shall be fitted or not.
Definition: MdtSegmentFitter.h:32
MuonR4::MdtSegmentFitter::HitVec
std::vector< HitType > HitVec
Definition: MdtSegmentFitter.h:24
MuonR4::CalibratedSpacePoint
The calibrated Space point is created during the calibration process.
Definition: CalibratedSpacePoint.h:15
AthMessaging.h
MuonR4::MdtSegmentFitter::LineWithPartials::pos
Amg::Vector3D pos
segment position
Definition: MdtSegmentFitter.h:58
MuonR4::MdtSegmentFitter::ResidualAuxillaries::projDir
Amg::Vector3D projDir
projection of the segment direction onto the wire planes
Definition: MdtSegmentFitter.h:71
MuonR4::SegmentFitResult
Definition: SegmentFitterEventData.h:46
MuonR4::MdtSegmentFitter::Config::defaultRanges
static RangeArray defaultRanges()
Function that returns a set of predefined ranges for testing.
Definition: MdtSegmentFitter.cxx:40
MuonR4::AmgSymMatrix
const AmgSymMatrix(2) &SpacePoint
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:150
MuonR4::MdtSegmentFitter::recalibrate
bool recalibrate(const EventContext &ctx, SegmentFitResult &fitResult) const
Recalibrate the measurements participating in the fit & shift them into the centre-of gravity frame.
Definition: MdtSegmentFitter.cxx:62
MuonR4::MdtSegmentFitter::updateParameters
UpdateStatus updateParameters(Parameters &currentPars, Parameters &previousPars, Parameters &currGrad, Parameters &prevGrad, const AmgSymMatrix(5)&hessian) const
Update step of the segment parameters using the Hessian and the gradient.
Definition: MdtSegmentFitter.cxx:616
MuonR4::MdtSegmentFitter::ResidualWithPartials::hessian
std::array< Amg::Vector3D, sumUp(nPars)> hessian
Second order derivatives.
Definition: MdtSegmentFitter.h:95
MuonR4::SegmentFit::ParamDefs::nPars
@ nPars
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
MuonR4::CalibratedSpacePoint::Covariance_t
std::variant< AmgSymMatrix(2), AmgSymMatrix(3)> Covariance_t
The spatial covariance matrix of the calibrated space point.
Definition: CalibratedSpacePoint.h:49
MuonR4::MdtSegmentFitter::updateLinePartials
static void updateLinePartials(const Parameters &fitPars, LineWithPartials &line)
Updates the line parameters together with its first & second order partial derivatives.
Definition: MdtSegmentFitter.cxx:119