Back to home page

sPhenix code displayed by LXR

 
 

    


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

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_KalmanFitterInfo_h
0024 #define genfit_KalmanFitterInfo_h
0025 
0026 #include "AbsFitterInfo.h"
0027 #include "KalmanFittedStateOnPlane.h"
0028 #include "MeasuredStateOnPlane.h"
0029 #include "MeasurementOnPlane.h"
0030 #include "ReferenceStateOnPlane.h"
0031 #include "StateOnPlane.h"
0032 
0033 #include <vector>
0034 
0035 #include <memory>
0036 
0037 
0038 namespace genfit {
0039 
0040 
0041 /**
0042  *  @brief Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one AbsTrackRep of the Track.
0043  */
0044 class KalmanFitterInfo : public AbsFitterInfo {
0045 
0046  public:
0047 
0048   KalmanFitterInfo();
0049   KalmanFitterInfo(const TrackPoint* trackPoint, const AbsTrackRep* rep);
0050   virtual ~KalmanFitterInfo();
0051 
0052   virtual KalmanFitterInfo* clone() const override;
0053 
0054   ReferenceStateOnPlane* getReferenceState() const {return referenceState_.get();}
0055   MeasuredStateOnPlane* getForwardPrediction() const {return forwardPrediction_.get();}
0056   MeasuredStateOnPlane* getBackwardPrediction() const {return backwardPrediction_.get();}
0057   MeasuredStateOnPlane* getPrediction(int direction) const {if (direction >=0) return forwardPrediction_.get(); return backwardPrediction_.get();}
0058   KalmanFittedStateOnPlane* getForwardUpdate() const {return forwardUpdate_.get();}
0059   KalmanFittedStateOnPlane* getBackwardUpdate() const {return backwardUpdate_.get();}
0060   KalmanFittedStateOnPlane* getUpdate(int direction) const {if (direction >=0) return forwardUpdate_.get(); return backwardUpdate_.get();}
0061   const std::vector< genfit::MeasurementOnPlane* >& getMeasurementsOnPlane() const {return measurementsOnPlane_;}
0062   MeasurementOnPlane* getMeasurementOnPlane(int i = 0) const {if (i<0) i += measurementsOnPlane_.size(); return measurementsOnPlane_.at(i);}
0063   //! Get weighted mean of all measurements.
0064   //! @param ignoreWeights If set, the weights of the individual measurements will be ignored (they will be treated as if they all had weight 1)
0065   MeasurementOnPlane getAvgWeightedMeasurementOnPlane(bool ignoreWeights = false) const;
0066   //! Get measurements which is closest to state.
0067   MeasurementOnPlane* getClosestMeasurementOnPlane(const StateOnPlane*) const;
0068   unsigned int getNumMeasurements() const {return measurementsOnPlane_.size();}
0069   //! Get weights of measurements.
0070   std::vector<double> getWeights() const;
0071   //! Are the weights fixed?
0072   bool areWeightsFixed() const {return fixWeights_;}
0073   //! Get unbiased or biased (default) smoothed state.
0074   const MeasuredStateOnPlane& getFittedState(bool biased = true) const override;
0075   //! Get unbiased (default) or biased residual from ith measurement.
0076   MeasurementOnPlane getResidual(unsigned int iMeasurement = 0, bool biased = false, bool onlyMeasurementErrors = true) const override; // calculate residual, track and measurement errors are added if onlyMeasurementErrors is false
0077   double getSmoothedChi2(unsigned int iMeasurement = 0) const;
0078 
0079   bool hasMeasurements() const override {return getNumMeasurements() > 0;}
0080   bool hasReferenceState() const override {return (referenceState_.get() != nullptr);}
0081   bool hasForwardPrediction() const override {return (forwardPrediction_.get()  != nullptr);}
0082   bool hasBackwardPrediction() const override {return (backwardPrediction_.get() != nullptr);}
0083   bool hasForwardUpdate() const override {return (forwardUpdate_.get() != nullptr);}
0084   bool hasBackwardUpdate() const override {return (backwardUpdate_.get() != nullptr);}
0085   bool hasUpdate(int direction) const override {if (direction < 0) return hasBackwardUpdate(); return hasForwardUpdate();}
0086   bool hasPredictionsAndUpdates() const {return (hasForwardPrediction() && hasBackwardPrediction() && hasForwardUpdate() && hasBackwardUpdate());}
0087 
0088   void setReferenceState(ReferenceStateOnPlane* referenceState);
0089   void setForwardPrediction(MeasuredStateOnPlane* forwardPrediction);
0090   void setBackwardPrediction(MeasuredStateOnPlane* backwardPrediction);
0091   void setPrediction(MeasuredStateOnPlane* prediction, int direction)  {if (direction >=0) setForwardPrediction(prediction); else setBackwardPrediction(prediction);}
0092   void setForwardUpdate(KalmanFittedStateOnPlane* forwardUpdate);
0093   void setBackwardUpdate(KalmanFittedStateOnPlane* backwardUpdate);
0094   void setUpdate(KalmanFittedStateOnPlane* update, int direction)  {if (direction >=0) setForwardUpdate(update); else setBackwardUpdate(update);}
0095   void setMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane* >& measurementsOnPlane);
0096   void addMeasurementOnPlane(MeasurementOnPlane* measurementOnPlane);
0097   void addMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane* >& measurementsOnPlane);
0098   //! Set weights of measurements.
0099   void setWeights(const std::vector<double>&);
0100   void fixWeights(bool arg = true) {fixWeights_ = arg;}
0101   void setRep(const AbsTrackRep* rep) override;
0102 
0103   void deleteForwardInfo() override;
0104   void deleteBackwardInfo() override;
0105   void deletePredictions();
0106   void deleteReferenceInfo() override {setReferenceState(nullptr);}
0107   void deleteMeasurementInfo() override;
0108 
0109   virtual void Print(const Option_t* = "") const override;
0110 
0111   virtual bool checkConsistency(const genfit::PruneFlags* = nullptr) const override;
0112 
0113  private:
0114 
0115   //! Reference state. Used by KalmanFitterRefTrack.
0116   std::unique_ptr<ReferenceStateOnPlane> referenceState_; // Ownership
0117   std::unique_ptr<MeasuredStateOnPlane> forwardPrediction_; // Ownership
0118   std::unique_ptr<KalmanFittedStateOnPlane> forwardUpdate_; // Ownership
0119   std::unique_ptr<MeasuredStateOnPlane> backwardPrediction_; // Ownership
0120   std::unique_ptr<KalmanFittedStateOnPlane> backwardUpdate_; // Ownership
0121   mutable std::unique_ptr<MeasuredStateOnPlane> fittedStateUnbiased_; //!  cache
0122   mutable std::unique_ptr<MeasuredStateOnPlane> fittedStateBiased_; //!  cache
0123 
0124  //> TODO ! ptr implement: to the special ownership version
0125   /* class owned_pointer_vector : private std::vector<MeasuredStateOnPlane*> {
0126    public: 
0127     ~owned_pointer_vector() { for (size_t i = 0; i < this->size(); ++i)
0128                          delete this[i]; }
0129     size_t size() const { return this->size(); };
0130     void push_back(MeasuredStateOnPlane* measuredState) { this->push_back(measuredState); };
0131     const  MeasuredStateOnPlane* at(size_t i)  const { return this->at(i); }; 
0132     //owned_pointer_vector::iterator erase(owned_pointer_vector::iterator position) ;
0133     //owned_pointer_vector::iterator erase(owned_pointer_vector::iterator first, owned_pointer_vector::iterator last);
0134 };
0135     */
0136 
0137   std::vector<MeasurementOnPlane*> measurementsOnPlane_; // Ownership
0138   bool fixWeights_; // weights should not be altered by fitters anymore
0139 
0140  public:
0141 
0142   ClassDefOverride(KalmanFitterInfo,1)
0143 
0144 };
0145 
0146 } /* End of namespace genfit */
0147 /** @} */
0148 
0149 #endif // genfit_KalmanFitterInfo_h