CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VertexMerging.cc
Go to the documentation of this file.
2 
3 
5  maxFraction(params.getParameter<double>("maxFraction")),
6  minSignificance(params.getParameter<double>("minSignificance"))
7 {
8 
9 }
10 
11 static double computeSharedTracks(const reco::Vertex &pv,
12  const reco::Vertex &sv)
13 {
14  std::set<reco::TrackRef> pvTracks;
15  for(std::vector<reco::TrackBaseRef>::const_iterator iter = pv.tracks_begin();
16  iter != pv.tracks_end(); iter++) {
17  if (pv.trackWeight(*iter) >= 0.5)
18  pvTracks.insert(iter->castTo<reco::TrackRef>());
19  }
20 
21  unsigned int count = 0, total = 0;
22  for(std::vector<reco::TrackBaseRef>::const_iterator iter = sv.tracks_begin();
23  iter != sv.tracks_end(); iter++) {
24  if (sv.trackWeight(*iter) >= 0.5) {
25  total++;
26  count += pvTracks.count(iter->castTo<reco::TrackRef>());
27  }
28  }
29 
30  return (double)count / (double)total;
31 }
32 
33 
34 
35 
36 
38  reco::VertexCollection & secondaryVertices){
39 
40 
41 
42 
43  VertexDistance3D dist;
44  reco::VertexCollection recoVertices;
45  for(std::vector<reco::Vertex>::const_iterator sv = secondaryVertices.begin();
46  sv != secondaryVertices.end(); ++sv) {
47  recoVertices.push_back(*sv);
48  }
49  for(std::vector<reco::Vertex>::iterator sv = recoVertices.begin();
50  sv != recoVertices.end(); ++sv) {
51 
52  bool shared=false;
53  for(std::vector<reco::Vertex>::iterator sv2 = recoVertices.begin();
54  sv2 != recoVertices.end(); ++sv2) {
55  double fr=computeSharedTracks(*sv2, *sv);
56  // std::cout << sv2-recoVertices->begin() << " vs " << sv-recoVertices->begin() << " : " << fr << " " << computeSharedTracks(*sv, *sv2) << " sig " << dist.distance(*sv,*sv2).significance() << std::endl;
57  // std::cout << (fr > maxFraction) << " && " << (dist.distance(*sv,*sv2).significance() < 2) << " && " << (sv-sv2!=0) << " && " << (fr >= computeSharedTracks(*sv2, *sv)) << std::endl;
58  if (fr > maxFraction && dist.distance(*sv,*sv2).significance() < minSignificance && sv-sv2!=0
59  && fr >= computeSharedTracks(*sv, *sv2) )
60  {
61  shared=true;
62  // std::cout << "shared " << sv-recoVertices->begin() << " and " << sv2-recoVertices->begin() << " fractions: " << fr << " , " << computeSharedTracks(*sv2, *sv) << " sig: " << dist.distance(*sv,*sv2).significance() << std::endl;
63 
64  }
65 
66 
67  }
68  if(shared) { sv=recoVertices.erase(sv)-1; }
69  // std::cout << "it = " << sv-recoVertices->begin() << " new size is: " << recoVertices->size() << std::endl;
70  }
71 
72  return recoVertices;
73 
74 
75 }
76 
virtual Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
double minSignificance
Definition: VertexMerging.h:29
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
reco::VertexCollection mergeVertex(reco::VertexCollection &secondaryVertices)
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
Definition: Vertex.h:74
double significance() const
Definition: Measurement1D.h:32
double maxFraction
Definition: VertexMerging.h:28
VertexMerging(const edm::ParameterSet &params)
Definition: VertexMerging.cc:4
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:39
static double computeSharedTracks(const reco::Vertex &pv, const reco::Vertex &sv)