All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GFAbsTrackRep.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 
20 /** @addtogroup genfit
21  * @{
22  */
23 
24 #ifndef GFABSTRACKREP_H
25 #define GFABSTRACKREP_H
26 
27 #include<stdexcept> // std::logic_error
28 #include<iostream>
29 
30 #include "TMatrixT.h"
31 #include "TVector3.h"
32 
34 
35 //class genf::GFAbsRecoHit;
36 
37 namespace genf {
38 
39 
40 
41 /** @brief Base Class for genfit track representations.
42  * Defines interface for track parameterizations.
43  *
44  * @author Christian H&ouml;ppner (Technische Universit&auml;t M&uuml;nchen, original author)
45  * @author Sebastian Neubert (Technische Universit&auml;t M&uuml;nchen, original author)
46  *
47  * It is important to understand the difference between a track and a
48  * track representation in genfit:
49  * - A track representation is a specific parameterization of a trajectory.
50  * It contains the parameters that describe the track at some point and
51  * code for the extrapolation of the track parameters through space.
52  * The actual extrapolation code is not part of genfit but has to be supplied
53  * in some additional package (e.g. GEANE). LSLTrackRep is a very basic example
54  * of a track representation.
55  * - A Track is a collection of RecoHits (see GFAbsRecoHit) plus a collection
56  * of track representation objects. The hits can be from different detectors.
57  * There can be several representations of the same track. This makes it
58  * possible to perform several fits in parallel, for example to compare
59  * different parameterizations or to fit different particle hypotheses.
60  *
61  * All track tepresentations must inherit GFAbsTrackRep to be available
62  * in genfit. Algorithms in genfit use this class as interface to
63  * access track parameters
64  *
65  * Provides:
66  * - Matrix objects to store track parameters
67  * - ... and covariances
68  * - interface to track extrapolation code
69  *
70  * The track extrapolation engine can be exchanged in genfit.
71  * Or one can even use more than one engine in parallel!
72  * In order to use a track extrapolation engine (like e.g. GEANE) with genfit
73  * one has to write a TrackRep class that inherits from GFAbsTrackRep. This makes
74  * it possible to uses different track extrapolation codes within a unified
75  * framework without major changes in the detector code.
76  *
77  * There is only one thing one has to do to use a specific track
78  * representation together with the hits from a detector:
79  * add the respective code in the GFAbsRecoHit::getHMatrix method implementation
80  * of the RecoHit in question.
81  */
82 
83 class GFAbsTrackRep : public TObject{
84 
85  /*----- Data members -----*/
86  protected:
87  //! Dimensionality of track representation
88  unsigned int fDimension;
89 
90  //! The vector of track parameters
91  TMatrixT<Double_t> fState;
92 
93  //! The covariance matrix
94  TMatrixT<Double_t> fCov;
95 
96  //! chiSqu of the track fit
97  double fChiSqu;
98  unsigned int fNdf;
99 
100  //! status of track representation: 0 means everything's OK
102  //! specifies the direction of flight of the particle
103  bool fInverted;
104 
105  //!state, cov and plane for first and last point in fit
106  TMatrixT<Double_t> fFirstState;
107  TMatrixT<Double_t> fFirstCov;
108 
109  TMatrixT<Double_t> fLastState;
110  TMatrixT<Double_t> fLastCov;
113 
114  // detector plane where the track parameters are given
116 
117 
118 
119  public:
120  virtual GFAbsTrackRep* clone() const = 0;
121 
122  virtual GFAbsTrackRep* prototype() const = 0;
123 
124  //! returns the tracklength spanned in this extrapolation
125  /* ! There is a default implementation in GFAbsTrackRep.cxx which just drops
126  the predicted covaraiance. If your trackrep has a way to extrapolate
127  without giving a correct cov (that would be faster probably), please
128  overwrite it.
129  */
130  virtual double extrapolate(const GFDetPlane& plane, TMatrixT<Double_t>& statePred);
131 
132 
133  public:
134 
135  GFAbsTrackRep();
136  GFAbsTrackRep(int);
137  virtual ~GFAbsTrackRep();
138 
139 
140  //! This method is to extrapolate the track to point of closest approach to a point in space
141  /* ! There is an empty implementation of this method in GFAbsTrackRep.cxx,
142  which will just abort with an error message. One can overwrite this
143  method if one wishes to implement a track representation, which should
144  have this feature. An example of an experiment in which you would not
145  need this feature would be track fitting (not so much vertexing) in
146  an experiment with only planar trackers like silicons or planar wire
147  chambers and such. An example where you would need it, would be a TPC
148  where you have to fit the track to space points, or other drift chambers
149  with complicated hit topology.
150  */
151  virtual void extrapolateToPoint(const TVector3& point,
152  TVector3& poca,
153  TVector3& normVec);
154 
155  //!
156  /** @brief This method extrapolates to the point of closest approach to a line
157  *
158  * This method extrapolates to the POCA to a line, i.e. a wire. There
159  * is a default implementation just like for the extrapolateToPoca for
160  * trackReps which do not need this feature, which will abort the
161  * execution if it is ever called.
162  */
163  virtual void extrapolateToLine(const TVector3& point1,
164  const TVector3& point2,
165  TVector3& poca,
166  TVector3& normVec,
167  TVector3& poca_onwire);
168 
169 
170  //! make step of h cm along the track
171  /*! There is an emply implementation in GFAbsTrackRep.cxx which will abort
172  (see one of the extrapolate methods above). This can be overwritten,
173  if this feature is needed.
174  */
175  virtual void stepalong(double h);
176 
177  //! Extrapolates the track to the given detectorplane
178  /*! Results are put into statePred and covPred
179  This method does NOT alter the state of the object!
180  */
181  virtual double extrapolate(const GFDetPlane& plane,
182  TMatrixT<Double_t>& statePred,
183  TMatrixT<Double_t>& covPred)=0;
184 
185  //! This changes the state and cov and plane of the rep
186  /*! This method extrapolates to to the plane and sets the results of state,
187  cov and also plane in itself.
188  */
189  double extrapolate(const GFDetPlane& plane);
190 
191  //! returns dimension of state vector
192  unsigned int getDim() const {return fDimension;}
193 
194  virtual void Print(std::ostream& out = std::cout) const;
195 
196  const TMatrixT<Double_t>& getState() const { return fState; }
197  const TMatrixT<Double_t>& getCov() const { return fCov; }
198 
199  double getStateElem(int i) const {return fState(i,0);}
200  double getCovElem(int i, int j) const {return fCov(i,j);}
201 
202 
203 
204  virtual TVector3 getPos(const GFDetPlane& pl)=0;
205  virtual TVector3 getMom(const GFDetPlane& pl)=0;
206 
207  virtual void getPosMom(const GFDetPlane& pl,TVector3& pos,TVector3& mom)=0;
208 
209  //! method which gets position, momentum and 6x6 covariance matrix
210  /*!
211  * default implementation in cxx file, if a ConcreteTrackRep can
212  * not implement this functionality
213  */
214  virtual void getPosMomCov(const GFDetPlane& pl,TVector3& pos,TVector3& mom,TMatrixT<Double_t>& cov);
215 
216  virtual double getCharge()const =0;
217 
218  TVector3 getPos() {return getPos(fRefPlane);}
219  TVector3 getMom() {return getMom(fRefPlane);}
220 
221  void getPosMomCov(TVector3& pos,TVector3& mom,TMatrixT<Double_t>& c){
222  getPosMomCov(fRefPlane,pos,mom,c);
223  }
224 
225  inline TMatrixT<Double_t> getFirstState() const {
226  return fFirstState;
227  }
228  inline TMatrixT<Double_t> getFirstCov() const {
229  return fFirstCov;
230  }
231  inline GFDetPlane getFirstPlane() const {
232  return fFirstPlane;
233  }
234  inline TMatrixT<Double_t> getLastState() const {
235  return fLastState;
236  }
237  inline TMatrixT<Double_t> getLastCov() const {
238  return fLastCov;
239  }
240  inline GFDetPlane getLastPlane() const {
241  return fLastPlane;
242  }
243  inline double getChiSqu() const {
244  return fChiSqu;
245  }
246  //! returns chi2/ndf
247  inline double getRedChiSqu() const {
248  if(getNDF()>0) return getChiSqu()/getNDF();
249  return 0;
250  }
251  inline unsigned int getNDF() const {
252  if(fNdf>getDim()) return fNdf-getDim();
253  return 0;
254  }
255 
256  virtual void setData(const TMatrixT<Double_t>& st, const GFDetPlane& pl, const TMatrixT<Double_t>* cov=NULL){
257  fState=st;
258  fRefPlane=pl;
259  if(cov!=NULL) fCov=*cov;
260  }
261  inline void setCov(const TMatrixT<Double_t>& aCov) {
262  fCov=aCov;
263  }
264  inline void setFirstState(const TMatrixT<Double_t>& aState) {
265  fFirstState = aState;
266  }
267  inline void setFirstCov(const TMatrixT<Double_t>& aCov) {
268  fFirstCov = aCov;
269  }
270  inline void setFirstPlane(const GFDetPlane& aPlane) {
271  fFirstPlane = aPlane;;
272  }
273  inline void setLastState(const TMatrixT<Double_t>& aState) {
274  fLastState = aState;
275  }
276  inline void setLastCov(const TMatrixT<Double_t>& aCov) {
277  fLastCov = aCov;
278  }
279  inline void setLastPlane(const GFDetPlane& aPlane) {
280  fLastPlane = aPlane;;
281  }
282 
283  const GFDetPlane& getReferencePlane() const {return fRefPlane;}
284 
285  inline void setChiSqu(double aChiSqu) {
286  fChiSqu = aChiSqu;
287  }
288  inline void setNDF(unsigned int n) {
289  fNdf = n;
290  }
291  inline void addChiSqu(double aChiSqu) {
292  fChiSqu += aChiSqu;
293  }
294  inline void addNDF(unsigned int n) {
295  fNdf += n;
296  }
297  inline void setStatusFlag(int _val) {
298  fStatusFlag = _val;
299  }
300 
301  virtual void switchDirection() = 0;
302 
303  //! Deprecated. Should be removed soon.
304  bool setInverted(bool f=true){fInverted=f; return true;}
305 
306  inline bool getStatusFlag() {
307  return fStatusFlag;
308  }
309 
310  virtual void reset();
311 
312  private:
313  void Abort(std::string method);
314 
315  virtual void Print(Option_t*) const
316  { throw std::logic_error(std::string(__func__) + "::Print(Option_t*) not available"); }
317 
318 
319  //ClassDef(GFAbsTrackRep,3)
320 
321 };
322 
323 } // namespace genf
324 
325 #endif
326 /** @} */
unsigned int getNDF() const
void setNDF(unsigned int n)
virtual void extrapolateToLine(const TVector3 &point1, const TVector3 &point2, TVector3 &poca, TVector3 &normVec, TVector3 &poca_onwire)
This method extrapolates to the point of closest approach to a line.
bool fInverted
specifies the direction of flight of the particle
const GFDetPlane & getReferencePlane() const
TMatrixT< Double_t > getLastCov() const
GFDetPlane getLastPlane() const
TMatrixT< Double_t > getLastState() const
virtual void stepalong(double h)
make step of h cm along the track
TMatrixT< Double_t > getFirstCov() const
void setLastCov(const TMatrixT< Double_t > &aCov)
double fChiSqu
chiSqu of the track fit
Definition: GFAbsTrackRep.h:97
virtual void reset()
virtual GFAbsTrackRep * clone() const =0
void setFirstPlane(const GFDetPlane &aPlane)
unsigned int fDimension
Dimensionality of track representation.
Definition: GFAbsTrackRep.h:88
const TMatrixT< Double_t > & getState() const
GFDetPlane fFirstPlane
virtual void getPosMomCov(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom, TMatrixT< Double_t > &cov)
method which gets position, momentum and 6x6 covariance matrix
GFDetPlane getFirstPlane() const
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:83
void setCov(const TMatrixT< Double_t > &aCov)
virtual void Print(Option_t *) const
void setChiSqu(double aChiSqu)
while getopts h
TMatrixT< Double_t > fCov
The covariance matrix.
Definition: GFAbsTrackRep.h:94
void addNDF(unsigned int n)
double getCovElem(int i, int j) const
void getPosMomCov(TVector3 &pos, TVector3 &mom, TMatrixT< Double_t > &c)
virtual void setData(const TMatrixT< Double_t > &st, const GFDetPlane &pl, const TMatrixT< Double_t > *cov=NULL)
TMatrixT< Double_t > fFirstCov
void addChiSqu(double aChiSqu)
bool setInverted(bool f=true)
Deprecated. Should be removed soon.
virtual void extrapolateToPoint(const TVector3 &point, TVector3 &poca, TVector3 &normVec)
This method is to extrapolate the track to point of closest approach to a point in space...
virtual double getCharge() const =0
virtual double extrapolate(const GFDetPlane &plane, TMatrixT< Double_t > &statePred)
returns the tracklength spanned in this extrapolation
void Abort(std::string method)
TMatrixT< Double_t > getFirstState() const
unsigned int fNdf
Definition: GFAbsTrackRep.h:98
TMatrixT< Double_t > fLastState
TMatrixT< Double_t > fLastCov
const TMatrixT< Double_t > & getCov() const
void setFirstCov(const TMatrixT< Double_t > &aCov)
void setLastPlane(const GFDetPlane &aPlane)
TMatrixT< Double_t > fFirstState
state, cov and plane for first and last point in fit
void setLastState(const TMatrixT< Double_t > &aState)
int fStatusFlag
status of track representation: 0 means everything&#39;s OK
BEGIN_PROLOG method
double getStateElem(int i) const
void setStatusFlag(int _val)
TMatrixT< Double_t > fState
The vector of track parameters.
Definition: GFAbsTrackRep.h:91
void setFirstState(const TMatrixT< Double_t > &aState)
double getChiSqu() const
unsigned int getDim() const
returns dimension of state vector
virtual GFAbsTrackRep * prototype() const =0
virtual void switchDirection()=0
double getRedChiSqu() const
returns chi2/ndf
virtual void getPosMom(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom)=0
BEGIN_PROLOG could also be cout
virtual void Print(std::ostream &out=std::cout) const