File indexing completed on 2025-01-18 09:27:59
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 <functional>
0026
0027 namespace Acts {
0028
0029
0030
0031
0032
0033
0034
0035
0036 class AdaptiveMultiVertexFitter {
0037 public:
0038
0039 struct State {
0040 State(const MagneticFieldProvider& field,
0041 const Acts::MagneticFieldContext& magContext)
0042 : ipState{field.makeCache(magContext)},
0043 fieldCache(field.makeCache(magContext)) {}
0044
0045 std::vector<Vertex*> vertexCollection;
0046
0047
0048 AnnealingUtility::State annealingState;
0049
0050 ImpactPointEstimator::State ipState;
0051
0052 MagneticFieldProvider::Cache fieldCache;
0053
0054
0055
0056 std::map<Vertex*, VertexInfo> vtxInfoMap;
0057
0058 std::multimap<InputTrack, Vertex*> trackToVerticesMultiMap;
0059
0060 std::map<std::pair<InputTrack, Vertex*>, TrackAtVertex> tracksAtVerticesMap;
0061
0062
0063 void addVertexToMultiMap(Vertex& vtx) {
0064 for (auto trk : vtxInfoMap[&vtx].trackLinks) {
0065 trackToVerticesMultiMap.emplace(trk, &vtx);
0066 }
0067 }
0068
0069
0070 void removeVertexFromMultiMap(Vertex& vtx) {
0071 for (auto iter = trackToVerticesMultiMap.begin();
0072 iter != trackToVerticesMultiMap.end();) {
0073 if (iter->second == &vtx) {
0074 iter = trackToVerticesMultiMap.erase(iter);
0075 } else {
0076 ++iter;
0077 }
0078 }
0079 }
0080
0081 Result<void> removeVertexFromCollection(Vertex& vtxToRemove,
0082 const Logger& logger) {
0083 auto it = std::find(vertexCollection.begin(), vertexCollection.end(),
0084 &vtxToRemove);
0085
0086 if (it == vertexCollection.end()) {
0087 ACTS_ERROR("vtxToRemove is not part of vertexCollection.");
0088 return VertexingError::ElementNotFound;
0089 }
0090
0091 vertexCollection.erase(it);
0092 return {};
0093 }
0094 };
0095
0096 struct Config {
0097
0098
0099
0100 Config(ImpactPointEstimator est) : ipEst(std::move(est)) {}
0101
0102
0103 ImpactPointEstimator ipEst;
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 AnnealingUtility annealingTool;
0115
0116
0117 unsigned int maxIterations{30};
0118
0119
0120
0121 double maxDistToLinPoint{0.5};
0122
0123
0124 double minWeight{0.0001};
0125
0126
0127 double maxRelativeShift{0.01};
0128
0129
0130 bool doSmoothing{false};
0131
0132
0133 bool useTime{false};
0134
0135
0136 InputTrack::Extractor extractParameters;
0137
0138 TrackLinearizer trackLinearizer;
0139 };
0140
0141
0142
0143
0144
0145
0146
0147 AdaptiveMultiVertexFitter(Config cfg,
0148 std::unique_ptr<const Logger> logger =
0149 getDefaultLogger("AdaptiveMultiVertexFitter",
0150 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 }