ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VertexFitAlgorithm.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VertexFitAlgorithm.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 
11 #include <iostream>
12 
28 
31  : FW::BareAlgorithm("VertexFit", level), m_cfg(cfg) {}
32 
36  const FW::AlgorithmContext& ctx) const {
37  using MagneticField = Acts::ConstantBField;
40  using PropagatorOptions = Acts::PropagatorOptions<>;
43  using VertexFitter =
45  using VertexFitterOptions = Acts::VertexingOptions<TrackParameters>;
46 
47  // Setup the magnetic field
48  MagneticField bField(m_cfg.bField);
49  // Setup the propagator with void navigator
50  auto propagator = std::make_shared<Propagator>(Stepper(bField));
51  PropagatorOptions propagatorOpts(ctx.geoContext, ctx.magFieldContext);
52  // Setup the vertex fitter
53  VertexFitter::Config vertexFitterCfg;
54  VertexFitter vertexFitter(vertexFitterCfg);
55  // Setup the linearizer
56  Linearizer::Config ltConfig(bField, propagator);
57  Linearizer linearizer(ltConfig);
58 
59  const auto& input = ctx.eventStore.get<std::vector<FW::VertexAndTracks>>(
60  m_cfg.trackCollection);
61  for (auto& vertexAndTracks : input) {
62  const auto& inputTrackCollection = vertexAndTracks.tracks;
63 
64  std::vector<const Acts::BoundParameters*> inputTrackPtrCollection;
65  for (const auto& trk : inputTrackCollection) {
66  inputTrackPtrCollection.push_back(&trk);
67  }
68 
69  Acts::Vertex<TrackParameters> fittedVertex;
70  if (!m_cfg.doConstrainedFit) {
71  if (inputTrackCollection.size() < 2) {
72  continue;
73  }
74  // Vertex fitter options
75  VertexFitterOptions vfOptions(ctx.geoContext, ctx.magFieldContext);
76 
77  auto fitRes =
78  vertexFitter.fit(inputTrackPtrCollection, linearizer, vfOptions);
79  if (fitRes.ok()) {
80  fittedVertex = *fitRes;
81  } else {
82  ACTS_ERROR("Error in vertex fit.");
83  }
84  } else {
85  // Vertex constraint
86  Acts::Vertex<TrackParameters> theConstraint;
87 
88  theConstraint.setCovariance(m_cfg.constraintCov);
89  theConstraint.setPosition(m_cfg.constraintPos);
90 
91  // Vertex fitter options
92  VertexFitterOptions vfOptionsConstr(ctx.geoContext, ctx.magFieldContext,
93  theConstraint);
94 
95  auto fitRes = vertexFitter.fit(inputTrackPtrCollection, linearizer,
96  vfOptionsConstr);
97  if (fitRes.ok()) {
98  fittedVertex = *fitRes;
99  } else {
100  ACTS_ERROR("Error in vertex fit.");
101  }
102  }
103 
104  ACTS_INFO("Fitted Vertex: "
105  << "(" << fittedVertex.position().x() << ","
106  << fittedVertex.position().y() << ","
107  << fittedVertex.position().z() << ")");
108  ACTS_INFO("Truth Vertex: "
109  << "(" << vertexAndTracks.vertex.position().x() << ","
110  << vertexAndTracks.vertex.position().y() << ","
111  << vertexAndTracks.vertex.position().z() << ")");
112  }
113 
115 }