CMS 3D CMS Logo

PFDisplacedVertexFinder.cc
Go to the documentation of this file.
3 
5 
8 
12 
14 
17 
19 
20 #include "TMath.h"
21 
22 using namespace std;
23 using namespace reco;
24 
25 //for debug only
26 //#define PFLOW_DEBUG
27 
29  displacedVertexCandidates_( nullptr),
30  displacedVertices_( new PFDisplacedVertexCollection ),
31  transvSize_(0.0),
32  longSize_(0.0),
33  primaryVertexCut_(0.0),
34  tobCut_(0.0),
35  tecCut_(0.0),
36  minAdaptWeight_(2.0),
37  debug_(false) {}
38 
39 
41 
42 void
44  const edm::Handle<reco::PFDisplacedVertexCandidateCollection>& displacedVertexCandidates) {
45 
46  if (displacedVertexCandidates.isValid()){
47  displacedVertexCandidates_ = displacedVertexCandidates.product();
48  } else {
50  }
51 
52 }
53 
54 
55 // -------- Main function which find vertices -------- //
56 
57 void
59 
60  if (debug_) cout << "========= Start Find Displaced Vertices =========" << endl;
61 
62  // The vertexCandidates have not been passed to the event
63  // So they need to be cleared is they are not empty
64  if( displacedVertices_.get() ) displacedVertices_->clear();
65  else
67 
68  if (displacedVertexCandidates_ == nullptr) {
69  edm::LogInfo("EmptyVertexInput")<<"displacedVertexCandidates are not set or the setInput was called with invalid vertex";
70  return;
71  }
72 
73  // Prepare the collections
74  PFDisplacedVertexSeedCollection tempDisplacedVertexSeeds;
75  tempDisplacedVertexSeeds.reserve(4*displacedVertexCandidates_->size());
76  PFDisplacedVertexCollection tempDisplacedVertices;
77  tempDisplacedVertices.reserve(4*displacedVertexCandidates_->size());
78 
79  if (debug_)
80  cout << "1) Parsing displacedVertexCandidates into displacedVertexSeeds" << endl;
81 
82  // 1) Parsing displacedVertexCandidates into displacedVertexSeeds which would
83  // be later used for vertex fitting
84 
85  int i = -1;
86 
87  for(auto const& idvc : *displacedVertexCandidates_) {
88 
89  i++;
90  if (debug_) {
91  cout << "Analyse Vertex Candidate " << i << endl;
92  }
93 
94  findSeedsFromCandidate(idvc, tempDisplacedVertexSeeds);
95 
96  }
97 
98  if (debug_) cout << "2) Merging Vertex Seeds" << endl;
99 
100  // 2) Some displacedVertexSeeds coming from different displacedVertexCandidates
101  // may be closed enough to be merged together. bLocked is an array which keeps the
102  // information about the seeds which are desabled.
103  vector<bool> bLockedSeeds;
104  bLockedSeeds.resize(tempDisplacedVertexSeeds.size());
105  mergeSeeds(tempDisplacedVertexSeeds, bLockedSeeds);
106 
107  if (debug_) cout << "3) Fitting Vertices From Seeds" << endl;
108 
109  // 3) Fit displacedVertices from displacedVertexSeeds
110  for(unsigned idv = 0; idv < tempDisplacedVertexSeeds.size(); idv++){
111 
112  if (!tempDisplacedVertexSeeds[idv].isEmpty() && !bLockedSeeds[idv]) {
113  PFDisplacedVertex displacedVertex;
114  bLockedSeeds[idv] = fitVertexFromSeed(tempDisplacedVertexSeeds[idv], displacedVertex);
115  if (!bLockedSeeds[idv]) tempDisplacedVertices.emplace_back(displacedVertex);
116  }
117  }
118 
119  if (debug_) cout << "4) Rejecting Bad Vertices and label them" << endl;
120 
121  // 4) Reject displaced vertices which may be considered as fakes
122  vector<bool> bLocked;
123  bLocked.resize(tempDisplacedVertices.size());
124  selectAndLabelVertices(tempDisplacedVertices, bLocked);
125 
126  if (debug_) cout << "5) Fill the Displaced Vertices" << endl;
127 
128  // 5) Fill the displacedVertex_ which would be transfered to the producer
129  displacedVertices_->reserve(tempDisplacedVertices.size());
130 
131  for(unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++)
132  if (!bLocked[idv]) displacedVertices_->push_back(tempDisplacedVertices[idv]);
133 
134  if (debug_) cout << "========= End Find Displaced Vertices =========" << endl;
135 
136 
137 }
138 
139 // -------- Different steps of the finder algorithm -------- //
140 
141 
142 void
144 
145  const PFDisplacedVertexCandidate::DistMap r2Map = vertexCandidate.r2Map();
146  bool bNeedNewCandidate = false;
147 
148  tempDisplacedVertexSeeds.push_back( PFDisplacedVertexSeed() );
149 
150  IDVS idvc_current;
151 
152  for (PFDisplacedVertexCandidate::DistMap::const_iterator imap = r2Map.begin();
153  imap != r2Map.end(); imap++){
154 
155  unsigned ie1 = (*imap).second.first;
156  unsigned ie2 = (*imap).second.second;
157 
158  if (debug_) cout << "ie1 = " << ie1 << " ie2 = " << ie2 << " radius = " << sqrt((*imap).first) << endl;
159 
160  GlobalPoint dcaPoint = vertexCandidate.dcaPoint(ie1, ie2);
161  if (fabs(dcaPoint.x()) > 1e9) continue;
162 
163  bNeedNewCandidate = true;
164  for (idvc_current = tempDisplacedVertexSeeds.begin(); idvc_current != tempDisplacedVertexSeeds.end(); idvc_current++){
165  if ((*idvc_current).isEmpty()) {
166  bNeedNewCandidate = false;
167  break;
168  }
169  const GlobalPoint vertexPoint = (*idvc_current).seedPoint();
170  std::pair<float,float> diffs = getTransvLongDiff(vertexPoint,dcaPoint);
171  if (diffs.second > longSize_) continue;
172  if (diffs.first > transvSize_) continue;
173  bNeedNewCandidate = false;
174  break;
175  }
176  if (bNeedNewCandidate) {
177  if (debug_) cout << "create new displaced vertex" << endl;
178  tempDisplacedVertexSeeds.push_back( PFDisplacedVertexSeed() );
179  idvc_current = tempDisplacedVertexSeeds.end();
180  idvc_current--;
181  }
182 
183 
184 
185  (*idvc_current).updateSeedPoint(dcaPoint, vertexCandidate.tref(ie1), vertexCandidate.tref(ie2));
186 
187 
188 
189  }
190 
191 
192 }
193 
194 
195 
196 
197 void
198 PFDisplacedVertexFinder::mergeSeeds(PFDisplacedVertexSeedCollection& tempDisplacedVertexSeeds, vector<bool>& bLocked){
199 
200  // loop over displaced vertex candidates
201  // and merge them if they are close to each other
202  for(unsigned idv_mother = 0;idv_mother < tempDisplacedVertexSeeds.size(); idv_mother++){
203  if (!bLocked[idv_mother]){
204 
205  for (unsigned idv_daughter = idv_mother+1;idv_daughter < tempDisplacedVertexSeeds.size(); idv_daughter++){
206 
207  if (!bLocked[idv_daughter]){
208  if (isCloseTo(tempDisplacedVertexSeeds[idv_mother], tempDisplacedVertexSeeds[idv_daughter])) {
209 
210  tempDisplacedVertexSeeds[idv_mother].mergeWith(tempDisplacedVertexSeeds[idv_daughter]);
211  bLocked[idv_daughter] = true;
212  if (debug_) cout << "Seeds " << idv_mother << " and " << idv_daughter << " merged" << endl;
213  }
214  }
215  }
216  }
217  }
218 
219 }
220 
221 
222 
223 
224 
225 
226 
227 
228 bool
230 
231 
232  if (debug_) cout << "== Start vertexing procedure ==" << endl;
233 
234 
235  // ---- Prepare transient track list ----
236 
237  set < TrackBaseRef, PFDisplacedVertexSeed::Compare > const& tracksToFit = displacedVertexSeed.elements();
238  const GlobalPoint& seedPoint = displacedVertexSeed.seedPoint();
239 
240  vector<TransientTrack> transTracks;
241  vector<TransientTrack> transTracksRaw;
242  vector<TrackBaseRef> transTracksRef;
243  vector<TrackBaseRef> transTracksRefRaw;
244 
245  transTracks.reserve(tracksToFit.size());
246  transTracksRaw.reserve(tracksToFit.size());
247  transTracksRef.reserve(tracksToFit.size());
248  transTracksRefRaw.reserve(tracksToFit.size());
249 
250 
251 
252  TransientVertex theVertexAdaptiveRaw;
253  TransientVertex theRecoVertex;
254 
255 
256  // ---- 1) Clean for potentially poor seeds ------- //
257  // --------------------------------------------- //
258 
259  if (tracksToFit.size() < 2) {
260  if (debug_) cout << "Only one to Fit Track" << endl;
261  return true;
262  }
263 
264  double rho = sqrt(seedPoint.x()*seedPoint.x()+seedPoint.y()*seedPoint.y());
265  double z = seedPoint.z();
266 
267  if (rho > tobCut_ || fabs(z) > tecCut_) {
268  if (debug_) cout << "Seed Point out of the tracker rho = " << rho << " z = "<< z << " nTracks = " << tracksToFit.size() << endl;
269  return true;
270  }
271 
272  if (debug_) displacedVertexSeed.Dump();
273 
274  int nStep45 = 0;
275  int nNotIterative = 0;
276 
277  // Fill vectors of TransientTracks and TrackRefs after applying preselection cuts.
278  for(auto const& ie : tracksToFit){
279  TransientTrack tmpTk( *(ie.get()), magField_, globTkGeomHandle_);
280  transTracksRaw.emplace_back( tmpTk );
281  transTracksRefRaw.push_back( ie );
282  bool nonIt = PFTrackAlgoTools::nonIterative((ie)->algo());
283  bool step45 = PFTrackAlgoTools::step45((ie)->algo());
284  bool highQ = PFTrackAlgoTools::highQuality((ie)->algo());
285  if (step45)
286  nStep45++;
287  else if (nonIt)
288  nNotIterative++;
289  else if (!highQ) {
290  nNotIterative++;
291  nStep45++;
292  }
293 
294  }
295 
296  if (rho > 25 && nStep45 + nNotIterative < 1){
297  if (debug_) cout << "Seed point at rho > 25 cm but no step 4-5 tracks" << endl;
298  return true;
299  }
300 
301  // ----------------------------------------------- //
302  // ---- PRESELECT GOOD TRACKS FOR FINAL VERTEX --- //
303  // ----------------------------------------------- //
304 
305 
306 
307  // 1)If only two track are found do not prefit
308 
309 
310  if ( transTracksRaw.size() == 2 ){
311 
312  if (debug_) cout << "No raw fit done" << endl;
314  if (debug_)
315  cout << "Due to probably high pile-up conditions 2 track vertices switched off" << endl;
316  return true;
317 
318  }
319  GlobalError globalError;
320 
321  theVertexAdaptiveRaw = TransientVertex(seedPoint, globalError, transTracksRaw, 1.);
322 
323 
324 
325  } else {//branch with transTracksRaw.size of at least 3
326 
327 
328 
329  if (debug_) cout << "Raw fit done." << endl;
330 
336 
337  if (transTracksRaw.size() == 3){
338 
339  theVertexAdaptiveRaw = theAdaptiveFitterRaw.vertex(transTracksRaw, seedPoint);
340 
341  }
342  else if ( transTracksRaw.size() < 1000){
345 
346  if (debug_) cout << "First test with KFT" << endl;
347 
348  KalmanVertexFitter theKalmanFitter(true);
349  theVertexAdaptiveRaw = theKalmanFitter.vertex(transTracksRaw, seedPoint);
350 
351  if( !theVertexAdaptiveRaw.isValid() || theVertexAdaptiveRaw.totalChiSquared() < 0. ) {
352  if(debug_) cout << "Prefit failed : valid? " << theVertexAdaptiveRaw.isValid()
353  << " totalChi2 = " << theVertexAdaptiveRaw.totalChiSquared() << endl;
354  return true;
355  }
356 
357  if (debug_) cout << "We use KFT instead of seed point to set up a point for AVF "
358  << " x = " << theVertexAdaptiveRaw.position().x()
359  << " y = " << theVertexAdaptiveRaw.position().y()
360  << " z = " << theVertexAdaptiveRaw.position().z()
361  << endl;
362 
363  // To save time: reject the Displaced vertex if it is too close to the beam pipe.
364  // Frequently it is very big vertices, with some dosens of tracks
365 
366  Vertex vtx = theVertexAdaptiveRaw;
367  rho = vtx.position().rho();
368 
369  // cout << "primary vertex cut = " << primaryVertexCut_ << endl;
370 
371  if (rho < primaryVertexCut_ || rho > 100) {
372  if (debug_) cout << "KFT Vertex geometrically rejected with tracks #rho = " << rho << endl;
373  return true;
374  }
375 
376  // cout << "primary vertex cut = " << primaryVertexCut_ << " rho = " << rho << endl;
377 
378  theVertexAdaptiveRaw = theAdaptiveFitterRaw.vertex(transTracksRaw, theVertexAdaptiveRaw.position());
379 
380 
381  } else {
382  edm::LogWarning("TooManyPFDVCandidates")<<"gave up vertex reco for "<< transTracksRaw.size() <<" tracks";
383  }
384 
385  if( !theVertexAdaptiveRaw.isValid() || theVertexAdaptiveRaw.totalChiSquared() < 0. ) {
386  if(debug_) cout << "Fit failed : valid? " << theVertexAdaptiveRaw.isValid()
387  << " totalChi2 = " << theVertexAdaptiveRaw.totalChiSquared() << endl;
388  return true;
389  }
390 
391  // To save time: reject the Displaced vertex if it is too close to the beam pipe.
392  // Frequently it is very big vertices, with some dosens of tracks
393 
394  Vertex vtx = theVertexAdaptiveRaw;
395  rho = vtx.position().rho();
396 
397  if (rho < primaryVertexCut_) {
398  if (debug_) cout << "Vertex " << " geometrically rejected with " << transTracksRaw.size() << " tracks #rho = " << rho << endl;
399  return true;
400  }
401 
402 
403  }
404 
405 
406 
407  // ---- Remove tracks with small weight or
408  // big first (last) hit_to_vertex distance
409  // and then refit ---- //
410 
411 
412 
413  for (unsigned i = 0; i < transTracksRaw.size(); i++) {
414 
415  if (debug_) cout << "Raw Weight track " << i << " = " << theVertexAdaptiveRaw.trackWeight(transTracksRaw[i]) << endl;
416 
417  if (theVertexAdaptiveRaw.trackWeight(transTracksRaw[i]) > minAdaptWeight_){
418 
419  PFTrackHitFullInfo pattern = hitPattern_.analyze(tkerTopo_, tkerGeom_, transTracksRefRaw[i], theVertexAdaptiveRaw);
420 
421  PFDisplacedVertex::VertexTrackType vertexTrackType = getVertexTrackType(pattern);
422 
423  if (vertexTrackType != PFDisplacedVertex::T_NOT_FROM_VERTEX){
424 
425  bool bGoodTrack = helper_.isTrackSelected(transTracksRaw[i].track(), vertexTrackType);
426 
427  if (bGoodTrack){
428  transTracks.push_back(transTracksRaw[i]);
429  transTracksRef.push_back(transTracksRefRaw[i]);
430  } else {
431  if (debug_)
432  cout << "Track rejected nChi2 = " << transTracksRaw[i].track().normalizedChi2()
433  << " pt = " << transTracksRaw[i].track().pt()
434  << " dxy (wrt (0,0,0)) = " << transTracksRaw[i].track().dxy()
435  << " nHits = " << transTracksRaw[i].track().numberOfValidHits()
436  << " nOuterHits = " << transTracksRaw[i].track().hitPattern().numberOfLostHits(HitPattern::MISSING_OUTER_HITS) << endl;
437  }
438  } else {
439 
440  if (debug_){
441  cout << "Remove track because too far away from the vertex:" << endl;
442  }
443 
444  }
445 
446  }
447 
448  }
449 
450 
451 
452  if (debug_) cout << "All Tracks " << transTracksRaw.size()
453  << " with good weight " << transTracks.size() << endl;
454 
455 
456  // ---- Refit ---- //
457  FitterType vtxFitter = F_NOTDEFINED;
458 
459  if (transTracks.size() < 2) return true;
460  else if (transTracks.size() == 2){
461 
463  if (debug_)
464  cout << "Due to probably high pile-up conditions 2 track vertices switched off" << endl;
465  return true;
466  }
467  vtxFitter = F_KALMAN;
468  }
469  else if (transTracks.size() > 2 && transTracksRaw.size() > transTracks.size())
470  vtxFitter = F_ADAPTIVE;
471  else if (transTracks.size() > 2 && transTracksRaw.size() == transTracks.size())
472  vtxFitter = F_DONOTREFIT;
473  else return true;
474 
475  if (debug_) cout << "Vertex Fitter " << vtxFitter << endl;
476 
477  if(vtxFitter == F_KALMAN){
478 
479  KalmanVertexFitter theKalmanFitter(true);
480  theRecoVertex = theKalmanFitter.vertex(transTracks, seedPoint);
481 
482  } else if(vtxFitter == F_ADAPTIVE){
483 
484  AdaptiveVertexFitter theAdaptiveFitter(
490 
491  theRecoVertex = theAdaptiveFitter.vertex(transTracks, seedPoint);
492 
493  } else if (vtxFitter == F_DONOTREFIT) {
494  theRecoVertex = theVertexAdaptiveRaw;
495  } else {
496  return true;
497  }
498 
499 
500  // ---- Check if the fitted vertex is valid ---- //
501 
502  if( !theRecoVertex.isValid() || theRecoVertex.totalChiSquared() < 0. ) {
503  if (debug_) cout << "Refit failed : valid? " << theRecoVertex.isValid()
504  << " totalChi2 = " << theRecoVertex.totalChiSquared() << endl;
505  return true;
506  }
507 
508  // ---- Create vertex ---- //
509 
510  Vertex theRecoVtx = theRecoVertex;
511 
512  double chi2 = theRecoVtx.chi2();
513  double ndf = theRecoVtx.ndof();
514 
515 
516  if (chi2 > TMath::ChisquareQuantile(0.95, ndf)) {
517  if (debug_)
518  cout << "Rejected because of chi2 = " << chi2 << " ndf = " << ndf << " confid. level: " << TMath::ChisquareQuantile(0.95, ndf) << endl;
519  return true;
520  }
521 
522 
523 
524  // ---- Create and fill vector of refitted TransientTracks ---- //
525 
526  // -----------------------------------------------//
527  // ---- Prepare and Fill the Displaced Vertex ----//
528  // -----------------------------------------------//
529 
530 
531  displacedVertex = (PFDisplacedVertex) theRecoVtx;
532  displacedVertex.removeTracks();
533 
534  for(unsigned i = 0; i < transTracks.size();i++) {
535 
536  PFTrackHitFullInfo pattern = hitPattern_.analyze(tkerTopo_, tkerGeom_, transTracksRef[i], theRecoVertex);
537 
538  PFDisplacedVertex::VertexTrackType vertexTrackType = getVertexTrackType(pattern);
539 
540  Track refittedTrack;
541  float weight = theRecoVertex.trackWeight(transTracks[i]);
542 
543 
544  if (weight < minAdaptWeight_) continue;
545 
546  try{
547  refittedTrack = theRecoVertex.refittedTrack(transTracks[i]).track();
548  }catch( cms::Exception& exception ){
549  continue;
550  }
551 
552  if (debug_){
553  cout << "Vertex Track Type = " << vertexTrackType << endl;
554 
555  cout << "nHitBeforeVertex = " << pattern.first.first
556  << " nHitAfterVertex = " << pattern.second.first
557  << " nMissHitBeforeVertex = " << pattern.first.second
558  << " nMissHitAfterVertex = " << pattern.second.second
559  << " Weight = " << weight << endl;
560  }
561 
562  displacedVertex.addElement(transTracksRef[i],
563  refittedTrack,
564  pattern, vertexTrackType, weight);
565 
566  }
567 
568  displacedVertex.setPrimaryDirection(helper_.primaryVertex());
569  displacedVertex.calcKinematics();
570 
571 
572 
573  if (debug_) cout << "== End vertexing procedure ==" << endl;
574 
575  return false;
576 
577 }
578 
579 
580 
581 
582 
583 
584 void
585 PFDisplacedVertexFinder::selectAndLabelVertices(PFDisplacedVertexCollection& tempDisplacedVertices, vector <bool>& bLocked){
586 
587  if (debug_) cout << " 4.1) Reject vertices " << endl;
588 
589  for(unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++){
590 
591 
592  // ---- We accept a vertex only if it is not in TOB in the barrel
593  // and not in TEC in the end caps
594  // and not too much before the first pixel layer ---- //
595 
596  const float rho = tempDisplacedVertices[idv].position().rho();
597  const float z = tempDisplacedVertices[idv].position().z();
598 
599  if (rho > tobCut_ || rho < primaryVertexCut_ || fabs(z) > tecCut_) {
600  if (debug_) cout << "Vertex " << idv
601  << " geometrically rejected #rho = " << rho
602  << " z = " << z << endl;
603 
604  bLocked[idv] = true;
605 
606  continue;
607  }
608 
609  unsigned nPrimary = tempDisplacedVertices[idv].nPrimaryTracks();
610  unsigned nMerged = tempDisplacedVertices[idv].nMergedTracks();
611  unsigned nSecondary = tempDisplacedVertices[idv].nSecondaryTracks();
612 
613  if (nPrimary + nMerged > 1) {
614  bLocked[idv] = true;
615  if (debug_) cout << "Vertex " << idv
616  << " rejected because two primary or merged tracks" << endl;
617 
618 
619  }
620 
621  if (nPrimary + nMerged + nSecondary < 2){
622  bLocked[idv] = true;
623  if (debug_) cout << "Vertex " << idv
624  << " rejected because only one track related to the vertex" << endl;
625  }
626 
627 
628  }
629 
630 
631  if (debug_) cout << " 4.2) Check for common vertices" << endl;
632 
633  // ---- Among the remaining vertex we shall remove one
634  // of those which have two common tracks ---- //
635 
636  for(unsigned idv_mother = 0; idv_mother < tempDisplacedVertices.size(); idv_mother++){
637  for(unsigned idv_daughter = idv_mother+1;
638  idv_daughter < tempDisplacedVertices.size(); idv_daughter++){
639 
640  if(!bLocked[idv_daughter] && !bLocked[idv_mother]){
641 
642  const unsigned commonTrks = commonTracks(tempDisplacedVertices[idv_daughter], tempDisplacedVertices[idv_mother]);
643 
644  if (commonTrks > 1) {
645 
646  if (debug_) cout << "Vertices " << idv_daughter << " and " << idv_mother
647  << " has many common tracks" << endl;
648 
649  // We keep the vertex vertex which contains the most of the tracks
650 
651  const int mother_size = tempDisplacedVertices[idv_mother].nTracks();
652  const int daughter_size = tempDisplacedVertices[idv_daughter].nTracks();
653 
654  if (mother_size > daughter_size) bLocked[idv_daughter] = true;
655  else if (mother_size < daughter_size) bLocked[idv_mother] = true;
656  else {
657 
658  // If they have the same size we keep the vertex with the best normalised chi2
659 
660  const float mother_normChi2 = tempDisplacedVertices[idv_mother].normalizedChi2();
661  const float daughter_normChi2 = tempDisplacedVertices[idv_daughter].normalizedChi2();
662  if (mother_normChi2 < daughter_normChi2) bLocked[idv_daughter] = true;
663  else bLocked[idv_mother] = true;
664  }
665 
666  }
667  }
668  }
669  }
670 
671  for(unsigned idv = 0; idv < tempDisplacedVertices.size(); idv++)
672  if ( !bLocked[idv] ) bLocked[idv] = rejectAndLabelVertex(tempDisplacedVertices[idv]);
673 
674 
675 }
676 
677 bool
679 
681  dv.setVertexType(vertexType);
682 
683  return dv.isFake();
684 
685 }
686 
687 
689 
690 bool
692 
693  const GlobalPoint& vP1 = dv1.seedPoint();
694  const GlobalPoint& vP2 = dv2.seedPoint();
695 
696  std::pair<float,float> diffs = getTransvLongDiff(vP1,vP2);
697  if (diffs.second > longSize_) return false;
698  if (diffs.first > transvSize_) return false;
699  // if (Delta_Long < longSize_ && Delta_Transv < transvSize_) isCloseTo = true;
700 
701  return true;
702 
703 }
704 
705 
706 std::pair<float,float>
708 
709  const auto & vRef = Ref.basicVector();
710  const auto & vToProject = ToProject.basicVector();
711  float vRefMag2 = vRef.mag2();
712  float oneOverMag = 1.0f/sqrt(vRefMag2);
713 
714  return std::make_pair(fabs(vRef.cross(vToProject).mag()*oneOverMag),fabs((vRef.dot(vToProject)-vRefMag2)*oneOverMag));
715 }
716 
717 
720 
721  unsigned int nHitBeforeVertex = pairTrackHitInfo.first.first;
722  unsigned int nHitAfterVertex = pairTrackHitInfo.second.first;
723 
724  unsigned int nMissHitBeforeVertex = pairTrackHitInfo.first.second;
725  unsigned int nMissHitAfterVertex = pairTrackHitInfo.second.second;
726 
727  // For the moment those definitions are given apriori a more general study would be useful to refine those criteria
728 
729  if (nHitBeforeVertex <= 1 && nHitAfterVertex >= 3 && nMissHitAfterVertex <= 1)
730  return PFDisplacedVertex::T_FROM_VERTEX;
731  else if (nHitBeforeVertex >= 3 && nHitAfterVertex <= 1 && nMissHitBeforeVertex <= 1)
732  return PFDisplacedVertex::T_TO_VERTEX;
733  else if ((nHitBeforeVertex >= 2 && nHitAfterVertex >= 3)
734  ||
735  (nHitBeforeVertex >= 3 && nHitAfterVertex >= 2))
736  return PFDisplacedVertex::T_MERGED;
737  else
738  return PFDisplacedVertex::T_NOT_FROM_VERTEX;
739 }
740 
741 
743 
744  vector<Track> vt1 = v1.refittedTracks();
745  vector<Track> vt2 = v2.refittedTracks();
746 
747  unsigned commonTracks = 0;
748 
749  for ( unsigned il1 = 0; il1 < vt1.size(); il1++){
750  unsigned il1_idx = v1.originalTrack(vt1[il1]).key();
751 
752  for ( unsigned il2 = 0; il2 < vt2.size(); il2++)
753  if (il1_idx == v2.originalTrack(vt2[il2]).key()) {commonTracks++; break;}
754 
755  }
756 
757  return commonTracks;
758 
759 }
760 
761 std::ostream& operator<<(std::ostream& out, const PFDisplacedVertexFinder& a) {
762 
763  if(! out) return out;
764  out << setprecision(3) << setw(5) << endl;
765  out << "" << endl;
766  out << " ====================================== " << endl;
767  out << " ====== Displaced Vertex Finder ======= " << endl;
768  out << " ====================================== " << endl;
769  out << " " << endl;
770 
771  a.helper_.Dump();
772  out << "" << endl
773  << " Adaptive Vertex Fitter parameters are :"<< endl
774  << " sigmacut = " << a.sigmacut_ << " T_ini = "
775  << a.t_ini_ << " ratio = " << a.ratio_ << endl << endl;
776 
777  const std::auto_ptr< reco::PFDisplacedVertexCollection >& displacedVertices_
778  = a.displacedVertices();
779 
780 
781  if(!displacedVertices_.get() ) {
782  out<<"displacedVertex already transfered"<<endl;
783  }
784  else{
785 
786  out<<"Number of displacedVertices found : "<< displacedVertices_->size()<<endl<<endl;
787 
788  int i = -1;
789 
790  for(PFDisplacedVertexFinder::IDV idv = displacedVertices_->begin();
791  idv != displacedVertices_->end(); idv++){
792  i++;
793  out << i << " "; idv->Dump(); out << "" << endl;
794  }
795  }
796 
797  return out;
798 }
std::vector< PFDisplacedVertex > PFDisplacedVertexCollection
collection of PFDisplacedVertex objects
A block of tracks linked together.
void setPrimaryDirection(const math::XYZPoint &pvtx)
reco::PFDisplacedVertexSeedCollection::iterator IDVS
-----— Useful Types -----— ///
TrackBaseRef originalTrack(const Track &refTrack) const
Definition: Vertex.cc:108
std::auto_ptr< reco::PFDisplacedVertexCollection > displacedVertices_
edm::ESHandle< GlobalTrackingGeometry > globTkGeomHandle_
Tracker geometry for discerning hit positions.
const TrackerTopology * tkerTopo_
doc?
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.
T y() const
Definition: PV3DBase.h:63
bool rejectAndLabelVertex(reco::PFDisplacedVertex &dv)
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
Definition: weight.py:1
#define nullptr
std::map< float, std::pair< int, int > > DistMap
const std::vector< Track > & refittedTracks() const
Returns the container of refitted tracks.
Definition: Vertex.h:164
void findDisplacedVertices()
-----— Main function which find vertices -----— ///
bool debug_
If true, debug printouts activated.
const Point & position() const
position
Definition: Vertex.h:109
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
void Dump(std::ostream &out=std::cout) const
cout function
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
size_t key() const
Definition: RefToBase.h:250
T sqrt(T t)
Definition: SSEVec.h:18
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 --—— ///
T z() const
Definition: PV3DBase.h:64
bool nonIterative(const reco::TrackBase::TrackAlgorithm &)
void selectAndLabelVertices(reco::PFDisplacedVertexCollection &, std::vector< bool > &)
Remove potentially fakes displaced vertices.
bool step45(const reco::TrackBase::TrackAlgorithm &)
bool highQuality(const reco::TrackBase::TrackAlgorithm &)
const MagneticField * magField_
to be able to extrapolate tracks f
double chi2() const
chi-squares
Definition: Vertex.h:98
friend std::ostream & operator<<(std::ostream &, const PFDisplacedVertexFinder &)
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
DistMap r2Map() const
--—— Provide useful information --—— ///
bool isValid() const
Definition: HandleBase.h:74
void setInput(const edm::Handle< reco::PFDisplacedVertexCandidateCollection > &)
Set input collections of tracks.
float trackWeight(const reco::TransientTrack &track) const
double ndof() const
Definition: Vertex.h:105
std::pair< float, float > getTransvLongDiff(const GlobalPoint &, const GlobalPoint &) const
const std::auto_ptr< reco::PFDisplacedVertexCollection > & displacedVertices() const
const GlobalPoint & seedPoint() const
Block of elements.
T const * product() const
Definition: Handle.h:81
const Track & track() const
double sigmacut_
Adaptive Vertex Fitter parameters.
reco::PFDisplacedVertexCollection::iterator IDV
fixed size matrix
math::XYZPoint primaryVertex() const
Set Vertex direction using the primary vertex.
double a
Definition: hdecay.h:121
float transvSize_
--—— Parameters --—— ///
const TrackerGeometry * tkerGeom_
void removeTracks()
Definition: Vertex.cc:101
bool isCloseTo(const reco::PFDisplacedVertexSeed &, const reco::PFDisplacedVertexSeed &) const
-----— Tools -----— ///
T x() const
Definition: PV3DBase.h:62
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
bool isValid() const
reco::PFDisplacedVertex::VertexTrackType getVertexTrackType(PFTrackHitFullInfo &) const
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
PFDisplacedVertexHelper helper_