Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:19

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/EventData/TrackParameters.hpp"
0012 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0013 #include "Acts/EventData/detail/GenerateParameters.hpp"
0014 #include "Acts/EventData/detail/TestSourceLink.hpp"
0015 #include "Acts/Surfaces/CurvilinearSurface.hpp"
0016 #include "Acts/Utilities/CalibrationContext.hpp"
0017 
0018 #include <random>
0019 
0020 namespace Acts::detail::Test {
0021 
0022 struct TestTrackState {
0023   std::shared_ptr<Surface> surface;
0024   TestSourceLink sourceLink;
0025   BoundTrackParameters predicted;
0026   BoundTrackParameters filtered;
0027   BoundTrackParameters smoothed;
0028   BoundMatrix jacobian;
0029   double chi2;
0030   double pathLength;
0031 
0032   // Generate a random TestTrackState.
0033   //
0034   // @param rng Random number generator
0035   // @param std::size_t nMeasurement either 1 or 2
0036   template <typename rng_t>
0037   TestTrackState(rng_t& rng, std::size_t measdim)
0038       : surface(
0039             CurvilinearSurface(Vector3::Zero(), Vector3::UnitZ()).surface()),
0040         // set bogus parameters first since they are not default-constructible
0041         predicted(surface, BoundVector::Zero(), std::nullopt,
0042                   ParticleHypothesis::pion()),
0043         filtered(surface, BoundVector::Zero(), std::nullopt,
0044                  ParticleHypothesis::pion()),
0045         smoothed(surface, BoundVector::Zero(), std::nullopt,
0046                  ParticleHypothesis::pion()),
0047         jacobian(BoundMatrix::Identity()),
0048         chi2(std::chi_squared_distribution<double>(measdim)(rng)),
0049         pathLength(std::uniform_real_distribution<ActsScalar>(
0050             1 * Acts::UnitConstants::mm, 10 * Acts::UnitConstants::mm)(rng)) {
0051     // set a random geometry identifier to uniquely identify each surface
0052     auto geoId =
0053         std::uniform_int_distribution<GeometryIdentifier::Value>()(rng);
0054     surface->assignGeometryId(geoId);
0055 
0056     // create source link w/ inline 1d or 2d measurement data
0057     if (measdim == 1u) {
0058       auto [par, cov] = generateParametersCovariance<ActsScalar, 1u>(rng);
0059       sourceLink = TestSourceLink(eBoundLoc0, par[0], cov(0, 0), geoId);
0060     } else if (measdim == 2u) {
0061       auto [par, cov] = generateParametersCovariance<ActsScalar, 2u>(rng);
0062       sourceLink = TestSourceLink(eBoundLoc1, eBoundQOverP, par, cov, geoId);
0063     } else {
0064       throw std::runtime_error("invalid number of measurement dimensions");
0065     }
0066 
0067     // create track parameters
0068     auto [trkPar, trkCov] = generateBoundParametersCovariance(rng);
0069     // trkPar[eBoundPhi] = 45_degree;
0070     // trkPar[eBoundTheta] = 90_degree;
0071     // trkPar[eBoundQOverP] = 5.;
0072     // predicted
0073     predicted = BoundTrackParameters(surface, trkPar, trkCov,
0074                                      ParticleHypothesis::pion());
0075     // filtered, modified q/p, reduced covariance
0076     // trkPar[eBoundQOverP] = 10.;
0077     filtered = BoundTrackParameters(surface, trkPar, 0.75 * trkCov,
0078                                     ParticleHypothesis::pion());
0079     // smoothed, modified q/p, further reduced covariance
0080     // trkPar[eBoundQOverP] = 15.;
0081     smoothed = BoundTrackParameters(surface, trkPar, 0.5 * trkCov,
0082                                     ParticleHypothesis::pion());
0083 
0084     // propagation jacobian is identity + corrections
0085     for (Eigen::Index c = 0; c < jacobian.cols(); ++c) {
0086       for (Eigen::Index r = 0; r < jacobian.rows(); ++r) {
0087         jacobian(c, r) +=
0088             std::uniform_real_distribution<ActsScalar>(-0.125, 0.125)(rng);
0089       }
0090     }
0091   }
0092 };
0093 
0094 // Fill a TrackStateProxy with values from a TestTrackState.
0095 //
0096 // @param[in] pc TestTrackState with the input values
0097 // @param[in] mask Specifies which components are used/filled
0098 // @param[out] ts TrackStateProxy which is filled
0099 // @param [in] measdim Dimension of the measurement
0100 template <typename trajectory_t, typename track_state_t>
0101 void fillTrackState(const TestTrackState& pc, TrackStatePropMask mask,
0102                     track_state_t& ts) {
0103   // always set the reference surface
0104   ts.setReferenceSurface(pc.predicted.referenceSurface().getSharedPtr());
0105 
0106   if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Predicted)) {
0107     ts.predicted() = pc.predicted.parameters();
0108     assert(pc.predicted.covariance().has_value());
0109     ts.predictedCovariance() = *(pc.predicted.covariance());
0110   }
0111   if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Filtered)) {
0112     ts.filtered() = pc.filtered.parameters();
0113     assert(pc.filtered.covariance().has_value());
0114     ts.filteredCovariance() = *(pc.filtered.covariance());
0115   }
0116   if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Smoothed)) {
0117     ts.smoothed() = pc.smoothed.parameters();
0118     assert(pc.smoothed.covariance().has_value());
0119     ts.smoothedCovariance() = *(pc.smoothed.covariance());
0120   }
0121   if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Jacobian)) {
0122     ts.jacobian() = pc.jacobian;
0123   }
0124   ts.chi2() = pc.chi2;
0125   ts.pathLength() = pc.pathLength;
0126   // source link defines the uncalibrated measurement
0127   // create calibrated measurements from source link
0128   if (ACTS_CHECK_BIT(mask, TrackStatePropMask::Calibrated)) {
0129     testSourceLinkCalibrator<trajectory_t>(Acts::GeometryContext{},
0130                                            Acts::CalibrationContext{},
0131                                            SourceLink{pc.sourceLink}, ts);
0132     assert(ts.hasUncalibratedSourceLink());
0133   }
0134 }
0135 
0136 }  // namespace Acts::detail::Test