Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:23

0001 /* Copyright 2013, Ludwig-Maximilians Universität München,
0002    Authors: Tobias Schlüter & Johannes Rauch
0003 
0004    This file is part of GENFIT.
0005 
0006    GENFIT is free software: you can redistribute it and/or modify
0007    it under the terms of the GNU Lesser General Public License as published
0008    by the Free Software Foundation, either version 3 of the License, or
0009    (at your option) any later version.
0010 
0011    GENFIT is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014    GNU Lesser General Public License for more details.
0015 
0016    You should have received a copy of the GNU Lesser General Public License
0017    along with GENFIT.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 /** @addtogroup genfit
0020  * @{
0021  */
0022 
0023 #ifndef genfit_KalmanFitterRefTrack_h
0024 #define genfit_KalmanFitterRefTrack_h
0025 
0026 #include "AbsKalmanFitter.h"
0027 
0028 
0029 namespace genfit {
0030 
0031 class KalmanFitterInfo;
0032 class TrackPoint;
0033 
0034 /**
0035  * @brief Kalman filter implementation with linearization around a reference track
0036  */
0037 class KalmanFitterRefTrack : public AbsKalmanFitter {
0038  public:
0039   KalmanFitterRefTrack(unsigned int maxIterations = 4, double deltaPval = 1e-3, double blowUpFactor = 1e3,
0040                bool squareRootFormalism = false)
0041     : AbsKalmanFitter(maxIterations, deltaPval, blowUpFactor), refitAll_(false), deltaChi2Ref_(1),
0042       squareRootFormalism_(squareRootFormalism)
0043   {}
0044 
0045   virtual ~KalmanFitterRefTrack() {}
0046 
0047   /** @brief Fit the track.
0048    *
0049    * Needs a prepared track! Return last TrackPoint that has been processed.
0050    */
0051   TrackPoint* fitTrack(Track* tr, const AbsTrackRep* rep, double& chi2, double& ndf, int direction);
0052 
0053   void processTrackWithRep(Track* tr, const AbsTrackRep* rep, bool resortHits = false) override;
0054 
0055   /** @brief Prepare the track
0056    *
0057    * Calc all reference states.
0058    * If setSortingParams is true, the extrapolation lengths will be set as sorting parameters
0059    * of the TrackPoints.
0060    * Returns if the track has been changed.
0061    */
0062   bool prepareTrack(Track* tr, const AbsTrackRep* rep, bool setSortingParams, int& nFailedHits);
0063 
0064   //! If true always refit all points, otherwise fit points only if reference states have changed
0065   void setRefitAll(bool refit = true) {refitAll_ = refit;}
0066 
0067   /**
0068    * When will the reference track be updated?
0069    * If (smoothedState - referenceState) * smoothedCov^(-1) * (smoothedState - referenceState)^T >= deltaChi2Ref_.
0070    */
0071   void setDeltaChi2Ref(double dChi2) {deltaChi2Ref_ = dChi2;}
0072 
0073  private:
0074   void processTrackPoint(KalmanFitterInfo* fi, const KalmanFitterInfo* prevFi, const TrackPoint* tp, double& chi2, double& ndf, int direction);
0075   void processTrackPointSqrt(KalmanFitterInfo* fi, const KalmanFitterInfo* prevFi, const TrackPoint* tp, double& chi2, double& ndf, int direction);
0076 
0077   /**
0078    * @brief Remove referenceStates if they are too far from smoothed states.
0079    *
0080    * Does NOT remove forward and backward info, but returns from/to where they have to be removed later
0081    * Return if anything has changed.
0082    */
0083   bool removeOutdated(Track* tr, const AbsTrackRep* rep, int& notChangedUntil, int& notChangedFrom);
0084 
0085   //! If refitAll_, remove all information.
0086   void removeForwardBackwardInfo(Track* tr, const AbsTrackRep* rep, int notChangedUntil, int notChangedFrom) const;
0087 
0088   bool refitAll_; // always refit all points or only if reference states have changed
0089   double deltaChi2Ref_; // reference track update cut
0090 
0091   // aux variables for prepareTrack
0092   TMatrixD FTransportMatrix_; //!
0093   TMatrixD BTransportMatrix_; //!
0094   TMatrixDSym FNoiseMatrix_; //!
0095   TMatrixDSym BNoiseMatrix_; //!
0096   TVectorD forwardDeltaState_; //!
0097   TVectorD backwardDeltaState_; //!
0098 
0099   // aux variables for processTrackPoint
0100   TVectorD p_; //!
0101   TMatrixDSym C_; //!
0102   TMatrixDSym covSumInv_; //!
0103   TMatrixDSym Rinv_; //!
0104   TVectorD res_; //!
0105 
0106   // aux variables for removeOutdated
0107   TVectorD resM_; //!
0108 
0109   bool squareRootFormalism_;
0110 
0111  public:
0112   ClassDefOverride(KalmanFitterRefTrack, 1)
0113 
0114 };
0115 
0116 }  /* End of namespace genfit */
0117 /** @} */
0118 
0119 #endif //genfit_KalmanFitterRefTrack_h