test
CMS 3D CMS Logo

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