File indexing completed on 2025-01-18 09:11:13
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 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 AdaptiveMultiVertexFitter(Config cfg,
0149 std::unique_ptr<const Logger> logger =
0150 getDefaultLogger("AdaptiveMultiVertexFitter",
0151 Logging::INFO))
0152 : m_cfg(std::move(cfg)), m_logger(std::move(logger)) {
0153 if (!m_cfg.extractParameters.connected()) {
0154 throw std::invalid_argument(
0155 "AdaptiveMultiVertexFitter: No function to extract parameters "
0156 "from InputTrack_t provided.");
0157 }
0158
0159 if (!m_cfg.trackLinearizer.connected()) {
0160 throw std::invalid_argument(
0161 "AdaptiveMultiVertexFitter: No track linearizer provided.");
0162 }
0163 }
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179 Result<void> addVtxToFit(State& state, Vertex& newVertex,
0180 const VertexingOptions& vertexingOptions) const;
0181
0182
0183
0184
0185
0186
0187
0188
0189 Result<void> fit(State& state,
0190 const VertexingOptions& vertexingOptions) const;
0191
0192 private:
0193
0194 const Config m_cfg;
0195
0196
0197 std::unique_ptr<const Logger> m_logger;
0198
0199
0200 const Logger& logger() const { return *m_logger; }
0201
0202
0203
0204
0205
0206
0207
0208 bool isAlreadyInList(Vertex* vtx,
0209 const std::vector<Vertex*>& verticesVec) const;
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 Result<void> prepareVertexForFit(
0220 State& state, Vertex* vtx,
0221 const VertexingOptions& vertexingOptions) const;
0222
0223
0224
0225
0226
0227
0228
0229 Result<void> setAllVertexCompatibilities(
0230 State& state, Vertex* currentVtx,
0231 const VertexingOptions& vertexingOptions) const;
0232
0233
0234
0235
0236
0237
0238 Result<void> setWeightsAndUpdate(
0239 State& state, const VertexingOptions& vertexingOptions) const;
0240
0241
0242
0243
0244
0245
0246
0247
0248 std::vector<double> collectTrackToVertexCompatibilities(
0249 State& state, const InputTrack& trk) const;
0250
0251
0252
0253
0254
0255
0256
0257 bool checkSmallShift(State& state) const;
0258
0259
0260
0261
0262
0263 void doVertexSmoothing(State& state) const;
0264
0265
0266
0267
0268
0269 void logDebugData(const State& state,
0270 const GeometryContext& geoContext) const;
0271 };
0272
0273 }