GENFIT  Rev:NoNumberAvailable
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
RKTrackRep.h
Go to the documentation of this file.
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 */
19 
24 #ifndef genfit_RKTrackRep_h
25 #define genfit_RKTrackRep_h
26 
27 #include "AbsTrackRep.h"
28 #include "StateOnPlane.h"
29 #include "RKTools.h"
30 #include "StepLimits.h"
31 
32 #include <algorithm>
33 
34 namespace genfit {
35 
39 struct RKStep {
40  MatStep matStep_; // material properties and stepsize
41  M1x7 state7_; // 7D state vector
43 
44  RKStep() {
45  std::fill(state7_.begin(), state7_.end(), 0);
46  }
47 };
48 
49 
53 struct ExtrapStep {
54  M7x7 jac7_; // 5D jacobian of transport
55  M7x7 noise7_; // 5D noise matrix
56 
58  std::fill(jac7_.begin(), jac7_.end(), 0);
59  std::fill(noise7_.begin(), jac7_.end(), 0);
60  }
61 };
62 
63 
71 class RKTrackRep : public AbsTrackRep {
72 
73 
74  public:
75 
76  RKTrackRep();
77  RKTrackRep(int pdgCode, char propDir = 0);
78 
79  virtual ~RKTrackRep();
80 
81  virtual AbsTrackRep* clone() const {return new RKTrackRep(*this);}
82 
83  virtual double extrapolateToPlane(StateOnPlane& state,
84  const SharedPlanePtr& plane,
85  bool stopAtBoundary = false,
86  bool calcJacobianNoise = false) const;
87 
89 
90  virtual double extrapolateToLine(StateOnPlane& state,
91  const TVector3& linePoint,
92  const TVector3& lineDirection,
93  bool stopAtBoundary = false,
94  bool calcJacobianNoise = false) const;
95 
96  virtual double extrapolateToPoint(StateOnPlane& state,
97  const TVector3& point,
98  bool stopAtBoundary = false,
99  bool calcJacobianNoise = false) const {
100  return extrapToPoint(state, point, NULL, stopAtBoundary, calcJacobianNoise);
101  }
102 
103  virtual double extrapolateToPoint(StateOnPlane& state,
104  const TVector3& point,
105  const TMatrixDSym& G, // weight matrix (metric)
106  bool stopAtBoundary = false,
107  bool calcJacobianNoise = false) const {
108  return extrapToPoint(state, point, &G, stopAtBoundary, calcJacobianNoise);
109  }
110 
111  virtual double extrapolateToCylinder(StateOnPlane& state,
112  double radius,
113  const TVector3& linePoint = TVector3(0.,0.,0.),
114  const TVector3& lineDirection = TVector3(0.,0.,1.),
115  bool stopAtBoundary = false,
116  bool calcJacobianNoise = false) const;
117 
118 
119  virtual double extrapolateToCone(StateOnPlane& state,
120  double radius,
121  const TVector3& linePoint = TVector3(0.,0.,0.),
122  const TVector3& lineDirection = TVector3(0.,0.,1.),
123  bool stopAtBoundary = false,
124  bool calcJacobianNoise = false) const;
125 
126  virtual double extrapolateToSphere(StateOnPlane& state,
127  double radius,
128  const TVector3& point = TVector3(0.,0.,0.),
129  bool stopAtBoundary = false,
130  bool calcJacobianNoise = false) const;
131 
132  virtual double extrapolateBy(StateOnPlane& state,
133  double step,
134  bool stopAtBoundary = false,
135  bool calcJacobianNoise = false) const;
136 
137 
138  unsigned int getDim() const {return 5;}
139 
140  virtual TVector3 getPos(const StateOnPlane& state) const;
141 
142  virtual TVector3 getMom(const StateOnPlane& state) const;
143  virtual void getPosMom(const StateOnPlane& state, TVector3& pos, TVector3& mom) const;
144 
145  virtual double getMomMag(const StateOnPlane& state) const;
146  virtual double getMomVar(const MeasuredStateOnPlane& state) const;
147 
148  virtual TMatrixDSym get6DCov(const MeasuredStateOnPlane& state) const;
149  virtual void getPosMomCov(const MeasuredStateOnPlane& state, TVector3& pos, TVector3& mom, TMatrixDSym& cov) const;
150  virtual double getCharge(const StateOnPlane& state) const;
151  virtual double getQop(const StateOnPlane& state) const {return state.getState()(0);}
152  double getSpu(const StateOnPlane& state) const;
153  double getTime(const StateOnPlane& state) const;
154 
155  virtual void getForwardJacobianAndNoise(TMatrixD& jacobian, TMatrixDSym& noise, TVectorD& deltaState) const;
156 
157  virtual void getBackwardJacobianAndNoise(TMatrixD& jacobian, TMatrixDSym& noise, TVectorD& deltaState) const;
158 
159  std::vector<genfit::MatStep> getSteps() const;
160 
161  virtual double getRadiationLenght() const;
162 
163  virtual void setPosMom(StateOnPlane& state, const TVector3& pos, const TVector3& mom) const;
164  virtual void setPosMom(StateOnPlane& state, const TVectorD& state6) const;
165  virtual void setPosMomErr(MeasuredStateOnPlane& state, const TVector3& pos, const TVector3& mom, const TVector3& posErr, const TVector3& momErr) const;
166  virtual void setPosMomCov(MeasuredStateOnPlane& state, const TVector3& pos, const TVector3& mom, const TMatrixDSym& cov6x6) const;
167  virtual void setPosMomCov(MeasuredStateOnPlane& state, const TVectorD& state6, const TMatrixDSym& cov6x6) const;
168 
169  virtual void setChargeSign(StateOnPlane& state, double charge) const;
170  virtual void setQop(StateOnPlane& state, double qop) const {state.getState()(0) = qop;}
171 
172  void setSpu(StateOnPlane& state, double spu) const;
173  void setTime(StateOnPlane& state, double time) const;
174 
176 
184  double RKPropagate(M1x7& state7,
185  M7x7* jacobian,
186  M1x3& SA,
187  double S,
188  bool varField = true,
189  bool calcOnlyLastRowOfJ = false) const;
190 
191  virtual bool isSameType(const AbsTrackRep* other);
192  virtual bool isSame(const AbsTrackRep* other);
193 
194  private:
195 
196  void initArrays() const;
197 
198  virtual double extrapToPoint(StateOnPlane& state,
199  const TVector3& point,
200  const TMatrixDSym* G = NULL, // weight matrix (metric)
201  bool stopAtBoundary = false,
202  bool calcJacobianNoise = false) const;
203 
204  void getState7(const StateOnPlane& state, M1x7& state7) const;
205  void getState5(StateOnPlane& state, const M1x7& state7) const; // state7 must already lie on plane of state!
206 
207  void transformPM7(const MeasuredStateOnPlane& state,
208  M7x7& out7x7) const;
209 
210  void calcJ_pM_5x7(M5x7& J_pM, const TVector3& U, const TVector3& V, const M1x3& pTilde, double spu) const;
211 
212  void transformPM6(const MeasuredStateOnPlane& state,
213  M6x6& out6x6) const;
214 
215  void transformM7P(const M7x7& in7x7,
216  const M1x7& state7,
217  MeasuredStateOnPlane& state) const; // plane must already be set!
218 
219  void calcJ_Mp_7x5(M7x5& J_Mp, const TVector3& U, const TVector3& V, const TVector3& W, const M1x3& A) const;
220 
221  void calcForwardJacobianAndNoise(const M1x7& startState7, const DetPlane& startPlane,
222  const M1x7& destState7, const DetPlane& destPlane) const;
223 
224  void transformM6P(const M6x6& in6x6,
225  const M1x7& state7,
226  MeasuredStateOnPlane& state) const; // plane and charge must already be set!
227 
229 
238  bool RKutta(const M1x4& SU,
239  const DetPlane& plane,
240  double charge,
241  double mass,
242  M1x7& state7,
243  M7x7* jacobianT,
244  M1x7* J_MMT_unprojected_lastRow,
245  double& coveredDistance, // signed
246  double& flightTime,
247  bool& checkJacProj,
248  M7x7& noiseProjection,
249  StepLimits& limits,
250  bool onlyOneStep = false,
251  bool calcOnlyLastRowOfJ = false) const;
252 
253  double estimateStep(const M1x7& state7,
254  const M1x4& SU,
255  const DetPlane& plane,
256  const double& charge,
257  double& relMomLoss,
258  StepLimits& limits) const;
259 
260  TVector3 pocaOnLine(const TVector3& linePoint,
261  const TVector3& lineDirection,
262  const TVector3& point) const;
263 
265 
273  double Extrap(const DetPlane& startPlane, // plane where Extrap starts
274  const DetPlane& destPlane, // plane where Extrap has to extrapolate to
275  double charge,
276  double mass,
277  bool& isAtBoundary,
278  M1x7& state7,
279  double& flightTime,
280  bool fillExtrapSteps,
281  TMatrixDSym* cov = nullptr,
282  bool onlyOneStep = false,
283  bool stopAtBoundary = false,
284  double maxStep = 1.E99) const;
285 
286  void checkCache(const StateOnPlane& state, const SharedPlanePtr* plane) const;
287 
288  double momMag(const M1x7& state7) const;
289 
290 
293  mutable std::vector<RKStep> RKSteps_;
294  mutable int RKStepsFXStart_;
295  mutable int RKStepsFXStop_;
296  mutable std::vector<ExtrapStep> ExtrapSteps_;
297 
298  mutable TMatrixD fJacobian_;
299  mutable TMatrixDSym fNoise_;
300 
301  mutable bool useCache_;
302  mutable unsigned int cachePos_;
303 
304  // auxiliary variables and arrays
305  // needed in Extrap()
306  mutable StepLimits limits_;
307  mutable M7x7 noiseArray_;
309  mutable M7x7 J_MMT_;
310 
311  public:
312 
313  ClassDef(RKTrackRep, 1)
314 
315 };
316 
317 } /* End of namespace genfit */
320 #endif // genfit_RKTrackRep_h
virtual double extrapolateToPoint(StateOnPlane &state, const TVector3 &point, const TMatrixDSym &G, bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Extrapolates the state to the POCA to a point in the metric of G, and returns the extrapolation lengt...
Definition: RKTrackRep.h:103
void transformPM7(const MeasuredStateOnPlane &state, M7x7 &out7x7) const
Definition: RKTrackRep.cc:1568
void calcForwardJacobianAndNoise(const M1x7 &startState7, const DetPlane &startPlane, const M1x7 &destState7, const DetPlane &destPlane) const
Definition: RKTrackRep.cc:931
Helper to store different limits on the stepsize for the RKTRackRep.
Definition: StepLimits.h:54
virtual TVector3 getPos(const StateOnPlane &state) const
Get the cartesian position of a state.
Definition: RKTrackRep.cc:816
M7x7 noiseProjection_
noise matrix of the last extrapolation
Definition: RKTrackRep.h:308
StepLimits limits_
Definition: RKTrackRep.h:306
TVector3 pocaOnLine(const TVector3 &linePoint, const TVector3 &lineDirection, const TVector3 &point) const
Definition: RKTrackRep.cc:2348
virtual double getQop(const StateOnPlane &state) const
Get charge over momentum.
Definition: RKTrackRep.h:151
boost::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
double * end()
Definition: RKTools.h:46
virtual void getPosMomCov(const MeasuredStateOnPlane &state, TVector3 &pos, TVector3 &mom, TMatrixDSym &cov) const
Translates MeasuredStateOnPlane into 3D position, momentum and 6x6 covariance.
Definition: RKTrackRep.cc:844
double momMag(const M1x7 &state7) const
Definition: RKTrackRep.cc:2706
virtual double extrapolateToPlane(StateOnPlane &state, const SharedPlanePtr &plane, bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Extrapolates the state to plane, and returns the extrapolation length and, via reference, the extrapolated state.
Definition: RKTrackRep.cc:80
double RKPropagate(M1x7 &state7, M7x7 *jacobian, M1x3 &SA, double S, bool varField=true, bool calcOnlyLastRowOfJ=false) const
The actual Runge Kutta propagation.
Definition: RKTrackRep.cc:1272
bool RKutta(const M1x4 &SU, const DetPlane &plane, double charge, double mass, M1x7 &state7, M7x7 *jacobianT, M1x7 *J_MMT_unprojected_lastRow, double &coveredDistance, double &flightTime, bool &checkJacProj, M7x7 &noiseProjection, StepLimits &limits, bool onlyOneStep=false, bool calcOnlyLastRowOfJ=false) const
Propagates the particle through the magnetic field.
Definition: RKTrackRep.cc:1852
virtual double extrapolateBy(StateOnPlane &state, double step, bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Extrapolates the state by step (cm) and returns the extrapolation length and, via reference...
Definition: RKTrackRep.cc:721
void checkCache(const StateOnPlane &state, const SharedPlanePtr *plane) const
Definition: RKTrackRep.cc:2630
virtual ~RKTrackRep()
Definition: RKTrackRep.cc:75
const TVectorD & getState() const
Definition: StateOnPlane.h:61
virtual double extrapolateToSphere(StateOnPlane &state, double radius, const TVector3 &point=TVector3(0., 0., 0.), bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Extrapolates the state to the sphere surface, and returns the extrapolation length and...
Definition: RKTrackRep.cc:610
virtual void setPosMom(StateOnPlane &state, const TVector3 &pos, const TVector3 &mom) const
Set position and momentum of state.
Definition: RKTrackRep.cc:1081
void transformM6P(const M6x6 &in6x6, const M1x7 &state7, MeasuredStateOnPlane &state) const
Definition: RKTrackRep.cc:1770
void calcJ_pM_5x7(M5x7 &J_pM, const TVector3 &U, const TVector3 &V, const M1x3 &pTilde, double spu) const
Definition: RKTrackRep.cc:1595
int RKStepsFXStart_
RungeKutta steps made in the last extrapolation.
Definition: RKTrackRep.h:294
virtual void setQop(StateOnPlane &state, double qop) const
Set charge/momentum.
Definition: RKTrackRep.h:170
virtual double getRadiationLenght() const
Get the accumulated X/X0 (path / radiation length) of the material crossed in the last extrapolation...
Definition: RKTrackRep.cc:1061
TMatrixD fJacobian_
steps made in Extrap during last extrapolation
Definition: RKTrackRep.h:298
virtual double extrapolateToPoint(StateOnPlane &state, const TVector3 &point, bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Extrapolates the state to the POCA to a point, and returns the extrapolation length and...
Definition: RKTrackRep.h:96
MatStep matStep_
Definition: RKTrackRep.h:40
virtual void setPosMomErr(MeasuredStateOnPlane &state, const TVector3 &pos, const TVector3 &mom, const TVector3 &posErr, const TVector3 &momErr) const
Set position and momentum and error of state.
Definition: RKTrackRep.cc:1160
virtual AbsTrackRep * clone() const
Clone the trackRep.
Definition: RKTrackRep.h:81
void initArrays() const
Definition: RKTrackRep.cc:1478
void setSpu(StateOnPlane &state, double spu) const
Definition: RKTrackRep.cc:1260
Helper for RKTrackRep.
Definition: RKTrackRep.h:53
void setTime(StateOnPlane &state, double time) const
Set time at which the state was defined.
Definition: RKTrackRep.cc:1265
StateOnPlane lastEndState_
state where the last extrapolation has started
Definition: RKTrackRep.h:292
virtual double extrapolateToLine(StateOnPlane &state, const TVector3 &linePoint, const TVector3 &lineDirection, bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Extrapolates the state to the POCA to a line, and returns the extrapolation length and...
Definition: RKTrackRep.cc:135
virtual bool isSameType(const AbsTrackRep *other)
check if other is of same type (e.g. RKTrackRep).
Definition: RKTrackRep.cc:2712
StateOnPlane with additional covariance matrix.
Simple struct containing MaterialProperties and stepsize in the material.
Definition: AbsTrackRep.h:42
virtual double getCharge(const StateOnPlane &state) const
Get the (fitted) charge of a state. This is not always equal the pdg charge (e.g. if the charge sign ...
Definition: RKTrackRep.cc:859
virtual TVector3 getMom(const StateOnPlane &state) const
Get the cartesian momentum vector of a state.
Definition: RKTrackRep.cc:824
virtual TMatrixDSym get6DCov(const MeasuredStateOnPlane &state) const
Get the 6D covariance.
Definition: RKTrackRep.cc:851
double * begin()
Definition: RKTools.h:45
unsigned int cachePos_
use cached RKSteps_ for extrapolation
Definition: RKTrackRep.h:302
virtual void getPosMom(const StateOnPlane &state, TVector3 &pos, TVector3 &mom) const
Get cartesian position and momentum vector of a state.
Definition: RKTrackRep.cc:834
virtual void getBackwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const
Get the jacobian and noise matrix of the last extrapolation if it would have been done in opposite di...
Definition: RKTrackRep.cc:1001
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
virtual void setPosMomCov(MeasuredStateOnPlane &state, const TVector3 &pos, const TVector3 &mom, const TMatrixDSym &cov6x6) const
Set position, momentum and covariance of state.
Definition: RKTrackRep.cc:1202
double estimateStep(const M1x7 &state7, const M1x4 &SU, const DetPlane &plane, const double &charge, double &relMomLoss, StepLimits &limits) const
Definition: RKTrackRep.cc:2126
double getSpu(const StateOnPlane &state) const
Definition: RKTrackRep.cc:905
Helper for RKTrackRep.
Definition: RKTrackRep.h:39
virtual double extrapolateToCone(StateOnPlane &state, double radius, const TVector3 &linePoint=TVector3(0., 0., 0.), const TVector3 &lineDirection=TVector3(0., 0., 1.), bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Extrapolates the state to the cone surface, and returns the extrapolation length and, via reference, the extrapolated state.
Definition: RKTrackRep.cc:476
StepLimits limits_
Definition: RKTrackRep.h:42
void getState7(const StateOnPlane &state, M1x7 &state7) const
Definition: RKTrackRep.cc:1497
double getTime(const StateOnPlane &state) const
Get the time corresponding to the StateOnPlane. Extrapolation.
Definition: RKTrackRep.cc:921
void calcJ_Mp_7x5(M7x5 &J_Mp, const TVector3 &U, const TVector3 &V, const TVector3 &W, const M1x3 &A) const
Definition: RKTrackRep.cc:1725
std::vector< genfit::MatStep > getSteps() const
Get stepsizes and material properties of crossed materials of the last extrapolation.
Definition: RKTrackRep.cc:1041
TMatrixDSym fNoise_
Definition: RKTrackRep.h:299
StateOnPlane lastStartState_
Definition: RKTrackRep.h:291
void getState5(StateOnPlane &state, const M1x7 &state7) const
Definition: RKTrackRep.cc:1531
unsigned int getDim() const
Get the dimension of the state vector used by the track representation.
Definition: RKTrackRep.h:138
AbsTrackRep with 5D track parameterization in plane coordinates: (q/p, u', v', u, v) ...
Definition: RKTrackRep.h:71
double Extrap(const DetPlane &startPlane, const DetPlane &destPlane, double charge, double mass, bool &isAtBoundary, M1x7 &state7, double &flightTime, bool fillExtrapSteps, TMatrixDSym *cov=nullptr, bool onlyOneStep=false, bool stopAtBoundary=false, double maxStep=1.E99) const
Handles propagation and material effects.
Definition: RKTrackRep.cc:2360
virtual double getMomVar(const MeasuredStateOnPlane &state) const
get the variance of the absolute value of the momentum .
Definition: RKTrackRep.cc:885
virtual bool isSame(const AbsTrackRep *other)
check if other is of same type (e.g. RKTrackRep) and has same pdg code.
Definition: RKTrackRep.cc:2720
Detector plane.
Definition: DetPlane.h:61
A state with arbitrary dimension defined in a DetPlane.
Definition: StateOnPlane.h:45
virtual double getMomMag(const StateOnPlane &state) const
get the magnitude of the momentum in GeV.
Definition: RKTrackRep.cc:877
std::vector< RKStep > RKSteps_
state where the last extrapolation has ended
Definition: RKTrackRep.h:293
virtual double extrapolateToLine(StateOnPlane &state, const TVector3 &linePoint, const TVector3 &lineDirection, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to the POCA to a line, and returns the extrapolation length and...
virtual void getForwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const
Get the jacobian and noise matrix of the last extrapolation.
Definition: RKTrackRep.cc:977
virtual double extrapToPoint(StateOnPlane &state, const TVector3 &point, const TMatrixDSym *G=NULL, bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Definition: RKTrackRep.cc:235
virtual double extrapolateToCylinder(StateOnPlane &state, double radius, const TVector3 &linePoint=TVector3(0., 0., 0.), const TVector3 &lineDirection=TVector3(0., 0., 1.), bool stopAtBoundary=false, bool calcJacobianNoise=false) const
Extrapolates the state to the cylinder surface, and returns the extrapolation length and...
Definition: RKTrackRep.cc:351
void transformPM6(const MeasuredStateOnPlane &state, M6x6 &out6x6) const
Definition: RKTrackRep.cc:1640
std::vector< ExtrapStep > ExtrapSteps_
Definition: RKTrackRep.h:296
void transformM7P(const M7x7 &in7x7, const M1x7 &state7, MeasuredStateOnPlane &state) const
Definition: RKTrackRep.cc:1702
virtual void setChargeSign(StateOnPlane &state, double charge) const
Set the sign of the charge according to charge.
Definition: RKTrackRep.cc:1246
Defines for I/O streams used for error and debug printing.