33 primaryVertexCut_(0.0),
53 if(displacedVertexCandidates.
isValid()) {
54 for(
unsigned i=0;
i<displacedVertexCandidates->size();
i++) {
68 if (
debug_)
cout <<
"========= Start Find Displaced Vertices =========" << endl;
84 cout <<
"1) Parsing displacedVertexCandidates into displacedVertexSeeds" << endl;
96 cout <<
"Analyse Vertex Candidate " << i << endl;
103 if (
debug_)
cout <<
"2) Merging Vertex Seeds" << endl;
108 vector<bool> bLockedSeeds;
109 bLockedSeeds.resize(tempDisplacedVertexSeeds.size());
110 mergeSeeds(tempDisplacedVertexSeeds, bLockedSeeds);
112 if (
debug_)
cout <<
"3) Fitting Vertices From Seeds" << endl;
115 for(
unsigned idv = 0; idv < tempDisplacedVertexSeeds.size(); idv++){
117 if (!tempDisplacedVertexSeeds[idv].isEmpty() && !bLockedSeeds[idv]) {
119 bLockedSeeds[idv] =
fitVertexFromSeed(tempDisplacedVertexSeeds[idv], displacedVertex);
120 if (!bLockedSeeds[idv]) tempDisplacedVertices.push_back(displacedVertex);
124 if (
debug_)
cout <<
"4) Rejecting Bad Vertices and label them" << endl;
127 vector<bool> bLocked;
128 bLocked.resize(tempDisplacedVertices.size());
131 if (
debug_)
cout <<
"5) Fill the Displaced Vertices" << endl;
136 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++)
139 if (
debug_)
cout <<
"========= End Find Displaced Vertices =========" << endl;
151 bool bNeedNewCandidate =
false;
157 for (PFDisplacedVertexCandidate::DistMap::const_iterator imap = r2Map.begin();
158 imap != r2Map.end(); imap++){
160 unsigned ie1 = (*imap).second.first;
161 unsigned ie2 = (*imap).second.second;
163 if (
debug_)
cout <<
"ie1 = " << ie1 <<
" ie2 = " << ie2 <<
" radius = " <<
sqrt((*imap).first) << endl;
166 if (fabs(dcaPoint.
x()) > 1e9)
continue;
168 bNeedNewCandidate =
true;
169 for (idvc_current = tempDisplacedVertexSeeds.begin(); idvc_current != tempDisplacedVertexSeeds.end(); idvc_current++){
170 if ((*idvc_current).isEmpty()) {
171 bNeedNewCandidate =
false;
174 const GlobalPoint vertexPoint = (*idvc_current).seedPoint();
175 double Delta_Long =
getLongDiff(vertexPoint, dcaPoint);
179 bNeedNewCandidate =
false;
182 if (bNeedNewCandidate) {
183 if (
debug_)
cout <<
"create new displaced vertex" << endl;
185 idvc_current = tempDisplacedVertexSeeds.end();
187 bNeedNewCandidate =
false;
192 (*idvc_current).updateSeedPoint(dcaPoint, vertexCandidate.
tref(ie1), vertexCandidate.
tref(ie2));
209 for(
unsigned idv_mother = 0;idv_mother < tempDisplacedVertexSeeds.size(); idv_mother++){
210 if (!bLocked[idv_mother]){
212 for (
unsigned idv_daughter = idv_mother+1;idv_daughter < tempDisplacedVertexSeeds.size(); idv_daughter++){
214 if (!bLocked[idv_daughter]){
215 if (
isCloseTo(tempDisplacedVertexSeeds[idv_mother], tempDisplacedVertexSeeds[idv_daughter])) {
217 tempDisplacedVertexSeeds[idv_mother].mergeWith(tempDisplacedVertexSeeds[idv_daughter]);
218 bLocked[idv_daughter] =
true;
219 if (
debug_)
cout <<
"Seeds " << idv_mother <<
" and " << idv_daughter <<
" merged" << endl;
239 if (
debug_)
cout <<
"== Start vertexing procedure ==" << endl;
244 set < TrackBaseRef, PFDisplacedVertexSeed::Compare > tracksToFit = displacedVertexSeed.
elements();
247 vector<TransientTrack> transTracks;
248 vector<TransientTrack> transTracksRaw;
249 vector<TrackBaseRef> transTracksRef;
250 vector<TrackBaseRef> transTracksRefRaw;
252 transTracks.reserve(tracksToFit.size());
253 transTracksRaw.reserve(tracksToFit.size());
254 transTracksRef.reserve(tracksToFit.size());
255 transTracksRefRaw.reserve(tracksToFit.size());
266 if (tracksToFit.size() < 2) {
267 if (
debug_)
cout <<
"Only one to Fit Track" << endl;
271 double rho =
sqrt(seedPoint.
x()*seedPoint.
x()+seedPoint.
y()*seedPoint.
y());
272 double z = seedPoint.
z();
275 if (
debug_)
cout <<
"Seed Point out of the tracker rho = " << rho <<
" z = "<< z <<
" nTracks = " << tracksToFit.size() << endl;
282 int nNotIterative = 0;
285 for(
IEset ie = tracksToFit.begin(); ie != tracksToFit.end(); ie++){
287 transTracksRaw.push_back( tmpTk );
288 transTracksRefRaw.push_back( *ie );
303 if (rho > 25 && nStep45 + nNotIterative < 1){
304 if (
debug_)
cout <<
"Seed point at rho > 25 cm but no step 4-5 tracks" << endl;
317 if ( transTracksRaw.size() == 2 ){
319 if (
debug_)
cout <<
"No raw fit done" << endl;
322 cout <<
"Due to probably high pile-up conditions 2 track vertices switched off" << endl;
328 theVertexAdaptiveRaw =
TransientVertex(seedPoint, globalError, transTracksRaw, 1.);
348 if ( transTracksRaw.size() < 1000 && transTracksRaw.size() > 3){
350 if (
debug_)
cout <<
"First test with KFT" << endl;
353 theVertexAdaptiveRaw = theKalmanFitter.
vertex(transTracksRaw, seedPoint);
361 if (
debug_)
cout <<
"We use KFT instead of seed point to set up a point for AVF "
362 <<
" x = " << theVertexAdaptiveRaw.
position().
x()
363 <<
" y = " << theVertexAdaptiveRaw.
position().
y()
364 <<
" z = " << theVertexAdaptiveRaw.
position().
z()
370 Vertex vtx = theVertexAdaptiveRaw;
375 if (rho < primaryVertexCut_ || rho > 100) {
376 if (
debug_)
cout <<
"KFT Vertex geometrically rejected with tracks #rho = " << rho << endl;
382 theVertexAdaptiveRaw = theAdaptiveFitterRaw.
vertex(transTracksRaw, theVertexAdaptiveRaw.
position());
388 theVertexAdaptiveRaw = theAdaptiveFitterRaw.
vertex(transTracksRaw, seedPoint);
401 Vertex vtx = theVertexAdaptiveRaw;
405 if (
debug_)
cout <<
"Vertex " <<
" geometrically rejected with " << transTracksRaw.size() <<
" tracks #rho = " << rho << endl;
420 for (
unsigned i = 0;
i < transTracksRaw.size();
i++) {
422 if (
debug_)
cout <<
"Raw Weight track " <<
i <<
" = " << theVertexAdaptiveRaw.
trackWeight(transTracksRaw[
i]) << endl;
430 if (vertexTrackType != PFDisplacedVertex::T_NOT_FROM_VERTEX){
435 transTracks.push_back(transTracksRaw[i]);
436 transTracksRef.push_back(transTracksRefRaw[i]);
439 cout <<
"Track rejected nChi2 = " << transTracksRaw[
i].track().normalizedChi2()
440 <<
" pt = " << transTracksRaw[
i].track().pt()
441 <<
" dxy (wrt (0,0,0)) = " << transTracksRaw[
i].track().dxy()
442 <<
" nHits = " << transTracksRaw[
i].track().numberOfValidHits()
443 <<
" nOuterHits = " << transTracksRaw[
i].track().hitPattern().numberOfHits(HitPattern::MISSING_OUTER_HITS) << endl;
448 cout <<
"Remove track because too far away from the vertex:" << endl;
459 if (
debug_)
cout <<
"All Tracks " << transTracksRaw.size()
460 <<
" with good weight " << transTracks.size() << endl;
466 if (transTracks.size() < 2)
return true;
467 else if (transTracks.size() == 2){
471 cout <<
"Due to probably high pile-up conditions 2 track vertices switched off" << endl;
476 else if (transTracks.size() > 2 && transTracksRaw.size() > transTracks.size())
478 else if (transTracks.size() > 2 && transTracksRaw.size() == transTracks.size())
482 if (
debug_)
cout <<
"Vertex Fitter " << vtxFitter << endl;
487 theRecoVertex = theKalmanFitter.
vertex(transTracks, seedPoint);
498 theRecoVertex = theAdaptiveFitter.
vertex(transTracks, seedPoint);
501 theRecoVertex = theVertexAdaptiveRaw;
517 Vertex theRecoVtx = theRecoVertex;
520 double ndf = theRecoVtx.
ndof();
523 if (chi2 > TMath::ChisquareQuantile(0.95, ndf)) {
525 cout <<
"Rejected because of chi2 = " << chi2 <<
" ndf = " << ndf <<
" confid. level: " << TMath::ChisquareQuantile(0.95, ndf) << endl;
541 for(
unsigned i = 0;
i < transTracks.size();
i++) {
560 cout <<
"Vertex Track Type = " << vertexTrackType << endl;
562 cout <<
"nHitBeforeVertex = " << pattern.first.first
563 <<
" nHitAfterVertex = " << pattern.second.first
564 <<
" nMissHitBeforeVertex = " << pattern.first.second
565 <<
" nMissHitAfterVertex = " << pattern.second.second
566 <<
" Weight = " << weight << endl;
571 pattern, vertexTrackType, weight);
580 if (
debug_)
cout <<
"== End vertexing procedure ==" << endl;
594 if (
debug_)
cout <<
" 4.1) Reject vertices " << endl;
596 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++){
603 const float rho = tempDisplacedVertices[idv].position().rho();
604 const float z = tempDisplacedVertices[idv].position().z();
608 <<
" geometrically rejected #rho = " << rho
609 <<
" z = " << z << endl;
616 unsigned nPrimary = tempDisplacedVertices[idv].nPrimaryTracks();
617 unsigned nMerged = tempDisplacedVertices[idv].nMergedTracks();
618 unsigned nSecondary = tempDisplacedVertices[idv].nSecondaryTracks();
620 if (nPrimary + nMerged > 1) {
623 <<
" rejected because two primary or merged tracks" << endl;
628 if (nPrimary + nMerged + nSecondary < 2){
631 <<
" rejected because only one track related to the vertex" << endl;
638 if (
debug_)
cout <<
" 4.2) Check for common vertices" << endl;
643 for(
unsigned idv_mother = 0; idv_mother < tempDisplacedVertices.size(); idv_mother++){
644 for(
unsigned idv_daughter = idv_mother+1;
645 idv_daughter < tempDisplacedVertices.size(); idv_daughter++){
647 if(!bLocked[idv_daughter] && !bLocked[idv_mother]){
649 const unsigned commonTrks =
commonTracks(tempDisplacedVertices[idv_daughter], tempDisplacedVertices[idv_mother]);
651 if (commonTrks > 1) {
653 if (
debug_)
cout <<
"Vertices " << idv_daughter <<
" and " << idv_mother
654 <<
" has many common tracks" << endl;
658 const int mother_size = tempDisplacedVertices[idv_mother].nTracks();
659 const int daughter_size = tempDisplacedVertices[idv_daughter].nTracks();
661 if (mother_size > daughter_size) bLocked[idv_daughter] =
true;
662 else if (mother_size < daughter_size) bLocked[idv_mother] =
true;
667 const float mother_normChi2 = tempDisplacedVertices[idv_mother].normalizedChi2();
668 const float daughter_normChi2 = tempDisplacedVertices[idv_daughter].normalizedChi2();
669 if (mother_normChi2 < daughter_normChi2) bLocked[idv_daughter] =
true;
670 else bLocked[idv_mother] =
true;
678 for(
unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++)
704 if (Delta_Long >
longSize_)
return false;
719 return fabs((vRef.
dot(vToProject)-vRef.
mag2())/vRef.
mag());
728 return (vRef.
dot(vToProject))/vRef.
mag();
739 return fabs(vRef.
cross(vToProject).
mag()/vRef.
mag());
747 unsigned int nHitBeforeVertex = pairTrackHitInfo.first.first;
748 unsigned int nHitAfterVertex = pairTrackHitInfo.second.first;
750 unsigned int nMissHitBeforeVertex = pairTrackHitInfo.first.second;
751 unsigned int nMissHitAfterVertex = pairTrackHitInfo.second.second;
755 if (nHitBeforeVertex <= 1 && nHitAfterVertex >= 3 && nMissHitAfterVertex <= 1)
756 return PFDisplacedVertex::T_FROM_VERTEX;
757 else if (nHitBeforeVertex >= 3 && nHitAfterVertex <= 1 && nMissHitBeforeVertex <= 1)
758 return PFDisplacedVertex::T_TO_VERTEX;
759 else if ((nHitBeforeVertex >= 2 && nHitAfterVertex >= 3)
761 (nHitBeforeVertex >= 3 && nHitAfterVertex >= 2))
762 return PFDisplacedVertex::T_MERGED;
764 return PFDisplacedVertex::T_NOT_FROM_VERTEX;
775 for (
unsigned il1 = 0; il1 < vt1.size(); il1++){
778 for (
unsigned il2 = 0; il2 < vt2.size(); il2++)
789 if(! out)
return out;
790 out << setprecision(3) << setw(5) << endl;
792 out <<
" ====================================== " << endl;
793 out <<
" ====== Displaced Vertex Finder ======= " << endl;
794 out <<
" ====================================== " << endl;
799 <<
" Adaptive Vertex Fitter parameters are :"<< endl
800 <<
" sigmacut = " << a.
sigmacut_ <<
" T_ini = "
803 const std::auto_ptr< reco::PFDisplacedVertexCollection >& displacedVertices_
807 if(!displacedVertices_.get() ) {
808 out<<
"displacedVertex already transfered"<<endl;
812 out<<
"Number of displacedVertices found : "<< displacedVertices_->size()<<endl<<endl;
817 idv != displacedVertices_->end(); idv++){
819 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
volatile std::atomic< bool > shutdown_flag false
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.