File indexing completed on 2025-09-17 08:01:43
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Material/IVolumeMaterial.hpp"
0013 #include "Acts/Material/Interactions.hpp"
0014 #include "Acts/Material/Material.hpp"
0015 #include "Acts/Material/MaterialSlab.hpp"
0016 #include "Acts/Propagator/EigenStepperDefaultExtension.hpp"
0017 #include "Acts/Utilities/MathHelpers.hpp"
0018
0019 namespace Acts {
0020
0021
0022
0023
0024
0025
0026 struct EigenStepperDenseExtension {
0027
0028 EigenStepperDefaultExtension defaultExtension;
0029
0030
0031 double currentMomentum = 0.;
0032
0033 double initialMomentum = 0.;
0034
0035
0036 Material material = Material::Vacuum();
0037
0038 std::array<double, 4> dLdl{};
0039
0040 std::array<double, 4> qop{};
0041
0042 std::array<double, 4> dPds{};
0043
0044 double dgdqopValue = 0.;
0045
0046 double g = 0.;
0047
0048 std::array<double, 4> tKi{};
0049
0050 std::array<double, 4> Lambdappi{};
0051
0052 std::array<double, 4> energy{};
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 template <int i, typename stepper_t>
0071 bool k(const typename stepper_t::State& state, const stepper_t& stepper,
0072 const IVolumeMaterial* volumeMaterial, Vector3& knew,
0073 const Vector3& bField, std::array<double, 4>& kQoP,
0074 const double h = 0., const Vector3& kprev = Vector3::Zero())
0075 requires(i >= 0 && i <= 3)
0076 {
0077 if (volumeMaterial == nullptr) {
0078 return defaultExtension.template k<i>(state, stepper, volumeMaterial,
0079 knew, bField, kQoP, h, kprev);
0080 }
0081
0082 double q = stepper.charge(state);
0083 const auto& particleHypothesis = stepper.particleHypothesis(state);
0084 float mass = particleHypothesis.mass();
0085
0086
0087 if constexpr (i == 0) {
0088
0089 Vector3 position = stepper.position(state);
0090 material = volumeMaterial->material(position.template cast<double>());
0091 initialMomentum = stepper.absoluteMomentum(state);
0092 currentMomentum = initialMomentum;
0093 qop[0] = stepper.qOverP(state);
0094 initializeEnergyLoss(state, stepper);
0095
0096 knew = qop[0] * stepper.direction(state).cross(bField);
0097
0098 Lambdappi[0] = -qop[0] * qop[0] * qop[0] * g * energy[0] / (q * q);
0099
0100 tKi[0] = fastHypot(1, mass * qop[0]);
0101 kQoP[0] = Lambdappi[0];
0102 } else {
0103
0104 updateEnergyLoss(mass, h, state, stepper, i);
0105 if (currentMomentum < state.options.dense.momentumCutOff) {
0106 return false;
0107 }
0108
0109 knew = qop[i] * (stepper.direction(state) + h * kprev).cross(bField);
0110
0111 auto qopNew = qop[0] + h * Lambdappi[i - 1];
0112 Lambdappi[i] = -qopNew * qopNew * qopNew * g * energy[i] / (q * q);
0113 tKi[i] = fastHypot(1, mass * qopNew);
0114 kQoP[i] = Lambdappi[i];
0115 }
0116 return true;
0117 }
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 template <typename stepper_t>
0133 bool finalize(typename stepper_t::State& state, const stepper_t& stepper,
0134 const IVolumeMaterial* volumeMaterial, const double h) const {
0135 if (volumeMaterial == nullptr) {
0136 return defaultExtension.finalize(state, stepper, volumeMaterial, h);
0137 }
0138
0139 const auto& particleHypothesis = stepper.particleHypothesis(state);
0140 float mass = particleHypothesis.mass();
0141
0142
0143 auto newMomentum =
0144 stepper.absoluteMomentum(state) +
0145 (h / 6.) * (dPds[0] + 2. * (dPds[1] + dPds[2]) + dPds[3]);
0146
0147
0148 if (newMomentum < state.options.dense.momentumCutOff) {
0149 return false;
0150 }
0151
0152
0153 state.derivative(7) = -fastHypot(mass, newMomentum) * g /
0154 (newMomentum * newMomentum * newMomentum);
0155
0156
0157 state.pars[eFreeQOverP] = stepper.charge(state) / newMomentum;
0158
0159 state.derivative(3) = fastHypot(1, mass / newMomentum);
0160
0161 state.pars[eFreeTime] +=
0162 (h / 6.) * (tKi[0] + 2. * (tKi[1] + tKi[2]) + tKi[3]);
0163
0164 return true;
0165 }
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183 template <typename stepper_t>
0184 bool finalize(typename stepper_t::State& state, const stepper_t& stepper,
0185 const IVolumeMaterial* volumeMaterial, const double h,
0186 FreeMatrix& D) const {
0187 if (volumeMaterial == nullptr) {
0188 return defaultExtension.finalize(state, stepper, volumeMaterial, h, D);
0189 }
0190
0191 return finalize(state, stepper, volumeMaterial, h) &&
0192 transportMatrix(state, stepper, h, D);
0193 }
0194
0195 private:
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207 template <typename stepper_t>
0208 bool transportMatrix(typename stepper_t::State& state,
0209 const stepper_t& stepper, const double h,
0210 FreeMatrix& D) const {
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231 auto& sd = state.stepData;
0232 auto dir = stepper.direction(state);
0233 const auto& particleHypothesis = stepper.particleHypothesis(state);
0234 float mass = particleHypothesis.mass();
0235
0236 D = FreeMatrix::Identity();
0237 const double half_h = h * 0.5;
0238
0239
0240
0241 auto dFdT = D.block<3, 3>(0, 4);
0242 auto dFdL = D.block<3, 1>(0, 7);
0243
0244 auto dGdT = D.block<3, 3>(4, 4);
0245 auto dGdL = D.block<3, 1>(4, 7);
0246
0247 SquareMatrix3 dk1dT = SquareMatrix3::Zero();
0248 SquareMatrix3 dk2dT = SquareMatrix3::Identity();
0249 SquareMatrix3 dk3dT = SquareMatrix3::Identity();
0250 SquareMatrix3 dk4dT = SquareMatrix3::Identity();
0251
0252 Vector3 dk1dL = Vector3::Zero();
0253 Vector3 dk2dL = Vector3::Zero();
0254 Vector3 dk3dL = Vector3::Zero();
0255 Vector3 dk4dL = Vector3::Zero();
0256
0257
0258 std::array<double, 4> jdL{};
0259
0260
0261 jdL[0] = dLdl[0];
0262 dk1dL = dir.cross(sd.B_first);
0263
0264 jdL[1] = dLdl[1] * (1. + half_h * jdL[0]);
0265 dk2dL = (1. + half_h * jdL[0]) * (dir + half_h * sd.k1).cross(sd.B_middle) +
0266 qop[1] * half_h * dk1dL.cross(sd.B_middle);
0267
0268 jdL[2] = dLdl[2] * (1. + half_h * jdL[1]);
0269 dk3dL = (1. + half_h * jdL[1]) * (dir + half_h * sd.k2).cross(sd.B_middle) +
0270 qop[2] * half_h * dk2dL.cross(sd.B_middle);
0271
0272 jdL[3] = dLdl[3] * (1. + h * jdL[2]);
0273 dk4dL = (1. + h * jdL[2]) * (dir + h * sd.k3).cross(sd.B_last) +
0274 qop[3] * h * dk3dL.cross(sd.B_last);
0275
0276 dk1dT(0, 1) = sd.B_first.z();
0277 dk1dT(0, 2) = -sd.B_first.y();
0278 dk1dT(1, 0) = -sd.B_first.z();
0279 dk1dT(1, 2) = sd.B_first.x();
0280 dk1dT(2, 0) = sd.B_first.y();
0281 dk1dT(2, 1) = -sd.B_first.x();
0282 dk1dT *= qop[0];
0283
0284 dk2dT += half_h * dk1dT;
0285 dk2dT = qop[1] * VectorHelpers::cross(dk2dT, sd.B_middle);
0286
0287 dk3dT += half_h * dk2dT;
0288 dk3dT = qop[2] * VectorHelpers::cross(dk3dT, sd.B_middle);
0289
0290 dk4dT += h * dk3dT;
0291 dk4dT = qop[3] * VectorHelpers::cross(dk4dT, sd.B_last);
0292
0293 dFdT.setIdentity();
0294 dFdT += h / 6. * (dk1dT + dk2dT + dk3dT);
0295 dFdT *= h;
0296
0297 dFdL = h * h / 6. * (dk1dL + dk2dL + dk3dL);
0298
0299 dGdT += h / 6. * (dk1dT + 2. * (dk2dT + dk3dT) + dk4dT);
0300
0301 dGdL = h / 6. * (dk1dL + 2. * (dk2dL + dk3dL) + dk4dL);
0302
0303
0304 D(7, 7) += (h / 6.) * (jdL[0] + 2. * (jdL[1] + jdL[2]) + jdL[3]);
0305
0306
0307
0308
0309
0310
0311
0312
0313 double dtp1dl = qop[0] * mass * mass / fastHypot(1, qop[0] * mass);
0314 double qopNew = qop[0] + half_h * Lambdappi[0];
0315
0316
0317
0318
0319
0320
0321 double dtp2dl = qopNew * mass * mass / fastHypot(1, qopNew * mass);
0322 qopNew = qop[0] + half_h * Lambdappi[1];
0323
0324
0325
0326
0327
0328
0329 double dtp3dl = qopNew * mass * mass / fastHypot(1, qopNew * mass);
0330 qopNew = qop[0] + half_h * Lambdappi[2];
0331 double dtp4dl = qopNew * mass * mass / fastHypot(1, qopNew * mass);
0332
0333
0334
0335
0336
0337 D(3, 7) = (h / 6.) * (dtp1dl + 2. * (dtp2dl + dtp3dl) + dtp4dl);
0338 return true;
0339 }
0340
0341
0342
0343
0344
0345
0346
0347
0348 template <typename stepper_t>
0349 void initializeEnergyLoss(const typename stepper_t::State& state,
0350 const stepper_t& stepper) {
0351 const auto& particleHypothesis = stepper.particleHypothesis(state);
0352 float mass = particleHypothesis.mass();
0353 PdgParticle absPdg = particleHypothesis.absolutePdg();
0354 float absQ = particleHypothesis.absoluteCharge();
0355
0356 energy[0] = fastHypot(initialMomentum, mass);
0357
0358 MaterialSlab slab(material, 1);
0359
0360 if (state.options.dense.meanEnergyLoss) {
0361 g = -computeEnergyLossMean(slab, absPdg, mass, static_cast<float>(qop[0]),
0362 absQ);
0363 } else {
0364
0365
0366 g = -computeEnergyLossMode(slab, absPdg, mass, static_cast<float>(qop[0]),
0367 absQ);
0368 }
0369
0370
0371 dPds[0] = g * energy[0] / initialMomentum;
0372 if (state.covTransport) {
0373
0374
0375 if (state.options.dense.includeGradient) {
0376 if (state.options.dense.meanEnergyLoss) {
0377 dgdqopValue = deriveEnergyLossMeanQOverP(
0378 slab, absPdg, mass, static_cast<float>(qop[0]), absQ);
0379 } else {
0380
0381 dgdqopValue = deriveEnergyLossModeQOverP(
0382 slab, absPdg, mass, static_cast<float>(qop[0]), absQ);
0383 }
0384 }
0385
0386 dLdl[0] = (-qop[0] * qop[0] * g * energy[0] *
0387 (3. - (initialMomentum * initialMomentum) /
0388 (energy[0] * energy[0])) -
0389 qop[0] * qop[0] * qop[0] * energy[0] * dgdqopValue);
0390 }
0391 }
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403 template <typename stepper_t>
0404 void updateEnergyLoss(const double mass, const double h,
0405 const typename stepper_t::State& state,
0406 const stepper_t& stepper, const int i) {
0407
0408 currentMomentum = initialMomentum + h * dPds[i - 1];
0409 energy[i] = fastHypot(currentMomentum, mass);
0410 dPds[i] = g * energy[i] / currentMomentum;
0411 qop[i] = stepper.charge(state) / currentMomentum;
0412
0413 if (state.covTransport) {
0414 dLdl[i] = (-qop[i] * qop[i] * g * energy[i] *
0415 (3. - (currentMomentum * currentMomentum) /
0416 (energy[i] * energy[i])) -
0417 qop[i] * qop[i] * qop[i] * energy[i] * dgdqopValue);
0418 }
0419 }
0420 };
0421
0422 }