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), theNDF(0), theNDFAvailable(false),
16  theTracks(tks), theCovMapAvailable(false), withPrior(false),
17  theValid(true), vertexIs4D(false)
18 
19 {}
20 
21 //to be removed
22 template <unsigned int N>
24  const double time,
25  const GlobalError & posTimeErr,
26  const std::vector<RefCountedVertexTrack> & tks,
27  float totalChiSq)
28  : theVertexState(pos, time, posTimeErr),
29  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
32 
33 {}
34 
35 
36 //to be removed
37 template <unsigned int N>
39  const GlobalWeight & posWeight,
40  const std::vector<RefCountedVertexTrack> & tks,
41  float totalChiSq)
42  : theVertexState(pos, posWeight),
43  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
46 {}
47 
48 //to be removed
49 template <unsigned int N>
51  const double time,
52  const GlobalWeight & posTimeWeight,
53  const std::vector<RefCountedVertexTrack> & tks,
54  float totalChiSq)
55  : theVertexState(pos, time, posTimeWeight),
56  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
59 {}
60 
61 
62 //to be removed
63 template <unsigned int N>
65  const GlobalWeight & posWeight,
66  const std::vector<RefCountedVertexTrack> & tks,
67  float totalChiSq)
68  : theVertexState(weightTimesPosition, posWeight),
69  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
72 {}
73 
74 //to be removed
75 template <unsigned int N>
77  const GlobalWeight & posWeight,
78  const std::vector<RefCountedVertexTrack> & tks,
79  float totalChiSq)
80  : theVertexState(weightTimesPosition, posWeight),
81  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
84 {}
85 
86 template <unsigned int N>
88  const std::vector<RefCountedVertexTrack> & tks,
89  float totalChiSq)
90  : theVertexState(aVertexState),
91  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
93  theValid(true),
94  vertexIs4D( aVertexState.is4D() )
95 {}
96 
97 
98 template <unsigned int N>
100  const std::vector<RefCountedVertexTrack> & tks,
101  float totalChiSq,
102  const TrackToTrackMap & covMap)
103  : theVertexState(aVertexState),
104  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
105  theTracks(tks), theCovMap(covMap), theCovMapAvailable(true),
107  vertexIs4D( aVertexState.is4D() )
108 {
109  if (theCovMap.empty()) theCovMapAvailable = false;
110 }
111 
112 template <unsigned int N>
114  const VertexState & aVertexState,
115  const std::vector<RefCountedVertexTrack> & tks,
116  float totalChiSq)
117  : theVertexState(aVertexState), theChiSquared(totalChiSq),
119  theCovMapAvailable(false), thePriorVertexState(priorVertexState),
121  vertexIs4D( priorVertexState.is4D() && aVertexState.is4D() )
122 {}
123 
124 //to be removed
125 template <unsigned int N>
127  const GlobalError & priorErr,
128  const GlobalPoint & pos,
129  const GlobalError & posErr,
130  const std::vector<RefCountedVertexTrack> & tks,
131  float totalChiSq)
132  : theVertexState(pos, posErr),
133  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
136 {}
137 
138 //to be removed
139 template <unsigned int N>
141  const double priorTime,
142  const GlobalError & priorErr,
143  const GlobalPoint & pos,
144  const double time,
145  const GlobalError & posErr,
146  const std::vector<RefCountedVertexTrack> & tks,
147  float totalChiSq)
148  : theVertexState(pos, time,posErr),
149  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
151  thePriorVertexState(priorPos, priorTime, priorErr), withPrior(true),
153 {}
154 
155 
156 //to be removed
157 template <unsigned int N>
159  const GlobalError & priorErr,
160  const GlobalPoint & pos,
161  const GlobalWeight & posWeight,
162  const std::vector<RefCountedVertexTrack> & tks,
163  float totalChiSq)
164  : theVertexState(pos, posWeight),
165  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
168 {}
169 
170 //to be removed
171 template <unsigned int N>
173  const double priorTime,
174  const GlobalError & priorErr,
175  const GlobalPoint & pos,
176  const double time,
177  const GlobalWeight & posWeight,
178  const std::vector<RefCountedVertexTrack> & tks,
179  float totalChiSq)
180  : theVertexState(pos, priorTime, posWeight),
181  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
183  thePriorVertexState(priorPos, priorTime, priorErr), withPrior(true),
185 {}
186 
187 
188 //to be removed
189 template <unsigned int N>
191  const GlobalError & priorErr,
193  const GlobalWeight & posWeight,
194  const std::vector<RefCountedVertexTrack> & tks,
195  float totalChiSq)
196  : theVertexState(weightTimesPosition, posWeight),
197  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
199  thePriorVertexState(priorPos, priorErr), withPrior(true), theValid(true)
200 {}
201 
202 //to be removed
203 template <unsigned int N>
205  const GlobalError & priorErr,
207  const GlobalWeight & posWeight,
208  const std::vector<RefCountedVertexTrack> & tks,
209  float totalChiSq)
210  : theVertexState(weightTimesPosition, posWeight),
211  theChiSquared(totalChiSq), theNDF(0), theNDFAvailable(false),
213  thePriorVertexState(priorPos, priorErr), withPrior(true), theValid(true)
214 {}
215 
216 
217 template <unsigned int N>
219  const VertexState & aVertexState,
220  const std::vector<RefCountedVertexTrack> & tks,
221  float totalChiSq,
222  const TrackToTrackMap & covMap)
223  : theVertexState(aVertexState), theChiSquared(totalChiSq),
225  theCovMap(covMap), theCovMapAvailable(true),
226  thePriorVertexState(priorVertexState), withPrior(true), theValid(true),
227  vertexIs4D( priorVertexState.is4D() && aVertexState.is4D() )
228 {
229  if (theCovMap.empty()) theCovMapAvailable = false;
230 }
231 
232 template <unsigned int N>
237 {}
238 
239 template <unsigned int N>
241 {
242  return theVertexState.position();
243 }
244 
245 template <unsigned int N>
246 double CachingVertex<N>::time() const
247 {
248  return theVertexState.time();
249 }
250 
251 template <unsigned int N>
253 {
254  return theVertexState.error();
255 }
256 
257 template <unsigned int N>
259 {
260  return theVertexState.error4D();
261 }
262 
263 
264 template <unsigned int N>
266 {
267  return theVertexState.weight();
268 }
269 
270 template <unsigned int N>
272 {
273  return theVertexState.weight4D();
274 }
275 
276 
277 template <unsigned int N>
279 {
281 }
282 
283 template <unsigned int N>
285 {
287 }
288 
289 template <unsigned int N>
291 {
292  if (!theNDFAvailable) computeNDF();
293  return theNDF;
294 }
295 
296 
297 template <unsigned int N>
299 {
300  theNDF = 0;
301  for (typename std::vector<RefCountedVertexTrack>::const_iterator itk = theTracks.begin();
302  itk != theTracks.end(); ++itk) {
303  theNDF += (**itk).weight(); // adds up weights
304  }
305  theNDF *= 2.; // times 2df for each track
306  const double adjust = ( vertexIs4D ? 4 : 3 ); // ndf adjust is 3 or 4
307  if (!withPrior) theNDF -= adjust;
308  theNDFAvailable = true;
309 }
310 
311 
312 template <unsigned int N>
315  const RefCountedVertexTrack t2) const
316 {
318  throw VertexException("CachingVertex::TkTkCovariance requested before been calculated");
319  }
320  else {
323  bool transp = false;
324  if(t1 < t2) {
325  tr1 = t1;
326  tr2 = t2;
327  }
328  else {
329  tr1 = t2;
330  tr2 = t1;
331  transp = true;
332  }
333  typename TrackToTrackMap::const_iterator it = theCovMap.find(tr1);
334  if (it != theCovMap.end()) {
335  const TrackMap & tm = it->second;
336  typename TrackMap::const_iterator nit = tm.find(tr2);
337  if (nit != tm.end()) {
338  if (transp) return( ROOT::Math::Transpose(nit->second) );
339  else return( nit->second);
340  }
341  else {
342  throw VertexException("CachingVertex::requested TkTkCovariance does not exist");
343  }
344  }
345  else {
346  throw VertexException("CachingVertex::requested TkTkCovariance does not exist");
347  }
348  }
349 }
350 
351 template <unsigned int N>
353 {
354  //If the vertex is invalid, return an invalid TV !
355  if (!isValid()) return TransientVertex();
356 
357  typedef std::map<reco::TransientTrack, float> TransientTrackToFloatMap;
358 
359 // Construct Track vector
360  std::vector<reco::TransientTrack> ttVect;
361  ttVect.reserve(theTracks.size());
362  std::vector<reco::TransientTrack> refTTVect;
363  TransientTrackToFloatMap theWeightMap;
364  TTtoTTmap ttCovMap;
365  // float theMinWeight = 0.5;
366 
367  for (typename std::vector<RefCountedVertexTrack>::const_iterator i = theTracks.begin();
368  i != theTracks.end(); ++i) {
369  // discard tracks with too low weight
370  // if ((**i).weight() < theMinWeight) continue;
371 
372  reco::TransientTrack t1((**i).linearizedTrack()->track());
373  ttVect.push_back(t1);
374  //Fill in the weight map
375  theWeightMap[t1] = (**i).weight();
376 
377  //Fill in the tk-to-tk covariance map
378  if (theCovMapAvailable) {
379  for (typename std::vector<RefCountedVertexTrack>::const_iterator j = (i+1);
380  j != theTracks.end(); ++j) {
381  reco::TransientTrack t2((**j).linearizedTrack()->track());
382  ttCovMap[t1][t2] = tkToTkCovariance(*i, *j);
383  }
384  }
385  if ((**i).refittedStateAvailable()) {
386  refTTVect.push_back( (**i).refittedState()->transientTrack()) ;
387  }
388  }
389  TransientVertex tv;
390  if (withPrior) {
392  } else {
394  }
395  tv.weightMap(theWeightMap);
396  if (theCovMapAvailable) tv.tkToTkCovariance(ttCovMap);
397  if (!refTTVect.empty()) tv.refittedTracks(refTTVect);
398  return tv;
399 }
400 
401 
402 
403 template class CachingVertex<5>;
404 template class CachingVertex<6>;
bool theCovMapAvailable
void computeNDF() const
VertexState thePriorVertexState
Common base class.
VertexState const & vertexState() const
TrackToTrackMap theCovMap
std::map< reco::TransientTrack, TTmap > TTtoTTmap
Definition: TTtoTTmap.h:12
GlobalPoint position() const
Definition: VertexState.h:69
bool is4D() const
GlobalError error4D() const
GlobalWeight weight4D() const
Definition: VertexState.h:90
AlgebraicVector3 weightTimesPosition() const
GlobalWeight weight() const
AlgebraicVector3 weightTimesPosition() const
Definition: VertexState.h:103
float totalChiSquared() const
ROOT::Math::SVector< double, 3 > AlgebraicVector3
std::map< RefCountedVertexTrack, AlgebraicMatrixMM > TrackMap
Definition: CachingVertex.h:32
double time() const
Definition: VertexState.h:95
float degreesOfFreedom() const
std::vector< RefCountedVertexTrack > theTracks
GlobalWeight weight() const
Definition: VertexState.h:85
AlgebraicVector4 weightTimesPosition4D() const
GlobalError error4D() const
Definition: VertexState.h:80
VertexState const & priorVertexState() const
AlgebraicMatrixMM tkToTkCovariance(const RefCountedVertexTrack t1, const RefCountedVertexTrack t2) const
GlobalWeight weight4D() const
bool tkToTkCovarianceIsAvailable() const
GlobalPoint position() const
AlgebraicVector4 weightTimesPosition4D() const
Definition: VertexState.h:108
double priorTime() const
ROOT::Math::SMatrix< double, N-2, N-2, ROOT::Math::MatRepStd< double, N-2, N-2 > > AlgebraicMatrixMM
Definition: CachingVertex.h:31
bool isValid() const
GlobalError error() const
Definition: VertexState.h:74
std::vector< reco::TransientTrack > const & refittedTracks() const
ROOT::Math::SVector< double, 4 > AlgebraicVector4
GlobalError error() const
AlgebraicMatrix33 tkToTkCovariance(const reco::TransientTrack &t1, const reco::TransientTrack &t2) const
double time() const
TransientTrackToFloatMap weightMap() const
VertexState theVertexState