test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrimmedVertexFinder.cc
Go to the documentation of this file.
6 
7 using namespace reco;
8 
10  const VertexFitter<5> * vf, const VertexUpdator<5> * vu,
12  : theFitter(vf->clone()), theUpdator(vu->clone()),
13  theEstimator(ve->clone()), theMinProb(0.05)
14 {}
15 
16 
18 const TrimmedVertexFinder & other)
19  : theFitter(other.theFitter->clone()),
20  theUpdator(other.theUpdator->clone()),
21  theEstimator(other.theEstimator->clone()),
22  theMinProb(other.theMinProb)
23 {}
24 
25 
27  delete theFitter;
28  delete theUpdator;
29  delete theEstimator;
30 }
31 
32 std::vector<TransientVertex>
33 TrimmedVertexFinder::vertices(std::vector<TransientTrack> & tks ) const
34 {
35  // FIXME write this!!!
36  return vertices ( tks, reco::BeamSpot(), false );
37 }
38 
39 std::vector<TransientVertex>
40 TrimmedVertexFinder::vertices(std::vector<TransientTrack> & tks,
41  const reco::BeamSpot & spot, bool use_spot ) const
42 {
43  std::vector<TransientVertex> all;
44  if (tks.size() < 2) return all;
45 
46  // prepare vertex tracks and initial vertex
47  CachingVertex<5> vtx;
48  if ( use_spot )
49  {
50  vtx = theFitter->vertex(tks, spot );
51  } else {
52  vtx = theFitter->vertex(tks);
53  }
54  if (!vtx.isValid()) {
55  edm::LogWarning ( "TrimmedVertexFinder" ) << "initial vertex invalid."
56  << " vertex finding stops here.";
57  return all;
58  }
59 
60  std::vector<RefCountedVertexTrack> selected = vtx.tracks();
61 
62  // reject incompatible tracks starting from the worst
63  std::vector<RefCountedVertexTrack> remain;
64  bool found = false;
65  while (!found && selected.size() >= 2) {
66 
67  // find track with worst compatibility
68  std::vector<RefCountedVertexTrack>::iterator iWorst = theWorst(vtx,
69  selected,
70  theMinProb);
71 
72  if (iWorst != selected.end()) {
73  // reject track
74  remain.push_back(*iWorst);
75  selected.erase(iWorst);
76 
77  if (selected.size() == 1) {
78  // not enough tracks to build new vertices
79  remain.push_back(selected.front());
80  }
81  else {
82  // removing track from vertex
83  // need to redo the vertex fit instead of removing the track;
84  // successive removals lead to numerical problems
85  // this is however quick since intermediate quantities are cached
86  // in the RefCountedVertexTracks
87  if ( use_spot ) // && all.size()==0 )
88  {
89  vtx = theFitter->vertex(selected,spot);
90  } else {
91  vtx = theFitter->vertex(selected);
92  }
93  if (!vtx.isValid()) {
94  edm::LogWarning ( "TrimmedVertexFinder" ) << "current vertex invalid"
95  << "vertex finding stops here.";
96  return all;
97  }
98 
99  // ref-counted tracks may have changed during the fit
100  // if the linearization point has moved too much
101  selected = vtx.tracks();
102  }
103 
104  } else {
105  // no incompatible track remains, make vertex
106  found = true;
107  int n_tracks_in_vertex = selected.size();
108 
109  // now return all tracks with weight < 0.5 to 'remain'.
110  for ( std::vector< RefCountedVertexTrack >::const_iterator t=selected.begin();
111  t!=selected.end() ; ++t )
112  {
113  if ( (**t).weight() < 0.5 )
114  {
115  /*
116  cout << "[TrimmedVertexFinder] recycling track with weight "
117  << (**t).weight() << endl;*/
118  remain.push_back ( *t );
119  n_tracks_in_vertex--; // one 'good' track less in the vertex
120  };
121  };
122 
123  if ( n_tracks_in_vertex > 1 ) {
124  all.push_back(vtx);
125  }
126  else {
127  edm::LogError ( "TrimmedVertexFinder" )
128  << "found vertex has less than 2 tracks";
129  }
130  }
131  }
132 
133  // modify list of incompatible tracks
134  tks.clear();
135  for (std::vector<RefCountedVertexTrack>::const_iterator i = remain.begin();
136  i != remain.end(); i++) {
137  const PerigeeLinearizedTrackState* plts =
138  dynamic_cast<const PerigeeLinearizedTrackState*>
139  ((**i).linearizedTrack().get());
140  if (plts == 0) {
141  throw cms::Exception("TrimmedVertexFinder: can't take track from non-perigee track state");
142  }
143 
144  tks.push_back(plts->track());
145  }
146 
147  // return 0 or 1 vertex
148  return all;
149 }
150 
151 
152 std::vector<TrimmedVertexFinder::RefCountedVertexTrack>::iterator
154  std::vector<RefCountedVertexTrack> & vtxTracks, float cut) const
155 {
156 
157  // cout << "Cut is now " << cut << endl;
158 
159  // find track with worst compatibility
160  std::vector<RefCountedVertexTrack>::iterator iWorst = vtxTracks.end();
161  float worseChi2 = 0.;
162  for (std::vector<RefCountedVertexTrack>::iterator itr = vtxTracks.begin();
163  itr != vtxTracks.end(); itr++) {
164 
165  CachingVertex<5> newV = theUpdator->remove(vtx, *itr);
166  if (!newV.isValid()) return itr;
167  std::pair<bool, double> result = theEstimator->estimate(newV, *itr);
168  if (!result.first) return itr;
169  float chi2 = result.second;
170 
171  // compute number of degrees of freedom
172  if ( chi2 > 0. ) {
173  // we want to keep negative chi squares, and avoid calling
174  // ChiSquaredProbability with a negative chi2.
175  int ndf = 2;
176  if (vtx.tracks().size() == 2) ndf = 1;
177 
178  float prob = ChiSquaredProbability(chi2, ndf);
179  if (prob < cut && chi2 >= worseChi2) {
180  // small inconsistency: sorting on chi2, not on chi2 probability
181  // because large chi2 are not rounded off while small probabilities
182  // are rounded off to 0....
183  // should not matter since at a given iteration
184  // all track chi2 increments have the same ndf
185  iWorst = itr;
186  worseChi2 = chi2;
187  }
188  }
189  }
190 
191  return iWorst;
192 }
int i
Definition: DBlmapReader.cc:9
virtual reco::TransientTrack track() const
tuple result
Definition: mps_fire.py:84
std::vector< RefCountedVertexTrack > const & tracks() const
Definition: CachingVertex.h:91
virtual CachingVertex< N > remove(const CachingVertex< N > &v, const typename CachingVertex< N >::RefCountedVertexTrack t) const =0
virtual CachingVertex< N > vertex(const std::vector< reco::TransientTrack > &tracks) const =0
virtual BDpair estimate(const CachingVertex< N > &v, const RefCountedLinearizedTrackState track, unsigned int hint=UINT_MAX) const =0
VertexUpdator< 5 > * theUpdator
VertexTrackCompatibilityEstimator< 5 > * theEstimator
float ChiSquaredProbability(double chiSquared, double nrDOF)
std::vector< RefCountedVertexTrack >::iterator theWorst(const CachingVertex< 5 > &vtx, std::vector< RefCountedVertexTrack > &vtxTracks, float cut) const
std::vector< TransientVertex > vertices(std::vector< reco::TransientTrack > &remain) const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
bool isValid() const
Definition: CachingVertex.h:96
VertexFitter< 5 > * theFitter
TrimmedVertexFinder(const VertexFitter< 5 > *vf, const VertexUpdator< 5 > *vu, const VertexTrackCompatibilityEstimator< 5 > *ve)