9 #include <Math/SVector.h>
10 #include <Math/SMatrix.h>
11 #include <Math/MatrixFunctions.h>
60 typedef SVector<double, 3> Vector3;
62 typedef SMatrix<double, 3, 3, MatRepSym<double, 3> > Matrix3S;
63 typedef SMatrix<double, 2, 2, MatRepSym<double, 2> > Matrix2S;
64 typedef SMatrix<double, 2, 3> Matrix23;
71 bool operator()(
const RefCountedVertexTrack &vtxTrack)
const {
72 return vtxTrack->linearizedTrack()->track() ==
track;
120 return ROOT::Math::Similarity(
conv(
dir),
error.matrix());
129 double weight = err1 / (err1 + err2);
139 Matrix3S &cov,
const Vector3 &residual,
const Matrix3S &
error,
double &
chi2,
double theta,
double phi) {
149 Matrix2S measErr = Similarity(jacobian,
error);
150 Matrix2S combErr = Similarity(jacobian, cov) + measErr;
151 if (!measErr.Invert() || !combErr.Invert())
154 cov -= SimilarityT(jacobian * cov, combErr);
155 chi2 += Similarity(jacobian * residual, measErr);
166 if (!
state.isValid())
181 if (!linState[0]->isValid() || !linState[1]->isValid())
184 Matrix3S cov = SMatrixIdentity();
191 linState[0]->predictedStateParameters()[1],
192 linState[0]->predictedStateParameters()[2]) ||
197 linState[1]->predictedStateParameters()[1],
198 linState[1]->predictedStateParameters()[2]))
204 std::vector<RefCountedVertexTrack> linTracks(2);
205 linTracks[0] = vertexTrackFactory.
vertexTrack(linState[0], vtxState);
206 linTracks[1] = vertexTrackFactory.
vertexTrack(linState[1], vtxState);
214 RefCountedLinearizedTrackState linTrack =
track->linearizedTrack();
215 linTrack = linTrack->stateWithNewLinearizationPoint(
state.position());
223 std::vector<RefCountedVertexTrack> finalTracks;
224 finalTracks.reserve(
tracks.size());
226 for (std::vector<RefCountedVertexTrack>::const_iterator iter =
tracks.begin(); iter !=
tracks.end(); ++iter)
237 return sqr(ROOT::Math::Dot(
diff,
diff)) / ROOT::Math::Similarity(cov,
diff);
253 Vector3
dir =
conv(point2 - point1);
254 Matrix3S
error =
vtx.error().matrix() + tsos.cartesianError().matrix().Sub<Matrix3S>(0, 0);
258 return ROOT::Math::Similarity(
error,
dir);
262 : maxFitChi2_(10.0), mergeThreshold_(3.0), primcut_(2.0), seccut_(5.0), fitType_(kAlwaysWithGhostTrack) {}
289 std::cout <<
"\tpt = " << mom.perp() <<
", eta = " << mom.eta() <<
", phi = " << mom.phi()
290 <<
", charge = " << fts.
charge();
291 if (
vtx &&
vtx->hasTrackWeight())
299 for (std::vector<TransientTrack>::const_iterator iter =
tracks.begin(); iter !=
tracks.end(); ++iter) {
300 debugTrack(*iter,
vtx);
312 static void debugTracks(
const std::vector<RefCountedVertexTrack> &
tracks) {
313 std::vector<TransientTrack> tracks_;
314 for (std::vector<RefCountedVertexTrack>::const_iterator iter =
tracks.begin(); iter !=
tracks.end(); ++iter) {
315 std::cout <<
"+ " << (*iter)->linearizedTrack()->linearizationPoint() << std::endl;
316 tracks_.push_back((*iter)->linearizedTrack()->track());
318 debugTracks(tracks_);
323 std::cout <<
vtx.position() <<
"-> " <<
vtx.totalChiSquared() <<
" with " <<
vtx.degreesOfFreedom() << std::endl;
327 << ((pred.
lambda(
vtx.position()) * pred.
rho() - origin) /
err) << std::endl;
329 std::vector<TransientTrack>
tracks =
vtx.originalTracks();
337 const std::vector<TransientTrack> &
tracks)
const {
349 const std::vector<TransientTrack> &
tracks)
const {
362 const std::vector<TransientTrack> &primaries,
363 const std::vector<TransientTrack> &
tracks)
const {
377 const std::vector<TransientTrack> &
tracks)
const {
380 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
382 std::vector<TransientVertex>
result =
vertices(ghostTrack, primary);
385 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
397 const std::vector<TransientTrack> &
tracks)
const {
400 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
405 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
417 const std::vector<TransientTrack> &primaries,
418 const std::vector<TransientTrack> &
tracks)
const {
421 std::vector<RefCountedVertexTrack> primaryVertexTracks;
422 if (!primaries.empty()) {
428 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
429 RefCountedLinearizedTrackState linState = linTrackFactory.
linearizedTrackState(primaryPosition, *iter);
431 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState,
state));
435 CachingVertex<5> primary(primaryPosition, primaryError, primaryVertexTracks, 0.);
440 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
450 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
452 std::vector<TransientVertex>
result =
vertices(ghostTrack, primary);
455 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
466 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
471 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
481 const std::vector<TransientTrack> &primaries,
483 std::vector<RefCountedVertexTrack> primaryVertexTracks;
484 if (!primaries.empty()) {
490 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
491 RefCountedLinearizedTrackState linState = linTrackFactory.
linearizedTrackState(primaryPosition, *iter);
493 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState,
state));
497 CachingVertex<5> primary(primaryPosition, primaryError, primaryVertexTracks, 0.);
502 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
526 const std::vector<TransientTrack> &primaries,
543 const Track &ghostTrack,
544 const std::vector<TransientTrack> &
tracks,
545 const std::vector<float> &
weights)
const {
555 std::vector<RefCountedVertexTrack>(),
558 std::vector<TransientVertex>
result =
vertices(ghostTrack_, primary);
561 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
569 const Track &ghostTrack,
571 const std::vector<TransientTrack> &
tracks,
572 const std::vector<float> &
weights)
const {
582 std::vector<RefCountedVertexTrack>(),
588 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
596 const Track &ghostTrack,
598 const std::vector<TransientTrack> &primaries,
599 const std::vector<TransientTrack> &
tracks,
600 const std::vector<float> &
weights)
const {
608 std::vector<RefCountedVertexTrack> primaryVertexTracks;
609 if (!primaries.empty()) {
616 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
619 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState,
state));
631 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
641 std::vector<CachingVertex<5> >
vertices;
642 for (std::vector<GhostTrackState>::const_iterator iter =
info.states.begin(); iter !=
info.states.end(); ++iter) {
643 if (!iter->isValid())
649 if (!
state.isValid())
662 std::vector<RefCountedVertexTrack> &newTracks,
664 const VtxTrackIs &ghostTrackFinder,
665 RefCountedVertexTrack &ghostTrack,
667 for (std::vector<RefCountedVertexTrack>::const_iterator iter =
tracks.begin(); iter !=
tracks.end(); ++iter) {
668 bool gt = ghostTrackFinder(*iter);
669 if (
gt && ghostTrack)
677 newTracks.push_back(*iter);
688 std::vector<RefCountedVertexTrack> linTracks;
689 VtxTrackIs isGhostTrack(
info.ghostTrack);
690 RefCountedVertexTrack vtxGhostTrack;
696 linTracks.push_back(vertexTrackFactory.
vertexTrack(vtxGhostTrack->linearizedTrack(), vtxGhostTrack->vertexState()));
714 typedef std::pair<unsigned int, unsigned int>
Indices;
716 std::multimap<float, Indices> compatMap;
718 for (
unsigned int i = 0;
i <
n;
i++) {
720 for (
unsigned int j =
i + 1;
j <
n;
j++) {
728 compatMap.insert(std::make_pair(compat,
Indices(
i,
j)));
732 bool changesMade =
false;
736 for (std::multimap<float, Indices>::const_iterator iter = compatMap.begin(); iter != compatMap.end(); ++iter) {
737 unsigned int v1 = iter->second.first;
738 unsigned int v2 = iter->second.second;
748 std::multimap<float, Indices> newCompatMap;
749 for (++iter; iter != compatMap.end(); ++iter) {
750 if (iter->second.first == v1 || iter->second.first == v2 || iter->second.second == v1 ||
751 iter->second.second == v2)
758 newCompatMap.insert(std::make_pair(iter->first,
indices));
762 for (
unsigned int i = 0;
i <
n;
i++) {
786 std::vector<std::pair<RefCountedVertexTrack, std::vector<RefCountedVertexTrack> > > trackBundles(vertices_.size());
788 VtxTrackIs isGhostTrack(
info.ghostTrack);
790 bool assignmentChanged =
false;
792 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
794 if (vtxTracks.empty()) {
800 trackBundles[iter - vertices_.begin()].first = vertexTrackFactory.
vertexTrack(linState, iter->vertexState());
803 for (std::vector<RefCountedVertexTrack>::const_iterator
track = vtxTracks.begin();
track != vtxTracks.end();
805 if (isGhostTrack(*
track)) {
806 trackBundles[iter - vertices_.begin()].first = *
track;
810 if ((*track)->weight() < 1
e-3) {
811 trackBundles[iter - vertices_.begin()].second.push_back(*
track);
815 unsigned int idx = iter - vertices_.begin();
818 if (
info.pred.lambda(
vtx->position()) <
info.pred.lambda(vertices_[0].position()))
827 idx =
vtx - vertices_.begin();
831 if ((
int)
idx != iter - vertices_.begin())
832 assignmentChanged =
true;
834 trackBundles[
idx].second.push_back(*
track);
838 if (!assignmentChanged)
842 std::vector<CachingVertex<5> >
vertices;
846 const std::vector<RefCountedVertexTrack> &
tracks = trackBundles[iter - vertices_.begin()].second;
856 for (std::vector<GhostTrackState>::const_iterator iter =
info.states.begin(); iter !=
info.states.end(); ++iter) {
857 if (iter->isTrack() && iter->track() ==
track) {
858 idx = iter -
info.states.begin();
873 relinearizeTrack(trackBundles[iter - vertices_.begin()].first, iter->vertexState(), vertexTrackFactory));
875 bool primary = iter == vertices_.begin();
877 if (primary &&
info.hasBeamSpot)
896 VtxTrackIs isGhostTrack(
info.ghostTrack);
898 std::vector<GhostTrackState> states;
899 std::vector<unsigned int> oldStates;
900 oldStates.reserve(
info.states.size());
903 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
906 for (std::vector<RefCountedVertexTrack>::const_iterator
track = vtxTracks.begin();
track != vtxTracks.end();
908 if (isGhostTrack(*
track) || (*track)->weight() < 1
e-3)
914 for (std::vector<GhostTrackState>::const_iterator iter =
info.states.begin(); iter !=
info.states.end(); ++iter) {
915 if (iter->isTrack() && iter->track() ==
tt) {
916 idx = iter -
info.states.begin();
922 oldStates.push_back(
idx);
925 if (oldStates.size() == 1)
926 states.push_back(
info.states[oldStates[0]]);
940 std::vector<CachingVertex<5> > newVertices;
942 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
946 for (std::vector<RefCountedVertexTrack>::iterator
track = vtxTracks.begin();
track != vtxTracks.end(); ++
track) {
947 if (isGhostTrack(*
track)) {
952 iter->vertexState());
964 for (std::vector<GhostTrackState>::const_iterator it =
info.states.begin(); it !=
info.states.end(); ++it) {
968 if (it->track() ==
tt) {
969 idx = it -
info.states.begin();
978 newVertices.push_back(
vtx);
980 bool primary = iter ==
vertices.begin();
982 if (primary &&
info.hasBeamSpot)
987 newVertices.push_back(
vtx);
989 newVertices.push_back(*iter);
993 info.ghostTrack = ghostTrack;
1002 bool hasPrimaries)
const {
1005 std::vector<TransientVertex>
result;
1006 if (
info.states.empty())
1009 info.field =
info.states[0].track().field();
1019 unsigned int reassigned = 0;
1020 while (reassigned < 3) {
1029 std::cout <<
"----- recursive merging: ---------" << std::endl;
1033 if ((!changed && !reassigned) ||
vertices.size() < 2)
1047 std::cout <<
"----- reassignment: ---------" << std::endl;
1063 std::vector<RefCountedVertexTrack>
tracks = iter->tracks();
1064 std::vector<RefCountedVertexTrack> newTracks;
1065 newTracks.reserve(
tracks.size());
1067 std::remove_copy_if(
tracks.begin(),
tracks.end(), std::back_inserter(newTracks), VtxTrackIs(
info.ghostTrack));
1069 if (newTracks.empty())