LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
trkmkr::KalmanFilterFitTrackMaker Class Reference

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...
 
 ~KalmanFilterFitTrackMaker ()
 Destructor. 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
 override of TrackMaker purely virtual function with recob::TrackTrajectory as argument More...
 
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 setParticleID (const recob::TrackTrajectory &traj, const int tkID) const
 set the particle ID hypothesis More...
 
double setMomentum (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
 restore the TrajectoryPoints in the Track to be the same as those in the input TrackTrajectory (but keep covariance matrices and chi2 from fit). More...
 
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::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...
 

Private Attributes

Parameters p_
 
const trkf::TrackKalmanFitterkalmanFitter
 
const trkf::TrackStatePropagatorprop
 
const trkf::TrajectoryMCSFittermcsfitter
 
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 40 of file KalmanFilterFitTrackMaker_tool.cc.

Member Typedef Documentation

Constructor & Destructor Documentation

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

Constructor from Parameters.

Definition at line 130 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.

130  : p_(p)
131  {
132  prop = new trkf::TrackStatePropagator(p_().propagator);
134  mcsfitter = new trkf::TrajectoryMCSFitter(p_().mcsfit);
135  mom_def_ = p_().options().defaultMomInGeV();
136  momFromMCSColl_ = p_().options().momFromMCSCollection();
137  if (momFromMCSColl_) {
138  mcsInputTag_ = p_().options().mcsInputTag();
139  }
140  momFromCombAndPid_ = p_().options().momFromCombAndPid();
141  if (momFromCombAndPid_) {
142  contInputTag_ = p_().options().contInputTag();
143  }
144  pidFromColl_ = p_().options().pidFromCollection();
145  if (pidFromColl_) {
146  pidInputTag_ = p_().options().pidInputTag();
147  }
148  mom_len_cut_ = p_().options().pidFromLengthCut();
149  pid_def_ = p_().options().defaultPdgId();
150  alwaysFlip_ = p_().options().alwaysInvertDir();
151  dirFromVec_ = p_().options().dirFromVec();
152  if (dirFromVec_) {
153  auto d = p_().options().dirVec();
154  dirVec = recob::tracking::Vector_t(d[0],d[1],d[2]);
155  }
156  //
157  if ( p_().options().keepInputTrajectoryPoints() && (p_().fitter().sortHitsByPlane() || p_().fitter().sortOutputHitsMinLength() || p_().fitter().skipNegProp()) ) {
158  throw cet::exception("KalmanFilterFitTrackMaker")
159  << "Incompatible configuration parameters: keepInputTrajectoryPoints needs the following fitter options all set to false: sortHitsByPlane, sortOutputHitsMinLength, skipNegProp." << "\n";
160  }
162  throw cet::exception("KalmanFilterFitTrackMaker")
163  << "Incompatible configuration parameters: momFromMCSCollection and momFromCombAndPid cannot be both true at the same time." << "\n";
164  }
165  if (pidFromColl_ && mom_len_cut_>0) {
166  throw cet::exception("KalmanFilterFitTrackMaker")
167  << "Incompatible configuration parameters: pidFromCollection and pidFromLengthCut cannot be respectively true and >0. at the same time." << "\n";
168  }
169  if (alwaysFlip_ && dirFromVec_) {
170  throw cet::exception("KalmanFilterFitTrackMaker")
171  << "Incompatible configuration parameters: alwaysInvertDir and dirFromVec cannot be both true at the same time." << "\n";
172  }
173  //
174  }
const trkf::TrajectoryMCSFitter * mcsfitter
Fit tracks using Kalman Filter fit+smooth.
const trkf::TrackKalmanFitter * kalmanFitter
Class for propagation of a trkf::TrackState to a recob::tracking::Plane.
geo::Vector_t Vector_t
Type for representation of momenta in 3D space.
Definition: TrackingTypes.h:23
Float_t d
Definition: plot.C:237
const trkf::TrackStatePropagator * prop
Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Trac...
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
trkmkr::KalmanFilterFitTrackMaker::~KalmanFilterFitTrackMaker ( )
inline

Destructor.

Definition at line 177 of file KalmanFilterFitTrackMaker_tool.cc.

References kalmanFitter, mcsfitter, and prop.

177  {
178  delete prop;
179  delete kalmanFitter;
180  delete mcsfitter;
181  }
const trkf::TrajectoryMCSFitter * mcsfitter
const trkf::TrackKalmanFitter * kalmanFitter
const trkf::TrackStatePropagator * prop

Member Function Documentation

virtual void trkmkr::KalmanFilterFitTrackMaker::initEvent ( const art::Event e)
inlineoverridevirtual

initialize event: get collection of recob::MCSFitResult

Reimplemented from trkmkr::TrackMaker.

Definition at line 184 of file KalmanFilterFitTrackMaker_tool.cc.

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

184  {
185  if (momFromMCSColl_) mcs = e.getValidHandle<std::vector<recob::MCSFitResult> >(mcsInputTag_).product();
186  if (momFromCombAndPid_) {
187  cont = e.getValidHandle<std::vector<anab::CosmicTag> >(contInputTag_).product();
188  }
189  if (pidFromColl_) {
190  pid = e.getValidHandle<std::vector<anab::ParticleID> >(pidInputTag_).product();
191  }
192  return;
193  }
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 304 of file KalmanFilterFitTrackMaker_tool.cc.

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

Referenced by makeTrack(), and makeTrackImpl().

304  {
305  if (alwaysFlip_) {
306  return true;
307  } else if (dirFromVec_) {
308  auto tdir = traj.VertexDirection();
309  if ( tdir.Dot(dirVec)<0. ) return true;
310  }
311  return false;
312 }
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:172
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:172
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 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:105
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
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
inlineoverridevirtual

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

Implements trkmkr::TrackMaker.

Definition at line 201 of file KalmanFilterFitTrackMaker_tool.cc.

References makeTrackImpl().

202  {
203  return makeTrackImpl(traj, tkID, inHits, trkf::SMatrixSym55(), trkf::SMatrixSym55(), outTrack, outHits, optionals);
204  }
recob::tracking::SMatrixSym55 SMatrixSym55
Definition: TrackState.h:15
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
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
inlineoverridevirtual

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

Reimplemented from trkmkr::TrackMaker.

Definition at line 207 of file KalmanFilterFitTrackMaker_tool.cc.

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

208  {
209  auto covs = track.Covariances();
210  return makeTrackImpl(track.Trajectory(), track.ID(), inHits, covs.first, covs.second, outTrack, outHits, optionals);
211  }
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:105
std::pair< SMatrixSym55, SMatrixSym55 > Covariances() const
Access to position, momentum or covariance at the start and end of the track.
Definition: Track.h:169
int ID() const
Definition: Track.h:205
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
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 249 of file KalmanFilterFitTrackMaker_tool.cc.

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

Referenced by initEvent(), and makeTrack().

251  {
252  //
253  const int pid = setParticleID(traj, tkID);
254  const bool flipDirection = isFlipDirection(traj, tkID);
255  const double mom = setMomentum(traj, pid, flipDirection, tkID);// what about mom uncertainty?
256  //std::cout << "fitting track with mom=" << mom << " pid=" << pid << " flip=" << flipDirection << " start pos=" << traj.Start() << " dir=" << traj.StartDirection() << std::endl;
257  bool fitok = kalmanFitter->fitTrack(traj, tkID, covVtx, covEnd, inHits, mom, pid, flipDirection, outTrack, outHits, optionals);
258  if (!fitok) return false;
259  //
260  //std::cout << "fitted track with mom=" << outTrack.StartMomentum() << " pid=" << outTrack.ParticleId() << " flip=" << flipDirection << " start pos=" << outTrack.Start() << " dir=" << outTrack.StartDirection() << " nchi2=" << outTrack.Chi2PerNdof() << std::endl;
261  //
262  if (p_().options().keepInputTrajectoryPoints()) {
263  restoreInputPoints(traj,inHits,outTrack,outHits,optionals);
264  }
265  //
266  return true;
267 }
const trkf::TrackKalmanFitter * kalmanFitter
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.
double setMomentum(const recob::TrackTrajectory &traj, const int pid, const bool isFlip, const int tkID) const
set the initial momentum estimate
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
restore the TrajectoryPoints in the Track to be the same as those in the input TrackTrajectory (but k...
bool isFlipDirection(const recob::TrackTrajectory &traj, const int tkID) const
decide whether to flip the direction or not
int setParticleID(const recob::TrackTrajectory &traj, const int tkID) const
set the particle ID hypothesis
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 314 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::Trajectory::LocationAtPoint(), recob::TrajectoryPointFlags::mask(), recob::Trajectory::MomentumVectorAtPoint(), recob::TrajectoryPointFlagTraits::NoPoint, recob::Track::NumberTrajectoryPoints(), recob::Track::ParticleId(), and util::flags::BitMask< Storage >::unset().

Referenced by makeTrack(), and makeTrackImpl().

315  {
316  if (optionals.isTrackFitInfosInit()) {
317  throw cet::exception("KalmanFilterFitTrackMaker")
318  << "Option keepInputTrajectoryPoints not compatible with doTrackFitHitInfo, please set doTrackFitHitInfo to false in the track producer.\n";
319  }
320  const auto np = outTrack.NumberTrajectoryPoints();
321  trkmkr::TrackCreationBookKeeper tcbk(outHits, optionals, outTrack.ID(), outTrack.ParticleId(), traj.HasMomentum());
322  //
323  std::vector<unsigned int> flagsmap(np,-1);
324  for (unsigned int i=0; i<np; ++i) flagsmap[outTrack.FlagsAtPoint(i).fromHit()] = i;
325  //
326  for (unsigned int p=0; p<np; ++p) {
327  auto mask = outTrack.FlagsAtPoint(flagsmap[p]).mask();
329  tcbk.addPoint(traj.LocationAtPoint(p), traj.MomentumVectorAtPoint(p), inHits[p], recob::TrajectoryPointFlags(p,mask), 0);
330  }
331  auto covs = outTrack.Covariances();
332  tcbk.setTotChi2(outTrack.Chi2());
333  outTrack = tcbk.finalizeTrack(std::move(covs.first),std::move(covs.second));
334  //
335 }
static constexpr Flag_t NoPoint
The trajectory point is not defined.
int ParticleId() const
Access to various track properties.
Definition: Track.h:178
float Chi2() const
Access to various track properties.
Definition: Track.h:175
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:109
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:169
constexpr HitIndex_t fromHit() const
Point_t const & LocationAtPoint(size_t i) const
Returns the position at the specified trajectory point.
Definition: Trajectory.h:255
Vector_t const & MomentumVectorAtPoint(size_t i) const
Returns the momentum vector at a point.
Definition: Trajectory.h:492
int ID() const
Definition: Track.h:205
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:460
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:125
Set of flags pertaining a point of the track.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
double trkmkr::KalmanFilterFitTrackMaker::setMomentum ( const recob::TrackTrajectory traj,
const int  pid,
const bool  isFlip,
const int  tkID 
) const

set the initial momentum estimate

Definition at line 269 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().

269  {
270  double mom = mom_def_;
271  if (momFromMCSColl_) {
272  double mcsmom = ( isFlip ? mcs->at(tkID).bwdMomentum() : mcs->at(tkID).fwdMomentum() );
273  //make sure the mcs fit converged
274  if (mcsmom>0.01 && mcsmom<7.) mom = mcsmom;
275  }
276  if (momFromCombAndPid_) {
277  bool isContained = cont->at(tkID).CosmicType()==anab::kNotTagged;
278  // for now momentum from range implemented only for muons and protons
279  // so treat pions as muons (~MIPs) and kaons as protons
280  int pidtmp = pid;
281  if (pidtmp==211 || pidtmp==13) pidtmp = 13;
282  else pidtmp = 2212;
283  mom = tmc.GetTrackMomentum(traj.Length(),pidtmp);
284  if (isContained==false) {
285  auto mcsresult = mcsfitter->fitMcs(traj,pid);
286  double mcsmom = ( isFlip ? mcsresult.bwdMomentum() : mcsresult.fwdMomentum() );
287  //make sure the mcs fit converged, also the mcsmom should not be less than the range!
288  if (mcsmom>0.01 && mcsmom<7. && mcsmom>mom) mom = mcsmom;
289  }
290  }
291  return mom;
292 }
const trkf::TrajectoryMCSFitter * mcsfitter
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)
int trkmkr::KalmanFilterFitTrackMaker::setParticleID ( const recob::TrackTrajectory traj,
const int  tkID 
) const

set the particle ID hypothesis

Definition at line 294 of file KalmanFilterFitTrackMaker_tool.cc.

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

Referenced by makeTrack(), and makeTrackImpl().

294  {
295  if (pidFromColl_) {
296  return pid->at(tkID).Pdg();
297  }
298  if (mom_len_cut_>0.) {
299  return (traj.Length()<mom_len_cut_ ? 2212 : 13);
300  }
301  return pid_def_;
302 }
double Length(size_t startAt=0) const
Returns the approximate length of the trajectory.

Member Data Documentation

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

Definition at line 242 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by initEvent(), and setMomentum().

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

Definition at line 233 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 240 of file KalmanFilterFitTrackMaker_tool.cc.

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

Definition at line 241 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by initEvent(), and setMomentum().

const trkf::TrajectoryMCSFitter* trkmkr::KalmanFilterFitTrackMaker::mcsfitter
private
art::InputTag trkmkr::KalmanFilterFitTrackMaker::mcsInputTag_
private

Definition at line 231 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by initEvent(), and KalmanFilterFitTrackMaker().

double trkmkr::KalmanFilterFitTrackMaker::mom_def_
private

Definition at line 229 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by KalmanFilterFitTrackMaker(), and setMomentum().

double trkmkr::KalmanFilterFitTrackMaker::mom_len_cut_
private

Definition at line 236 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by KalmanFilterFitTrackMaker(), and setParticleID().

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

Definition at line 225 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by KalmanFilterFitTrackMaker(), and makeTrackImpl().

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

Definition at line 243 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by setMomentum().

int trkmkr::KalmanFilterFitTrackMaker::pid_def_
private

Definition at line 237 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by KalmanFilterFitTrackMaker(), and setParticleID().

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

Definition at line 235 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by initEvent(), and KalmanFilterFitTrackMaker().

const trkf::TrackStatePropagator* trkmkr::KalmanFilterFitTrackMaker::prop
private
trkf::TrackMomentumCalculator trkmkr::KalmanFilterFitTrackMaker::tmc
mutableprivate

Definition at line 244 of file KalmanFilterFitTrackMaker_tool.cc.

Referenced by setMomentum().


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