9 #include <Math/SVector.h>
10 #include <Math/SMatrix.h>
11 #include <Math/MatrixFunctions.h>
60 using namespace ROOT::Math;
62 typedef SVector<double, 3> Vector3;
64 typedef SMatrix<double, 3, 3, MatRepSym<double, 3> > Matrix3S;
65 typedef SMatrix<double, 2, 2, MatRepSym<double, 2> > Matrix2S;
66 typedef SMatrix<double, 2, 3> Matrix23;
73 bool operator()(
const RefCountedVertexTrack &vtxTrack)
const {
74 return vtxTrack->linearizedTrack()->
track() ==
track;
88 inline double sqr(
double arg) {
return arg *
arg; }
97 : primaryVertex(primaryVertex),
98 pred(ghostTrack.prediction()),
102 hasBeamSpot(hasBeamSpot),
103 hasPrimaries(hasPrimaries),
122 return ROOT::Math::Similarity(
conv(dir), error.
matrix());
136 double weight = err1 / (err1 + err2);
138 return p1 + weight *
diff;
146 Matrix3S &cov,
const Vector3 &residual,
const Matrix3S &
error,
double &
chi2,
double theta,
double phi) {
147 using namespace ROOT::Math;
156 Matrix2S measErr = Similarity(jacobian, error);
157 Matrix2S combErr = Similarity(jacobian, cov) + measErr;
158 if (!measErr.Invert() || !combErr.Invert())
161 cov -= SimilarityT(jacobian * cov, combErr);
162 chi2 += Similarity(jacobian * residual, measErr);
186 RefCountedLinearizedTrackState linState[2] = {linTrackFactory.
linearizedTrackState(point, ghostTrack),
191 Matrix3S cov = SMatrixIdentity();
198 linState[0]->predictedStateParameters()[1],
199 linState[0]->predictedStateParameters()[2]) ||
204 linState[1]->predictedStateParameters()[1],
205 linState[1]->predictedStateParameters()[2]))
211 std::vector<RefCountedVertexTrack> linTracks(2);
212 linTracks[0] = vertexTrackFactory.
vertexTrack(linState[0], vtxState);
213 linTracks[1] = vertexTrackFactory.
vertexTrack(linState[1], vtxState);
221 RefCountedLinearizedTrackState linTrack = track->linearizedTrack();
222 linTrack = linTrack->stateWithNewLinearizationPoint(state.
position());
230 std::vector<RefCountedVertexTrack> finalTracks;
231 finalTracks.reserve(tracks.size());
233 for (std::vector<RefCountedVertexTrack>::const_iterator iter = tracks.begin(); iter != tracks.end(); ++iter)
244 return sqr(ROOT::Math::Dot(diff, diff)) / ROOT::Math::Similarity(cov, diff);
248 using namespace ROOT::Math;
260 Vector3
dir =
conv(point2 - point1);
261 Matrix3S
error = vtx.
error().
matrix() + tsos.cartesianError().matrix().Sub<Matrix3S>(0, 0);
265 return ROOT::Math::Similarity(
error,
dir);
269 : maxFitChi2_(10.0), mergeThreshold_(3.0), primcut_(2.0), seccut_(5.0), fitType_(kAlwaysWithGhostTrack) {}
272 double maxFitChi2,
double mergeThreshold,
double primcut,
double seccut,
FitType fitType)
273 : maxFitChi2_(maxFitChi2), mergeThreshold_(mergeThreshold), primcut_(primcut), seccut_(seccut), fitType_(fitType) {}
296 std::cout <<
"\tpt = " << mom.perp() <<
", eta = " << mom.eta() <<
", phi = " << mom.phi()
297 <<
", charge = " << fts.
charge();
298 if (vtx && vtx->hasTrackWeight())
299 std::cout <<
", w = " << vtx->trackWeight(track) << std::endl;
306 for (std::vector<TransientTrack>::const_iterator iter = tracks.begin(); iter != tracks.end(); ++iter) {
307 debugTrack(*iter, vtx);
319 static void debugTracks(
const std::vector<RefCountedVertexTrack> &tracks) {
320 std::vector<TransientTrack> tracks_;
321 for (std::vector<RefCountedVertexTrack>::const_iterator iter = tracks.begin(); iter != tracks.end(); ++iter) {
322 std::cout <<
"+ " << (*iter)->linearizedTrack()->linearizationPoint() << std::endl;
323 tracks_.push_back((*iter)->linearizedTrack()->track());
325 debugTracks(tracks_);
337 debugTracks(tracks, &vtx);
344 const std::vector<TransientTrack> &tracks)
const {
356 const std::vector<TransientTrack> &tracks)
const {
369 const std::vector<TransientTrack> &primaries,
370 const std::vector<TransientTrack> &tracks)
const {
384 const std::vector<TransientTrack> &tracks)
const {
387 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
389 std::vector<TransientVertex> result =
vertices(ghostTrack, primary);
392 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
404 const std::vector<TransientTrack> &tracks)
const {
407 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
409 std::vector<TransientVertex> result =
vertices(ghostTrack, primary, beamSpot,
true);
412 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
424 const std::vector<TransientTrack> &primaries,
425 const std::vector<TransientTrack> &tracks)
const {
428 std::vector<RefCountedVertexTrack> primaryVertexTracks;
429 if (!primaries.empty()) {
435 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
436 RefCountedLinearizedTrackState linState = linTrackFactory.
linearizedTrackState(primaryPosition, *iter);
438 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState, state));
442 CachingVertex<5> primary(primaryPosition, primaryError, primaryVertexTracks, 0.);
444 std::vector<TransientVertex> result =
vertices(ghostTrack, primary, beamSpot,
true,
true);
447 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
457 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
459 std::vector<TransientVertex> result =
vertices(ghostTrack, primary);
462 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
473 CachingVertex<5> primary(primaryPosition, primaryError, std::vector<RefCountedVertexTrack>(), 0.);
475 std::vector<TransientVertex> result =
vertices(ghostTrack, primary, beamSpot,
true);
478 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
488 const std::vector<TransientTrack> &primaries,
490 std::vector<RefCountedVertexTrack> primaryVertexTracks;
491 if (!primaries.empty()) {
497 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
498 RefCountedLinearizedTrackState linState = linTrackFactory.
linearizedTrackState(primaryPosition, *iter);
500 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState, state));
504 CachingVertex<5> primary(primaryPosition, primaryError, primaryVertexTracks, 0.);
506 std::vector<TransientVertex> result =
vertices(ghostTrack, primary, beamSpot,
true,
true);
509 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
533 const std::vector<TransientTrack> &primaries,
550 const Track &ghostTrack,
551 const std::vector<TransientTrack> &tracks,
552 const std::vector<float> &
weights)
const {
562 std::vector<RefCountedVertexTrack>(),
565 std::vector<TransientVertex> result =
vertices(ghostTrack_, primary);
568 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
576 const Track &ghostTrack,
578 const std::vector<TransientTrack> &tracks,
579 const std::vector<float> &
weights)
const {
589 std::vector<RefCountedVertexTrack>(),
592 std::vector<TransientVertex> result =
vertices(ghostTrack_, primary, beamSpot,
true);
595 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
603 const Track &ghostTrack,
605 const std::vector<TransientTrack> &primaries,
606 const std::vector<TransientTrack> &tracks,
607 const std::vector<float> &
weights)
const {
615 std::vector<RefCountedVertexTrack> primaryVertexTracks;
616 if (!primaries.empty()) {
623 for (std::vector<TransientTrack>::const_iterator iter = primaries.begin(); iter != primaries.end(); ++iter) {
626 primaryVertexTracks.push_back(vertexTrackFactory.
vertexTrack(linState, state));
635 std::vector<TransientVertex> result =
vertices(ghostTrack_, primary, beamSpot,
true,
true);
638 for (std::vector<TransientVertex>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
648 std::vector<CachingVertex<5> >
vertices;
649 for (std::vector<GhostTrackState>::const_iterator iter = info.
states.begin(); iter != info.
states.end(); ++iter) {
650 if (!iter->isValid())
662 vertices.push_back(vtx);
669 std::vector<RefCountedVertexTrack> &newTracks,
671 const VtxTrackIs &ghostTrackFinder,
672 RefCountedVertexTrack &ghostTrack,
674 for (std::vector<RefCountedVertexTrack>::const_iterator iter = tracks.begin(); iter != tracks.end(); ++iter) {
675 bool gt = ghostTrackFinder(*iter);
676 if (gt && ghostTrack)
684 newTracks.push_back(*iter);
695 std::vector<RefCountedVertexTrack> linTracks;
697 RefCountedVertexTrack vtxGhostTrack;
703 linTracks.push_back(vertexTrackFactory.
vertexTrack(vtxGhostTrack->linearizedTrack(), vtxGhostTrack->vertexState()));
721 typedef std::pair<unsigned int, unsigned int>
Indices;
723 std::multimap<float, Indices> compatMap;
725 for (
unsigned int i = 0;
i <
n;
i++) {
727 for (
unsigned int j =
i + 1;
j <
n;
j++) {
735 compatMap.insert(std::make_pair(compat,
Indices(
i,
j)));
739 bool changesMade =
false;
743 for (std::multimap<float, Indices>::const_iterator iter = compatMap.begin(); iter != compatMap.end(); ++iter) {
744 unsigned int v1 = iter->second.first;
745 unsigned int v2 = iter->second.second;
755 std::multimap<float, Indices> newCompatMap;
756 for (++iter; iter != compatMap.end(); ++iter) {
757 if (iter->second.first == v1 || iter->second.first == v2 || iter->second.second == v1 ||
758 iter->second.second == v2)
761 Indices
indices = iter->second;
762 indices.first -= indices.first > v2;
763 indices.second -= indices.second > v2;
765 newCompatMap.insert(std::make_pair(iter->first, indices));
769 for (
unsigned int i = 0;
i <
n;
i++) {
793 std::vector<std::pair<RefCountedVertexTrack, std::vector<RefCountedVertexTrack> > > trackBundles(vertices_.size());
797 bool assignmentChanged =
false;
799 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
801 if (vtxTracks.empty()) {
807 trackBundles[iter - vertices_.begin()].first = vertexTrackFactory.
vertexTrack(linState, iter->vertexState());
810 for (std::vector<RefCountedVertexTrack>::const_iterator track = vtxTracks.begin(); track != vtxTracks.end();
812 if (isGhostTrack(*track)) {
813 trackBundles[iter - vertices_.begin()].first = *
track;
817 if ((*track)->weight() < 1
e-3) {
818 trackBundles[iter - vertices_.begin()].second.push_back(*track);
822 unsigned int idx = iter - vertices_.begin();
834 idx = vtx - vertices_.begin();
838 if ((
int)idx != iter - vertices_.begin())
839 assignmentChanged =
true;
841 trackBundles[idx].second.push_back(*track);
845 if (!assignmentChanged)
849 std::vector<CachingVertex<5> >
vertices;
850 vertices.reserve(vertices_.size());
853 const std::vector<RefCountedVertexTrack> &tracks = trackBundles[iter - vertices_.begin()].second;
859 if (tracks.size() == 1) {
860 const TransientTrack &track = tracks[0]->linearizedTrack()->track();
863 for (std::vector<GhostTrackState>::const_iterator iter = info.
states.begin(); iter != info.
states.end(); ++iter) {
864 if (iter->isTrack() && iter->track() ==
track) {
865 idx = iter - info.
states.begin();
876 std::vector<RefCountedVertexTrack> linTracks =
relinearizeTracks(tracks, iter->vertexState());
880 relinearizeTrack(trackBundles[iter - vertices_.begin()].first, iter->vertexState(), vertexTrackFactory));
882 bool primary = iter == vertices_.begin();
895 vertices.push_back(vtx);
905 std::vector<GhostTrackState> states;
906 std::vector<unsigned int> oldStates;
907 oldStates.reserve(info.
states.size());
910 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
913 for (std::vector<RefCountedVertexTrack>::const_iterator track = vtxTracks.begin(); track != vtxTracks.end();
915 if (isGhostTrack(*track) || (*track)->weight() < 1
e-3)
921 for (std::vector<GhostTrackState>::const_iterator iter = info.
states.begin(); iter != info.
states.end(); ++iter) {
922 if (iter->isTrack() && iter->track() ==
tt) {
923 idx = iter - info.
states.begin();
929 oldStates.push_back(idx);
932 if (oldStates.size() == 1)
933 states.push_back(info.
states[oldStates[0]]);
941 info.
pred = fitter.
fit(updater, info.
prior, states, ndof, chi2);
947 std::vector<CachingVertex<5> > newVertices;
949 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
953 for (std::vector<RefCountedVertexTrack>::iterator track = vtxTracks.begin(); track != vtxTracks.end(); ++
track) {
954 if (isGhostTrack(*track)) {
959 iter->vertexState());
971 for (std::vector<GhostTrackState>::const_iterator it = info.
states.begin(); it != info.
states.end(); ++it) {
975 if (it->track() ==
tt) {
976 idx = it - info.
states.begin();
985 newVertices.push_back(vtx);
987 bool primary = iter ==
vertices.begin();
994 newVertices.push_back(vtx);
996 newVertices.push_back(*iter);
1009 bool hasPrimaries)
const {
1010 FinderInfo info(primary, ghostTrack, beamSpot, hasBeamSpot, hasPrimaries);
1012 std::vector<TransientVertex>
result;
1021 vertices.push_back(primary);
1022 if (vertices.size() > 1)
1023 std::swap(vertices.front(), vertices.back());
1026 unsigned int reassigned = 0;
1027 while (reassigned < 3) {
1028 if (vertices.size() < 2)
1036 std::cout <<
"----- recursive merging: ---------" << std::endl;
1040 if ((!changed && !reassigned) || vertices.size() < 2)
1054 std::cout <<
"----- reassignment: ---------" << std::endl;
1070 std::vector<RefCountedVertexTrack> tracks = iter->tracks();
1071 std::vector<RefCountedVertexTrack> newTracks;
1072 newTracks.reserve(tracks.size());
1074 std::remove_copy_if(tracks.begin(), tracks.end(), std::back_inserter(newTracks), VtxTrackIs(info.
ghostTrack));
1076 if (newTracks.empty())
1079 CachingVertex<5> vtx(iter->vertexState(), newTracks, iter->totalChiSquared());
1080 result.push_back(vtx);
GlobalError positionError() const
reco::Vertex::Point convertPos(const GlobalPoint &p)
~GhostTrackVertexFinder()
RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const override
GhostTrackPrediction pred
std::vector< RefCountedVertexTrack > tracks() const
std::unique_ptr< VertexFitter< 5 > > primVertexFitter_
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
static bool covarianceUpdate(Matrix3S &cov, const Vector3 &residual, const Matrix3S &error, double &chi2, double theta, double phi)
double lambda(const GlobalPoint &point) const
bool isPrimary(const SimTrack &simTrk, const PSimHit *simHit)
const TransientTrack & track() const
void add(const reco::Track &track, double weight=1.0)
TrackBaseRef trackBaseRef() const
VertexState const & vertexState() const
const AlgebraicSymMatrix33 matrix() const
Sin< T >::type sin(const T &t)
float totalChiSquared() const
static RefCountedVertexTrack relinearizeTrack(const RefCountedVertexTrack &track, const VertexState &state, const VertexTrackFactory< 5 > factory)
reco::Vertex::Error convertError(const GlobalError &ge)
Geom::Theta< T > theta() const
FreeTrajectoryState fts(const MagneticField *fieldProvider) const
static double vertexCompat(const CachingVertex< 5 > &vtx1, const CachingVertex< 5 > &vtx2, const FinderInfo &info, double scale1=1.0, double scale2=1.0)
auto const & tracks
cannot be loose
bool reassignTracks(std::vector< CachingVertex< 5 > > &vertices, const FinderInfo &info) const
bool recursiveMerge(std::vector< CachingVertex< 5 > > &vertices, const FinderInfo &info) const
GlobalError cartesianError() const
TrackCharge charge() const
double px() const
x coordinate of momentum vector
const MagneticField * field
static TransientTrack transientGhostTrack(const GhostTrackPrediction &pred, const MagneticField *field)
static double fitChi2(const CachingVertex< 5 > &vtx)
GlobalPoint position() const
const Point & position() const
position
static VertexState stateMean(const VertexState &v1, const VertexState &v2)
GhostTrack fit(const GlobalPoint &priorPosition, const GlobalError &priorError, const GlobalVector &direction, double coneRadius, const std::vector< TransientTrack > &tracks) const
const CachingVertex< 5 > & primaryVertex
GhostTrackPrediction fit(const GhostTrackFitter::PredictionUpdater &updater, const GhostTrackPrediction &prior, std::vector< GhostTrackState > &states, double &ndof, double &chi2) override
std::vector< TransientVertex > vertices(const reco::Vertex &primaryVertex, const GlobalVector &direction, double coneRadius, const std::vector< TransientTrack > &tracks) const
static std::vector< RefCountedVertexTrack > relinearizeTracks(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &state)
virtual CachingVertex< N > vertex(const std::vector< reco::TransientTrack > &tracks) const =0
std::vector< reco::TransientTrack > const & originalTracks() const
float degreesOfFreedom() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
GlobalPoint position() const
Cos< T >::type cos(const T &t)
float totalChiSquared() const
static GhostTrackPrediction dummyPrediction(const Vertex &primaryVertex, const Track &ghostTrack)
static GlobalPoint vtxMean(const GlobalPoint &p1, const GlobalError &e1, const GlobalPoint &p2, const GlobalError &e2)
float degreesOfFreedom() const
GlobalVector momentum() const
double pz() const
z coordinate of momentum vector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalVector
vector in glovbal coordinate system
FreeTrajectoryState initialFreeState() const
const Track & track() const
CachingVertex< 5 > mergeVertices(const CachingVertex< 5 > &vertex1, const CachingVertex< 5 > &vertex2, const FinderInfo &info, bool isPrimary) const
bool linearize(const GhostTrackPrediction &pred, bool initial=false, double lambda=0.)
reco::TransientTrack build(const FreeTrajectoryState &fts) const
std::unique_ptr< VertexFitter< 5 > > secVertexFitter_
std::vector< CachingVertex< 5 > > initialVertices(const FinderInfo &info) const
Error error() const
return SMatrix
FinderInfo(const CachingVertex< 5 > &primaryVertex, const GhostTrack &ghostTrack, const BeamSpot &beamSpot, bool hasBeamSpot, bool hasPrimaries)
VertexFitter< 5 > & vertexFitter(bool primary) const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
GlobalPoint position() const
static double trackVertexCompat(const CachingVertex< 5 > &vtx, const RefCountedVertexTrack &vertexTrack)
GhostTrackFitter & ghostTrackFitter() const
const GhostTrackPrediction & prediction() const
const math::XYZTLorentzVector & vectorSum() const
GlobalPoint position(double lambda=0.) const
void refitGhostTrack(std::vector< CachingVertex< 5 > > &vertices, FinderInfo &info) const
std::vector< GhostTrackState > states
static double vtxErrorLong(const GlobalError &error, const GlobalVector &dir)
static void mergeTrackHelper(const std::vector< RefCountedVertexTrack > &tracks, std::vector< RefCountedVertexTrack > &newTracks, const VertexState &state, const VtxTrackIs &ghostTrackFinder, RefCountedVertexTrack &ghostTrack, const VertexTrackFactory< 5 > &factory)
GlobalError error() const
std::unique_ptr< GhostTrackFitter > ghostTrackFitter_
TransientTrack ghostTrack
static CachingVertex< 5 > vertexAtState(const TransientTrack &ghostTrack, const GhostTrackPrediction &pred, const GhostTrackState &state)
Log< level::Warning, false > LogWarning
GlobalPoint globalPosition() const
GlobalError error() const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
GhostTrackPrediction prior
double py() const
y coordinate of momentum vector
Global3DVector GlobalVector
GlobalError positionError(double lambda=0.) const
const GlobalVector direction() const