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;
65 RefCountedVertexTrack;
67 RefCountedLinearizedTrackState;
71 bool operator()(
const RefCountedVertexTrack &vtxTrack)
const 72 {
return vtxTrack->linearizedTrack()->
track() ==
track; }
86 inline double sqr(
double arg) {
return arg *
arg; }
92 bool hasBeamSpot,
bool hasPrimaries) :
93 primaryVertex(primaryVertex), pred(ghostTrack.prediction()),
94 prior(ghostTrack.
prior()), states(ghostTrack.states()),
95 beamSpot(beamSpot), hasBeamSpot(hasBeamSpot),
96 hasPrimaries(hasPrimaries), field(
nullptr) {}
115 return ROOT::Math::Similarity(
conv(dir), error.
matrix());
126 double weight = err1 / (err1 + err2);
128 return p1 + weight *
diff;
140 double theta,
double phi)
151 Matrix2S measErr = Similarity(jacobian, error);
152 Matrix2S combErr = Similarity(jacobian, cov) + measErr;
153 if (!measErr.Invert() || !combErr.Invert())
156 cov -= SimilarityT(jacobian * cov, combErr);
157 chi2 += Similarity(jacobian * residual, measErr);
182 RefCountedLinearizedTrackState linState[2] = {
186 if ( !linState[0]->isValid() || !linState[1]->isValid() )
189 Matrix3S cov = SMatrixIdentity();
193 linState[0]->predictedStateParameters()[1],
194 linState[0]->predictedStateParameters()[2]) ||
196 linState[1]->predictedStateParameters()[1],
197 linState[1]->predictedStateParameters()[2]))
203 std::vector<RefCountedVertexTrack> linTracks(2);
204 linTracks[0] = vertexTrackFactory.
vertexTrack(linState[0], vtxState);
205 linTracks[1] = vertexTrackFactory.
vertexTrack(linState[1], vtxState);
211 const RefCountedVertexTrack &
track,
215 RefCountedLinearizedTrackState linTrack = track->linearizedTrack();
216 linTrack = linTrack->stateWithNewLinearizationPoint(state.
position());
221 const std::vector<RefCountedVertexTrack> &
tracks,
226 std::vector<RefCountedVertexTrack> finalTracks;
227 finalTracks.reserve(tracks.size());
229 for(std::vector<RefCountedVertexTrack>::const_iterator iter =
230 tracks.begin(); iter != tracks.end(); ++iter)
231 finalTracks.push_back(
240 double scale1,
double scale2)
246 return sqr(ROOT::Math::Dot(diff, diff)) / ROOT::Math::Similarity(cov, diff);
250 const RefCountedVertexTrack &vertexTrack)
265 Vector3
dir =
conv(point2 - point1);
267 tsos.cartesianError().matrix().Sub<Matrix3S>(0, 0);
271 return ROOT::Math::Similarity(error, dir);
276 mergeThreshold_(3.0),
279 fitType_(kAlwaysWithGhostTrack)
308 std::unique_ptr<VertexFitter<5> > *ptr =
323 std::cout <<
"\tpt = " << mom.perp() <<
", eta = " << mom.eta() <<
", phi = " << mom.phi() <<
", charge = " << fts.
charge();
324 if (
vtx &&
vtx->hasTrackWeight())
325 std::cout <<
", w = " <<
vtx->trackWeight(track) << std::endl;
333 for(std::vector<TransientTrack>::const_iterator iter = tracks.begin();
334 iter != tracks.end(); ++iter) {
335 debugTrack(*iter,
vtx);
347 static void debugTracks(
const std::vector<RefCountedVertexTrack> &tracks)
349 std::vector<TransientTrack>
tracks_;
350 for(std::vector<RefCountedVertexTrack>::const_iterator iter = tracks.begin();
351 iter != tracks.end(); ++iter) {
352 std::cout <<
"+ " << (*iter)->linearizedTrack()->linearizationPoint() << std::endl;
353 tracks_.push_back((*iter)->linearizedTrack()->track());
355 debugTracks(tracks_);
373 debugTracks(tracks, &vtx);
381 const std::vector<TransientTrack> &tracks)
const 385 direction, coneRadius, tracks);
393 const std::vector<TransientTrack> &tracks)
const 397 direction, coneRadius, beamSpot, tracks);
405 const std::vector<TransientTrack> &primaries,
406 const std::vector<TransientTrack> &tracks)
const 410 direction, coneRadius, beamSpot, primaries, tracks);
418 const std::vector<TransientTrack> &tracks)
const 422 direction, coneRadius, tracks);
425 std::vector<RefCountedVertexTrack>(), 0.);
427 std::vector<TransientVertex> result =
vertices(ghostTrack, primary);
430 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
431 iter != result.end(); ++iter)
444 const std::vector<TransientTrack> &tracks)
const 448 direction, coneRadius, tracks);
451 std::vector<RefCountedVertexTrack>(), 0.);
453 std::vector<TransientVertex> result =
454 vertices(ghostTrack, primary, beamSpot,
true);
457 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
458 iter != result.end(); ++iter)
471 const std::vector<TransientTrack> &primaries,
472 const std::vector<TransientTrack> &tracks)
const 476 direction, coneRadius, tracks);
478 std::vector<RefCountedVertexTrack> primaryVertexTracks;
479 if (!primaries.empty()) {
485 for(std::vector<TransientTrack>::const_iterator iter =
486 primaries.begin(); iter != primaries.end(); ++iter) {
488 RefCountedLinearizedTrackState linState =
490 primaryPosition, *iter);
492 primaryVertexTracks.push_back(
499 primaryVertexTracks, 0.);
501 std::vector<TransientVertex> result =
502 vertices(ghostTrack, primary, beamSpot,
true,
true);
505 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
506 iter != result.end(); ++iter)
519 std::vector<RefCountedVertexTrack>(), 0.);
521 std::vector<TransientVertex> result =
vertices(ghostTrack, primary);
524 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
525 iter != result.end(); ++iter)
540 std::vector<RefCountedVertexTrack>(), 0.);
542 std::vector<TransientVertex> result =
543 vertices(ghostTrack, primary, beamSpot,
true);
546 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
547 iter != result.end(); ++iter)
558 const std::vector<TransientTrack> &primaries,
561 std::vector<RefCountedVertexTrack> primaryVertexTracks;
562 if (!primaries.empty()) {
568 for(std::vector<TransientTrack>::const_iterator iter =
569 primaries.begin(); iter != primaries.end(); ++iter) {
571 RefCountedLinearizedTrackState linState =
573 primaryPosition, *iter);
575 primaryVertexTracks.push_back(
582 primaryVertexTracks, 0.);
584 std::vector<TransientVertex> result =
585 vertices(ghostTrack, primary, beamSpot,
true,
true);
588 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
589 iter != result.end(); ++iter)
612 beamSpot, ghostTrack);
618 const std::vector<TransientTrack> &primaries,
623 beamSpot, primaries, ghostTrack);
633 ghostTrack.
pz()), 0.05);
638 const Track &ghostTrack,
639 const std::vector<TransientTrack> &tracks,
640 const std::vector<float> &
weights)
const 642 GhostTrack ghostTrack_(ghostTrack, tracks, weights,
651 std::vector<RefCountedVertexTrack>(), 0.);
653 std::vector<TransientVertex> result =
vertices(ghostTrack_, primary);
656 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
657 iter != result.end(); ++iter)
666 const Track &ghostTrack,
668 const std::vector<TransientTrack> &tracks,
669 const std::vector<float> &
weights)
const 671 GhostTrack ghostTrack_(ghostTrack, tracks, weights,
679 std::vector<RefCountedVertexTrack>(), 0.);
681 std::vector<TransientVertex> result =
682 vertices(ghostTrack_, primary, beamSpot,
true);
685 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
686 iter != result.end(); ++iter)
695 const Track &ghostTrack,
697 const std::vector<TransientTrack> &primaries,
698 const std::vector<TransientTrack> &tracks,
699 const std::vector<float> &
weights)
const 701 GhostTrack ghostTrack_(ghostTrack, tracks, weights,
706 std::vector<RefCountedVertexTrack> primaryVertexTracks;
707 if (!primaries.empty()) {
715 for(std::vector<TransientTrack>::const_iterator iter =
716 primaries.begin(); iter != primaries.end(); ++iter) {
718 RefCountedLinearizedTrackState linState =
722 primaryVertexTracks.push_back(
731 primaryVertexTracks, 0.);
733 std::vector<TransientVertex> result =
734 vertices(ghostTrack_, primary, beamSpot,
true,
true);
737 for(std::vector<TransientVertex>::const_iterator iter = result.begin();
738 iter != result.end(); ++iter)
753 std::vector<CachingVertex<5> >
vertices;
754 for(std::vector<GhostTrackState>::const_iterator iter =
755 info.
states.begin(); iter != info. states.end(); ++iter) {
757 if (!iter->isValid())
770 vertices.push_back(vtx);
777 std::vector<RefCountedVertexTrack> &newTracks,
779 const VtxTrackIs &ghostTrackFinder,
780 RefCountedVertexTrack &ghostTrack,
783 for(std::vector<RefCountedVertexTrack>::const_iterator iter =
784 tracks.begin(); iter != tracks.end(); ++iter) {
785 bool gt = ghostTrackFinder(*iter);
786 if (gt && ghostTrack)
789 RefCountedVertexTrack track =
795 newTracks.push_back(*iter);
803 bool isPrimary)
const 809 std::vector<RefCountedVertexTrack> linTracks;
811 RefCountedVertexTrack vtxGhostTrack;
814 isGhostTrack, vtxGhostTrack, vertexTrackFactory);
816 isGhostTrack, vtxGhostTrack, vertexTrackFactory);
822 vtxGhostTrack->linearizedTrack(),
823 vtxGhostTrack->vertexState()));
846 typedef std::pair<unsigned int, unsigned int>
Indices;
848 std::multimap<float, Indices> compatMap;
850 for(
unsigned int i = 0;
i <
n;
i++) {
852 for(
unsigned int j =
i + 1; j <
n; j++) {
862 std::make_pair(compat,
Indices(
i, j)));
866 bool changesMade =
false;
870 for(std::multimap<float, Indices>::const_iterator iter =
871 compatMap.begin(); iter != compatMap.end(); ++iter) {
872 unsigned int v1 = iter->second.first;
873 unsigned int v2 = iter->second.second;
886 std::multimap<float, Indices> newCompatMap;
887 for(++iter; iter != compatMap.end(); ++iter) {
888 if (iter->second.first == v1 ||
889 iter->second.first == v2 ||
890 iter->second.second == v1 ||
891 iter->second.second == v2)
894 Indices indices = iter->second;
895 indices.first -= indices.first > v2;
896 indices.second -= indices.second > v2;
898 newCompatMap.insert(std::make_pair(
899 iter->first, indices));
903 for(
unsigned int i = 0;
i <
n;
i++) {
936 std::vector<std::pair<RefCountedVertexTrack,
937 std::vector<RefCountedVertexTrack> > >
938 trackBundles(vertices_.size());
942 bool assignmentChanged =
false;
944 vertices_.begin(); iter != vertices_.end(); ++iter) {
945 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
947 if (vtxTracks.empty()) {
951 RefCountedLinearizedTrackState linState =
955 trackBundles[iter - vertices_.begin()].first =
957 linState, iter->vertexState());
960 for(std::vector<RefCountedVertexTrack>::const_iterator track =
961 vtxTracks.begin(); track != vtxTracks.end(); ++
track) {
963 if (isGhostTrack(*track)) {
964 trackBundles[iter - vertices_.begin()]
969 if ((*track)->weight() < 1
e-3) {
970 trackBundles[iter - vertices_.begin()]
971 .second.push_back(*track);
975 unsigned int idx = iter - vertices_.begin();
978 vtx = vertices_.begin();
979 vtx != vertices_.end(); ++
vtx) {
987 compat /= (vtx == vertices_.begin()) ?
992 idx = vtx - vertices_.begin();
996 if ((
int)idx != iter - vertices_.begin())
997 assignmentChanged =
true;
999 trackBundles[
idx].second.push_back(*track);
1003 if (!assignmentChanged)
1007 std::vector<CachingVertex<5> >
vertices;
1008 vertices.reserve(vertices_.size());
1011 vertices_.begin(); iter != vertices_.end(); ++iter) {
1012 const std::vector<RefCountedVertexTrack> &tracks =
1013 trackBundles[iter - vertices_.begin()].second;
1019 if (tracks.size() == 1) {
1021 tracks[0]->linearizedTrack()->
track();
1024 for(std::vector<GhostTrackState>::const_iterator iter =
1026 iter != info.
states.end(); ++iter) {
1027 if (iter->isTrack() && iter->track() ==
track) {
1028 idx = iter - info.
states.begin();
1040 std::vector<RefCountedVertexTrack> linTracks =
1045 trackBundles[iter - vertices_.begin()].first,
1046 iter->vertexState(), vertexTrackFactory));
1048 bool primary = iter == vertices_.begin();
1065 vertices.push_back(vtx);
1078 std::vector<GhostTrackState> states;
1079 std::vector<unsigned int> oldStates;
1080 oldStates.reserve(info.
states.size());
1084 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
1087 for(std::vector<RefCountedVertexTrack>::const_iterator track =
1088 vtxTracks.begin(); track != vtxTracks.end(); ++
track) {
1090 if (isGhostTrack(*track) || (*track)->weight() < 1
e-3)
1094 (*track)->linearizedTrack()->track();
1097 for(std::vector<GhostTrackState>::const_iterator iter =
1099 iter != info.
states.end(); ++iter) {
1100 if (iter->isTrack() && iter->track() ==
tt) {
1101 idx = iter - info.
states.begin();
1107 oldStates.push_back(idx);
1110 if (oldStates.size() == 1)
1111 states.push_back(info.
states[oldStates[0]]);
1119 info.
pred = fitter.
fit(updater, info.
prior, states, ndof, chi2);
1125 std::vector<CachingVertex<5> > newVertices;
1128 std::vector<RefCountedVertexTrack> vtxTracks = iter->tracks();
1132 for(std::vector<RefCountedVertexTrack>::iterator track =
1133 vtxTracks.begin(); track != vtxTracks.end(); ++
track) {
1135 if (isGhostTrack(*track)) {
1141 iter->position(), ghostTrack),
1142 iter->vertexState());
1148 (*track)->linearizedTrack()->track();
1155 for(std::vector<GhostTrackState>::const_iterator it =
1157 it != info.
states.end(); ++it) {
1161 if (it->track() ==
tt) {
1162 idx = it - info.
states.begin();
1173 newVertices.push_back(vtx);
1175 bool primary = iter ==
vertices.begin();
1185 newVertices.push_back(vtx);
1187 newVertices.push_back(*iter);
1200 bool hasBeamSpot,
bool hasPrimaries)
const 1203 hasBeamSpot, hasPrimaries);
1205 std::vector<TransientVertex>
result;
1214 vertices.push_back(primary);
1215 if (vertices.size() > 1)
1216 std::swap(vertices.front(), vertices.back());
1219 unsigned int reassigned = 0;
1220 while(reassigned < 3) {
1221 if (vertices.size() < 2)
1226 vertices.begin(); iter != vertices.end(); ++iter)
1230 std::cout <<
"----- recursive merging: ---------" << std::endl;
1234 if ((!changed && !reassigned) || vertices.size() < 2)
1247 iter = vertices.begin();
1248 iter != vertices.end(); ++iter)
1250 std::cout <<
"----- reassignment: ---------" << std::endl;
1266 vertices.begin(); iter != vertices.end(); ++iter) {
1267 std::vector<RefCountedVertexTrack> tracks = iter->tracks();
1268 std::vector<RefCountedVertexTrack> newTracks;
1269 newTracks.reserve(tracks.size());
1271 std::remove_copy_if(tracks.begin(), tracks.end(),
1272 std::back_inserter(newTracks),
1275 if (newTracks.empty())
1279 iter->totalChiSquared());
1280 result.push_back(vtx);
GlobalError positionError() const
reco::Vertex::Point convertPos(const GlobalPoint &p)
~GhostTrackVertexFinder()
GhostTrackPrediction pred
std::vector< RefCountedVertexTrack > tracks() const
std::unique_ptr< VertexFitter< 5 > > primVertexFitter_
static bool covarianceUpdate(Matrix3S &cov, const Vector3 &residual, const Matrix3S &error, double &chi2, double theta, double phi)
double lambda(const GlobalPoint &point) const
const TransientTrack & track() const
static HepMC::IO_HEPEVT conv
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)
const MagneticField * field() const
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)
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
virtual CachingVertex< N > vertex(const std::vector< reco::TransientTrack > &tracks) const =0
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
RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const override
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 std::vector< reco::CandidatePtr > & tracks_
const GhostTrackPrediction & prediction() const
const math::XYZTLorentzVector & vectorSum() const
Square< F >::type sqr(const F &f)
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
TrajectoryStateOnSurface impactPointState() 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