LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
trkmkr::KalmanFilterFitTrackMaker Class Referenceabstract

Concrete implementation of a tool to fit tracks with TrackKalmanFitter. More...

Inheritance diagram for trkmkr::KalmanFilterFitTrackMaker:
trkmkr::TrackMaker

Classes

struct  Config
 
struct  Options
 

Public Types

using Parameters = art::ToolConfigTable< Config >
 

Public Member Functions

 KalmanFilterFitTrackMaker (Parameters const &p)
 Constructor from Parameters. More...
 
virtual void initEvent (const art::Event &e) override
 initialize event: get collection of recob::MCSFitResult More...
 
bool makeTrackImpl (const recob::TrackTrajectory &traj, const int tkID, const std::vector< art::Ptr< recob::Hit >> &inHits, const SMatrixSym55 &covVtx, const SMatrixSym55 &covEnd, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
 function that actually calls the fitter More...
 
bool makeTrack (const recob::TrackTrajectory &traj, const int tkID, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const override
 
bool makeTrack (const recob::Track &track, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const override
 override of TrackMaker virtual function with recob::Track as argument More...
 
int getParticleID (const recob::TrackTrajectory &traj, const int tkID) const
 set the particle ID hypothesis More...
 
double getMomentum (const recob::TrackTrajectory &traj, const int pid, const bool isFlip, const int tkID) const
 set the initial momentum estimate More...
 
bool isFlipDirection (const recob::TrackTrajectory &traj, const int tkID) const
 decide whether to flip the direction or not More...
 
void restoreInputPoints (const recob::TrackTrajectory &traj, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
 
virtual bool makeTrack (const art::Ptr< recob::TrackTrajectory > ttraj, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
 makeTrack functions with art::Ptr<recob::TrackTrajectory>; calls the purely virtual version with const recob::TrackTrajectory reference as argument. More...
 
virtual bool makeTrack (const recob::TrackTrajectory &ttraj, const int tkID, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const =0
 makeTrack functions with const recob::TrackTrajectory reference as argument: purely virtual, to be implemented in concrete classes. More...
 
virtual bool makeTrack (const recob::Trajectory &traj, const std::vector< recob::TrajectoryPointFlags > &flags, const int tkID, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
 makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory using a dummy flags vector. More...
 
virtual bool makeTrack (const art::Ptr< recob::Trajectory > traj, const std::vector< recob::TrajectoryPointFlags > &flags, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
 makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory using a dummy flags vector. More...
 
virtual bool makeTrack (const art::Ptr< recob::Track > track, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
 makeTrack functions with recob::Track as argument; calls the version with recob::TrackTrajectory. More...
 
virtual bool makeTrack (const recob::Track &track, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
 makeTrack functions with recob::Track as argument; calls the version with recob::TrackTrajectory. More...
 

Private Attributes

Parameters p_
 
const trkf::TrackStatePropagator prop
 
const trkf::TrackKalmanFitter kalmanFitter
 
const trkf::TrajectoryMCSFitter mcsfitter
 
double mom_def_
 
bool momFromMCSColl_
 
art::InputTag mcsInputTag_
 
bool momFromCombAndPid_
 
art::InputTag contInputTag_
 
bool pidFromColl_
 
art::InputTag pidInputTag_
 
double mom_len_cut_
 
int pid_def_
 
bool alwaysFlip_
 
bool dirFromVec_
 
recob::tracking::Vector_t dirVec
 
const std::vector< recob::MCSFitResult > * mcs = nullptr
 
const std::vector< anab::CosmicTag > * cont = nullptr
 
const std::vector< anab::ParticleID > * pid = nullptr
 
trkf::TrackMomentumCalculator tmc
 

Detailed Description

Concrete implementation of a tool to fit tracks with TrackKalmanFitter.

Concrete implementation of a tool to fit tracks with trkf::TrackKalmanFitter; inherits from abstract class TrackMaker. It prepares the input needed by the fitter (momentum, particleId, direction), and returns a track with all outputs filled. If the flag keepInputTrajectoryPoints is set to true, the tracjetory points from the input track are copied into the output, so that only the covariance matrices, the chi2 and the ndof in the output track are resulting from the fit.

For configuration options see KalmanFilterFitTrackMaker::Options and KalmanFilterFitTrackMaker::Config.

Author
G. Cerati (FNAL, MicroBooNE)
Date
2017
Version
1.0

Definition at line 46 of file KalmanFilterFitTrackMaker_tool.cc.

Member Typedef Documentation

Constructor & Destructor Documentation

trkmkr::KalmanFilterFitTrackMaker::KalmanFilterFitTrackMaker ( Parameters const &  p)
inlineexplicit

Constructor from Parameters.

Definition at line 131 of file KalmanFilterFitTrackMaker_tool.cc.

References alwaysFlip_, contInputTag_, d, dirFromVec_, trkmkr::KalmanFilterFitTrackMaker::Options::dirVec, kalmanFitter, trkmkr::KalmanFilterFitTrackMaker::Options::keepInputTrajectoryPoints, mcsfitter, mcsInputTag_, mom_def_, mom_len_cut_, momFromCombAndPid_, momFromMCSColl_, p_, pid_def_, pidFromColl_, pidInputTag_, and prop.

131  :
132  p_(p),
133  prop{p_().propagator},
134  kalmanFitter{&prop, p_().fitter},
135  mcsfitter{p_().mcsfit},
136  mom_def_{p_().options().defaultMomInGeV()},
137  momFromMCSColl_{p_().options().momFromMCSCollection()},
138  momFromCombAndPid_{p_().options().momFromCombAndPid()},
139  pidFromColl_{p_().options().pidFromCollection()},
140  mom_len_cut_{p_().options().pidFromLengthCut()},
141  pid_def_{p_().options().defaultPdgId()},
142  alwaysFlip_{p_().options().alwaysInvertDir()},
143  dirFromVec_{p_().options().dirFromVec()}
144  {
145  if (momFromMCSColl_) {
146  mcsInputTag_ = p_().options().mcsInputTag();
147  }
148  if (momFromCombAndPid_) {
149  contInputTag_ = p_().options().contInputTag();
150  }
151  if (pidFromColl_) {
152  pidInputTag_ = p_().options().pidInputTag();
153  }
154  if (dirFromVec_) {
155  auto d = p_().options().dirVec();
156  dirVec = recob::tracking::Vector_t{d[0], d[1], d[2]};
157  }
158  //
159  if (p_().options().keepInputTrajectoryPoints() &&
160  (p_().fitter().sortHitsByPlane() ||
161  p_().fitter().sortOutputHitsMinLength() ||
162  p_().fitter().skipNegProp())) {
163  throw cet::exception("KalmanFilterFitTrackMaker")
164  << "Incompatible configuration parameters: keepInputTrajectoryPoints "
165  "needs the following fitter options all set to false: "
166  "sortHitsByPlane, sortOutputHitsMinLength, skipNegProp."
167  << "\n";
168  }
170  throw cet::exception("KalmanFilterFitTrackMaker")
171  << "Incompatible configuration parameters: momFromMCSCollection and "
172  "momFromCombAndPid cannot be both true at the same time."
173  << "\n";
174  }
175  if (pidFromColl_ && mom_len_cut_ > 0) {
176  throw cet::exception("KalmanFilterFitTrackMaker")
177  << "Incompatible configuration parameters: pidFromCollection and "
178  "pidFromLengthCut cannot be respectively true and >0. at the same "
179  "time."
180  << "\n";
181  }
182  if (alwaysFlip_ && dirFromVec_) {
183  throw cet::exception("KalmanFilterFitTrackMaker")
184  << "Incompatible configuration parameters: alwaysInvertDir and "
185  "dirFromVec cannot be both true at the same time."
186  << "\n";
187  }
188  //
189  }
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
Definition: TrackingTypes.h:29
Float_t d
Definition: plot.C:237
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Function Documentation

double trkmkr::KalmanFilterFitTrackMaker::getMomentum ( const recob::TrackTrajectory traj,
const int  pid,
const bool  isFlip,
const int  tkID 
) const

set the initial momentum estimate

Definition at line 342 of file KalmanFilterFitTrackMaker_tool.cc.

References cont, trkf::TrajectoryMCSFitter::fitMcs(), trkf::TrackMomentumCalculator::GetTrackMomentum(), anab::kNotTagged, recob::TrackTrajectory::Length(), mcs, mcsfitter, mom_def_, momFromCombAndPid_, momFromMCSColl_, pid, and tmc.

Referenced by makeTrack(), and makeTrackImpl().

346 {
347  double mom = mom_def_;
348  if (momFromMCSColl_) {
349  double mcsmom =
350  (isFlip ? mcs->at(tkID).bwdMomentum() : mcs->at(tkID).fwdMomentum());
351  // make sure the mcs fit converged
352  if (mcsmom > 0.01 && mcsmom < 7.)
353  mom = mcsmom;
354  }
355  if (momFromCombAndPid_) {
356  bool isContained = cont->at(tkID).CosmicType() == anab::kNotTagged;
357  // for now momentum from range implemented only for muons and protons
358  // so treat pions as muons (~MIPs) and kaons as protons
359  int pidtmp = pid;
360  if (pidtmp == 211 || pidtmp == 13)
361  pidtmp = 13;
362  else
363  pidtmp = 2212;
364  mom = tmc.GetTrackMomentum(traj.Length(), pidtmp);
365  if (isContained == false) {
366  auto mcsresult = mcsfitter.fitMcs(traj, pid);
367  double mcsmom =
368  (isFlip ? mcsresult.bwdMomentum() : mcsresult.fwdMomentum());
369  // make sure the mcs fit converged, also the mcsmom should not be less
370  // than the range!
371  if (mcsmom > 0.01 && mcsmom < 7. && mcsmom > mom)
372  mom = mcsmom;
373  }
374  }
375  return mom;
376 }
const std::vector< anab::CosmicTag > * cont
const std::vector< recob::MCSFitResult > * mcs
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
const std::vector< anab::ParticleID > * pid
recob::MCSFitResult fitMcs(const recob::TrackTrajectory &traj, bool momDepConst=true) const
double GetTrackMomentum(double trkrange, int pdg) const
int trkmkr::KalmanFilterFitTrackMaker::getParticleID ( const recob::TrackTrajectory traj,
const int  tkID 
) const

set the particle ID hypothesis

Definition at line 379 of file KalmanFilterFitTrackMaker_tool.cc.

References recob::TrackTrajectory::Length(), mom_len_cut_, pid_def_, and pidFromColl_.

Referenced by makeTrack(), and makeTrackImpl().

381 {
382  if (pidFromColl_) {
383  return pid->at(tkID).Pdg();
384  }
385  if (mom_len_cut_ > 0.) {
386  return (traj.Length() < mom_len_cut_ ? 2212 : 13);
387  }
388  return pid_def_;
389 }
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.
virtual void trkmkr::KalmanFilterFitTrackMaker::initEvent ( const art::Event e)
inlineoverridevirtual

initialize event: get collection of recob::MCSFitResult

Reimplemented from trkmkr::TrackMaker.

Definition at line 193 of file KalmanFilterFitTrackMaker_tool.cc.

References cont, contInputTag_, art::DataViewImpl::getValidHandle(), makeTrackImpl(), mcs, mcsInputTag_, momFromCombAndPid_, momFromMCSColl_, pidFromColl_, pidInputTag_, and lar::dump::vector().

194  {
195  if (momFromMCSColl_)
196  mcs = e.getValidHandle<std::vector<recob::MCSFitResult>>(mcsInputTag_).product();
197  if (momFromCombAndPid_) {
198  cont = e.getValidHandle<std::vector<anab::CosmicTag>>(contInputTag_).product();
199  }
200  if (pidFromColl_) {
201  pid = e.getValidHandle<std::vector<anab::ParticleID>>(pidInputTag_).product();
202  }
203  return;
204  }
const std::vector< anab::CosmicTag > * cont
const std::vector< recob::MCSFitResult > * mcs
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool trkmkr::KalmanFilterFitTrackMaker::isFlipDirection ( const recob::TrackTrajectory traj,
const int  tkID 
) const

decide whether to flip the direction or not

Definition at line 392 of file KalmanFilterFitTrackMaker_tool.cc.

References alwaysFlip_, dirFromVec_, trkmkr::KalmanFilterFitTrackMaker::Options::dirVec, and recob::TrackTrajectory::VertexDirection().

Referenced by makeTrack(), and makeTrackImpl().

394 {
395  if (alwaysFlip_) {
396  return true;
397  } else if (dirFromVec_) {
398  auto tdir = traj.VertexDirection();
399  if (tdir.Dot(dirVec) < 0.)
400  return true;
401  }
402  return false;
403 }
Vector_t VertexDirection() const
Returns the direction of the trajectory at the first point.
virtual bool trkmkr::TrackMaker::makeTrack ( const recob::Trajectory traj,
const std::vector< recob::TrajectoryPointFlags > &  flags,
const int  tkID,
const std::vector< art::Ptr< recob::Hit > > &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit > > &  outHits,
OptionalOutputs optionals 
) const
inlinevirtualinherited

makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory using a dummy flags vector.

Definition at line 162 of file TrackMaker.h.

165  {
166  return makeTrack(recob::TrackTrajectory(traj,recob::TrackTrajectory::Flags_t(traj.NPoints())), tkID, inHits, outTrack, outHits, optionals);
167  }
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:173
A trajectory in space reconstructed from hits.
std::vector< PointFlags_t > Flags_t
Type of point flag list.
virtual bool makeTrack(const recob::Trajectory &traj, const std::vector< recob::TrajectoryPointFlags > &flags, const int tkID, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory...
Definition: TrackMaker.h:162
virtual bool trkmkr::TrackMaker::makeTrack ( const art::Ptr< recob::Trajectory traj,
const std::vector< recob::TrajectoryPointFlags > &  flags,
const std::vector< art::Ptr< recob::Hit > > &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit > > &  outHits,
OptionalOutputs optionals 
) const
inlinevirtualinherited

makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory using a dummy flags vector.

Definition at line 168 of file TrackMaker.h.

References art::Ptr< T >::key(), and recob::Trajectory::NPoints().

171  {
172  return makeTrack(recob::TrackTrajectory(*traj,recob::TrackTrajectory::Flags_t(traj->NPoints())), traj.key(), inHits, outTrack, outHits, optionals);
173  }
key_type key() const
Definition: Ptr.h:356
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:173
A trajectory in space reconstructed from hits.
std::vector< PointFlags_t > Flags_t
Type of point flag list.
virtual bool makeTrack(const recob::Trajectory &traj, const std::vector< recob::TrajectoryPointFlags > &flags, const int tkID, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory...
Definition: TrackMaker.h:162
virtual bool trkmkr::TrackMaker::makeTrack ( const art::Ptr< recob::TrackTrajectory ttraj,
const std::vector< art::Ptr< recob::Hit > > &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit > > &  outHits,
OptionalOutputs optionals 
) const
inlinevirtualinherited

makeTrack functions with art::Ptr<recob::TrackTrajectory>; calls the purely virtual version with const recob::TrackTrajectory reference as argument.

Definition at line 177 of file TrackMaker.h.

References art::Ptr< T >::key(), track, recob::Track::Trajectory(), and lar::dump::vector().

179  {
180  return makeTrack(*ttraj, ttraj.key(), inHits, outTrack, outHits, optionals);
181  }
key_type key() const
Definition: Ptr.h:356
virtual bool makeTrack(const recob::Trajectory &traj, const std::vector< recob::TrajectoryPointFlags > &flags, const int tkID, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory...
Definition: TrackMaker.h:162
virtual bool trkmkr::TrackMaker::makeTrack ( const recob::TrackTrajectory ttraj,
const int  tkID,
const std::vector< art::Ptr< recob::Hit > > &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit > > &  outHits,
OptionalOutputs optionals 
) const
pure virtualinherited

makeTrack functions with const recob::TrackTrajectory reference as argument: purely virtual, to be implemented in concrete classes.

virtual bool trkmkr::TrackMaker::makeTrack ( const art::Ptr< recob::Track track,
const std::vector< art::Ptr< recob::Hit > > &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit > > &  outHits,
OptionalOutputs optionals 
) const
inlinevirtualinherited

makeTrack functions with recob::Track as argument; calls the version with recob::TrackTrajectory.

Definition at line 189 of file TrackMaker.h.

191  {
192  return makeTrack(track->Trajectory(), track.key(), inHits, outTrack, outHits, optionals);
193  }
key_type key() const
Definition: Ptr.h:356
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:101
virtual bool makeTrack(const recob::Trajectory &traj, const std::vector< recob::TrajectoryPointFlags > &flags, const int tkID, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory...
Definition: TrackMaker.h:162
virtual bool trkmkr::TrackMaker::makeTrack ( const recob::Track track,
const std::vector< art::Ptr< recob::Hit > > &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit > > &  outHits,
OptionalOutputs optionals 
) const
inlinevirtualinherited

makeTrack functions with recob::Track as argument; calls the version with recob::TrackTrajectory.

Definition at line 195 of file TrackMaker.h.

References recob::Track::ID(), and recob::Track::Trajectory().

197  {
198  return makeTrack(track.Trajectory(), track.ID(), inHits, outTrack, outHits, optionals);
199  }
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:101
virtual bool makeTrack(const recob::Trajectory &traj, const std::vector< recob::TrajectoryPointFlags > &flags, const int tkID, const std::vector< art::Ptr< recob::Hit > > &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit > > &outHits, OptionalOutputs &optionals) const
makeTrack functions with recob::Trajectory as argument; calls the version with recob::TrackTrajectory...
Definition: TrackMaker.h:162
int ID() const
Definition: Track.h:201
bool trkmkr::KalmanFilterFitTrackMaker::makeTrack ( const recob::TrackTrajectory traj,
const int  tkID,
const std::vector< art::Ptr< recob::Hit >> &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit >> &  outHits,
OptionalOutputs optionals 
) const
inlineoverride

override of TrackMaker purely virtual function with recob::TrackTrajectory as argument

Definition at line 219 of file KalmanFilterFitTrackMaker_tool.cc.

References makeTrackImpl().

225  {
226  return makeTrackImpl(traj,
227  tkID,
228  inHits,
231  outTrack,
232  outHits,
233  optionals);
234  }
bool makeTrackImpl(const recob::TrackTrajectory &traj, const int tkID, const std::vector< art::Ptr< recob::Hit >> &inHits, const SMatrixSym55 &covVtx, const SMatrixSym55 &covEnd, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
function that actually calls the fitter
recob::tracking::SMatrixSym55 SMatrixSym55
Definition: TrackState.h:15
bool trkmkr::KalmanFilterFitTrackMaker::makeTrack ( const recob::Track track,
const std::vector< art::Ptr< recob::Hit >> &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit >> &  outHits,
OptionalOutputs optionals 
) const
inlineoverride

override of TrackMaker virtual function with recob::Track as argument

Definition at line 238 of file KalmanFilterFitTrackMaker_tool.cc.

References recob::Track::Covariances(), getMomentum(), getParticleID(), recob::Track::ID(), isFlipDirection(), makeTrackImpl(), restoreInputPoints(), recob::Track::Trajectory(), and lar::dump::vector().

243  {
244  auto covs = track.Covariances();
245  return makeTrackImpl(track.Trajectory(),
246  track.ID(),
247  inHits,
248  covs.first,
249  covs.second,
250  outTrack,
251  outHits,
252  optionals);
253  }
bool makeTrackImpl(const recob::TrackTrajectory &traj, const int tkID, const std::vector< art::Ptr< recob::Hit >> &inHits, const SMatrixSym55 &covVtx, const SMatrixSym55 &covEnd, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
function that actually calls the fitter
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:101
std::pair< SMatrixSym55, SMatrixSym55 > Covariances() const
Access to position, momentum or covariance at the start and end of the track.
Definition: Track.h:165
int ID() const
Definition: Track.h:201
bool trkmkr::KalmanFilterFitTrackMaker::makeTrackImpl ( const recob::TrackTrajectory traj,
const int  tkID,
const std::vector< art::Ptr< recob::Hit >> &  inHits,
const SMatrixSym55 covVtx,
const SMatrixSym55 covEnd,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit >> &  outHits,
OptionalOutputs optionals 
) const

function that actually calls the fitter

Definition at line 299 of file KalmanFilterFitTrackMaker_tool.cc.

References trkf::TrackKalmanFitter::fitTrack(), getMomentum(), getParticleID(), isFlipDirection(), kalmanFitter, trkmkr::KalmanFilterFitTrackMaker::Options::keepInputTrajectoryPoints, p_, and restoreInputPoints().

Referenced by initEvent(), and makeTrack().

307 {
308  //
309  const int pid = getParticleID(traj, tkID);
310  const bool flipDirection = isFlipDirection(traj, tkID);
311  const double mom = getMomentum(traj, pid, flipDirection, tkID); // what about mom uncertainty?
312  // std::cout << "fitting track with mom=" << mom << " pid=" << pid << " flip="
313  // << flipDirection << " start pos=" << traj.Start() << " dir=" <<
314  // traj.StartDirection() << std::endl;
315  bool fitok = kalmanFitter.fitTrack(traj,
316  tkID,
317  covVtx,
318  covEnd,
319  inHits,
320  mom,
321  pid,
322  flipDirection,
323  outTrack,
324  outHits,
325  optionals);
326  if (!fitok)
327  return false;
328  //
329  // std::cout << "fitted track with mom=" << outTrack.StartMomentum() << "
330  // pid=" << outTrack.ParticleId() << " flip=" << flipDirection << " start pos="
331  // << outTrack.Start() << " dir=" << outTrack.StartDirection() << " nchi2=" <<
332  // outTrack.Chi2PerNdof() << std::endl;
333  //
334  if (p_().options().keepInputTrajectoryPoints()) {
335  restoreInputPoints(traj, inHits, outTrack, outHits, optionals);
336  }
337  //
338  return true;
339 }
int getParticleID(const recob::TrackTrajectory &traj, const int tkID) const
set the particle ID hypothesis
bool fitTrack(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.
void restoreInputPoints(const recob::TrackTrajectory &traj, const std::vector< art::Ptr< recob::Hit >> &inHits, recob::Track &outTrack, std::vector< art::Ptr< recob::Hit >> &outHits, OptionalOutputs &optionals) const
double getMomentum(const recob::TrackTrajectory &traj, const int pid, const bool isFlip, const int tkID) const
set the initial momentum estimate
bool isFlipDirection(const recob::TrackTrajectory &traj, const int tkID) const
decide whether to flip the direction or not
void trkmkr::KalmanFilterFitTrackMaker::restoreInputPoints ( const recob::TrackTrajectory traj,
const std::vector< art::Ptr< recob::Hit >> &  inHits,
recob::Track outTrack,
std::vector< art::Ptr< recob::Hit >> &  outHits,
OptionalOutputs optionals 
) const

restore the TrajectoryPoints in the Track to be the same as those in the input TrackTrajectory (but keep covariance matrices and chi2 from fit).

Definition at line 406 of file KalmanFilterFitTrackMaker_tool.cc.

References recob::Track::Chi2(), recob::Track::Covariances(), DEFINE_ART_CLASS_TOOL, recob::Track::FlagsAtPoint(), recob::TrajectoryPointFlags::fromHit(), recob::Trajectory::HasMomentum(), recob::Track::ID(), trkmkr::OptionalOutputs::isTrackFitInfosInit(), recob::TrackTrajectory::LocationAtPoint(), recob::TrajectoryPointFlags::mask(), recob::TrackTrajectory::MomentumVectorAtPoint(), recob::TrajectoryPointFlagTraits::NoPoint, recob::Track::NumberTrajectoryPoints(), recob::Track::ParticleId(), and util::flags::BitMask< Storage >::unset().

Referenced by makeTrack(), and makeTrackImpl().

411 {
412  if (optionals.isTrackFitInfosInit()) {
413  throw cet::exception("KalmanFilterFitTrackMaker")
414  << "Option keepInputTrajectoryPoints not compatible with "
415  "doTrackFitHitInfo, please set doTrackFitHitInfo to false in the "
416  "track producer.\n";
417  }
418  const auto np = outTrack.NumberTrajectoryPoints();
419  trkmkr::TrackCreationBookKeeper tcbk(outHits,
420  optionals,
421  outTrack.ID(),
422  outTrack.ParticleId(),
423  traj.HasMomentum());
424  //
425  std::vector<unsigned int> flagsmap(np, -1);
426  for (unsigned int i = 0; i < np; ++i)
427  flagsmap[outTrack.FlagsAtPoint(i).fromHit()] = i;
428  //
429  for (unsigned int p = 0; p < np; ++p) {
430  auto mask = outTrack.FlagsAtPoint(flagsmap[p]).mask();
433  tcbk.addPoint(traj.LocationAtPoint(p),
434  traj.MomentumVectorAtPoint(p),
435  inHits[p],
437  0);
438  }
439  auto covs = outTrack.Covariances();
440  tcbk.setTotChi2(outTrack.Chi2());
441  outTrack = tcbk.finalizeTrack(std::move(covs.first), std::move(covs.second));
442  //
443 }
static constexpr Flag_t NoPoint
The trajectory point is not defined.
int ParticleId() const
Access to various track properties.
Definition: Track.h:174
float Chi2() const
Access to various track properties.
Definition: Track.h:171
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:105
constexpr Mask_t const & mask() const
Returns the entire set of bits as a bit mask.
std::pair< SMatrixSym55, SMatrixSym55 > Covariances() const
Access to position, momentum or covariance at the start and end of the track.
Definition: Track.h:165
constexpr HitIndex_t fromHit() const
T LocationAtPoint(unsigned int p) const
Position at point p. Use e.g. as:
int ID() const
Definition: Track.h:201
void unset(Flag first, OtherFlags...others)
Unsets all specified flags.
Definition: BitMask.h:779
bool HasMomentum() const
Returns whether information about the momentum is available.
Definition: Trajectory.h:431
Helper class to aid the creation of a recob::Track, keeping data vectors in sync. ...
PointFlags_t const & FlagsAtPoint(size_t i) const
Access to i-th TrajectoryPoint or its Flags.
Definition: Track.h:121
T MomentumVectorAtPoint(unsigned int p) const
Momentum vector at point p. Use e.g. as:
Set of flags pertaining a point of the track.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

bool trkmkr::KalmanFilterFitTrackMaker::alwaysFlip_
private
const std::vector<anab::CosmicTag>* trkmkr::KalmanFilterFitTrackMaker::cont = nullptr
private

Definition at line 292 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by getMomentum(), and initEvent().

art::InputTag trkmkr::KalmanFilterFitTrackMaker::contInputTag_
private

Definition at line 283 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by initEvent(), and KalmanFilterFitTrackMaker().

bool trkmkr::KalmanFilterFitTrackMaker::dirFromVec_
private
recob::tracking::Vector_t trkmkr::KalmanFilterFitTrackMaker::dirVec
private

Definition at line 290 of file KalmanFilterFitTrackMaker_tool.cc.

const trkf::TrackKalmanFitter trkmkr::KalmanFilterFitTrackMaker::kalmanFitter
private

Definition at line 277 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by KalmanFilterFitTrackMaker(), and makeTrackImpl().

const std::vector<recob::MCSFitResult>* trkmkr::KalmanFilterFitTrackMaker::mcs = nullptr
private

Definition at line 291 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by getMomentum(), and initEvent().

const trkf::TrajectoryMCSFitter trkmkr::KalmanFilterFitTrackMaker::mcsfitter
private

Definition at line 278 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by getMomentum(), and KalmanFilterFitTrackMaker().

art::InputTag trkmkr::KalmanFilterFitTrackMaker::mcsInputTag_
private

Definition at line 281 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by initEvent(), and KalmanFilterFitTrackMaker().

double trkmkr::KalmanFilterFitTrackMaker::mom_def_
private

Definition at line 279 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by getMomentum(), and KalmanFilterFitTrackMaker().

double trkmkr::KalmanFilterFitTrackMaker::mom_len_cut_
private

Definition at line 286 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by getParticleID(), and KalmanFilterFitTrackMaker().

bool trkmkr::KalmanFilterFitTrackMaker::momFromCombAndPid_
private
bool trkmkr::KalmanFilterFitTrackMaker::momFromMCSColl_
private
Parameters trkmkr::KalmanFilterFitTrackMaker::p_
private

Definition at line 275 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by KalmanFilterFitTrackMaker(), and makeTrackImpl().

const std::vector<anab::ParticleID>* trkmkr::KalmanFilterFitTrackMaker::pid = nullptr
private

Definition at line 293 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by getMomentum().

int trkmkr::KalmanFilterFitTrackMaker::pid_def_
private

Definition at line 287 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by getParticleID(), and KalmanFilterFitTrackMaker().

bool trkmkr::KalmanFilterFitTrackMaker::pidFromColl_
private
art::InputTag trkmkr::KalmanFilterFitTrackMaker::pidInputTag_
private

Definition at line 285 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by initEvent(), and KalmanFilterFitTrackMaker().

const trkf::TrackStatePropagator trkmkr::KalmanFilterFitTrackMaker::prop
private

Definition at line 276 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by KalmanFilterFitTrackMaker().

trkf::TrackMomentumCalculator trkmkr::KalmanFilterFitTrackMaker::tmc
private

Definition at line 294 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by getMomentum().


The documentation for this class was generated from the following file: