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/Surfaces/PerigeeSurface.hpp"
23 #include "Acts/Vertexing/TrackAtVertex.hpp"
32 struct VertexAndSignalComp {
44 const std::string&
name,
52 using namespace std::literals::string_literals;
58 ATH_CHECK( m_trackingGeometryTool.retrieve() );
59 std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry
60 = m_trackingGeometryTool->trackingGeometry();
62 ATH_CHECK( m_extrapolationTool.retrieve() );
68 logger().cloneWithSuffix(
"Navigator"));
70 auto bField = std::make_shared<ATLASMagneticFieldWrapper>();
71 auto stepper = Acts::EigenStepper<>(bField);
72 m_propagator = std::make_shared<Propagator>(std::move(stepper),
74 logger().cloneWithSuffix(
"Prop"));
77 Acts::ImpactPointEstimator::Config ipEstCfg(bField, m_propagator);
78 ipEstCfg.maxIterations = m_ipEstMaxIterations;
79 ipEstCfg.precision = m_ipEstPrecision;
80 Acts::ImpactPointEstimator ipEst(ipEstCfg,
81 logger().cloneWithSuffix(
"ImpactPointEstimator"));
83 Acts::AnnealingUtility::Config annealingConfig;
84 annealingConfig.setOfTemperatures = m_annealingTemps;
85 annealingConfig.cutOff = m_annealingCutOff;
86 Acts::AnnealingUtility annealingUtility(annealingConfig);
89 TrackLinearizer::Config ltConfig;
90 ltConfig.bField = bField;
91 ltConfig.propagator = m_propagator;
92 m_linearizer.emplace(ltConfig,
logger().cloneWithSuffix(
"Linearizer"));
95 VertexFitter::Config fitterCfg(ipEst);
96 fitterCfg.annealingTool = annealingUtility;
97 fitterCfg.maxIterations = m_fitterMaxIterations;
98 fitterCfg.maxDistToLinPoint = m_fitterMaxDistToLinPoint;
99 fitterCfg.minWeight = m_minWeightFitter;
100 fitterCfg.maxRelativeShift = m_fitterMaxRelativeShift;
101 fitterCfg.doSmoothing = m_fitterDoSmoothing;
102 fitterCfg.extractParameters.connect<&TrackWrapper::extractParameters>();
103 fitterCfg.trackLinearizer.connect<&TrackLinearizer::linearizeTrack>(&*m_linearizer);
107 Acts::GaussianTrackDensity::Config trackDensityConfig;
108 trackDensityConfig.d0MaxSignificance = m_gaussianMaxD0Significance;
109 trackDensityConfig.z0MaxSignificance = m_gaussianMaxZ0Significance;
110 trackDensityConfig.extractParameters.connect<&TrackWrapper::extractParameters>();
111 Acts::GaussianTrackDensity trackDensity(trackDensityConfig);
114 VertexSeedFinder::Config seedFinderConfig{trackDensity};
115 auto seedFinder = std::make_shared<VertexSeedFinder>(seedFinderConfig);
116 VertexFinder::Config finderConfig(std::move(
fitter), seedFinder,
120 finderConfig.tracksMaxZinterval = m_tracksMaxZinterval;
121 finderConfig.tracksMaxSignificance = m_tracksMaxSignificance;
122 finderConfig.maxVertexChi2 = m_maxVertexChi2;
123 finderConfig.doRealMultiVertex = m_doRealMultiVertex;
124 finderConfig.useFastCompatibility = m_useFastCompatibility;
125 finderConfig.maxMergeVertexSignificance = m_maxMergeVertexSignificance;
126 finderConfig.minWeight = m_minWeight;
127 finderConfig.maxIterations = m_maxIterations;
128 finderConfig.addSingleTrackVertices = m_addSingleTrackVertices;
129 finderConfig.doFullSplitting = m_doFullSplitting;
130 finderConfig.maximumVertexContamination = m_maximumVertexContamination;
131 finderConfig.initialVariances = Acts::Vector4::Constant(m_looseConstrValue);
132 finderConfig.useVertexCovForIPEstimation = m_useVertexCovForIPEstimation;
133 finderConfig.useSeedConstraint = m_useSeedConstraint;
134 finderConfig.extractParameters.connect<&TrackWrapper::extractParameters>();
135 m_vertexFinder = std::make_shared<VertexFinder>(std::move(finderConfig),
136 logger().cloneWithSuffix(
"Finder"));
138 ATH_MSG_INFO(
"ACTS AMVF tool successfully initialized");
139 return StatusCode::SUCCESS;
142 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
149 std::vector<std::unique_ptr<Trk::ITrackLink>> selectedTracks;
153 bool selectionPassed;
154 for (TrackDataVecIter itr = (*trackTES).begin(); itr != (*trackTES).end(); ++itr) {
155 if (m_useBeamConstraint) {
156 selectionPassed =
static_cast<bool>(m_trkFilter->accept(**itr, &beamposition));
159 selectionPassed =
static_cast<bool>(m_trkFilter->accept(**itr, &
null));
161 if (selectionPassed) {
164 auto trkPtr = std::make_unique<Trk::LinkToTrack>(link);
165 trkPtr->setStorableObject(*trackTES);
166 selectedTracks.push_back(std::move(trkPtr));
170 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> returnContainers = findVertex(ctx, std::move(selectedTracks));
172 return returnContainers;
175 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
180 std::vector<std::unique_ptr<Trk::ITrackLink>> selectedTracks;
184 beamposition.
setPosition(beamSpotHandle->beamVtx().position());
189 bool selectionPassed;
190 for (TrackParticleDataVecIter itr = (*trackParticles).begin(); itr != (*trackParticles).end(); ++itr) {
191 if (m_useBeamConstraint) {
192 selectionPassed =
static_cast<bool>(m_trkFilter->accept(**itr, &beamposition));
198 vertexError.setZero();
199 null.setCovariancePosition(vertexError);
200 selectionPassed =
static_cast<bool>(m_trkFilter->accept(**itr, &
null));
203 if (selectionPassed) {
206 auto trkPtr = std::make_unique<Trk::LinkToXAODTrackParticle>(link);
207 trkPtr->setStorableObject(*trackParticles);
208 selectedTracks.push_back(std::move(trkPtr));
212 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> returnContainers = findVertex(ctx, std::move(selectedTracks));
214 return returnContainers;
218 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
220 const std::vector<std::unique_ptr<Trk::ITrackLink>>& trackVector)
const
222 using namespace Acts::UnitLiterals;
225 const Acts::Vector3& beamSpotPos = beamSpotHandle->beamVtx().position();
227 beamSpotConstraintVtx.setCovariance(beamSpotHandle->beamVtx().covariancePosition());
230 Acts::MagneticFieldContext magFieldContext = m_extrapolationTool->getMagneticFieldContext(ctx);
232 const auto& geoContext = m_trackingGeometryTool->getGeometryContext(ctx).context();
237 theVertexContainer->setStore(theVertexAuxContainer);
239 if(trackVector.empty()){
241 theVertexContainer->
push_back(dummyxAODVertex);
242 dummyxAODVertex->
setPosition(beamSpotHandle->beamVtx().position());
246 return std::make_pair(theVertexContainer, theVertexAuxContainer);
249 std::shared_ptr<Acts::PerigeeSurface> perigeeSurface =
250 Acts::Surface::makeShared<Acts::PerigeeSurface>((trackVector[0])->
parameters()->associatedSurface().
transform());
253 std::vector<TrackWrapper> allTracks;
255 for (
const auto& trk : trackVector) {
256 const auto& trkParams = trk->parameters();
257 const auto&
params = trkParams->parameters();
259 Acts::BoundVector actsParams;
262 if(trkParams->covariance() ==
nullptr){
266 auto cov = *(trkParams->covariance());
271 Acts::BoundSquareMatrix covMat;
272 covMat <<
cov(0,0) ,
cov(0,1) ,
cov(0,2) ,
cov(0,3) ,
cov(0,4) *1./(1_MeV), 0
273 ,
cov(1,0) ,
cov(1,1) ,
cov(1,2) ,
cov(1,3) ,
cov(1,4) *1./(1_MeV) , 0
274 ,
cov(2,0) ,
cov(2,1) ,
cov(2,2) ,
cov(2,3) ,
cov(2,4) *1./(1_MeV) , 0
275 ,
cov(3,0) ,
cov(3,1) ,
cov(3,2) ,
cov(3,3) ,
cov(3,4) *1./(1_MeV) , 0
276 ,
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
277 , 0. , 0. , 0. , 0., 0., 1.;
282 std::vector<Acts::InputTrack> allTrackPtrs;
283 allTrackPtrs.reserve(allTracks.size());
285 for(
const auto& trk : allTracks){
286 allTrackPtrs.emplace_back(&trk);
289 Acts::VertexingOptions vertexingOptions( geoContext, magFieldContext );
291 if(!m_useBeamConstraint){
294 looseConstraintCovariance.setIdentity();
295 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
296 beamSpotConstraintVtx.setCovariance(looseConstraintCovariance);
299 vertexingOptions.useConstraintInFit = m_useBeamConstraint;
300 vertexingOptions.constraint = beamSpotConstraintVtx;
302 auto finderState = m_vertexFinder->makeState(magFieldContext);
304 auto findResult = m_vertexFinder->find(allTrackPtrs, vertexingOptions, finderState);
306 if(!findResult.ok()){
308 theVertexContainer->
push_back(dummyxAODVertex);
309 dummyxAODVertex->
setPosition(beamSpotHandle->beamVtx().position());
312 return std::make_pair(theVertexContainer, theVertexAuxContainer);
315 std::vector<Acts::Vertex> allVertices = *findResult;
317 std::vector<VertexAndSignalComp> vtxList;
320 vtxList.reserve(allVertices.size());
322 for(
const auto& vtx : allVertices){
324 if(vtx.covariance()(0,0)<0||vtx.covariance()(1,1)<0||vtx.covariance()(2,2)<0)
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){
337 if ((trk.vertexCompatibility > m_maxVertexChi2 && m_useFastCompatibility) ||
338 ((trk.trackWeight < m_minWeight
339 || trk.chi2Track > m_maxVertexChi2)
340 && !m_useFastCompatibility)) {
344 const TrackWrapper* originalParams = trk.originalParams.template as<TrackWrapper>();
346 Trk::Perigee* fittedPerigee = actsBoundToTrkPerigee(trk.fittedParams, beamSpotPos);
352 trkAtVtxVec->push_back(trkAtVtx);
361 double sigComp = estimateSignalCompatibility(xAODVtx);
363 VertexAndSignalComp vertexAndSig(xAODVtx, sigComp);
364 auto it = std::lower_bound( vtxList.begin(), vtxList.end(), vertexAndSig );
365 vtxList.insert(
it, vertexAndSig );
368 for(
unsigned int i = 0;
i < vtxList.size();
i++){
369 auto vtx = vtxList[
i].first;
381 theVertexContainer->
push_back(dummyxAODVertex);
383 if(!vtxList.empty()){
391 dummyxAODVertex->
setPosition(beamSpotHandle->beamVtx().position());
396 return std::make_pair(theVertexContainer, theVertexAuxContainer);
402 const Acts::Vector3& surfCenter)
const
404 using namespace Acts::UnitLiterals;
408 Acts::ActsVector<5>
params = bound.parameters().head<5>();
418 unsigned int nTracks = 0;
421 if ((trk.vtxCompatibility() < m_finalCutMaxVertexChi2 && m_useFastCompatibility) ||
422 (trk.weight() > m_minWeight
423 && trk.trackQuality().chiSquared() < m_finalCutMaxVertexChi2
424 && !m_useFastCompatibility)) {
426 if (trk.perigeeAtVertex() !=
nullptr) {
427 perigee = trk.perigeeAtVertex();
430 perigee = trk.initialPerigee();
432 if (perigee ==
nullptr) {
433 ATH_MSG_ERROR(
"Neutrals are not supported. Skipping track in pT calculation...");
441 return totalPt2 * std::sqrt((
double) nTracks);