PandaRoot
genfit2/trackReps/include/RKTrackRep.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 /* Copyright 2008-2010, Technische Universitaet Muenchen,
14  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch
15 
16  This file is part of GENFIT.
17 
18  GENFIT is free software: you can redistribute it and/or modify
19  it under the terms of the GNU Lesser General Public License as published
20  by the Free Software Foundation, either version 3 of the License, or
21  (at your option) any later version.
22 
23  GENFIT is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  GNU Lesser General Public License for more details.
27 
28  You should have received a copy of the GNU Lesser General Public License
29  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
30 */
31 
36 #ifndef genfit_RKTrackRep_h
37 #define genfit_RKTrackRep_h
38 
39 #include "AbsTrackRep.h"
40 #include "StateOnPlane.h"
41 #include "RKTools.h"
42 #include "StepLimits.h"
43 
44 namespace genfit {
45 
49 struct RKStep {
50  MatStep matStep_; // material properties and stepsize
51  M1x7 state7_; // 7D state vector
53 
54  RKStep() { memset(state7_, 0x00, 7 * sizeof(double)); }
55 };
56 
60 struct ExtrapStep {
61  M7x7 jac7_; // 5D jacobian of transport
62  M7x7 noise7_; // 5D noise matrix
63 
65  {
66  memset(jac7_, 0, sizeof(M7x7));
67  memset(noise7_, 0, sizeof(M7x7));
68  }
69 };
70 
78 class RKTrackRep : public AbsTrackRep {
79 
80  public:
81  RKTrackRep();
82  RKTrackRep(int pdgCode, char propDir = 0);
83 
84  virtual ~RKTrackRep();
85 
86  virtual AbsTrackRep *clone() const { return new RKTrackRep(*this); }
87 
88  virtual double extrapolateToPlane(StateOnPlane &state, const SharedPlanePtr &plane, bool stopAtBoundary = false, bool calcJacobianNoise = false) const;
89 
91 
92  virtual double
93  extrapolateToLine(StateOnPlane &state, const TVector3 &linePoint, const TVector3 &lineDirection, bool stopAtBoundary = false, bool calcJacobianNoise = false) const;
94 
95  virtual double extrapolateToPoint(StateOnPlane &state, const TVector3 &point, bool stopAtBoundary = false, bool calcJacobianNoise = false) const
96  {
97  return extrapToPoint(state, point, nullptr, stopAtBoundary, calcJacobianNoise);
98  }
99 
100  virtual double extrapolateToPoint(StateOnPlane &state, const TVector3 &point,
101  const TMatrixDSym &G, // weight matrix (metric)
102  bool stopAtBoundary = false, bool calcJacobianNoise = false) const
103  {
104  return extrapToPoint(state, point, &G, stopAtBoundary, calcJacobianNoise);
105  }
106 
107  virtual double extrapolateToCylinder(StateOnPlane &state, double radius, const TVector3 &linePoint = TVector3(0., 0., 0.), const TVector3 &lineDirection = TVector3(0., 0., 1.),
108  bool stopAtBoundary = false, bool calcJacobianNoise = false) const;
109 
110  virtual double
111  extrapolateToSphere(StateOnPlane &state, double radius, const TVector3 &point = TVector3(0., 0., 0.), bool stopAtBoundary = false, bool calcJacobianNoise = false) const;
112 
113  virtual double extrapolateBy(StateOnPlane &state, double step, bool stopAtBoundary = false, bool calcJacobianNoise = false) const;
114 
115  unsigned int getDim() const { return 5; }
116 
117  virtual TVector3 getPos(const StateOnPlane &state) const;
118 
119  virtual TVector3 getMom(const StateOnPlane &state) const;
120  virtual void getPosMom(const StateOnPlane &state, TVector3 &pos, TVector3 &mom) const;
121 
122  virtual double getMomMag(const StateOnPlane &state) const;
123  virtual double getMomVar(const MeasuredStateOnPlane &state) const;
124 
125  virtual TMatrixDSym get6DCov(const MeasuredStateOnPlane &state) const;
126  virtual void getPosMomCov(const MeasuredStateOnPlane &state, TVector3 &pos, TVector3 &mom, TMatrixDSym &cov) const;
127  virtual double getCharge(const StateOnPlane &state) const;
128  virtual double getQop(const StateOnPlane &state) const { return state.getState()(0); }
129  double getSpu(const StateOnPlane &state) const;
130  double getTime(const StateOnPlane &state) const;
131 
132  virtual void getForwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const;
133 
134  virtual void getBackwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const;
135 
136  std::vector<genfit::MatStep> getSteps() const;
137 
138  virtual double getRadiationLenght() const;
139 
140  virtual void setPosMom(StateOnPlane &state, const TVector3 &pos, const TVector3 &mom) const;
141  virtual void setPosMom(StateOnPlane &state, const TVectorD &state6) const;
142  virtual void setPosMomErr(MeasuredStateOnPlane &state, const TVector3 &pos, const TVector3 &mom, const TVector3 &posErr, const TVector3 &momErr) const;
143  virtual void setPosMomCov(MeasuredStateOnPlane &state, const TVector3 &pos, const TVector3 &mom, const TMatrixDSym &cov6x6) const;
144  virtual void setPosMomCov(MeasuredStateOnPlane &state, const TVectorD &state6, const TMatrixDSym &cov6x6) const;
145 
146  virtual void setChargeSign(StateOnPlane &state, double charge) const;
147  virtual void setQop(StateOnPlane &state, double qop) const { state.getState()(0) = qop; }
148 
149  void setSpu(StateOnPlane &state, double spu) const;
150  void setTime(StateOnPlane &state, double time) const;
151 
153 
160  double RKPropagate(M1x7 &state7, M7x7 *jacobian, M1x3 &SA, double S, bool varField = true, bool calcOnlyLastRowOfJ = false) const;
161 
162  virtual bool isSameType(const AbsTrackRep *other);
163  virtual bool isSame(const AbsTrackRep *other);
164 
165  private:
166  void initArrays() const;
167 
168  virtual double extrapToPoint(StateOnPlane &state, const TVector3 &point,
169  const TMatrixDSym *G = nullptr, // weight matrix (metric)
170  bool stopAtBoundary = false, bool calcJacobianNoise = false) const;
171 
172  void getState7(const StateOnPlane &state, M1x7 &state7) const;
173  void getState5(StateOnPlane &state, const M1x7 &state7) const; // state7 must already lie on plane of state!
174 
175  void transformPM7(const MeasuredStateOnPlane &state, M7x7 &out7x7) const;
176 
177  void calcJ_pM_5x7(M5x7 &J_pM, const TVector3 &U, const TVector3 &V, const M1x3 &pTilde, double spu) const;
178 
179  void transformPM6(const MeasuredStateOnPlane &state, M6x6 &out6x6) const;
180 
181  void transformM7P(const M7x7 &in7x7, const M1x7 &state7,
182  MeasuredStateOnPlane &state) const; // plane must already be set!
183 
184  void calcJ_Mp_7x5(M7x5 &J_Mp, const TVector3 &U, const TVector3 &V, const TVector3 &W, const M1x3 &A) const;
185 
186  void calcForwardJacobianAndNoise(const M1x7 &startState7, const DetPlane &startPlane, const M1x7 &destState7, const DetPlane &destPlane) const;
187 
188  void transformM6P(const M6x6 &in6x6, const M1x7 &state7,
189  MeasuredStateOnPlane &state) const; // plane and charge must already be set!
190 
192 
201  bool RKutta(const M1x4 &SU, const DetPlane &plane, double charge, double mass, M1x7 &state7, M7x7 *jacobianT, M1x7 *J_MMT_unprojected_lastRow,
202  double &coveredDistance, // signed
203  double &flightTime, bool &checkJacProj, M7x7 &noiseProjection, StepLimits &limits, bool onlyOneStep = false, bool calcOnlyLastRowOfJ = false) const;
204 
205  double estimateStep(const M1x7 &state7, const M1x4 &SU, const DetPlane &plane, const double &charge, double &relMomLoss, StepLimits &limits) const;
206 
207  TVector3 pocaOnLine(const TVector3 &linePoint, const TVector3 &lineDirection, const TVector3 &point) const;
208 
210 
218  double Extrap(const DetPlane &startPlane, // plane where Extrap starts
219  const DetPlane &destPlane, // plane where Extrap has to extrapolate to
220  double charge, double mass, bool &isAtBoundary, M1x7 &state7, double &flightTime, bool fillExtrapSteps, TMatrixDSym *cov = nullptr, bool onlyOneStep = false,
221  bool stopAtBoundary = false, double maxStep = 1.E99) const;
222 
223  void checkCache(const StateOnPlane &state, const SharedPlanePtr *plane) const;
224 
225  double momMag(const M1x7 &state7) const;
226 
227  mutable StateOnPlane lastStartState_;
228  mutable StateOnPlane lastEndState_;
229  mutable std::vector<RKStep> RKSteps_;
230  mutable int RKStepsFXStart_;
231  mutable int RKStepsFXStop_;
232  mutable std::vector<ExtrapStep> ExtrapSteps_;
233 
234  mutable TMatrixD fJacobian_;
235  mutable TMatrixDSym fNoise_;
236 
237  mutable bool useCache_;
238  mutable unsigned int cachePos_;
239 
240  // auxiliary variables and arrays
241  // needed in Extrap()
242  mutable StepLimits limits_;
243  mutable M7x7 noiseArray_;
244  mutable M7x7 noiseProjection_;
245  mutable M7x7 J_MMT_;
246 
247  public:
248  ClassDef(RKTrackRep, 1)
249 };
250 
251 } /* End of namespace genfit */
254 #endif // genfit_RKTrackRep_h
const TVectorD & getState() const
Definition: StateOnPlane.h:69
Detector plane.
Definition: DetPlane.h:72
Simple struct containing MaterialProperties and stepsize in the material.
Definition: AbsTrackRep.h:53
Helper to store different limits on the stepsize for the RKTRackRep.
Definition: StepLimits.h:64
double M6x6[6 *6]
Definition: RKTools.h:50
Abstract base class for a track representation.
Definition: AbsTrackRep.h:74
double M1x4[1 *4]
Definition: RKTools.h:46
StateOnPlane with additional covariance matrix.
virtual AbsTrackRep * clone() const
Clone the trackRep.
double M7x5[7 *5]
Definition: RKTools.h:54
A state with arbitrary dimension defined in a DetPlane.
Definition: StateOnPlane.h:56
double M1x7[1 *7]
Definition: RKTools.h:48
double M5x7[5 *7]
Definition: RKTools.h:56
virtual void setQop(StateOnPlane &state, double qop) const
Set charge/momentum.
boost::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
virtual double getQop(const StateOnPlane &state) const
Get charge over momentum.
double M1x3[1 *3]
Definition: RKTools.h:45
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...
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...
AbsTrackRep with 5D track parameterization in plane coordinates: (q/p, u&#39;, v&#39;, u, v) ...
double M7x7[7 *7]
Definition: RKTools.h:51
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...
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:64
unsigned int getDim() const
Get the dimension of the state vector used by the track representation.
Matrix inversion tools.
Definition: AbsBField.h:40