CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
104 GsfVertexUpdator::createNewComponent(const VertexState & oldVertex,
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
VertexTrack< 5 >::RefCountedLinearizedTrackState RefCountedLinearizedTrackState
CachingVertex< 5 > merge(const CachingVertex< 5 > &vertex) const
GsfVertexWeightCalculator theWeightCalculator
Common base class.
std::vector< VertexState > VSC
VertexState const & vertexState() const
Definition: CachingVertex.h:85
GsfVertexMerger * clone() const
KalmanVertexUpdator< 5 > kalmanVertexUpdator
GlobalError priorError() const
Definition: CachingVertex.h:94
CachingVertex< 5 >::RefCountedVertexTrack RefCountedVertexTrack
std::vector< RefCountedVertexTrack > const & tracks() const
Definition: CachingVertex.h:91
GsfVertexUpdator(bool limit=false, const GsfVertexMerger *merger=0)
float totalChiSquared() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool hasPrior() const
Definition: CachingVertex.h:95
double calculate(const VertexState &oldVertex, const RefCountedLinearizedTrackState track, double cov) const
CachingVertex< 5 > remove(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const
VertexState positionUpdate(const VertexState &oldVertex, const RefCountedLinearizedTrackState linearizedTrack, const float weight, int sign) const
VertexChi2Pair assembleVertexComponents(const std::vector< VertexComponent > &newVertexComponents) const
CachingVertex< 5 > add(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const
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< N > add(const CachingVertex< N > &oldVertex, const RefCountedVertexTrack track) const
int weight
Definition: histoStyle.py:50
std::vector< RefCountedLinearizedTrackState > LTC
GlobalPoint priorPosition() const
Definition: CachingVertex.h:93
std::pair< VertexState, WeightChi2Pair > VertexComponent