LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
trkf::Track3DKalmanHitAlg Class Reference

#include "Track3DKalmanHitAlg.h"

Public Member Functions

 Track3DKalmanHitAlg (const fhicl::ParameterSet &pset)
 Constructor. More...
 
void reconfigure (const fhicl::ParameterSet &pset)
 Reconfigure method. More...
 
std::vector< trkf::KalmanOutputmakeTracks (KalmanInputs &kalman_inputs)
 
bool fetchPFParticleSeeds (const art::PtrVector< recob::Seed > &pfseeds, const std::vector< Hits > &pfseedhits, std::vector< recob::Seed > &seeds, std::vector< Hits > &hitsperseed)
 Fetch Seeds method. More...
 
recob::Seed makeSeed (const Hits &hits) const
 Make seed method. More...
 
void growSeedsIntoTracks (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 (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 (const std::shared_ptr< trkf::Surface > psurf, const Surface::TrackDirection trkdir, Hits &seedhits, Hits &hits, std::deque< KGTrack > &kalman_tracks)
 
bool smoothandextendTrack (KGTrack &trg0, const Hits hits, unsigned int prefplane, std::deque< KGTrack > &kalman_tracks)
 SMooth and extend track. More...
 
bool extendandsmoothLoop (KGTrack &trg1, unsigned int prefplane, Hits &trackhits)
 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 (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 (KGTrack &trg1, KGTrack &trg2)
 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...
 
std::unique_ptr< const PropagatorfProp
 Propagator. More...
 
int fNumTrack
 Number of tracks produced. More...
 

Detailed Description

Definition at line 64 of file Track3DKalmanHitAlg.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 52 of file Track3DKalmanHitAlg.cxx.

References reconfigure().

52  :
53 fDoDedx(false),
54 fSelfSeed(false),
55 fMaxTcut(0.),
56 fLineSurface(false),
57 fMinSeedHits(0),
59 fMaxChopHits(0),
60 fMaxSeedChiDF(0.),
61 fMinSeedSlope(0.),
63 fKFAlg(pset.get<fhicl::ParameterSet>("KalmanFilterAlg")),
64 fSeedFinderAlg(pset.get<fhicl::ParameterSet>("SeedFinderAlg")),
65 fProp(nullptr),
66 fNumTrack(0)
67 {
68  mf::LogInfo("Track3DKalmanHitAlg") << "Track3DKalmanHitAlg instantiated.";
69 
70  // Load fcl parameters.
71 
72  reconfigure(pset);
73 }
size_t fMinSeedHits
Minimum number of hits per track seed.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool fDoDedx
Global dE/dx enable flag.
std::unique_ptr< const Propagator > fProp
Propagator.
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:231
void reconfigure(const fhicl::ParameterSet &pset)
Reconfigure method.
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 364 of file Track3DKalmanHitAlg.cxx.

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

Referenced by growSeedIntoTracks().

366  {
367  const int nchopmax = (pfseed || fSelfSeed) ?
368  0:
369  std::max(0, int((hpsit.size() - fMinSeedChopHits)/2));
370  //SS: FIXME
371 
372  const int nchop = std::min(nchopmax, fMaxChopHits);
373  Hits::const_iterator itb = hpsit.begin();
374  Hits::const_iterator ite = hpsit.end();
375  itb += nchop;
376  ite -= nchop;
377  seedhits.reserve(hpsit.size());
378  for(Hits::const_iterator it = itb; it != ite; ++it)
379  seedhits.push_back(*it);
380 }
int fMinSeedChopHits
Potentially chop seeds that exceed this length.
Int_t max
Definition: plot.C:27
data_t::const_iterator const_iterator
Definition: PtrVector.h:61
Int_t min
Definition: plot.C:26
int fMaxChopHits
Maximum number of hits to chop from each end of seed.
bool fSelfSeed
Self seed flag.
bool trkf::Track3DKalmanHitAlg::extendandsmoothLoop ( KGTrack trg1,
unsigned int  prefplane,
Hits trackhits 
)

SMooth and extend a track in a loop.

Definition at line 437 of file Track3DKalmanHitAlg.cxx.

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

Referenced by smoothandextendTrack().

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

Fetch Seeds method.

Definition at line 156 of file Track3DKalmanHitAlg.cxx.

Referenced by makeTracks().

159  {
160  for(const auto& pseed : pfseeds) {
161  seeds.push_back(*pseed);
162  }
163  hitsperseed.insert(hitsperseed.end(),
164  pfseedhits.begin(),
165  pfseedhits.end());
166  return true;
167 }
std::unique_ptr< trkf::KHitContainer > trkf::Track3DKalmanHitAlg::fillHitContainer ( const Hits hits) const

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

Definition at line 332 of file Track3DKalmanHitAlg.cxx.

References fLineSurface.

Referenced by extendandsmoothLoop(), and makeKalmanTracks().

332  {
333  std::unique_ptr<KHitContainer> hitcont(fLineSurface ?
334  static_cast<KHitContainer *>(new KHitContainerWireLine) :
335  static_cast<KHitContainer *>(new KHitContainerWireX));
336  hitcont->fill(hits, -1);
337  return hitcont;
338 }
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 320 of file Track3DKalmanHitAlg.cxx.

References trkf::KGTrack::fillHits().

Referenced by growSeedIntoTracks().

322  {
323  Hits track_used_hits;
324  std::vector<unsigned int> hittpindex;
325  trg.fillHits(track_used_hits, hittpindex);
326  filterHits(hits, track_used_hits);
327  filterHits(seederhits, track_used_hits);
328 }
void hits()
Definition: readHits.C:15
art::PtrVector< recob::Hit > Hits
void trkf::Track3DKalmanHitAlg::fitnupdateMomentum ( KGTrack trg1,
KGTrack trg2 
)

fit and update method, used twice.

Definition at line 481 of file Track3DKalmanHitAlg.cxx.

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

Referenced by extendandsmoothLoop(), and smoothandextendTrack().

481  {
482  KETrack tremom;
483  if(fKFAlg.fitMomentum(trg1, fProp.get(), tremom)) {
484  fKFAlg.updateMomentum(tremom, fProp.get(), trg2);
485  }
486 }
std::unique_ptr< const Propagator > fProp
Propagator.
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.
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
void trkf::Track3DKalmanHitAlg::growSeedIntoTracks ( const bool  pfseed,
const recob::Seed seed,
const Hits hpsit,
Hits unusedhits,
Hits hits,
std::deque< KGTrack > &  kgtracks 
)

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

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

References growSeedIntoTracks().

Referenced by makeTracks().

177  {
178  //check for size of both containers
179  if (seeds.size() != hitsperseed.size()){
180  throw cet::exception("Track3DKalmanHitAlg")
181  << "Different size containers for Seeds and Hits/Seed.\n";
182  }
183  for(size_t i = 0; i < seeds.size(); ++i){
184  growSeedIntoTracks(pfseed, seeds[i], hitsperseed[i], unusedhits, hits, kgtracks);
185  }
186 }
void hits()
Definition: readHits.C:15
void growSeedIntoTracks(const bool pfseed, const recob::Seed &seed, const Hits &hpsit, Hits &unusedhits, Hits &hits, std::deque< KGTrack > &kgtracks)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool trkf::Track3DKalmanHitAlg::makeKalmanTracks ( const std::shared_ptr< trkf::Surface psurf,
const Surface::TrackDirection  trkdir,
Hits seedhits,
Hits hits,
std::deque< KGTrack > &  kalman_tracks 
)

Definition at line 270 of file Track3DKalmanHitAlg.cxx.

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

Referenced by growSeedIntoTracks().

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

Make seed method.

Definition at line 490 of file Track3DKalmanHitAlg.cxx.

References detinfo::DetectorProperties::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().

491 {
492 
493  // Get Services.
494 
496  const detinfo::DetectorProperties* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
497 
498  // Do a linear 3D least squares for of y and z vs. x.
499  // y = y0 + ay*(x-x0)
500  // z = z0 + az*(x-x0)
501  // Here x0 is the global average x coordinate of all hits in all planes.
502  // Parameters y0, z0, ay, and az are determined by a simultaneous least squares
503  // fit in all planes.
504 
505  // First, determine x0 by looping over every hit.
506 
507  double x0 = 0.;
508  int n = 0;
509  for(auto const& phit : hits) {
510  const recob::Hit& hit = *phit;
511  geo::WireID wire_id = hit.WireID();
512  double time = hit.PeakTime();
513  double x = detprop->ConvertTicksToX(time, wire_id);
514  x0 += x;
515  ++n;
516  }
517 
518  // If there are no hits, return invalid seed.
519 
520  if(n == 0)
521  return recob::Seed();
522 
523  // Find the average x.
524 
525  x0 /= n;
526 
527  // Now do the least squares fit proper.
528 
529  KSymMatrix<4>::type sm(4);
530  KVector<4>::type sv(4);
531  sm.clear();
532  sv.clear();
533 
534  // Loop over hits (again).
535 
536  for(auto const& phit : hits) {
537  const recob::Hit& hit = *phit;
538 
539  // Extract the angle, w and x coordinates from hit.
540 
541  geo::WireID wire_id = hit.WireID();
542  const geo::WireGeo& wgeom = geom->Wire(wire_id);
543  double xyz[3];
544  wgeom.GetCenter(xyz);
545 
546  // Phi convention is the one documented in SurfYZPlane.h.
547 
548  double phi = TMath::PiOver2() - wgeom.ThetaZ();
549  double sphi = std::sin(phi);
550  double cphi = std::cos(phi);
551  double w = -xyz[1]*sphi + xyz[2]*cphi;
552 
553  double time = hit.PeakTime();
554  double x = detprop->ConvertTicksToX(time, wire_id);
555 
556  // Accumulate data for least squares fit.
557 
558  double dx = x-x0;
559 
560  sm(0, 0) += sphi*sphi;
561  sm(1, 0) -= sphi*cphi;
562  sm(1, 1) += cphi*cphi;
563  sm(2, 0) += sphi*sphi * dx;
564  sm(2, 1) -= sphi*cphi * dx;
565  sm(2, 2) += sphi*sphi * dx*dx;
566  sm(3, 0) -= sphi*cphi * dx;
567  sm(3, 1) += cphi*cphi * dx;
568  sm(3, 2) -= sphi*cphi * dx*dx;
569  sm(3, 3) += cphi*cphi * dx*dx;
570 
571  sv(0) -= sphi * w;
572  sv(1) += cphi * w;
573  sv(2) -= sphi * w*dx;
574  sv(3) += cphi * w*dx;
575  }
576 
577  // Solve.
578 
579  bool ok = syminvert(sm);
580  if(!ok)
581  return recob::Seed();
582  KVector<4>::type par(4);
583  par = prod(sm, sv);
584 
585  double y0 = par(0);
586  double z0 = par(1);
587  double dydx = par(2);
588  double dzdx = par(3);
589 
590  // Make seed.
591 
592  double dsdx = std::hypot(1., std::hypot(dydx, dzdx));
593 
594  double pos[3] = {x0, y0, z0};
595  double dir[3] = {1./dsdx, dydx/dsdx, dzdx/dsdx};
596  double poserr[3] = {0., 0., 0.};
597  double direrr[3] = {0., 0., 0.};
598 
599  recob::Seed result(pos, dir, poserr, direrr);
600 
601  return result;
602 
603 }
Float_t x
Definition: compare.C:6
ublas::symmetric_matrix< double, ublas::lower, ublas::row_major, ublas::bounded_array< double, N *(N+1)/2 > > type
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
Definition: WireGeo.h:61
geo::WireID WireID() const
Initial tdc tick for hit.
Definition: Hit.h:234
double ThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
Definition: WireGeo.h:192
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.
virtual double ConvertTicksToX(double ticks, int p, int t, int c) const =0
WireGeo const & Wire(geo::WireID const &wireid) const
Returns the specified wire.
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:219
TDirectory * dir
Definition: macro.C:5
Char_t n[5]
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:68
Float_t w
Definition: plot.C:23
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 249 of file Track3DKalmanHitAlg.cxx.

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

Referenced by growSeedIntoTracks().

250  {
251  double xyz[3];
252  double err[3]; // Dummy.
253  seed.GetPoint(xyz, err);
254  seed.GetDirection(dir, err);
255  if (mf::isDebugEnabled()) {
256  mf::LogDebug("Track3DKalmanHit")
257  //<< "Seed found with " << seedhits.size() <<" hits.\n"
258  << "(x,y,z) = " << xyz[0] << ", " << xyz[1] << ", " << xyz[2] << "\n"
259  << "(dx,dy,dz) = " << dir[0] << ", " << dir[1] << ", " << dir[2] << "\n";
260  } // if debug
261 
262  return std::shared_ptr<Surface>(new SurfXYZPlane(xyz[0], xyz[1], xyz[2],
263  dir[0], dir[1], dir[2]));
264 }
void GetPoint(double *Pt, double *Err) const
Definition: Seed.cxx:112
bool isDebugEnabled()
TDirectory * dir
Definition: macro.C:5
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void GetDirection(double *Dir, double *Err) const
Definition: Seed.cxx:102
std::vector< trkf::KalmanOutput > trkf::Track3DKalmanHitAlg::makeTracks ( KalmanInputs kalman_inputs)

Definition at line 97 of file Track3DKalmanHitAlg.cxx.

References art::PtrVector< T >::begin(), 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().

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

Quality cuts on seed track.

Definition at line 344 of file Track3DKalmanHitAlg.cxx.

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

Referenced by smoothandextendTrack().

344  {
345  double mom0[3];
346  double mom1[3];
347  trg0.startTrack().getMomentum(mom0);
348  trg0.endTrack().getMomentum(mom1);
349 
350  double dxds0 = mom0[0] / calcMagnitude(mom0);
351  double dxds1 = mom1[0] / calcMagnitude(mom1);
352 
353  return (std::abs(dxds0) > fMinSeedSlope &&
354  std::abs(dxds1) > fMinSeedSlope);
355 }
double fMinSeedSlope
Minimum seed slope (dx/dz).
void trkf::Track3DKalmanHitAlg::reconfigure ( const fhicl::ParameterSet pset)

Reconfigure method.

Definition at line 78 of file Track3DKalmanHitAlg.cxx.

References fDoDedx, fInitialMomentum, fKFAlg, fLineSurface, fMaxChopHits, fMaxSeedChiDF, fMaxTcut, fMinSeedChopHits, fMinSeedHits, fMinSeedSlope, fProp, fSeedFinderAlg, fSelfSeed, fhicl::ParameterSet::get(), trkf::SeedFinderAlgorithm::reconfigure(), and trkf::KalmanFilterAlg::reconfigure().

Referenced by trkf::Track3DKalmanHit::reconfigure(), and Track3DKalmanHitAlg().

79 {
80  fDoDedx = pset.get<bool>("DoDedx");
81  fSelfSeed = pset.get<bool>("SelfSeed");
82  fMaxTcut = pset.get<double>("MaxTcut");
83  fLineSurface = pset.get<bool>("LineSurface");
84  fMinSeedHits = pset.get<size_t>("MinSeedHits");
85  fMinSeedChopHits = pset.get<int>("MinSeedChopHits");
86  fMaxChopHits = pset.get<int>("MaxChopHits");
87  fMaxSeedChiDF = pset.get<double>("MaxSeedChiDF");
88  fMinSeedSlope = pset.get<double>("MinSeedSlope");
89  fInitialMomentum = pset.get<double>("InitialMomentum");
90  fKFAlg.reconfigure(pset.get<fhicl::ParameterSet>("KalmanFilterAlg"));
91  fSeedFinderAlg.reconfigure(pset.get<fhicl::ParameterSet>("SeedFinderAlg"));
92  fProp.reset(new PropAny(fMaxTcut, fDoDedx));
93 }
size_t fMinSeedHits
Minimum number of hits per track seed.
bool fDoDedx
Global dE/dx enable flag.
std::unique_ptr< const Propagator > fProp
Propagator.
void reconfigure(fhicl::ParameterSet const &pset)
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:231
void reconfigure(const fhicl::ParameterSet &pset)
Reconfigure method.
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
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.
bool trkf::Track3DKalmanHitAlg::smoothandextendTrack ( KGTrack trg0,
const Hits  hits,
unsigned int  prefplane,
std::deque< KGTrack > &  kalman_tracks 
)

SMooth and extend track.

Definition at line 384 of file Track3DKalmanHitAlg.cxx.

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

Referenced by makeKalmanTracks().

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

Definition at line 313 of file Track3DKalmanHitAlg.cxx.

References fMinSeedSlope.

Referenced by growSeedIntoTracks().

313  {
314  return std::abs(dir[0]) >= fMinSeedSlope * calcMagnitude(dir);
315 }
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 124 of file Track3DKalmanHitAlg.h.

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

double trkf::Track3DKalmanHitAlg::fInitialMomentum
private

Initial (or constant) momentum.

Definition at line 133 of file Track3DKalmanHitAlg.h.

Referenced by makeKalmanTracks(), and reconfigure().

KalmanFilterAlg trkf::Track3DKalmanHitAlg::fKFAlg
private

Kalman filter algorithm.

Definition at line 137 of file Track3DKalmanHitAlg.h.

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

bool trkf::Track3DKalmanHitAlg::fLineSurface
private

Line surface flag.

Definition at line 127 of file Track3DKalmanHitAlg.h.

Referenced by fillHitContainer(), and reconfigure().

int trkf::Track3DKalmanHitAlg::fMaxChopHits
private

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

Definition at line 130 of file Track3DKalmanHitAlg.h.

Referenced by chopHitsOffSeeds(), and reconfigure().

double trkf::Track3DKalmanHitAlg::fMaxSeedChiDF
private

Maximum seed track chisquare/dof.

Definition at line 131 of file Track3DKalmanHitAlg.h.

Referenced by reconfigure(), and smoothandextendTrack().

double trkf::Track3DKalmanHitAlg::fMaxTcut
private

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

Definition at line 126 of file Track3DKalmanHitAlg.h.

Referenced by reconfigure().

int trkf::Track3DKalmanHitAlg::fMinSeedChopHits
private

Potentially chop seeds that exceed this length.

Definition at line 129 of file Track3DKalmanHitAlg.h.

Referenced by chopHitsOffSeeds(), and reconfigure().

size_t trkf::Track3DKalmanHitAlg::fMinSeedHits
private

Minimum number of hits per track seed.

Definition at line 128 of file Track3DKalmanHitAlg.h.

Referenced by reconfigure(), and smoothandextendTrack().

double trkf::Track3DKalmanHitAlg::fMinSeedSlope
private

Minimum seed slope (dx/dz).

Definition at line 132 of file Track3DKalmanHitAlg.h.

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

int trkf::Track3DKalmanHitAlg::fNumTrack
private

Number of tracks produced.

Definition at line 144 of file Track3DKalmanHitAlg.h.

Referenced by smoothandextendTrack().

std::unique_ptr<const Propagator> trkf::Track3DKalmanHitAlg::fProp
private
SeedFinderAlgorithm trkf::Track3DKalmanHitAlg::fSeedFinderAlg
private

Seed finder.

Definition at line 138 of file Track3DKalmanHitAlg.h.

Referenced by makeTracks(), and reconfigure().

bool trkf::Track3DKalmanHitAlg::fSelfSeed
private

Self seed flag.

Definition at line 125 of file Track3DKalmanHitAlg.h.

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


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