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