8 #include "GaudiKernel/IInterface.h"
18 #include "Acts/Propagator/Navigator.hpp"
19 #include "Acts/Propagator/EigenStepper.hpp"
20 #include "Acts/Propagator/Propagator.hpp"
21 #include "Acts/Utilities/AnnealingUtility.hpp"
22 #include "Acts/Vertexing/TrackAtVertex.hpp"
31 struct VertexAndSignalComp {
43 const std::string&
name,
51 using namespace std::literals::string_literals;
58 ATH_MSG_INFO(
"Initializing ACTS Iterative Vertex Finder tool");
59 ATH_CHECK( m_trackingGeometryTool.retrieve() );
60 std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry
61 = m_trackingGeometryTool->trackingGeometry();
63 ATH_CHECK( m_extrapolationTool.retrieve() );
66 logger().cloneWithSuffix(
"Navigator"));
68 m_bField = std::make_shared<ATLASMagneticFieldWrapper>();
69 auto stepper = Acts::EigenStepper<>(m_bField);
70 m_propagator = std::make_shared<Propagator>(std::move(stepper),
72 logger().cloneWithSuffix(
"Prop"));
74 Acts::ImpactPointEstimator::Config ipEstCfg(m_bField, m_propagator);
75 ipEstCfg.maxIterations = m_ipEstMaxIterations;
76 ipEstCfg.precision = m_ipEstPrecision;
77 Acts::ImpactPointEstimator ipEst(ipEstCfg,
78 logger().cloneWithSuffix(
"ImpactPointEstimator"));
81 TrackLinearizer::Config ltConfig;
82 ltConfig.bField = m_bField;
83 ltConfig.propagator = m_propagator;
84 m_linearizer.emplace(ltConfig,
logger().cloneWithSuffix(
"Linearizer"));
87 VertexFitter::Config fitterCfg;
88 fitterCfg.maxIterations = m_fitterMaxIterations;
89 fitterCfg.extractParameters.connect<&TrackWrapper::extractParameters>();
90 fitterCfg.trackLinearizer.connect<&TrackLinearizer::linearizeTrack>(&*m_linearizer);
96 Acts::GaussianTrackDensity::Config trackDensityConfig;
97 trackDensityConfig.d0MaxSignificance = m_gaussianMaxD0Significance;
98 trackDensityConfig.z0MaxSignificance = m_gaussianMaxZ0Significance;
99 trackDensityConfig.extractParameters.connect<&TrackWrapper::extractParameters>();
100 Acts::GaussianTrackDensity trackDensity(trackDensityConfig);
103 VertexSeedFinder::Config seedFinderConfig{trackDensity};
104 auto seedFinder = std::make_shared<VertexSeedFinder>(seedFinderConfig);
107 VertexFinder::Config finderConfig(std::move(
fitter),
108 std::move(seedFinder),
110 finderConfig.significanceCutSeeding = m_significanceCutSeeding;
111 finderConfig.maximumChi2cutForSeeding = m_maximumChi2cutForSeeding;
112 finderConfig.maxVertices = m_maxVertices;
113 finderConfig.createSplitVertices = m_createSplitVertices;
114 finderConfig.splitVerticesTrkInvFraction = m_splitVerticesTrkInvFraction;
115 finderConfig.reassignTracksAfterFirstFit = m_reassignTracksAfterFirstFit;
116 finderConfig.doMaxTracksCut = m_doMaxTracksCut;
117 finderConfig.maxTracks = m_maxTracks;
118 finderConfig.cutOffTrackWeight = m_cutOffTrackWeight;
119 finderConfig.extractParameters.connect<&TrackWrapper::extractParameters>();
120 finderConfig.trackLinearizer.connect<&TrackLinearizer::linearizeTrack>(&*m_linearizer);
121 m_vertexFinder = std::make_shared<VertexFinder>(std::move(finderConfig),
logger().cloneWithSuffix(
"Finder"));
123 ATH_MSG_INFO(
"ACTS Iterative Vertex Finder tool successfully initialized");
124 return StatusCode::SUCCESS;
127 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
135 std::vector<std::unique_ptr<Trk::ITrackLink>> selectedTracks;
139 bool selectionPassed;
140 for (TrackDataVecIter itr = (*trackTES).begin(); itr != (*trackTES).end(); ++itr) {
141 if (m_useBeamConstraint) {
142 selectionPassed =
static_cast<bool>(m_trkFilter->accept(**itr, &beamposition));
145 selectionPassed =
static_cast<bool>(m_trkFilter->accept(**itr, &
null));
147 if (selectionPassed) {
150 auto trkPtr = std::make_unique<Trk::LinkToTrack>(link);
151 trkPtr->setStorableObject(*trackTES);
152 selectedTracks.push_back(std::move(trkPtr));
156 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> returnContainers = findVertex(ctx, std::move(selectedTracks));
158 return returnContainers;
161 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
166 std::vector<std::unique_ptr<Trk::ITrackLink>> selectedTracks;
170 beamposition.
setPosition(beamSpotHandle->beamVtx().position());
175 bool selectionPassed;
176 for (TrackParticleDataVecIter itr = (*trackParticles).begin(); itr != (*trackParticles).end(); ++itr) {
177 if (m_useBeamConstraint) {
178 selectionPassed =
static_cast<bool>(m_trkFilter->accept(**itr, &beamposition));
184 vertexError.setZero();
185 null.setCovariancePosition(vertexError);
186 selectionPassed =
static_cast<bool>(m_trkFilter->accept(**itr, &
null));
189 if (selectionPassed) {
192 auto trkPtr = std::make_unique<Trk::LinkToXAODTrackParticle>(link);
193 trkPtr->setStorableObject(*trackParticles);
194 selectedTracks.push_back(std::move(trkPtr));
198 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> returnContainers = findVertex(ctx, std::move(selectedTracks));
200 return returnContainers;
203 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
205 const std::vector<std::unique_ptr<Trk::ITrackLink>>& trackVector)
const
208 using namespace Acts::UnitLiterals;
216 theVertexContainer->setStore(theVertexAuxContainer);
219 if((m_doMaxTracksCut && (trackVector.size() > m_maxTracks)) || trackVector.empty()) {
221 <<
" tracks - exceeds maximum (" << m_maxTracks
222 <<
"), skipping vertexing and returning only dummy...");
226 dummyxAODVertex->
setPosition(beamSpotHandle->beamVtx().position());
228 beamSpotHandle->beamVtx().covariancePosition());
229 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
231 return std::make_pair(theVertexContainer, theVertexAuxContainer);
234 const Acts::Vector3& beamSpotPos = beamSpotHandle->beamVtx().position();
236 beamSpotConstraintVtx.setCovariance(beamSpotHandle->beamVtx().covariancePosition());
238 std::shared_ptr<Acts::PerigeeSurface> perigeeSurface =
239 Acts::Surface::makeShared<Acts::PerigeeSurface>((trackVector[0])->
parameters()->associatedSurface().
transform());
242 Acts::MagneticFieldContext magFieldContext = m_extrapolationTool->getMagneticFieldContext(ctx);
244 const auto& geoContext
245 = m_trackingGeometryTool->getGeometryContext(ctx).context();
248 std::vector<TrackWrapper> allTracks;
250 for (
const auto& trk : trackVector) {
252 const auto& trkParams = trk->parameters();
253 const auto&
params = trkParams->parameters();
255 Acts::BoundVector actsParams;
258 if(trkParams->covariance() ==
nullptr){
261 auto cov = *(trkParams->covariance());
266 Acts::BoundSquareMatrix covMat;
267 covMat <<
cov(0,0) ,
cov(0,1) ,
cov(0,2) ,
cov(0,3) ,
cov(0,4) *1./(1_MeV), 0
268 ,
cov(1,0) ,
cov(1,1) ,
cov(1,2) ,
cov(1,3) ,
cov(1,4) *1./(1_MeV) , 0
269 ,
cov(2,0) ,
cov(2,1) ,
cov(2,2) ,
cov(2,3) ,
cov(2,4) *1./(1_MeV) , 0
270 ,
cov(3,0) ,
cov(3,1) ,
cov(3,2) ,
cov(3,3) ,
cov(3,4) *1./(1_MeV) , 0
271 ,
cov(4,0) *1./(1_MeV) ,
cov(4,1) *1./(1_MeV) ,
cov(4,2) *1./(1_MeV) ,
cov(4,3) *1./(1_MeV) ,
cov(4,4) *1./(1_MeV*1_MeV), 0
272 , 0. , 0. , 0. , 0., 0., 1.;
277 std::vector<Acts::InputTrack> allTrackPtrs;
278 allTrackPtrs.reserve(allTracks.size());
280 for(
const auto& trk : allTracks){
281 allTrackPtrs.emplace_back(&trk);
284 Acts::VertexingOptions vertexingOptions(geoContext,
287 if(!m_useBeamConstraint){
291 vertexingOptions.useConstraintInFit = m_useBeamConstraint;
294 Acts::Vector4 vtxConstraintPos;
295 Acts::SquareMatrix4 vtxConstraintCov;
297 auto beamSpotCov = beamSpotHandle->beamVtx().covariancePosition();
299 vtxConstraintPos << beamSpotPos(0), beamSpotPos(1), beamSpotPos(2), 0.;
300 vtxConstraintCov << beamSpotCov(0,0), beamSpotCov(0,1), beamSpotCov(0,2), 0.
301 , beamSpotCov(1,0), beamSpotCov(1,1), beamSpotCov(1,2), 0.
302 , beamSpotCov(2,0), beamSpotCov(2,1), beamSpotCov(2,2), 0.
305 vertexingOptions.constraint.setFullPosition(vtxConstraintPos);
306 vertexingOptions.constraint.setFullCovariance(vtxConstraintCov);
308 auto finderState = m_vertexFinder->makeState(magFieldContext);
310 auto findResult = m_vertexFinder->find(allTrackPtrs, vertexingOptions, finderState);
312 if(!findResult.ok()){
314 theVertexContainer->
push_back(dummyxAODVertex);
315 dummyxAODVertex->
setPosition(beamSpotHandle->beamVtx().position());
317 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
320 return std::make_pair(theVertexContainer, theVertexAuxContainer);
323 std::vector<Acts::Vertex> allVertices = *findResult;
325 for(
const auto& vtx : allVertices){
330 xAODVtx->
setFitQuality(vtx.fitQuality().first, vtx.fitQuality().second);
332 const auto& tracks = vtx.tracks();
333 std::vector<Trk::VxTrackAtVertex>* trkAtVtxVec = &(xAODVtx->
vxTrackAtVertex());
334 for(
const auto& trk : tracks){
336 Trk::Perigee* fittedPerigee = actsBoundToTrkPerigee(trk.fittedParams, beamSpotPos);
338 const TrackWrapper* originalParams = trk.originalParams.template as<TrackWrapper>();
346 trkAtVtxVec->push_back(trkAtVtx);
358 if (!m_createSplitVertices) {
359 if (!theVertexContainer->
empty()) {
364 theVertexContainer->
push_back(dummyxAODVertex);
367 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
374 theVertexContainer->
push_back(dummyxAODVertex);
375 dummyxAODVertex->
setPosition(beamSpotHandle->beamVtx().position());
377 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
383 for (
unsigned int i = 0;
i < theVertexContainer->
size() - 1;
i++) {
386 " Vtx: " <<
i <<
" x= " << (*theVertexContainer)[
i]->position().
x()
387 <<
" y= " << (*theVertexContainer)[
i]->position().
y() <<
" z= "
388 << (*theVertexContainer)[
i]->position().
z() <<
" ntracks= "
389 << (*theVertexContainer)[
i]->vxTrackAtVertex().
size()
390 <<
" chi2= " << (*theVertexContainer)[
i]->
chiSquared()
391 <<
" ndf = " << (*theVertexContainer)[
i]->numberDoF());
398 return std::make_pair(theVertexContainer, theVertexAuxContainer);
403 const Acts::Vector3& surfCenter)
const {
404 using namespace Acts::UnitLiterals;
408 Acts::ActsVector<5>
params = bound.parameters().head<5>();