CMS 3D CMS Logo

CachingVertex.cc
Go to the documentation of this file.
6 #include <map>
7 
8 //to be removed
9 template <unsigned int N>
11  const GlobalError& posErr,
12  const std::vector<RefCountedVertexTrack>& tks,
13  float totalChiSq)
14  : theVertexState(pos, posErr),
15  theChiSquared(totalChiSq),
16  theNDF(0),
17  theNDFAvailable(false),
18  theTracks(tks),
19  theCovMapAvailable(false),
20  withPrior(false),
21  theValid(true),
22  vertexIs4D(false)
23 
24 {}
25 
26 //to be removed
27 template <unsigned int N>
29  const double time,
30  const GlobalError& posTimeErr,
31  const std::vector<RefCountedVertexTrack>& tks,
32  float totalChiSq)
33  : theVertexState(pos, time, posTimeErr),
34  theChiSquared(totalChiSq),
35  theNDF(0),
36  theNDFAvailable(false),
37  theTracks(tks),
38  theCovMapAvailable(false),
39  withPrior(false),
40  theValid(true),
41  vertexIs4D(true)
42 
43 {}
44 
45 //to be removed
46 template <unsigned int N>
48  const GlobalWeight& posWeight,
49  const std::vector<RefCountedVertexTrack>& tks,
50  float totalChiSq)
51  : theVertexState(pos, posWeight),
52  theChiSquared(totalChiSq),
53  theNDF(0),
54  theNDFAvailable(false),
55  theTracks(tks),
56  theCovMapAvailable(false),
57  withPrior(false),
58  theValid(true),
59  vertexIs4D(false) {}
60 
61 //to be removed
62 template <unsigned int N>
64  const double time,
65  const GlobalWeight& posTimeWeight,
66  const std::vector<RefCountedVertexTrack>& tks,
67  float totalChiSq)
68  : theVertexState(pos, time, posTimeWeight),
69  theChiSquared(totalChiSq),
70  theNDF(0),
71  theNDFAvailable(false),
72  theTracks(tks),
73  theCovMapAvailable(false),
74  withPrior(false),
75  theValid(true),
76  vertexIs4D(true) {}
77 
78 //to be removed
79 template <unsigned int N>
81  const GlobalWeight& posWeight,
82  const std::vector<RefCountedVertexTrack>& tks,
83  float totalChiSq)
84  : theVertexState(weightTimesPosition, posWeight),
85  theChiSquared(totalChiSq),
86  theNDF(0),
87  theNDFAvailable(false),
88  theTracks(tks),
89  theCovMapAvailable(false),
90  withPrior(false),
91  theValid(true),
92  vertexIs4D(false) {}
93 
94 //to be removed
95 template <unsigned int N>
97  const GlobalWeight& posWeight,
98  const std::vector<RefCountedVertexTrack>& tks,
99  float totalChiSq)
100  : theVertexState(weightTimesPosition, posWeight),
101  theChiSquared(totalChiSq),
102  theNDF(0),
103  theNDFAvailable(false),
104  theTracks(tks),
105  theCovMapAvailable(false),
106  withPrior(false),
107  theValid(true),
108  vertexIs4D(false) {}
109 
110 template <unsigned int N>
112  const std::vector<RefCountedVertexTrack>& tks,
113  float totalChiSq)
114  : theVertexState(aVertexState),
115  theChiSquared(totalChiSq),
116  theNDF(0),
117  theNDFAvailable(false),
118  theTracks(tks),
119  theCovMapAvailable(false),
120  withPrior(false),
121  theValid(true),
122  vertexIs4D(aVertexState.is4D()) {}
123 
124 template <unsigned int N>
126  const std::vector<RefCountedVertexTrack>& tks,
127  float totalChiSq,
128  const TrackToTrackMap& covMap)
129  : theVertexState(aVertexState),
130  theChiSquared(totalChiSq),
131  theNDF(0),
132  theNDFAvailable(false),
133  theTracks(tks),
134  theCovMap(covMap),
135  theCovMapAvailable(true),
136  withPrior(false),
137  theValid(true),
138  vertexIs4D(aVertexState.is4D()) {
139  if (theCovMap.empty())
140  theCovMapAvailable = false;
141 }
142 
143 template <unsigned int N>
145  const VertexState& aVertexState,
146  const std::vector<RefCountedVertexTrack>& tks,
147  float totalChiSq)
148  : theVertexState(aVertexState),
149  theChiSquared(totalChiSq),
150  theNDF(0),
151  theNDFAvailable(false),
152  theTracks(tks),
153  theCovMapAvailable(false),
154  thePriorVertexState(priorVertexState),
155  withPrior(true),
156  theValid(true),
157  vertexIs4D(priorVertexState.is4D() && aVertexState.is4D()) {}
158 
159 //to be removed
160 template <unsigned int N>
162  const GlobalError& priorErr,
163  const GlobalPoint& pos,
164  const GlobalError& posErr,
165  const std::vector<RefCountedVertexTrack>& tks,
166  float totalChiSq)
167  : theVertexState(pos, posErr),
168  theChiSquared(totalChiSq),
169  theNDF(0),
170  theNDFAvailable(false),
171  theTracks(tks),
172  theCovMapAvailable(false),
173  thePriorVertexState(priorPos, priorErr),
174  withPrior(true),
175  theValid(true),
176  vertexIs4D(false) {}
177 
178 //to be removed
179 template <unsigned int N>
181  const double priorTime,
182  const GlobalError& priorErr,
183  const GlobalPoint& pos,
184  const double time,
185  const GlobalError& posErr,
186  const std::vector<RefCountedVertexTrack>& tks,
187  float totalChiSq)
188  : theVertexState(pos, time, posErr),
189  theChiSquared(totalChiSq),
190  theNDF(0),
191  theNDFAvailable(false),
192  theTracks(tks),
193  theCovMapAvailable(false),
194  thePriorVertexState(priorPos, priorTime, priorErr),
195  withPrior(true),
196  theValid(true),
197  vertexIs4D(true) {}
198 
199 //to be removed
200 template <unsigned int N>
202  const GlobalError& priorErr,
203  const GlobalPoint& pos,
204  const GlobalWeight& posWeight,
205  const std::vector<RefCountedVertexTrack>& tks,
206  float totalChiSq)
207  : theVertexState(pos, posWeight),
208  theChiSquared(totalChiSq),
209  theNDF(0),
210  theNDFAvailable(false),
211  theTracks(tks),
212  theCovMapAvailable(false),
213  thePriorVertexState(priorPos, priorErr),
214  withPrior(true),
215  theValid(true),
216  vertexIs4D(false) {}
217 
218 //to be removed
219 template <unsigned int N>
221  const double priorTime,
222  const GlobalError& priorErr,
223  const GlobalPoint& pos,
224  const double time,
225  const GlobalWeight& posWeight,
226  const std::vector<RefCountedVertexTrack>& tks,
227  float totalChiSq)
228  : theVertexState(pos, priorTime, posWeight),
229  theChiSquared(totalChiSq),
230  theNDF(0),
231  theNDFAvailable(false),
232  theTracks(tks),
233  theCovMapAvailable(false),
234  thePriorVertexState(priorPos, priorTime, priorErr),
235  withPrior(true),
236  theValid(true),
237  vertexIs4D(true) {}
238 
239 //to be removed
240 template <unsigned int N>
242  const GlobalError& priorErr,
243  const AlgebraicVector3& weightTimesPosition,
244  const GlobalWeight& posWeight,
245  const std::vector<RefCountedVertexTrack>& tks,
246  float totalChiSq)
247  : theVertexState(weightTimesPosition, posWeight),
248  theChiSquared(totalChiSq),
249  theNDF(0),
250  theNDFAvailable(false),
251  theTracks(tks),
252  theCovMapAvailable(false),
253  thePriorVertexState(priorPos, priorErr),
254  withPrior(true),
255  theValid(true) {}
256 
257 //to be removed
258 template <unsigned int N>
260  const GlobalError& priorErr,
261  const AlgebraicVector4& weightTimesPosition,
262  const GlobalWeight& posWeight,
263  const std::vector<RefCountedVertexTrack>& tks,
264  float totalChiSq)
265  : theVertexState(weightTimesPosition, posWeight),
266  theChiSquared(totalChiSq),
267  theNDF(0),
268  theNDFAvailable(false),
269  theTracks(tks),
270  theCovMapAvailable(false),
271  thePriorVertexState(priorPos, priorErr),
272  withPrior(true),
273  theValid(true) {}
274 
275 template <unsigned int N>
277  const VertexState& aVertexState,
278  const std::vector<RefCountedVertexTrack>& tks,
279  float totalChiSq,
280  const TrackToTrackMap& covMap)
281  : theVertexState(aVertexState),
282  theChiSquared(totalChiSq),
283  theNDF(0),
284  theNDFAvailable(false),
285  theTracks(tks),
286  theCovMap(covMap),
287  theCovMapAvailable(true),
288  thePriorVertexState(priorVertexState),
289  withPrior(true),
290  theValid(true),
291  vertexIs4D(priorVertexState.is4D() && aVertexState.is4D()) {
292  if (theCovMap.empty())
293  theCovMapAvailable = false;
294 }
295 
296 template <unsigned int N>
298  : theChiSquared(-1),
299  theNDF(0),
300  theNDFAvailable(false),
301  theTracks(),
302  theCovMapAvailable(false),
303  withPrior(false),
304  theValid(false),
305  vertexIs4D(false) {}
306 
307 template <unsigned int N>
309  return theVertexState.position();
310 }
311 
312 template <unsigned int N>
313 double CachingVertex<N>::time() const {
314  return theVertexState.time();
315 }
316 
317 template <unsigned int N>
319  return theVertexState.error();
320 }
321 
322 template <unsigned int N>
324  return theVertexState.error4D();
325 }
326 
327 template <unsigned int N>
329  return theVertexState.weight();
330 }
331 
332 template <unsigned int N>
334  return theVertexState.weight4D();
335 }
336 
337 template <unsigned int N>
339  return theVertexState.weightTimesPosition();
340 }
341 
342 template <unsigned int N>
344  return theVertexState.weightTimesPosition4D();
345 }
346 
347 template <unsigned int N>
349  if (!theNDFAvailable)
350  computeNDF();
351  return theNDF;
352 }
353 
354 template <unsigned int N>
356  theNDF = 0;
357  for (typename std::vector<RefCountedVertexTrack>::const_iterator itk = theTracks.begin(); itk != theTracks.end();
358  ++itk) {
359  theNDF += (**itk).weight(); // adds up weights
360  }
361  theNDF *= 2.; // times 2df for each track
362  const double adjust = (vertexIs4D ? 4 : 3); // ndf adjust is 3 or 4
363  if (!withPrior)
364  theNDF -= adjust;
365  theNDFAvailable = true;
366 }
367 
368 template <unsigned int N>
370  const RefCountedVertexTrack t2) const {
371  if (!tkToTkCovarianceIsAvailable()) {
372  throw VertexException("CachingVertex::TkTkCovariance requested before been calculated");
373  } else {
376  bool transp = false;
377  if (t1 < t2) {
378  tr1 = t1;
379  tr2 = t2;
380  } else {
381  tr1 = t2;
382  tr2 = t1;
383  transp = true;
384  }
385  typename TrackToTrackMap::const_iterator it = theCovMap.find(tr1);
386  if (it != theCovMap.end()) {
387  const TrackMap& tm = it->second;
388  typename TrackMap::const_iterator nit = tm.find(tr2);
389  if (nit != tm.end()) {
390  if (transp)
391  return (ROOT::Math::Transpose(nit->second));
392  else
393  return (nit->second);
394  } else {
395  throw VertexException("CachingVertex::requested TkTkCovariance does not exist");
396  }
397  } else {
398  throw VertexException("CachingVertex::requested TkTkCovariance does not exist");
399  }
400  }
401 }
402 
403 template <unsigned int N>
405  //If the vertex is invalid, return an invalid TV !
406  if (!isValid())
407  return TransientVertex();
408 
409  typedef std::map<reco::TransientTrack, float> TransientTrackToFloatMap;
410 
411  // Construct Track vector
412  std::vector<reco::TransientTrack> ttVect;
413  ttVect.reserve(theTracks.size());
414  std::vector<reco::TransientTrack> refTTVect;
415  TransientTrackToFloatMap theWeightMap;
416  TTtoTTmap ttCovMap;
417  // float theMinWeight = 0.5;
418 
419  for (typename std::vector<RefCountedVertexTrack>::const_iterator i = theTracks.begin(); i != theTracks.end(); ++i) {
420  // discard tracks with too low weight
421  // if ((**i).weight() < theMinWeight) continue;
422 
423  reco::TransientTrack t1((**i).linearizedTrack()->track());
424  ttVect.push_back(t1);
425  //Fill in the weight map
426  theWeightMap[t1] = (**i).weight();
427 
428  //Fill in the tk-to-tk covariance map
429  if (theCovMapAvailable) {
430  for (typename std::vector<RefCountedVertexTrack>::const_iterator j = (i + 1); j != theTracks.end(); ++j) {
431  reco::TransientTrack t2((**j).linearizedTrack()->track());
432  ttCovMap[t1][t2] = tkToTkCovariance(*i, *j);
433  }
434  }
435  if ((**i).refittedStateAvailable()) {
436  refTTVect.push_back((**i).refittedState()->transientTrack());
437  }
438  }
439  TransientVertex tv;
440  if (withPrior) {
441  tv = TransientVertex(priorVertexState(), vertexState(), ttVect, totalChiSquared(), degreesOfFreedom());
442  } else {
443  tv = TransientVertex(vertexState(), ttVect, totalChiSquared(), degreesOfFreedom());
444  }
445  tv.weightMap(theWeightMap);
446  if (theCovMapAvailable)
447  tv.tkToTkCovariance(ttCovMap);
448  if (!refTTVect.empty())
449  tv.refittedTracks(refTTVect);
450  return tv;
451 }
452 
453 template class CachingVertex<5>;
454 template class CachingVertex<6>;
bool theCovMapAvailable
GlobalError error4D() const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
GlobalWeight weight4D() const
Common base class.
TrackToTrackMap theCovMap
std::map< reco::TransientTrack, TTmap > TTtoTTmap
Definition: TTtoTTmap.h:12
TransientTrackToFloatMap weightMap() const
void computeNDF() const
double time() const
AlgebraicVector3 weightTimesPosition() const
ROOT::Math::SVector< double, 4 > AlgebraicVector4
AlgebraicMatrix33 tkToTkCovariance(const reco::TransientTrack &t1, const reco::TransientTrack &t2) const
ROOT::Math::SMatrix< double, N - 2, N - 2, ROOT::Math::MatRepStd< double, N - 2, N - 2 > > AlgebraicMatrixMM
Definition: CachingVertex.h:26
AlgebraicMatrixMM tkToTkCovariance(const RefCountedVertexTrack t1, const RefCountedVertexTrack t2) const
ROOT::Math::SVector< double, 3 > AlgebraicVector3
float degreesOfFreedom() const
std::map< RefCountedVertexTrack, AlgebraicMatrixMM > TrackMap
Definition: CachingVertex.h:27
GlobalPoint position() const
GlobalError error() const
AlgebraicVector4 weightTimesPosition4D() const
GlobalWeight weight() const
std::vector< reco::TransientTrack > const & refittedTracks() const