1 #ifndef TRACKKALMANFITTER_H
2 #define TRACKKALMANFITTER_H
4 #include "art/Framework/Services/Registry/ServiceHandle.h"
5 #include "canvas/Persistency/Common/Ptr.h"
6 #include "fhiclcpp/types/Atom.h"
7 #include "fhiclcpp/types/Comment.h"
8 #include "fhiclcpp/types/Name.h"
9 #include "fhiclcpp/types/Table.h"
17 class DetectorPropertiesData;
22 class TrackTrajectory;
26 struct OptionalOutputs;
34 class TrackStatePropagator;
63 Comment(
"Flag to replace the default hit error "
64 "recob::Hit::SigmaPeakTime() with recob::Hit::RMS()."),
67 Name(
"sortHitsByPlane"),
68 Comment(
"Flag to sort hits along the forward fit. The hit order in each plane is preserved "
69 "(unless sortHitsByWire is true), the next hit to process in 3D is chosen as the "
70 "one with shorter 3D propagation distance among the next hit in all planes."),
73 Name(
"sortHitsByWire"),
74 Comment(
"Set to true if, instead of keeping the hit sorting in each plane from the pattern "
75 "recognition stage, the hits need to be sorted by wire number. Ignored if "
76 "sortHitsByPlane = false."),
79 Name(
"sortOutputHitsMinLength"),
80 Comment(
"Flag to decide whether the hits are sorted before creating the output track in "
81 "order to avoid tracks with huge length."),
86 "Flag to decide whether, during the forward fit, the hits corresponding to a negative "
87 "propagation distance should be dropped. Also, if sortOutputHitsMinLength is true, "
88 "during sorting hits at a negative distance with respect to the previous are rejected."),
92 Comment(
"Flag to decide whether hits with a zigzag pattern should be iteratively removed. "
93 "Zigzag identified as negative dot product of segments connecting a point to the "
94 "points before and after it."),
97 Name(
"rejectHighMultHits"),
98 Comment(
"Flag to rejects hits with recob::Hit::Multiplicity()>1."),
101 Name(
"rejectHitsNegativeGOF"),
102 Comment(
"Flag to rejects hits with recob::Hit::GoodnessOfFit<0."),
105 Comment(
"Scale the hit error squared by this factor."),
108 Name(
"tryNoSkipWhenFails"),
109 Comment(
"In case skipNegProp is true and the track fit fails, make a second attempt to fit "
110 "the track with skipNegProp=false in order to attempt to avoid losing efficiency."),
114 Comment(
"Try fit in both with default and reversed direction, choose the track with "
115 "highest score=CountValidPoints/(Length*Chi2PerNdof)."),
118 Name(
"pickBestHitOnWire"),
119 Comment(
"If there is >1 consecutive hit on the same wire, choose the one with best chi2 "
120 "and exclude the others."),
124 Comment(
"Reject hits with residue > maxResidue [cm]. If negative, it is set to "
125 "std::numeric_limits<float>::max()."),
128 Name(
"maxResidueFirstHit"),
129 Comment(
"Reject firt hit if has residue > maxResidueFirstHit [cm]. If negative, it is set "
130 "to std::numeric_limits<float>::max()."),
133 Comment(
"Reject hits with chi2 > maxChi2. If negative, it is set "
134 "to std::numeric_limits<float>::max()."),
138 Comment(
"Reject hits with propagation distance > maxDist [cm]. If negative, it is set to "
139 "std::numeric_limits<float>::max()."),
142 Name(
"negDistTolerance"),
143 Comment(
"Tolerance for negative propagation distance to avoid hit rejection (so this is "
144 "expected to be a small negative number)."),
148 Comment(
"0 for no debug printouts, 1 for moderate, 2 for maximum."),
156 bool sortHitsByPlane,
158 bool sortOutputHitsMinLength,
161 bool rejectHighMultHits,
162 bool rejectHitsNegativeGOF,
163 float hitErr2ScaleFact,
164 bool tryNoSkipWhenFails,
166 bool pickBestHitOnWire,
168 float maxResidueFirstHit,
171 float negDistTolerance,
187 maxResidue_ = (maxResidue > 0 ? maxResidue : std::numeric_limits<float>::max());
189 (maxResidueFirstHit > 0 ? maxResidueFirstHit : std::numeric_limits<float>::max());
190 maxChi2_ = (maxChi2 > 0 ? maxChi2 : std::numeric_limits<float>::max());
191 maxDist_ = (maxDist > 0 ? maxDist : std::numeric_limits<float>::max());
200 p().sortHitsByPlane(),
202 p().sortOutputHitsMinLength(),
205 p().rejectHighMultHits(),
206 p().rejectHitsNegativeGOF(),
207 p().hitErr2ScaleFact(),
208 p().tryNoSkipWhenFails(),
210 p().pickBestHitOnWire(),
212 p().maxResidueFirstHit(),
215 p().negDistTolerance(),
228 const bool flipDirection,
239 const std::vector<recob::TrajectoryPointFlags>& flags,
250 std::vector<HitState>& hitstatev,
251 std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv,
252 std::vector<KFTrackState>& fwdPrdTkState,
253 std::vector<KFTrackState>& fwdUpdTkState,
254 std::vector<unsigned int>& hitstateidx,
255 std::vector<unsigned int>& rejectedhsidx,
256 std::vector<unsigned int>& sortedtksidx,
257 bool applySkipClean =
true)
const;
265 const int pdgid)
const;
270 const std::vector<recob::TrajectoryPointFlags>& flags,
272 std::vector<HitState>& hitstatev,
273 std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv)
const;
276 void sortOutput(std::vector<HitState>& hitstatev,
277 std::vector<KFTrackState>& fwdUpdTkState,
278 std::vector<unsigned int>& hitstateidx,
279 std::vector<unsigned int>& rejectedhsidx,
280 std::vector<unsigned int>& sortedtksidx,
281 std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv,
282 bool applySkipClean =
true)
const;
288 std::vector<HitState>& hitstatev,
289 std::vector<recob::TrajectoryPointFlags::Mask_t>& hitflagsv,
290 std::vector<KFTrackState>& fwdPrdTkState,
291 std::vector<KFTrackState>& fwdUpdTkState,
292 std::vector<unsigned int>& hitstateidx,
293 std::vector<unsigned int>& rejectedhsidx,
294 std::vector<unsigned int>& sortedtksidx,
299 art::ServiceHandle<geo::Geometry const>
geom;
fhicl::Atom< bool > skipNegProp
Fit tracks using Kalman Filter fit+smooth.
fhicl::Atom< bool > tryBothDirs
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.
recob::tracking::Point_t Point_t
recob::tracking::Vector_t Vector_t
Declaration of signal hit object.
fhicl::Atom< bool > sortHitsByPlane
recob::tracking::SMatrixSym55 SMatrixSym55
TrackKalmanFitter(const TrackStatePropagator *prop, bool useRMS, bool sortHitsByPlane, bool sortHitsByWire, bool sortOutputHitsMinLength, bool skipNegProp, bool cleanZigzag, bool rejectHighMultHits, bool rejectHitsNegativeGOF, float hitErr2ScaleFact, bool tryNoSkipWhenFails, bool tryBothDirs, bool pickBestHitOnWire, float maxResidue, float maxResidueFirstHit, float maxChi2, float maxDist, float negDistTolerance, int dumpLevel)
Constructor from TrackStatePropagator and values of configuration parameters.
fhicl::Atom< float > maxChi2
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.
Class for propagation of a trkf::TrackState to a recob::tracking::Plane.
art::ServiceHandle< geo::Geometry const > geom
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.
fhicl::Atom< bool > pickBestHitOnWire
fhicl::Atom< bool > cleanZigzag
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.
bool sortHitsByWire(art::Ptr< recob::Hit > a, art::Ptr< recob::Hit > b)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
fhicl::Atom< float > negDistTolerance
fhicl::Table< Config > Parameters
fhicl::Atom< float > maxResidueFirstHit
Extension of a TrackState to perform KalmanFilter calculations.
bool rejectHitsNegativeGOF_
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.
fhicl::Atom< bool > tryNoSkipWhenFails
BEGIN_PROLOG vertical distance to the surface Name
const TrackStatePropagator * propagator
Set of flags pertaining a point of the track.
fhicl::Atom< bool > sortHitsByWire
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.
fhicl::Atom< float > maxResidue
float maxResidueFirstHit_
fhicl::Atom< bool > useRMS
bool sortOutputHitsMinLength_
TrackKalmanFitter(const TrackStatePropagator *prop, Parameters const &p)
Constructor from TrackStatePropagator and Parameters table.
fhicl::Atom< bool > rejectHitsNegativeGOF
fhicl::Atom< bool > sortOutputHitsMinLength
fhicl::Atom< float > maxDist
fhicl::Atom< int > dumpLevel
Struct holding optional TrackMaker outputs.
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:
fhicl::Atom< bool > rejectHighMultHits
fhicl::Atom< float > hitErr2ScaleFact