File indexing completed on 2025-08-05 08:18:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef genfit_RKTrackRep_h
0025 #define genfit_RKTrackRep_h
0026
0027 #include "AbsTrackRep.h"
0028 #include "StateOnPlane.h"
0029 #include "RKTools.h"
0030 #include "StepLimits.h"
0031 #include "Material.h"
0032
0033 #include <algorithm>
0034
0035 namespace genfit {
0036
0037
0038
0039
0040 struct RKStep {
0041 MatStep matStep_;
0042 M1x7 state7_;
0043 StepLimits limits_;
0044
0045 RKStep() {
0046 std::fill(state7_.begin(), state7_.end(), 0);
0047 }
0048 };
0049
0050
0051
0052
0053
0054 struct ExtrapStep {
0055 M7x7 jac7_;
0056 M7x7 noise7_;
0057
0058 ExtrapStep() {
0059 std::fill(jac7_.begin(), jac7_.end(), 0);
0060 std::fill(noise7_.begin(), noise7_.end(), 0);
0061 }
0062 };
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 class RKTrackRep : public AbsTrackRep {
0073 friend class RKTrackRepTests_momMag_Test;
0074 friend class RKTrackRepTests_calcForwardJacobianAndNoise_Test;
0075 friend class RKTrackRepTests_getState7_Test;
0076 friend class RKTrackRepTests_getState5_Test;
0077
0078 public:
0079
0080 RKTrackRep();
0081 RKTrackRep(int pdgCode, char propDir = 0);
0082
0083 virtual ~RKTrackRep();
0084
0085 virtual AbsTrackRep* clone() const override {return new RKTrackRep(*this);}
0086
0087 virtual double extrapolateToPlane(StateOnPlane& state,
0088 const SharedPlanePtr& plane,
0089 bool stopAtBoundary = false,
0090 bool calcJacobianNoise = false) const override;
0091
0092 using AbsTrackRep::extrapolateToLine;
0093
0094 virtual double extrapolateToLine(StateOnPlane& state,
0095 const TVector3& linePoint,
0096 const TVector3& lineDirection,
0097 bool stopAtBoundary = false,
0098 bool calcJacobianNoise = false) const override;
0099
0100 virtual double extrapolateToPoint(StateOnPlane& state,
0101 const TVector3& point,
0102 bool stopAtBoundary = false,
0103 bool calcJacobianNoise = false) const override {
0104 return extrapToPoint(state, point, nullptr, stopAtBoundary, calcJacobianNoise);
0105 }
0106
0107 virtual double extrapolateToPoint(StateOnPlane& state,
0108 const TVector3& point,
0109 const TMatrixDSym& G,
0110 bool stopAtBoundary = false,
0111 bool calcJacobianNoise = false) const override {
0112 return extrapToPoint(state, point, &G, stopAtBoundary, calcJacobianNoise);
0113 }
0114
0115 virtual double extrapolateToCylinder(StateOnPlane& state,
0116 double radius,
0117 const TVector3& linePoint = TVector3(0.,0.,0.),
0118 const TVector3& lineDirection = TVector3(0.,0.,1.),
0119 bool stopAtBoundary = false,
0120 bool calcJacobianNoise = false) const override;
0121
0122
0123 virtual double extrapolateToCone(StateOnPlane& state,
0124 double radius,
0125 const TVector3& linePoint = TVector3(0.,0.,0.),
0126 const TVector3& lineDirection = TVector3(0.,0.,1.),
0127 bool stopAtBoundary = false,
0128 bool calcJacobianNoise = false) const override ;
0129
0130 virtual double extrapolateToSphere(StateOnPlane& state,
0131 double radius,
0132 const TVector3& point = TVector3(0.,0.,0.),
0133 bool stopAtBoundary = false,
0134 bool calcJacobianNoise = false) const override;
0135
0136 virtual double extrapolateBy(StateOnPlane& state,
0137 double step,
0138 bool stopAtBoundary = false,
0139 bool calcJacobianNoise = false) const override;
0140
0141
0142 unsigned int getDim() const override {return 5;}
0143
0144 virtual TVector3 getPos(const StateOnPlane& state) const override;
0145
0146 virtual TVector3 getMom(const StateOnPlane& state) const override;
0147 virtual void getPosMom(const StateOnPlane& state, TVector3& pos, TVector3& mom) const override;
0148
0149 virtual double getMomMag(const StateOnPlane& state) const override;
0150 virtual double getMomVar(const MeasuredStateOnPlane& state) const override;
0151
0152 virtual TMatrixDSym get6DCov(const MeasuredStateOnPlane& state) const override;
0153 virtual void getPosMomCov(const MeasuredStateOnPlane& state, TVector3& pos, TVector3& mom, TMatrixDSym& cov) const override;
0154 virtual double getCharge(const StateOnPlane& state) const override;
0155 virtual double getQop(const StateOnPlane& state) const override {return state.getState()(0);}
0156 double getSpu(const StateOnPlane& state) const;
0157 double getTime(const StateOnPlane& state) const override;
0158
0159 virtual void getForwardJacobianAndNoise(TMatrixD& jacobian, TMatrixDSym& noise, TVectorD& deltaState) const override;
0160
0161 virtual void getBackwardJacobianAndNoise(TMatrixD& jacobian, TMatrixDSym& noise, TVectorD& deltaState) const override;
0162
0163 std::vector<genfit::MatStep> getSteps() const override;
0164
0165 virtual double getRadiationLenght() const override;
0166
0167 virtual void setPosMom(StateOnPlane& state, const TVector3& pos, const TVector3& mom) const override;
0168 virtual void setPosMom(StateOnPlane& state, const TVectorD& state6) const override;
0169 virtual void setPosMomErr(MeasuredStateOnPlane& state, const TVector3& pos, const TVector3& mom, const TVector3& posErr, const TVector3& momErr) const override;
0170 virtual void setPosMomCov(MeasuredStateOnPlane& state, const TVector3& pos, const TVector3& mom, const TMatrixDSym& cov6x6) const override;
0171 virtual void setPosMomCov(MeasuredStateOnPlane& state, const TVectorD& state6, const TMatrixDSym& cov6x6) const override;
0172
0173 virtual void setChargeSign(StateOnPlane& state, double charge) const override;
0174 virtual void setQop(StateOnPlane& state, double qop) const override {state.getState()(0) = qop;}
0175
0176 void setSpu(StateOnPlane& state, double spu) const;
0177 void setTime(StateOnPlane& state, double time) const override;
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 virtual double RKPropagate(M1x7& state7,
0189 M7x7* jacobian,
0190 M1x3& SA,
0191 double S,
0192 bool varField = true,
0193 bool calcOnlyLastRowOfJ = false) const;
0194
0195 virtual bool isSameType(const AbsTrackRep* other) override;
0196 virtual bool isSame(const AbsTrackRep* other) override;
0197
0198 private:
0199
0200 void initArrays() const;
0201
0202 virtual double extrapToPoint(StateOnPlane& state,
0203 const TVector3& point,
0204 const TMatrixDSym* G = nullptr,
0205 bool stopAtBoundary = false,
0206 bool calcJacobianNoise = false) const;
0207
0208 void getState7(const StateOnPlane& state, M1x7& state7) const;
0209 void getState5(StateOnPlane& state, const M1x7& state7) const;
0210
0211 void calcJ_pM_5x7(M5x7& J_pM, const TVector3& U, const TVector3& V, const M1x3& pTilde, double spu) const;
0212
0213 void transformPM6(const MeasuredStateOnPlane& state,
0214 M6x6& out6x6) const;
0215
0216 void calcJ_Mp_7x5(M7x5& J_Mp, const TVector3& U, const TVector3& V, const TVector3& W, const M1x3& A) const;
0217
0218 void calcForwardJacobianAndNoise(const M1x7& startState7, const DetPlane& startPlane,
0219 const M1x7& destState7, const DetPlane& destPlane) const;
0220
0221 void transformM6P(const M6x6& in6x6,
0222 const M1x7& state7,
0223 MeasuredStateOnPlane& state) const;
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235 bool RKutta(const M1x4& SU,
0236 const DetPlane& plane,
0237 double charge,
0238 double mass,
0239 M1x7& state7,
0240 M7x7* jacobianT,
0241 M1x7* J_MMT_unprojected_lastRow,
0242 double& coveredDistance,
0243 double& flightTime,
0244 bool& checkJacProj,
0245 M7x7& noiseProjection,
0246 StepLimits& limits,
0247 bool onlyOneStep = false,
0248 bool calcOnlyLastRowOfJ = false) const;
0249
0250 double estimateStep(const M1x7& state7,
0251 const M1x4& SU,
0252 const DetPlane& plane,
0253 const double& charge,
0254 double& relMomLoss,
0255 StepLimits& limits) const;
0256
0257 TVector3 pocaOnLine(const TVector3& linePoint,
0258 const TVector3& lineDirection,
0259 const TVector3& point) const;
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270 double Extrap(const DetPlane& startPlane,
0271 const DetPlane& destPlane,
0272 double charge,
0273 double mass,
0274 bool& isAtBoundary,
0275 M1x7& state7,
0276 double& flightTime,
0277 bool fillExtrapSteps,
0278 TMatrixDSym* cov = nullptr,
0279 bool onlyOneStep = false,
0280 bool stopAtBoundary = false,
0281 double maxStep = 1.E99) const;
0282
0283 void checkCache(const StateOnPlane& state, const SharedPlanePtr* plane) const;
0284
0285 double momMag(const M1x7& state7) const;
0286
0287 protected:
0288
0289 mutable StateOnPlane lastStartState_;
0290 mutable StateOnPlane lastEndState_;
0291
0292 private:
0293
0294 mutable std::vector<RKStep> RKSteps_;
0295 mutable int RKStepsFXStart_;
0296 mutable int RKStepsFXStop_;
0297 mutable std::vector<ExtrapStep> ExtrapSteps_;
0298
0299 mutable TMatrixD fJacobian_;
0300 mutable TMatrixDSym fNoise_;
0301
0302 mutable bool useCache_;
0303 mutable unsigned int cachePos_;
0304
0305
0306
0307 mutable StepLimits limits_;
0308 mutable M7x7 noiseArray_;
0309 mutable M7x7 noiseProjection_;
0310 mutable M7x7 J_MMT_;
0311
0312 public:
0313
0314 ClassDefOverride(RKTrackRep, 1)
0315
0316 };
0317
0318 }
0319
0320
0321 #endif