CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
TrimmedVertexFinder Class Reference

#include <TrimmedVertexFinder.h>

Public Types

typedef
ReferenceCountingPointer
< LinearizedTrackState< 5 > > 
RefCountedLinearizedTrackState
 
typedef
ReferenceCountingPointer
< VertexTrack< 5 > > 
RefCountedVertexTrack
 

Public Member Functions

TrimmedVertexFinderclone () const
 
void setTrackCompatibilityCut (float cut)
 
float trackCompatibilityCut () const
 
 TrimmedVertexFinder (const VertexFitter< 5 > *vf, const VertexUpdator< 5 > *vu, const VertexTrackCompatibilityEstimator< 5 > *ve)
 
 TrimmedVertexFinder (const TrimmedVertexFinder &other)
 
std::vector< TransientVertexvertices (std::vector< reco::TransientTrack > &remain) const
 
std::vector< TransientVertexvertices (std::vector< reco::TransientTrack > &remain, const reco::BeamSpot &s, bool use_beamspot=true) const
 
 ~TrimmedVertexFinder ()
 

Private Member Functions

std::vector
< RefCountedVertexTrack >
::iterator 
theWorst (const CachingVertex< 5 > &vtx, std::vector< RefCountedVertexTrack > &vtxTracks, float cut) const
 

Private Attributes

VertexTrackCompatibilityEstimator< 5 > * theEstimator
 
VertexFitter< 5 > * theFitter
 
float theMinProb
 
VertexUpdator< 5 > * theUpdator
 

Detailed Description

Algorithm to find 0 or 1 cluster of tracks that are compatible with a single vertex, among remain, the initial set of tracks. A track is declared incompatible with the vertex if the chi-squared probability between the track and the vertex is smaller than min. The algorithm applied is:
1) fit a single vertex with all tracks;
2) remove incompatible tracks 1 by 1 starting from the least compatible one.
On output, remain contains the incompatible tracks. This algorithm has 1 parameter that can be set at runtime via the corresponding set() method:

Definition at line 28 of file TrimmedVertexFinder.h.

Member Typedef Documentation

Definition at line 33 of file TrimmedVertexFinder.h.

Definition at line 32 of file TrimmedVertexFinder.h.

Constructor & Destructor Documentation

TrimmedVertexFinder::TrimmedVertexFinder ( const VertexFitter< 5 > *  vf,
const VertexUpdator< 5 > *  vu,
const VertexTrackCompatibilityEstimator< 5 > *  ve 
)

Definition at line 9 of file TrimmedVertexFinder.cc.

Referenced by clone().

12  : theFitter(vf->clone()), theUpdator(vu->clone()),
13  theEstimator(ve->clone()), theMinProb(0.05)
14 {}
virtual VertexFitter * clone() const =0
virtual VertexTrackCompatibilityEstimator< N > * clone() const =0
VertexUpdator< 5 > * theUpdator
VertexTrackCompatibilityEstimator< 5 > * theEstimator
virtual VertexUpdator * clone() const =0
VertexFitter< 5 > * theFitter
TrimmedVertexFinder::TrimmedVertexFinder ( const TrimmedVertexFinder other)

Copy constructor, needed to handle copy of pointer data members correctly

Definition at line 17 of file TrimmedVertexFinder.cc.

19  : theFitter(other.theFitter->clone()),
20  theUpdator(other.theUpdator->clone()),
21  theEstimator(other.theEstimator->clone()),
22  theMinProb(other.theMinProb)
23 {}
virtual VertexFitter * clone() const =0
virtual VertexTrackCompatibilityEstimator< N > * clone() const =0
VertexUpdator< 5 > * theUpdator
VertexTrackCompatibilityEstimator< 5 > * theEstimator
virtual VertexUpdator * clone() const =0
VertexFitter< 5 > * theFitter
TrimmedVertexFinder::~TrimmedVertexFinder ( )

Definition at line 26 of file TrimmedVertexFinder.cc.

References theEstimator, theFitter, and theUpdator.

26  {
27  delete theFitter;
28  delete theUpdator;
29  delete theEstimator;
30 }
VertexUpdator< 5 > * theUpdator
VertexTrackCompatibilityEstimator< 5 > * theEstimator
VertexFitter< 5 > * theFitter

Member Function Documentation

TrimmedVertexFinder* TrimmedVertexFinder::clone ( void  ) const
inline

clone method

Definition at line 68 of file TrimmedVertexFinder.h.

References TrimmedVertexFinder().

68  {
69  return new TrimmedVertexFinder(*this);
70  }
TrimmedVertexFinder(const VertexFitter< 5 > *vf, const VertexUpdator< 5 > *vu, const VertexTrackCompatibilityEstimator< 5 > *ve)
void TrimmedVertexFinder::setTrackCompatibilityCut ( float  cut)
inline
std::vector< TrimmedVertexFinder::RefCountedVertexTrack >::iterator TrimmedVertexFinder::theWorst ( const CachingVertex< 5 > &  vtx,
std::vector< RefCountedVertexTrack > &  vtxTracks,
float  cut 
) const
private

Definition at line 153 of file TrimmedVertexFinder.cc.

References ChiSquaredProbability(), VertexTrackCompatibilityEstimator< N >::estimate(), CachingVertex< N >::isValid(), mix_2012_Summer_inTimeOnly_cff::prob, VertexUpdator< N >::remove(), query::result, theEstimator, theUpdator, and CachingVertex< N >::tracks().

Referenced by vertices().

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 }
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 BDpair estimate(const CachingVertex< N > &v, const RefCountedLinearizedTrackState track, unsigned int hint=UINT_MAX) const =0
VertexUpdator< 5 > * theUpdator
tuple result
Definition: query.py:137
VertexTrackCompatibilityEstimator< 5 > * theEstimator
float ChiSquaredProbability(double chiSquared, double nrDOF)
bool isValid() const
Definition: CachingVertex.h:96
float TrimmedVertexFinder::trackCompatibilityCut ( ) const
inline

Access to parameter

Definition at line 60 of file TrimmedVertexFinder.h.

References theMinProb.

60 { return theMinProb; }
std::vector< TransientVertex > TrimmedVertexFinder::vertices ( std::vector< reco::TransientTrack > &  remain) const

Make 0 or 1 vertex On output, remain contains the incompatible tracks

Definition at line 33 of file TrimmedVertexFinder.cc.

Referenced by ConfigurableTrimmedVertexFinder::vertexCandidates().

34 {
35  // FIXME write this!!!
36  return vertices ( tks, reco::BeamSpot(), false );
37 }
std::vector< TransientVertex > vertices(std::vector< reco::TransientTrack > &remain) const
std::vector< TransientVertex > TrimmedVertexFinder::vertices ( std::vector< reco::TransientTrack > &  remain,
const reco::BeamSpot s,
bool  use_beamspot = true 
) const

Same as above, only with the extra information of the beamspot constraint.

Definition at line 40 of file TrimmedVertexFinder.cc.

References cond::ecalcond::all, edm::hlt::Exception, newFWLiteAna::found, i, CachingVertex< N >::isValid(), edmStreamStallGrapher::t, theFitter, theMinProb, theWorst(), CachingVertex< N >::tracks(), and VertexFitter< N >::vertex().

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 }
int i
Definition: DBlmapReader.cc:9
std::vector< RefCountedVertexTrack > const & tracks() const
Definition: CachingVertex.h:91
virtual CachingVertex< N > vertex(const std::vector< reco::TransientTrack > &tracks) const =0
std::vector< RefCountedVertexTrack >::iterator theWorst(const CachingVertex< 5 > &vtx, std::vector< RefCountedVertexTrack > &vtxTracks, float cut) const
bool isValid() const
Definition: CachingVertex.h:96
VertexFitter< 5 > * theFitter

Member Data Documentation

VertexTrackCompatibilityEstimator<5>* TrimmedVertexFinder::theEstimator
private

Definition at line 85 of file TrimmedVertexFinder.h.

Referenced by theWorst(), and ~TrimmedVertexFinder().

VertexFitter<5>* TrimmedVertexFinder::theFitter
private

Definition at line 83 of file TrimmedVertexFinder.h.

Referenced by vertices(), and ~TrimmedVertexFinder().

float TrimmedVertexFinder::theMinProb
private

Definition at line 86 of file TrimmedVertexFinder.h.

Referenced by setTrackCompatibilityCut(), trackCompatibilityCut(), and vertices().

VertexUpdator<5>* TrimmedVertexFinder::theUpdator
private

Definition at line 84 of file TrimmedVertexFinder.h.

Referenced by theWorst(), and ~TrimmedVertexFinder().