CMS 3D CMS Logo

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

◆ RefCountedLinearizedTrackState

Definition at line 31 of file TrimmedVertexFinder.h.

◆ RefCountedVertexTrack

Definition at line 30 of file TrimmedVertexFinder.h.

Constructor & Destructor Documentation

◆ TrimmedVertexFinder() [1/2]

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()), theEstimator(ve->clone()), theMinProb(0.05) {}
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() [2/2]

TrimmedVertexFinder::TrimmedVertexFinder ( const TrimmedVertexFinder other)

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

Definition at line 14 of file TrimmedVertexFinder.cc.

15  : theFitter(other.theFitter->clone()),
16  theUpdator(other.theUpdator->clone()),
17  theEstimator(other.theEstimator->clone()),
18  theMinProb(other.theMinProb) {}
VertexUpdator< 5 > * theUpdator
VertexTrackCompatibilityEstimator< 5 > * theEstimator
VertexFitter< 5 > * theFitter

◆ ~TrimmedVertexFinder()

TrimmedVertexFinder::~TrimmedVertexFinder ( )

Definition at line 20 of file TrimmedVertexFinder.cc.

References theEstimator, theFitter, and theUpdator.

20  {
21  delete theFitter;
22  delete theUpdator;
23  delete theEstimator;
24 }
VertexUpdator< 5 > * theUpdator
VertexTrackCompatibilityEstimator< 5 > * theEstimator
VertexFitter< 5 > * theFitter

Member Function Documentation

◆ clone()

TrimmedVertexFinder* TrimmedVertexFinder::clone ( void  ) const
inline

clone method

Definition at line 65 of file TrimmedVertexFinder.h.

References TrimmedVertexFinder().

65 { return new TrimmedVertexFinder(*this); }
TrimmedVertexFinder(const VertexFitter< 5 > *vf, const VertexUpdator< 5 > *vu, const VertexTrackCompatibilityEstimator< 5 > *ve)

◆ setTrackCompatibilityCut()

void TrimmedVertexFinder::setTrackCompatibilityCut ( float  cut)
inline

Set parameter

Definition at line 61 of file TrimmedVertexFinder.h.

References DMR_cfg::cut, and theMinProb.

Referenced by ConfigurableTrimmedVertexFinder::vertexCandidates().

◆ theWorst()

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

Definition at line 131 of file TrimmedVertexFinder.cc.

References nano_mu_local_reco_cff::chi2, ChiSquaredProbability(), VertexTrackCompatibilityEstimator< N >::estimate(), CachingVertex< N >::isValid(), TtFullHadEvtBuilder_cfi::prob, VertexUpdator< N >::remove(), mps_fire::result, theEstimator, theUpdator, and L1BJetProducer_cff::vtx.

Referenced by vertices().

132  {
133  // cout << "Cut is now " << cut << endl;
134 
135  // find track with worst compatibility
136  std::vector<RefCountedVertexTrack>::iterator iWorst = vtxTracks.end();
137  float worseChi2 = 0.;
138  for (std::vector<RefCountedVertexTrack>::iterator itr = vtxTracks.begin(); itr != vtxTracks.end(); itr++) {
139  CachingVertex<5> newV = theUpdator->remove(vtx, *itr);
140  if (!newV.isValid())
141  return itr;
142  std::pair<bool, double> result = theEstimator->estimate(newV, *itr);
143  if (!result.first)
144  return itr;
145  float chi2 = result.second;
146 
147  // compute number of degrees of freedom
148  if (chi2 > 0.) {
149  // we want to keep negative chi squares, and avoid calling
150  // ChiSquaredProbability with a negative chi2.
151  int ndf = 2;
152  if (vtx.tracks().size() == 2)
153  ndf = 1;
154 
155  float prob = ChiSquaredProbability(chi2, ndf);
156  if (prob < cut && chi2 >= worseChi2) {
157  // small inconsistency: sorting on chi2, not on chi2 probability
158  // because large chi2 are not rounded off while small probabilities
159  // are rounded off to 0....
160  // should not matter since at a given iteration
161  // all track chi2 increments have the same ndf
162  iWorst = itr;
163  worseChi2 = chi2;
164  }
165  }
166  }
167 
168  return iWorst;
169 }
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
VertexTrackCompatibilityEstimator< 5 > * theEstimator
float ChiSquaredProbability(double chiSquared, double nrDOF)
bool isValid() const

◆ trackCompatibilityCut()

float TrimmedVertexFinder::trackCompatibilityCut ( ) const
inline

Access to parameter

Definition at line 57 of file TrimmedVertexFinder.h.

References theMinProb.

57 { return theMinProb; }

◆ vertices() [1/2]

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 26 of file TrimmedVertexFinder.cc.

Referenced by ConfigurableTrimmedVertexFinder::vertexCandidates().

26  {
27  // FIXME write this!!!
28  return vertices(tks, reco::BeamSpot(), false);
29 }
std::vector< TransientVertex > vertices(std::vector< reco::TransientTrack > &remain) const

◆ vertices() [2/2]

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 31 of file TrimmedVertexFinder.cc.

References python.cmstools::all(), Exception, newFWLiteAna::found, mps_fire::i, submitPVValidationJobs::t, theFitter, theMinProb, theWorst(), PerigeeLinearizedTrackState::track(), VertexFitter< N >::vertex(), and L1BJetProducer_cff::vtx.

33  {
34  std::vector<TransientVertex> all;
35  if (tks.size() < 2)
36  return all;
37 
38  // prepare vertex tracks and initial vertex
40  if (use_spot) {
41  vtx = theFitter->vertex(tks, spot);
42  } else {
43  vtx = theFitter->vertex(tks);
44  }
45  if (!vtx.isValid()) {
46  edm::LogWarning("TrimmedVertexFinder") << "initial vertex invalid."
47  << " vertex finding stops here.";
48  return all;
49  }
50 
51  std::vector<RefCountedVertexTrack> selected = vtx.tracks();
52 
53  // reject incompatible tracks starting from the worst
54  std::vector<RefCountedVertexTrack> remain;
55  bool found = false;
56  while (!found && selected.size() >= 2) {
57  // find track with worst compatibility
58  std::vector<RefCountedVertexTrack>::iterator iWorst = theWorst(vtx, selected, theMinProb);
59 
60  if (iWorst != selected.end()) {
61  // reject track
62  remain.push_back(*iWorst);
63  selected.erase(iWorst);
64 
65  if (selected.size() == 1) {
66  // not enough tracks to build new vertices
67  remain.push_back(selected.front());
68  } else {
69  // removing track from vertex
70  // need to redo the vertex fit instead of removing the track;
71  // successive removals lead to numerical problems
72  // this is however quick since intermediate quantities are cached
73  // in the RefCountedVertexTracks
74  if (use_spot) // && all.size()==0 )
75  {
76  vtx = theFitter->vertex(selected, spot);
77  } else {
78  vtx = theFitter->vertex(selected);
79  }
80  if (!vtx.isValid()) {
81  edm::LogWarning("TrimmedVertexFinder") << "current vertex invalid"
82  << "vertex finding stops here.";
83  return all;
84  }
85 
86  // ref-counted tracks may have changed during the fit
87  // if the linearization point has moved too much
88  selected = vtx.tracks();
89  }
90 
91  } else {
92  // no incompatible track remains, make vertex
93  found = true;
94  int n_tracks_in_vertex = selected.size();
95 
96  // now return all tracks with weight < 0.5 to 'remain'.
97  for (std::vector<RefCountedVertexTrack>::const_iterator t = selected.begin(); t != selected.end(); ++t) {
98  if ((**t).weight() < 0.5) {
99  /*
100  cout << "[TrimmedVertexFinder] recycling track with weight "
101  << (**t).weight() << endl;*/
102  remain.push_back(*t);
103  n_tracks_in_vertex--; // one 'good' track less in the vertex
104  };
105  };
106 
107  if (n_tracks_in_vertex > 1) {
108  all.push_back(vtx);
109  } else {
110  edm::LogError("TrimmedVertexFinder") << "found vertex has less than 2 tracks";
111  }
112  }
113  }
114 
115  // modify list of incompatible tracks
116  tks.clear();
117  for (std::vector<RefCountedVertexTrack>::const_iterator i = remain.begin(); i != remain.end(); i++) {
118  const PerigeeLinearizedTrackState* plts =
119  dynamic_cast<const PerigeeLinearizedTrackState*>((**i).linearizedTrack().get());
120  if (plts == nullptr) {
121  throw cms::Exception("TrimmedVertexFinder: can't take track from non-perigee track state");
122  }
123 
124  tks.push_back(plts->track());
125  }
126 
127  // return 0 or 1 vertex
128  return all;
129 }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
Log< level::Error, false > LogError
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
reco::TransientTrack track() const override
VertexFitter< 5 > * theFitter
Log< level::Warning, false > LogWarning

Member Data Documentation

◆ theEstimator

VertexTrackCompatibilityEstimator<5>* TrimmedVertexFinder::theEstimator
private

Definition at line 77 of file TrimmedVertexFinder.h.

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

◆ theFitter

VertexFitter<5>* TrimmedVertexFinder::theFitter
private

Definition at line 75 of file TrimmedVertexFinder.h.

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

◆ theMinProb

float TrimmedVertexFinder::theMinProb
private

Definition at line 78 of file TrimmedVertexFinder.h.

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

◆ theUpdator

VertexUpdator<5>* TrimmedVertexFinder::theUpdator
private

Definition at line 76 of file TrimmedVertexFinder.h.

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