LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
trkf::Track3DKalmanHitAlg Class Reference

#include "Track3DKalmanHitAlg.h"

Public Member Functions

 Track3DKalmanHitAlg (const fhicl::ParameterSet &pset)
 Constructor. More...
 
std::vector< trkf::KalmanOutputmakeTracks (detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, KalmanInputs &kalman_inputs)
 
void fetchPFParticleSeeds (const art::PtrVector< recob::Seed > &pfseeds, const std::vector< Hits > &pfseedhits, std::vector< recob::Seed > &seeds, std::vector< Hits > &hitsperseed) const
 Fetch Seeds method. More...
 
recob::Seed makeSeed (detinfo::DetectorPropertiesData const &detProp, const Hits &hits) const
 Make seed method. More...
 
void growSeedsIntoTracks (detinfo::DetectorPropertiesData const &detProp, const bool pfseed, const std::vector< recob::Seed > &seeds, const std::vector< Hits > &hitsperseed, Hits &unusedhits, Hits &hits, std::deque< KGTrack > &kalman_tracks)
 Grow Seeds method. More...
 
void growSeedIntoTracks (detinfo::DetectorPropertiesData const &detProp, const bool pfseed, const recob::Seed &seed, const Hits &hpsit, Hits &unusedhits, Hits &hits, std::deque< KGTrack > &kgtracks)
 
void chopHitsOffSeeds (Hits const &hpsit, bool pfseed, Hits &seedhits) const
 Chop hits off of the end of seeds. More...
 
bool testSeedSlope (const double *dir) const
 
std::shared_ptr< SurfacemakeSurface (const recob::Seed &seed, double *dir) const
 method to return a seed to surface. More...
 
bool makeKalmanTracks (detinfo::DetectorPropertiesData const &detProp, const std::shared_ptr< trkf::Surface > psurf, const Surface::TrackDirection trkdir, Hits &seedhits, Hits &hits, std::deque< KGTrack > &kalman_tracks)
 
bool smoothandextendTrack (detinfo::DetectorPropertiesData const &detProp, Propagator const &propagator, KGTrack &trg0, const Hits hits, unsigned int prefplane, std::deque< KGTrack > &kalman_tracks)
 SMooth and extend track. More...
 
bool extendandsmoothLoop (detinfo::DetectorPropertiesData const &detProp, Propagator const &propagator, KGTrack &trg1, unsigned int prefplane, Hits &trackhits) const
 SMooth and extend a track in a loop. More...
 
void filterHitsOnKalmanTrack (const KGTrack &trg, Hits &hits, Hits &seederhits) const
 Filter hits that are on kalman tracks. More...
 
std::unique_ptr< KHitContainerfillHitContainer (detinfo::DetectorPropertiesData const &detProp, const Hits &hits) const
 Fill hit container with either seedhits or filtered hits i.e. recob::Hit. More...
 
bool qualityCutsOnSeedTrack (const KGTrack &trg0) const
 Quality cuts on seed track. More...
 
void fitnupdateMomentum (Propagator const &propagator, KGTrack &trg1, KGTrack &trg2) const
 fit and update method, used twice. More...
 

Private Attributes

bool fDoDedx
 Global dE/dx enable flag. More...
 
bool fSelfSeed
 Self seed flag. More...
 
double fMaxTcut
 Maximum delta ray energy in MeV for restricted dE/dx. More...
 
bool fLineSurface
 Line surface flag. More...
 
size_t fMinSeedHits
 Minimum number of hits per track seed. More...
 
int fMinSeedChopHits
 Potentially chop seeds that exceed this length. More...
 
int fMaxChopHits
 Maximum number of hits to chop from each end of seed. More...
 
double fMaxSeedChiDF
 Maximum seed track chisquare/dof. More...
 
double fMinSeedSlope
 Minimum seed slope (dx/dz). More...
 
double fInitialMomentum
 Initial (or constant) momentum. More...
 
KalmanFilterAlg fKFAlg
 Kalman filter algorithm. More...
 
SeedFinderAlgorithm fSeedFinderAlg
 Seed finder. More...
 
int fNumTrack
 Number of tracks produced. More...
 

Detailed Description

Definition at line 60 of file Track3DKalmanHitAlg.h.

Constructor & Destructor Documentation

trkf::Track3DKalmanHitAlg::Track3DKalmanHitAlg ( const fhicl::ParameterSet pset)
explicit

Constructor.

Definition at line 82 of file Track3DKalmanHitAlg.cxx.

References fInitialMomentum, fKFAlg, fLineSurface, fMaxChopHits, fMaxSeedChiDF, fMaxTcut, fMinSeedChopHits, fMinSeedHits, fMinSeedSlope, fNumTrack, fSeedFinderAlg, fSelfSeed, and fhicl::ParameterSet::get().

83  : fDoDedx{pset.get<bool>("DoDedx")}
84  , fSelfSeed{pset.get<bool>("SelfSeed")}
85  , fMaxTcut{pset.get<double>("MaxTcut")}
86  , fLineSurface{pset.get<bool>("LineSurface")}
87  , fMinSeedHits{pset.get<size_t>("MinSeedHits")}
88  , fMinSeedChopHits{pset.get<int>("MinSeedChopHits")}
89  , fMaxChopHits{pset.get<int>("MaxChopHits")}
90  , fMaxSeedChiDF{pset.get<double>("MaxSeedChiDF")}
91  , fMinSeedSlope{pset.get<double>("MinSeedSlope")}
92  , fInitialMomentum{pset.get<double>("InitialMomentum")}
93  , fKFAlg(pset.get<fhicl::ParameterSet>("KalmanFilterAlg"))
94  , fSeedFinderAlg(pset.get<fhicl::ParameterSet>("SeedFinderAlg"))
95  , fNumTrack(0)
96 {
97  mf::LogInfo("Track3DKalmanHitAlg") << "Track3DKalmanHitAlg instantiated.";
98 }
size_t fMinSeedHits
Minimum number of hits per track seed.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool fDoDedx
Global dE/dx enable flag.
double fMaxSeedChiDF
Maximum seed track chisquare/dof.
int fMinSeedChopHits
Potentially chop seeds that exceed this length.
double fInitialMomentum
Initial (or constant) momentum.
T get(std::string const &key) const
Definition: ParameterSet.h:314
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
int fNumTrack
Number of tracks produced.
bool fLineSurface
Line surface flag.
SeedFinderAlgorithm fSeedFinderAlg
Seed finder.
int fMaxChopHits
Maximum number of hits to chop from each end of seed.
bool fSelfSeed
Self seed flag.
double fMinSeedSlope
Minimum seed slope (dx/dz).
double fMaxTcut
Maximum delta ray energy in MeV for restricted dE/dx.

Member Function Documentation

void trkf::Track3DKalmanHitAlg::chopHitsOffSeeds ( Hits const &  hpsit,
bool  pfseed,
Hits seedhits 
) const

Chop hits off of the end of seeds.

Definition at line 379 of file Track3DKalmanHitAlg.cxx.

References art::PtrVector< T >::begin(), art::PtrVector< T >::end(), fMaxChopHits, fMinSeedChopHits, fSelfSeed, art::PtrVector< T >::push_back(), art::PtrVector< T >::reserve(), and art::PtrVector< T >::size().

Referenced by growSeedIntoTracks().

382 {
383  const int nchopmax =
384  (pfseed || fSelfSeed) ? 0 : std::max(0, int((hpsit.size() - fMinSeedChopHits) / 2));
385  //SS: FIXME
386 
387  const int nchop = std::min(nchopmax, fMaxChopHits);
388  Hits::const_iterator itb = hpsit.begin();
389  Hits::const_iterator ite = hpsit.end();
390  itb += nchop;
391  ite -= nchop;
392  seedhits.reserve(hpsit.size());
393  for (Hits::const_iterator it = itb; it != ite; ++it)
394  seedhits.push_back(*it);
395 }
int fMinSeedChopHits
Potentially chop seeds that exceed this length.
typename data_t::const_iterator const_iterator
Definition: PtrVector.h:55
int fMaxChopHits
Maximum number of hits to chop from each end of seed.
bool fSelfSeed
Self seed flag.
bool trkf::Track3DKalmanHitAlg::extendandsmoothLoop ( detinfo::DetectorPropertiesData const &  detProp,
Propagator const &  propagator,
KGTrack trg1,
unsigned int  prefplane,
Hits trackhits 
) const

SMooth and extend a track in a loop.

Definition at line 449 of file Track3DKalmanHitAlg.cxx.

References trkf::KalmanFilterAlg::extendTrack(), fDoDedx, fillHitContainer(), trkf::KGTrack::fillHits(), fitnupdateMomentum(), fKFAlg, and trkf::KalmanFilterAlg::smoothTrack().

Referenced by smoothandextendTrack().

454 {
455  bool ok = true;
456  const int niter = 6;
457  int nfail = 0; // Number of consecutive extend fails.
458  for (int ix = 0; ok && ix < niter && nfail < 2; ++ix) {
459 
460  // Fill a collection of hits from the last good track
461  // (initially the seed track).
462  Hits goodhits;
463  std::vector<unsigned int> hittpindex;
464  trg1.fillHits(goodhits, hittpindex);
465 
466  // Filter hits already on the track out of the available hits.
467  filterHits(trackhits, goodhits);
468 
469  // Fill hit container using filtered hits.
470  std::unique_ptr<KHitContainer> ptrackcont = fillHitContainer(detProp, trackhits);
471 
472  // Extend the track. It is not an error for the
473  // extend operation to fail, meaning that no new hits
474  // were added.
475 
476  if (fKFAlg.extendTrack(trg1, propagator, *ptrackcont))
477  nfail = 0;
478  else
479  ++nfail;
480 
481  // Smooth the extended track, and make a new
482  // unidirectionally fit track in the opposite
483  // direction.
484 
485  KGTrack trg2(prefplane);
486  ok = fKFAlg.smoothTrack(trg1, &trg2, propagator);
487  if (ok) {
488  // Skip momentum estimate for constant-momentum tracks.
489  if (fDoDedx) { fitnupdateMomentum(propagator, trg1, trg2); }
490  trg1 = trg2;
491  }
492  }
493  return ok;
494 }
bool fDoDedx
Global dE/dx enable flag.
bool extendTrack(KGTrack &trg, const Propagator &prop, KHitContainer &hits) const
Add hits to existing track.
std::unique_ptr< KHitContainer > fillHitContainer(detinfo::DetectorPropertiesData const &detProp, const Hits &hits) const
Fill hit container with either seedhits or filtered hits i.e. recob::Hit.
bool smoothTrack(KGTrack &trg, KGTrack *trg1, const Propagator &prop) const
Smooth track.
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
art::PtrVector< recob::Hit > Hits
void fitnupdateMomentum(Propagator const &propagator, KGTrack &trg1, KGTrack &trg2) const
fit and update method, used twice.
void trkf::Track3DKalmanHitAlg::fetchPFParticleSeeds ( const art::PtrVector< recob::Seed > &  pfseeds,
const std::vector< Hits > &  pfseedhits,
std::vector< recob::Seed > &  seeds,
std::vector< Hits > &  hitsperseed 
) const

Fetch Seeds method.

Definition at line 165 of file Track3DKalmanHitAlg.cxx.

Referenced by makeTracks().

169 {
170  for (const auto& pseed : pfseeds) {
171  seeds.push_back(*pseed);
172  }
173  hitsperseed.insert(hitsperseed.end(), pfseedhits.begin(), pfseedhits.end());
174 }
std::unique_ptr< trkf::KHitContainer > trkf::Track3DKalmanHitAlg::fillHitContainer ( detinfo::DetectorPropertiesData const &  detProp,
const Hits hits 
) const

Fill hit container with either seedhits or filtered hits i.e. recob::Hit.

Definition at line 344 of file Track3DKalmanHitAlg.cxx.

References fLineSurface.

Referenced by extendandsmoothLoop(), and makeKalmanTracks().

347 {
348  std::unique_ptr<KHitContainer> hitcont(fLineSurface ?
349  static_cast<KHitContainer*>(new KHitContainerWireLine) :
350  static_cast<KHitContainer*>(new KHitContainerWireX));
351  hitcont->fill(detProp, hits, -1);
352  return hitcont;
353 }
void hits()
Definition: readHits.C:15
bool fLineSurface
Line surface flag.
void trkf::Track3DKalmanHitAlg::filterHitsOnKalmanTrack ( const KGTrack trg,
Hits hits,
Hits seederhits 
) const

Filter hits that are on kalman tracks.

Definition at line 331 of file Track3DKalmanHitAlg.cxx.

References trkf::KGTrack::fillHits().

Referenced by growSeedIntoTracks().

334 {
335  Hits track_used_hits;
336  std::vector<unsigned int> hittpindex;
337  trg.fillHits(track_used_hits, hittpindex);
338  filterHits(hits, track_used_hits);
339  filterHits(seederhits, track_used_hits);
340 }
void hits()
Definition: readHits.C:15
art::PtrVector< recob::Hit > Hits
void trkf::Track3DKalmanHitAlg::fitnupdateMomentum ( Propagator const &  propagator,
KGTrack trg1,
KGTrack trg2 
) const

fit and update method, used twice.

Definition at line 497 of file Track3DKalmanHitAlg.cxx.

References trkf::KalmanFilterAlg::fitMomentum(), fKFAlg, and trkf::KalmanFilterAlg::updateMomentum().

Referenced by extendandsmoothLoop(), and smoothandextendTrack().

500 {
501  KETrack tremom;
502  if (fKFAlg.fitMomentum(trg1, propagator, tremom)) {
503  fKFAlg.updateMomentum(tremom, propagator, trg2);
504  }
505 }
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
bool fitMomentum(const KGTrack &trg, const Propagator &prop, KETrack &tremom) const
Estimate track momentum using either range or multiple scattering.
bool updateMomentum(const KETrack &tremom, const Propagator &prop, KGTrack &trg) const
Set track momentum at each track surface.
void trkf::Track3DKalmanHitAlg::growSeedIntoTracks ( detinfo::DetectorPropertiesData const &  detProp,
const bool  pfseed,
const recob::Seed seed,
const Hits hpsit,
Hits unusedhits,
Hits hits,
std::deque< KGTrack > &  kgtracks 
)

Definition at line 198 of file Track3DKalmanHitAlg.cxx.

References trkf::Surface::BACKWARD, chopHitsOffSeeds(), dir, fDoDedx, filterHitsOnKalmanTrack(), trkf::Surface::FORWARD, makeKalmanTracks(), makeSurface(), art::PtrVector< T >::size(), and testSeedSlope().

Referenced by growSeedsIntoTracks().

205 {
206  Hits trimmedhits;
207  // Chop a couple of hits off each end of the seed.
208  chopHitsOffSeeds(hpsit, pfseed, trimmedhits);
209 
210  // Filter hits used by (chopped) seed from hits available to make future seeds.
211  // No matter what, we will never use these hits for another seed.
212  // This eliminates the possibility of an infinite loop.
213 
214  size_t initial_unusedhits = unusedhits.size();
215  filterHits(unusedhits, trimmedhits);
216 
217  // Require that this seed be fully disjoint from existing tracks.
218  //SS: replace this test with a method with appropriate name
219  if (!(trimmedhits.size() + unusedhits.size() == initial_unusedhits)) return;
220 
221  // Convert seed into initial KTracks on surface located at seed point,
222  // and normal to seed direction.
223  double dir[3];
224  std::shared_ptr<Surface> psurf = makeSurface(seed, dir);
225 
226  // Cut on the seed slope dx/ds.
227  //SS: replace test name with a reasonable name
228  if (!testSeedSlope(dir)) return;
229 
230  // Make one or two initial KTracks for forward and backward directions.
231  // The build_both flag specifies whether we should attempt to make
232  // tracks from all both FORWARD and BACKWARD initial tracks,
233  // or alternatively, whether we
234  // should declare victory and quit after getting a successful
235  // track from one initial track.
236  const bool build_both = fDoDedx;
237  const int ninit = 2;
238 
239  auto ntracks = kgtracks.size(); // Remember original track count.
240  bool ok = makeKalmanTracks(detProp, psurf, Surface::FORWARD, trimmedhits, hits, kgtracks);
241  if ((!ok || build_both) && ninit == 2) {
242  makeKalmanTracks(detProp, psurf, Surface::BACKWARD, trimmedhits, hits, kgtracks);
243  }
244 
245  // Loop over newly added tracks and remove hits contained on
246  // these tracks from hits available for making additional
247  // tracks or track seeds.
248  for (unsigned int itrk = ntracks; itrk < kgtracks.size(); ++itrk) {
249  const KGTrack& trg = kgtracks[itrk];
250  filterHitsOnKalmanTrack(trg, hits, unusedhits);
251  }
252 }
void filterHitsOnKalmanTrack(const KGTrack &trg, Hits &hits, Hits &seederhits) const
Filter hits that are on kalman tracks.
bool fDoDedx
Global dE/dx enable flag.
void chopHitsOffSeeds(Hits const &hpsit, bool pfseed, Hits &seedhits) const
Chop hits off of the end of seeds.
bool makeKalmanTracks(detinfo::DetectorPropertiesData const &detProp, const std::shared_ptr< trkf::Surface > psurf, const Surface::TrackDirection trkdir, Hits &seedhits, Hits &hits, std::deque< KGTrack > &kalman_tracks)
void hits()
Definition: readHits.C:15
art::PtrVector< recob::Hit > Hits
TDirectory * dir
Definition: macro.C:5
bool testSeedSlope(const double *dir) const
std::shared_ptr< Surface > makeSurface(const recob::Seed &seed, double *dir) const
method to return a seed to surface.
void trkf::Track3DKalmanHitAlg::growSeedsIntoTracks ( detinfo::DetectorPropertiesData const &  detProp,
const bool  pfseed,
const std::vector< recob::Seed > &  seeds,
const std::vector< Hits > &  hitsperseed,
Hits unusedhits,
Hits hits,
std::deque< KGTrack > &  kalman_tracks 
)

Grow Seeds method.

Definition at line 179 of file Track3DKalmanHitAlg.cxx.

References growSeedIntoTracks().

Referenced by makeTracks().

186 {
187  // check for size of both containers
188  if (seeds.size() != hitsperseed.size()) {
189  throw cet::exception("Track3DKalmanHitAlg")
190  << "Different size containers for Seeds and Hits/Seed.\n";
191  }
192  for (size_t i = 0; i < seeds.size(); ++i) {
193  growSeedIntoTracks(detProp, pfseed, seeds[i], hitsperseed[i], unusedhits, hits, kgtracks);
194  }
195 }
void growSeedIntoTracks(detinfo::DetectorPropertiesData const &detProp, const bool pfseed, const recob::Seed &seed, const Hits &hpsit, Hits &unusedhits, Hits &hits, std::deque< KGTrack > &kgtracks)
void hits()
Definition: readHits.C:15
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool trkf::Track3DKalmanHitAlg::makeKalmanTracks ( detinfo::DetectorPropertiesData const &  detProp,
const std::shared_ptr< trkf::Surface psurf,
const Surface::TrackDirection  trkdir,
Hits seedhits,
Hits hits,
std::deque< KGTrack > &  kalman_tracks 
)

Definition at line 276 of file Track3DKalmanHitAlg.cxx.

References trkf::KalmanFilterAlg::buildTrack(), fDoDedx, fillHitContainer(), fInitialMomentum, fKFAlg, fMaxTcut, trkf::Propagator::FORWARD, fSelfSeed, mf::isDebugEnabled(), trkf::KalmanFilterAlg::setPlane(), and smoothandextendTrack().

Referenced by growSeedIntoTracks().

282 {
283  const int pdg = 13; //SS: FIXME another constant?
284  // SS: FIXME
285  // It is a contant value inside a loop so I took it out
286  // revisit the linear algebra stuff used here (use of ublas)
287  // make a lambda here ... const TrackVector
288  //
289  TrackVector vec(5);
290  vec(0) = 0.;
291  vec(1) = 0.;
292  vec(2) = 0.;
293  vec(3) = 0.;
294  vec(4) = (fInitialMomentum != 0. ? 1. / fInitialMomentum : 2.);
295 
296  KTrack initial_track(psurf, vec, trkdir, pdg);
297 
298  // Fill hit container with current seed hits.
299  // KHitContainer may not be cheaply movabale thats why unique_ptr
300  std::unique_ptr<KHitContainer> pseedcont = fillHitContainer(detProp, seedhits);
301 
302  // Set the preferred plane to be the one with the most hits.
303  unsigned int prefplane = pseedcont->getPreferredPlane();
304  fKFAlg.setPlane(prefplane);
305  if (mf::isDebugEnabled())
306  mf::LogDebug("Track3DKalmanHit") << "Preferred plane = " << prefplane << "\n";
307 
308  PropAny const propagator{detProp, fMaxTcut, fDoDedx};
309 
310  // Build and smooth seed track.
311  KGTrack trg0(prefplane);
312  bool ok =
313  fKFAlg.buildTrack(initial_track, trg0, propagator, Propagator::FORWARD, *pseedcont, fSelfSeed);
314  if (ok) ok = smoothandextendTrack(detProp, propagator, trg0, hits, prefplane, kgtracks);
315 
316  if (mf::isDebugEnabled())
317  mf::LogDebug("Track3DKalmanHit")
318  << (ok ? "Find track succeeded." : "Find track failed.") << "\n";
319  return ok;
320 }
bool fDoDedx
Global dE/dx enable flag.
double fInitialMomentum
Initial (or constant) momentum.
void hits()
Definition: readHits.C:15
bool buildTrack(const KTrack &trk, KGTrack &trg, const Propagator &prop, const Propagator::PropDirection dir, KHitContainer &hits, bool linear) const
Make a new track.
std::unique_ptr< KHitContainer > fillHitContainer(detinfo::DetectorPropertiesData const &detProp, const Hits &hits) const
Fill hit container with either seedhits or filtered hits i.e. recob::Hit.
bool isDebugEnabled()
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
bool smoothandextendTrack(detinfo::DetectorPropertiesData const &detProp, Propagator const &propagator, KGTrack &trg0, const Hits hits, unsigned int prefplane, std::deque< KGTrack > &kalman_tracks)
SMooth and extend track.
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void setPlane(int plane)
Set preferred view plane.
bool fSelfSeed
Self seed flag.
double fMaxTcut
Maximum delta ray energy in MeV for restricted dE/dx.
recob::Seed trkf::Track3DKalmanHitAlg::makeSeed ( detinfo::DetectorPropertiesData const &  detProp,
const Hits hits 
) const

Make seed method.

Definition at line 509 of file Track3DKalmanHitAlg.cxx.

References detinfo::DetectorPropertiesData::ConvertTicksToX(), dir, geo::WireGeo::GetCenter(), n, recob::Hit::PeakTime(), trkf::syminvert(), geo::WireGeo::ThetaZ(), w, geo::GeometryCore::Wire(), recob::Hit::WireID(), and x.

Referenced by makeTracks().

511 {
513 
514  // Do a linear 3D least squares for of y and z vs. x.
515  // y = y0 + ay*(x-x0)
516  // z = z0 + az*(x-x0)
517  // Here x0 is the global average x coordinate of all hits in all planes.
518  // Parameters y0, z0, ay, and az are determined by a simultaneous least squares
519  // fit in all planes.
520 
521  // First, determine x0 by looping over every hit.
522 
523  double x0 = 0.;
524  int n = 0;
525  for (auto const& phit : hits) {
526  const recob::Hit& hit = *phit;
527  geo::WireID wire_id = hit.WireID();
528  double time = hit.PeakTime();
529  double x = detProp.ConvertTicksToX(time, wire_id);
530  x0 += x;
531  ++n;
532  }
533 
534  // If there are no hits, return invalid seed.
535 
536  if (n == 0) return recob::Seed();
537 
538  // Find the average x.
539 
540  x0 /= n;
541 
542  // Now do the least squares fit proper.
543 
544  KSymMatrix<4>::type sm(4);
545  KVector<4>::type sv(4);
546  sm.clear();
547  sv.clear();
548 
549  // Loop over hits (again).
550 
551  for (auto const& phit : hits) {
552  const recob::Hit& hit = *phit;
553 
554  // Extract the angle, w and x coordinates from hit.
555 
556  geo::WireID wire_id = hit.WireID();
557  const geo::WireGeo& wgeom = geom->Wire(wire_id);
558  auto const xyz = wgeom.GetCenter();
559 
560  // Phi convention is the one documented in SurfYZPlane.h.
561 
562  double phi = TMath::PiOver2() - wgeom.ThetaZ();
563  double sphi = std::sin(phi);
564  double cphi = std::cos(phi);
565  double w = -xyz.Y() * sphi + xyz.Z() * cphi;
566 
567  double time = hit.PeakTime();
568  double x = detProp.ConvertTicksToX(time, wire_id);
569 
570  // Accumulate data for least squares fit.
571 
572  double dx = x - x0;
573 
574  sm(0, 0) += sphi * sphi;
575  sm(1, 0) -= sphi * cphi;
576  sm(1, 1) += cphi * cphi;
577  sm(2, 0) += sphi * sphi * dx;
578  sm(2, 1) -= sphi * cphi * dx;
579  sm(2, 2) += sphi * sphi * dx * dx;
580  sm(3, 0) -= sphi * cphi * dx;
581  sm(3, 1) += cphi * cphi * dx;
582  sm(3, 2) -= sphi * cphi * dx * dx;
583  sm(3, 3) += cphi * cphi * dx * dx;
584 
585  sv(0) -= sphi * w;
586  sv(1) += cphi * w;
587  sv(2) -= sphi * w * dx;
588  sv(3) += cphi * w * dx;
589  }
590 
591  // Solve.
592 
593  bool ok = syminvert(sm);
594  if (!ok) return recob::Seed();
595  KVector<4>::type par(4);
596  par = prod(sm, sv);
597 
598  double y0 = par(0);
599  double z0 = par(1);
600  double dydx = par(2);
601  double dzdx = par(3);
602 
603  // Make seed.
604 
605  double dsdx = std::hypot(1., std::hypot(dydx, dzdx));
606 
607  double pos[3] = {x0, y0, z0};
608  double dir[3] = {1. / dsdx, dydx / dsdx, dzdx / dsdx};
609  double poserr[3] = {0., 0., 0.};
610  double direrr[3] = {0., 0., 0.};
611 
612  recob::Seed result(pos, dir, poserr, direrr);
613 
614  return result;
615 }
Float_t x
Definition: compare.C:6
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:114
Point_t const & GetCenter() const
Returns the world coordinate of the center of the wire [cm].
Definition: WireGeo.h:221
geo::WireID const & WireID() const
Initial tdc tick for hit.
Definition: Hit.h:280
WireGeo const & Wire(WireID const &wireid) const
Returns the specified wire.
double ThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
Definition: WireGeo.h:248
ublas::symmetric_matrix< double, ublas::lower, ublas::row_major, ublas::bounded_array< double, N *(N+1)/2 > > type
void hits()
Definition: readHits.C:15
ublas::vector< double, ublas::bounded_array< double, N > > type
bool syminvert(ublas::symmetric_matrix< T, TRI, L, A > &m)
Detector simulation of raw signals on wires.
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:220
TDirectory * dir
Definition: macro.C:5
Char_t n[5]
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
Float_t w
Definition: plot.C:20
std::shared_ptr< trkf::Surface > trkf::Track3DKalmanHitAlg::makeSurface ( const recob::Seed seed,
double *  dir 
) const

method to return a seed to surface.

Definition at line 257 of file Track3DKalmanHitAlg.cxx.

References recob::Seed::GetDirection(), recob::Seed::GetPoint(), and mf::isDebugEnabled().

Referenced by growSeedIntoTracks().

259 {
260  double xyz[3];
261  double err[3]; // Dummy.
262  seed.GetPoint(xyz, err);
263  seed.GetDirection(dir, err);
264  if (mf::isDebugEnabled()) {
265  mf::LogDebug("Track3DKalmanHit")
266  //<< "Seed found with " << seedhits.size() <<" hits.\n"
267  << "(x,y,z) = " << xyz[0] << ", " << xyz[1] << ", " << xyz[2] << "\n"
268  << "(dx,dy,dz) = " << dir[0] << ", " << dir[1] << ", " << dir[2] << "\n";
269  } // if debug
270 
271  return std::make_shared<SurfXYZPlane>(xyz[0], xyz[1], xyz[2], dir[0], dir[1], dir[2]);
272 }
void GetPoint(double *Pt, double *Err) const
Definition: Seed.cxx:89
bool isDebugEnabled()
TDirectory * dir
Definition: macro.C:5
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void GetDirection(double *Dir, double *Err) const
Definition: Seed.cxx:80
std::vector< trkf::KalmanOutput > trkf::Track3DKalmanHitAlg::makeTracks ( detinfo::DetectorClocksData const &  clockData,
detinfo::DetectorPropertiesData const &  detProp,
KalmanInputs kalman_inputs 
)

Definition at line 102 of file Track3DKalmanHitAlg.cxx.

References art::PtrVector< T >::begin(), util::empty(), art::PtrVector< T >::end(), fetchPFParticleSeeds(), fSeedFinderAlg, fSelfSeed, trkf::SeedFinderAlgorithm::GetSeedsFromUnSortedHits(), growSeedsIntoTracks(), hits(), makeSeed(), tca::seeds, and art::PtrVector< T >::size().

Referenced by trkf::Track3DKalmanHit::produce().

106 {
107  std::vector<KalmanOutput> outputs(inputs.size());
108  // Loop over input vectors.
109  for (size_t i = 0; i < inputs.size(); ++i) {
110  Hits& hits = inputs[i].hits;
111  // The hit collection "hits" (just filled), initially containing all
112  // hits, represents hits available for making tracks. Now we will
113  // fill a second hit collection called "unusedhits", also initially
114  // containing all hits, which will represent hits available for
115  // making track seeds. These collections are not necessarily the
116  // same, since hits that are not suitable for seeds may still be
117  // suitable for tracks.
118  Hits unusedhits = hits;
119  // Start of loop.
120  bool first = true;
121  while (true) {
122  std::vector<Hits> hitsperseed;
123  std::vector<recob::Seed> seeds;
124  // On the first trip through this loop, try to use pfparticle-associated seeds.
125  // Do this, provided the list of pfparticle-associated seeds and associated
126  // hits are not empty.
127  bool pfseed = false;
128  auto const seedsize = inputs[i].seeds.size();
129  if (first && seedsize > 0 && inputs[i].seedhits.size() > 0) {
130  seeds.reserve(seedsize);
131  fetchPFParticleSeeds(inputs[i].seeds, inputs[i].seedhits, seeds, hitsperseed);
132  pfseed = true;
133  }
134  else {
135  // On subsequent trips, or if there were no usable pfparticle-associated seeds,
136  // attempt to generate our own seeds.
137  if (unusedhits.size() > 0) {
138  if (fSelfSeed) {
139  // Self seed - convert all hits into one big seed.
140  seeds.emplace_back(makeSeed(detProp, unusedhits));
141  hitsperseed.emplace_back();
142  hitsperseed.back().insert(
143  hitsperseed.back().end(), unusedhits.begin(), unusedhits.end());
144  }
145  else
146  seeds =
147  fSeedFinderAlg.GetSeedsFromUnSortedHits(clockData, detProp, unusedhits, hitsperseed);
148  }
149  }
150 
151  assert(seeds.size() == hitsperseed.size());
152  first = false;
153 
154  if (empty(seeds)) break;
155 
156  growSeedsIntoTracks(detProp, pfseed, seeds, hitsperseed, unusedhits, hits, outputs[i].tracks);
157  }
158  }
159  return outputs;
160 }
recob::Seed makeSeed(detinfo::DetectorPropertiesData const &detProp, const Hits &hits) const
Make seed method.
void hits()
Definition: readHits.C:15
void growSeedsIntoTracks(detinfo::DetectorPropertiesData const &detProp, const bool pfseed, const std::vector< recob::Seed > &seeds, const std::vector< Hits > &hitsperseed, Hits &unusedhits, Hits &hits, std::deque< KGTrack > &kalman_tracks)
Grow Seeds method.
void fetchPFParticleSeeds(const art::PtrVector< recob::Seed > &pfseeds, const std::vector< Hits > &pfseedhits, std::vector< recob::Seed > &seeds, std::vector< Hits > &hitsperseed) const
Fetch Seeds method.
std::vector< recob::Seed > GetSeedsFromUnSortedHits(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, art::PtrVector< recob::Hit > const &, std::vector< art::PtrVector< recob::Hit >> &, unsigned int StopAfter=0) const
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:14
art::PtrVector< recob::Hit > Hits
SeedFinderAlgorithm fSeedFinderAlg
Seed finder.
bool fSelfSeed
Self seed flag.
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
bool trkf::Track3DKalmanHitAlg::qualityCutsOnSeedTrack ( const KGTrack trg0) const

Quality cuts on seed track.

Definition at line 359 of file Track3DKalmanHitAlg.cxx.

References util::abs(), trkf::KGTrack::endTrack(), fMinSeedSlope, trkf::KTrack::getMomentum(), and trkf::KGTrack::startTrack().

Referenced by smoothandextendTrack().

360 {
361  double mom0[3];
362  double mom1[3];
363  trg0.startTrack().getMomentum(mom0);
364  trg0.endTrack().getMomentum(mom1);
365 
366  double dxds0 = mom0[0] / calcMagnitude(mom0);
367  double dxds1 = mom1[0] / calcMagnitude(mom1);
368 
369  return (std::abs(dxds0) > fMinSeedSlope && std::abs(dxds1) > fMinSeedSlope);
370 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
double fMinSeedSlope
Minimum seed slope (dx/dz).
bool trkf::Track3DKalmanHitAlg::smoothandextendTrack ( detinfo::DetectorPropertiesData const &  detProp,
Propagator const &  propagator,
KGTrack trg0,
const Hits  hits,
unsigned int  prefplane,
std::deque< KGTrack > &  kalman_tracks 
)

SMooth and extend track.

Definition at line 399 of file Track3DKalmanHitAlg.cxx.

References trkf::KGTrack::endTrack(), extendandsmoothLoop(), fDoDedx, fitnupdateMomentum(), fKFAlg, fMaxSeedChiDF, fMinSeedHits, fNumTrack, trkf::KFitTrack::getChisq(), hits(), n, trkf::KGTrack::numHits(), qualityCutsOnSeedTrack(), trkf::KalmanFilterAlg::smoothTrack(), and trkf::KGTrack::startTrack().

Referenced by makeKalmanTracks().

405 {
406  KGTrack trg1(prefplane);
407  bool ok = fKFAlg.smoothTrack(trg0, &trg1, propagator);
408  if (!ok) return ok;
409 
410  // Now we have the seed track in the form of a KGTrack.
411  // Do additional quality cuts.
412 
413  auto const n = trg1.numHits();
414  auto const chisq = n * fMaxSeedChiDF;
415 
416  ok = n >= fMinSeedHits && trg1.startTrack().getChisq() <= chisq &&
417  trg1.endTrack().getChisq() <= chisq && trg0.startTrack().getChisq() <= chisq &&
418  trg0.endTrack().getChisq() <= chisq && qualityCutsOnSeedTrack(trg0);
419 
420  if (!ok) return ok;
421 
422  // Make a copy of the original hit collection of all
423  // available track hits.
424  Hits trackhits = hits;
425 
426  // Do an extend + smooth loop here.
427  // Exit after two consecutive failures to extend (i.e. from each end),
428  // or if the iteration count reaches the maximum.
429  if (ok) ok = extendandsmoothLoop(detProp, propagator, trg1, prefplane, trackhits);
430 
431  // Do a final smooth.
432  if (!ok) return false;
433 
434  ok = fKFAlg.smoothTrack(trg1, 0, propagator);
435  if (!ok) return false;
436 
437  // Skip momentum estimate for constant-momentum tracks.
438 
439  if (fDoDedx) { fitnupdateMomentum(propagator, trg1, trg1); }
440  // Save this track.
441  ++fNumTrack;
442  kalman_tracks.push_back(trg1);
443  return true;
444 }
size_t fMinSeedHits
Minimum number of hits per track seed.
bool fDoDedx
Global dE/dx enable flag.
double fMaxSeedChiDF
Maximum seed track chisquare/dof.
void hits()
Definition: readHits.C:15
bool smoothTrack(KGTrack &trg, KGTrack *trg1, const Propagator &prop) const
Smooth track.
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
art::PtrVector< recob::Hit > Hits
void fitnupdateMomentum(Propagator const &propagator, KGTrack &trg1, KGTrack &trg2) const
fit and update method, used twice.
int fNumTrack
Number of tracks produced.
Char_t n[5]
bool qualityCutsOnSeedTrack(const KGTrack &trg0) const
Quality cuts on seed track.
bool extendandsmoothLoop(detinfo::DetectorPropertiesData const &detProp, Propagator const &propagator, KGTrack &trg1, unsigned int prefplane, Hits &trackhits) const
SMooth and extend a track in a loop.
bool trkf::Track3DKalmanHitAlg::testSeedSlope ( const double *  dir) const

Definition at line 324 of file Track3DKalmanHitAlg.cxx.

References util::abs(), and fMinSeedSlope.

Referenced by growSeedIntoTracks().

325 {
326  return std::abs(dir[0]) >= fMinSeedSlope * calcMagnitude(dir);
327 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
TDirectory * dir
Definition: macro.C:5
double fMinSeedSlope
Minimum seed slope (dx/dz).

Member Data Documentation

bool trkf::Track3DKalmanHitAlg::fDoDedx
private

Global dE/dx enable flag.

Definition at line 116 of file Track3DKalmanHitAlg.h.

Referenced by extendandsmoothLoop(), growSeedIntoTracks(), makeKalmanTracks(), and smoothandextendTrack().

double trkf::Track3DKalmanHitAlg::fInitialMomentum
private

Initial (or constant) momentum.

Definition at line 125 of file Track3DKalmanHitAlg.h.

Referenced by makeKalmanTracks(), and Track3DKalmanHitAlg().

KalmanFilterAlg trkf::Track3DKalmanHitAlg::fKFAlg
private

Kalman filter algorithm.

Definition at line 129 of file Track3DKalmanHitAlg.h.

Referenced by extendandsmoothLoop(), fitnupdateMomentum(), makeKalmanTracks(), smoothandextendTrack(), and Track3DKalmanHitAlg().

bool trkf::Track3DKalmanHitAlg::fLineSurface
private

Line surface flag.

Definition at line 119 of file Track3DKalmanHitAlg.h.

Referenced by fillHitContainer(), and Track3DKalmanHitAlg().

int trkf::Track3DKalmanHitAlg::fMaxChopHits
private

Maximum number of hits to chop from each end of seed.

Definition at line 122 of file Track3DKalmanHitAlg.h.

Referenced by chopHitsOffSeeds(), and Track3DKalmanHitAlg().

double trkf::Track3DKalmanHitAlg::fMaxSeedChiDF
private

Maximum seed track chisquare/dof.

Definition at line 123 of file Track3DKalmanHitAlg.h.

Referenced by smoothandextendTrack(), and Track3DKalmanHitAlg().

double trkf::Track3DKalmanHitAlg::fMaxTcut
private

Maximum delta ray energy in MeV for restricted dE/dx.

Definition at line 118 of file Track3DKalmanHitAlg.h.

Referenced by makeKalmanTracks(), and Track3DKalmanHitAlg().

int trkf::Track3DKalmanHitAlg::fMinSeedChopHits
private

Potentially chop seeds that exceed this length.

Definition at line 121 of file Track3DKalmanHitAlg.h.

Referenced by chopHitsOffSeeds(), and Track3DKalmanHitAlg().

size_t trkf::Track3DKalmanHitAlg::fMinSeedHits
private

Minimum number of hits per track seed.

Definition at line 120 of file Track3DKalmanHitAlg.h.

Referenced by smoothandextendTrack(), and Track3DKalmanHitAlg().

double trkf::Track3DKalmanHitAlg::fMinSeedSlope
private

Minimum seed slope (dx/dz).

Definition at line 124 of file Track3DKalmanHitAlg.h.

Referenced by qualityCutsOnSeedTrack(), testSeedSlope(), and Track3DKalmanHitAlg().

int trkf::Track3DKalmanHitAlg::fNumTrack
private

Number of tracks produced.

Definition at line 133 of file Track3DKalmanHitAlg.h.

Referenced by smoothandextendTrack(), and Track3DKalmanHitAlg().

SeedFinderAlgorithm trkf::Track3DKalmanHitAlg::fSeedFinderAlg
private

Seed finder.

Definition at line 130 of file Track3DKalmanHitAlg.h.

Referenced by makeTracks(), and Track3DKalmanHitAlg().

bool trkf::Track3DKalmanHitAlg::fSelfSeed
private

Self seed flag.

Definition at line 117 of file Track3DKalmanHitAlg.h.

Referenced by chopHitsOffSeeds(), makeKalmanTracks(), makeTracks(), and Track3DKalmanHitAlg().


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