CMS 3D CMS Logo

TransientVertex.cc
Go to the documentation of this file.
6 #include <algorithm>
7 
8 using namespace std;
9 using namespace reco;
10 
12  : theVertexState(),
13  theOriginalTracks(),
14  theChi2(0),
15  theNDF(0),
16  vertexValid(false),
17  withPrior(false),
18  theWeightMapIsAvailable(false),
19  theCovMapAvailable(false),
20  withRefittedTracks(false) {}
21 
23  const GlobalError& posError,
24  const std::vector<TransientTrack>& tracks,
25  float chi2)
26  : theVertexState(pos, posError),
27  theOriginalTracks(tracks),
28  theChi2(chi2),
29  theNDF(0),
35  theNDF = 2. * theOriginalTracks.size() - 3.;
36 }
37 
39  const double time,
40  const GlobalError& posTimeError,
41  const std::vector<TransientTrack>& tracks,
42  float chi2)
43  : theVertexState(pos, time, posTimeError),
44  theOriginalTracks(tracks),
45  theChi2(chi2),
46  theNDF(0),
52  theNDF = 2. * theOriginalTracks.size() - 3.;
53 }
54 
56  const GlobalError& posError,
57  const std::vector<TransientTrack>& tracks,
58  float chi2,
59  float ndf)
60  : theVertexState(pos, posError),
61  theOriginalTracks(tracks),
62  theChi2(chi2),
63  theNDF(ndf),
69 
71  const double time,
72  const GlobalError& posTimeError,
73  const std::vector<TransientTrack>& tracks,
74  float chi2,
75  float ndf)
76  : theVertexState(pos, time, posTimeError),
77  theOriginalTracks(tracks),
78  theChi2(chi2),
79  theNDF(ndf),
85 
87  const GlobalError& priorErr,
88  const GlobalPoint& pos,
89  const GlobalError& posError,
90  const std::vector<TransientTrack>& tracks,
91  float chi2)
92  : thePriorVertexState(priorPos, priorErr),
93  theVertexState(pos, posError),
94  theOriginalTracks(tracks),
95  theChi2(chi2),
96  theNDF(0),
98  withPrior(true),
102  theNDF = 2. * theOriginalTracks.size();
103 }
104 
106  const double priorTime,
107  const GlobalError& priorErr,
108  const GlobalPoint& pos,
109  const double time,
110  const GlobalError& posError,
111  const std::vector<TransientTrack>& tracks,
112  float chi2)
113  : thePriorVertexState(priorPos, priorTime, priorErr),
114  theVertexState(pos, time, posError),
115  theOriginalTracks(tracks),
116  theChi2(chi2),
117  theNDF(0),
118  vertexValid(true),
119  withPrior(true),
123  theNDF = 2. * theOriginalTracks.size();
124 }
125 
127  const GlobalError& priorErr,
128  const GlobalPoint& pos,
129  const GlobalError& posError,
130  const std::vector<TransientTrack>& tracks,
131  float chi2,
132  float ndf)
133  : thePriorVertexState(priorPos, priorErr),
134  theVertexState(pos, posError),
135  theOriginalTracks(tracks),
136  theChi2(chi2),
137  theNDF(ndf),
138  vertexValid(true),
139  withPrior(true),
143 
145  const double priorTime,
146  const GlobalError& priorErr,
147  const GlobalPoint& pos,
148  const double time,
149  const GlobalError& posError,
150  const std::vector<TransientTrack>& tracks,
151  float chi2,
152  float ndf)
153  : thePriorVertexState(priorPos, priorTime, priorErr),
154  theVertexState(pos, time, posError),
155  theOriginalTracks(tracks),
156  theChi2(chi2),
157  theNDF(ndf),
158  vertexValid(true),
159  withPrior(true),
163 
164 TransientVertex::TransientVertex(const VertexState& state, const std::vector<TransientTrack>& tracks, float chi2)
165  : theVertexState(state),
166  theOriginalTracks(tracks),
167  theChi2(chi2),
168  theNDF(0),
169  vertexValid(true),
170  withPrior(false),
174  theNDF = 2. * theOriginalTracks.size() - 3.;
175 }
176 
178  const std::vector<TransientTrack>& tracks,
179  float chi2,
180  float ndf)
181  : theVertexState(state),
182  theOriginalTracks(tracks),
183  theChi2(chi2),
184  theNDF(ndf),
185  vertexValid(true),
186  withPrior(false),
190 
192  const VertexState& state,
193  const std::vector<TransientTrack>& tracks,
194  float chi2)
195  : thePriorVertexState(prior),
196  theVertexState(state),
197  theOriginalTracks(tracks),
198  theChi2(chi2),
199  theNDF(0),
200  vertexValid(true),
201  withPrior(true),
205  theNDF = 2. * theOriginalTracks.size();
206 }
207 
209  const VertexState& state,
210  const std::vector<TransientTrack>& tracks,
211  float chi2,
212  float ndf)
213  : thePriorVertexState(prior),
214  theVertexState(state),
215  theOriginalTracks(tracks),
216  theChi2(chi2),
217  theNDF(ndf),
218  vertexValid(true),
219  withPrior(true),
223 
225  theWeightMap = theMap;
227 }
228 
229 void TransientVertex::refittedTracks(const std::vector<reco::TransientTrack>& refittedTracks) {
230  if (refittedTracks.empty())
231  throw VertexException("TransientVertex::refittedTracks: No refitted tracks stored in input container");
233  withRefittedTracks = true;
234 }
235 
237  theCovMap = covMap;
238  theCovMapAvailable = true;
239 }
240 
243  std::vector<TransientTrack>::const_iterator foundTrack =
245  return ((foundTrack != theOriginalTracks.end()) ? 1. : 0.);
246  }
247  TransientTrackToFloatMap::const_iterator it = theWeightMap.find(track);
248  if (it != theWeightMap.end()) {
249  return (it->second);
250  }
251  return 0.;
252 }
253 
255  if (!theCovMapAvailable) {
256  throw VertexException("TransientVertex::Track-to-track covariance matrices not available");
257  }
258  const TransientTrack* tr1;
259  const TransientTrack* tr2;
260  if (t1 < t2) {
261  tr1 = &t1;
262  tr2 = &t2;
263  } else {
264  tr1 = &t2;
265  tr2 = &t1;
266  }
267  TTtoTTmap::const_iterator it = theCovMap.find(*tr1);
268  if (it != theCovMap.end()) {
269  const TTmap& tm = it->second;
270  TTmap::const_iterator nit = tm.find(*tr2);
271  if (nit != tm.end()) {
272  return (nit->second);
273  } else {
274  throw VertexException("TransientVertex::requested Track-to-track covariance matrix does not exist");
275  }
276  } else {
277  throw VertexException("TransientVertex::requested Track-to-track covariance matrix does not exist");
278  }
279 }
280 
282  if (theRefittedTracks.empty())
283  throw VertexException("No refitted tracks stored in vertex");
284  std::vector<TransientTrack>::const_iterator it = find(theRefittedTracks.begin(), theRefittedTracks.end(), refTrack);
285  if (it == theRefittedTracks.end())
286  throw VertexException("Refitted track not found in list");
287  size_t pos = it - theRefittedTracks.begin();
288  return theOriginalTracks[pos];
289 }
290 
292  if (theRefittedTracks.empty())
293  throw VertexException("No refitted tracks stored in vertex");
294  std::vector<TransientTrack>::const_iterator it = find(theOriginalTracks.begin(), theOriginalTracks.end(), track);
295  if (it == theOriginalTracks.end())
296  throw VertexException("Track not found in list");
297  size_t pos = it - theOriginalTracks.begin();
298  return theRefittedTracks[pos];
299 }
300 
302  //If the vertex is invalid, return an invalid TV !
303  if (!isValid())
304  return Vertex();
305 
307  // RecoVertex::convertError(theVertexState.error()),
310  totalChiSquared(),
312  theOriginalTracks.size());
313  for (std::vector<TransientTrack>::const_iterator i = theOriginalTracks.begin(); i != theOriginalTracks.end(); ++i) {
314  // const TrackTransientTrack* ttt = dynamic_cast<const TrackTransientTrack*>((*i).basicTransientTrack());
315  // if ((ttt!=0) && (ttt->persistentTrackRef().isNonnull()))
316  // {
317  // TrackRef tr = ttt->persistentTrackRef();
318  // TrackBaseRef tbr(tr);
319  if (withRefittedTracks) {
320  vertex.add((*i).trackBaseRef(), refittedTrack(*i).track(), trackWeight(*i));
321  } else {
322  vertex.add((*i).trackBaseRef(), trackWeight(*i));
323  }
324  //}
325  }
326  return vertex;
327 }
328 
330  using namespace reco;
331  if (!isValid())
333 
334  VertexCompositePtrCandidate vtxCompPtrCand;
335 
336  vtxCompPtrCand.setTime(vertexState().time());
337  vtxCompPtrCand.setCovariance(vertexState().error4D().matrix4D());
338  vtxCompPtrCand.setChi2AndNdof(totalChiSquared(), degreesOfFreedom());
339  vtxCompPtrCand.setVertex(Candidate::Point(position().x(), position().y(), position().z()));
340 
342  for (std::vector<reco::TransientTrack>::const_iterator tt = theOriginalTracks.begin(); tt != theOriginalTracks.end();
343  ++tt) {
344  if (trackWeight(*tt) < 0.5)
345  continue;
346 
347  const CandidatePtrTransientTrack* cptt = dynamic_cast<const CandidatePtrTransientTrack*>(tt->basicTransientTrack());
348  if (cptt == nullptr)
349  edm::LogError("DynamicCastingFailed") << "Casting of TransientTrack to CandidatePtrTransientTrack failed!";
350  else {
351  p4 += cptt->candidate()->p4();
352  vtxCompPtrCand.addDaughter(cptt->candidate());
353  }
354  }
355 
356  //TODO: if has refitted tracks we should scale the candidate p4 to the refitted one
357  vtxCompPtrCand.setP4(p4);
358  return vtxCompPtrCand;
359 }
double priorTime() const
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
Common base class.
float totalChiSquared() const
std::map< reco::TransientTrack, float > TransientTrackToFloatMap
std::map< reco::TransientTrack, TTmap > TTtoTTmap
Definition: TTtoTTmap.h:12
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
GlobalPoint position() const
Definition: VertexState.h:62
std::map< reco::TransientTrack, AlgebraicMatrix33 > TTmap
Definition: TTtoTTmap.h:11
const AlgebraicSymMatrix44 & matrix4D() const
void setVertex(const Point &vertex) override
set vertex
reco::TransientTrack refittedTrack(const reco::TransientTrack &track) const
VertexState thePriorVertexState
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
float degreesOfFreedom() const
TransientTrackToFloatMap theWeightMap
double p4[4]
Definition: TauolaWrapper.h:92
GlobalPoint position() const
double time() const
Definition: VertexState.h:73
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
std::vector< reco::TransientTrack > theOriginalTracks
float trackWeight(const reco::TransientTrack &track) const
CandidatePtr candidate() const override
GlobalError error4D() const
Definition: VertexState.h:67
const Track & track() const
reco::TransientTrack originalTrack(const reco::TransientTrack &refTrack) const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
double time() const
fixed size matrix
VertexState theVertexState
void setCovariance(const CovarianceMatrix &m)
set covariance matrix
void addDaughter(const CandidatePtr &)
add a daughter via a reference
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
std::vector< reco::TransientTrack > const & refittedTracks() const
std::vector< reco::TransientTrack > theRefittedTracks
void setChi2AndNdof(double chi2, double ndof)
set chi2 and ndof
VertexState const & vertexState() const
AlgebraicMatrix33 tkToTkCovariance(const reco::TransientTrack &t1, const reco::TransientTrack &t2) const
bool isValid() const
void setP4(const LorentzVector &p4) final
set 4-momentum
TransientTrackToFloatMap weightMap() const