File indexing completed on 2025-01-18 09:11:34
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Geometry/GeometryHierarchyMap.hpp"
0012 #include "Acts/TrackFitting/KalmanFitter.hpp"
0013 #include "ActsAlignment/Kernel/Alignment.hpp"
0014 #include "ActsExamples/EventData/Measurement.hpp"
0015 #include "ActsExamples/EventData/ProtoTrack.hpp"
0016 #include "ActsExamples/EventData/Track.hpp"
0017 #include "ActsExamples/Framework/DataHandle.hpp"
0018 #include "ActsExamples/Framework/IAlgorithm.hpp"
0019 #include "ActsExamples/MagneticField/MagneticField.hpp"
0020
0021 #include <functional>
0022 #include <memory>
0023 #include <vector>
0024
0025 namespace ActsExamples {
0026
0027 class AlignmentGroup {
0028 public:
0029 AlignmentGroup(const std::string& name,
0030 const std::vector<Acts::GeometryIdentifier>& geoIds)
0031 : m_name(name), m_map(constructHierarchyMap(geoIds)) {}
0032
0033
0034 std::string getNameOfGroup() const { return m_name; }
0035
0036
0037 bool has(Acts::GeometryIdentifier geoId) {
0038 auto it = m_map.find(geoId);
0039 return (it == m_map.end()) ? false : *it;
0040 }
0041
0042 private:
0043 std::string m_name;
0044 Acts::GeometryHierarchyMap<bool> m_map;
0045
0046 Acts::GeometryHierarchyMap<bool> constructHierarchyMap(
0047 const std::vector<Acts::GeometryIdentifier>& geoIds) {
0048 std::vector<Acts::GeometryHierarchyMap<bool>::InputElement> ies;
0049 for (const auto& geoId : geoIds) {
0050 ies.emplace_back(geoId, true);
0051 }
0052 return Acts::GeometryHierarchyMap<bool>(ies);
0053 }
0054 };
0055
0056 class AlignmentAlgorithm final : public IAlgorithm {
0057 public:
0058 using AlignmentResult = Acts::Result<ActsAlignment::AlignmentResult>;
0059 using AlignmentParameters =
0060 std::unordered_map<Acts::DetectorElementBase*, Acts::Transform3>;
0061
0062
0063
0064 using TrackFitterOptions =
0065 Acts::KalmanFitterOptions<Acts::VectorMultiTrajectory>;
0066
0067
0068
0069
0070 class AlignmentFunction {
0071 public:
0072 virtual ~AlignmentFunction() = default;
0073 virtual AlignmentResult operator()(
0074 const std::vector<std::vector<IndexSourceLink>>&,
0075 const TrackParametersContainer&,
0076 const ActsAlignment::AlignmentOptions<TrackFitterOptions>&) const = 0;
0077 };
0078
0079
0080
0081
0082
0083 static std::shared_ptr<AlignmentFunction> makeAlignmentFunction(
0084 std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry,
0085 std::shared_ptr<const Acts::MagneticFieldProvider> magneticField);
0086
0087 struct Config {
0088
0089 std::string inputMeasurements;
0090
0091 std::string inputProtoTracks;
0092
0093 std::string inputInitialTrackParameters;
0094
0095 std::string outputAlignmentParameters;
0096
0097 std::shared_ptr<AlignmentFunction> align;
0098
0099 ActsAlignment::AlignedTransformUpdater alignedTransformUpdater;
0100
0101 std::vector<Acts::DetectorElementBase*> alignedDetElements;
0102
0103 std::map<unsigned int, std::bitset<6>> iterationState;
0104
0105 double chi2ONdfCutOff = 0.10;
0106
0107 std::pair<std::size_t, double> deltaChi2ONdfCutOff = {10, 0.00001};
0108
0109 std::size_t maxNumIterations = 100;
0110
0111 int maxNumTracks = -1;
0112 std::vector<AlignmentGroup> m_groups;
0113 };
0114
0115
0116
0117
0118
0119 AlignmentAlgorithm(Config cfg, Acts::Logging::Level lvl);
0120
0121
0122
0123
0124
0125 ActsExamples::ProcessCode execute(
0126 const ActsExamples::AlgorithmContext& ctx) const override;
0127
0128 private:
0129 Config m_cfg;
0130
0131 ReadDataHandle<MeasurementContainer> m_inputMeasurements{this,
0132 "InputMeasurements"};
0133 ReadDataHandle<TrackParametersContainer> m_inputInitialTrackParameters{
0134 this, "InputInitialTrackParameters"};
0135 ReadDataHandle<ProtoTrackContainer> m_inputProtoTracks{this,
0136 "InputProtoTracks"};
0137 WriteDataHandle<AlignmentParameters> m_outputAlignmentParameters{
0138 this, "OutputAlignmentParameters"};
0139 };
0140
0141 }