GFKalman.h
Go to the documentation of this file.
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert
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 */
19 /** @addtogroup genfit
20  * @{
21  */
22 
23 #ifndef GFKALMAN_H
24 #define GFKALMAN_H
25 
26 #include <iostream>
28 
29 #include "RtypesCore.h"
30 #include "TMatrixT.h"
31 
32 /** @brief Generic Kalman Filter implementation
33  *
34  * @author Christian H&ouml;ppner (Technische Universit&auml;t M&uuml;nchen, original author)
35  * @author Sebastian Neubert (Technische Universit&auml;t M&uuml;nchen, original author)
36  *
37  * The Kalman Filter operates on genfit GFTrack objects. It is an implementation
38  * of the Kalman Filter algebra that uses the genfit interface classes
39  * GFAbsRecoHit and GFAbsTrackRep in order to be independent from the specific
40  * detector geometry and the details of the track parameterization /
41  * track extraoplation engine.
42  *
43  * The Kalman Filter can use hits from several detectors in a single fit
44  * to estimate the parameters of several track representations in parallel.
45  */
46 
47 namespace genf {
48 
49 class GFAbsRecoHit;
50 class GFAbsTrackRep;
51 class GFTrack;
52 
53 class GFKalman {
54 public:
55 
56  //friend class KalmanTester; // gives the Tester access to private methods
57 
58  // Constructors/Destructors ---------
59  GFKalman();
60  ~GFKalman();
61 
62  // Operators
63  /** @brief Operator for use with STL.
64  *
65  * This operator allows to use the std::foreach algorithm with an
66  * STL container o GFTrack* objects.
67  */
68  inline void operator()(GFTrack* track){processTrack(track);}
69 
70  /** @brief Operator for use with STL.
71  *
72  * This operator allows to use the std::foreach algorithm with an
73  * STL container o GFTrack* objects.
74  */
75  inline void operator()(std::pair<int,GFTrack*> tr){processTrack(tr.second);}
76 
77  // Operations ----------------------
78 
79  /** @brief Switch lazy error handling.
80  *
81  * This is a historically left-over method and shall be deleted some time
82  */
83  void setLazy(Int_t /* flag */){std::cerr<<"Using outdates setLazy method of class GFKalman:"<<std::endl;}
84 
85  /** @brief Set number of iterations for Kalman Filter
86  *
87  * One iteration is one forward pass plus one backward pass
88  */
89  void setNumIterations(Int_t i){fNumIt=i;}
90 
91  /** @brief Performs fit on a GFTrack.
92  *
93  * The hits are processed in the order in which they are stored in the GFTrack
94  * object. Sorting of hits in space has to be done before!
95  */
96  void processTrack(GFTrack*);
97 
98  /** @brief Performs fit on a GFTrack beginning with the current hit.
99  */
100  void fittingPass(GFTrack*,int dir); // continues track from lastHitInFit
101 
102  /** @brief Calculates chi2 of a given hit with respect to a
103  * given track representation.
104  */
106 
107  /** @brief Sets the inital direction of the track fit (1 for inner to outer,
108  * or -1 for outer to inner). The standard is 1 and is set in the ctor
109  */
111 
112  /** @brief Set the blowup factor (see blowUpCovs() )
113  */
115  void setMomLow(Double_t f){fMomLow=f;}
116  void setMomHigh(Double_t f){fMomHigh=f;}
117  void setMaxUpdate(Double_t f){fMaxUpdate=f;}
118  void setErrorScaleSTh(Double_t f){fErrScaleSTh=f;}
119  void setErrorScaleMTh(Double_t f){fErrScaleMTh=f;}
120 
121  // Private Methods -----------------
122 private:
123  /** @brief One Kalman step.
124  *
125  * Performs
126  * - Extrapolation to detector plane of the hit
127  * - Calculation of residual and Kalman Gain
128  * - Update of track representation state and chi2
129  *
130  */
131  void processHit(GFTrack*, int, int, int);
132 
133  /** @brief Used to switch between forward and backward filtering
134  */
135  void switchDirection(GFTrack* trk); // switches the direction of propagation for all reps
136 
137  /** @brief Calculate Kalman Gain
138  */
139  TMatrixT<Double_t> calcGain(const TMatrixT<Double_t>& cov,
140  const TMatrixT<Double_t>& HitCov,
141  const TMatrixT<Double_t>& H);
142  TMatrixT<Double_t> calcCov7x7(const TMatrixT<Double_t>& cov, const genf::GFDetPlane& plane) ;
143 
144  /** @brief this returns the reduced chi2 increment for a hit
145  */
146  double chi2Increment(const TMatrixT<Double_t>& r,const TMatrixT<Double_t>& H,
147  const TMatrixT<Double_t>& cov,const TMatrixT<Double_t>& V);
148 
149  /** @brief this is needed to blow up the covariance matrix before a fitting pass
150  * drops off-diagonal elements and blows up diagonal by blowUpFactor
151  */
152  void blowUpCovs(GFTrack* trk);
153  void blowUpCovsDiag(GFTrack* trk);
154 
156  Int_t fNumIt;
158 
159  Double_t fMomLow;
160  Double_t fMomHigh;
161  Double_t fMaxUpdate;
162  Double_t fErrScaleSTh; // simulated theta error scale
163  Double_t fErrScaleMTh; // measured theta error scale
165  //TH1D* fUpdate;
166  //TH1D* fIhitvUpdate;
167 
168 };
169 
170 } // namespace genf
171 #endif
172 
173 /** @} */
void setMomLow(Double_t f)
Definition: GFKalman.h:115
void setMaxUpdate(Double_t f)
Definition: GFKalman.h:117
double getChi2Hit(GFAbsRecoHit *, GFAbsTrackRep *)
Calculates chi2 of a given hit with respect to a given track representation.
Definition: GFKalman.cxx:276
Double_t fErrScaleMTh
Definition: GFKalman.h:163
Generic Interface to magnetic fields in GENFIT.
Definition: GFAbsBField.h:35
void operator()(GFTrack *track)
Operator for use with STL.
Definition: GFKalman.h:68
void processHit(GFTrack *, int, int, int)
One Kalman step.
Definition: GFKalman.cxx:303
void setMomHigh(Double_t f)
Definition: GFKalman.h:116
TMatrixT< Double_t > calcGain(const TMatrixT< Double_t > &cov, const TMatrixT< Double_t > &HitCov, const TMatrixT< Double_t > &H)
Calculate Kalman Gain.
Definition: GFKalman.cxx:733
void fittingPass(GFTrack *, int dir)
Performs fit on a GFTrack beginning with the current hit.
Definition: GFKalman.cxx:177
void setLazy(Int_t)
Switch lazy error handling.
Definition: GFKalman.h:83
string dir
void blowUpCovs(GFTrack *trk)
this is needed to blow up the covariance matrix before a fitting pass drops off-diagonal elements and...
Definition: GFKalman.cxx:154
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:83
int fInitialDirection
Definition: GFKalman.h:155
Double_t fMomLow
Definition: GFKalman.h:159
Double_t fMaxUpdate
Definition: GFKalman.h:161
Double_t fErrScaleSTh
Definition: GFKalman.h:162
void switchDirection(GFTrack *trk)
Used to switch between forward and backward filtering.
Definition: GFKalman.cxx:125
void setBlowUpFactor(double f)
Set the blowup factor (see blowUpCovs() )
Definition: GFKalman.h:114
double chi2Increment(const TMatrixT< Double_t > &r, const TMatrixT< Double_t > &H, const TMatrixT< Double_t > &cov, const TMatrixT< Double_t > &V)
this returns the reduced chi2 increment for a hit
Definition: GFKalman.cxx:222
void setNumIterations(Int_t i)
Set number of iterations for Kalman Filter.
Definition: GFKalman.h:89
void processTrack(GFTrack *)
Performs fit on a GFTrack.
Definition: GFKalman.cxx:46
void blowUpCovsDiag(GFTrack *trk)
Definition: GFKalman.cxx:132
double fBlowUpFactor
Definition: GFKalman.h:157
bool fGENfPRINT
Definition: GFKalman.h:164
Double_t fMomHigh
Definition: GFKalman.h:160
void setInitialDirection(int d)
Sets the inital direction of the track fit (1 for inner to outer, or -1 for outer to inner)...
Definition: GFKalman.h:110
TMatrixT< Double_t > calcCov7x7(const TMatrixT< Double_t > &cov, const genf::GFDetPlane &plane)
Definition: GFKalman.cxx:671
void setErrorScaleSTh(Double_t f)
Definition: GFKalman.h:118
void operator()(std::pair< int, GFTrack * > tr)
Operator for use with STL.
Definition: GFKalman.h:75
void setErrorScaleMTh(Double_t f)
Definition: GFKalman.h:119
QTextStream & endl(QTextStream &s)
Int_t fNumIt
Definition: GFKalman.h:156