CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GsfVertexUpdator.cc
Go to the documentation of this file.
4 #include <cfloat>
5 
6 GsfVertexUpdator::GsfVertexUpdator(bool limit, const GsfVertexMerger* merger) : limitComponents(limit) {
7  if (limitComponents)
8  theMerger = merger->clone();
9 }
10 
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 }
80 
82  throw VertexException("GsfVertexUpdator::Remove Methode not yet done");
83  // return CachingVertex<5>();
84 }
85 
92  const RefCountedLinearizedTrackState linTrack,
93  float weight,
94  int sign) const {
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 }
120 
122  const std::vector<GsfVertexUpdator::VertexComponent>& newVertexComponents) const {
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::pair< bool, double > chi2Increment(const VertexState &oldVertex, const VertexState &newVertexState, const RefCountedLinearizedTrackState linearizedTrack, float weight) const
CachingVertex< 5 > add(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override
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
double sign(double x)
GsfVertexMerger * clone() const
CachingVertex< 5 > remove(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override
KalmanVertexUpdator< 5 > kalmanVertexUpdator
GlobalError priorError() const
CachingVertex< 5 >::RefCountedVertexTrack RefCountedVertexTrack
AlgebraicVector3 weightTimesPosition() const
Definition: VertexState.h:77
float totalChiSquared() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< VertexState > components() const
Definition: VertexState.h:90
bool hasPrior() const
double calculate(const VertexState &oldVertex, const RefCountedLinearizedTrackState track, double cov) const
GlobalWeight weight() const
Definition: VertexState.h:69
VertexState positionUpdate(const VertexState &oldVertex, const RefCountedLinearizedTrackState linearizedTrack, const float weight, int sign) const
VertexChi2Pair assembleVertexComponents(const std::vector< VertexComponent > &newVertexComponents) const
GsfVertexUpdator(bool limit=false, const GsfVertexMerger *merger=nullptr)
bool isValid() const
Make the ReferenceCountingProxy method to check validity public.
Definition: VertexState.h:93
DeepCopyPointerByClone< GsfVertexMerger > theMerger
VertexComponent createNewComponent(const VertexState &oldVertex, const RefCountedLinearizedTrackState linTrack, float weight, int sign) const
CachingVertex< N > add(const CachingVertex< N > &oldVertex, const RefCountedVertexTrack track) const override
std::pair< VertexState, double > VertexChi2Pair
std::pair< double, double > WeightChi2Pair
Log< level::Warning, false > LogWarning
int weight
Definition: histoStyle.py:51
std::vector< RefCountedLinearizedTrackState > LTC
GlobalPoint priorPosition() const
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)
std::pair< VertexState, WeightChi2Pair > VertexComponent