7 #include <Math/SVector.h>
8 #include <Math/SMatrix.h>
9 #include <Math/MatrixFunctions.h>
58 typedef SVector<double, 3> Vector3;
60 typedef SMatrix<double, 3, 3, MatRepSym<double, 3> > Matrix3S;
61 typedef SMatrix<double, 2, 2, MatRepSym<double, 2> > Matrix2S;
62 typedef SMatrix<double, 2, 3> Matrix23;
69 bool operator()(
const RefCountedVertexTrack &vtxTrack)
const {
70 return vtxTrack->linearizedTrack()->track() ==
track;
118 return ROOT::Math::Similarity(
conv(
dir),
error.matrix());
127 double weight = err1 / (err1 + err2);
137 Matrix3S &cov,
const Vector3 &residual,
const Matrix3S &
error,
double &
chi2,
double theta,
double phi) {
147 Matrix2S measErr = Similarity(jacobian,
error);
148 Matrix2S combErr = Similarity(jacobian, cov) + measErr;
149 if (!measErr.Invert() || !combErr.Invert())
152 cov -= SimilarityT(jacobian * cov, combErr);
153 chi2 += Similarity(jacobian * residual, measErr);
179 if (!linState[0]->isValid() || !linState[1]->isValid())
182 Matrix3S cov = SMatrixIdentity();
189 linState[0]->predictedStateParameters()[1],
190 linState[0]->predictedStateParameters()[2]) ||
195 linState[1]->predictedStateParameters()[1],
196 linState[1]->predictedStateParameters()[2]))
202 std::vector<RefCountedVertexTrack> linTracks(2);
203 linTracks[0] = vertexTrackFactory.
vertexTrack(linState[0], vtxState);
204 linTracks[1] = vertexTrackFactory.
vertexTrack(linState[1], vtxState);
212 RefCountedLinearizedTrackState linTrack =
track->linearizedTrack();
213 linTrack = linTrack->stateWithNewLinearizationPoint(state.
position());
221 std::vector<RefCountedVertexTrack> finalTracks;
222 finalTracks.reserve(
tracks.size());
224 for (std::vector<RefCountedVertexTrack>::const_iterator iter =
tracks.begin(); iter !=
tracks.end(); ++iter)
235 return sqr(ROOT::Math::Dot(
diff,
diff)) / ROOT::Math::Similarity(cov,
diff);
251 Vector3
dir =
conv(point2 - point1);
252 Matrix3S
error =
vtx.error().matrix() + tsos.cartesianError().matrix().Sub<Matrix3S>(0, 0);
256 return ROOT::Math::Similarity(
error,
dir);
260 : maxFitChi2_(10.0), mergeThreshold_(3.0), primcut_(2.0), seccut_(5.0), fitType_(kAlwaysWithGhostTrack) {}
287 std::cout <<
"\tpt = " << mom.perp() <<
", eta = " << mom.eta() <<
", phi = " << mom.phi()
288 <<
", charge = " << fts.
charge();
289 if (
vtx &&
vtx->hasTrackWeight())
297 for (std::vector<TransientTrack>::const_iterator iter =
tracks.begin(); iter !=
tracks.end(); ++iter) {
298 debugTrack(*iter,
vtx);
310 static void debugTracks(
const std::vector<RefCountedVertexTrack> &
tracks) {
311 std::vector<TransientTrack> tracks_;
312 for (std::vector<RefCountedVertexTrack>::const_iterator iter =
tracks.begin(); iter !=
tracks.end(); ++iter) {
313 std::cout <<
"+ " << (*iter)->linearizedTrack()->linearizationPoint() << std::endl;
314 tracks_.push_back((*iter)->linearizedTrack()->track());
316 debugTracks(tracks_);
321 std::cout <<
vtx.position() <<
"-> " <<
vtx.totalChiSquared() <<
" with " <<
vtx.degreesOfFreedom() << std::endl;
325 << ((pred.
lambda(
vtx.position()) * pred.
rho() - origin) /
err) << std::endl;
327 std::vector<TransientTrack>
tracks =
vtx.originalTracks();
335 const std::vector<TransientTrack> &
tracks)
const {
347 const std::vector<TransientTrack> &
tracks)
const {
360 const std::vector<TransientTrack> &primaries,
361 const std::vector<TransientTrack> &
tracks)
const {
375 const std::vector<TransientTrack> &
tracks)
const {
378 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
380 std::vector<TransientVertex>
result =
vertices(ghostTrack, primary);
383 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
395 const std::vector<TransientTrack> &
tracks)
const {
398 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
403 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
415 const std::vector<TransientTrack> &primaries,
416 const std::vector<TransientTrack> &
tracks)
const {
419 std::vector<RefCountedVertexTrack> primaryVertexTracks;
420 if (!primaries.empty()) {
426 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
427 RefCountedLinearizedTrackState linState = linTrackFactory.
linearizedTrackState(primaryPosition, *iter);
429 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState, state));
433 CachingVertex<5> primary(primaryPosition, primaryError, primaryVertexTracks, 0.);
438 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
448 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
450 std::vector<TransientVertex>
result =
vertices(ghostTrack, primary);
453 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
464 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
469 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
479 const std::vector<TransientTrack> &primaries,
481 std::vector<RefCountedVertexTrack> primaryVertexTracks;
482 if (!primaries.empty()) {
488 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
489 RefCountedLinearizedTrackState linState = linTrackFactory.
linearizedTrackState(primaryPosition, *iter);
491 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState, state));
495 CachingVertex<5> primary(primaryPosition, primaryError, primaryVertexTracks, 0.);
500 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
524 const std::vector<TransientTrack> &primaries,
541 const Track &ghostTrack,
542 const std::vector<TransientTrack> &
tracks,
543 const std::vector<float> &
weights)
const {
553 std::vector<RefCountedVertexTrack>(),
556 std::vector<TransientVertex>
result =
vertices(ghostTrack_, primary);
559 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
567 const Track &ghostTrack,
569 const std::vector<TransientTrack> &
tracks,
570 const std::vector<float> &
weights)
const {
580 std::vector<RefCountedVertexTrack>(),
586 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
594 const Track &ghostTrack,
596 const std::vector<TransientTrack> &primaries,
597 const std::vector<TransientTrack> &
tracks,
598 const std::vector<float> &
weights)
const {
606 std::vector<RefCountedVertexTrack> primaryVertexTracks;
607 if (!primaries.empty()) {
614 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
617 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState, state));
629 for (std::vector<TransientVertex>::const_iterator iter =
result.begin(); iter !=
result.end(); ++iter)
639 std::vector<CachingVertex<5> >
vertices;
640 for (std::vector<GhostTrackState>::const_iterator iter =
info.states.begin(); iter !=
info.states.end(); ++iter) {
641 if (!iter->isValid())
660 std::vector<RefCountedVertexTrack> &newTracks,
662 const VtxTrackIs &ghostTrackFinder,
663 RefCountedVertexTrack &ghostTrack,
665 for (std::vector<RefCountedVertexTrack>::const_iterator iter =
tracks.begin(); iter !=
tracks.end(); ++iter) {
666 bool gt = ghostTrackFinder(*iter);
667 if (gt && ghostTrack)
675 newTracks.push_back(*iter);
682 bool isPrimary)
const {
686 std::vector<RefCountedVertexTrack> linTracks;
687 VtxTrackIs isGhostTrack(
info.ghostTrack);
688 RefCountedVertexTrack vtxGhostTrack;
694 linTracks.push_back(vertexTrackFactory.
vertexTrack(vtxGhostTrack->linearizedTrack(), vtxGhostTrack->vertexState()));
698 if (
info.hasBeamSpot && isPrimary)
712 typedef std::pair<unsigned int, unsigned int>
Indices;
714 std::multimap<float, Indices> compatMap;
716 for (
unsigned int i = 0;
i <
n;
i++) {
718 for (
unsigned int j =
i + 1;
j <
n;
j++) {
726 compatMap.insert(std::make_pair(compat,
Indices(
i,
j)));
730 bool changesMade =
false;
734 for (std::multimap<float, Indices>::const_iterator iter = compatMap.begin(); iter != compatMap.end(); ++iter) {
735 unsigned int v1 = iter->second.first;
736 unsigned int v2 = iter->second.second;
746 std::multimap<float, Indices> newCompatMap;
747 for (++iter; iter != compatMap.end(); ++iter) {
748 if (iter->second.first == v1 || iter->second.first == v2 || iter->second.second == v1 ||
749 iter->second.second == v2)
756 newCompatMap.insert(std::make_pair(iter->first,
indices));
760 for (
unsigned int i = 0;
i <
n;
i++) {
784 std::vector<std::pair<RefCountedVertexTrack, std::vector<RefCountedVertexTrack> > > trackBundles(vertices_.size());
786 VtxTrackIs isGhostTrack(
info.ghostTrack);
788 bool assignmentChanged =
false;
789 for (std::vector<
CachingVertex<5> >::const_iterator iter = vertices_.begin(); iter != vertices_.end(); ++iter) {
790 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
792 if (vtxTracks.empty()) {
798 trackBundles[iter - vertices_.begin()].first = vertexTrackFactory.
vertexTrack(linState, iter->vertexState());
801 for (std::vector<RefCountedVertexTrack>::const_iterator
track = vtxTracks.begin();
track != vtxTracks.end();
803 if (isGhostTrack(*
track)) {
804 trackBundles[iter - vertices_.begin()].first = *
track;
808 if ((*track)->weight() < 1
e-3) {
809 trackBundles[iter - vertices_.begin()].second.push_back(*
track);
813 unsigned int idx = iter - vertices_.begin();
816 if (
info.pred.lambda(
vtx->position()) <
info.pred.lambda(vertices_[0].position()))
825 idx =
vtx - vertices_.begin();
829 if ((
int)
idx != iter - vertices_.begin())
830 assignmentChanged =
true;
832 trackBundles[
idx].second.push_back(*
track);
836 if (!assignmentChanged)
840 std::vector<CachingVertex<5> >
vertices;
843 for (std::vector<
CachingVertex<5> >::const_iterator iter = vertices_.begin(); iter != vertices_.end(); ++iter) {
844 const std::vector<RefCountedVertexTrack> &
tracks = trackBundles[iter - vertices_.begin()].second;
854 for (std::vector<GhostTrackState>::const_iterator iter =
info.states.begin(); iter !=
info.states.end(); ++iter) {
855 if (iter->isTrack() && iter->track() ==
track) {
856 idx = iter -
info.states.begin();
871 relinearizeTrack(trackBundles[iter - vertices_.begin()].first, iter->vertexState(), vertexTrackFactory));
873 bool primary = iter == vertices_.begin();
875 if (primary &&
info.hasBeamSpot)
894 VtxTrackIs isGhostTrack(
info.ghostTrack);
896 std::vector<GhostTrackState> states;
897 std::vector<unsigned int> oldStates;
898 oldStates.reserve(
info.states.size());
901 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
904 for (std::vector<RefCountedVertexTrack>::const_iterator
track = vtxTracks.begin();
track != vtxTracks.end();
906 if (isGhostTrack(*
track) || (*track)->weight() < 1
e-3)
912 for (std::vector<GhostTrackState>::const_iterator iter =
info.states.begin(); iter !=
info.states.end(); ++iter) {
913 if (iter->isTrack() && iter->track() ==
tt) {
914 idx = iter -
info.states.begin();
920 oldStates.push_back(
idx);
923 if (oldStates.size() == 1)
924 states.push_back(
info.states[oldStates[0]]);
938 std::vector<CachingVertex<5> > newVertices;
940 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
944 for (std::vector<RefCountedVertexTrack>::iterator
track = vtxTracks.begin();
track != vtxTracks.end(); ++
track) {
945 if (isGhostTrack(*
track)) {
950 iter->vertexState());
962 for (std::vector<GhostTrackState>::const_iterator it =
info.states.begin(); it !=
info.states.end(); ++it) {
966 if (it->track() ==
tt) {
967 idx = it -
info.states.begin();
976 newVertices.push_back(
vtx);
978 bool primary = iter ==
vertices.begin();
980 if (primary &&
info.hasBeamSpot)
985 newVertices.push_back(
vtx);
987 newVertices.push_back(*iter);
991 info.ghostTrack = ghostTrack;
1000 bool hasPrimaries)
const {
1003 std::vector<TransientVertex>
result;
1004 if (
info.states.empty())
1007 info.field =
info.states[0].track().field();
1017 unsigned int reassigned = 0;
1018 while (reassigned < 3) {
1027 std::cout <<
"----- recursive merging: ---------" << std::endl;
1031 if ((!changed && !reassigned) ||
vertices.size() < 2)
1045 std::cout <<
"----- reassignment: ---------" << std::endl;
1061 std::vector<RefCountedVertexTrack>
tracks = iter->tracks();
1062 std::vector<RefCountedVertexTrack> newTracks;
1063 newTracks.reserve(
tracks.size());
1065 std::remove_copy_if(
tracks.begin(),
tracks.end(), std::back_inserter(newTracks), VtxTrackIs(
info.ghostTrack));
1067 if (newTracks.empty())