EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KalmanFitterInfo.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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"
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 
57  MeasuredStateOnPlane* getPrediction(int direction) const {if (direction >=0) return forwardPrediction_.get(); return backwardPrediction_.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();}
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