LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TrackKalmanFitter.h
Go to the documentation of this file.
1 #ifndef TRACKKALMANFITTER_H
2 #define TRACKKALMANFITTER_H
3 
5 #include "fhiclcpp/types/Atom.h"
6 #include "fhiclcpp/types/Table.h"
14 
15 namespace recob {
16  class Hit;
17 }
18 
19 class TVector3;
20 namespace trkmkr {
21  struct OptionalOutputs;
22 }
23 
24 namespace trkf {
25 
47 
48  public:
49 
50  struct Config {
51  using Name = fhicl::Name;
54  Name("useRMSError"),
55  Comment("Flag to replace the default hit error recob::Hit::SigmaPeakTime() with recob::Hit::RMS()."),
56  true
57  };
58  fhicl::Atom<bool> sortHitsByPlane {
59  Name("sortHitsByPlane"),
60  Comment("Flag to sort hits along the forward fit. The hit order in each plane is preserved, the next hit to process in 3D is chosen as the one with shorter 3D propagation distance among the next hit in all planes."),
61  true
62  };
63  fhicl::Atom<bool> sortOutputHitsMinLength {
64  Name("sortOutputHitsMinLength"),
65  Comment("Flag to decide whether the hits are sorted before creating the output track in order to avoid tracks with huge length."),
66  true
67  };
68  fhicl::Atom<bool> skipNegProp {
69  Name("skipNegProp"),
70  Comment("Flag to decide whether, during the forward fit, the hits corresponding to a negative propagation distance should be dropped. Also, if sortOutputHitsMinLength is true, during sorting hits at a negative distance with respect to the previous are rejected."),
71  true
72  };
73  fhicl::Atom<bool> cleanZigzag {
74  Name("cleanZigzag"),
75  Comment("Flag to decide whether hits with a zigzag pattern should be iteratively removed. Zigzag identified as negative dot product of segments connecting a point to the points before and after it."),
76  false
77  };
78  fhicl::Atom<bool> rejectHighMultHits {
79  Name("rejectHighMultHits"),
80  Comment("Flag to rejects hits with recob::Hit::Multiplicity()>1."),
81  false
82  };
83  fhicl::Atom<bool> rejectHitsNegativeGOF {
84  Name("rejectHitsNegativeGOF"),
85  Comment("Flag to rejects hits with recob::Hit::GoodnessOfFit<0."),
86  true
87  };
88  fhicl::Atom<float> hitErr2ScaleFact {
89  Name("hitErr2ScaleFact"),
90  Comment("Scale the hit error squared by this factor."),
91  1.0
92  };
93  fhicl::Atom<bool> tryNoSkipWhenFails {
94  Name("tryNoSkipWhenFails"),
95  Comment("In case skipNegProp is true and the track fit fails, make a second attempt to fit the track with skipNegProp=false in order to attempt to avoid losing efficiency."),
96  true
97  };
98  fhicl::Atom<int> dumpLevel {
99  Name("dumpLevel"),
100  Comment("0 for no debug printouts, 1 for moderate, 2 for maximum."),
101  0
102  };
103  };
105 
107  TrackKalmanFitter(const TrackStatePropagator* prop, bool useRMS, bool sortHitsByPlane, bool sortOutputHitsMinLength, bool skipNegProp, bool cleanZigzag,
108  bool rejectHighMultHits, bool rejectHitsNegativeGOF, float hitErr2ScaleFact, bool tryNoSkipWhenFails, int dumpLevel){
109  propagator=prop;
110  useRMS_=useRMS;
111  sortHitsByPlane_=sortHitsByPlane;
112  sortOutputHitsMinLength_=sortOutputHitsMinLength;
113  skipNegProp_=skipNegProp;
114  cleanZigzag_=cleanZigzag;
115  rejectHighMultHits_=rejectHighMultHits;
116  rejectHitsNegativeGOF_=rejectHitsNegativeGOF;
117  hitErr2ScaleFact_=hitErr2ScaleFact;
118  tryNoSkipWhenFails_=tryNoSkipWhenFails;
119  dumpLevel_=dumpLevel;
121  }
122 
124  explicit TrackKalmanFitter(const TrackStatePropagator* prop, Parameters const & p)
125  : TrackKalmanFitter(prop,p().useRMS(),p().sortHitsByPlane(),p().sortOutputHitsMinLength(),p().skipNegProp(),p().cleanZigzag(),
126  p().rejectHighMultHits(),p().rejectHitsNegativeGOF(),p().hitErr2ScaleFact(),p().tryNoSkipWhenFails(),p().dumpLevel()) {}
127 
129  bool fitTrack(const recob::TrackTrajectory& traj, int tkID, const SMatrixSym55& covVtx, const SMatrixSym55& covEnd,
130  const std::vector<art::Ptr<recob::Hit> >& hits, const double pval, const int pdgid, const bool flipDirection,
131  recob::Track& outTrack, std::vector<art::Ptr<recob::Hit> >& outHits, trkmkr::OptionalOutputs& optionals) const;
132 
134  bool fitTrack(const Point_t& position, const Vector_t& direction, SMatrixSym55& trackStateCov,
135  const std::vector<art::Ptr<recob::Hit> >& hits, const std::vector<recob::TrajectoryPointFlags>& flags,
136  const int tkID, const double pval, const int pdgid,
137  recob::Track& outTrack, std::vector<art::Ptr<recob::Hit> >& outHits, trkmkr::OptionalOutputs& optionals) const;
138 
140  bool doFitWork(KFTrackState& trackState, std::vector<HitState>& hitstatev, std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv,
141  std::vector<KFTrackState>& fwdPrdTkState, std::vector<KFTrackState>& fwdUpdTkState,
142  std::vector<unsigned int>& hitstateidx, std::vector<unsigned int>& rejectedhsidx, std::vector<unsigned int>& sortedtksidx,
143  bool applySkipClean = true) const;
144 
145  private:
147  KFTrackState setupInitialTrackState(const Point_t& position, const Vector_t& direction, SMatrixSym55& trackStateCov, const double pval, const int pdgid) const;
148 
150  bool setupInputStates(const std::vector<art::Ptr<recob::Hit> >& hits, const std::vector<recob::TrajectoryPointFlags>& flags,
151  const KFTrackState& trackState, bool& reverseHits,
152  std::vector<HitState>& hitstatev, std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv) const;
153 
155  void sortOutput(std::vector<HitState>& hitstatev, std::vector<KFTrackState>& fwdUpdTkState,
156  std::vector<unsigned int>& hitstateidx, std::vector<unsigned int>& rejectedhsidx,
157  std::vector<unsigned int>& sortedtksidx, bool applySkipClean = true) const;
158 
160  bool fillResult(const std::vector<art::Ptr<recob::Hit> >& inHits, const int tkID, const int pdgid, const bool reverseHits,
161  std::vector<HitState>& hitstatev, std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv,
162  std::vector<KFTrackState>& fwdPrdTkState, std::vector<KFTrackState>& fwdUpdTkState,
163  std::vector<unsigned int>& hitstateidx, std::vector<unsigned int>& rejectedhsidx, std::vector<unsigned int>& sortedtksidx,
164  recob::Track& outTrack, std::vector<art::Ptr<recob::Hit> >& outHits, trkmkr::OptionalOutputs& optionals) const;
165 
169  bool useRMS_;
179  };
180 
181 }
182 
183 #endif
Fit tracks using Kalman Filter fit+smooth.
Reconstruction base classes.
recob::tracking::Point_t Point_t
Definition: TrackState.h:18
recob::tracking::Vector_t Vector_t
Definition: TrackState.h:19
recob::tracking::SMatrixSym55 SMatrixSym55
Definition: TrackState.h:15
Class for propagation of a trkf::TrackState to a recob::tracking::Plane.
const detinfo::DetectorProperties * detprop
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Extension of a TrackState to perform KalmanFilter calculations.
Definition: KFTrackState.h:21
void hits()
Definition: readHits.C:15
A trajectory in space reconstructed from hits.
const TrackStatePropagator * propagator
art::ServiceHandle< geo::Geometry > geom
Provides recob::Track data product.
TrackKalmanFitter(const TrackStatePropagator *prop, Parameters const &p)
Constructor from TrackStatePropagator and Parameters table.
Struct holding optional TrackMaker outputs.
Definition: TrackMaker.h:73
art framework interface to geometry description
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:51
TrackKalmanFitter(const TrackStatePropagator *prop, bool useRMS, bool sortHitsByPlane, bool sortOutputHitsMinLength, bool skipNegProp, bool cleanZigzag, bool rejectHighMultHits, bool rejectHitsNegativeGOF, float hitErr2ScaleFact, bool tryNoSkipWhenFails, int dumpLevel)
Constructor from TrackStatePropagator and values of configuration parameters.