9 #include <Math/SVector.h>
10 #include <Math/SMatrix.h>
11 #include <Math/MatrixFunctions.h>
58 using namespace ROOT::Math;
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;
86 inline double sqr(
double arg) {
return arg *
arg; }
95 : primaryVertex(primaryVertex),
96 pred(ghostTrack.prediction()),
100 hasBeamSpot(hasBeamSpot),
101 hasPrimaries(hasPrimaries),
120 return ROOT::Math::Similarity(
conv(dir), error.
matrix());
129 double weight = err1 / (err1 + err2);
131 return p1 + weight *
diff;
139 Matrix3S &cov,
const Vector3 &residual,
const Matrix3S &
error,
double &
chi2,
double theta,
double phi) {
140 using namespace ROOT::Math;
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);
179 RefCountedLinearizedTrackState linState[2] = {linTrackFactory.
linearizedTrackState(point, ghostTrack),
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);
241 using namespace ROOT::Math;
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) {}
265 double maxFitChi2,
double mergeThreshold,
double primcut,
double seccut,
FitType fitType)
266 : maxFitChi2_(maxFitChi2), mergeThreshold_(mergeThreshold), primcut_(primcut), seccut_(seccut), fitType_(fitType) {}
289 std::cout <<
"\tpt = " << mom.perp() <<
", eta = " << mom.eta() <<
", phi = " << mom.phi()
290 <<
", charge = " << fts.
charge();
291 if (vtx && vtx->hasTrackWeight())
292 std::cout <<
", w = " << vtx->trackWeight(track) << std::endl;
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_);
330 debugTracks(tracks, &vtx);
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.);
402 std::vector<TransientVertex> result =
vertices(ghostTrack, primary, beamSpot,
true);
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.);
437 std::vector<TransientVertex> result =
vertices(ghostTrack, primary, beamSpot,
true,
true);
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.);
468 std::vector<TransientVertex> result =
vertices(ghostTrack, primary, beamSpot,
true);
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.);
499 std::vector<TransientVertex> result =
vertices(ghostTrack, primary, beamSpot,
true,
true);
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>(),
585 std::vector<TransientVertex> result =
vertices(ghostTrack_, primary, beamSpot,
true);
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));
628 std::vector<TransientVertex> result =
vertices(ghostTrack_, primary, beamSpot,
true,
true);
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())
655 vertices.push_back(vtx);
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;
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)
754 Indices
indices = iter->second;
755 indices.first -= indices.first > v2;
756 indices.second -= indices.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());
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();
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;
843 vertices.reserve(vertices_.size());
846 const std::vector<RefCountedVertexTrack> &tracks = trackBundles[iter - vertices_.begin()].second;
852 if (tracks.size() == 1) {
853 const TransientTrack &track = tracks[0]->linearizedTrack()->track();
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();
869 std::vector<RefCountedVertexTrack> linTracks =
relinearizeTracks(tracks, iter->vertexState());
873 relinearizeTrack(trackBundles[iter - vertices_.begin()].first, iter->vertexState(), vertexTrackFactory));
875 bool primary = iter == vertices_.begin();
888 vertices.push_back(vtx);
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]]);
934 info.
pred = fitter.
fit(updater, info.
prior, states, ndof, chi2);
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();
987 newVertices.push_back(vtx);
989 newVertices.push_back(*iter);
1002 bool hasPrimaries)
const {
1003 FinderInfo info(primary, ghostTrack, beamSpot, hasBeamSpot, hasPrimaries);
1005 std::vector<TransientVertex>
result;
1014 vertices.push_back(primary);
1015 if (vertices.size() > 1)
1016 std::swap(vertices.front(), vertices.back());
1019 unsigned int reassigned = 0;
1020 while (reassigned < 3) {
1021 if (vertices.size() < 2)
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())
1072 CachingVertex<5> vtx(iter->vertexState(), newTracks, iter->totalChiSquared());
1073 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)
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