CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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("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 
306  Vertex vertex(Vertex::Point(theVertexState.position()),
307  // RecoVertex::convertError(theVertexState.error()),
308  theVertexState.error4D().matrix4D(),
309  theVertexState.time(),
310  totalChiSquared(),
311  degreesOfFreedom(),
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 }
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepStd< double, 3, 3 > > AlgebraicMatrix33
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
void add(Ref const &r, float w=1.0)
add a reference to a Track
Definition: Vertex.h:86
auto const & tracks
cannot be loose
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
reco::TransientTrack refittedTrack(const reco::TransientTrack &track) const
TransientTrackToFloatMap theWeightMap
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
std::vector< reco::TransientTrack > theOriginalTracks
float trackWeight(const reco::TransientTrack &track) const
reco::TransientTrack originalTrack(const reco::TransientTrack &refTrack) const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
dictionary prior
static int position[264][3]
Definition: ReadPGInfo.cc:289
float x
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
std::vector< reco::TransientTrack > const & refittedTracks() const
std::vector< reco::TransientTrack > theRefittedTracks
AlgebraicMatrix33 tkToTkCovariance(const reco::TransientTrack &t1, const reco::TransientTrack &t2) const
TransientTrackToFloatMap weightMap() const
float trackWeight(const reco::Vertex &sv, const reco::TransientTrack &track)