CMS 3D CMS Logo

GsfVertexUpdator.cc
Go to the documentation of this file.
4 #include <cfloat>
5 
7  limitComponents (limit)
8 {
9  if (limitComponents) theMerger = merger->clone();
10 }
11 
12 
14  const RefCountedVertexTrack track) const
15 {
16 
17  VSC prevVtxComponents = oldVertex.vertexState().components();
18 
19 // cout << "GsfVertexUpdator::Add new Track with "
20 // << track->linearizedTrack()->components().size() << " components to vertex of "
21 // << prevVtxComponents.size() << " components.\n";
22 
23  if (prevVtxComponents.empty()) {
24  throw VertexException
25  ("GsfVertexUpdator::(Previous) Vertex to update has no components");
26  }
27 
28  LTC ltComponents = track->linearizedTrack()->components();
29  if (ltComponents.empty()) {
30  throw VertexException
31  ("GsfVertexUpdator::Track to add to vertex has no components");
32  }
33 
34  if ((ltComponents.size()==1) && (prevVtxComponents.size()==1))
35  return kalmanVertexUpdator.add(oldVertex, track);
36 
37  float trackWeight = track->weight();
38 
39  std::vector<VertexComponent> newVertexComponents;
40  newVertexComponents.reserve(prevVtxComponents.size()*ltComponents.size());
41 
42 // for (LTC::iterator trackCompIter = ltComponents.begin();
43 // trackCompIter != ltComponents.end(); trackCompIter++ ) {
44 // cout <<(**trackCompIter).state().globalPosition()<<endl;
45 // }
46 
47  for (VSC::iterator vertexCompIter = prevVtxComponents.begin();
48  vertexCompIter != prevVtxComponents.end(); vertexCompIter++ ) {
49  for (LTC::iterator trackCompIter = ltComponents.begin();
50  trackCompIter != ltComponents.end(); trackCompIter++ ) {
51  newVertexComponents.push_back(
52  createNewComponent(*vertexCompIter, *trackCompIter, trackWeight, +1));
53  // return invalid vertex in case one of the updated vertex-components is invalid
54  if (!newVertexComponents.back().first.isValid()) return CachingVertex<5>();
55  }
56  }
57 // cout << "updator components: "<<newVertexComponents.size()<<endl;
58 
59  // Update tracks vector
60 
61  std::vector<RefCountedVertexTrack> newVertexTracks = oldVertex.tracks();
62  newVertexTracks.push_back(track);
63 // cout << "a \n ";
64 
65  // Assemble VertexStates and compute Chi**2
66 
67  VertexChi2Pair vertexChi2Pair = assembleVertexComponents(newVertexComponents);
68 // cout << "b \n ";
69  VertexState newVertexState = vertexChi2Pair.first;
70 // cout << "c \n ";
71  double chi2 = oldVertex.totalChiSquared() + vertexChi2Pair.second;
72 
73  // Merge:
74  if (limitComponents) newVertexState = theMerger->merge(newVertexState);
75 
76  if (oldVertex.hasPrior()) {
77  return CachingVertex<5>(oldVertex.priorPosition(), oldVertex.priorError(),
78  newVertexState.weightTimesPosition(),
79  newVertexState.weight(), newVertexTracks, chi2);
80  } else {
81  return CachingVertex<5>(newVertexState, newVertexTracks, chi2);
82  }
83 
84 
85 }
86 
87 
88 
89 
91  const RefCountedVertexTrack track) const
92 {
93  throw VertexException("GsfVertexUpdator::Remove Methode not yet done");
94 // return CachingVertex<5>();
95 }
96 
97 
105  const RefCountedLinearizedTrackState linTrack, float weight, int sign) const
106 {
107 
108  if(abs(sign) != 1)
109  throw VertexException ("GsfVertexUpdator::sign not equal to 1.");
110 
111  if(sign == -1)
112  throw VertexException("GsfVertexUpdator::sign of -1 not yet implemented.");
113 
114 
115  // Weight of the component in the mixture (non-normalized)
116  double weightInMixture = theWeightCalculator.calculate(oldVertex, linTrack, 1.E9);
117  if (weightInMixture < 0.) return VertexComponent(VertexState(), WeightChi2Pair(0.,0.));
118 
119  // position estimate of the component
120  VertexState newVertex = kalmanVertexUpdator.positionUpdate(oldVertex,
121  linTrack, weight, sign);
122  if (!newVertex.isValid()) return VertexComponent(newVertex, WeightChi2Pair(0.,0.));
123 
124  //Chi**2 contribution of the component
125  std::pair <bool, double> chi2P = kalmanVertexUpdator.chi2Increment(oldVertex, newVertex,
126  linTrack, weight);
127  if (!chi2P.first) return VertexComponent(VertexState(), WeightChi2Pair(0.,0.));
128 // cout << "Update: "<<oldVertex.position()<<" "<<newVertex.position()<<" "<<chi2
129 // <<" "<<linTrack->weightInMixture()<<" "<<weightInMixture<<endl;
130 
131  return VertexComponent(newVertex, WeightChi2Pair(weightInMixture, chi2P.second));
132 }
133 
135  const std::vector<GsfVertexUpdator::VertexComponent> & newVertexComponents) const
136 {
137  VSC vertexComponents;
138  vertexComponents.reserve(newVertexComponents.size());
139 
140  //renormalize weights
141 // cout << "assemble "<<newVertexComponents.size()<<endl;
142  double totalWeight = 0.;
143  double totalChi2 = 0.;
144 
145  for (std::vector<VertexComponent>::const_iterator iter = newVertexComponents.begin();
146  iter != newVertexComponents.end(); iter ++) {
147  totalWeight += iter->second.first;
148  }
149 // cout << "totalWeight "<<totalWeight<<endl;
150  if (totalWeight<DBL_MIN) {
151  edm::LogWarning("GsfVertexUpdator") << "Updated Vertex has total weight of 0. "
152  <<"The track is probably very far away.";
153  return VertexChi2Pair( VertexState(), 0.);
154  }
155 
156  for (std::vector<VertexComponent>::const_iterator iter = newVertexComponents.begin();
157  iter != newVertexComponents.end(); iter ++) {
158  double weight = iter->second.first/totalWeight;
159  if (iter->second.first>DBL_MIN) {
160  vertexComponents.push_back(VertexState(iter->first.weightTimesPosition(),
161  iter->first.weight(), weight));
162  totalChi2 += iter->second.second * weight;
163  }
164  }
165 // cout << "totalChi2 "<<totalChi2<<endl;
166 // cout << "vertexComponents "<<vertexComponents.size()<<endl;
167 
168  if (vertexComponents.empty()){
169  edm::LogWarning("GsfVertexUpdator") << "No Vertex State left after reweighting.";
170  return VertexChi2Pair( VertexState(), 0.);
171  }
172 
173  return VertexChi2Pair( VertexState( new BasicMultiVertexState( vertexComponents)),
174  totalChi2);
175 }
std::pair< bool, double > chi2Increment(const VertexState &oldVertex, const VertexState &newVertexState, const RefCountedLinearizedTrackState linearizedTrack, float weight) const
std::vector< RefCountedVertexTrack > tracks() const
CachingVertex< 5 > merge(const CachingVertex< 5 > &vertex) const
GsfVertexWeightCalculator theWeightCalculator
Common base class.
std::vector< VertexState > VSC
VertexState const & vertexState() const
CachingVertex< N > add(const CachingVertex< N > &oldVertex, const RefCountedVertexTrack track) const override
GsfVertexMerger * clone() const
Definition: weight.py:1
KalmanVertexUpdator< 5 > kalmanVertexUpdator
GlobalError priorError() const
CachingVertex< 5 >::RefCountedVertexTrack RefCountedVertexTrack
CachingVertex< 5 > remove(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override
AlgebraicVector3 weightTimesPosition() const
Definition: VertexState.h:103
GsfVertexUpdator(bool limit=false, const GsfVertexMerger *merger=0)
float totalChiSquared() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< VertexState > components() const
Definition: VertexState.h:125
bool hasPrior() const
double calculate(const VertexState &oldVertex, const RefCountedLinearizedTrackState track, double cov) const
GlobalWeight weight() const
Definition: VertexState.h:85
VertexState positionUpdate(const VertexState &oldVertex, const RefCountedLinearizedTrackState linearizedTrack, const float weight, int sign) const
VertexChi2Pair assembleVertexComponents(const std::vector< VertexComponent > &newVertexComponents) const
bool isValid() const
Make the ReferenceCountingProxy method to check validity public.
Definition: VertexState.h:131
DeepCopyPointerByClone< GsfVertexMerger > theMerger
VertexComponent createNewComponent(const VertexState &oldVertex, const RefCountedLinearizedTrackState linTrack, float weight, int sign) const
std::pair< VertexState, double > VertexChi2Pair
std::pair< double, double > WeightChi2Pair
CachingVertex< 5 > add(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override
std::vector< RefCountedLinearizedTrackState > LTC
GlobalPoint priorPosition() const
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)
std::pair< VertexState, WeightChi2Pair > VertexComponent