RKTrackRep.h
Go to the documentation of this file.
1 /* Copyright 2008-2009, 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 /*
21  */
22 
23 /** @addtogroup RKTrackRep
24  * @{
25  */
26 
27 
28 #ifndef RKTRACKREP_H
29 #define RKTRACKREP_H
30 
31 #include <stdexcept> // std::logic_error
34 #include <TMatrixT.h>
35 
36 namespace genf { class GFTrackCand; }
37 
38 //#include "GFMaterialEffects.h"
39 
40 /** @brief Track Representation module based on a Runge-Kutta algorithm including a full material model
41  *
42  * @author Christian H&ouml;ppner (Technische Universit&auml;t M&uuml;nchen, original author)
43  * @author Johannes Rauch (Technische Universit&auml;t M&uuml;nchen, author)
44  *
45  * The Runge Kutta implementation stems from GEANT3 originally (R. Brun et al.).
46  * Porting to %C goes back to Igor Gavrilenko @ CERN.
47  * The code was taken from the Phast analysis package of the COMPASS experiment
48  * (Sergei Gerrassimov @ CERN).
49  */
50 
51 namespace genf {
52 
53 class RKTrackRep : public GFAbsTrackRep {
54 
55  public:
56 
57  // Constructors/Destructors ---------
58  RKTrackRep();
59  RKTrackRep(const TVector3& pos,
60  const TVector3& mom,
61  const TVector3& poserr,
62  const TVector3& momerr,
63  const int& PDGCode);
64 
65  RKTrackRep(const GFTrackCand* aGFTrackCandPtr);
66 
67  RKTrackRep(const TVector3& pos,
68  const TVector3& mom,
69  const int& PDGCode);
70 
71  RKTrackRep(const GFDetPlane& pl,
72  const TVector3& mom,
73  const int& PDGCode);
74 
75  virtual ~RKTrackRep();
76 
77 
78  virtual GFAbsTrackRep* clone() const {return new RKTrackRep(*this);}
79  virtual GFAbsTrackRep* prototype()const{return new RKTrackRep();}
80 
81  //! returns the tracklength spanned in this extrapolation
82  /** The covariance matrix is transformed from the plane coordinate system to the master reference system (for the propagation) and, after propagation, back to the plane coordinate system.\n
83  * Also the parameter spu (which is +1 or -1 and indicates the direction of the particle) is calculated and stored in #fCacheSpu. The plane is stored in #fCachePlane.
84  * \n
85  *
86  * Master reference system (MARS):
87  * \f{eqnarray*}x & = & O_{x}+uU_{x}+vV_{x}\\y & = & O_{y}+uU_{y}+vV_{y}\\z & = & O_{z}+uU_{z}+vV_{z}\\a_{x} & = & \frac{\mbox{spu}}{\widetilde{p}}\left(N_{x}+u\prime U_{x}+v\prime V_{x}\right)\\a_{y} & = & \frac{\mbox{spu}}{\widetilde{p}}\left(N_{y}+u\prime U_{y}+v\prime V_{y}\right)\\a_{z} & = & \frac{\mbox{spu}}{\widetilde{p}}\left(N_{z}+u\prime U_{z}+v\prime V_{z}\right)\\\frac{q}{p} & = & \frac{q}{p}\f}
88  * Plane coordinate system:
89  * \f{eqnarray*}u & = & \left(x-O_{x}\right)U_{x}+\left(y-O_{y}\right)U_{y}+\left(z-O_{z}\right)U_{z}\\v & = & \left(x-O_{x}\right)U_{x}+\left(y-O_{y}\right)U_{y}+\left(z-O_{z}\right)U_{z}\\u\prime & = & \frac{a_{x}U_{x}+a_{y}U_{y}+a_{z}U_{z}}{a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}}\\v\prime & = & \frac{a_{x}V_{x}+a_{y}V_{y}+a_{z}V_{z}}{a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}}\\\frac{q}{p} & = & \frac{q}{p}\\\mbox{spu} & = & \frac{a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}}{|a_{x}^{2}N_{x}^{2}+a_{y}^{2}N_{y}^{2}+a_{z}^{2}N_{z}^{2}|}=\pm1\f}
90  *
91  * Jacobians:\n
92  * \f$J_{p,M}=\left(\begin{array}{ccccc}\frac{\partial x}{\partial u} & \frac{\partial x}{\partial v} & \frac{\partial x}{\partial u\prime} & \frac{\partial x}{\partial v\prime} & \frac{\partial x}{\partial\frac{q}{p}}\\\frac{\partial y}{\partial u} & \frac{\partial y}{\partial v} & \frac{\partial y}{\partial u\prime} & \frac{\partial y}{\partial v\prime} & \frac{\partial y}{\partial\frac{q}{p}}\\\frac{\partial z}{\partial u} & \frac{\partial z}{\partial v} & \frac{\partial z}{\partial u\prime} & \frac{\partial z}{\partial v\prime} & \frac{\partial z}{\partial\frac{q}{p}}\\\frac{\partial a_{x}}{\partial u} & \frac{\partial a_{x}}{\partial v} & \frac{\partial a_{x}}{\partial u\prime} & \frac{\partial a_{x}}{\partial v\prime} & \frac{\partial a_{x}}{\partial\frac{q}{p}}\\\frac{\partial a_{y}}{\partial u} & \frac{\partial a_{y}}{\partial v} & \frac{\partial a_{y}}{\partial u\prime} & \frac{\partial a_{y}}{\partial v\prime} & \frac{\partial a_{y}}{\partial\frac{q}{p}}\\\frac{\partial a_{z}}{\partial u} & \frac{\partial a_{z}}{\partial v} & \frac{\partial a_{z}}{\partial u\prime} & \frac{\partial a_{z}}{\partial v\prime} & \frac{\partial a_{z}}{\partial\frac{q}{p}}\\\frac{\partial\frac{q}{p}}{\partial u} & \frac{\partial\frac{q}{p}}{\partial v} & \frac{\partial\frac{q}{p}}{\partial u\prime} & \frac{\partial\frac{q}{p}}{\partial v\prime} & \frac{\partial\frac{q}{p}}{\partial\frac{q}{p}}\end{array}\right)\f$
93  *
94  * \f$J_{p,M}=\left(\begin{array}{cccccc}U_{x} & V_{x} & 0 & 0 & 0\\U_{y} & V_{y} & 0 & 0 & 0\\U_{z} & V_{z} & 0 & 0 & 0\\0 & 0 & \left\{ \frac{\textrm{spu}}{\widetilde{p}}U_{x}-\left[\frac{\textrm{spu}}{\widetilde{p}^{3}}\widetilde{p}_{x}\left(U_{x}\widetilde{p}_{x}+U_{y}\widetilde{p}_{y}+U_{z}\widetilde{p}_{z}\right)\right]\right\} & \left\{ \frac{\textrm{spu}}{\widetilde{p}}V_{x}-\left[\frac{\textrm{spu}}{\widetilde{p}^{3}}\widetilde{p}_{x}\left(V_{x}\widetilde{p}_{x}+V_{y}\widetilde{p}_{y}+V_{z}\widetilde{p}_{z}\right)\right]\right\} & 0\\0 & 0 & \left\{ \frac{\textrm{spu}}{\widetilde{p}}U_{y}-\left[\frac{\textrm{spu}}{\widetilde{p}^{3}}\widetilde{p}_{y}\left(U_{x}\widetilde{p}_{x}+U_{y}\widetilde{p}_{y}+U_{z}\widetilde{p}_{z}\right)\right]\right\} & \left\{ \frac{\textrm{spu}}{\widetilde{p}}V_{y}-\left[\frac{\textrm{spu}}{\widetilde{p}^{3}}\widetilde{p}_{y}\left(V_{x}\widetilde{p}_{x}+V_{y}\widetilde{p}_{y}+V_{z}\widetilde{p}_{z}\right)\right]\right\} & 0\\0 & 0 & \left\{ \frac{\textrm{spu}}{\widetilde{p}}U_{z}-\left[\frac{\textrm{spu}}{\widetilde{p}^{3}}\widetilde{p}_{z}\left(U_{x}\widetilde{p}_{x}+U_{y}\widetilde{p}_{y}+U_{z}\widetilde{p}_{z}\right)\right]\right\} & \left\{ \frac{\textrm{spu}}{\widetilde{p}}V_{z}-\left[\frac{\textrm{spu}}{\widetilde{p}^{3}}\widetilde{p}_{z}\left(V_{x}\widetilde{p}_{x}+V_{y}\widetilde{p}_{y}+V_{z}\widetilde{p}_{z}\right)\right]\right\} & 0\\0 & 0 & 0 & 0 & 1\end{array}\right)\f$
95  *
96  * with
97  * \f{eqnarray*}\widetilde{p} & = & \sqrt{\widetilde{p}_{x}^{2}+\widetilde{p}_{y}^{2}+\widetilde{p}_{z}^{2}}\\\widetilde{p}_{x} & = & \textrm{spu}\left(N_{x}+u\prime U_{x}+v\prime V_{x}\right)\\\widetilde{p}_{y} & = & \textrm{spu}\left(N_{y}+u\prime U_{y}+v\prime V_{y}\right)\\\widetilde{p}_{z} & = & \textrm{spu}\left(N_{z}+u\prime U_{z}+v\prime V_{z}\right)\f}
98  *
99  * \f$J_{M,p}=\left(\begin{array}{ccccccc}\frac{\partial u}{\partial x} & \frac{\partial u}{\partial y} & \frac{\partial u}{\partial z} & \frac{\partial u}{\partial a_{x}} & \frac{\partial u}{\partial a_{y}} & \frac{\partial u}{\partial a_{z}} & \frac{\partial u}{\partial\frac{q}{p}}\\\frac{\partial v}{\partial x} & \frac{\partial v}{\partial y} & \frac{\partial v}{\partial z} & \frac{\partial v}{\partial a_{x}} & \frac{\partial v}{\partial a_{y}} & \frac{\partial v}{\partial a_{z}} & \frac{\partial v}{\partial\frac{q}{p}}\\\frac{\partial u\prime}{\partial x} & \frac{\partial u\prime}{\partial y} & \frac{\partial u\prime}{\partial z} & \frac{\partial u\prime}{\partial a_{x}} & \frac{\partial u\prime}{\partial a_{y}} & \frac{\partial u\prime}{\partial a_{z}} & \frac{\partial u\prime}{\partial\frac{q}{p}}\\\frac{\partial v\prime}{\partial x} & \frac{\partial v\prime}{\partial y} & \frac{\partial v\prime}{\partial z} & \frac{\partial v\prime}{\partial a_{x}} & \frac{\partial v\prime}{\partial a_{y}} & \frac{\partial v\prime}{\partial a_{z}} & \frac{\partial v\prime}{\partial\frac{q}{p}}\\ \frac{\partial\frac{q}{p}}{\partial x} & \frac{\partial\frac{q}{p}}{\partial y} & \frac{\partial\frac{q}{p}}{\partial z} & \frac{\partial\frac{q}{p}}{\partial a_{x}} & \frac{\partial\frac{q}{p}}{\partial a_{y}} & \frac{\partial\frac{q}{p}}{\partial a_{z}} & \frac{\partial\frac{q}{p}}{\partial\frac{q}{p}}\\ \\\end{array}\right)\f$
100  *
101  * \f$J_{M,p}=\left(\begin{array}{ccccccc} U_{x} & U_{y} & U_{z} & 0 & 0 & 0 & 0\\ V_{x} & V_{y} & V_{z} & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & \frac{U_{x}\left(a_{y}N_{y}+a_{z}N_{z}\right)-N_{x}\left(a_{y}U_{y}+a_{z}U_{z}\right)}{\left(a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}\right)^{2}} & \frac{U_{y}\left(a_{x}N_{x}+a_{z}N_{z}\right)-N_{y}\left(a_{x}U_{x}+a_{z}U_{z}\right)}{\left(a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}\right)^{2}} & \frac{U_{z}\left(a_{x}N_{x}+a_{y}N_{y}\right)-N_{z}\left(a_{x}U_{x}+a_{y}U_{y}\right)}{\left(a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}\right)^{2}} & 0\\ 0 & 0 & 0 & \frac{V_{x}\left(a_{y}N_{y}+a_{z}N_{z}\right)-N_{x}\left(a_{y}V_{y}+a_{z}V_{z}\right)}{\left(a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}\right)^{2}} & \frac{V_{y}\left(a_{x}N_{x}+a_{z}N_{z}\right)-N_{y}\left(a_{x}V_{x}+a_{z}V_{z}\right)}{\left(a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}\right)^{2}} & \frac{V_{z}\left(a_{x}N_{x}+a_{y}N_{y}\right)-N_{z}\left(a_{x}V_{x}+a_{y}V_{y}\right)}{\left(a_{x}N_{x}+a_{y}N_{y}+a_{z}N_{z}\right)^{2}} & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 1\\ \\\end{array}\right)\f$
102  *
103  */
104  double extrapolate(const GFDetPlane&,
105  TMatrixT<Double_t>& statePred,
106  TMatrixT<Double_t>& covPred);
107 
108  //! returns the tracklength spanned in this extrapolation
109  double extrapolate(const GFDetPlane&,
110  TMatrixT<Double_t>& statePred);
111 
112  //! This method is to extrapolate the track to point of closest approach to a point in space
113  void extrapolateToPoint(const TVector3& pos,
114  TVector3& poca,
115  TVector3& dirInPoca);
116 
117  //! This method extrapolates to the point of closest approach to a line
118  void extrapolateToLine(const TVector3& point1,
119  const TVector3& point2,
120  TVector3& poca,
121  TVector3& dirInPoca,
122  TVector3& poca_onwire);
123 
124 
125  //! Returns position of the track in the plane
126  /** If #GFDetPlane equals the reference plane #fRefPlane, returns current position; otherwise it extrapolates
127  * the track to the plane and returns the position.
128  */
129  TVector3 getPos(const GFDetPlane&);
130  //! Returns momentum of the track in the plane
131  /** If #GFDetPlane equals the reference plane #fRefPlane, returns current momentum; otherwise it extrapolates
132  * the track to the plane and returns the momentum.
133  */
134  TVector3 getMom(const GFDetPlane&);
135  TVector3 getMomLast(const GFDetPlane&);
136  //! Gets position and momentum in the plane by exrapolating or not.
137  /** If #GFDetPlane equals the reference plane #fRefPlane, it gets current position and momentum; otherwise for getMom() it extrapolates
138  * the track to the plane and gets the position and momentum. GetMomLast() does no extrapn. EC.
139  */
140  void getPosMom(const GFDetPlane&,TVector3& pos,TVector3& mom);
141  //! Returns charge
142  double getCharge()const {return fCharge;}
143  //! deprecated
145  //! Set PDG particle code
146  void setPDG(int);
147  int getPDG();
148  void rescaleCovOffDiags();
149 
150  //! Sets state, plane and (optionally) covariance
151  /** This function also sets the parameter #fSpu to the value stored in #fCacheSpu. Therefore it has to be ensured that
152  * the plane #pl is the same as the plane of the last extrapolation (i.e. #fCachePlane), where #fCacheSpu was calculated.
153  * Hence, if the argument #pl is not equal to #fCachePlane, an error message is shown an an exception is thrown.
154  */
155  void setData(const TMatrixT<double>& st, const GFDetPlane& pl, const TMatrixT<double>* cov=NULL, const TMatrixT<double>* aux=NULL);
156  // the base class method is hidden by the one above; which does not make much
157  // sense since polymorphic access will still get to it.
158  // We make it official by explicitly importing the base class method as well.
160 
161  const TMatrixT<double>* getAuxInfo(const GFDetPlane& pl);
162 
163  bool hasAuxInfo() { return true; }
164 
165  private:
166 
168  double fCacheSpu;
169  double fSpu;
170  TMatrixT<double> fAuxInfo;
171 
172 
173  RKTrackRep& operator=(const RKTrackRep* /* rhs */){return *this;}
174  RKTrackRep(const RKTrackRep& /* rhs */): GFAbsTrackRep() {}
176 
177  //! PDG particle code
178  int fPdg;
179  //! Mass (in GeV)
180  double fMass;
181  //! Charge
182  double fCharge;
183  //! Contains all material effects
184  //GFMaterialEffects *fEffect;
185 
186  //! Propagates the particle through the magnetic field.
187  /** If the propagation is successfull and the plane is reached, the function returns true.
188  * The argument P has to contain the state (#P[0] - #P[6]) and a unity matrix (#P[7] - #P[55])
189  * with the last column multiplied wit q/p (hence #P[55] is not 1 but q/p).
190  * Propagated state and the jacobian (with the last column multiplied wit q/p) of the extrapolation are written to #P.
191  * In the main loop of the Runge Kutta algorithm, the steppers in #fEffect are called
192  * and may reduce the estimated stepsize so that a maximum momentum loss will not be exceeded.
193  * If this is the case, RKutta() will only propagate the reduced distance and then return. This is to ensure that
194  * material effects, which are calculated after the propagation, are taken into account properly.
195  *
196  */
197  bool RKutta (const GFDetPlane& plane,double* P, double& coveredDistance, std::vector<TVector3>& points, std::vector<double>& pointLengths, const double& maxLen=-1, bool calcCov=true) const;
198 
199  TVector3 poca2Line(const TVector3& extr1,const TVector3& extr2,const TVector3& point) const;
200 
201  //! Handles propagation and material effects
202  /** extrapolate(), extrapolateToPoint() and extrapolateToLine() call this function.
203  * Extrap() needs a plane as an argument, hence extrapolateToPoint() and extrapolateToLine() create virtual detector planes.
204  * In this function, RKutta() is called and the resulting points and point paths are filtered
205  * so that the direction doesn't change and tiny steps are filtered out. After the propagation the material effects in #fEffect are called.
206  * Extrap() will loop until the plane is reached, unless the propagation fails or the maximum number of
207  * iterations is exceeded.
208  */
209  double Extrap(const GFDetPlane& plane, TMatrixT<Double_t>* state, TMatrixT<Double_t>* cov=NULL) const;
210 
211 
212  // void setData(const TMatrixT<Double_t>& /* st */, const GFDetPlane& /* pl */, const TMatrixT<Double_t>* cov=NULL, const TMatrixT<double>* aux=NULL);
213  // { throw std::logic_error(std::string(__func__) + "::setData(TMatrixT, GFDetPlane, TMatrixT) not available"); }
214 
215  // public:
216  //ClassDef(RKTrackRep,3)
217 
218  };
219 
220 } // end namespace
221 #endif
222 
223 /** @} */
int fPdg
PDG particle code.
Definition: RKTrackRep.h:178
const TMatrixT< double > * getAuxInfo(const GFDetPlane &pl)
Definition: RKTrackRep.cxx:55
void extrapolateToLine(const TVector3 &point1, const TVector3 &point2, TVector3 &poca, TVector3 &dirInPoca, TVector3 &poca_onwire)
This method extrapolates to the point of closest approach to a line.
Definition: RKTrackRep.cxx:424
Generic Interface to magnetic fields in GENFIT.
Definition: GFAbsBField.h:35
double fMass
Mass (in GeV)
Definition: RKTrackRep.h:180
GFDetPlane fCachePlane
Definition: RKTrackRep.h:167
virtual ~RKTrackRep()
Definition: RKTrackRep.cxx:65
std::pair< float, std::string > P
double extrapolate(const GFDetPlane &, TMatrixT< Double_t > &statePred, TMatrixT< Double_t > &covPred)
returns the tracklength spanned in this extrapolation
Definition: RKTrackRep.cxx:475
RKTrackRep(const RKTrackRep &)
Definition: RKTrackRep.h:174
void setData(const TMatrixT< double > &st, const GFDetPlane &pl, const TMatrixT< double > *cov=NULL, const TMatrixT< double > *aux=NULL)
Sets state, plane and (optionally) covariance.
Definition: RKTrackRep.cxx:42
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:83
TMatrixT< double > fAuxInfo
Definition: RKTrackRep.h:170
virtual void setData(const TMatrixT< Double_t > &st, const GFDetPlane &pl, const TMatrixT< Double_t > *cov=NULL)
void rescaleCovOffDiags()
void extrapolateToPoint(const TVector3 &pos, TVector3 &poca, TVector3 &dirInPoca)
This method is to extrapolate the track to point of closest approach to a point in space...
Definition: RKTrackRep.cxx:365
void setPDG(int)
Set PDG particle code.
Definition: RKTrackRep.cxx:299
void switchDirection()
deprecated
Definition: RKTrackRep.h:144
RKTrackRep & operator=(const RKTrackRep *)
Definition: RKTrackRep.h:173
double Extrap(const GFDetPlane &plane, TMatrixT< Double_t > *state, TMatrixT< Double_t > *cov=NULL) const
Handles propagation and material effects.
virtual GFAbsTrackRep * clone() const
Definition: RKTrackRep.h:78
TVector3 getMomLast(const GFDetPlane &)
Definition: RKTrackRep.cxx:337
double fCharge
Charge.
Definition: RKTrackRep.h:182
virtual GFAbsTrackRep * prototype() const
Definition: RKTrackRep.h:79
void getPosMom(const GFDetPlane &, TVector3 &pos, TVector3 &mom)
Gets position and momentum in the plane by exrapolating or not.
Definition: RKTrackRep.cxx:347
bool RKutta(const GFDetPlane &plane, double *P, double &coveredDistance, std::vector< TVector3 > &points, std::vector< double > &pointLengths, const double &maxLen=-1, bool calcCov=true) const
Contains all material effects.
Definition: RKTrackRep.cxx:691
TVector3 poca2Line(const TVector3 &extr1, const TVector3 &extr2, const TVector3 &point) const
Definition: RKTrackRep.cxx:411
double getCharge() const
Returns charge.
Definition: RKTrackRep.h:142