Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /* Copyright 2008-2010, Technische Universitaet Muenchen,
0002  *   Authors: Christian Hoeppner & Sebastian Neubert & 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_GblFitterInfo_h
0024 #define genfit_GblFitterInfo_h
0025 
0026 #include "AbsFitterInfo.h"
0027 #include "MeasuredStateOnPlane.h"
0028 #include "MeasurementOnPlane.h"
0029 #include "StateOnPlane.h"
0030 #include "TrackPoint.h"
0031 #include "ThinScatterer.h"
0032 #include "StateOnPlane.h"
0033 #include "Track.h"
0034 #include "ICalibrationParametersDerivatives.h"
0035 #include "GblPoint.h"
0036 #include "GblTrajectory.h"
0037 #include "GblFitter.h"
0038 #include "TMatrixD.h"
0039 #include "TMatrixDSym.h"
0040 #include "AbsHMatrix.h"
0041 
0042 #include <vector>
0043 #include <memory>
0044 
0045 
0046 namespace genfit {
0047   
0048   
0049   /**
0050    *  @brief Collects information needed and produced by a GblFitter/GBL and is specific to one AbsTrackRep of the Track.
0051    */
0052   class GblFitterInfo : public AbsFitterInfo {
0053     
0054   public:
0055     
0056     /**
0057      * @brief Constructor for ROOT I/O 
0058      */
0059     GblFitterInfo();
0060     
0061     /**
0062      * @brief Default (inherited) constructor
0063      * Should not be used or the reference should set immediately upon
0064      * construction (to set the plane).
0065      */
0066     GblFitterInfo(const TrackPoint* trackPoint, const AbsTrackRep* rep);
0067     
0068     /**
0069      * @brief Default user constructor
0070      * 
0071      * @param trackPoint The point at track to attach fitter info.
0072      * @param rep The representation this fitter info belongs to
0073      * @param referenceState State from extrapolation to init predictions and plane
0074      */
0075     GblFitterInfo(const TrackPoint* trackPoint, const AbsTrackRep* rep, StateOnPlane& referenceState);
0076     
0077     /**
0078      * @brief (Initial) reset of fitter info
0079      * 
0080      * @param measurementDim Measurement dimesion (2)
0081      * @param repDim Representation dimesion (5)
0082      * @return void
0083      */
0084     void reset(unsigned int measurementDim = 2, unsigned int repDim = 5);
0085         
0086     /**
0087      * @brief Set the prediction and plane (from measurement if any)
0088      * You should use the user constructor instead.
0089      * 
0090      * Reference gets not updated internally in fitter info.
0091      * After updateFitResults(...), updates affect the +/- predictions directly.
0092      * 
0093      * Should be called only once (so rather use constructor).
0094      * Otherwise will rewrite fitted state by reference (and you have to update from fit again)
0095      * 
0096      * @param referenceState StateOnPlane from extrapolation to this point
0097      * @return void
0098      */
0099     void setReferenceState(StateOnPlane& referenceState);
0100     /**
0101      * @brief Set the Jacobian for further GblPoint construction
0102      * 
0103      * @param jacobian 5x5 TMatrixD with Jacobian for propagation of the state from previous point
0104      *                 to this point.
0105      * @return void
0106      */
0107     void setJacobian(TMatrixD jacobian);
0108     
0109     /**
0110      * @brief Get scattering covariance projected into (measurement) plane
0111      * 
0112      * @param variance Variance of slopes in track frame
0113      * @param trackDirection Direction of the track at the plane
0114      * @param measurementPlane The plane with measurement to which MS shall be projected
0115      * @return TMatrixDSym
0116      */
0117     TMatrixDSym getCovariance(double variance, TVector3 trackDirection, SharedPlanePtr measurementPlane) const;
0118     
0119     /**
0120      * @brief Collect all data and create a GblPoint
0121      * - Jacobian is taken from fitter info ... use setJaobian() to change it
0122      * - A scatterer is added if ThinScatterer at point
0123      * - A measurement (first MeasurementOnPlane in 1st RawMeasurement) is added.
0124      * - Global and local derivatives are added for RawMesurement implementing
0125      *   ICalibrationParametersDerivatives interface. Using most up to date prediction.
0126      * 
0127      * @return gbl::GblPoint
0128      */
0129     gbl::GblPoint constructGblPoint();
0130   
0131     /**
0132      * @brief Update fitter info from GBL fit results
0133      * 
0134      * Locates itself in track/trajectory and updates
0135      * predictions, errors, etc.
0136      * 
0137      * @param traj Fitted GblTrajectory constructed with this point
0138      * @return void
0139      */
0140     void updateFitResults(gbl::GblTrajectory& traj);
0141     
0142     /**
0143      * @brief Get the prediction at this point
0144      * Always biased in GBL (global fit)
0145      * There are 2 states, before and after kink (if there is
0146      * a scatterer at this point).
0147      * Per default the state after kink for forward propagation
0148      * is returned.
0149      * 
0150      * If not yet fitted, returns the reference state
0151      * 
0152      * @param afterKink If true, returns prediction for forward propagation.
0153      *                  If false, for backward
0154      * @return const genfit::MeasuredStateOnPlane&
0155      */
0156     const MeasuredStateOnPlane& getFittedState(bool afterKink = true) const override;
0157 
0158     /**
0159      * @brief Get the residual
0160      * 
0161      * Temporarily constructs measurements
0162      * and calculates residual as meas - prediction.
0163      * 
0164      * Always biased. Always only one (1st) measurement!
0165      * 
0166      * @param  ...
0167      * @param  ...
0168      * @param onlyMeasurementErrors If true, covariance of measurement returned.
0169      *                              If false, diagonalized residual error incl. correlation from track fit is returned.
0170      * @return genfit::MeasurementOnPlane
0171      */
0172     MeasurementOnPlane getResidual(unsigned int = 0, bool = false, bool onlyMeasurementErrors = true) const override;
0173     
0174     /**
0175      * @brief Get kink (residual) with diagonalized covariance (2D)
0176      * Covariance may be zero if not yet fitted or no scatterer!
0177      * 
0178      * @return genfit::MeasurementOnPlane
0179      */
0180     MeasurementOnPlane getKink() const;
0181     
0182     /**
0183      * @brief Get kink (residual) (2D)
0184      * = 0 - ( (+)pred - (-)pred )
0185      * 
0186      * @return TVectorD
0187      */
0188     TVectorD getKinks() const;
0189     
0190     /**
0191      * @brief Get the measurement on plane from stored
0192      * measurement data (from last construction/update)
0193      * 
0194      * @return genfit::MeasuredStateOnPlane
0195      */
0196     MeasurementOnPlane getMeasurement() const;
0197     
0198     /**
0199      * @brief SHOULD BE USED ONLY INTERNALY!
0200      * Update the plane from measurement constructed with state
0201      * or take plane from state if there is no measurement.
0202      * 1st raw Measurement with highest weight is constructed and stored as matrices.
0203      * 
0204      * @return void
0205      */
0206     void updateMeasurementAndPlane(const StateOnPlane & sop);
0207 
0208     /**
0209      * @brief Returns (copy of) the stored reference 5D state at current plane with internal rep
0210      * 
0211      * @return genfit::StateOnPlane
0212      */
0213     StateOnPlane getReferenceState() const {return StateOnPlane(refPrediction_, sharedPlane_, rep_);}
0214     
0215     /**
0216      * @brief Re-extrapolates between prevFitterInfo and this point using
0217      * forward state to update the Jacobian (if planes and/or states changed,
0218      * internal predictions are extrapolated to new planes)
0219      * 
0220      * @param prevFitterInfo Pointer to GblFitterInfo of previous point
0221      * @return void
0222      */
0223     void recalculateJacobian(GblFitterInfo* prevFitterInfo);
0224     
0225     virtual ~GblFitterInfo() {;}
0226     virtual GblFitterInfo* clone() const override;
0227     bool hasMeasurements() const override {return trackPoint_->hasRawMeasurements();}
0228     bool hasReferenceState() const override {return (refPrediction_(0) != 0.);}
0229     bool hasForwardPrediction() const override {return hasReferenceState();}
0230     bool hasBackwardPrediction() const override {return hasReferenceState();}
0231     bool hasForwardUpdate() const override {return hasForwardPrediction();}
0232     bool hasBackwardUpdate() const override {return hasBackwardPrediction();}
0233     bool hasUpdate(int direction) const override {if (direction < 0) return hasBackwardPrediction(); return hasForwardPrediction();}
0234     bool hasPredictionsAndUpdates() const {return (hasForwardPrediction() && hasBackwardPrediction() && hasForwardUpdate() && hasBackwardUpdate());}
0235 
0236     void deleteForwardInfo() override {;}
0237     void deleteBackwardInfo() override {;}
0238     void deletePredictions() {
0239       deleteBackwardInfo();
0240       deleteForwardInfo();
0241     }
0242     void deleteReferenceInfo() override {;} // Empty because we really do not want to delete reference without a new one
0243     void deleteMeasurementInfo() override {;} // We do not keep the measurements
0244     virtual void Print(const Option_t* = "") const override;
0245     virtual bool checkConsistency(const genfit::PruneFlags* = nullptr) const override;
0246        
0247   private:
0248     TMatrixD jacobian_;
0249     TVectorD measResiduals_;
0250     TVectorD measResidualErrors_;
0251     TVectorD kinkResiduals_;
0252     TVectorD kinkResidualErrors_;
0253     TVectorD measDownWeights_;
0254     TVectorD kinkDownWeights_;
0255     TVectorD bwdStateCorrection_;
0256     TVectorD fwdStateCorrection_;
0257     TMatrixDSym bwdCov_;
0258     TMatrixDSym fwdCov_;
0259     TVectorD fwdPrediction_;
0260     TVectorD bwdPrediction_;
0261     TVectorD refPrediction_;
0262     
0263     TVectorD measurement_;
0264     TMatrixDSym measCov_;
0265     TMatrixD hMatrix_;
0266 
0267     mutable std::unique_ptr<MeasuredStateOnPlane> fittedStateBwd_; //!  cache
0268     mutable std::unique_ptr<MeasuredStateOnPlane> fittedStateFwd_; //!  cache
0269     
0270   public:
0271     
0272     ClassDefOverride(GblFitterInfo, 1)
0273     
0274   };
0275   
0276 } /* End of namespace genfit */
0277 /** @} */
0278 
0279 #endif // genfit_GblFitterInfo_h