Geometric3DVertexFitter.cxx
Go to the documentation of this file.
2 
5  detinfo::DetectorPropertiesData const& detProp,
6  size_t iPF,
7  const art::ValidHandle<std::vector<recob::PFParticle>>& inputPFParticle,
8  const std::unique_ptr<art::FindManyP<recob::Track>>& assocTracks) const
9 {
10  using namespace std;
11  art::Ptr<recob::PFParticle> pfp(inputPFParticle, iPF);
12  if (debugLevel > 1)
13  std::cout << "pfp#" << iPF << " PdgCode=" << pfp->PdgCode() << " IsPrimary=" << pfp->IsPrimary()
14  << " NumDaughters=" << pfp->NumDaughters() << std::endl;
15  if (pfp->IsPrimary() == false || pfp->NumDaughters() < 2) return VertexWrapper();
16 
18 
19  auto& pfd = pfp->Daughters();
20  for (auto ipfd : pfd) {
21  vector<art::Ptr<recob::Track>> pftracks = assocTracks->at(ipfd);
22  for (auto t : pftracks) {
23  tracks.push_back(*t);
24  }
25  }
26 
27  if (size(tracks) < 2) { return VertexWrapper{}; }
28 
29  return fitTracks(detProp, tracks);
30 }
31 
34  const std::vector<art::Ptr<recob::Track>>& arttracks) const
35 {
37  for (auto t : arttracks) {
38  tracks.push_back(*t);
39  }
40  return fitTracks(detProp, tracks);
41 }
42 
45  TrackRefVec& tracks) const
46 {
47  if (debugLevel > 0) std::cout << "fitting vertex with ntracks=" << tracks.size() << std::endl;
48  if (tracks.size() < 2) return VertexWrapper();
49 
50  // sort tracks by number of hits
51  std::sort(
52  tracks.begin(),
53  tracks.end(),
54  [](std::reference_wrapper<const recob::Track> a, std::reference_wrapper<const recob::Track> b) {
55  return a.get().CountValidPoints() > b.get().CountValidPoints();
56  });
57 
58  //find pair with closest start positions and put them upfront
59  unsigned int tk0 = tracks.size();
60  unsigned int tk1 = tracks.size();
61  float mind = FLT_MAX;
62  for (unsigned int i = 0; i < tracks.size() - 1; i++) {
63  for (unsigned int j = i + 1; j < tracks.size(); j++) {
64  float d =
65  (tracks[i].get().Trajectory().Start() - tracks[j].get().Trajectory().Start()).Mag2();
66  if (debugLevel > 1)
67  std::cout << "test i=" << i << " start=" << tracks[i].get().Trajectory().Start()
68  << " j=" << j << " start=" << tracks[j].get().Trajectory().Start() << " d=" << d
69  << " mind=" << mind << " tk0=" << tk0 << " tk1=" << tk1 << std::endl;
70  if (d < mind) {
71  mind = d;
72  tk0 = i;
73  tk1 = j;
74  }
75  }
76  }
77  if (tk0 > 1 || tk1 > 1) {
78  if (tk0 > 1 && tk1 > 1) {
79  std::swap(tracks[0], tracks[tk0]);
80  std::swap(tracks[1], tracks[tk1]);
81  }
82  if (tk0 == 0) std::swap(tracks[1], tracks[tk1]);
83  if (tk0 == 1) std::swap(tracks[0], tracks[tk1]);
84  if (tk1 == 0) std::swap(tracks[1], tracks[tk0]);
85  if (tk1 == 1) std::swap(tracks[0], tracks[tk0]);
86  }
87 
88  // find vertex between the first two tracks
89  VertexWrapper vtx = fitTwoTracks(detProp, tracks[0], tracks[1]);
90  if (vtx.isValid() == false || vtx.tracksSize() < 2) return vtx;
91 
92  // then add other tracks and update vertex measurement
93  for (auto tk = tracks.begin() + 2; tk < tracks.end(); ++tk) {
94  auto sipv = sip(detProp, vtx, *tk);
95  if (debugLevel > 1) std::cout << "sip=" << sipv << std::endl;
96  if (sipv > sipCut) continue;
97  addTrackToVertex(detProp, vtx, *tk);
98  }
99  return vtx;
100 }
101 
104  detinfo::DetectorPropertiesData const& detProp,
105  const std::vector<art::Ptr<recob::Track>>& arttracks,
106  const recob::tracking::Point_t& vtxPos) const
107 {
109  for (auto t : arttracks) {
110  tracks.push_back(*t);
111  }
112  return fitTracksWithVtx(detProp, tracks, vtxPos);
113 }
114 
118  const recob::tracking::Point_t& vtxPos) const
119 {
120  if (debugLevel > 0) std::cout << "fitting vertex with ntracks=" << tracks.size() << std::endl;
121  if (tracks.size() < 2) return VertexWrapper();
122  // sort tracks by proximity to input vertex
123  std::sort(tracks.begin(), tracks.end(), TracksFromVertexSorter(vtxPos));
124 
125  // find vertex between the first two tracks
126  VertexWrapper vtx = fitTwoTracks(detProp, tracks[0], tracks[1]);
127  if (vtx.isValid() == false || vtx.tracks().size() < 2) return vtx;
128 
129  // then add other tracks and update vertex measurement
130  for (auto tk = tracks.begin() + 2; tk < tracks.end(); ++tk) {
131  auto sipv = sip(detProp, vtx, *tk);
132  if (debugLevel > 1) std::cout << "sip=" << sipv << std::endl;
133  if (sipv > sipCut) continue;
134  addTrackToVertex(detProp, vtx, *tk);
135  }
136  return vtx;
137 }
138 
139 std::pair<trkf::TrackState, double>
141  SVector2& par2,
142  SMatrixSym22& cov1,
143  SMatrixSym22& cov2,
145 {
146  SVector2 deltapar = par2 - par1;
147  SMatrixSym22 covsum = (cov2 + cov1);
148 
149  if (debugLevel > 1) {
150  std::cout << "par1=" << par1 << std::endl;
151  std::cout << "par2=" << par2 << std::endl;
152  std::cout << "deltapar=" << deltapar << std::endl;
153 
154  std::cout << "cov1=\n" << cov1 << std::endl;
155  std::cout << "cov2=\n" << cov2 << std::endl;
156  std::cout << "covsum=\n" << covsum << std::endl;
157  }
158 
159  if (debugLevel > 1) {
160  double det1;
161  bool d1ok = cov1.Det2(det1);
162  std::cout << "cov1 det=" << det1 << " ok=" << d1ok << std::endl;
163  double det2;
164  bool d2ok = cov2.Det2(det2);
165  std::cout << "cov2 det=" << det2 << " ok=" << d2ok << std::endl;
166  double detsum;
167  bool dsok = covsum.Det2(detsum);
168  std::cout << "covsum det=" << detsum << " ok=" << dsok << std::endl;
169  }
170 
171  bool invertok = covsum.Invert();
172  if (!invertok) {
173  SVector5 vtxpar5(0, 0, 0, 0, 0);
174  SMatrixSym55 vtxcov55;
175  TrackState vtxstate(vtxpar5, vtxcov55, target, true, 0);
176  return std::make_pair(vtxstate, util::kBogusD);
177  }
178  auto k = cov1 * covsum;
179 
180  if (debugLevel > 1) {
181  std::cout << "inverted covsum=\n" << covsum << std::endl;
182  std::cout << "k=\n" << k << std::endl;
183  }
184 
185  SVector2 vtxpar2 = par1 + k * deltapar;
186  SMatrixSym22 vtxcov22 = cov1 - ROOT::Math::SimilarityT(cov1, covsum);
187 
188  if (debugLevel > 1) {
189  std::cout << "vtxpar2=" << vtxpar2 << std::endl;
190  std::cout << "vtxcov22=\n" << vtxcov22 << std::endl;
191  }
192 
193  auto chi2 = ROOT::Math::Similarity(deltapar, covsum);
194 
195  SVector5 vtxpar5(vtxpar2[0], vtxpar2[1], 0, 0, 0);
196  SMatrixSym55 vtxcov55;
197  vtxcov55.Place_at(vtxcov22, 0, 0);
198  TrackState vtxstate(vtxpar5, vtxcov55, target, true, 0);
199 
200  return std::make_pair(vtxstate, chi2);
201 }
202 
205  detinfo::DetectorPropertiesData const& detProp,
206  const recob::Track& track,
207  const recob::Track& other) const
208 {
209  // find the closest approach point along track
210  const auto& start1 = track.Trajectory().Start();
211  const auto& start2 = other.Trajectory().Start();
212 
213  const auto dir1 = track.Trajectory().StartDirection();
214  const auto dir2 = other.Trajectory().StartDirection();
215 
216  if (debugLevel > 0) {
217  std::cout << "track1 with start=" << start1 << " dir=" << dir1 << " length=" << track.Length()
218  << " points=" << track.CountValidPoints() << std::endl;
219  std::cout << "covariance=\n" << track.VertexCovarianceGlobal6D() << std::endl;
220  std::cout << "track2 with start=" << start2 << " dir=" << dir2 << " length=" << other.Length()
221  << " points=" << other.CountValidPoints() << std::endl;
222  std::cout << "covariance=\n" << other.VertexCovarianceGlobal6D() << std::endl;
223  }
224 
225  const auto dpos = start1 - start2;
226  const auto dotd1d2 = dir1.Dot(dir2);
227  const auto dotdpd1 = dpos.Dot(dir1);
228  const auto dotdpd2 = dpos.Dot(dir2);
229  const auto dist2 = (dotd1d2 * dotdpd1 - dotdpd2) / (dotd1d2 * dotd1d2 - 1);
230  const auto dist1 = (dotd1d2 * dist2 - dotdpd1);
231 
232  if (debugLevel > 0) {
233  std::cout << "track1 pca=" << start1 + dist1 * dir1 << " dist=" << dist1 << std::endl;
234  std::cout << "track2 pca=" << start2 + dist2 * dir2 << " dist=" << dist2 << std::endl;
235  }
236 
237  //by construction both point of closest approach on the two lines lie on this plane
238  recob::tracking::Plane target(start1 + dist1 * dir1, dir1);
239 
240  recob::tracking::Plane plane1(start1, dir1);
242  track.VertexCovarianceLocal5D(),
243  plane1,
244  true,
245  track.ParticleId());
246  bool propok1 = true;
247  state1 = prop->propagateToPlane(
248  propok1, detProp, state1, target, true, true, trkf::TrackStatePropagator::UNKNOWN);
249  if (!propok1) {
250  std::cout << "failed propagation, return track1 start pos=" << track.Start() << std::endl;
251  VertexWrapper vtx;
253  track.Start(), track.VertexCovarianceGlobal6D().Sub<SMatrixSym33>(0, 0), 0, 0, track);
254  return vtx;
255  }
256  else {
257  VertexWrapper vtx;
259  state1.position(), state1.covariance6D().Sub<SMatrixSym33>(0, 0), 0, 0, track);
260  return vtx;
261  }
262 }
263 
266  const recob::Track& tk1,
267  const recob::Track& tk2) const
268 {
269  // find the closest approach points
270  auto start1 = tk1.Trajectory().Start();
271  auto start2 = tk2.Trajectory().Start();
272 
273  auto dir1 = tk1.Trajectory().StartDirection();
274  auto dir2 = tk2.Trajectory().StartDirection();
275 
276  if (debugLevel > 0) {
277  std::cout << "track1 with start=" << start1 << " dir=" << dir1 << " length=" << tk1.Length()
278  << " points=" << tk1.CountValidPoints() << std::endl;
279  std::cout << "covariance=\n" << tk1.VertexCovarianceGlobal6D() << std::endl;
280  std::cout << "track2 with start=" << start2 << " dir=" << dir2 << " length=" << tk2.Length()
281  << " points=" << tk2.CountValidPoints() << std::endl;
282  std::cout << "covariance=\n" << tk2.VertexCovarianceGlobal6D() << std::endl;
283  }
284 
285  auto dpos = start1 - start2;
286  auto dotd1d2 = dir1.Dot(dir2);
287 
288  auto dotdpd1 = dpos.Dot(dir1);
289  auto dotdpd2 = dpos.Dot(dir2);
290 
291  auto dist2 = (dotd1d2 * dotdpd1 - dotdpd2) / (dotd1d2 * dotd1d2 - 1);
292  auto dist1 = (dotd1d2 * dist2 - dotdpd1);
293 
294  //by construction both point of closest approach on the two lines lie on this plane
295  recob::tracking::Plane target(start1 + dist1 * dir1, dir1);
296 
297  recob::tracking::Plane plane1(start1, dir1);
298  trkf::TrackState state1(
299  tk1.VertexParametersLocal5D(), tk1.VertexCovarianceLocal5D(), plane1, true, tk1.ParticleId());
300  bool propok1 = true;
301  state1 = prop->propagateToPlane(
302  propok1, detProp, state1, target, true, true, trkf::TrackStatePropagator::UNKNOWN);
303  if (!propok1) {
304  std::cout << "failed propagation, return track1 start pos=" << tk1.Start() << std::endl;
305  VertexWrapper vtx;
307  tk1.Start(), tk1.VertexCovarianceGlobal6D().Sub<SMatrixSym33>(0, 0), 0, 0, tk1);
308  return vtx;
309  }
310 
311  recob::tracking::Plane plane2(start2, dir2);
312  trkf::TrackState state2(
313  tk2.VertexParametersLocal5D(), tk2.VertexCovarianceLocal5D(), plane2, true, tk2.ParticleId());
314  bool propok2 = true;
315  state2 = prop->propagateToPlane(
316  propok2, detProp, state2, target, true, true, trkf::TrackStatePropagator::UNKNOWN);
317  if (!propok2) {
318  std::cout << "failed propagation, return track1 start pos=" << tk1.Start() << std::endl;
319  VertexWrapper vtx;
321  tk1.Start(), tk1.VertexCovarianceGlobal6D().Sub<SMatrixSym33>(0, 0), 0, 0, tk1);
322  return vtx;
323  }
324 
325  if (debugLevel > 0) {
326  std::cout << "track1 pca=" << start1 + dist1 * dir1 << " dist=" << dist1 << std::endl;
327  std::cout << "track2 pca=" << start2 + dist2 * dir2 << " dist=" << dist2 << std::endl;
328  }
329 
330  //here we neglect that to find dist1 and dist2 one track depends on the other...
331  SMatrixSym22 cov1 = state1.covariance().Sub<SMatrixSym22>(0, 0);
332  SMatrixSym22 cov2 = state2.covariance().Sub<SMatrixSym22>(0, 0);
333 
334  if (debugLevel > 1) {
335  std::cout << "target pos=" << target.position() << " dir=" << target.direction() << std::endl;
336  //test if orthogonal
337  auto dcp = state1.position() - state2.position();
338  std::cout << "dot dcp-dir1=" << dcp.Dot(tk1.Trajectory().StartDirection()) << std::endl;
339  std::cout << "dot dcp-dir2=" << dcp.Dot(tk2.Trajectory().StartDirection()) << std::endl;
340 
341  std::cout << "cov1=" << cov1 << std::endl;
342  std::cout << "cov2=" << cov2 << std::endl;
343  }
344 
345  SVector2 par1(state1.parameters()[0], state1.parameters()[1]);
346  SVector2 par2(state2.parameters()[0], state2.parameters()[1]);
347 
348  std::pair<TrackState, double> was = weightedAverageState(par1, par2, cov1, cov2, target);
349  if (was.second <= (util::kBogusD - 1)) {
350  std::cout << "failed inversion, return track1 start pos=" << tk1.Start() << std::endl;
351  VertexWrapper vtx;
353  tk1.Start(), tk1.VertexCovarianceGlobal6D().Sub<SMatrixSym33>(0, 0), 0, 0, tk1);
354  return vtx;
355  }
356 
357  const int ndof = 1; //1=2*2-3; each measurement is 2D because it is defined on a plane
359  was.first.position(), was.first.covariance6D().Sub<SMatrixSym33>(0, 0), was.second, ndof);
360  vtx.addTrack(tk1);
361  vtx.addTrack(tk2);
362 
363  if (debugLevel > 0) {
364  std::cout << "vtxpos=" << vtx.position() << std::endl;
365  std::cout << "vtxcov=\n" << vtx.covariance() << std::endl;
366  std::cout << "chi2=" << was.second << std::endl;
367  }
368 
369  return vtx;
370 }
371 
374  const trkf::VertexWrapper& vtx,
375  const recob::Track& tk) const
376 {
377  auto start = tk.Trajectory().Start();
378  auto dir = tk.Trajectory().StartDirection();
379 
380  auto vtxpos = vtx.position();
381  auto vtxcov = vtx.covariance();
382 
383  auto dist = dir.Dot(vtxpos - start);
384 
385  //by construction vtxpos also lies on this plane
386  recob::tracking::Plane target(start + dist * dir, dir);
387 
388  recob::tracking::Plane plane(start, dir);
389  trkf::TrackState state(
390  tk.VertexParametersLocal5D(), tk.VertexCovarianceLocal5D(), plane, true, tk.ParticleId());
391  bool propok = true;
392  state = prop->propagateToPlane(
393  propok, detProp, state, target, true, true, trkf::TrackStatePropagator::UNKNOWN);
394 
395  if (debugLevel > 0) {
396  std::cout << "input vtx=" << vtxpos << std::endl;
397  std::cout << "input cov=\n" << vtxcov << std::endl;
398  std::cout << "track pca=" << start + dist * dir << " dist=" << dist << std::endl;
399  std::cout << "target pos=" << target.position() << " dir=" << target.direction() << std::endl;
400  }
401 
402  //rotate the vertex position and covariance to the target plane
403  SVector6 vtxpar6(vtxpos.X(), vtxpos.Y(), vtxpos.Z(), 0, 0, 0);
404  SMatrixSym66 vtxcov66;
405  vtxcov66.Place_at(vtxcov, 0, 0);
406 
407  auto vtxpar5 = target.Global6DToLocal5DParameters(vtxpar6);
408  SVector2 par1(vtxpar5[0], vtxpar5[1]);
409  SVector2 par2(state.parameters()[0], state.parameters()[1]);
410 
411  //here we neglect that to find dist, the vertex is used...
412  SMatrixSym22 cov1 =
413  target.Global6DToLocal5DCovariance(vtxcov66, false, Vector_t()).Sub<SMatrixSym22>(0, 0);
414  SMatrixSym22 cov2 = state.covariance().Sub<SMatrixSym22>(0, 0);
415 
416  if (debugLevel > 1) {
417  std::cout << "vtxpar5=" << vtxpar5 << std::endl;
418  std::cout << "state.parameters()=" << state.parameters() << std::endl;
419  std::cout << "vtx covariance=\n" << vtxcov66 << std::endl;
420  std::cout << "trk covariance=\n" << state.covariance6D() << std::endl;
421  std::cout << "cov1=\n" << cov1 << std::endl;
422  std::cout << "cov2=\n" << cov2 << std::endl;
423  }
424 
425  return ParsCovsOnPlane(par1, par2, cov1, cov2, target);
426 }
427 
428 void
430  trkf::VertexWrapper& vtx,
431  const recob::Track& tk) const
432 {
433 
434  if (debugLevel > 0) {
435  std::cout << "adding track with start=" << tk.Start() << " dir=" << tk.StartDirection()
436  << " length=" << tk.Length() << " points=" << tk.CountValidPoints() << std::endl;
437  std::cout << "covariance=\n" << tk.VertexCovarianceGlobal6D() << std::endl;
438  }
439 
440  ParsCovsOnPlane pcp = getParsCovsOnPlane(detProp, vtx, tk);
441  std::pair<TrackState, double> was = weightedAverageState(pcp);
442  if (was.second <= (util::kBogusD - 1.)) { return; }
443 
444  const int ndof = 2; // Each measurement is 2D because it is defined on a plane
446  was.first.position(), was.first.covariance6D().Sub<SMatrixSym33>(0, 0), was.second, ndof, tk);
447 
448  if (debugLevel > 0) {
449  std::cout << "updvtxpos=" << vtx.position() << std::endl;
450  std::cout << "updvtxcov=\n" << vtx.covariance() << std::endl;
451  std::cout << "add chi2=" << was.second << std::endl;
452  }
453 }
454 
455 double
457 {
458  const SVector2 deltapar = pcp.par2 - pcp.par1;
459  SMatrixSym22 covsum = (pcp.cov2 + pcp.cov1);
460 
461  bool invertok = covsum.Invert();
462  if (!invertok) return -1.;
463 
464  return ROOT::Math::Similarity(deltapar, covsum);
465 }
466 
467 double
469  const VertexWrapper& vtx,
470  const recob::Track& tk) const
471 {
472  return chi2(getParsCovsOnPlane(detProp, vtx, tk));
473 }
474 
475 double
477 {
478  const SVector2 deltapar = pcp.par2 - pcp.par1;
479  return std::sqrt(deltapar[0] * deltapar[0] + deltapar[1] * deltapar[1]);
480 }
481 
482 double
484  const VertexWrapper& vtx,
485  const recob::Track& tk) const
486 {
487  return ip(getParsCovsOnPlane(detProp, vtx, tk));
488 }
489 
490 double
493 {
494  SVector2 deltapar = pcp.par2 - pcp.par1;
495  deltapar /= std::sqrt(deltapar[0] * deltapar[0] + deltapar[1] * deltapar[1]);
496  SMatrixSym22 covsum = (pcp.cov2 + pcp.cov1);
497  return std::sqrt(ROOT::Math::Similarity(deltapar, covsum));
498 }
499 
500 double
502  const VertexWrapper& vtx,
503  const recob::Track& tk) const
504 {
505  return ipErr(getParsCovsOnPlane(detProp, vtx, tk));
506 }
507 
508 double
510 {
511  return ip(pcp) / ipErr(pcp);
512 }
513 
514 double
516  const VertexWrapper& vtx,
517  const recob::Track& tk) const
518 {
519  return sip(getParsCovsOnPlane(detProp, vtx, tk));
520 }
521 
522 double
524 {
525  return tk.Trajectory().StartDirection().Dot(vtx.position() - tk.Trajectory().Start());
526 }
527 
530  const trkf::VertexWrapper& vtx,
531  const recob::Track& tk) const
532 {
533  auto ittoerase = vtx.findTrack(tk);
534  if (ittoerase == vtx.tracksSize()) { return vtx; }
535  else {
536  auto tks = vtx.tracksWithoutElement(ittoerase);
537  return fitTracks(detProp, tks);
538  }
539 }
540 
541 double
543  const trkf::VertexWrapper& vtx,
544  const recob::Track& tk) const
545 {
546  auto ittoerase = vtx.findTrack(tk);
547  if (ittoerase == vtx.tracksSize()) { return chi2(detProp, vtx, tk); }
548  else {
549  auto tks = vtx.tracksWithoutElement(ittoerase);
550  return chi2(detProp, fitTracks(detProp, tks), tk);
551  }
552 }
553 
554 double
556  const trkf::VertexWrapper& vtx,
557  const recob::Track& tk) const
558 {
559  auto ittoerase = vtx.findTrack(tk);
560  if (ittoerase == vtx.tracksSize()) { return ip(detProp, vtx, tk); }
561  else {
562  auto tks = vtx.tracksWithoutElement(ittoerase);
563  return ip(detProp, fitTracks(detProp, tks), tk);
564  }
565 }
566 
567 double
569  const trkf::VertexWrapper& vtx,
570  const recob::Track& tk) const
571 {
572  auto ittoerase = vtx.findTrack(tk);
573  if (ittoerase == vtx.tracksSize()) { return ipErr(detProp, vtx, tk); }
574  else {
575  auto tks = vtx.tracksWithoutElement(ittoerase);
576  return ipErr(detProp, fitTracks(detProp, tks), tk);
577  }
578 }
579 
580 double
582  const trkf::VertexWrapper& vtx,
583  const recob::Track& tk) const
584 {
585  auto ittoerase = vtx.findTrack(tk);
586  if (ittoerase == vtx.tracksSize()) { return sip(detProp, vtx, tk); }
587  else {
588  auto tks = vtx.tracksWithoutElement(ittoerase);
589  return sip(detProp, fitTracks(detProp, tks), tk);
590  }
591 }
592 
593 double
595  const trkf::VertexWrapper& vtx,
596  const recob::Track& tk) const
597 {
598  auto ittoerase = vtx.findTrack(tk);
599  if (ittoerase == vtx.tracksSize()) { return pDist(vtx, tk); }
600  else {
601  auto tks = vtx.tracksWithoutElement(ittoerase);
602  return pDist(fitTracks(detProp, tks), tk);
603  }
604 }
605 
606 std::vector<recob::VertexAssnMeta>
608  const VertexWrapper& vtx)
609 {
610  return computeMeta(detProp, vtx, vtx.tracks());
611 }
612 
613 std::vector<recob::VertexAssnMeta>
615  const VertexWrapper& vtx,
616  const std::vector<art::Ptr<recob::Track>>& arttracks)
617 {
619  for (auto t : arttracks)
620  tracks.push_back(*t);
621  return computeMeta(detProp, vtx, tracks);
622 }
623 
624 std::vector<recob::VertexAssnMeta>
626  const VertexWrapper& vtx,
627  const TrackRefVec& trks)
628 {
629  std::vector<recob::VertexAssnMeta> result;
630  for (auto tk : trks) {
631  float d = util::kBogusF;
632  float i = util::kBogusF;
633  float e = util::kBogusF;
634  float c = util::kBogusF;
635  auto ittoerase = vtx.findTrack(tk);
636  if (debugLevel > 1)
637  std::cout << "computeMeta for vertex with ntracks=" << vtx.tracksSize() << std::endl;
638  auto ubvtx = unbiasedVertex(detProp, vtx, tk.get());
639  if (debugLevel > 1)
640  std::cout << "got unbiased vertex with ntracks=" << ubvtx.tracksSize()
641  << " isValid=" << ubvtx.isValid() << std::endl;
642  if (ubvtx.isValid()) {
643  d = pDist(ubvtx, tk.get());
644  auto pcop = getParsCovsOnPlane(detProp, ubvtx, tk.get());
645  i = ip(pcop);
646  e = ipErr(pcop);
647  c = chi2(pcop);
648  if (debugLevel > 1)
649  std::cout << "unbiasedVertex d=" << d << " i=" << i << " e=" << e << " c=" << c
650  << std::endl;
651  }
652  else if (vtx.tracksSize() == 2 && ittoerase != vtx.tracksSize()) {
653  auto tks = vtx.tracksWithoutElement(ittoerase);
654  auto fakevtx = closestPointAlongTrack(detProp, tks[0], tk);
655  d = pDist(fakevtx, tk.get());
656  // these will be identical for the two tracks (modulo numerical instabilities in the matrix inversion for the chi2)
657  auto pcop = getParsCovsOnPlane(detProp, fakevtx, tk.get());
658  i = ip(pcop);
659  e = ipErr(pcop);
660  c = chi2(pcop);
661  if (debugLevel > 1)
662  std::cout << "closestPointAlongTrack d=" << d << " i=" << i << " e=" << e << " c=" << c
663  << std::endl;
664  }
665  if (ittoerase == vtx.tracksSize()) {
666  result.push_back(recob::VertexAssnMeta(d, i, e, c, recob::VertexAssnMeta::NotUsedInFit));
667  }
668  else {
669  result.push_back(recob::VertexAssnMeta(d, i, e, c, recob::VertexAssnMeta::IncludedInFit));
670  }
671  }
672  return result;
673 }
void addTrackToVertex(detinfo::DetectorPropertiesData const &detProp, VertexWrapper &vtx, const recob::Track &tk) const
const recob::tracking::Point_t & position() const
Definition: VertexWrapper.h:38
Class for track parameters (and errors) defined on a recob::tracking::Plane.
Definition: TrackState.h:79
Vector_t const & direction() const
Reference direction orthogonal to the plane.
Definition: TrackingPlane.h:70
std::pair< TrackState, double > weightedAverageState(ParsCovsOnPlane &pcop) const
TrackRefVec tracksWithoutElement(size_t element) const
Definition: VertexWrapper.h:59
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
double sip(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
Definition: PFParticle.h:89
static QCString result
const recob::tracking::SMatrixSym33 & covariance() const
Definition: VertexWrapper.h:39
VertexWrapper closestPointAlongTrack(detinfo::DetectorPropertiesData const &detProp, const recob::Track &track, const recob::Track &other) const
VertexWrapper fitTracksWithVtx(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Track >> &tracks, const recob::tracking::Point_t &vtxPos) const
int ParticleId() const
Definition: Track.h:171
bool isValid() const
Definition: VertexWrapper.h:37
recob::tracking::Vector_t Vector_t
Definition: TrackState.h:19
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:98
Wrapper class to facilitate vertex production.
Definition: VertexWrapper.h:28
recob::tracking::SVector2 SVector2
recob::tracking::SMatrixSym55 SMatrixSym55
Definition: TrackState.h:15
struct vector vector
void addTrack(const recob::Track &tk)
Definition: VertexWrapper.h:43
void addTrackAndUpdateVertex(const recob::tracking::Point_t &pos, const recob::tracking::SMatrixSym33 &cov, double chi2, int ndof, const recob::Track &tk)
Definition: VertexWrapper.h:44
recob::tracking::SMatrixSym22 SMatrixSym22
SVector5 VertexParametersLocal5D() const
Accessors to track parameters and covariance matrices in Local5D and Global6D coordinates.
Definition: Track.cxx:71
SVector5 Global6DToLocal5DParameters(const SVector6 &par6d) const
Function to convert parameters from global to local coordinates. Local coordinates are on the plane w...
Definition: TrackingPlane.h:74
STL namespace.
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
std::vector< recob::VertexAssnMeta > computeMeta(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx)
string dir
double ip(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
double ipErr(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
VertexWrapper unbiasedVertex(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
double sipUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
SMatrixSym66 VertexCovarianceGlobal6D() const
Definition: Track.cxx:81
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
unsigned int CountValidPoints() const
Definition: Track.h:112
size_t tracksSize() const
Definition: VertexWrapper.h:57
VertexWrapper fitTwoTracks(detinfo::DetectorPropertiesData const &detProp, const recob::Track &tk1, const recob::Track &tk2) const
Vector_t StartDirection() const
Access to track direction at different points.
Definition: Track.h:131
const TrackRefVec & tracks() const
Definition: VertexWrapper.h:58
const double e
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
recob::tracking::SVector5 SVector5
Definition: TrackState.h:12
Point_t const & Start() const
Access to track position at different points.
Definition: Track.h:123
void swap(Handle< T > &a, Handle< T > &b)
Point_t const & position() const
Reference position on the plane.
Definition: TrackingPlane.h:66
const double a
Class storing the meta-data for track-vertex association: status, propagation distance, impact parameter, impact parameter error, chi2.
std::unique_ptr< TrackStatePropagator > prop
double pDistUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:86
VertexWrapper fitTracks(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Track >> &arttracks) const
ParsCovsOnPlane getParsCovsOnPlane(detinfo::DetectorPropertiesData const &detProp, const trkf::VertexWrapper &vtx, const recob::Track &tk) const
Class defining a plane for tracking. It provides various functionalities to convert track parameters ...
Definition: TrackingPlane.h:37
VertexWrapper fitPFP(detinfo::DetectorPropertiesData const &detProp, size_t iPF, const art::ValidHandle< std::vector< recob::PFParticle >> &inputPFParticle, const std::unique_ptr< art::FindManyP< recob::Track >> &assocTracks) const
Definition: tracks.py:1
constexpr float kBogusF
obviously bogus float value
double pDist(const VertexWrapper &vtx, const recob::Track &tk) const
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
double chi2(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
recob::tracking::SMatrixSym66 SMatrixSym66
Definition: TrackState.h:16
double ipErrUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
static bool * b
Definition: config.cpp:1043
recob::tracking::SMatrixSym33 SMatrixSym33
recob::tracking::SVector6 SVector6
Definition: TrackState.h:13
constexpr double kBogusD
obviously bogus double value
SMatrixSym55 Global6DToLocal5DCovariance(SMatrixSym66 cov6d, bool hasMomentum, const Vector_t &trackMomOrDir) const
Translate track covariance from global to local coordinates. The track momentum (or direction) is nee...
double ipUnbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
size_t findTrack(const recob::Track &tk) const
Definition: VertexWrapper.h:50
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space. See recob::tracking::Coord_t for more detai...
Definition: TrackingTypes.h:26
const SMatrixSym55 & VertexCovarianceLocal5D() const
Definition: Track.h:206
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
double chi2Unbiased(detinfo::DetectorPropertiesData const &detProp, const VertexWrapper &vtx, const recob::Track &tk) const
QTextStream & endl(QTextStream &s)
std::vector< std::reference_wrapper< const recob::Track > > TrackRefVec
Definition: VertexWrapper.h:26