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