Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AdaptiveMultiVertexFinderAlgorithm.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AdaptiveMultiVertexFinderAlgorithm.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020-2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
25 
26 #include <memory>
27 #include <optional>
28 #include <ostream>
29 #include <stdexcept>
30 #include <system_error>
31 
32 #include "VertexingHelpers.hpp"
33 
37  : ActsExamples::IAlgorithm("AdaptiveMultiVertexFinder", level),
38  m_cfg(config) {
39  if (m_cfg.inputTrackParameters.empty() == m_cfg.inputTrajectories.empty()) {
40  throw std::invalid_argument(
41  "You have to either provide track parameters or trajectories");
42  }
43  if (m_cfg.outputProtoVertices.empty()) {
44  throw std::invalid_argument("Missing output proto vertices collection");
45  }
46  if (m_cfg.outputVertices.empty()) {
47  throw std::invalid_argument("Missing output vertices collection");
48  }
49 
52 
55 }
56 
59  const ActsExamples::AlgorithmContext& ctx) const {
60  if (m_cfg.seedFinder == SeedFinder::GaussianSeeder) {
61  using Seeder = Acts::TrackDensityVertexFinder<
64  Seeder seedFinder;
65  return executeAfterSeederChoice<Seeder, Finder>(ctx, seedFinder);
66  } else if (m_cfg.seedFinder == SeedFinder::AdaptiveGridSeeder) {
69  // The seeder config argument corresponds to the bin size in mm
70  Seeder::Config seederConfig(0.05);
71  Seeder seedFinder(seederConfig);
72  return executeAfterSeederChoice<Seeder, Finder>(ctx, seedFinder);
73  } else {
74  return ActsExamples::ProcessCode::ABORT;
75  }
76 }
77 
78 template <typename vseeder_t, typename vfinder_t>
82  const vseeder_t& seedFinder) const {
83  using Finder = vfinder_t;
84 
85  // Set up EigenStepper
87 
88  // Set up the propagator
89  auto propagator = std::make_shared<Propagator>(stepper);
90 
91  // Set up ImpactPointEstimator
92  IPEstimator::Config ipEstimatorCfg(m_cfg.bField, propagator);
93  IPEstimator ipEstimator(ipEstimatorCfg);
94 
95  // Set up the helical track linearizer
96  Linearizer::Config ltConfig(m_cfg.bField, propagator);
97  Linearizer linearizer(ltConfig, logger().cloneWithSuffix("HelLin"));
98 
99  // Set up deterministic annealing with user-defined temperatures
100  Acts::AnnealingUtility::Config annealingConfig;
101  annealingConfig.setOfTemperatures = {1.};
102  Acts::AnnealingUtility annealingUtility(annealingConfig);
103 
104  // Set up the vertex fitter with user-defined annealing
105  Fitter::Config fitterCfg(ipEstimator);
106  fitterCfg.annealingTool = annealingUtility;
107  fitterCfg.minWeight = 0.001;
108  fitterCfg.doSmoothing = true;
109  Fitter fitter(fitterCfg, logger().cloneWithSuffix("AMVFitter"));
110 
111  typename Finder::Config finderConfig(std::move(fitter), seedFinder,
112  ipEstimator, std::move(linearizer),
113  m_cfg.bField);
114  finderConfig.looseConstrValue = 1e2;
115  finderConfig.tracksMaxZinterval = 1. * Acts::UnitConstants::mm;
116  finderConfig.maxIterations = 200;
117 
118  // Instantiate the finder
119  Finder finder(finderConfig, logger().cloneWithSuffix("AMVFinder"));
120 
121  // retrieve input tracks and convert into the expected format
122 
123  auto [inputTrackParameters, inputTrackPointers] =
124  makeParameterContainers(ctx, m_inputTrackParameters, m_inputTrajectories);
125 
126  if (inputTrackParameters.size() != inputTrackPointers.size()) {
127  ACTS_ERROR("Input track containers do not align: "
128  << inputTrackParameters.size()
129  << " != " << inputTrackPointers.size());
130  }
131 
132  for (const auto& trk : inputTrackParameters) {
133  if (trk.covariance() && trk.covariance()->determinant() <= 0) {
134  // actually we should consider this as an error but I do not want the CI
135  // to fail
136  ACTS_WARNING("input track " << trk << " has det(cov) = "
137  << trk.covariance()->determinant());
138  }
139  }
140 
142  /* Full tutorial example code for reference */
144 
145  // The vertex finder state
146  typename Finder::State state;
147 
148  // Default vertexing options, this is where e.g. a constraint could be set
149  Options finderOpts(ctx.geoContext, ctx.magFieldContext);
150 
152 
153  if (inputTrackParameters.empty()) {
154  ACTS_DEBUG("Empty track parameter collection found, skipping vertexing");
155  } else {
156  ACTS_DEBUG("Have " << inputTrackParameters.size()
157  << " input track parameters, running vertexing");
158  // find vertices
159  auto result = finder.find(inputTrackPointers, finderOpts, state);
160 
161  if (result.ok()) {
162  vertices = std::move(result.value());
163  } else {
164  ACTS_ERROR("Error in vertex finder: " << result.error().message());
165  }
166  }
167 
168  // show some debug output
169  ACTS_INFO("Found " << vertices.size() << " vertices in event");
170  for (const auto& vtx : vertices) {
171  ACTS_DEBUG("Found vertex at " << vtx.fullPosition().transpose() << " with "
172  << vtx.tracks().size() << " tracks.");
173  }
174 
175  // store proto vertices extracted from the found vertices
176  m_outputProtoVertices(ctx, makeProtoVertices(inputTrackParameters, vertices));
177 
178  // store found vertices
179  m_outputVertices(ctx, std::move(vertices));
180 
182 }