32 primaryVertexCut_(0.0),
52 if(displacedVertexCandidates.
isValid()) {
53 for(
unsigned i=0;
i<displacedVertexCandidates->size();
i++) {
67 if (
debug_)
cout <<
"========= Start Find Displaced Vertices =========" << endl;
83 cout <<
"1) Parsing displacedVertexCandidates into displacedVertexSeeds" << endl;
95 cout <<
"Analyse Vertex Candidate " << i << endl;
102 if (
debug_)
cout <<
"2) Merging Vertex Seeds" << endl;
107 vector<bool> bLockedSeeds;
108 bLockedSeeds.resize(tempDisplacedVertexSeeds.size());
109 mergeSeeds(tempDisplacedVertexSeeds, bLockedSeeds);
111 if (
debug_)
cout <<
"3) Fitting Vertices From Seeds" << endl;
114 for(
unsigned idv = 0; idv < tempDisplacedVertexSeeds.size(); idv++){
116 if (!tempDisplacedVertexSeeds[idv].isEmpty() && !bLockedSeeds[idv]) {
118 bLockedSeeds[idv] =
fitVertexFromSeed(tempDisplacedVertexSeeds[idv], displacedVertex);
119 if (!bLockedSeeds[idv]) tempDisplacedVertices.push_back(displacedVertex);
123 if (
debug_)
cout <<
"4) Rejecting Bad Vertices and label them" << endl;
126 vector<bool> bLocked;
127 bLocked.resize(tempDisplacedVertices.size());
130 if (
debug_)
cout <<
"5) Fill the Displaced Vertices" << endl;
135 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++)
138 if (
debug_)
cout <<
"========= End Find Displaced Vertices =========" << endl;
150 bool bNeedNewCandidate =
false;
156 for (PFDisplacedVertexCandidate::DistMap::const_iterator imap = r2Map.begin();
157 imap != r2Map.end(); imap++){
159 unsigned ie1 = (*imap).second.first;
160 unsigned ie2 = (*imap).second.second;
162 if (
debug_)
cout <<
"ie1 = " << ie1 <<
" ie2 = " << ie2 <<
" radius = " <<
sqrt((*imap).first) << endl;
165 if (fabs(dcaPoint.
x()) > 1e9)
continue;
167 bNeedNewCandidate =
true;
168 for (idvc_current = tempDisplacedVertexSeeds.begin(); idvc_current != tempDisplacedVertexSeeds.end(); idvc_current++){
169 if ((*idvc_current).isEmpty()) {
170 bNeedNewCandidate =
false;
173 const GlobalPoint vertexPoint = (*idvc_current).seedPoint();
174 double Delta_Long =
getLongDiff(vertexPoint, dcaPoint);
178 bNeedNewCandidate =
false;
181 if (bNeedNewCandidate) {
182 if (
debug_)
cout <<
"create new displaced vertex" << endl;
184 idvc_current = tempDisplacedVertexSeeds.end();
186 bNeedNewCandidate =
false;
191 (*idvc_current).updateSeedPoint(dcaPoint, vertexCandidate.
tref(ie1), vertexCandidate.
tref(ie2));
208 for(
unsigned idv_mother = 0;idv_mother < tempDisplacedVertexSeeds.size(); idv_mother++){
209 if (!bLocked[idv_mother]){
211 for (
unsigned idv_daughter = idv_mother+1;idv_daughter < tempDisplacedVertexSeeds.size(); idv_daughter++){
213 if (!bLocked[idv_daughter]){
214 if (
isCloseTo(tempDisplacedVertexSeeds[idv_mother], tempDisplacedVertexSeeds[idv_daughter])) {
216 tempDisplacedVertexSeeds[idv_mother].mergeWith(tempDisplacedVertexSeeds[idv_daughter]);
217 bLocked[idv_daughter] =
true;
218 if (
debug_)
cout <<
"Seeds " << idv_mother <<
" and " << idv_daughter <<
" merged" << endl;
238 if (
debug_)
cout <<
"== Start vertexing procedure ==" << endl;
243 set < TrackBaseRef, PFDisplacedVertexSeed::Compare > tracksToFit = displacedVertexSeed.
elements();
246 vector<TransientTrack> transTracks;
247 vector<TransientTrack> transTracksRaw;
248 vector<TrackBaseRef> transTracksRef;
249 vector<TrackBaseRef> transTracksRefRaw;
251 transTracks.reserve(tracksToFit.size());
252 transTracksRaw.reserve(tracksToFit.size());
253 transTracksRef.reserve(tracksToFit.size());
254 transTracksRefRaw.reserve(tracksToFit.size());
265 if (tracksToFit.size() < 2) {
266 if (
debug_)
cout <<
"Only one to Fit Track" << endl;
270 double rho =
sqrt(seedPoint.
x()*seedPoint.
x()+seedPoint.
y()*seedPoint.
y());
271 double z = seedPoint.
z();
274 if (
debug_)
cout <<
"Seed Point out of the tracker rho = " << rho <<
" z = "<< z <<
" nTracks = " << tracksToFit.size() << endl;
281 int nNotIterative = 0;
284 for(
IEset ie = tracksToFit.begin(); ie != tracksToFit.end(); ie++){
286 transTracksRaw.push_back( tmpTk );
287 transTracksRefRaw.push_back( *ie );
288 if ( (*ie)->algo()-4 > 3 ) nStep45++;
289 if ( (*ie)->algo()-4 < 0 ||(*ie)->algo()-4 > 5 ) nNotIterative++;
292 if (rho > 25 && nStep45 + nNotIterative < 1){
293 if (
debug_)
cout <<
"Seed point at rho > 25 cm but no step 4-5 tracks" << endl;
306 if ( transTracksRaw.size() == 2 ){
308 if (
debug_)
cout <<
"No raw fit done" << endl;
311 cout <<
"Due to probably high pile-up conditions 2 track vertices switched off" << endl;
317 theVertexAdaptiveRaw =
TransientVertex(seedPoint, globalError, transTracksRaw, 1.);
337 if ( transTracksRaw.size() < 1000 && transTracksRaw.size() > 3){
339 if (
debug_)
cout <<
"First test with KFT" << endl;
342 theVertexAdaptiveRaw = theKalmanFitter.
vertex(transTracksRaw, seedPoint);
350 if (
debug_)
cout <<
"We use KFT instead of seed point to set up a point for AVF "
351 <<
" x = " << theVertexAdaptiveRaw.
position().
x()
352 <<
" y = " << theVertexAdaptiveRaw.
position().
y()
353 <<
" z = " << theVertexAdaptiveRaw.
position().
z()
359 Vertex vtx = theVertexAdaptiveRaw;
364 if (rho < primaryVertexCut_ || rho > 100) {
365 if (
debug_)
cout <<
"KFT Vertex geometrically rejected with tracks #rho = " << rho << endl;
371 theVertexAdaptiveRaw = theAdaptiveFitterRaw.
vertex(transTracksRaw, theVertexAdaptiveRaw.
position());
377 theVertexAdaptiveRaw = theAdaptiveFitterRaw.
vertex(transTracksRaw, seedPoint);
390 Vertex vtx = theVertexAdaptiveRaw;
394 if (
debug_)
cout <<
"Vertex " <<
" geometrically rejected with " << transTracksRaw.size() <<
" tracks #rho = " << rho << endl;
409 for (
unsigned i = 0;
i < transTracksRaw.size();
i++) {
411 if (
debug_)
cout <<
"Raw Weight track " <<
i <<
" = " << theVertexAdaptiveRaw.
trackWeight(transTracksRaw[
i]) << endl;
419 if (vertexTrackType != PFDisplacedVertex::T_NOT_FROM_VERTEX){
424 transTracks.push_back(transTracksRaw[i]);
425 transTracksRef.push_back(transTracksRefRaw[i]);
428 cout <<
"Track rejected nChi2 = " << transTracksRaw[
i].track().normalizedChi2()
429 <<
" pt = " << transTracksRaw[
i].track().pt()
430 <<
" dxy (wrt (0,0,0)) = " << transTracksRaw[
i].track().dxy()
431 <<
" nHits = " << transTracksRaw[
i].track().numberOfValidHits()
432 <<
" nOuterHits = " << transTracksRaw[
i].track().trackerExpectedHitsOuter().numberOfHits() << endl;
437 cout <<
"Remove track because too far away from the vertex:" << endl;
448 if (
debug_)
cout <<
"All Tracks " << transTracksRaw.size()
449 <<
" with good weight " << transTracks.size() << endl;
455 if (transTracks.size() < 2)
return true;
456 else if (transTracks.size() == 2){
460 cout <<
"Due to probably high pile-up conditions 2 track vertices switched off" << endl;
465 else if (transTracks.size() > 2 && transTracksRaw.size() > transTracks.size())
467 else if (transTracks.size() > 2 && transTracksRaw.size() == transTracks.size())
471 if (
debug_)
cout <<
"Vertex Fitter " << vtxFitter << endl;
476 theRecoVertex = theKalmanFitter.
vertex(transTracks, seedPoint);
487 theRecoVertex = theAdaptiveFitter.
vertex(transTracks, seedPoint);
490 theRecoVertex = theVertexAdaptiveRaw;
506 Vertex theRecoVtx = theRecoVertex;
508 double chi2 = theRecoVtx.
chi2();
509 double ndf = theRecoVtx.
ndof();
512 if (chi2 > TMath::ChisquareQuantile(0.95, ndf)) {
514 cout <<
"Rejected because of chi2 = " << chi2 <<
" ndf = " << ndf <<
" confid. level: " << TMath::ChisquareQuantile(0.95, ndf) << endl;
530 for(
unsigned i = 0;
i < transTracks.size();
i++) {
549 cout <<
"Vertex Track Type = " << vertexTrackType << endl;
551 cout <<
"nHitBeforeVertex = " << pattern.first.first
552 <<
" nHitAfterVertex = " << pattern.second.first
553 <<
" nMissHitBeforeVertex = " << pattern.first.second
554 <<
" nMissHitAfterVertex = " << pattern.second.second
555 <<
" Weight = " << weight << endl;
560 pattern, vertexTrackType, weight);
569 if (
debug_)
cout <<
"== End vertexing procedure ==" << endl;
583 if (
debug_)
cout <<
" 4.1) Reject vertices " << endl;
585 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++){
592 const float rho = tempDisplacedVertices[idv].position().rho();
593 const float z = tempDisplacedVertices[idv].position().z();
597 <<
" geometrically rejected #rho = " << rho
598 <<
" z = " << z << endl;
605 unsigned nPrimary = tempDisplacedVertices[idv].nPrimaryTracks();
606 unsigned nMerged = tempDisplacedVertices[idv].nMergedTracks();
607 unsigned nSecondary = tempDisplacedVertices[idv].nSecondaryTracks();
609 if (nPrimary + nMerged > 1) {
612 <<
" rejected because two primary or merged tracks" << endl;
617 if (nPrimary + nMerged + nSecondary < 2){
620 <<
" rejected because only one track related to the vertex" << endl;
627 if (
debug_)
cout <<
" 4.2) Check for common vertices" << endl;
632 for(
unsigned idv_mother = 0; idv_mother < tempDisplacedVertices.size(); idv_mother++){
633 for(
unsigned idv_daughter = idv_mother+1;
634 idv_daughter < tempDisplacedVertices.size(); idv_daughter++){
636 if(!bLocked[idv_daughter] && !bLocked[idv_mother]){
638 const unsigned commonTrks =
commonTracks(tempDisplacedVertices[idv_daughter], tempDisplacedVertices[idv_mother]);
640 if (commonTrks > 1) {
642 if (
debug_)
cout <<
"Vertices " << idv_daughter <<
" and " << idv_mother
643 <<
" has many common tracks" << endl;
647 const int mother_size = tempDisplacedVertices[idv_mother].nTracks();
648 const int daughter_size = tempDisplacedVertices[idv_daughter].nTracks();
650 if (mother_size > daughter_size) bLocked[idv_daughter] =
true;
651 else if (mother_size < daughter_size) bLocked[idv_mother] =
true;
656 const float mother_normChi2 = tempDisplacedVertices[idv_mother].normalizedChi2();
657 const float daughter_normChi2 = tempDisplacedVertices[idv_daughter].normalizedChi2();
658 if (mother_normChi2 < daughter_normChi2) bLocked[idv_daughter] =
true;
659 else bLocked[idv_mother] =
true;
667 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++)
693 if (Delta_Long >
longSize_)
return false;
708 return fabs((vRef.
dot(vToProject)-vRef.
mag2())/vRef.
mag());
717 return (vRef.
dot(vToProject))/vRef.
mag();
728 return fabs(vRef.
cross(vToProject).
mag()/vRef.
mag());
736 unsigned int nHitBeforeVertex = pairTrackHitInfo.first.first;
737 unsigned int nHitAfterVertex = pairTrackHitInfo.second.first;
739 unsigned int nMissHitBeforeVertex = pairTrackHitInfo.first.second;
740 unsigned int nMissHitAfterVertex = pairTrackHitInfo.second.second;
744 if (nHitBeforeVertex <= 1 && nHitAfterVertex >= 3 && nMissHitAfterVertex <= 1)
745 return PFDisplacedVertex::T_FROM_VERTEX;
746 else if (nHitBeforeVertex >= 3 && nHitAfterVertex <= 1 && nMissHitBeforeVertex <= 1)
747 return PFDisplacedVertex::T_TO_VERTEX;
748 else if ((nHitBeforeVertex >= 2 && nHitAfterVertex >= 3)
750 (nHitBeforeVertex >= 3 && nHitAfterVertex >= 2))
751 return PFDisplacedVertex::T_MERGED;
753 return PFDisplacedVertex::T_NOT_FROM_VERTEX;
764 for (
unsigned il1 = 0; il1 < vt1.size(); il1++){
767 for (
unsigned il2 = 0; il2 < vt2.size(); il2++)
778 if(! out)
return out;
779 out << setprecision(3) << setw(5) << endl;
781 out <<
" ====================================== " << endl;
782 out <<
" ====== Displaced Vertex Finder ======= " << endl;
783 out <<
" ====================================== " << endl;
788 <<
" Adaptive Vertex Fitter parameters are :"<< endl
789 <<
" sigmacut = " << a.
sigmacut_ <<
" T_ini = "
792 const std::auto_ptr< reco::PFDisplacedVertexCollection >& displacedVertices_
796 if(!displacedVertices_.get() ) {
797 out<<
"displacedVertex already transfered"<<endl;
801 out<<
"Number of displacedVertices found : "<< displacedVertices_->size()<<endl<<endl;
806 idv != displacedVertices_->end(); idv++){
808 out << i <<
" "; idv->Dump(); out <<
"" << endl;
double getTransvDiff(const GlobalPoint &, const GlobalPoint &) const
std::vector< PFDisplacedVertex > PFDisplacedVertexCollection
collection of PFDisplacedVertex objects
std::vector< PFDisplacedVertexCandidate > PFDisplacedVertexCandidateCollection
collection of PFDisplacedVertexCandidate 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
TrackBaseRef originalTrack(const Track &refTrack) const
std::auto_ptr< reco::PFDisplacedVertexCollection > displacedVertices_
edm::ESHandle< GlobalTrackingGeometry > globTkGeomHandle_
Tracker geometry for discerning hit positions.
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
float totalChiSquared() const
void Dump(std::ostream &out=std::cout) const
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
bool rejectAndLabelVertex(reco::PFDisplacedVertex &dv)
std::ostream & operator<<(std::ostream &out, const ALILine &li)
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
bool fitVertexFromSeed(reco::PFDisplacedVertexSeed &, reco::PFDisplacedVertex &)
Fit one by one the vertex points with associated tracks to get displaced vertices.
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.
std::set< reco::TrackBaseRef >::iterator IEset
-----— Useful Types -----— ///
PFTrackHitFullInfo analyze(edm::ESHandle< TrackerGeometry >, const reco::TrackBaseRef track, const TransientVertex &vert)
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.
edm::ESHandle< TrackerGeometry > tkerGeomHandle_
doc?
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::auto_ptr< reco::PFDisplacedVertexCandidateCollection > displacedVertexCandidates_
-----— Members -----— ///
std::vector< PFDisplacedVertexSeed > PFDisplacedVertexSeedCollection
collection of PFDisplacedVertexSeed objects
reco::PFDisplacedVertex::VertexType identifyVertex(const reco::PFDisplacedVertex &v) const
Vertex identification tool.
GlobalPoint position() const
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
double getLongProj(const GlobalPoint &, const GlobalVector &) const
DistMap r2Map() const
--—— Provide useful information --—— ///
reco::PFDisplacedVertexCandidateCollection::iterator IDVC
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
void findSeedsFromCandidate(reco::PFDisplacedVertexCandidate &, reco::PFDisplacedVertexSeedCollection &)
--—— Different steps of the finder algorithm --—— ///
const GlobalPoint & seedPoint() const
double transvSize_
--—— Parameters --—— ///
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
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.