9 #include <Math/SVector.h> 10 #include <Math/SMatrix.h> 11 #include <Math/MatrixFunctions.h> 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;
122 return ROOT::Math::Similarity(
conv(
dir),
error.matrix());
136 double weight = err1 / (err1 + err2);
146 Matrix3S &cov,
const Vector3 &residual,
const Matrix3S &
error,
double &
chi2,
double theta,
double phi) {
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);
173 if (!
state.isValid())
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);
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) {}
296 std::cout <<
"\tpt = " << mom.perp() <<
", eta = " << mom.eta() <<
", phi = " << mom.phi()
297 <<
", charge = " << fts.
charge();
298 if (
vtx &&
vtx->hasTrackWeight())
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_);
330 std::cout <<
vtx.position() <<
"-> " <<
vtx.totalChiSquared() <<
" with " <<
vtx.degreesOfFreedom() << std::endl;
334 << ((pred.
lambda(
vtx.position()) * pred.
rho() - origin) /
err) << std::endl;
336 std::vector<TransientTrack>
tracks =
vtx.originalTracks();
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.);
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.);
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.);
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.);
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>(),
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));
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())
656 if (!
state.isValid())
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;
696 VtxTrackIs isGhostTrack(
info.ghostTrack);
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)
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());
795 VtxTrackIs isGhostTrack(
info.ghostTrack);
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();
825 if (
info.pred.lambda(
vtx->position()) <
info.pred.lambda(vertices_[0].position()))
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;
853 const std::vector<RefCountedVertexTrack> &
tracks = trackBundles[iter - vertices_.begin()].second;
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();
880 relinearizeTrack(trackBundles[iter - vertices_.begin()].first, iter->vertexState(), vertexTrackFactory));
882 bool primary = iter == vertices_.begin();
884 if (primary &&
info.hasBeamSpot)
903 VtxTrackIs isGhostTrack(
info.ghostTrack);
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]]);
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();
989 if (primary &&
info.hasBeamSpot)
994 newVertices.push_back(
vtx);
996 newVertices.push_back(*iter);
1000 info.ghostTrack = ghostTrack;
1009 bool hasPrimaries)
const {
1012 std::vector<TransientVertex>
result;
1013 if (
info.states.empty())
1016 info.field =
info.states[0].track().field();
1026 unsigned int reassigned = 0;
1027 while (reassigned < 3) {
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())
GhostTrackFitter & ghostTrackFitter() const
FreeTrajectoryState fts(const MagneticField *fieldProvider) const
reco::Vertex::Point convertPos(const GlobalPoint &p)
~GhostTrackVertexFinder()
RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const override
GhostTrackPrediction pred
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)
GlobalPoint position(double lambda=0.) const
bool isPrimary(const SimTrack &simTrk, const PSimHit *simHit)
void add(const reco::Track &track, double weight=1.0)
reco::TransientTrack build(const FreeTrajectoryState &fts) const
double px() const
x coordinate of momentum vector
Sin< T >::type sin(const T &t)
static RefCountedVertexTrack relinearizeTrack(const RefCountedVertexTrack &track, const VertexState &state, const VertexTrackFactory< 5 > factory)
reco::Vertex::Error convertError(const GlobalError &ge)
VertexState const & vertexState() const
double py() const
y coordinate of momentum vector
static double vertexCompat(const CachingVertex< 5 > &vtx1, const CachingVertex< 5 > &vtx2, const FinderInfo &info, double scale1=1.0, double scale2=1.0)
CachingVertex< 5 > mergeVertices(const CachingVertex< 5 > &vertex1, const CachingVertex< 5 > &vertex2, const FinderInfo &info, bool isPrimary) const
const MagneticField * field
static TransientTrack transientGhostTrack(const GhostTrackPrediction &pred, const MagneticField *field)
static double fitChi2(const CachingVertex< 5 > &vtx)
static VertexState stateMean(const VertexState &v1, const VertexState &v2)
const CachingVertex< 5 > & primaryVertex
GhostTrackPrediction fit(const GhostTrackFitter::PredictionUpdater &updater, const GhostTrackPrediction &prior, std::vector< GhostTrackState > &states, double &ndof, double &chi2) override
const GlobalVector direction() const
std::vector< RefCountedVertexTrack > tracks() const
GlobalError positionError(double lambda=0.) 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
bool recursiveMerge(std::vector< CachingVertex< 5 > > &vertices, const FinderInfo &info) const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
TrackCharge charge() const
GlobalError error() const
Cos< T >::type cos(const T &t)
const math::XYZTLorentzVector & vectorSum() const
VertexFitter< 5 > & vertexFitter(bool primary) const
GlobalVector momentum() 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)
const AlgebraicSymMatrix33 matrix() const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalVector
vector in glovbal coordinate system
bool reassignTracks(std::vector< CachingVertex< 5 > > &vertices, const FinderInfo &info) const
void refitGhostTrack(std::vector< CachingVertex< 5 > > &vertices, FinderInfo &info) const
auto const & tracks
cannot be loose
std::unique_ptr< VertexFitter< 5 > > secVertexFitter_
double pz() const
z coordinate of momentum vector
double lambda(const GlobalPoint &point) const
FinderInfo(const CachingVertex< 5 > &primaryVertex, const GhostTrack &ghostTrack, const BeamSpot &beamSpot, bool hasBeamSpot, bool hasPrimaries)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
static double trackVertexCompat(const CachingVertex< 5 > &vtx, const RefCountedVertexTrack &vertexTrack)
const GhostTrackPrediction & prediction() const
Square< F >::type sqr(const F &f)
std::vector< TransientVertex > vertices(const reco::Vertex &primaryVertex, const GlobalVector &direction, double coneRadius, const std::vector< TransientTrack > &tracks) const
std::vector< CachingVertex< 5 > > initialVertices(const FinderInfo &info) const
GhostTrack fit(const GlobalPoint &priorPosition, const GlobalError &priorError, const GlobalVector &direction, double coneRadius, const std::vector< TransientTrack > &tracks) 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)
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 position() const
GlobalError error() const
primaryVertex
hltOfflineBeamSpot for HLTMON
Geom::Theta< T > theta() 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
Global3DVector GlobalVector
GlobalPoint position() const