Belle II Software  release-08-01-10
KalmanFitterInfo.h
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
23 #ifndef genfit_KalmanFitterInfo_h
24 #define genfit_KalmanFitterInfo_h
25 
26 #include "AbsFitterInfo.h"
27 #include "KalmanFittedStateOnPlane.h"
28 #include "MeasuredStateOnPlane.h"
29 #include "MeasurementOnPlane.h"
30 #include "ReferenceStateOnPlane.h"
31 #include "StateOnPlane.h"
32 
33 #include <vector>
34 
35 #include <memory>
36 
37 
38 namespace genfit {
39 
40 
45 
46  public:
47 
49  KalmanFitterInfo(const TrackPoint* trackPoint, const AbsTrackRep* rep);
50  virtual ~KalmanFitterInfo();
51 
52  virtual KalmanFitterInfo* clone() const override;
53 
54  ReferenceStateOnPlane* getReferenceState() const {return referenceState_.get();}
55  MeasuredStateOnPlane* getForwardPrediction() const {return forwardPrediction_.get();}
56  MeasuredStateOnPlane* getBackwardPrediction() const {return backwardPrediction_.get();}
57  MeasuredStateOnPlane* getPrediction(int direction) const {if (direction >=0) return forwardPrediction_.get(); return backwardPrediction_.get();}
58  KalmanFittedStateOnPlane* getForwardUpdate() const {return forwardUpdate_.get();}
59  KalmanFittedStateOnPlane* getBackwardUpdate() const {return backwardUpdate_.get();}
60  KalmanFittedStateOnPlane* getUpdate(int direction) const {if (direction >=0) return forwardUpdate_.get(); return backwardUpdate_.get();}
61  const std::vector< genfit::MeasurementOnPlane* >& getMeasurementsOnPlane() const {return measurementsOnPlane_;}
62  MeasurementOnPlane* getMeasurementOnPlane(int i = 0) const {if (i<0) i += measurementsOnPlane_.size(); return measurementsOnPlane_.at(i);}
65  MeasurementOnPlane getAvgWeightedMeasurementOnPlane(bool ignoreWeights = false) const;
68  unsigned int getNumMeasurements() const {return measurementsOnPlane_.size();}
70  std::vector<double> getWeights() const;
72  bool areWeightsFixed() const {return fixWeights_;}
74  const MeasuredStateOnPlane& getFittedState(bool biased = true) const override;
76  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
77  double getSmoothedChi2(unsigned int iMeasurement = 0) const;
78 
79  bool hasMeasurements() const override {return getNumMeasurements() > 0;}
80  bool hasReferenceState() const override {return (referenceState_.get() != nullptr);}
81  bool hasForwardPrediction() const override {return (forwardPrediction_.get() != nullptr);}
82  bool hasBackwardPrediction() const override {return (backwardPrediction_.get() != nullptr);}
83  bool hasForwardUpdate() const override {return (forwardUpdate_.get() != nullptr);}
84  bool hasBackwardUpdate() const override {return (backwardUpdate_.get() != nullptr);}
85  bool hasUpdate(int direction) const override {if (direction < 0) return hasBackwardUpdate(); return hasForwardUpdate();}
86  bool hasPredictionsAndUpdates() const {return (hasForwardPrediction() && hasBackwardPrediction() && hasForwardUpdate() && hasBackwardUpdate());}
87 
88  void setReferenceState(ReferenceStateOnPlane* referenceState);
89  void setForwardPrediction(MeasuredStateOnPlane* forwardPrediction);
90  void setBackwardPrediction(MeasuredStateOnPlane* backwardPrediction);
91  void setPrediction(MeasuredStateOnPlane* prediction, int direction) {if (direction >=0) setForwardPrediction(prediction); else setBackwardPrediction(prediction);}
92  void setForwardUpdate(KalmanFittedStateOnPlane* forwardUpdate);
93  void setBackwardUpdate(KalmanFittedStateOnPlane* backwardUpdate);
94  void setUpdate(KalmanFittedStateOnPlane* update, int direction) {if (direction >=0) setForwardUpdate(update); else setBackwardUpdate(update);}
95  void setMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane* >& measurementsOnPlane);
96  void addMeasurementOnPlane(MeasurementOnPlane* measurementOnPlane);
97  void addMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane* >& measurementsOnPlane);
99  void setWeights(const std::vector<double>&);
100  void fixWeights(bool arg = true) {fixWeights_ = arg;}
101  void setRep(const AbsTrackRep* rep) override;
102 
103  void deleteForwardInfo() override;
104  void deleteBackwardInfo() override;
105  void deletePredictions();
106  void deleteReferenceInfo() override {setReferenceState(nullptr);}
107  void deleteMeasurementInfo() override;
108 
109  virtual void Print(const Option_t* = "") const override;
110 
111  virtual bool checkConsistency(const genfit::PruneFlags* = nullptr) const override;
112 
113  private:
114 
116  std::unique_ptr<ReferenceStateOnPlane> referenceState_; // Ownership
117  std::unique_ptr<MeasuredStateOnPlane> forwardPrediction_; // Ownership
118  std::unique_ptr<KalmanFittedStateOnPlane> forwardUpdate_; // Ownership
119  std::unique_ptr<MeasuredStateOnPlane> backwardPrediction_; // Ownership
120  std::unique_ptr<KalmanFittedStateOnPlane> backwardUpdate_; // Ownership
121  mutable std::unique_ptr<MeasuredStateOnPlane> fittedStateUnbiased_;
122  mutable std::unique_ptr<MeasuredStateOnPlane> fittedStateBiased_;
123 
124  //> TODO ! ptr implement: to the special ownership version
125  /* class owned_pointer_vector : private std::vector<MeasuredStateOnPlane*> {
126  public:
127  ~owned_pointer_vector() { for (size_t i = 0; i < this->size(); ++i)
128  delete this[i]; }
129  size_t size() const { return this->size(); };
130  void push_back(MeasuredStateOnPlane* measuredState) { this->push_back(measuredState); };
131  const MeasuredStateOnPlane* at(size_t i) const { return this->at(i); };
132  //owned_pointer_vector::iterator erase(owned_pointer_vector::iterator position) ;
133  //owned_pointer_vector::iterator erase(owned_pointer_vector::iterator first, owned_pointer_vector::iterator last);
134 };
135  */
136 
137  std::vector<MeasurementOnPlane*> measurementsOnPlane_; // Ownership
138  bool fixWeights_; // weights should not be altered by fitters anymore
139 
140  public:
141 
142  ClassDefOverride(KalmanFitterInfo,1)
143 
144 };
145 
146 } /* End of namespace genfit */
149 #endif // genfit_KalmanFitterInfo_h
This class collects all information needed and produced by a specific AbsFitter and is specific to on...
Definition: AbsFitterInfo.h:42
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
#MeasuredStateOnPlane with additional info produced by a Kalman filter or DAF.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
MeasurementOnPlane getResidual(unsigned int iMeasurement=0, bool biased=false, bool onlyMeasurementErrors=true) const override
Get unbiased (default) or biased residual from ith measurement.
void setWeights(const std::vector< double > &)
Set weights of measurements.
MeasurementOnPlane getAvgWeightedMeasurementOnPlane(bool ignoreWeights=false) const
Get weighted mean of all measurements.
MeasurementOnPlane * getClosestMeasurementOnPlane(const StateOnPlane *) const
Get measurements which is closest to state.
std::unique_ptr< ReferenceStateOnPlane > referenceState_
Reference state. Used by KalmanFitterRefTrack.
std::vector< MeasurementOnPlane * > measurementsOnPlane_
cache
std::unique_ptr< MeasuredStateOnPlane > fittedStateBiased_
cache
virtual KalmanFitterInfo * clone() const override
Deep copy ctor for polymorphic class.
const MeasuredStateOnPlane & getFittedState(bool biased=true) const override
Get unbiased or biased (default) smoothed state.
std::vector< double > getWeights() const
Get weights of measurements.
bool areWeightsFixed() const
Are the weights fixed?
#StateOnPlane with additional covariance matrix.
Measured coordinates on a plane.
#StateOnPlane with linearized transport to that #ReferenceStateOnPlane from previous and next #Refere...
A state with arbitrary dimension defined in a DetPlane.
Definition: StateOnPlane.h:47
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
Defines for I/O streams used for error and debug printing.
Info which information has been pruned from the Track.
Definition: FitStatus.h:47