CMS 3D CMS Logo

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