3 #include "canvas/Persistency/Common/Ptr.h"
4 #include "messagefacility/MessageLogger/MessageLogger.h"
14 #include "Math/BinaryOperators.h"
15 #include "Math/Expression.h"
16 #include "Math/GenVector/Cartesian3D.h"
17 #include "Math/GenVector/DisplacementVector3D.h"
18 #include "Math/GenVector/PositionVector3D.h"
19 #include "Math/MatrixRepresentationsStatic.h"
20 #include "Math/SMatrix.h"
45 const bool flipDirection,
50 auto position = traj.
Vertex();
55 std::vector<art::Ptr<recob::Hit>> fwdHits;
72 std::vector<art::Ptr<recob::Hit>> bwdHits;
88 if (okfwd ==
false && okbwd ==
false) {
return false; }
89 else if (okfwd ==
true && okbwd ==
true) {
90 if ((fwdTrack.CountValidPoints() / (fwdTrack.Length() * fwdTrack.Chi2PerNdof())) >=
91 (bwdTrack.CountValidPoints() / (bwdTrack.Length() * bwdTrack.Chi2PerNdof()))) {
94 optionals = std::move(fwdoptionals);
99 optionals = std::move(bwdoptionals);
102 else if (okfwd ==
true) {
105 optionals = std::move(fwdoptionals);
110 optionals = std::move(bwdoptionals);
116 position = traj.
End();
120 auto trackStateCov = (flipDirection ? covEnd : covVtx);
143 const std::vector<recob::TrajectoryPointFlags>& flags,
152 std::cout <<
"Fitting track with tkID=" << tkID <<
" start pos=" << position
153 <<
" dir=" << direction <<
" nHits=" << hits.size() <<
" mom=" << pval
154 <<
" pdg=" << pdgid << std::endl;
155 if (hits.size() < 4) {
156 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failure at " << __FILE__ <<
" " << __LINE__;
161 KFTrackState trackState = setupInitialTrackState(position, direction, trackStateCov, pval, pdgid);
165 std::vector<HitState> hitstatev;
166 std::vector<recob::TrajectoryPointFlags::Mask_t> hitflagsv;
167 bool inputok = setupInputStates(detProp, hits, flags, trackState, hitstatev, hitflagsv);
168 if (!inputok)
return false;
171 std::vector<KFTrackState> fwdPrdTkState;
172 std::vector<KFTrackState> fwdUpdTkState;
173 std::vector<unsigned int> hitstateidx;
174 std::vector<unsigned int> rejectedhsidx;
175 std::vector<unsigned int> sortedtksidx;
178 bool fitok = doFitWork(trackState,
187 if (!fitok && (skipNegProp_ || cleanZigzag_) && tryNoSkipWhenFails_) {
188 mf::LogWarning(
"TrackKalmanFitter")
189 <<
"Trying to recover with skipNegProp = false and cleanZigzag = false\n";
190 fitok = doFitWork(trackState,
202 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failed for track with ID=" << tkID <<
"\n";
207 bool fillok = fillResult(hits,
228 const int pdgid)
const
232 trackStateCov(0, 0) = 1000.;
233 trackStateCov(1, 1) = 1000.;
234 trackStateCov(2, 2) = 0.25;
235 trackStateCov(3, 3) = 0.25;
236 trackStateCov(4, 4) = 10.;
239 trackStateCov *= 100.;
241 SVector5 trackStatePar(0., 0., 0., 0., 1. / pval);
244 Plane(position, direction),
253 const std::vector<recob::TrajectoryPointFlags>& flags,
255 std::vector<HitState>& hitstatev,
256 std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv)
const
259 std::cout <<
"flags.size()=" << flags.size() <<
" hits.size()=" << hits.size() << std::endl;
263 const size_t fsize = flags.size();
264 for (
size_t ihit = 0; ihit != hits.size(); ihit++) {
265 const auto&
hit = hits[ihit];
266 double t =
hit->PeakTime();
267 double terr = (useRMS_ ?
hit->RMS() :
hit->SigmaPeakTime());
271 hitstatev.emplace_back(
272 x, hitErr2ScaleFact_ * xerr * xerr,
hit->WireID(), geom->WireIDToWireGeo(
hit->WireID()));
274 if (fsize > 0 && ihit < fsize)
275 hitflagsv.push_back(flags[ihit].
mask());
279 if (rejectHighMultHits_ &&
hit->Multiplicity() > 1) {
283 if (rejectHitsNegativeGOF_ &&
hit->GoodnessOfFit() < 0) {
289 std::cout <<
"pushed flag mask=" << hitflagsv.back()
296 if (dumpLevel_ > 2) assert(hits.size() == hitstatev.size());
303 std::vector<HitState>& hitstatev,
304 std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv,
305 std::vector<KFTrackState>& fwdPrdTkState,
306 std::vector<KFTrackState>& fwdUpdTkState,
307 std::vector<unsigned int>& hitstateidx,
308 std::vector<unsigned int>& rejectedhsidx,
309 std::vector<unsigned int>& sortedtksidx,
310 bool applySkipClean)
const
312 fwdPrdTkState.clear();
313 fwdUpdTkState.clear();
315 rejectedhsidx.clear();
316 sortedtksidx.clear();
318 fwdPrdTkState.reserve(hitstatev.size());
319 fwdUpdTkState.reserve(hitstatev.size());
320 hitstateidx.reserve(hitstatev.size());
325 if (sortHitsByPlane_) {
327 const unsigned int nplanes = geom->MaxPlanes();
328 std::vector<std::vector<unsigned int>> hitsInPlanes(nplanes);
329 for (
unsigned int ihit = 0; ihit < hitstatev.size(); ihit++) {
330 hitsInPlanes[hitstatev[ihit].wireId().Plane].push_back(ihit);
332 if (sortHitsByWire_) {
333 for (
unsigned int iplane = 0; iplane < nplanes; ++iplane) {
334 if (geom->Plane(iplane).GetIncreasingWireDirection<
Vector_t>().Dot(trackState.
momentum()) >
336 std::sort(hitsInPlanes[iplane].
begin(),
337 hitsInPlanes[iplane].
end(),
338 [hitstatev](
const unsigned int&
a,
const unsigned int& b) ->
bool {
339 return hitstatev[
a].wireId().Wire < hitstatev[b].wireId().Wire;
343 std::sort(hitsInPlanes[iplane].
begin(),
344 hitsInPlanes[iplane].
end(),
345 [hitstatev](
const unsigned int&
a,
const unsigned int& b) ->
bool {
346 return hitstatev[
a].wireId().Wire > hitstatev[b].wireId().Wire;
353 if (dumpLevel_ > 1) {
355 for (
auto p : hitsInPlanes) {
357 std::cout <<
"hit #/Plane/Wire/x/mask: " << ch++ <<
" " << hitstatev[
h].wireId().Plane
358 <<
" " << hitstatev[
h].wireId().Wire <<
" " << hitstatev[
h].hitMeas() <<
" "
359 << hitflagsv[
h] << std::endl;
365 std::vector<unsigned int> iterHitsInPlanes(nplanes, 0);
366 for (
unsigned int p = 0;
p < hitstatev.size(); ++
p) {
367 if (dumpLevel_ > 1)
std::cout << std::endl <<
"processing hit #" <<
p << std::endl;
369 std::cout <<
"hit sizes: rej=" << rejectedhsidx.size() <<
" good=" << hitstateidx.size()
370 <<
" input=" << hitstatev.size() << std::endl;
371 if (dumpLevel_ > 1) {
372 std::cout <<
"compute distance from state=" << std::endl;
376 double min_dist = DBL_MAX;
378 for (
unsigned int iplane = 0; iplane < nplanes; ++iplane) {
381 std::cout <<
"iplane=" << iplane <<
" nplanes=" << nplanes
382 <<
" iterHitsInPlanes[iplane]=" << iterHitsInPlanes[iplane]
383 <<
" hitsInPlanes[iplane].size()=" << hitsInPlanes[iplane].size() << std::endl;
384 for (
unsigned int& ih = iterHitsInPlanes[iplane]; ih < hitsInPlanes[iplane].size(); ++ih) {
386 unsigned int ihit = hitsInPlanes[iplane][ih];
388 std::cout <<
"ih=" << ih <<
" ihit=" << ihit <<
" size=" << hitsInPlanes[iplane].size()
390 const auto& hitstate = hitstatev[ihit];
391 const auto& hitflags = hitflagsv[ihit];
400 << hitflags << std::endl;
401 rejectedhsidx.push_back(ihit);
407 propagator->distanceToPlane(success, trackState.
trackState(), hitstate.
plane());
409 std::cout <<
"distance to plane " << iplane <<
" wire=" << hitstate.wireId().Wire
410 <<
" = " << dist <<
", min_dist=" << std::min(min_dist, 999.)
411 <<
" min_plane=" << min_plane <<
" success=" << success
412 <<
" wirepo=" << hitstate.plane().position() << std::endl;
414 rejectedhsidx.push_back(ihit);
417 if (applySkipClean && skipNegProp_ && fwdUpdTkState.size() > 0 &&
418 dist < negDistTolerance_) {
419 rejectedhsidx.push_back(ihit);
422 if (dist < min_dist) {
431 <<
"pick min_dist=" << min_dist <<
" min_plane=" << min_plane <<
" wire="
434 hitstatev[hitsInPlanes[min_plane][iterHitsInPlanes[min_plane]]].wireId().Wire)
439 if (rejectedhsidx.size() + hitstateidx.size() == hitstatev.size())
444 unsigned int ihit = hitsInPlanes[min_plane][iterHitsInPlanes[min_plane]];
445 const auto* hitstate = &hitstatev[ihit];
446 iterHitsInPlanes[min_plane]++;
450 trackState = propagator->propagateToPlane(propok,
457 if (!propok && !(applySkipClean && fwdUpdTkState.size() > 0 && skipNegProp_)) {
458 if (dumpLevel_ > 1)
std::cout <<
"attempt backward prop" << std::endl;
459 trackState = propagator->propagateToPlane(propok,
467 if (dumpLevel_ > 1) {
470 std::cout <<
"propagation result=" << propok << std::endl;
471 std::cout <<
"propagated state " << std::endl;
474 << hitstate->plane().direction().Dot(hitstate->plane().position() -
478 <<
" chi2=" << trackState.
chi2(*hitstate) << std::endl;
483 if (applySkipClean && fwdUpdTkState.size() == 0 &&
486 std::cout <<
"rejecting first hit with residual=" << trackState.
residual(*hitstate)
488 rejectedhsidx.push_back(ihit);
489 trackState = startState;
494 if (pickBestHitOnWire_) {
495 auto wire = hitstate->wireId().Wire;
496 float min_chi2_wire = trackState.
chi2(*hitstate);
497 for (
unsigned int jh = iterHitsInPlanes[min_plane]; jh < hitsInPlanes[min_plane].size();
499 const unsigned int jhit = hitsInPlanes[min_plane][jh];
500 const auto& jhitstate = hitstatev[jhit];
501 if (jhitstate.wireId().Wire != wire)
break;
502 if (ihit != jhit) iterHitsInPlanes[min_plane]++;
503 float chi2 = trackState.
chi2(jhitstate);
504 if (dumpLevel_ > 1 && ihit != jhit)
505 std::cout <<
"additional hit on the same wire with jhit=" << jhit <<
" chi2=" << chi2
506 <<
" ihit=" << ihit <<
" min_chi2_wire=" << min_chi2_wire << std::endl;
507 if (chi2 < min_chi2_wire) {
508 min_chi2_wire = chi2;
509 if (dumpLevel_ > 1 && ihit != jhit) {
513 if (ihit != jhit) rejectedhsidx.push_back(ihit);
517 rejectedhsidx.push_back(jhit);
522 hitstate = &hitstatev[ihit];
523 auto& hitflags = hitflagsv[ihit];
526 if (fwdUpdTkState.size() > 0 && applySkipClean &&
528 trackState.
chi2(*hitstate) > maxChi2_ || min_dist > maxDist_)) {
532 <<
" chi2=" << trackState.
chi2(*hitstate) <<
" dist=" << min_dist
535 if (fwdUpdTkState.size() > 0)
536 trackState = fwdUpdTkState.back();
538 trackState = startState;
539 rejectedhsidx.push_back(ihit);
547 hitstateidx.push_back(ihit);
548 fwdPrdTkState.push_back(trackState);
559 if (fwdUpdTkState.size() > 0)
560 trackState = fwdUpdTkState.back();
562 trackState = startState;
563 fwdUpdTkState.push_back(trackState);
573 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failure at " << __FILE__ <<
" " << __LINE__;
576 if (dumpLevel_ > 1) {
577 std::cout <<
"updated state " << std::endl;
580 fwdUpdTkState.push_back(trackState);
584 std::cout <<
"WARNING: forward propagation failed. Skip this hit..." << std::endl;
586 if (fwdPrdTkState.size() > 0)
587 trackState = fwdPrdTkState.back();
589 trackState = startState;
590 rejectedhsidx.push_back(ihit);
593 if (rejectedhsidx.size() + hitstateidx.size() == hitstatev.size())
break;
597 for (
unsigned int ihit = 0; ihit < hitstatev.size(); ++ihit) {
598 const auto& hitstate = hitstatev[ihit];
599 if (dumpLevel_ > 1) {
600 std::cout << std::endl <<
"processing hit #" << ihit << std::endl;
603 auto& hitflags = hitflagsv[ihit];
606 rejectedhsidx.push_back(ihit);
611 propagator->distanceToPlane(success, trackState.
trackState(), hitstate.
plane());
612 if (applySkipClean && fwdUpdTkState.size() > 0 && skipNegProp_) {
613 if (dist < 0. || success ==
false) {
615 std::cout <<
"WARNING: negative propagation distance. Skip this hit..." << std::endl;
617 rejectedhsidx.push_back(ihit);
623 trackState = propagator->propagateToPlane(propok,
630 if (!propok && !(applySkipClean && skipNegProp_))
631 trackState = propagator->propagateToPlane(propok,
639 hitstateidx.push_back(ihit);
640 fwdPrdTkState.push_back(trackState);
648 (fwdUpdTkState.size() > 0 && applySkipClean &&
650 trackState.
chi2(hitstate) > maxChi2_ || dist > maxDist_))) {
653 <<
" chi2=" << trackState.
chi2(hitstate) <<
" dist=" << dist << std::endl;
655 if (fwdUpdTkState.size() > 0)
656 trackState = fwdUpdTkState.back();
658 trackState = startState;
659 fwdUpdTkState.push_back(trackState);
669 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failure at " << __FILE__ <<
" " << __LINE__;
672 fwdUpdTkState.push_back(trackState);
676 std::cout <<
"WARNING: forward propagation failed. Skip this hit..." << std::endl;
679 if (fwdPrdTkState.size() > 0)
680 trackState = fwdPrdTkState.back();
682 trackState = startState;
683 rejectedhsidx.push_back(ihit);
689 if (dumpLevel_ > 2) assert(rejectedhsidx.size() + hitstateidx.size() == hitstatev.size());
690 if (dumpLevel_ > 0) {
691 std::cout <<
"TRACK AFTER FWD" << std::endl;
692 std::cout <<
"hit sizes=" << rejectedhsidx.size() <<
" " << hitstateidx.size() <<
" "
693 << hitstatev.size() << std::endl;
700 startState = trackState;
704 for (
int itk = fwdPrdTkState.size() - 1; itk >= 0; itk--) {
705 auto& fwdPrdTrackState = fwdPrdTkState[itk];
706 auto& fwdUpdTrackState = fwdUpdTkState[itk];
707 const auto& hitstate = hitstatev[hitstateidx[itk]];
708 auto& hitflags = hitflagsv[hitstateidx[itk]];
709 if (dumpLevel_ > 1) {
710 std::cout << std::endl <<
"processing backward hit #" << itk << std::endl;
714 trackState = propagator->propagateToPlane(propok,
722 trackState = propagator->propagateToPlane(propok,
730 if (dumpLevel_ > 1) {
731 std::cout <<
"propagation result=" << propok << std::endl;
732 std::cout <<
"propagated state " << std::endl;
735 << hitstate.plane().direction().Dot(hitstate.plane().position() -
741 bool pcombok = fwdPrdTrackState.combineWithTrackState(trackState.
trackState());
743 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failure at " << __FILE__ <<
" " << __LINE__;
746 if (dumpLevel_ > 1) {
747 std::cout <<
"combined prd state " << std::endl;
748 fwdPrdTrackState.dump();
752 bool ucombok = fwdUpdTrackState.combineWithTrackState(trackState.
trackState());
754 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failure at " << __FILE__ <<
" " << __LINE__;
757 if (dumpLevel_ > 1) {
758 std::cout <<
"combined upd state " << std::endl;
759 fwdUpdTrackState.dump();
763 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failure at " << __FILE__ <<
" " << __LINE__;
766 if (dumpLevel_ > 1) {
767 std::cout <<
"updated state " << std::endl;
771 startState = trackState;
776 fwdUpdTrackState = fwdPrdTrackState;
787 std::cout <<
"WARNING: backward propagation failed. Skip this hit... hitstateidx[itk]="
788 << hitstateidx[itk] <<
" itk=" << itk << std::endl;
791 trackState = startState;
796 if (nvalidhits < 4) {
797 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failure at " << __FILE__ <<
" " << __LINE__ <<
" ";
801 if (dumpLevel_ > 1)
std::cout <<
"sort output with nvalidhits=" << nvalidhits << std::endl;
805 hitstatev, fwdUpdTkState, hitstateidx, rejectedhsidx, sortedtksidx, hitflagsv, applySkipClean);
806 size_t nsortvalid = 0;
807 for (
auto& idx : sortedtksidx) {
808 auto& hitflags = hitflagsv[hitstateidx[idx]];
811 if (nsortvalid < 4) {
812 mf::LogWarning(
"TrackKalmanFitter") <<
"Fit failure at " << __FILE__ <<
" " << __LINE__ <<
" ";
816 if (dumpLevel_ > 2) assert(rejectedhsidx.size() + sortedtksidx.size() == hitstatev.size());
822 std::vector<KFTrackState>& fwdUpdTkState,
823 std::vector<unsigned int>& hitstateidx,
824 std::vector<unsigned int>& rejectedhsidx,
825 std::vector<unsigned int>& sortedtksidx,
826 std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv,
827 bool applySkipClean)
const
830 if (sortOutputHitsMinLength_) {
832 const unsigned int nplanes = geom->MaxPlanes();
833 std::vector<std::vector<unsigned int>> tracksInPlanes(nplanes);
834 for (
unsigned int p = 0;
p < hitstateidx.size(); ++
p) {
835 const auto& hitstate = hitstatev[hitstateidx[
p]];
836 tracksInPlanes[hitstate.wireId().Plane].push_back(
p);
838 if (dumpLevel_ > 2) {
839 for (
auto s : fwdUpdTkState) {
840 std::cout <<
"state pos=" <<
s.position() << std::endl;
844 std::vector<unsigned int> iterTracksInPlanes;
845 for (
auto it : tracksInPlanes)
846 iterTracksInPlanes.push_back(0);
847 auto pos = fwdUpdTkState.front().position();
848 auto dir = fwdUpdTkState.front().momentum();
850 for (; p < fwdUpdTkState.size(); ++
p) {
852 pos = fwdUpdTkState[
p].position();
853 dir = fwdUpdTkState[
p].momentum();
855 std::cout <<
"sort output found point not excluded with p=" << p
856 <<
" hitstateidx[p]=" << hitstateidx[
p] <<
" pos=" << pos << std::endl;
860 rejectedhsidx.push_back(hitstateidx[p]);
864 std::cout <<
"sort output init with pos=" << pos <<
" dir=" <<
dir << std::endl;
866 for (; p < fwdUpdTkState.size(); ++
p) {
868 double min_dotp = DBL_MAX;
869 for (
unsigned int iplane = 0; iplane < iterTracksInPlanes.size(); ++iplane) {
870 for (
unsigned int& itk = iterTracksInPlanes[iplane]; itk < tracksInPlanes[iplane].size();
872 auto& trackstate = fwdUpdTkState[tracksInPlanes[iplane][iterTracksInPlanes[iplane]]];
873 auto& tmppos = trackstate.position();
874 const double dotp =
dir.Dot(tmppos - pos);
876 std::cout <<
"iplane=" << iplane <<
" tmppos=" << tmppos <<
" tmpdir=" << tmppos - pos
877 <<
" dotp=" << dotp << std::endl;
878 if (dotp < min_dotp) {
885 if (min_plane < 0)
continue;
886 const unsigned int ihit = tracksInPlanes[min_plane][iterTracksInPlanes[min_plane]];
887 if (applySkipClean && skipNegProp_ && min_dotp < negDistTolerance_ &&
888 sortedtksidx.size() > 0) {
890 std::cout <<
"sort output rejecting hit #" << ihit <<
" plane=" << min_plane
891 <<
" with min_dotp=" << min_dotp << std::endl;
892 rejectedhsidx.push_back(hitstateidx[ihit]);
893 iterTracksInPlanes[min_plane]++;
897 std::cout <<
"sort output picking hit #" << ihit <<
" plane=" << min_plane
898 <<
" with min_dotp=" << min_dotp << std::endl;
899 auto& trackstate = fwdUpdTkState[ihit];
900 pos = trackstate.position();
901 dir = trackstate.momentum();
903 sortedtksidx.push_back(ihit);
904 iterTracksInPlanes[min_plane]++;
908 for (
unsigned int p = 0;
p < fwdUpdTkState.size(); ++
p) {
909 sortedtksidx.push_back(
p);
913 if (applySkipClean && cleanZigzag_) {
914 std::vector<unsigned int> itoerase;
918 auto pos0 = fwdUpdTkState[sortedtksidx[0]].position();
920 unsigned int end = sortedtksidx.size() - 1;
921 for (; i <
end; ++i) {
922 auto dir0 = fwdUpdTkState[sortedtksidx[i]].position() - pos0;
924 fwdUpdTkState[sortedtksidx[i + 1]].position() - fwdUpdTkState[sortedtksidx[i]].position();
927 if (dir2.Dot(dir0) < 0.) {
933 pos0 = fwdUpdTkState[sortedtksidx[i]].position();
935 if (!broken) { clean =
true; }
937 rejectedhsidx.push_back(hitstateidx[sortedtksidx[i]]);
938 sortedtksidx.erase(sortedtksidx.begin() + i);
949 std::vector<HitState>& hitstatev,
950 std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv,
951 std::vector<KFTrackState>& fwdPrdTkState,
952 std::vector<KFTrackState>& fwdUpdTkState,
953 std::vector<unsigned int>& hitstateidx,
954 std::vector<unsigned int>& rejectedhsidx,
955 std::vector<unsigned int>& sortedtksidx,
963 for (
unsigned int p : sortedtksidx) {
964 const auto& trackstate = fwdUpdTkState[
p];
965 const auto& hitflags = hitflagsv[hitstateidx[
p]];
966 const unsigned int originalPos = hitstateidx[
p];
967 if (dumpLevel_ > 2) assert(originalPos >= 0 && originalPos < hitstatev.size());
969 const auto& prdtrack = fwdPrdTkState[
p];
970 const auto& hitstate = hitstatev[hitstateidx[
p]];
971 if (dumpLevel_ > 2) assert(hitstate.wireId().Plane == inHits[originalPos]->WireID().Plane);
975 prdtrack.chi2(hitstate));
981 hitstate.hitMeasErr2(),
982 prdtrack.parameters(),
983 prdtrack.covariance(),
986 tcbk.
addPoint(trackstate.position(),
987 trackstate.momentum(),
993 if (dumpLevel_ > 0)
std::cout <<
"fillResult nvalidhits=" << nvalidhits << std::endl;
997 for (
int i = 0; i < 5; i++)
998 for (
int j = i; j < 5; j++)
1000 for (
unsigned int rejidx = 0; rejidx < rejectedhsidx.size(); ++rejidx) {
1001 const unsigned int originalPos = rejectedhsidx[rejidx];
1002 auto&
mask = hitflagsv[rejectedhsidx[rejidx]];
1008 const auto& hitstate = hitstatev[rejectedhsidx[rejidx]];
1009 if (dumpLevel_ > 2) assert(hitstate.wireId().Plane == inHits[originalPos]->WireID().Plane);
1014 hitstate.hitMeasErr2(),
1017 hitstate.wireId()));
1021 inHits[originalPos],
1028 std::cout <<
"outHits.size()=" << outHits.size() <<
" inHits.size()=" << inHits.size()
1030 if (dumpLevel_ > 2) assert(outHits.size() == inHits.size());
1034 propagator->rotateToPlane(propok,
1035 fwdUpdTkState[sortedtksidx.front()].trackState(),
1036 Plane(fwdUpdTkState[sortedtksidx.front()].position(),
1037 fwdUpdTkState[sortedtksidx.front()].momentum()));
1039 propagator->rotateToPlane(propok,
1040 fwdUpdTkState[sortedtksidx.back()].trackState(),
1041 Plane(fwdUpdTkState[sortedtksidx.back()].position(),
1042 fwdUpdTkState[sortedtksidx.back()].momentum()));
1051 mf::LogWarning(
"TrackKalmanFitter") <<
"found point with zero momentum!" << std::endl;
1056 if (dumpLevel_ > 0) {
1060 <<
"\nchi2/ndof=" << outTrack.
Chi2PerNdof() << std::endl;
static constexpr Flag_t Merged
The hit might have contribution from particles other than this.
void addPoint(const Point_t &point, const Vector_t &vect, art::Ptr< recob::Hit > hit, const PointFlags_t &flag, double chi2)
Add a single point; different version of the functions are provided using const references or rvalue ...
const TrackState & trackState() const
Get the (const reference to the) TrackState.
static constexpr Flag_t Suspicious
The point reconstruction is somehow questionable.
Flags_t const & Flags() const
Returns all flags.
process_name opflash particleana ie x
static constexpr Flag_t NoPoint
The trajectory point is not defined.
bool doFitWork(KFTrackState &trackState, detinfo::DetectorPropertiesData const &detProp, std::vector< HitState > &hitstatev, std::vector< recob::TrajectoryPointFlags::Mask_t > &hitflagsv, std::vector< KFTrackState > &fwdPrdTkState, std::vector< KFTrackState > &fwdUpdTkState, std::vector< unsigned int > &hitstateidx, std::vector< unsigned int > &rejectedhsidx, std::vector< unsigned int > &sortedtksidx, bool applySkipClean=true) const
Function where the core of the fit is performed.
double GetXTicksCoefficient(int t, int c) const
recob::tracking::Point_t Point_t
recob::tracking::Vector_t Vector_t
static constexpr Mask_t DefaultFlagsMask()
Flags used in default construction.
Declaration of signal hit object.
recob::tracking::SMatrixSym55 SMatrixSym55
bool HasValidPoint(size_t i) const
Namespace for the trajectory point flags.
bool fitTrack(detinfo::DetectorPropertiesData const &detProp, const recob::TrackTrajectory &traj, int tkID, const SMatrixSym55 &covVtx, const SMatrixSym55 &covEnd, const std::vector< art::Ptr< recob::Hit >> &hits, const double pval, const int pdgid, const bool flipDirection, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, trkmkr::OptionalOutputs &optionals) const
Fit track starting from TrackTrajectory.
bool setupInputStates(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit >> &hits, const std::vector< recob::TrajectoryPointFlags > &flags, const KFTrackState &trackState, std::vector< HitState > &hitstatev, std::vector< recob::TrajectoryPointFlags::Mask_t > &hitflagsv) const
Setup vectors of HitState and Masks to be used during the fit.
double chi2(const HitState &hitstate) const
double MomentumAtPoint(unsigned int p) const
void setCovariance(const SMatrixSym55 &trackStateCov)
void sortOutput(std::vector< HitState > &hitstatev, std::vector< KFTrackState > &fwdUpdTkState, std::vector< unsigned int > &hitstateidx, std::vector< unsigned int > &rejectedhsidx, std::vector< unsigned int > &sortedtksidx, std::vector< recob::TrajectoryPointFlags::Mask_t > &hitflagsv, bool applySkipClean=true) const
Sort the output states.
const Point_t & position() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
Extension of a TrackState to perform KalmanFilter calculations.
Vector_t StartDirection() const
Access to track direction at different points.
double Length(size_t p=0) const
Access to various track properties.
double residual(const HitState &hitstate) const
recob::tracking::SVector5 SVector5
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
Point_t const & Start() const
Access to track position at different points.
const SMatrixSym55 & covariance() const
bool fillResult(const std::vector< art::Ptr< recob::Hit >> &inHits, const int tkID, const int pdgid, std::vector< HitState > &hitstatev, std::vector< recob::TrajectoryPointFlags::Mask_t > &hitflagsv, std::vector< KFTrackState > &fwdPrdTkState, std::vector< KFTrackState > &fwdUpdTkState, std::vector< unsigned int > &hitstateidx, std::vector< unsigned int > &rejectedhsidx, std::vector< unsigned int > &sortedtksidx, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, trkmkr::OptionalOutputs &optionals) const
Fill the output objects.
A trajectory in space reconstructed from hits.
Object storing per-hit information from a track fit.
Struct holding point-by-point elements used in OptionalOutputs.
float Chi2PerNdof() const
auto end(FixedBins< T, C > const &) noexcept
bool updateWithHitState(const HitState &hitstate)
Update the TrackState given a HitState (they need to be on the same plane)
Data product for reconstructed trajectory in space.
static constexpr Flag_t HitIgnored
Hit was not included for the computation of the trajectory.
Definition of data types for geometry description.
Provides recob::Track data product.
Point_t const & Vertex() const
Returns the position of the first valid point of the trajectory [cm].
static constexpr Flag_t Rejected
The hit is extraneous to this track.
static constexpr Flag_t ExcludedFromFit
double ConvertTicksToX(double ticks, int p, int t, int c) const
auto begin(FixedBins< T, C > const &) noexcept
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
KFTrackState setupInitialTrackState(const Point_t &position, const Vector_t &direction, SMatrixSym55 &trackStateCov, const double pval, const int pdgid) const
Return track state from intial position, direction, and covariance.
size_t NextValidPoint(size_t index) const
Encapsulate the construction of a single detector plane.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
then echo File list $list not found else cat $list while read file do echo $file sed s
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
Helper class to aid the creation of a recob::Track, keeping data vectors in sync. ...
static constexpr Flag_t DetectorIssue
The hit is associated to a problematic channel.
bool isTrackFitInfosInit()
check initialization of the output vector of TrackFitHitInfos
recob::Track finalizeTrack(const recob::tracking::SMatrixSym55 &covStart, const recob::tracking::SMatrixSym55 &covEnd)
Get the finalized recob::Track; needs the start and end covariance matrices.
static constexpr Flag_t DeltaRay
The hit might have contribution from a δ ray.
constexpr double kBogusD
obviously bogus double value
const Vector_t & momentum() const
std::ostream & dump(std::ostream &out=std::cout) const
Printout information.
void setTrackFitHitInfo(recob::TrackFitHitInfo &&aTrackFitHitInfo)
set the recob::TrackFitHitInfo unique_ptr
Collection of Physical constants used in LArSoft.
const Plane & plane() const
plane where the parameters are defined
recob::tracking::Plane Plane
static constexpr Flag_t Shared
The hit is known to be associated also to another trajectory.
Struct holding optional TrackMaker outputs.
Set of flags pertaining a point of the track.
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
const SMatrixSym55 & StartCovariance() const
Access to covariance matrices.