13 #if __cplusplus < 201402L
14 #include <boost/make_unique.hpp>
17 #include <trackbase_historic/SvtxVertexMap.h>
18 #include <trackbase_historic/SvtxVertex.h>
19 #include <trackbase_historic/SvtxVertex_v1.h>
20 #include <trackbase_historic/SvtxVertexMap_v1.h>
23 #include <ActsExamples/Plugins/BField/BFieldOptions.hpp>
24 #include <ActsExamples/Plugins/BField/ScalableBField.hpp>
29 #include <Acts/MagneticField/SharedBField.hpp>
33 #include <Acts/Utilities/Definitions.hpp>
36 #include <Acts/Utilities/Units.hpp>
73 std::cout <<
"PHActsInitialVertexFinder processing event "
79 <<
"No silicon track seeds found. Can't run initial vertexing, setting dummy vertex of (0,0,0)"
103 for(
auto track : trackPointers)
110 std::cout <<
"PHActsInitialVertexFinder processed event "
142 if(track->get_vertex_id() != UINT_MAX)
145 const auto trackZ = track->get_z();
147 double closestVertZ = 9999;
151 double dz = fabs(trackZ -
vertex->get_z());
153 if(dz < closestVertZ)
161 auto vertex = m_vertexMap->get(vertId);
162 vertex->insert_track(trackKey);
163 track->set_vertex_id(vertId);
170 unsigned int vertexId = 0;
171 if(vertices.size() != 0)
176 if(vertices.size() == 0)
180 std::cout <<
"No vertices found. Adding a dummy vertex"
185 for(
auto vertex : vertices)
187 const auto &[chi2, ndf] =
vertex.fitQuality();
188 const auto numTracks =
vertex.tracks().size();
192 std::cout <<
"Found vertex at (" <<
vertex.position().x()
193 <<
", " <<
vertex.position().y() <<
", "
194 <<
vertex.position().z() <<
")" << std::endl;
195 std::cout <<
"Vertex has ntracks = " << numTracks
196 <<
" with chi2/ndf " << chi2 / ndf << std::endl;
200 #if __cplusplus < 201402L
201 auto svtxVertex = boost::make_unique<SvtxVertex_v1>();
203 auto svtxVertex = std::make_unique<SvtxVertex_v1>();
209 for(
int i = 0;
i < 3; ++
i)
210 for(
int j = 0;
j < 3; ++
j)
211 svtxVertex->set_error(
i,
j,
215 svtxVertex->set_chisq(chi2);
216 svtxVertex->set_ndof(ndf);
217 svtxVertex->set_t0(
vertex.time());
218 svtxVertex->set_id(vertexId);
220 for(
const auto& track :
vertex.tracks())
222 const auto originalParams = track.originalParams;
224 const auto trackKey = keyMap.find(originalParams)->second;
225 svtxVertex->insert_track(trackKey);
232 svtxTrack->identify();
233 std::cout <<
"Updating track key " << trackKey <<
" with vertex "
234 << vertexId << std::endl;
237 svtxTrack->set_vertex_id(vertexId);
258 #if __cplusplus < 201402L
259 auto svtxVertex = boost::make_unique<SvtxVertex_v1>();
261 auto svtxVertex = std::make_unique<SvtxVertex_v1>();
264 svtxVertex->set_x(x);
265 svtxVertex->set_y(y);
266 svtxVertex->set_z(z);
268 for(
int i = 0;
i < 3; ++
i)
269 for(
int j = 0;
j < 3; ++
j)
272 svtxVertex->set_error(
i,
j, 10.);
274 svtxVertex->set_error(
i,
j, 0);
278 svtxVertex->set_chisq(nan);
279 svtxVertex->set_ndof(nan);
280 svtxVertex->set_t0(nan);
281 svtxVertex->set_id(0);
284 std::cout <<
"Created dummy vertex at " << x <<
", " << y <<
", " << z
287 track->set_vertex_id(0);
300 return std::visit([tracks,
this](
auto &inputField) {
302 using InputMagneticField =
303 typename std::decay_t<decltype(inputField)>::element_type;
304 using MagneticField = Acts::SharedBField<InputMagneticField>;
312 using ImpactPointEstimator =
319 static_assert(Acts::VertexFinderConcept<VertexSeeder>,
320 "VertexSeeder does not fulfill vertex finder concept.");
321 static_assert(Acts::VertexFinderConcept<VertexFinder>,
322 "VertexFinder does not fulfill vertex finder concept.");
331 auto propagator = std::make_shared<Propagator>(
Stepper(bField));
341 vertexFitterConfig.maxIterations = 1;
343 VertexFitter vertexFitter(
std::move(vertexFitterConfig));
349 ImpactPointEstimator ipEst(
std::move(ipEstConfig));
356 seederConfig.disableAllWeights =
true;
363 finderConfig.reassignTracksAfterFirstFit =
true;
370 auto result = finder.find(tracks, finderOptions, state);
378 auto vertexCollection = *result;
382 std::cout <<
"Acts IVF found " << vertexCollection.size()
383 <<
" vertices in event" << std::endl;
386 for(
const auto&
vertex : vertexCollection)
388 vertexVector.push_back(
vertex);
395 std::cout <<
"Acts initial vertex finder returned error: "
396 << result.error().message() << std::endl;
397 std::cout <<
"Track positions IVF used are : " << std::endl;
398 for(
const auto track : tracks)
402 <<
", " <<
position(2) << std::endl;
424 std::uniform_int_distribution<int> indices(0,
m_trackMap->
size() - 1);
425 std::vector<int> usedIndices;
428 for(
auto& centroid : centroids)
431 for(
const auto used : usedIndices)
435 usedIndices.push_back(
index);
443 std::cout <<
"Centroid is (" << centroid(0)
444 <<
", " << centroid(1) <<
", "
445 << centroid(2) <<
")" << std::endl;
462 std::vector<Acts::Vector3D>& centroids)
465 std::vector<SvtxTrack*> sortedTracks;
469 std::cout <<
"Final centroids are : " << std::endl;
470 for(
const auto& [centroidIndex, trackVec] : clusters)
472 std::cout <<
"Centroid: " << centroids.at(centroidIndex).transpose()
473 <<
" has tracks " << std::endl;
474 for(
const auto& track : trackVec)
476 std::cout <<
"(" << track->get_x() <<
", "
477 << track->get_y() <<
", " << track->get_z()
484 int maxTrackCentroid = 0;
487 for(
const auto& [centroidIndex, trackVec] : clusters)
489 Acts::Vector3D
sum = Acts::Vector3D::Zero();
490 if(trackVec.size() > maxTrackCentroid)
492 maxTrackCentroid = trackVec.size();
495 for(
const auto& track : trackVec)
497 for(
int i = 0;
i < sum.rows();
i++)
499 sum(
i) += pow(track->get_pos(
i) - centroids.at(centroidIndex)(
i), 2);
502 for(
int i = 0;
i < 3;
i++)
504 stddev.at(centroidIndex)(
i) = sqrt(
sum(
i) / trackVec.size());
508 for(
const auto& [centroidIndex, trackVec] : clusters)
513 if(trackVec.size() < 0.2 * maxTrackCentroid)
517 float centroidR = sqrt(pow(centroids.at(centroidIndex)(0), 2) +
518 pow(centroids.at(centroidIndex)(1), 2));
522 std::cout <<
"Checking to add tracks from centroid "
523 << centroids.at(centroidIndex).transpose() << std::endl;
531 for(
const auto& track : trackVec)
533 Acts::Vector3D pulls = Acts::Vector3D::Zero();
534 for(
int i = 0;
i < 3;
i++)
536 pulls(
i) = fabs(track->get_pos(
i) - centroids.at(centroidIndex)(
i)) / stddev.at(centroidIndex)(
i);
541 std::cout <<
"Track pos is (" << track->get_x() <<
", "
542 << track->get_y() <<
", " << track->get_z()
543 <<
") and pull is " << pulls.transpose() << std::endl;
546 if ((pulls(0) < 2 and pulls(1) < 2 and pulls(2) < 2))
548 sortedTracks.push_back(track);
559 std::cout <<
"Not adding track with pos (" << track->get_x()
560 <<
", " << track->get_y() <<
", " << track->get_z()
561 <<
") as it is incompatible with centroid "
562 << centroids.at(centroidIndex).transpose()
564 << stddev.at(centroidIndex).transpose() << std::endl;
584 std::vector<SvtxTrack*>
vec;
585 clusters.insert(std::make_pair(
i, vec));
591 std::cout <<
"Starting centroid is : "
592 << centroids.at(
i).transpose() << std::endl;
596 Acts::Vector3D trackPos(track->get_x(),
600 double minDist = std::numeric_limits<double>::max();
601 unsigned int centKey = std::numeric_limits<unsigned int>::max();
602 for(
int i = 0;
i < centroids.size();
i++)
604 double dist = sqrt(pow(trackPos(0) - centroids.at(
i)(0), 2) +
605 pow(trackPos(1) - centroids.at(
i)(1), 2) +
606 pow(trackPos(2) - centroids.at(
i)(2), 2));
613 std::cout <<
"mindist and centkey are "
614 << minDist <<
", " << centKey
623 std::cout <<
"adding track with " << trackPos.transpose()
625 << centroids.at(centKey).transpose() << std::endl;
628 clusters.find(centKey)->second.push_back(track);
632 std::vector<Acts::Vector3D> newCentroids(m_nCentroids);
633 for(
auto& centroid : newCentroids)
634 centroid = Acts::Vector3D(0,0,0);
636 for(
const auto& [centroidVal, trackVec] : clusters)
638 for(
const auto& track : trackVec)
640 for(
int i = 0;
i < 3;
i++)
641 newCentroids.at(centroidVal)(
i) += track->get_pos(
i);
645 centroids.at(centroidVal) =
646 newCentroids.at(centroidVal) / trackVec.size();
652 std::cout <<
"new centroids " << centroids.at(
i).transpose()
655 for(
const auto& [centKey, trackVec] : clusters)
657 std::cout <<
"cent key : " << centKey <<
" has " << trackVec.size()
658 <<
"tracks" << std::endl;
659 for(
const auto track : trackVec)
661 std::cout <<
"track id : " << track->get_id()
662 <<
" with pos (" << track->get_x() <<
", "
663 << track->get_y() <<
", " << track->get_z()
687 std::vector<SvtxTrack*> sortedTracks;
695 sortedTracks.push_back(track);
698 for(
const auto& track : sortedTracks)
702 std::cout <<
"Adding track seed to vertex finder "
710 if(track->size_cluster_keys() < 5)
716 const Acts::Vector4D stubVec(
722 const Acts::Vector3D stubMom(track->get_px(),
731 if(
m_magField.find(
"3d") != std::string::npos)
734 const double p = track->get_p();
738 Acts::BoundSymMatrix
cov;
742 0., 0., 0.005, 0., 0., 0.,
743 0., 0., 0., 0.001, 0., 0.,
744 0., 0., 0., 0., 0.3 , 0.,
745 0., 0., 0., 0., 0., 1.;
756 auto perigee = Acts::Surface::makeShared<Acts::PerigeeSurface>(
757 Acts::Vector3D(stubVec(0),
768 tracks.push_back(param);
769 keyMap.insert(std::make_pair(param, track->get_id()));
782 <<
" on node tree, bailing."
787 m_tGeometry = findNode::getClass<ActsTrackingGeometry>(topNode,
788 "ActsTrackingGeometry");
791 std::cout <<
PHWHERE <<
"ActsTrackingGeometry not on node tree. Exiting"
810 std::cerr <<
"DST Node missing, quitting" << std::endl;
811 throw std::runtime_error(
"failed to find DST node in PHActsInitialVertexFinder::createNodes");
823 m_vertexMap = findNode::getClass<SvtxVertexMap>(topNode,