File indexing completed on 2025-01-18 09:11:19
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/EventData/detail/PrintParameters.hpp"
0010
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Surfaces/Surface.hpp"
0013
0014 #include <array>
0015 #include <cstddef>
0016 #include <iomanip>
0017 #include <ostream>
0018 #include <string>
0019
0020 namespace {
0021
0022 constexpr std::array<const char*, Acts::eBoundSize> makeBoundNames() {
0023 std::array<const char*, Acts::eBoundSize> names = {nullptr};
0024
0025 names[Acts::eBoundLoc0] = "loc0:";
0026 names[Acts::eBoundLoc1] = "loc1:";
0027 names[Acts::eBoundTime] = "time:";
0028 names[Acts::eBoundPhi] = "phi:";
0029 names[Acts::eBoundTheta] = "theta:";
0030 names[Acts::eBoundQOverP] = "q/p:";
0031 return names;
0032 }
0033
0034 constexpr std::array<const char*, Acts::eFreeSize> makeFreeNames() {
0035 std::array<const char*, Acts::eFreeSize> names = {nullptr};
0036
0037 names[Acts::eFreePos0] = "pos0:";
0038 names[Acts::eFreePos1] = "pos1:";
0039 names[Acts::eFreePos2] = "pos2:";
0040 names[Acts::eFreeTime] = "time:";
0041 names[Acts::eFreeDir0] = "dir0:";
0042 names[Acts::eFreeDir1] = "dir1:";
0043 names[Acts::eFreeDir2] = "dir2:";
0044 names[Acts::eFreeQOverP] = "q/p:";
0045 return names;
0046 }
0047
0048 constexpr std::array<std::size_t, 8> kMonotonic = {
0049 0, 1, 2, 3, 4, 5, 6, 7,
0050 };
0051
0052 constexpr std::size_t kNamesMaxSize = 6;
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 template <typename names_container_t, typename indices_container_t,
0072 typename parameters_t, typename covariance_t>
0073 void printParametersCovariance(std::ostream& os, const names_container_t& names,
0074 const indices_container_t& nameIndices,
0075 const Eigen::MatrixBase<parameters_t>& params,
0076 const Eigen::MatrixBase<covariance_t>& cov) {
0077 EIGEN_STATIC_ASSERT_VECTOR_ONLY(parameters_t);
0078
0079
0080 auto flags = os.flags();
0081 auto precision = os.precision();
0082
0083
0084 auto stddev = cov.diagonal().cwiseSqrt().eval();
0085
0086 for (Eigen::Index i = 0; i < params.size(); ++i) {
0087
0088
0089 if (0 < i) {
0090 os << '\n';
0091 }
0092
0093 os << std::setw(kNamesMaxSize) << std::left << names[nameIndices[i]];
0094
0095 os << " ";
0096 os << std::defaultfloat << std::setprecision(4);
0097 os << std::setw(10) << std::right << params[i];
0098
0099 os << " +- ";
0100 os << std::setw(10) << std::left << stddev[i];
0101
0102 os << " ";
0103 os << std::fixed << std::setprecision(3);
0104 for (Eigen::Index j = 0; j <= i; ++j) {
0105 auto corr = cov(i, j) / (stddev[i] * stddev[j]);
0106 os << " " << std::setw(6) << std::right << corr;
0107 }
0108 }
0109
0110
0111 os.flags(flags);
0112 os.precision(precision);
0113 }
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 template <typename names_container_t, typename indices_container_t,
0132 typename parameters_t>
0133 void printParameters(std::ostream& os, const names_container_t& names,
0134 const indices_container_t& nameIndices,
0135 const Eigen::MatrixBase<parameters_t>& params) {
0136 EIGEN_STATIC_ASSERT_VECTOR_ONLY(parameters_t);
0137
0138
0139 auto flags = os.flags();
0140 auto precision = os.precision();
0141
0142 for (Eigen::Index i = 0; i < params.size(); ++i) {
0143
0144
0145 if (0 < i) {
0146 os << '\n';
0147 }
0148
0149 os << std::setw(kNamesMaxSize) << std::left << names[nameIndices[i]];
0150
0151 os << " ";
0152 os << std::defaultfloat << std::setprecision(4);
0153 os << std::setw(10) << std::right << params[i];
0154 }
0155
0156
0157 os.flags(flags);
0158 os.precision(precision);
0159 }
0160
0161 using ParametersMap = Eigen::Map<const Acts::ActsDynamicVector>;
0162 using CovarianceMap = Eigen::Map<const Acts::ActsDynamicMatrix>;
0163
0164 }
0165
0166 void Acts::detail::printBoundParameters(std::ostream& os,
0167 const Acts::Surface& surface,
0168 const Acts::BoundVector& params,
0169 const Acts::BoundSquareMatrix* cov) {
0170 if (cov != nullptr) {
0171 printParametersCovariance(os, makeBoundNames(), kMonotonic, params, *cov);
0172 } else {
0173 printParameters(os, makeBoundNames(), kMonotonic, params);
0174 }
0175 os << "\non surface " << surface.geometryId() << " of type "
0176 << surface.name();
0177 }
0178
0179 void Acts::detail::printFreeParameters(std::ostream& os,
0180 const Acts::FreeVector& params,
0181 const Acts::FreeMatrix* cov) {
0182 if (cov != nullptr) {
0183 printParametersCovariance(os, makeFreeNames(), kMonotonic, params, *cov);
0184 } else {
0185 printParameters(os, makeFreeNames(), kMonotonic, params);
0186 }
0187 }
0188
0189 void Acts::detail::printMeasurement(std::ostream& os, BoundIndices size,
0190 const std::uint8_t* indices,
0191 const double* params, const double* cov) {
0192 auto s = static_cast<Eigen::Index>(size);
0193 printParametersCovariance(os, makeBoundNames(), indices,
0194 ParametersMap(params, s), CovarianceMap(cov, s, s));
0195 }
0196
0197 void Acts::detail::printMeasurement(std::ostream& os, FreeIndices size,
0198 const std::uint8_t* indices,
0199 const double* params, const double* cov) {
0200 auto s = static_cast<Eigen::Index>(size);
0201 printParametersCovariance(os, makeFreeNames(), indices,
0202 ParametersMap(params, s), CovarianceMap(cov, s, s));
0203 }