LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 
24 #ifndef GFABSTRACKREP_H
25 #define GFABSTRACKREP_H
26 
27 #include <iostream>
28 #include <stdexcept> // std::logic_error
29 
30 #include "TMatrixT.h"
31 #include "TVector3.h"
32 
34 
35 //class genf::GFAbsRecoHit;
36 
37 namespace genf {
38 
81  class GFAbsTrackRep : public TObject {
82 
83  /*----- Data members -----*/
84  protected:
86  unsigned int fDimension;
87 
89  TMatrixT<Double_t> fState;
90 
92  TMatrixT<Double_t> fCov;
93 
95  double fChiSqu;
96  unsigned int fNdf;
97 
101  bool fInverted;
102 
104  TMatrixT<Double_t> fFirstState;
105  TMatrixT<Double_t> fFirstCov;
106 
107  TMatrixT<Double_t> fLastState;
108  TMatrixT<Double_t> fLastCov;
111 
112  // detector plane where the track parameters are given
114 
115  public:
116  virtual GFAbsTrackRep* clone() const = 0;
117 
118  virtual GFAbsTrackRep* prototype() const = 0;
119 
121  /* ! There is a default implementation in GFAbsTrackRep.cxx which just drops
122  the predicted covaraiance. If your trackrep has a way to extrapolate
123  without giving a correct cov (that would be faster probably), please
124  overwrite it.
125  */
126  virtual double extrapolate(const GFDetPlane& plane, TMatrixT<Double_t>& statePred);
127 
128  public:
129  GFAbsTrackRep();
130  GFAbsTrackRep(int);
131  virtual ~GFAbsTrackRep();
132 
134  /* ! There is an empty implementation of this method in GFAbsTrackRep.cxx,
135  which will just abort with an error message. One can overwrite this
136  method if one wishes to implement a track representation, which should
137  have this feature. An example of an experiment in which you would not
138  need this feature would be track fitting (not so much vertexing) in
139  an experiment with only planar trackers like silicons or planar wire
140  chambers and such. An example where you would need it, would be a TPC
141  where you have to fit the track to space points, or other drift chambers
142  with complicated hit topology.
143  */
144  virtual void extrapolateToPoint(const TVector3& point, TVector3& poca, TVector3& normVec);
145 
147 
154  virtual void extrapolateToLine(const TVector3& point1,
155  const TVector3& point2,
156  TVector3& poca,
157  TVector3& normVec,
158  TVector3& poca_onwire);
159 
161 
165  virtual void stepalong(double h);
166 
168 
171  virtual double extrapolate(const GFDetPlane& plane,
172  TMatrixT<Double_t>& statePred,
173  TMatrixT<Double_t>& covPred) = 0;
174 
176 
179  double extrapolate(const GFDetPlane& plane);
180 
182  unsigned int getDim() const { return fDimension; }
183 
184  virtual void Print(std::ostream& out = std::cout) const;
185 
186  const TMatrixT<Double_t>& getState() const { return fState; }
187  const TMatrixT<Double_t>& getCov() const { return fCov; }
188 
189  double getStateElem(int i) const { return fState(i, 0); }
190  double getCovElem(int i, int j) const { return fCov(i, j); }
191 
192  virtual TVector3 getPos(const GFDetPlane& pl) = 0;
193  virtual TVector3 getMom(const GFDetPlane& pl) = 0;
194 
195  virtual void getPosMom(const GFDetPlane& pl, TVector3& pos, TVector3& mom) = 0;
196 
198 
202  virtual void getPosMomCov(const GFDetPlane& pl,
203  TVector3& pos,
204  TVector3& mom,
205  TMatrixT<Double_t>& cov);
206 
207  virtual double getCharge() const = 0;
208 
209  TVector3 getPos() { return getPos(fRefPlane); }
210  TVector3 getMom() { return getMom(fRefPlane); }
211 
212  void getPosMomCov(TVector3& pos, TVector3& mom, TMatrixT<Double_t>& c)
213  {
214  getPosMomCov(fRefPlane, pos, mom, c);
215  }
216 
217  inline TMatrixT<Double_t> getFirstState() const { return fFirstState; }
218  inline TMatrixT<Double_t> getFirstCov() const { return fFirstCov; }
219  inline GFDetPlane getFirstPlane() const { return fFirstPlane; }
220  inline TMatrixT<Double_t> getLastState() const { return fLastState; }
221  inline TMatrixT<Double_t> getLastCov() const { return fLastCov; }
222  inline GFDetPlane getLastPlane() const { return fLastPlane; }
223  inline double getChiSqu() const { return fChiSqu; }
225  inline double getRedChiSqu() const
226  {
227  if (getNDF() > 0) return getChiSqu() / getNDF();
228  return 0;
229  }
230  inline unsigned int getNDF() const
231  {
232  if (fNdf > getDim()) return fNdf - getDim();
233  return 0;
234  }
235 
236  virtual void setData(const TMatrixT<Double_t>& st,
237  const GFDetPlane& pl,
238  const TMatrixT<Double_t>* cov = NULL)
239  {
240  fState = st;
241  fRefPlane = pl;
242  if (cov != NULL) fCov = *cov;
243  }
244  inline void setCov(const TMatrixT<Double_t>& aCov) { fCov = aCov; }
245  inline void setFirstState(const TMatrixT<Double_t>& aState) { fFirstState = aState; }
246  inline void setFirstCov(const TMatrixT<Double_t>& aCov) { fFirstCov = aCov; }
247  inline void setFirstPlane(const GFDetPlane& aPlane)
248  {
249  fFirstPlane = aPlane;
250  ;
251  }
252  inline void setLastState(const TMatrixT<Double_t>& aState) { fLastState = aState; }
253  inline void setLastCov(const TMatrixT<Double_t>& aCov) { fLastCov = aCov; }
254  inline void setLastPlane(const GFDetPlane& aPlane)
255  {
256  fLastPlane = aPlane;
257  ;
258  }
259 
260  const GFDetPlane& getReferencePlane() const { return fRefPlane; }
261 
262  inline void setChiSqu(double aChiSqu) { fChiSqu = aChiSqu; }
263  inline void setNDF(unsigned int n) { fNdf = n; }
264  inline void addChiSqu(double aChiSqu) { fChiSqu += aChiSqu; }
265  inline void addNDF(unsigned int n) { fNdf += n; }
266  inline void setStatusFlag(int _val) { fStatusFlag = _val; }
267 
268  virtual void switchDirection() = 0;
269 
271  bool setInverted(bool f = true)
272  {
273  fInverted = f;
274  return true;
275  }
276 
277  inline bool getStatusFlag() { return fStatusFlag; }
278 
279  virtual void reset();
280 
281  private:
282  void Abort(std::string method);
283 
284  virtual void Print(Option_t*) const
285  {
286  throw std::logic_error(std::string(__func__) + "::Print(Option_t*) not available");
287  }
288 
289  //ClassDef(GFAbsTrackRep,3)
290  };
291 
292 } // namespace genf
293 
294 #endif
295 
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
virtual GFAbsTrackRep * clone() const =0
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
Generic Interface to magnetic fields in GENFIT.
Definition: GFAbsBField.h:34
void setLastCov(const TMatrixT< Double_t > &aCov)
double fChiSqu
chiSqu of the track fit
Definition: GFAbsTrackRep.h:95
virtual void reset()
void setFirstPlane(const GFDetPlane &aPlane)
unsigned int fDimension
Dimensionality of track representation.
Definition: GFAbsTrackRep.h:86
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:81
void setCov(const TMatrixT< Double_t > &aCov)
virtual void Print(Option_t *) const
void setChiSqu(double aChiSqu)
TFile f
Definition: plotHisto.C:6
TMatrixT< Double_t > fCov
The covariance matrix.
Definition: GFAbsTrackRep.h:92
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)
virtual GFAbsTrackRep * prototype() const =0
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 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:96
virtual double getCharge() const =0
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
Definition: GFAbsTrackRep.h:99
double getStateElem(int i) const
void setStatusFlag(int _val)
Char_t n[5]
TMatrixT< Double_t > fState
The vector of track parameters.
Definition: GFAbsTrackRep.h:89
void setFirstState(const TMatrixT< Double_t > &aState)
double getChiSqu() const
unsigned int getDim() const
returns dimension of state vector
virtual void switchDirection()=0
double getRedChiSqu() const
returns chi2/ndf
virtual void getPosMom(const GFDetPlane &pl, TVector3 &pos, TVector3 &mom)=0
virtual void Print(std::ostream &out=std::cout) const