File indexing completed on 2025-01-18 09:11:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016 #include "ActsExamples/EventData/Index.hpp"
0017 #include "ActsExamples/EventData/SimHit.hpp"
0018 #include "ActsExamples/Utilities/Range.hpp"
0019
0020 #include <tuple>
0021
0022 namespace ActsExamples {
0023
0024
0025 using HitSimHitsRange = Range<IndexMultimap<Index>::const_iterator>;
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 inline std::tuple<Acts::Vector2, Acts::Vector4, Acts::Vector3> averageSimHits(
0038 const Acts::GeometryContext& gCtx, const Acts::Surface& surface,
0039 const SimHitContainer& simHits, const HitSimHitsRange& hitSimHitsRange,
0040 const Acts::Logger& logger) {
0041 using namespace Acts::UnitLiterals;
0042
0043 Acts::Vector2 avgLocal = Acts::Vector2::Zero();
0044 Acts::Vector4 avgPos4 = Acts::Vector4::Zero();
0045 Acts::Vector3 avgDir = Acts::Vector3::Zero();
0046
0047 std::size_t n = 0u;
0048 for (auto [_, simHitIdx] : hitSimHitsRange) {
0049 n += 1u;
0050
0051
0052
0053 const auto& simHit = *simHits.nth(simHitIdx);
0054
0055
0056
0057
0058 const auto tolerance =
0059 surface.associatedDetectorElement() != nullptr
0060 ? surface.associatedDetectorElement()->thickness()
0061 : Acts::s_onSurfaceTolerance;
0062
0063
0064
0065
0066 auto result = surface.globalToLocal(gCtx, simHit.position(),
0067 simHit.direction(), tolerance);
0068 if (result.ok()) {
0069 avgLocal += result.value();
0070 } else {
0071 ACTS_WARNING("While averaging simhit, hit "
0072 << simHitIdx << " is not on the corresponding surface "
0073 << surface.geometryId() << "; use [0,0] as local position");
0074 }
0075
0076
0077 avgPos4 += simHit.fourPosition();
0078 avgDir += simHit.direction();
0079 }
0080
0081
0082 if (2u <= n) {
0083 double scale = 1.0 / n;
0084 avgLocal *= scale;
0085 avgPos4 *= scale;
0086 avgDir.normalize();
0087 }
0088
0089 return {avgLocal, avgPos4, avgDir};
0090 }
0091
0092 }