29 displacedVertexCandidates_(
nullptr),
33 primaryVertexCut_(0.0),
46 if (displacedVertexCandidates.
isValid()){
60 if (
debug_)
cout <<
"========= Start Find Displaced Vertices =========" << endl;
69 edm::LogInfo(
"EmptyVertexInput")<<
"displacedVertexCandidates are not set or the setInput was called with invalid vertex";
80 cout <<
"1) Parsing displacedVertexCandidates into displacedVertexSeeds" << endl;
91 cout <<
"Analyse Vertex Candidate " << i << endl;
98 if (
debug_)
cout <<
"2) Merging Vertex Seeds" << endl;
103 vector<bool> bLockedSeeds;
104 bLockedSeeds.resize(tempDisplacedVertexSeeds.size());
105 mergeSeeds(tempDisplacedVertexSeeds, bLockedSeeds);
107 if (
debug_)
cout <<
"3) Fitting Vertices From Seeds" << endl;
110 for(
unsigned idv = 0; idv < tempDisplacedVertexSeeds.size(); idv++){
112 if (!tempDisplacedVertexSeeds[idv].isEmpty() && !bLockedSeeds[idv]) {
114 bLockedSeeds[idv] =
fitVertexFromSeed(tempDisplacedVertexSeeds[idv], displacedVertex);
115 if (!bLockedSeeds[idv]) tempDisplacedVertices.emplace_back(displacedVertex);
119 if (
debug_)
cout <<
"4) Rejecting Bad Vertices and label them" << endl;
122 vector<bool> bLocked;
123 bLocked.resize(tempDisplacedVertices.size());
126 if (
debug_)
cout <<
"5) Fill the Displaced Vertices" << endl;
131 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++)
134 if (
debug_)
cout <<
"========= End Find Displaced Vertices =========" << endl;
146 bool bNeedNewCandidate =
false;
152 for (PFDisplacedVertexCandidate::DistMap::const_iterator imap = r2Map.begin();
153 imap != r2Map.end(); imap++){
155 unsigned ie1 = (*imap).second.first;
156 unsigned ie2 = (*imap).second.second;
158 if (
debug_)
cout <<
"ie1 = " << ie1 <<
" ie2 = " << ie2 <<
" radius = " <<
sqrt((*imap).first) << endl;
161 if (fabs(dcaPoint.
x()) > 1e9)
continue;
163 bNeedNewCandidate =
true;
164 for (idvc_current = tempDisplacedVertexSeeds.begin(); idvc_current != tempDisplacedVertexSeeds.end(); idvc_current++){
165 if ((*idvc_current).isEmpty()) {
166 bNeedNewCandidate =
false;
169 const GlobalPoint vertexPoint = (*idvc_current).seedPoint();
170 double Delta_Long =
getLongDiff(vertexPoint, dcaPoint);
174 bNeedNewCandidate =
false;
177 if (bNeedNewCandidate) {
178 if (
debug_)
cout <<
"create new displaced vertex" << endl;
180 idvc_current = tempDisplacedVertexSeeds.end();
182 bNeedNewCandidate =
false;
187 (*idvc_current).updateSeedPoint(dcaPoint, vertexCandidate.
tref(ie1), vertexCandidate.
tref(ie2));
204 for(
unsigned idv_mother = 0;idv_mother < tempDisplacedVertexSeeds.size(); idv_mother++){
205 if (!bLocked[idv_mother]){
207 for (
unsigned idv_daughter = idv_mother+1;idv_daughter < tempDisplacedVertexSeeds.size(); idv_daughter++){
209 if (!bLocked[idv_daughter]){
210 if (
isCloseTo(tempDisplacedVertexSeeds[idv_mother], tempDisplacedVertexSeeds[idv_daughter])) {
212 tempDisplacedVertexSeeds[idv_mother].mergeWith(tempDisplacedVertexSeeds[idv_daughter]);
213 bLocked[idv_daughter] =
true;
214 if (
debug_)
cout <<
"Seeds " << idv_mother <<
" and " << idv_daughter <<
" merged" << endl;
234 if (
debug_)
cout <<
"== Start vertexing procedure ==" << endl;
239 set < TrackBaseRef, PFDisplacedVertexSeed::Compare >
const& tracksToFit = displacedVertexSeed.
elements();
242 vector<TransientTrack> transTracks;
243 vector<TransientTrack> transTracksRaw;
244 vector<TrackBaseRef> transTracksRef;
245 vector<TrackBaseRef> transTracksRefRaw;
247 transTracks.reserve(tracksToFit.size());
248 transTracksRaw.reserve(tracksToFit.size());
249 transTracksRef.reserve(tracksToFit.size());
250 transTracksRefRaw.reserve(tracksToFit.size());
261 if (tracksToFit.size() < 2) {
262 if (
debug_)
cout <<
"Only one to Fit Track" << endl;
266 double rho =
sqrt(seedPoint.
x()*seedPoint.
x()+seedPoint.
y()*seedPoint.
y());
267 double z = seedPoint.
z();
270 if (
debug_)
cout <<
"Seed Point out of the tracker rho = " << rho <<
" z = "<< z <<
" nTracks = " << tracksToFit.size() << endl;
277 int nNotIterative = 0;
280 for(
auto const& ie : tracksToFit){
282 transTracksRaw.emplace_back( tmpTk );
283 transTracksRefRaw.push_back( ie );
298 if (rho > 25 && nStep45 + nNotIterative < 1){
299 if (
debug_)
cout <<
"Seed point at rho > 25 cm but no step 4-5 tracks" << endl;
312 if ( transTracksRaw.size() == 2 ){
314 if (
debug_)
cout <<
"No raw fit done" << endl;
317 cout <<
"Due to probably high pile-up conditions 2 track vertices switched off" << endl;
323 theVertexAdaptiveRaw =
TransientVertex(seedPoint, globalError, transTracksRaw, 1.);
339 if (transTracksRaw.size() == 3){
341 theVertexAdaptiveRaw = theAdaptiveFitterRaw.
vertex(transTracksRaw, seedPoint);
344 else if ( transTracksRaw.size() < 1000){
348 if (
debug_)
cout <<
"First test with KFT" << endl;
351 theVertexAdaptiveRaw = theKalmanFitter.
vertex(transTracksRaw, seedPoint);
359 if (
debug_)
cout <<
"We use KFT instead of seed point to set up a point for AVF " 360 <<
" x = " << theVertexAdaptiveRaw.
position().
x()
361 <<
" y = " << theVertexAdaptiveRaw.
position().
y()
362 <<
" z = " << theVertexAdaptiveRaw.
position().
z()
373 if (rho < primaryVertexCut_ || rho > 100) {
374 if (
debug_)
cout <<
"KFT Vertex geometrically rejected with tracks #rho = " << rho << endl;
380 theVertexAdaptiveRaw = theAdaptiveFitterRaw.
vertex(transTracksRaw, theVertexAdaptiveRaw.
position());
384 edm::LogWarning(
"TooManyPFDVCandidates")<<
"gave up vertex reco for "<< transTracksRaw.size() <<
" tracks";
400 if (
debug_)
cout <<
"Vertex " <<
" geometrically rejected with " << transTracksRaw.size() <<
" tracks #rho = " << rho << endl;
415 for (
unsigned i = 0;
i < transTracksRaw.size();
i++) {
417 if (
debug_)
cout <<
"Raw Weight track " <<
i <<
" = " << theVertexAdaptiveRaw.
trackWeight(transTracksRaw[
i]) << endl;
425 if (vertexTrackType != PFDisplacedVertex::T_NOT_FROM_VERTEX){
430 transTracks.push_back(transTracksRaw[i]);
431 transTracksRef.push_back(transTracksRefRaw[i]);
434 cout <<
"Track rejected nChi2 = " << transTracksRaw[
i].track().normalizedChi2()
435 <<
" pt = " << transTracksRaw[
i].track().pt()
436 <<
" dxy (wrt (0,0,0)) = " << transTracksRaw[
i].track().dxy()
437 <<
" nHits = " << transTracksRaw[
i].track().numberOfValidHits()
438 <<
" nOuterHits = " << transTracksRaw[
i].track().hitPattern().numberOfHits(HitPattern::MISSING_OUTER_HITS) << endl;
443 cout <<
"Remove track because too far away from the vertex:" << endl;
454 if (
debug_)
cout <<
"All Tracks " << transTracksRaw.size()
455 <<
" with good weight " << transTracks.size() << endl;
461 if (transTracks.size() < 2)
return true;
462 else if (transTracks.size() == 2){
466 cout <<
"Due to probably high pile-up conditions 2 track vertices switched off" << endl;
471 else if (transTracks.size() > 2 && transTracksRaw.size() > transTracks.size())
473 else if (transTracks.size() > 2 && transTracksRaw.size() == transTracks.size())
477 if (
debug_)
cout <<
"Vertex Fitter " << vtxFitter << endl;
482 theRecoVertex = theKalmanFitter.
vertex(transTracks, seedPoint);
493 theRecoVertex = theAdaptiveFitter.
vertex(transTracks, seedPoint);
496 theRecoVertex = theVertexAdaptiveRaw;
512 Vertex theRecoVtx = theRecoVertex;
515 double ndf = theRecoVtx.
ndof();
518 if (chi2 > TMath::ChisquareQuantile(0.95, ndf)) {
520 cout <<
"Rejected because of chi2 = " << chi2 <<
" ndf = " << ndf <<
" confid. level: " << TMath::ChisquareQuantile(0.95, ndf) << endl;
536 for(
unsigned i = 0;
i < transTracks.size();
i++) {
555 cout <<
"Vertex Track Type = " << vertexTrackType << endl;
557 cout <<
"nHitBeforeVertex = " << pattern.first.first
558 <<
" nHitAfterVertex = " << pattern.second.first
559 <<
" nMissHitBeforeVertex = " << pattern.first.second
560 <<
" nMissHitAfterVertex = " << pattern.second.second
561 <<
" Weight = " << weight << endl;
566 pattern, vertexTrackType, weight);
575 if (
debug_)
cout <<
"== End vertexing procedure ==" << endl;
589 if (
debug_)
cout <<
" 4.1) Reject vertices " << endl;
591 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++){
598 const float rho = tempDisplacedVertices[idv].position().rho();
599 const float z = tempDisplacedVertices[idv].position().z();
603 <<
" geometrically rejected #rho = " << rho
604 <<
" z = " << z << endl;
611 unsigned nPrimary = tempDisplacedVertices[idv].nPrimaryTracks();
612 unsigned nMerged = tempDisplacedVertices[idv].nMergedTracks();
613 unsigned nSecondary = tempDisplacedVertices[idv].nSecondaryTracks();
615 if (nPrimary + nMerged > 1) {
618 <<
" rejected because two primary or merged tracks" << endl;
623 if (nPrimary + nMerged + nSecondary < 2){
626 <<
" rejected because only one track related to the vertex" << endl;
633 if (
debug_)
cout <<
" 4.2) Check for common vertices" << endl;
638 for(
unsigned idv_mother = 0; idv_mother < tempDisplacedVertices.size(); idv_mother++){
639 for(
unsigned idv_daughter = idv_mother+1;
640 idv_daughter < tempDisplacedVertices.size(); idv_daughter++){
642 if(!bLocked[idv_daughter] && !bLocked[idv_mother]){
644 const unsigned commonTrks =
commonTracks(tempDisplacedVertices[idv_daughter], tempDisplacedVertices[idv_mother]);
646 if (commonTrks > 1) {
648 if (
debug_)
cout <<
"Vertices " << idv_daughter <<
" and " << idv_mother
649 <<
" has many common tracks" << endl;
653 const int mother_size = tempDisplacedVertices[idv_mother].nTracks();
654 const int daughter_size = tempDisplacedVertices[idv_daughter].nTracks();
656 if (mother_size > daughter_size) bLocked[idv_daughter] =
true;
657 else if (mother_size < daughter_size) bLocked[idv_mother] =
true;
662 const float mother_normChi2 = tempDisplacedVertices[idv_mother].normalizedChi2();
663 const float daughter_normChi2 = tempDisplacedVertices[idv_daughter].normalizedChi2();
664 if (mother_normChi2 < daughter_normChi2) bLocked[idv_daughter] =
true;
665 else bLocked[idv_mother] =
true;
673 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++)
699 if (Delta_Long >
longSize_)
return false;
714 return fabs((vRef.
dot(vToProject)-vRef.
mag2())/vRef.
mag());
723 return (vRef.
dot(vToProject))/vRef.
mag();
734 return fabs(vRef.
cross(vToProject).
mag()/vRef.
mag());
742 unsigned int nHitBeforeVertex = pairTrackHitInfo.first.first;
743 unsigned int nHitAfterVertex = pairTrackHitInfo.second.first;
745 unsigned int nMissHitBeforeVertex = pairTrackHitInfo.first.second;
746 unsigned int nMissHitAfterVertex = pairTrackHitInfo.second.second;
750 if (nHitBeforeVertex <= 1 && nHitAfterVertex >= 3 && nMissHitAfterVertex <= 1)
751 return PFDisplacedVertex::T_FROM_VERTEX;
752 else if (nHitBeforeVertex >= 3 && nHitAfterVertex <= 1 && nMissHitBeforeVertex <= 1)
753 return PFDisplacedVertex::T_TO_VERTEX;
754 else if ((nHitBeforeVertex >= 2 && nHitAfterVertex >= 3)
756 (nHitBeforeVertex >= 3 && nHitAfterVertex >= 2))
757 return PFDisplacedVertex::T_MERGED;
759 return PFDisplacedVertex::T_NOT_FROM_VERTEX;
770 for (
unsigned il1 = 0; il1 < vt1.size(); il1++){
773 for (
unsigned il2 = 0; il2 < vt2.size(); il2++)
784 if(! out)
return out;
785 out << setprecision(3) << setw(5) << endl;
787 out <<
" ====================================== " << endl;
788 out <<
" ====== Displaced Vertex Finder ======= " << endl;
789 out <<
" ====================================== " << endl;
794 <<
" Adaptive Vertex Fitter parameters are :"<< endl
795 <<
" sigmacut = " << a.
sigmacut_ <<
" T_ini = " 802 if(!displacedVertices_.get() ) {
803 out<<
"displacedVertex already transfered"<<endl;
807 out<<
"Number of displacedVertices found : "<< displacedVertices_->size()<<endl<<endl;
812 idv != displacedVertices_->end(); idv++){
814 out << i <<
" "; idv->Dump(); out <<
"" << endl;
double getTransvDiff(const GlobalPoint &, const GlobalPoint &) const
std::vector< PFDisplacedVertex > PFDisplacedVertexCollection
collection of PFDisplacedVertex objects
edm::Ref< Container > Ref
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
A block of tracks linked together.
void setPrimaryDirection(const math::XYZPoint &pvtx)
reco::PFDisplacedVertexSeedCollection::iterator IDVS
-----— Useful Types -----— ///
TrackBaseRef originalTrack(const Track &refTrack) const
std::auto_ptr< reco::PFDisplacedVertexCollection > displacedVertices_
edm::ESHandle< GlobalTrackingGeometry > globTkGeomHandle_
Tracker geometry for discerning hit positions.
const TrackerTopology * tkerTopo_
doc?
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
float totalChiSquared() const
void Dump(std::ostream &out=std::cout) const
bool fitVertexFromSeed(const reco::PFDisplacedVertexSeed &, reco::PFDisplacedVertex &)
Fit one by one the vertex points with associated tracks to get displaced vertices.
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
bool rejectAndLabelVertex(reco::PFDisplacedVertex &dv)
std::map< float, std::pair< int, int > > DistMap
const std::vector< Track > & refittedTracks() const
Returns the container of refitted tracks.
void findDisplacedVertices()
-----— Main function which find vertices -----— ///
bool debug_
If true, debug printouts activated.
const Point & position() const
position
const std::set< TrackBaseRef, Compare > & elements() const
std::pair< PFTrackHitInfo, PFTrackHitInfo > PFTrackHitFullInfo
unsigned commonTracks(const reco::PFDisplacedVertex &, const reco::PFDisplacedVertex &) const
void mergeSeeds(reco::PFDisplacedVertexSeedCollection &, std::vector< bool > &bLocked)
Sometimes two vertex candidates can be quite close and coming from the same vertex.
reco::TransientTrack refittedTrack(const reco::TransientTrack &track) const
~PFDisplacedVertexFinder()
void Dump(std::ostream &out=std::cout) const
cout function
bool switchOff2TrackVertex_
PFDisplacedVertexFinder()
void addElement(const TrackBaseRef &r, const Track &refTrack, const PFTrackHitFullInfo &hitInfo, VertexTrackType trackType=T_NOT_FROM_VERTEX, float w=1.0)
Add a new track to the vertex.
bool isTrackSelected(const reco::Track &trk, const reco::PFDisplacedVertex::VertexTrackType vertexTrackType) const
Select tracks tool.
PFTrackHitFullInfo analyze(const TrackerTopology *tkerTopo, const TrackerGeometry *tkerGeom, const reco::TrackBaseRef track, const TransientVertex &vert)
const TrackBaseRef & tref(unsigned ie) const
void setVertexType(VertexType vertexType)
Set the type of this vertex.
const GlobalPoint dcaPoint(unsigned ie1, unsigned ie2) const
std::vector< PFDisplacedVertexSeed > PFDisplacedVertexSeedCollection
collection of PFDisplacedVertexSeed objects
reco::PFDisplacedVertexCandidateCollection const * displacedVertexCandidates_
-----— Members -----— ///
reco::PFDisplacedVertex::VertexType identifyVertex(const reco::PFDisplacedVertex &v) const
Vertex identification tool.
GlobalPoint position() const
void findSeedsFromCandidate(const reco::PFDisplacedVertexCandidate &, reco::PFDisplacedVertexSeedCollection &)
--—— Different steps of the finder algorithm --—— ///
void selectAndLabelVertices(reco::PFDisplacedVertexCollection &, std::vector< bool > &)
Remove potentially fakes displaced vertices.
const MagneticField * magField_
to be able to extrapolate tracks f
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
double chi2() const
chi-squares
friend std::ostream & operator<<(std::ostream &, const PFDisplacedVertexFinder &)
double getLongProj(const GlobalPoint &, const GlobalVector &) const
DistMap r2Map() const
--—— Provide useful information --—— ///
void setInput(const edm::Handle< reco::PFDisplacedVertexCandidateCollection > &)
Set input collections of tracks.
float trackWeight(const reco::TransientTrack &track) const
const std::auto_ptr< reco::PFDisplacedVertexCollection > & displacedVertices() const
const GlobalPoint & seedPoint() const
double transvSize_
--—— Parameters --—— ///
T const * product() const
const Track & track() const
double sigmacut_
Adaptive Vertex Fitter parameters.
reco::PFDisplacedVertexCollection::iterator IDV
math::XYZPoint primaryVertex() const
Set Vertex direction using the primary vertex.
double getLongDiff(const GlobalPoint &, const GlobalPoint &) const
const TrackerGeometry * tkerGeom_
bool isCloseTo(const reco::PFDisplacedVertexSeed &, const reco::PFDisplacedVertexSeed &) const
-----— Tools -----— ///
PFCheckHitPattern hitPattern_
reco::PFDisplacedVertex::VertexTrackType getVertexTrackType(PFTrackHitFullInfo &) const
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
PFDisplacedVertexHelper helper_
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.