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),
30  vertexValid(true),
31  withPrior(false),
32  theWeightMapIsAvailable(false),
33  theCovMapAvailable(false),
34  withRefittedTracks(false) {
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),
47  vertexValid(true),
48  withPrior(false),
49  theWeightMapIsAvailable(false),
50  theCovMapAvailable(false),
51  withRefittedTracks(false) {
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),
64  vertexValid(true),
65  withPrior(false),
66  theWeightMapIsAvailable(false),
67  theCovMapAvailable(false),
68  withRefittedTracks(false) {}
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),
80  vertexValid(true),
81  withPrior(false),
82  theWeightMapIsAvailable(false),
83  theCovMapAvailable(false),
84  withRefittedTracks(false) {}
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),
97  vertexValid(true),
98  withPrior(true),
99  theWeightMapIsAvailable(false),
100  theCovMapAvailable(false),
101  withRefittedTracks(false) {
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),
120  theWeightMapIsAvailable(false),
121  theCovMapAvailable(false),
122  withRefittedTracks(false) {
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),
140  theWeightMapIsAvailable(false),
141  theCovMapAvailable(false),
142  withRefittedTracks(false) {}
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),
160  theWeightMapIsAvailable(false),
161  theCovMapAvailable(false),
162  withRefittedTracks(false) {}
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),
171  theWeightMapIsAvailable(false),
172  theCovMapAvailable(false),
173  withRefittedTracks(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),
187  theWeightMapIsAvailable(false),
188  theCovMapAvailable(false),
189  withRefittedTracks(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),
202  theWeightMapIsAvailable(false),
203  theCovMapAvailable(false),
204  withRefittedTracks(false) {
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),
220  theWeightMapIsAvailable(false),
221  theCovMapAvailable(false),
222  withRefittedTracks(false) {}
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("TransientVertex::requested 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(
287  "TransientVertex::requested Refitted track not found in list.\n address used for comparison: ")
288  << refTrack.basicTransientTrack();
289  size_t pos = it - theRefittedTracks.begin();
290  return theOriginalTracks[pos];
291 }
292 
294  if (theRefittedTracks.empty())
295  throw VertexException("TransientVertex::requested No refitted tracks stored in vertex");
296  std::vector<TransientTrack>::const_iterator it = find(theOriginalTracks.begin(), theOriginalTracks.end(), track);
297  if (it == theOriginalTracks.end())
298  throw VertexException("transientVertex::requested Track not found in list.\n address used for comparison: ")
299  << track.basicTransientTrack();
300  size_t pos = it - theOriginalTracks.begin();
301  return theRefittedTracks[pos];
302 }
303 
305  //If the vertex is invalid, return an invalid TV !
306  if (!isValid())
307  return Vertex();
308 
309  Vertex vertex(Vertex::Point(theVertexState.position()),
310  // RecoVertex::convertError(theVertexState.error()),
311  theVertexState.error4D().matrix4D(),
312  theVertexState.time(),
313  totalChiSquared(),
314  degreesOfFreedom(),
315  theOriginalTracks.size());
316  for (std::vector<TransientTrack>::const_iterator i = theOriginalTracks.begin(); i != theOriginalTracks.end(); ++i) {
317  // const TrackTransientTrack* ttt = dynamic_cast<const TrackTransientTrack*>((*i).basicTransientTrack());
318  // if ((ttt!=0) && (ttt->persistentTrackRef().isNonnull()))
319  // {
320  // TrackRef tr = ttt->persistentTrackRef();
321  // TrackBaseRef tbr(tr);
322  if (withRefittedTracks) {
323  vertex.add((*i).trackBaseRef(), refittedTrack(*i).track(), trackWeight(*i));
324  } else {
325  vertex.add((*i).trackBaseRef(), trackWeight(*i));
326  }
327  //}
328  }
329  return vertex;
330 }
331 
333  using namespace reco;
334  if (!isValid())
336 
337  VertexCompositePtrCandidate vtxCompPtrCand;
338 
339  vtxCompPtrCand.setTime(vertexState().time());
340  vtxCompPtrCand.setCovariance(vertexState().error4D().matrix4D());
341  vtxCompPtrCand.setChi2AndNdof(totalChiSquared(), degreesOfFreedom());
342  vtxCompPtrCand.setVertex(Candidate::Point(position().x(), position().y(), position().z()));
343 
345  for (std::vector<reco::TransientTrack>::const_iterator tt = theOriginalTracks.begin(); tt != theOriginalTracks.end();
346  ++tt) {
347  if (trackWeight(*tt) < 0.5)
348  continue;
349 
350  const CandidatePtrTransientTrack* cptt = dynamic_cast<const CandidatePtrTransientTrack*>(tt->basicTransientTrack());
351  if (cptt == nullptr)
352  edm::LogError("DynamicCastingFailed") << "Casting of TransientTrack to CandidatePtrTransientTrack failed!";
353  else {
354  p4 += cptt->candidate()->p4();
355  vtxCompPtrCand.addDaughter(cptt->candidate());
356  }
357  }
358 
359  //TODO: if has refitted tracks we should scale the candidate p4 to the refitted one
360  vtxCompPtrCand.setP4(p4);
361  return vtxCompPtrCand;
362 }
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
reco::TransientTrack refittedTrack(const reco::TransientTrack &track) const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
Common base class.
CandidatePtr candidate() const override
std::map< reco::TransientTrack, float > TransientTrackToFloatMap
reco::TransientTrack originalTrack(const reco::TransientTrack &refTrack) const
Log< level::Error, false > LogError
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
std::map< reco::TransientTrack, AlgebraicMatrix33 > TTmap
Definition: TTtoTTmap.h:11
TransientTrackToFloatMap weightMap() const
void setVertex(const Point &vertex) override
set vertex
Definition: TTTypes.h:54
TransientTrackToFloatMap theWeightMap
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
std::vector< reco::TransientTrack > theOriginalTracks
AlgebraicMatrix33 tkToTkCovariance(const reco::TransientTrack &t1, const reco::TransientTrack &t2) const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
fixed size matrix
static int position[264][3]
Definition: ReadPGInfo.cc:289
void setCovariance(const CovarianceMatrix &m)
set covariance matrix
float x
void addDaughter(const CandidatePtr &)
add a daughter via a reference
float trackWeight(const reco::TransientTrack &track) const
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
std::vector< reco::TransientTrack > theRefittedTracks
void setChi2AndNdof(double chi2, double ndof)
set chi2 and ndof
const BasicTransientTrack * basicTransientTrack() const
void setP4(const LorentzVector &p4) final
set 4-momentum
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)
std::vector< reco::TransientTrack > const & refittedTracks() const
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector