CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
GsfVertexUpdator Class Reference

#include <GsfVertexUpdator.h>

Inheritance diagram for GsfVertexUpdator:
VertexUpdator< 5 >

Public Types

typedef VertexTrack< 5 >::RefCountedLinearizedTrackState RefCountedLinearizedTrackState
 
typedef CachingVertex< 5 >::RefCountedVertexTrack RefCountedVertexTrack
 
- Public Types inherited from VertexUpdator< 5 >
typedef CachingVertex< N >::RefCountedVertexTrack RefCountedVertexTrack
 

Public Member Functions

CachingVertex< 5 > add (const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override
 
VertexUpdator< 5 > * clone () const override
 
 GsfVertexUpdator (bool limit=false, const GsfVertexMerger *merger=nullptr)
 
CachingVertex< 5 > remove (const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override
 
- Public Member Functions inherited from VertexUpdator< 5 >
virtual CachingVertex< Nadd (const CachingVertex< N > &v, const typename CachingVertex< N >::RefCountedVertexTrack t) const=0
 
virtual CachingVertex< Nremove (const CachingVertex< N > &v, const typename CachingVertex< N >::RefCountedVertexTrack t) const=0
 
 VertexUpdator ()
 
virtual ~VertexUpdator ()
 

Private Types

typedef std::vector< RefCountedLinearizedTrackStateLTC
 
typedef std::pair< VertexState, double > VertexChi2Pair
 
typedef std::pair< VertexState, WeightChi2PairVertexComponent
 
typedef std::vector< VertexStateVSC
 
typedef std::pair< double, double > WeightChi2Pair
 

Private Member Functions

VertexChi2Pair assembleVertexComponents (const std::vector< VertexComponent > &newVertexComponents) const
 
VertexComponent createNewComponent (const VertexState &oldVertex, const RefCountedLinearizedTrackState linTrack, float weight, int sign) const
 

Private Attributes

KalmanVertexUpdator< 5 > kalmanVertexUpdator
 
bool limitComponents
 
DeepCopyPointerByClone< GsfVertexMergertheMerger
 
GsfVertexWeightCalculator theWeightCalculator
 

Detailed Description

Vertex updator for the Gaussian Sum vertex filter. (c.f. Th.Speer & R. Fruewirth, Comp.Phys.Comm 174, 935 (2006) )

Definition at line 14 of file GsfVertexUpdator.h.

Member Typedef Documentation

◆ LTC

Definition at line 42 of file GsfVertexUpdator.h.

◆ RefCountedLinearizedTrackState

Definition at line 17 of file GsfVertexUpdator.h.

◆ RefCountedVertexTrack

Definition at line 16 of file GsfVertexUpdator.h.

◆ VertexChi2Pair

typedef std::pair<VertexState, double> GsfVertexUpdator::VertexChi2Pair
private

Definition at line 45 of file GsfVertexUpdator.h.

◆ VertexComponent

Definition at line 44 of file GsfVertexUpdator.h.

◆ VSC

typedef std::vector<VertexState> GsfVertexUpdator::VSC
private

Definition at line 41 of file GsfVertexUpdator.h.

◆ WeightChi2Pair

typedef std::pair<double, double> GsfVertexUpdator::WeightChi2Pair
private

Definition at line 43 of file GsfVertexUpdator.h.

Constructor & Destructor Documentation

◆ GsfVertexUpdator()

GsfVertexUpdator::GsfVertexUpdator ( bool  limit = false,
const GsfVertexMerger merger = nullptr 
)

Definition at line 6 of file GsfVertexUpdator.cc.

References GsfVertexMerger::clone(), limitComponents, and theMerger.

Referenced by clone().

7  if (limitComponents)
8  theMerger = merger->clone();
9 }
GsfVertexMerger * clone() const
DeepCopyPointerByClone< GsfVertexMerger > theMerger

Member Function Documentation

◆ add()

CachingVertex< 5 > GsfVertexUpdator::add ( const CachingVertex< 5 > &  oldVertex,
const RefCountedVertexTrack  track 
) const
override

Method to add a track to an existing CachingVertex An invalid vertex is returned in case of problems during the update.

Definition at line 11 of file GsfVertexUpdator.cc.

References KalmanVertexUpdator< N >::add(), assembleVertexComponents(), nano_mu_local_reco_cff::chi2, VertexState::components(), createNewComponent(), CachingVertex< N >::hasPrior(), kalmanVertexUpdator, limitComponents, GsfVertexMerger::merge(), CachingVertex< N >::priorError(), CachingVertex< N >::priorPosition(), theMerger, CachingVertex< N >::totalChiSquared(), HLT_2024v14_cff::track, CachingVertex< N >::tracks(), trackWeight(), CachingVertex< N >::vertexState(), VertexState::weight(), and VertexState::weightTimesPosition().

Referenced by counter.Counter::register(), and GsfVertexSmoother::smooth().

11  {
12  VSC prevVtxComponents = oldVertex.vertexState().components();
13 
14  // cout << "GsfVertexUpdator::Add new Track with "
15  // << track->linearizedTrack()->components().size() << " components to vertex of "
16  // << prevVtxComponents.size() << " components.\n";
17 
18  if (prevVtxComponents.empty()) {
19  throw VertexException("GsfVertexUpdator::(Previous) Vertex to update has no components");
20  }
21 
22  LTC ltComponents = track->linearizedTrack()->components();
23  if (ltComponents.empty()) {
24  throw VertexException("GsfVertexUpdator::Track to add to vertex has no components");
25  }
26 
27  if ((ltComponents.size() == 1) && (prevVtxComponents.size() == 1))
28  return kalmanVertexUpdator.add(oldVertex, track);
29 
30  float trackWeight = track->weight();
31 
32  std::vector<VertexComponent> newVertexComponents;
33  newVertexComponents.reserve(prevVtxComponents.size() * ltComponents.size());
34 
35  // for (LTC::iterator trackCompIter = ltComponents.begin();
36  // trackCompIter != ltComponents.end(); trackCompIter++ ) {
37  // cout <<(**trackCompIter).state().globalPosition()<<endl;
38  // }
39 
40  for (VSC::iterator vertexCompIter = prevVtxComponents.begin(); vertexCompIter != prevVtxComponents.end();
41  vertexCompIter++) {
42  for (LTC::iterator trackCompIter = ltComponents.begin(); trackCompIter != ltComponents.end(); trackCompIter++) {
43  newVertexComponents.push_back(createNewComponent(*vertexCompIter, *trackCompIter, trackWeight, +1));
44  // return invalid vertex in case one of the updated vertex-components is invalid
45  if (!newVertexComponents.back().first.isValid())
46  return CachingVertex<5>();
47  }
48  }
49  // cout << "updator components: "<<newVertexComponents.size()<<endl;
50 
51  // Update tracks vector
52 
53  std::vector<RefCountedVertexTrack> newVertexTracks = oldVertex.tracks();
54  newVertexTracks.push_back(track);
55  // cout << "a \n ";
56 
57  // Assemble VertexStates and compute Chi**2
58 
59  VertexChi2Pair vertexChi2Pair = assembleVertexComponents(newVertexComponents);
60  // cout << "b \n ";
61  VertexState newVertexState = vertexChi2Pair.first;
62  // cout << "c \n ";
63  double chi2 = oldVertex.totalChiSquared() + vertexChi2Pair.second;
64 
65  // Merge:
66  if (limitComponents)
67  newVertexState = theMerger->merge(newVertexState);
68 
69  if (oldVertex.hasPrior()) {
70  return CachingVertex<5>(oldVertex.priorPosition(),
71  oldVertex.priorError(),
72  newVertexState.weightTimesPosition(),
73  newVertexState.weight(),
74  newVertexTracks,
75  chi2);
76  } else {
77  return CachingVertex<5>(newVertexState, newVertexTracks, chi2);
78  }
79 }
CachingVertex< 5 > merge(const CachingVertex< 5 > &vertex) const
GlobalPoint priorPosition() const
VertexComponent createNewComponent(const VertexState &oldVertex, const RefCountedLinearizedTrackState linTrack, float weight, int sign) const
Common base class.
std::vector< VertexState > VSC
VertexChi2Pair assembleVertexComponents(const std::vector< VertexComponent > &newVertexComponents) const
VertexState const & vertexState() const
GlobalError priorError() const
KalmanVertexUpdator< 5 > kalmanVertexUpdator
float totalChiSquared() const
std::vector< RefCountedVertexTrack > tracks() const
GlobalWeight weight() const
Definition: VertexState.h:69
std::vector< VertexState > components() const
Definition: VertexState.h:90
AlgebraicVector3 weightTimesPosition() const
Definition: VertexState.h:77
bool hasPrior() const
DeepCopyPointerByClone< GsfVertexMerger > theMerger
CachingVertex< N > add(const CachingVertex< N > &oldVertex, const RefCountedVertexTrack track) const override
std::pair< VertexState, double > VertexChi2Pair
std::vector< RefCountedLinearizedTrackState > LTC
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)

◆ assembleVertexComponents()

GsfVertexUpdator::VertexChi2Pair GsfVertexUpdator::assembleVertexComponents ( const std::vector< VertexComponent > &  newVertexComponents) const
private

Definition at line 121 of file GsfVertexUpdator.cc.

References generateEDF::totalWeight, and mps_merge::weight.

Referenced by add().

122  {
123  VSC vertexComponents;
124  vertexComponents.reserve(newVertexComponents.size());
125 
126  //renormalize weights
127  // cout << "assemble "<<newVertexComponents.size()<<endl;
128  double totalWeight = 0.;
129  double totalChi2 = 0.;
130 
131  for (std::vector<VertexComponent>::const_iterator iter = newVertexComponents.begin();
132  iter != newVertexComponents.end();
133  iter++) {
134  totalWeight += iter->second.first;
135  }
136  // cout << "totalWeight "<<totalWeight<<endl;
137  if (totalWeight < DBL_MIN) {
138  edm::LogWarning("GsfVertexUpdator") << "Updated Vertex has total weight of 0. "
139  << "The track is probably very far away.";
140  return VertexChi2Pair(VertexState(), 0.);
141  }
142 
143  for (std::vector<VertexComponent>::const_iterator iter = newVertexComponents.begin();
144  iter != newVertexComponents.end();
145  iter++) {
146  double weight = iter->second.first / totalWeight;
147  if (iter->second.first > DBL_MIN) {
148  vertexComponents.push_back(VertexState(iter->first.weightTimesPosition(), iter->first.weight(), weight));
149  totalChi2 += iter->second.second * weight;
150  }
151  }
152  // cout << "totalChi2 "<<totalChi2<<endl;
153  // cout << "vertexComponents "<<vertexComponents.size()<<endl;
154 
155  if (vertexComponents.empty()) {
156  edm::LogWarning("GsfVertexUpdator") << "No Vertex State left after reweighting.";
157  return VertexChi2Pair(VertexState(), 0.);
158  }
159 
160  return VertexChi2Pair(VertexState(new BasicMultiVertexState(vertexComponents)), totalChi2);
161 }
std::vector< VertexState > VSC
Definition: weight.py:1
std::pair< VertexState, double > VertexChi2Pair
Log< level::Warning, false > LogWarning

◆ clone()

VertexUpdator<5>* GsfVertexUpdator::clone ( void  ) const
inlineoverridevirtual

Clone method

Implements VertexUpdator< 5 >.

Definition at line 38 of file GsfVertexUpdator.h.

References GsfVertexUpdator().

38 { return new GsfVertexUpdator(*this); }
GsfVertexUpdator(bool limit=false, const GsfVertexMerger *merger=nullptr)

◆ createNewComponent()

GsfVertexUpdator::VertexComponent GsfVertexUpdator::createNewComponent ( const VertexState oldVertex,
const RefCountedLinearizedTrackState  linTrack,
float  weight,
int  sign 
) const
private

Where one component of the previous vertex gets updated with one component of the track.

Definition at line 91 of file GsfVertexUpdator.cc.

References funct::abs(), GsfVertexWeightCalculator::calculate(), KalmanVertexUpdator< N >::chi2Increment(), VertexState::isValid(), kalmanVertexUpdator, KalmanVertexUpdator< N >::positionUpdate(), Validation_hcalonly_cfi::sign, and theWeightCalculator.

Referenced by add().

94  {
95  if (abs(sign) != 1)
96  throw VertexException("GsfVertexUpdator::sign not equal to 1.");
97 
98  if (sign == -1)
99  throw VertexException("GsfVertexUpdator::sign of -1 not yet implemented.");
100 
101  // Weight of the component in the mixture (non-normalized)
102  double weightInMixture = theWeightCalculator.calculate(oldVertex, linTrack, 1.E9);
103  if (weightInMixture < 0.)
104  return VertexComponent(VertexState(), WeightChi2Pair(0., 0.));
105 
106  // position estimate of the component
107  VertexState newVertex = kalmanVertexUpdator.positionUpdate(oldVertex, linTrack, weight, sign);
108  if (!newVertex.isValid())
109  return VertexComponent(newVertex, WeightChi2Pair(0., 0.));
110 
111  //Chi**2 contribution of the component
112  std::pair<bool, double> chi2P = kalmanVertexUpdator.chi2Increment(oldVertex, newVertex, linTrack, weight);
113  if (!chi2P.first)
114  return VertexComponent(VertexState(), WeightChi2Pair(0., 0.));
115  // cout << "Update: "<<oldVertex.position()<<" "<<newVertex.position()<<" "<<chi2
116  // <<" "<<linTrack->weightInMixture()<<" "<<weightInMixture<<endl;
117 
118  return VertexComponent(newVertex, WeightChi2Pair(weightInMixture, chi2P.second));
119 }
double calculate(const VertexState &oldVertex, const RefCountedLinearizedTrackState track, double cov) const
GsfVertexWeightCalculator theWeightCalculator
Common base class.
VertexState positionUpdate(const VertexState &oldVertex, const RefCountedLinearizedTrackState linearizedTrack, const float weight, int sign) const
bool isValid() const
Make the ReferenceCountingProxy method to check validity public.
Definition: VertexState.h:93
Definition: weight.py:1
KalmanVertexUpdator< 5 > kalmanVertexUpdator
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< bool, double > chi2Increment(const VertexState &oldVertex, const VertexState &newVertexState, const RefCountedLinearizedTrackState linearizedTrack, float weight) const
std::pair< double, double > WeightChi2Pair
std::pair< VertexState, WeightChi2Pair > VertexComponent

◆ remove()

CachingVertex< 5 > GsfVertexUpdator::remove ( const CachingVertex< 5 > &  oldVertex,
const RefCountedVertexTrack  track 
) const
override

Method removing already used VertexTrack from existing CachingVertex This method is not yet implemented.

Definition at line 81 of file GsfVertexUpdator.cc.

81  {
82  throw VertexException("GsfVertexUpdator::Remove Methode not yet done");
83  // return CachingVertex<5>();
84 }
Common base class.

Member Data Documentation

◆ kalmanVertexUpdator

KalmanVertexUpdator<5> GsfVertexUpdator::kalmanVertexUpdator
private

Definition at line 56 of file GsfVertexUpdator.h.

Referenced by add(), and createNewComponent().

◆ limitComponents

bool GsfVertexUpdator::limitComponents
private

Definition at line 54 of file GsfVertexUpdator.h.

Referenced by add(), and GsfVertexUpdator().

◆ theMerger

DeepCopyPointerByClone<GsfVertexMerger> GsfVertexUpdator::theMerger
private

Definition at line 55 of file GsfVertexUpdator.h.

Referenced by add(), and GsfVertexUpdator().

◆ theWeightCalculator

GsfVertexWeightCalculator GsfVertexUpdator::theWeightCalculator
private

Definition at line 57 of file GsfVertexUpdator.h.

Referenced by createNewComponent().