File indexing completed on 2025-07-13 07:50:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/EventData/TrackParameters.hpp"
0013 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0014 #include "Acts/Utilities/AnnealingUtility.hpp"
0015 #include "Acts/Utilities/Logger.hpp"
0016 #include "Acts/Utilities/Result.hpp"
0017 #include "Acts/Vertexing/AMVFInfo.hpp"
0018 #include "Acts/Vertexing/ImpactPointEstimator.hpp"
0019 #include "Acts/Vertexing/TrackAtVertex.hpp"
0020 #include "Acts/Vertexing/TrackLinearizer.hpp"
0021 #include "Acts/Vertexing/Vertex.hpp"
0022 #include "Acts/Vertexing/VertexingError.hpp"
0023 #include "Acts/Vertexing/VertexingOptions.hpp"
0024
0025 #include <algorithm>
0026 #include <functional>
0027
0028 namespace Acts {
0029
0030
0031
0032
0033
0034
0035
0036
0037 class AdaptiveMultiVertexFitter {
0038 public:
0039
0040 struct State {
0041 State(const MagneticFieldProvider& field,
0042 const Acts::MagneticFieldContext& magContext)
0043 : ipState{field.makeCache(magContext)},
0044 fieldCache(field.makeCache(magContext)) {}
0045
0046
0047 std::vector<Vertex*> vertexCollection;
0048
0049
0050 AnnealingUtility::State annealingState;
0051
0052 ImpactPointEstimator::State ipState;
0053
0054 MagneticFieldProvider::Cache fieldCache;
0055
0056
0057
0058 std::map<Vertex*, VertexInfo> vtxInfoMap;
0059
0060 std::multimap<InputTrack, Vertex*> trackToVerticesMultiMap;
0061
0062 std::map<std::pair<InputTrack, Vertex*>, TrackAtVertex> tracksAtVerticesMap;
0063
0064
0065 void addVertexToMultiMap(Vertex& vtx) {
0066 for (auto trk : vtxInfoMap[&vtx].trackLinks) {
0067 trackToVerticesMultiMap.emplace(trk, &vtx);
0068 }
0069 }
0070
0071
0072 void removeVertexFromMultiMap(Vertex& vtx) {
0073 for (auto iter = trackToVerticesMultiMap.begin();
0074 iter != trackToVerticesMultiMap.end();) {
0075 if (iter->second == &vtx) {
0076 iter = trackToVerticesMultiMap.erase(iter);
0077 } else {
0078 ++iter;
0079 }
0080 }
0081 }
0082
0083 Result<void> removeVertexFromCollection(Vertex& vtxToRemove,
0084 const Logger& logger) {
0085 auto it = std::ranges::find(vertexCollection, &vtxToRemove);
0086
0087 if (it == vertexCollection.end()) {
0088 ACTS_ERROR("vtxToRemove is not part of vertexCollection.");
0089 return VertexingError::ElementNotFound;
0090 }
0091
0092 vertexCollection.erase(it);
0093 return {};
0094 }
0095 };
0096
0097 struct Config {
0098
0099
0100
0101 explicit Config(ImpactPointEstimator est) : ipEst(std::move(est)) {}
0102
0103
0104 ImpactPointEstimator ipEst;
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115 AnnealingUtility annealingTool;
0116
0117
0118 unsigned int maxIterations{30};
0119
0120
0121
0122 double maxDistToLinPoint{0.5};
0123
0124
0125 double minWeight{0.0001};
0126
0127
0128 double maxRelativeShift{0.01};
0129
0130
0131 bool doSmoothing{false};
0132
0133
0134 bool useTime{false};
0135
0136
0137 InputTrack::Extractor extractParameters;
0138
0139 TrackLinearizer trackLinearizer;
0140 };
0141
0142
0143
0144
0145
0146
0147
0148 explicit AdaptiveMultiVertexFitter(
0149 Config cfg, std::unique_ptr<const Logger> logger = getDefaultLogger(
0150 "AdaptiveMultiVertexFitter", Logging::INFO))
0151 : m_cfg(std::move(cfg)), m_logger(std::move(logger)) {
0152 if (!m_cfg.extractParameters.connected()) {
0153 throw std::invalid_argument(
0154 "AdaptiveMultiVertexFitter: No function to extract parameters "
0155 "from InputTrack_t provided.");
0156 }
0157
0158 if (!m_cfg.trackLinearizer.connected()) {
0159 throw std::invalid_argument(
0160 "AdaptiveMultiVertexFitter: No track linearizer provided.");
0161 }
0162 }
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 Result<void> addVtxToFit(State& state, Vertex& newVertex,
0179 const VertexingOptions& vertexingOptions) const;
0180
0181
0182
0183
0184
0185
0186
0187
0188 Result<void> fit(State& state,
0189 const VertexingOptions& vertexingOptions) const;
0190
0191 private:
0192
0193 const Config m_cfg;
0194
0195
0196 std::unique_ptr<const Logger> m_logger;
0197
0198
0199 const Logger& logger() const { return *m_logger; }
0200
0201
0202
0203
0204
0205
0206
0207 bool isAlreadyInList(Vertex* vtx,
0208 const std::vector<Vertex*>& verticesVec) const;
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218 Result<void> prepareVertexForFit(
0219 State& state, Vertex* vtx,
0220 const VertexingOptions& vertexingOptions) const;
0221
0222
0223
0224
0225
0226
0227
0228 Result<void> setAllVertexCompatibilities(
0229 State& state, Vertex* currentVtx,
0230 const VertexingOptions& vertexingOptions) const;
0231
0232
0233
0234
0235
0236
0237 Result<void> setWeightsAndUpdate(
0238 State& state, const VertexingOptions& vertexingOptions) const;
0239
0240
0241
0242
0243
0244
0245
0246
0247 std::vector<double> collectTrackToVertexCompatibilities(
0248 State& state, const InputTrack& trk) const;
0249
0250
0251
0252
0253
0254
0255
0256 bool checkSmallShift(State& state) const;
0257
0258
0259
0260
0261
0262 void doVertexSmoothing(State& state) const;
0263
0264
0265
0266
0267
0268 void logDebugData(const State& state,
0269 const GeometryContext& geoContext) const;
0270 };
0271
0272 }