CMS 3D CMS Logo

PF_PU_AssoMapAlgos.cc
Go to the documentation of this file.
1 
3 
5 
7 
12 
14 
17 
18 using namespace edm;
19 using namespace std;
20 using namespace reco;
21 
22 /*************************************************************************************/
23 /* dedicated constructor for the algorithms */
24 /*************************************************************************************/
25 
27  : maxNumWarnings_(3),
28  numWarnings_(0)
29 {
30 
31  input_MaxNumAssociations_ = iConfig.getParameter<int>("MaxNumberOfAssociations");
32 
33  token_VertexCollection_= iC.consumes<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
34 
35  token_BeamSpot_= iC.consumes<BeamSpot>(iConfig.getParameter<InputTag>("BeamSpot"));
36 
37  input_doReassociation_= iConfig.getParameter<bool>("doReassociation");
38  cleanedColls_ = iConfig.getParameter<bool>("GetCleanedCollections");
39 
40  ConversionsCollectionToken_= iC.consumes<ConversionCollection>(iConfig.getParameter<InputTag>("ConversionsCollection"));
41 
44 
46 
47  input_FinalAssociation_= iConfig.getUntrackedParameter<int>("FinalAssociation", 0);
48 
49  ignoremissingpfcollection_ = iConfig.getParameter<bool>("ignoreMissingCollection");
50 
51  input_nTrack_ = iConfig.getParameter<double>("nTrackWeight");
52 
53 }
54 
55 /*************************************************************************************/
56 /* get all needed collections at the beginning */
57 /*************************************************************************************/
58 
59 void
61 {
62 
63  //get the offline beam spot
65 
66  //get the conversion collection for the gamma conversions
69 
70  //get the vertex composite candidate collection for the Kshort's
73 
74  //get the vertex composite candidate collection for the Lambda's
77 
78  //get the displaced vertex collection for nuclear interactions
79  //create a new bool, true if no displaced vertex collection is in the event, mostly for AOD
80  missingColls = false;
83 
84  missingColls = true;
85 
86  if ( numWarnings_ < maxNumWarnings_ ) {
87  LogWarning("PF_PU_AssoMapAlgos::GetInputCollections")
88  << "No Extra objects available in input file --> skipping reconstruction of displaced vertices !!" << endl;
89  ++numWarnings_;
90  }
91 
92  }
93  } else {
94 
96 
97  }
98 
99  //get the input vertex collection
101 
102  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
103 
104 }
105 
106 /*************************************************************************************/
107 /* create the track-to-vertex and vertex-to-track maps in one go */
108 /*************************************************************************************/
109 std::pair<std::unique_ptr<TrackToVertexAssMap>, std::unique_ptr<VertexToTrackAssMap>>
111 {
112 
113  unique_ptr<TrackToVertexAssMap> track2vertex(new TrackToVertexAssMap(vtxcollH, trkcollH));
114  unique_ptr<VertexToTrackAssMap> vertex2track(new VertexToTrackAssMap(trkcollH, vtxcollH));
115 
116  int num_vertices = vtxcollH->size();
117  if ( num_vertices < input_MaxNumAssociations_) input_MaxNumAssociations_ = num_vertices;
118  vector<VertexRef> vtxColl_help;
119  if (input_MaxNumAssociations_ == 1) vtxColl_help = CreateVertexVector(vtxcollH);
120 
121  //loop over all tracks of the track collection
122  for ( size_t idxTrack = 0; idxTrack < trkcollH->size(); ++idxTrack ) {
123 
124  TrackRef trackref = TrackRef(trkcollH, idxTrack);
125 
126  TransientTrack transtrk(trackref, &(*bFieldH) );
127  transtrk.setBeamSpot(*beamspotH);
128  transtrk.setES(iSetup);
129 
130  if (input_MaxNumAssociations_ > 1) vtxColl_help = CreateVertexVector(vtxcollH);
131 
132  for ( int assoc_ite = 0; assoc_ite < input_MaxNumAssociations_; ++assoc_ite ) {
133 
134  VertexStepPair assocVtx = FindAssociation(trackref, vtxColl_help, bFieldH, iSetup, beamspotH, assoc_ite);
135  int step = assocVtx.second;
136  double distance = ( IPTools::absoluteImpactParameter3D( transtrk, *(assocVtx.first) ) ).second.value();
137 
138  int quality = DefineQuality(assoc_ite, step, distance);
139 
140  //std::cout << "associating track: Pt = " << trackref->pt() << ","
141  // << " eta = " << trackref->eta() << ", phi = " << trackref->phi()
142  // << " to vertex: z = " << associatedVertex.first->position().z() << " with quality q = " << quality << std::endl;
143 
144 
145  // Insert the best vertex and the pair of track and the quality of this association in the map
146  track2vertex->insert( assocVtx.first, make_pair(trackref, quality) );
147  vertex2track->insert( trackref, make_pair(assocVtx.first, quality) );
148 
149  //cleanup only if multiple iterations are made
150  if (input_MaxNumAssociations_ > 1) PF_PU_AssoMapAlgos::EraseVertex(vtxColl_help, assocVtx.first);
151 
152  }
153 
154  }
155 
156  return {std::move(track2vertex), std::move(vertex2track)};
157 
158 }
159 
160 /*************************************************************************************/
161 /* create the track to vertex association map */
162 /*************************************************************************************/
163 
164 std::unique_ptr<TrackToVertexAssMap>
166 {
167  return createMappings(trkcollH,iSetup).first;
168 }
169 
170 /*************************************************************************************/
171 /* create the vertex to track association map */
172 /*************************************************************************************/
173 
174 std::unique_ptr<VertexToTrackAssMap>
176 {
177  return createMappings(trkcollH,iSetup).second;
178 }
179 
180 /*****************************************************************************************/
181 /* function to sort the vertices in the AssociationMap by the sum of (pT - pT_Error)**2 */
182 /*****************************************************************************************/
183 
184 unique_ptr<TrackToVertexAssMap>
186 {
187  //create a new TrackVertexAssMap for the Output which will be sorted
188  unique_ptr<TrackToVertexAssMap> trackvertexassOutput(new TrackToVertexAssMap(vtxcollH, trkcollH));
189 
190  //Create and fill a vector of pairs of vertex and the summed (pT-pT_Error)**2 of the tracks associated to the vertex
191  VertexPtsumVector vertexptsumvector;
192 
193  //loop over all vertices in the association map
194  for(TrackToVertexAssMap::const_iterator assomap_ite=trackvertexassInput->begin(); assomap_ite!=trackvertexassInput->end(); assomap_ite++){
195 
196  const VertexRef assomap_vertexref = assomap_ite->key;
197  const TrackQualityPairVector trckcoll = assomap_ite->val;
198 
199  float ptsum = 0;
200 
201  TrackRef trackref;
202 
203  //get the tracks associated to the vertex and calculate the manipulated pT**2
204  for(unsigned int trckcoll_ite=0; trckcoll_ite<trckcoll.size(); trckcoll_ite++){
205 
206  trackref = trckcoll[trckcoll_ite].first;
207  int quality = trckcoll[trckcoll_ite].second;
208 
209  if ( quality<=2 ) continue;
210 
211  double man_pT = trackref->pt() - trackref->ptError();
212  if(man_pT>0.) ptsum+=man_pT*man_pT;
213 
214  }
215 
216  vertexptsumvector.push_back(make_pair(assomap_vertexref,ptsum));
217 
218  }
219 
220  while (!vertexptsumvector.empty()){
221 
222  VertexRef vertexref_highestpT;
223  float highestpT = 0.;
224  int highestpT_index = 0;
225 
226  for(unsigned int vtxptsumvec_ite=0; vtxptsumvec_ite<vertexptsumvector.size(); vtxptsumvec_ite++){
227 
228  if(vertexptsumvector[vtxptsumvec_ite].second>highestpT){
229 
230  vertexref_highestpT = vertexptsumvector[vtxptsumvec_ite].first;
231  highestpT = vertexptsumvector[vtxptsumvec_ite].second;
232  highestpT_index = vtxptsumvec_ite;
233 
234  }
235 
236  }
237 
238  //loop over all vertices in the association map
239  for(TrackToVertexAssMap::const_iterator assomap_ite=trackvertexassInput->begin(); assomap_ite!=trackvertexassInput->end(); assomap_ite++){
240 
241  const VertexRef assomap_vertexref = assomap_ite->key;
242  const TrackQualityPairVector trckcoll = assomap_ite->val;
243 
244  //if the vertex from the association map the vertex with the highest manipulated pT
245  //insert all associated tracks in the output Association Map
246  if(assomap_vertexref==vertexref_highestpT)
247  for(unsigned int trckcoll_ite=0; trckcoll_ite<trckcoll.size(); trckcoll_ite++)
248  trackvertexassOutput->insert(assomap_vertexref,trckcoll[trckcoll_ite]);
249 
250  }
251 
252  vertexptsumvector.erase(vertexptsumvector.begin()+highestpT_index);
253 
254  }
255 
256  return trackvertexassOutput;
257 
258 }
259 
260 /********************/
261 /* */
262 /* Member Functions */
263 /* */
264 /********************/
265 
266 /*************************************************************************************/
267 /* create helping vertex vector to remove associated vertices */
268 /*************************************************************************************/
269 
270 std::vector<reco::VertexRef>
272 {
273 
274  vector<VertexRef> output;
275  output.reserve(vtxcollH->size());
276  auto const nVtx = vtxcollH->size();
277  for (unsigned int i = 0; i < nVtx; ++i) output.emplace_back(vtxcollH,i);
278 
279  return output;
280 
281 }
282 
283 /****************************************************************************/
284 /* erase one vertex from the vertex vector */
285 /****************************************************************************/
286 
287 void
288 PF_PU_AssoMapAlgos::EraseVertex(std::vector<reco::VertexRef>& vtxcollV, reco::VertexRef toErase)
289 {
290 
291  for(unsigned int index_vtx=0; index_vtx<vtxcollV.size(); ++index_vtx){
292 
293  VertexRef vertexref = vtxcollV.at(index_vtx);
294 
295  if ( vertexref == toErase ){
296  vtxcollV.erase(vtxcollV.begin()+index_vtx);
297  break;
298  }
299 
300  }
301 
302 }
303 
304 
305 /*************************************************************************************/
306 /* function to find the closest vertex in 3D for a certain track */
307 /*************************************************************************************/
308 
309 VertexRef
310 PF_PU_AssoMapAlgos::FindClosestZ(const reco::TrackRef trkref, const std::vector<reco::VertexRef>& vtxcollV, double tWeight)
311 {
312 
313  double ztrack = trkref->vertex().z();
314 
315  VertexRef foundVertexRef = vtxcollV.at(0);
316 
317  double dzmin = 1e5;
318 
319  //loop over all vertices with a good quality in the vertex collection
320  for(unsigned int index_vtx=0; index_vtx<vtxcollV.size(); ++index_vtx){
321 
322  VertexRef vertexref = vtxcollV.at(index_vtx);
323 
324  double nTracks = sqrt(vertexref->tracksSize());
325 
326  double z_distance = fabs(ztrack - vertexref->z());
327 
328  double weightedDistance = z_distance-tWeight*nTracks;
329 
330  if(weightedDistance<dzmin) {
331  dzmin = weightedDistance;
332  foundVertexRef = vertexref;
333  }
334 
335  }
336 
337  return foundVertexRef;
338 }
339 
340 
341 /*************************************************************************************/
342 /* function to find the closest vertex in 3D for a certain track */
343 /*************************************************************************************/
344 
345 VertexRef
346 PF_PU_AssoMapAlgos::FindClosest3D(TransientTrack transtrk, const std::vector<reco::VertexRef>& vtxcollV, double tWeight)
347 {
348 
349  VertexRef foundVertexRef = vtxcollV.at(0);
350 
351  double d3min = 1e5;
352 
353  //loop over all vertices with a good quality in the vertex collection
354  for(unsigned int index_vtx=0; index_vtx<vtxcollV.size(); ++index_vtx){
355 
356  VertexRef vertexref = vtxcollV.at(index_vtx);
357 
358  double nTracks = sqrt(vertexref->tracksSize());
359 
360  double distance = 1e5;
361  pair<bool,Measurement1D> IpPair = IPTools::absoluteImpactParameter3D(transtrk, *vertexref);
362 
363  if(IpPair.first)
364  distance = IpPair.second.value();
365 
366  double weightedDistance = distance-tWeight*nTracks;
367 
368  if(weightedDistance<d3min) {
369  d3min = weightedDistance;
370  foundVertexRef = vertexref;
371  }
372 
373  }
374 
375  return foundVertexRef;
376 }
377 
378 /****************************************************************************************/
379 /* function to calculate the deltaR between a vector and a vector connecting two points */
380 /****************************************************************************************/
381 
382 double
384 {
385 
386  double bs_x = bsH->x0();
387  double bs_y = bsH->y0();
388  double bs_z = bsH->z0();
389 
390  double connVec_x = vtx_pos.x() - bs_x;
391  double connVec_y = vtx_pos.y() - bs_y;
392  double connVec_z = vtx_pos.z() - bs_z;
393 
394  double connVec_r = sqrt(connVec_x*connVec_x + connVec_y*connVec_y + connVec_z*connVec_z);
395  double connVec_theta = acos(connVec_z*1./connVec_r);
396 
397  double connVec_eta = -1.*log(tan(connVec_theta*1./2.));
398  double connVec_phi = atan2(connVec_y,connVec_x);
399 
400  return deltaR(vtx_mom.eta(),vtx_mom.phi(),connVec_eta,connVec_phi);
401 
402 }
403 
404 /*************************************************************************************/
405 /* function to filter the conversion collection */
406 /*************************************************************************************/
407 
408 unique_ptr<ConversionCollection>
410 {
411  unique_ptr<ConversionCollection> cleanedConvColl(new ConversionCollection() );
412 
413  for (unsigned int convcoll_idx=0; convcoll_idx<convCollH->size(); convcoll_idx++){
414 
415  ConversionRef convref(convCollH,convcoll_idx);
416 
417  if(!cleanedColl){
418  cleanedConvColl->push_back(*convref);
419  continue;
420  }
421 
422  if( (convref->nTracks()==2) &&
423  (fabs(convref->pairInvariantMass())<=0.1) ){
424 
425  cleanedConvColl->push_back(*convref);
426 
427  }
428 
429  }
430 
431  return cleanedConvColl;
432 
433 }
434 
435 
436 /*************************************************************************************/
437 /* function to find out if the track comes from a gamma conversion */
438 /*************************************************************************************/
439 
440 bool
442 {
443 
444  for(unsigned int convcoll_ite=0; convcoll_ite<cleanedConvColl.size(); convcoll_ite++){
445 
446  if(ConversionTools::matchesConversion(trackref,cleanedConvColl.at(convcoll_ite))){
447 
448  *gamma = cleanedConvColl.at(convcoll_ite);
449  return true;
450 
451  }
452 
453  }
454 
455  return false;
456 }
457 
458 
459 /********************************************************************************/
460 /* function to find the closest vertex for a track from a conversion */
461 /********************************************************************************/
462 
463 VertexRef
465  const EventSetup& iSetup, edm::Handle<reco::BeamSpot> bsH, const std::vector<reco::VertexRef>& vtxcollV, double tWeight)
466 {
467 
468  math::XYZPoint conv_pos = gamma.conversionVertex().position();
469 
470  math::XYZVector conv_mom(gamma.refittedPair4Momentum().x(),
471  gamma.refittedPair4Momentum().y(),
472  gamma.refittedPair4Momentum().z());
473 
474  Track photon(trackref->chi2(), trackref->ndof(), conv_pos, conv_mom, 0, trackref->covariance());
475 
476  TransientTrack transpho(photon, &(*bfH) );
477  transpho.setBeamSpot(*bsH);
478  transpho.setES(iSetup);
479 
480  return FindClosest3D(transpho, vtxcollV, tWeight);
481 
482 }
483 
484 /*************************************************************************************/
485 /* function to filter the Kshort collection */
486 /*************************************************************************************/
487 
488 unique_ptr<VertexCompositeCandidateCollection>
490 {
491 
492  unique_ptr<VertexCompositeCandidateCollection> cleanedKaonColl(new VertexCompositeCandidateCollection() );
493 
494  for (unsigned int kscoll_idx=0; kscoll_idx<KshortsH->size(); kscoll_idx++){
495 
496  VertexCompositeCandidateRef ksref(KshortsH,kscoll_idx);
497 
498  if(!cleanedColl){
499  cleanedKaonColl->push_back(*ksref);
500  continue;
501  }
502 
503  VertexDistance3D distanceComputer;
504 
505  GlobalPoint dec_pos = RecoVertex::convertPos(ksref->vertex());
506 
507  GlobalError decayVertexError = GlobalError(ksref->vertexCovariance(0,0), ksref->vertexCovariance(0,1), ksref->vertexCovariance(1,1), ksref->vertexCovariance(0,2), ksref->vertexCovariance(1,2), ksref->vertexCovariance(2,2));
508 
509  math::XYZVector dec_mom(ksref->momentum().x(),
510  ksref->momentum().y(),
511  ksref->momentum().z());
512 
513  GlobalPoint bsPosition = RecoVertex::convertPos(bsH->position());
515 
516  double kaon_significance = (distanceComputer.distance(VertexState(bsPosition,bsError), VertexState(dec_pos, decayVertexError))).significance();
517 
518  if ((ksref->vertex().rho()>=3.) &&
519  (ksref->vertexNormalizedChi2()<=3.) &&
520  (fabs(ksref->mass() - kMass)<=0.01) &&
521  (kaon_significance>15.) &&
522  (PF_PU_AssoMapAlgos::dR(ksref->vertex(),dec_mom,bsH)<=0.3) ){
523 
524  cleanedKaonColl->push_back(*ksref);
525 
526  }
527 
528  }
529 
530  return cleanedKaonColl;
531 }
532 
533 /*************************************************************************************/
534 /* function to filter the Lambda collection */
535 /*************************************************************************************/
536 
537 unique_ptr<VertexCompositeCandidateCollection>
539 {
540 
541  unique_ptr<VertexCompositeCandidateCollection> cleanedLambdaColl(new VertexCompositeCandidateCollection() );
542 
543  for (unsigned int lambdacoll_idx=0; lambdacoll_idx<LambdasH->size(); lambdacoll_idx++){
544 
545  VertexCompositeCandidateRef lambdaref(LambdasH,lambdacoll_idx);
546 
547  if(!cleanedColl){
548  cleanedLambdaColl->push_back(*lambdaref);
549  continue;
550  }
551 
552  VertexDistance3D distanceComputer;
553 
554  GlobalPoint dec_pos = RecoVertex::convertPos(lambdaref->vertex());
555 
556  GlobalError decayVertexError = GlobalError(lambdaref->vertexCovariance(0,0), lambdaref->vertexCovariance(0,1), lambdaref->vertexCovariance(1,1), lambdaref->vertexCovariance(0,2), lambdaref->vertexCovariance(1,2), lambdaref->vertexCovariance(2,2));
557 
558  math::XYZVector dec_mom(lambdaref->momentum().x(),
559  lambdaref->momentum().y(),
560  lambdaref->momentum().z());
561 
562  GlobalPoint bsPosition = RecoVertex::convertPos(bsH->position());
564 
565  double lambda_significance = (distanceComputer.distance(VertexState(bsPosition,bsError), VertexState(dec_pos, decayVertexError))).significance();
566 
567  if ((lambdaref->vertex().rho()>=3.) &&
568  (lambdaref->vertexNormalizedChi2()<=3.) &&
569  (fabs(lambdaref->mass() - lamMass)<=0.005) &&
570  (lambda_significance>15.) &&
571  (PF_PU_AssoMapAlgos::dR(lambdaref->vertex(),dec_mom,bsH)<=0.3) ){
572 
573  cleanedLambdaColl->push_back(*lambdaref);
574 
575  }
576 
577  }
578 
579  return cleanedLambdaColl;
580 }
581 
582 /*************************************************************************************/
583 /* function to find out if the track comes from a V0 decay */
584 /*************************************************************************************/
585 
586 bool
588 {
589 
590  //the part for the reassociation of particles from Kshort decays
591  for(VertexCompositeCandidateCollection::const_iterator iKS=cleanedKshort.begin(); iKS!=cleanedKshort.end(); iKS++){
592 
593  const RecoChargedCandidate *dauCand1 = dynamic_cast<const RecoChargedCandidate*>(iKS->daughter(0));
594  TrackRef dauTk1 = dauCand1->track();
595  const RecoChargedCandidate *dauCand2 = dynamic_cast<const RecoChargedCandidate*>(iKS->daughter(1));
596  TrackRef dauTk2 = dauCand2->track();
597 
598  if((trackref==dauTk1) || (trackref==dauTk2)){
599 
600  *V0 = *iKS;
601  return true;
602 
603  }
604 
605  }
606 
607  //the part for the reassociation of particles from Lambda decays
608  for(VertexCompositeCandidateCollection::const_iterator iLambda=cleanedLambda.begin(); iLambda!=cleanedLambda.end(); iLambda++){
609 
610  const RecoChargedCandidate *dauCand1 = dynamic_cast<const RecoChargedCandidate*>(iLambda->daughter(0));
611  TrackRef dauTk1 = dauCand1->track();
612  const RecoChargedCandidate *dauCand2 = dynamic_cast<const RecoChargedCandidate*>(iLambda->daughter(1));
613  TrackRef dauTk2 = dauCand2->track();
614 
615  if((trackref==dauTk1) || (trackref==dauTk2)){
616 
617  *V0 = *iLambda;
618  return true;
619 
620  }
621 
622  }
623 
624  return false;
625 }
626 
627 
628 /*************************************************************************************/
629 /* function to find the closest vertex in z for a track from a V0 */
630 /*************************************************************************************/
631 
632 VertexRef
634  const EventSetup& iSetup, Handle<BeamSpot> bsH, const std::vector<reco::VertexRef>& vtxcollV, double tWeight)
635 {
636 
637  const math::XYZPoint& dec_pos = V0_vtx.vertex();
638 
639  math::XYZVector dec_mom(V0_vtx.momentum().x(),
640  V0_vtx.momentum().y(),
641  V0_vtx.momentum().z());
642 
643  Track V0(trackref->chi2(), trackref->ndof(), dec_pos, dec_mom, 0, trackref->covariance());
644 
645  TransientTrack transV0(V0, &(*bFieldH) );
646  transV0.setBeamSpot(*bsH);
647  transV0.setES(iSetup);
648 
649  return FindClosest3D(transV0, vtxcollV, tWeight);
650 
651 }
652 
653 
654 /*************************************************************************************/
655 /* function to filter the nuclear interaction collection */
656 /*************************************************************************************/
657 
658 unique_ptr<PFDisplacedVertexCollection>
660 {
661 
662  unique_ptr<PFDisplacedVertexCollection> cleanedNIColl(new PFDisplacedVertexCollection() );
663 
664  for (PFDisplacedVertexCollection::const_iterator niref=NuclIntH->begin(); niref!=NuclIntH->end(); niref++){
665 
666 
667  if( (niref->isFake()) || !(niref->isNucl()) ) continue;
668 
669  if(!cleanedColl){
670  cleanedNIColl->push_back(*niref);
671  continue;
672  }
673 
674  VertexDistance3D distanceComputer;
675 
676  GlobalPoint ni_pos = RecoVertex::convertPos(niref->position());
677  GlobalError interactionVertexError = RecoVertex::convertError(niref->error());
678 
679  math::XYZVector ni_mom(niref->primaryMomentum().x(),
680  niref->primaryMomentum().y(),
681  niref->primaryMomentum().z());
682 
683  GlobalPoint bsPosition = RecoVertex::convertPos(bsH->position());
685 
686  double nuclint_significance = (distanceComputer.distance(VertexState(bsPosition,bsError), VertexState(ni_pos, interactionVertexError))).significance();
687 
688  if ((niref->position().rho()>=3.) &&
689  (nuclint_significance>15.) &&
690  (PF_PU_AssoMapAlgos::dR(niref->position(),ni_mom,bsH)<=0.3) ){
691 
692  cleanedNIColl->push_back(*niref);
693 
694  }
695 
696  }
697 
698  return cleanedNIColl;
699 }
700 
701 /*************************************************************************************/
702 /* function to find out if the track comes from a nuclear interaction */
703 /*************************************************************************************/
704 
705 bool
707 {
708 
709  //the part for the reassociation of particles from nuclear interactions
710  for(PFDisplacedVertexCollection::const_iterator iDisplV=cleanedNI.begin(); iDisplV!=cleanedNI.end(); iDisplV++){
711 
712  if(iDisplV->trackWeight(trackref)>1.e-5){
713 
714  *displVtx = *iDisplV;
715  return true;
716 
717  }
718 
719  }
720 
721  return false;
722 }
723 
724 
725 /*************************************************************************************/
726 /* function to find the closest vertex in z for a track from a nuclear interaction */
727 /*************************************************************************************/
728 
729 VertexRef
731  const EventSetup& iSetup, Handle<BeamSpot> bsH, const std::vector<reco::VertexRef>& vtxcollV, double tWeight)
732 {
733 
734  TrackCollection refittedTracks = displVtx.refittedTracks();
735 
736  if((displVtx.isTherePrimaryTracks()) || (displVtx.isThereMergedTracks())){
737 
738  for(TrackCollection::const_iterator trkcoll_ite=refittedTracks.begin(); trkcoll_ite!=refittedTracks.end(); trkcoll_ite++){
739 
740  const TrackBaseRef retrackbaseref = displVtx.originalTrack(*trkcoll_ite);
741 
742  if(displVtx.isIncomingTrack(retrackbaseref)){
743 
744  VertexRef VOAssociation = TrackWeightAssociation(retrackbaseref, vtxcollV);
745 
746  if( VOAssociation->trackWeight(retrackbaseref) >= 1.e-5 ){
747  return VOAssociation;
748  }
749 
750  TransientTrack transIncom(*retrackbaseref, &(*bFieldH) );
751  transIncom.setBeamSpot(*bsH);
752  transIncom.setES(iSetup);
753 
754  return FindClosest3D(transIncom, vtxcollV, tWeight);
755 
756  }
757 
758  }
759 
760  }
761 
762  const math::XYZPoint& ni_pos = displVtx.position();
763 
764  math::XYZVector ni_mom(displVtx.primaryMomentum().x(),
765  displVtx.primaryMomentum().y(),
766  displVtx.primaryMomentum().z());
767 
768  Track incom(trackref->chi2(), trackref->ndof(), ni_pos, ni_mom, 0, trackref->covariance());
769 
770  TransientTrack transIncom(incom, &(*bFieldH) );
771  transIncom.setBeamSpot(*bsH);
772  transIncom.setES(iSetup);
773 
774  return FindClosest3D(transIncom, vtxcollV, tWeight);
775 
776 }
777 
778 /*************************************************************************************/
779 /* function to find the vertex with the highest TrackWeight for a certain track */
780 /*************************************************************************************/
781 template<typename TREF>
782 VertexRef
783 PF_PU_AssoMapAlgos::TrackWeightAssociation(const TREF& trackRef, const std::vector<reco::VertexRef>& vtxcollV)
784 {
785 
786  VertexRef bestvertexref = vtxcollV.at(0);
787  float bestweight = 0.;
788 
789  //loop over all vertices in the vertex collection
790  for(auto const& vertexref : vtxcollV){
791 
792  //get the most probable vertex for the track
793  float weight = vertexref->trackWeight(trackRef);
794  if(weight>bestweight){
795  bestweight = weight;
796  bestvertexref = vertexref;
797  }
798 
799  }
800 
801  return bestvertexref;
802 
803 }
804 
805 /*************************************************************************************/
806 /* find an association for a certain track */
807 /*************************************************************************************/
808 
810 PF_PU_AssoMapAlgos::FindAssociation(const reco::TrackRef& trackref, const std::vector<reco::VertexRef>& vtxColl,
811  edm::ESHandle<MagneticField> bfH, const edm::EventSetup& iSetup, edm::Handle<reco::BeamSpot> bsH, int assocNum)
812 {
813 
814  VertexRef foundVertex;
815 
816  //if it is not the first try of an association jump to the final association
817  //to avoid multiple (secondary) associations and/or unphysical (primary and secondary) associations
818  if ( assocNum>0 ) goto finalStep;
819 
820  // Step 1: First round of association:
821  // Find the vertex with the highest track-to-vertex association weight
822  foundVertex = TrackWeightAssociation(trackref, vtxColl);
823 
824  if ( foundVertex->trackWeight(trackref) >= 1.e-5 ){
825  return make_pair( foundVertex, 0. );
826  }
827 
828  // Step 2: Reassociation
829  // Second round of association:
830  // In case no vertex with track-to-vertex association weight > 1.e-5 is found,
831  // check the track originates from a neutral hadron decay, photon conversion or nuclear interaction
832 
833  if ( input_doReassociation_ ) {
834 
835  // Test if the track comes from a photon conversion:
836  // If so, try to find the vertex of the mother particle
838  if ( ComesFromConversion(trackref, *cleanedConvCollP, &gamma) ){
839  foundVertex = FindConversionVertex(trackref, gamma, bfH, iSetup, bsH, vtxColl, input_nTrack_);
840  return make_pair( foundVertex, 1. );
841  }
842 
843  // Test if the track comes from a Kshort or Lambda decay:
844  // If so, reassociate the track to the vertex of the V0
846  if ( ComesFromV0Decay(trackref, *cleanedKshortCollP, *cleanedLambdaCollP, &V0) ) {
847  foundVertex = FindV0Vertex(trackref, V0, bfH, iSetup, bsH, vtxColl, input_nTrack_);
848  return make_pair( foundVertex, 1. );
849  }
850 
851  if ( !missingColls ) {
852 
853  // Test if the track comes from a nuclear interaction:
854  // If so, reassociate the track to the vertex of the incoming particle
855  PFDisplacedVertex displVtx;
856  if ( ComesFromNI(trackref, *cleanedNICollP, &displVtx) ){
857  foundVertex = FindNIVertex(trackref, displVtx, bfH, iSetup, bsH, vtxColl, input_nTrack_);
858  return make_pair( foundVertex, 1. );
859  }
860 
861  }
862 
863  }
864 
865  // Step 3: Final association
866  // If no vertex is found with track-to-vertex association weight > 1.e-5
867  // and no reassociation was done do the final association
868  // look for the closest vertex in 3D or in z/longitudinal distance
869  // or associate the track always to the first vertex (default)
870 
871  finalStep:
872 
873  switch (input_FinalAssociation_) {
874 
875  case 1:{
876 
877  // closest in z
878  foundVertex = FindClosestZ(trackref,vtxColl,input_nTrack_);
879  break;
880 
881 
882  }
883 
884  case 2:{
885 
886  // closest in 3D
887  TransientTrack transtrk(trackref, &(*bfH) );
888  transtrk.setBeamSpot(*bsH);
889  transtrk.setES(iSetup);
890 
891  foundVertex = FindClosest3D(transtrk,vtxColl,input_nTrack_);
892  break;
893 
894  }
895 
896  default:{
897 
898  // allways first vertex
899  foundVertex = vtxColl.at(0);
900  break;
901 
902  }
903 
904  }
905 
906  return make_pair( foundVertex, 2. );
907 
908 }
909 
910 /*************************************************************************************/
911 /* get the quality for a certain association */
912 /*************************************************************************************/
913 
914 int
916 {
917 
918  int quality = 0;
919 
920  switch (step) {
921 
922  case 0:{
923 
924  //TrackWeight association
925  if ( distance <= tw_90 ) {
926  quality = 5;
927  } else {
928  if ( distance <= tw_70 ) {
929  quality = 4;
930  } else {
931  if ( distance <= tw_50 ) {
932  quality = 3;
933  } else {
934  quality = 2;
935  }
936  }
937  }
938  break;
939 
940  }
941 
942  case 1:{
943 
944  //Secondary association
945  if ( distance <= sec_70 ) {
946  quality = 4;
947  } else {
948  if ( distance <= sec_50 ) {
949  quality = 3;
950  } else {
951  quality = 2;
952  }
953  }
954  break;
955 
956  }
957 
958  case 2:{
959 
960  //Final association
961  if ( assoc_ite == 1 ) {
962  quality = 1;
963  } else {
964  if ( assoc_ite >= 2 ) {
965  quality = 0;
966  } else {
967  if ( distance <= fin_70 ) {
968  quality = 4;
969  } else {
970  if ( distance <= fin_50 ) {
971  quality = 3;
972  } else {
973  quality = 2;
974  }
975  }
976  }
977  }
978  break;
979 
980  }
981 
982  default:{
983 
984  quality = -1;
985  break;
986  }
987 
988  }
989 
990  return quality;
991 
992 }
const reco::Vertex & conversionVertex() const
returns the reco conversion vertex
Definition: Conversion.h:98
edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > LambdaCollectionToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
reco::Vertex::Point convertPos(const GlobalPoint &p)
T getParameter(std::string const &) const
static std::unique_ptr< reco::VertexCompositeCandidateCollection > GetCleanedLambda(edm::Handle< reco::VertexCompositeCandidateCollection >, edm::Handle< reco::BeamSpot >, bool)
double z0() const
z coordinate
Definition: BeamSpot.h:68
T getUntrackedParameter(std::string const &, T const &) const
std::vector< PFDisplacedVertex > PFDisplacedVertexCollection
collection of PFDisplacedVertex objects
static bool matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch=true, bool allowAmbiguousGsfMatch=false)
std::vector< TrackQualityPair > TrackQualityPairVector
edm::ESHandle< MagneticField > bFieldH
edm::EDGetTokenT< reco::BeamSpot > token_BeamSpot_
const unsigned int nTracks(const reco::Vertex &sv)
const double lamMass
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
static std::unique_ptr< reco::PFDisplacedVertexCollection > GetCleanedNI(edm::Handle< reco::PFDisplacedVertexCollection >, edm::Handle< reco::BeamSpot >, bool)
std::unique_ptr< TrackToVertexAssMap > SortAssociationMap(TrackToVertexAssMap *, edm::Handle< reco::TrackCollection >)
Covariance3DMatrix covariance3D() const
return only 3D position covariance matrix
Definition: BeamSpot.h:118
const bool isTherePrimaryTracks() const
--—— Provide useful information --—— ///
const_iterator end() const
last iterator over the map (read only)
void setBeamSpot(const reco::BeamSpot &beamSpot)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const double kMass
TrackBaseRef originalTrack(const Track &refTrack) const
Definition: Vertex.cc:108
static bool ComesFromNI(const reco::TrackRef, const reco::PFDisplacedVertexCollection &, reco::PFDisplacedVertex *)
static reco::VertexRef FindV0Vertex(const reco::TrackRef, const reco::VertexCompositeCandidate &, edm::ESHandle< MagneticField >, const edm::EventSetup &, edm::Handle< reco::BeamSpot >, const std::vector< reco::VertexRef > &, double)
static std::unique_ptr< reco::VertexCompositeCandidateCollection > GetCleanedKshort(edm::Handle< reco::VertexCompositeCandidateCollection >, edm::Handle< reco::BeamSpot >, bool)
int DefineQuality(int, int, double)
static reco::VertexRef TrackWeightAssociation(const TREF &, const std::vector< reco::VertexRef > &)
reco::Vertex::Error convertError(const GlobalError &ge)
Definition: ConvertError.h:8
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:37
const double tw_70
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
const double fin_70
const bool isIncomingTrack(const reco::TrackBaseRef &originalTrack) const
Is primary or merged track.
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Definition: weight.py:1
key_type key() const
Accessor for product key.
Definition: Ref.h:263
const std::vector< Track > & refittedTracks() const
Returns the container of refitted tracks.
Definition: Vertex.h:164
std::unique_ptr< TrackToVertexAssMap > CreateTrackToVertexMap(edm::Handle< reco::TrackCollection >, const edm::EventSetup &)
std::unique_ptr< reco::PFDisplacedVertexCollection > cleanedNICollP
std::unique_ptr< reco::VertexCompositeCandidateCollection > cleanedLambdaCollP
const Point & position() const
position
Definition: Vertex.h:109
std::pair< reco::VertexRef, int > VertexStepPair
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
U second(std::pair< T, U > const &p)
VertexStepPair FindAssociation(const reco::TrackRef &, const std::vector< reco::VertexRef > &, edm::ESHandle< MagneticField >, const edm::EventSetup &, edm::Handle< reco::BeamSpot >, int)
Vector momentum() const final
spatial momentum vector
std::vector< VertexPtsumPair > VertexPtsumVector
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
int iEvent
Definition: GenABIO.cc:224
static std::unique_ptr< reco::ConversionCollection > GetCleanedConversions(edm::Handle< reco::ConversionCollection >, edm::Handle< reco::BeamSpot >, bool)
T sqrt(T t)
Definition: SSEVec.h:18
const Point & vertex() const override
vertex position (overwritten by PF...)
PF_PU_AssoMapAlgos(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
edm::Handle< reco::PFDisplacedVertexCollection > displVertexCollH
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
virtual void GetInputCollections(edm::Event &, const edm::EventSetup &)
reco::TrackRef track() const override
reference to a track
std::pair< std::unique_ptr< TrackToVertexAssMap >, std::unique_ptr< VertexToTrackAssMap > > createMappings(edm::Handle< reco::TrackCollection > trkcollH, const edm::EventSetup &iSetup)
static bool ComesFromV0Decay(const reco::TrackRef, const reco::VertexCompositeCandidateCollection &, const reco::VertexCompositeCandidateCollection &, reco::VertexCompositeCandidate *)
edm::AssociationMap< edm::OneToManyWithQuality< reco::VertexCollection, reco::TrackCollection, int > > TrackToVertexAssMap
static reco::VertexRef FindConversionVertex(const reco::TrackRef, const reco::Conversion &, edm::ESHandle< MagneticField >, const edm::EventSetup &, edm::Handle< reco::BeamSpot >, const std::vector< reco::VertexRef > &, double)
static double dR(const math::XYZPoint &, const math::XYZVector &, edm::Handle< reco::BeamSpot >)
edm::EDGetTokenT< reco::PFDisplacedVertexCollection > NIVertexCollectionToken_
void setES(const edm::EventSetup &es)
edm::Handle< reco::VertexCollection > vtxcollH
math::XYZTLorentzVectorF refittedPair4Momentum() const
Conversion track pair 4-momentum from the tracks refitted with vertex constraint. ...
Definition: Conversion.cc:235
const double sec_50
static reco::VertexRef FindClosest3D(reco::TransientTrack, const std::vector< reco::VertexRef > &, double tWeight=0.)
std::vector< reco::VertexRef > CreateVertexVector(edm::Handle< reco::VertexCollection >)
Block of elements.
std::unique_ptr< VertexToTrackAssMap > CreateVertexToTrackMap(edm::Handle< reco::TrackCollection >, const edm::EventSetup &)
edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > KshortCollectionToken_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const math::XYZTLorentzVector primaryMomentum(std::string massHypo="PI", bool useRefitted=true, double mass=0.0) const
Momentum of primary or merged track calculated with a mass hypothesis.
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:21
edm::EDGetTokenT< reco::ConversionCollection > ConversionsCollectionToken_
edm::Handle< reco::VertexCompositeCandidateCollection > vertCompCandCollLambdaH
edm::EDGetTokenT< reco::VertexCollection > token_VertexCollection_
std::unique_ptr< reco::VertexCompositeCandidateCollection > cleanedKshortCollP
void EraseVertex(std::vector< reco::VertexRef > &, reco::VertexRef)
significance
Definition: met_cff.py:19
fixed size matrix
HLT enums.
const double tw_50
const double sec_70
T get() const
Definition: EventSetup.h:71
static bool ComesFromConversion(const reco::TrackRef, const reco::ConversionCollection &, reco::Conversion *)
double y0() const
y coordinate
Definition: BeamSpot.h:66
const Point & position() const
position
Definition: BeamSpot.h:62
step
Definition: StallMonitor.cc:94
edm::Handle< reco::BeamSpot > beamspotH
const_iterator begin() const
first iterator over the map (read only)
edm::Handle< reco::ConversionCollection > convCollH
const bool isThereMergedTracks() const
If a merged track was identified.
static reco::VertexRef FindClosestZ(const reco::TrackRef, const std::vector< reco::VertexRef > &, double tWeight=0.)
edm::AssociationMap< edm::OneToManyWithQuality< reco::TrackCollection, reco::VertexCollection, int > > VertexToTrackAssMap
const double tw_90
def move(src, dest)
Definition: eostools.py:511
edm::Handle< reco::VertexCompositeCandidateCollection > vertCompCandCollKshortH
static reco::VertexRef FindNIVertex(const reco::TrackRef, const reco::PFDisplacedVertex &, edm::ESHandle< MagneticField >, const edm::EventSetup &, edm::Handle< reco::BeamSpot >, const std::vector< reco::VertexRef > &, double)
double x0() const
x coordinate
Definition: BeamSpot.h:64
const double fin_50
std::unique_ptr< reco::ConversionCollection > cleanedConvCollP