CMS 3D CMS Logo

GsfVertexSmoother.cc
Go to the documentation of this file.
5 
7  limitComponents (limit)
8 {
9  if (limitComponents) theMerger = merger->clone();
10 }
11 
14 {
15 
16  std::vector<RefCountedVertexTrack> tracks = vertex.tracks();
17  int numberOfTracks = tracks.size();
18  if (numberOfTracks<1) return vertex;
19 
20  // Initial vertex for ascending fit
21  GlobalPoint priorVertexPosition = tracks[0]->linearizedTrack()->linearizationPoint();
22  AlgebraicSymMatrix33 we = ROOT::Math::SMatrixIdentity();
23  GlobalError priorVertexError(we*10000);
24 
25  std::vector<RefCountedVertexTrack> initialTracks;
26  CachingVertex<5> fitVertex(priorVertexPosition,priorVertexError,initialTracks,0);
27  //In case prior vertex was used.
28  if (vertex.hasPrior()) {
29  const VertexState& priorVertexState = vertex.priorVertexState();
30  fitVertex = CachingVertex<5>(priorVertexState, priorVertexState,
31  initialTracks,0);
32  }
33 
34  // vertices from ascending fit
35  std::vector<CachingVertex<5> > ascendingFittedVertices;
36  ascendingFittedVertices.reserve(numberOfTracks);
37  ascendingFittedVertices.push_back(fitVertex);
38 
39  // ascending fit
40  for (std::vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
41  i != (tracks.end()-1); ++i) {
42  fitVertex = theUpdator.add(fitVertex,*i);
43  if (limitComponents) fitVertex = theMerger->merge(fitVertex);
44  ascendingFittedVertices.push_back(fitVertex);
45  }
46 
47  // Initial vertex for descending fit
48  priorVertexPosition = tracks[0]->linearizedTrack()->linearizationPoint();
49  priorVertexError = GlobalError(we*10000);
50  fitVertex = CachingVertex<5>(priorVertexPosition,priorVertexError,initialTracks,0);
51 
52  // vertices from descending fit
53  std::vector<CachingVertex<5> > descendingFittedVertices;
54  descendingFittedVertices.reserve(numberOfTracks);
55  descendingFittedVertices.push_back(fitVertex);
56 
57  // descending fit
58  for (std::vector<RefCountedVertexTrack>::const_iterator i = (tracks.end()-1);
59  i != (tracks.begin()); --i) {
60  fitVertex = theUpdator.add(fitVertex,*i);
61  if (limitComponents) fitVertex = theMerger->merge(fitVertex);
62  descendingFittedVertices.insert(descendingFittedVertices.begin(), fitVertex);
63  }
64 
65  std::vector<RefCountedVertexTrack> newTracks;
66  double smoothedChi2 = 0.; // Smoothed chi2
67 
68  // Track refit
69  for(std::vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
70  i != tracks.end();i++)
71  {
72  int indexNumber = i-tracks.begin();
73  //First, combine the vertices:
74  VertexState meanedVertex =
75  meanVertex(ascendingFittedVertices[indexNumber].vertexState(),
76  descendingFittedVertices[indexNumber].vertexState());
77  if (limitComponents) meanedVertex = theMerger->merge(meanedVertex);
78  // Add the vertex and smooth the track:
79  TrackChi2Pair thePair = vertexAndTrackUpdate(meanedVertex, *i, vertex.position());
80  smoothedChi2 += thePair.second.second;
81  newTracks.push_back( theVTFactory.vertexTrack((**i).linearizedTrack(),
82  vertex.vertexState(), thePair.first, thePair.second.second,
83  AlgebraicSymMatrixOO(), (**i).weight()) );
84  }
85 
86  if (vertex.hasPrior()) {
87  smoothedChi2 += priorVertexChi2(vertex.priorVertexState(), vertex.vertexState());
88  return CachingVertex<5>(vertex.priorVertexState(), vertex.vertexState(),
89  newTracks, smoothedChi2);
90  } else {
91  return CachingVertex<5>(vertex.vertexState(), newTracks, smoothedChi2);
92  }
93 }
94 
97  const RefCountedVertexTrack track, const GlobalPoint & referencePosition) const
98 {
99 
100  VSC prevVtxComponents = oldVertex.components();
101 
102  if (prevVtxComponents.empty()) {
103  throw VertexException
104  ("GsfVertexSmoother::(Previous) Vertex to update has no components");
105  }
106 
107  LTC ltComponents = track->linearizedTrack()->components();
108  if (ltComponents.empty()) {
109  throw VertexException
110  ("GsfVertexSmoother::Track to add to vertex has no components");
111  }
112  float trackWeight = track->weight();
113 
114  std::vector<RefittedTrackComponent> newTrackComponents;
115  newTrackComponents.reserve(prevVtxComponents.size()*ltComponents.size());
116 
117  for (VSC::iterator vertexCompIter = prevVtxComponents.begin();
118  vertexCompIter != prevVtxComponents.end(); vertexCompIter++ ) {
119 
120  for (LTC::iterator trackCompIter = ltComponents.begin();
121  trackCompIter != ltComponents.end(); trackCompIter++ ) {
122  newTrackComponents.push_back
123  (createNewComponent(*vertexCompIter, *trackCompIter, trackWeight));
124  }
125  }
126 
127  return assembleTrackComponents(newTrackComponents, referencePosition);
128 }
129 
136  const std::vector<GsfVertexSmoother::RefittedTrackComponent> & trackComponents,
137  const GlobalPoint & referencePosition)
138  const
139 {
140 
141  //renormalize weights
142 
143  double totalWeight = 0.;
144  double totalVtxChi2 = 0., totalTrkChi2 = 0.;
145 
146  for (std::vector<RefittedTrackComponent>::const_iterator iter = trackComponents.begin();
147  iter != trackComponents.end(); ++iter ) {
148  totalWeight += iter->first.second;
149  totalVtxChi2 += iter->second.first * iter->first.second ;
150  totalTrkChi2 += iter->second.second * iter->first.second ;
151  }
152 
153  totalVtxChi2 /= totalWeight ;
154  totalTrkChi2 /= totalWeight ;
155 
156  std::vector<RefCountedRefittedTrackState> reWeightedRTSC;
157  reWeightedRTSC.reserve(trackComponents.size());
158 
159 
160  for (std::vector<RefittedTrackComponent>::const_iterator iter = trackComponents.begin();
161  iter != trackComponents.end(); ++iter ) {
162  if (iter->second.first!=0) {
163  reWeightedRTSC.push_back(iter->first.first->stateWithNewWeight(iter->second.first/totalWeight));
164  }
165  }
166 
167  RefCountedRefittedTrackState finalRTS =
168  RefCountedRefittedTrackState(new MultiRefittedTS(reWeightedRTSC, referencePosition));
169  return TrackChi2Pair(finalRTS, VtxTrkChi2Pair(totalVtxChi2, totalTrkChi2));
170 }
171 
172 
180  const RefCountedLinearizedTrackState linTrack, float trackWeight) const
181 {
182 
183  int sign =+1;
184 
185  // Weight of the component in the mixture (non-normalized)
186  double weightInMixture = theWeightCalculator.calculate(oldVertex, linTrack, 1000000000.);
187 
188  // position estimate of the component
189  VertexState newVertex = kalmanVertexUpdator.positionUpdate(oldVertex,
190  linTrack, trackWeight, sign);
191 
193  theVertexTrackUpdator.trackRefit(newVertex, linTrack, trackWeight);
194 
195  //Chi**2 contribution of the track component
196  double vtxChi2 = helper.vertexChi2(oldVertex, newVertex);
197  std::pair<bool, double> trkCi2 = helper.trackParameterChi2(linTrack, thePair.first);
198 
199  return RefittedTrackComponent(TrackWeightPair(thePair.first, weightInMixture),
200  VtxTrkChi2Pair(vtxChi2, trkCi2.second));
201 }
202 
203 
206  const VertexState & vertexB) const
207 {
208  std::vector<VertexState> vsCompA = vertexA.components();
209  std::vector<VertexState> vsCompB = vertexB.components();
210  std::vector<VertexState> finalVS;
211  finalVS.reserve(vsCompA.size()*vsCompB.size());
212  for (std::vector<VertexState>::iterator iA = vsCompA.begin(); iA!= vsCompA.end(); ++iA)
213  {
214  for (std::vector<VertexState>::iterator iB = vsCompB.begin(); iB!= vsCompB.end(); ++iB)
215  {
216  AlgebraicSymMatrix33 newWeight = iA->weight().matrix() +
217  iB->weight().matrix();
218  AlgebraicVector3 newWtP = iA->weightTimesPosition() +
219  iB->weightTimesPosition();
220  double newWeightInMixture = iA->weightInMixture() *
221  iB->weightInMixture();
222  finalVS.push_back( VertexState(newWtP, newWeight, newWeightInMixture) );
223  }
224  }
225  #ifndef CMS_NO_COMPLEX_RETURNS
226  return VertexState(new BasicMultiVertexState(finalVS));
227  #else
228  VertexState theFinalVM(new BasicMultiVertexState(finalVS));
229  return theFinalVM;
230  #endif
231 }
232 
233 
235  const VertexState priorVertex, const VertexState fittedVertex) const
236 {
237  std::vector<VertexState> priorVertexComp = priorVertex.components();
238  std::vector<VertexState> fittedVertexComp = fittedVertex.components();
239  double vetexChi2 = 0.;
240  for (std::vector<VertexState>::iterator pvI = priorVertexComp.begin();
241  pvI!= priorVertexComp.end(); ++pvI)
242  {
243  for (std::vector<VertexState>::iterator fvI = fittedVertexComp.begin();
244  fvI!= fittedVertexComp.end(); ++fvI)
245  {
246  vetexChi2 += (pvI->weightInMixture())*(fvI->weightInMixture())*
247  helper.vertexChi2(*pvI, *fvI);
248  }
249  }
250  return vetexChi2;
251 }
VertexTrackFactory< 5 > theVTFactory
VertexTrack< 5 >::RefCountedRefittedTrackState RefCountedRefittedTrackState
std::vector< RefCountedLinearizedTrackState > LTC
std::vector< RefCountedVertexTrack > tracks() const
Definition: helper.py:1
TrackChi2Pair vertexAndTrackUpdate(const VertexState &oldVertex, const RefCountedVertexTrack track, const GlobalPoint &referencePosition) const
CachingVertex< 5 >::RefCountedVertexTrack RefCountedVertexTrack
CachingVertex< 5 > merge(const CachingVertex< 5 > &vertex) const
RefCountedVertexTrack vertexTrack(const RefCountedLinearizedTrackState lt, const VertexState vs, float weight=1.0) const
Common base class.
GsfVertexSmoother(bool limit, const GsfVertexMerger *merger)
VertexState const & vertexState() const
std::pair< double, double > VtxTrkChi2Pair
TrackChi2Pair assembleTrackComponents(const std::vector< RefittedTrackComponent > &trackComponents, const GlobalPoint &referencePosition) const
std::pair< RefCountedRefittedTrackState, double > TrackWeightPair
GsfVertexMerger * clone() const
GsfVertexUpdator theUpdator
GsfVertexWeightCalculator theWeightCalculator
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
KalmanVertexUpdator< 5 > kalmanVertexUpdator
std::pair< RefCountedRefittedTrackState, VtxTrkChi2Pair > TrackChi2Pair
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
ROOT::Math::SVector< double, 3 > AlgebraicVector3
std::vector< VertexState > components() const
Definition: VertexState.h:125
KalmanVertexTrackUpdator< 5 > theVertexTrackUpdator
bool hasPrior() const
VertexState meanVertex(const VertexState &vertexA, const VertexState &vertexB) const
double calculate(const VertexState &oldVertex, const RefCountedLinearizedTrackState track, double cov) const
std::vector< VertexState > VSC
RefittedTrackComponent createNewComponent(const VertexState &oldVertex, const RefCountedLinearizedTrackState linTrack, float weight) const
std::pair< TrackWeightPair, VtxTrkChi2Pair > RefittedTrackComponent
VertexState positionUpdate(const VertexState &oldVertex, const RefCountedLinearizedTrackState linearizedTrack, const float weight, int sign) const
CachingVertex< 5 > smooth(const CachingVertex< 5 > &vertex) const override
VertexState const & priorVertexState() const
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)
GlobalPoint position() const
DeepCopyPointerByClone< GsfVertexMerger > theMerger
double priorVertexChi2(const VertexState priorVertex, const VertexState fittedVertex) const
trackMatrixPair trackRefit(const VertexState &vertex, RefCountedLinearizedTrackState linTrackState, float weight) const
VertexTrack< 5 >::AlgebraicSymMatrixOO AlgebraicSymMatrixOO
CachingVertex< 5 > add(const CachingVertex< 5 > &oldVertex, const RefCountedVertexTrack track) const override