21 #include "cetlib_except/exception.h" 40 #include <type_traits> 49 inline double calcMagnitude(
const double*
x)
51 return std::hypot(x[0], x[1], x[2]);
64 if (used_hits.
size() > 0) {
66 std::stable_sort(hits.
begin(), hits.
end());
67 std::stable_sort(used_hits.
begin(), used_hits.
end());
83 : fDoDedx{pset.
get<
bool>(
"DoDedx")}
85 ,
fMaxTcut{pset.get<
double>(
"MaxTcut")}
97 mf::LogInfo(
"Track3DKalmanHitAlg") <<
"Track3DKalmanHitAlg instantiated.";
107 std::vector<KalmanOutput> outputs(inputs.size());
109 for (
size_t i = 0; i < inputs.size(); ++i) {
110 Hits& hits = inputs[i].hits;
122 std::vector<Hits> hitsperseed;
123 std::vector<recob::Seed>
seeds;
128 auto const seedsize = inputs[i].seeds.size();
129 if (first && seedsize > 0 && inputs[i].seedhits.size() > 0) {
130 seeds.reserve(seedsize);
137 if (unusedhits.
size() > 0) {
140 seeds.emplace_back(
makeSeed(detProp, unusedhits));
141 hitsperseed.emplace_back();
142 hitsperseed.back().insert(
143 hitsperseed.back().end(), unusedhits.
begin(), unusedhits.
end());
151 assert(seeds.size() == hitsperseed.size());
154 if (
empty(seeds))
break;
156 growSeedsIntoTracks(detProp, pfseed, seeds, hitsperseed, unusedhits, hits, outputs[i].tracks);
166 const std::vector<Hits>& pfseedhits,
167 std::vector<recob::Seed>&
seeds,
168 std::vector<Hits>& hitsperseed)
const 170 for (
const auto& pseed : pfseeds) {
171 seeds.push_back(*pseed);
173 hitsperseed.insert(hitsperseed.end(), pfseedhits.begin(), pfseedhits.end());
181 const std::vector<recob::Seed>&
seeds,
182 const std::vector<Hits>& hitsperseed,
185 std::deque<KGTrack>& kgtracks)
188 if (seeds.size() != hitsperseed.size()) {
190 <<
"Different size containers for Seeds and Hits/Seed.\n";
192 for (
size_t i = 0; i < seeds.size(); ++i) {
193 growSeedIntoTracks(detProp, pfseed, seeds[i], hitsperseed[i], unusedhits, hits, kgtracks);
204 std::deque<KGTrack>& kgtracks)
214 size_t initial_unusedhits = unusedhits.
size();
215 filterHits(unusedhits, trimmedhits);
219 if (!(trimmedhits.
size() + unusedhits.
size() == initial_unusedhits))
return;
224 std::shared_ptr<Surface> psurf =
makeSurface(seed, dir);
236 const bool build_both =
fDoDedx;
239 auto ntracks = kgtracks.size();
241 if ((!ok || build_both) && ninit == 2) {
248 for (
unsigned int itrk = ntracks; itrk < kgtracks.size(); ++itrk) {
249 const KGTrack& trg = kgtracks[itrk];
267 <<
"(x,y,z) = " << xyz[0] <<
", " << xyz[1] <<
", " << xyz[2] <<
"\n" 268 <<
"(dx,dy,dz) = " << dir[0] <<
", " << dir[1] <<
", " << dir[2] <<
"\n";
271 return std::make_shared<SurfXYZPlane>(xyz[0], xyz[1], xyz[2], dir[0], dir[1], dir[2]);
277 const std::shared_ptr<trkf::Surface> psurf,
281 std::deque<KGTrack>& kgtracks)
296 KTrack initial_track(psurf, vec, trkdir, pdg);
300 std::unique_ptr<KHitContainer> pseedcont =
fillHitContainer(detProp, seedhits);
303 unsigned int prefplane = pseedcont->getPreferredPlane();
306 mf::LogDebug(
"Track3DKalmanHit") <<
"Preferred plane = " << prefplane <<
"\n";
318 << (ok ?
"Find track succeeded." :
"Find track failed.") <<
"\n";
333 Hits& seederhits)
const 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);
346 const Hits& hits)
const 351 hitcont->fill(detProp, hits, -1);
366 double dxds0 = mom0[0] / calcMagnitude(mom0);
367 double dxds1 = mom1[0] / calcMagnitude(mom1);
381 Hits& seedhits)
const 403 unsigned int prefplane,
404 std::deque<KGTrack>& kalman_tracks)
432 if (!ok)
return false;
435 if (!ok)
return false;
442 kalman_tracks.push_back(trg1);
452 unsigned int prefplane,
453 Hits& trackhits)
const 458 for (
int ix = 0; ok && ix < niter && nfail < 2; ++ix) {
463 std::vector<unsigned int> hittpindex;
464 trg1.
fillHits(goodhits, hittpindex);
467 filterHits(trackhits, goodhits);
470 std::unique_ptr<KHitContainer> ptrackcont =
fillHitContainer(detProp, trackhits);
510 const Hits& hits)
const 525 for (
auto const& phit : hits) {
551 for (
auto const& phit : hits) {
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;
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;
587 sv(2) -= sphi * w * dx;
588 sv(3) += cphi * w * dx;
600 double dydx = par(2);
601 double dzdx = par(3);
605 double dsdx = std::hypot(1., std::hypot(dydx, dzdx));
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.};
Geometry description of a TPC wireThe wire is a single straight segment on a wire plane...
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 reserve(size_type n)
TrackDirection
Track direction enum.
Basic Kalman filter track class, plus one measurement on same surface.
Point_t const & GetCenter() const
Returns the world coordinate of the center of the wire [cm].
typename data_t::iterator iterator
Utilities related to art service access.
void fillHits(art::PtrVector< recob::Hit > &hits, std::vector< unsigned int > &hittpindex) const
Fill a PtrVector of Hits.
A KHitContainer for KHitWireLine type measurements.
A KHitContainer for KHitWireX type measurements.
const KHitTrack & endTrack() const
Track at end point.
size_t fMinSeedHits
Minimum number of hits per track seed.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
void filterHitsOnKalmanTrack(const KGTrack &trg, Hits &hits, Hits &seederhits) const
Filter hits that are on kalman tracks.
void GetPoint(double *Pt, double *Err) const
iterator erase(iterator position)
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::vector< trkf::KalmanOutput > makeTracks(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, KalmanInputs &kalman_inputs)
bool fDoDedx
Global dE/dx enable flag.
geo::WireID const & WireID() const
Initial tdc tick for hit.
double fMaxSeedChiDF
Maximum seed track chisquare/dof.
Track3DKalmanHitAlg(const fhicl::ParameterSet &pset)
Constructor.
WireGeo const & Wire(WireID const &wireid) const
Returns the specified wire.
int fMinSeedChopHits
Potentially chop seeds that exceed this length.
Track3DKalmanHit Algorithm.
double ThetaZ() const
Returns angle of wire with respect to z axis in the Y-Z plane in radians.
ublas::symmetric_matrix< double, ublas::lower, ublas::row_major, ublas::bounded_array< double, N *(N+1)/2 > > type
void chopHitsOffSeeds(Hits const &hpsit, bool pfseed, Hits &seedhits) const
Chop hits off of the end of seeds.
double fInitialMomentum
Initial (or constant) momentum.
recob::Seed makeSeed(detinfo::DetectorPropertiesData const &detProp, const Hits &hits) const
Make seed method.
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)
typename data_t::const_iterator const_iterator
bool buildTrack(const KTrack &trk, KGTrack &trg, const Propagator &prop, const Propagator::PropDirection dir, KHitContainer &hits, bool linear) const
Make a new track.
void push_back(Ptr< U > const &p)
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.
ublas::vector< double, ublas::bounded_array< double, N > > type
bool syminvert(ublas::symmetric_matrix< T, TRI, L, A > &m)
T get(std::string const &key) const
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.
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.
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
Definition of data types for geometry description.
bool smoothTrack(KGTrack &trg, KGTrack *trg1, const Propagator &prop) const
Smooth track.
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
Kalman filter linear algebra typedefs.
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.
Detector simulation of raw signals on wires.
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
Encapsulate the geometry of a wire.
double ConvertTicksToX(double ticks, int p, int t, int c) const
std::vector< TrajPoint > seeds
void fitnupdateMomentum(Propagator const &propagator, KGTrack &trg1, KGTrack &trg2) const
fit and update method, used twice.
float PeakTime() const
Time of the signal peak, in tick units.
Contains all timing reference information for the detector.
int fNumTrack
Number of tracks produced.
bool testSeedSlope(const double *dir) const
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void getMomentum(double mom[3]) const
Get momentum vector of track.
void setPlane(int plane)
Set preferred view plane.
bool fLineSurface
Line surface flag.
size_t numHits() const
Number of measurements in track.
SeedFinderAlgorithm fSeedFinderAlg
Seed finder.
Basic Kalman filter track class, with error.
2D representation of charge deposited in the TDC/wire plane
bool qualityCutsOnSeedTrack(const KGTrack &trg0) const
Quality cuts on seed track.
int fMaxChopHits
Maximum number of hits to chop from each end of seed.
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.
std::vector< KalmanInput > KalmanInputs
Basic Kalman filter track class, without error.
void GetDirection(double *Dir, double *Err) const
double getChisq() const
Fit chisquare.
bool fSelfSeed
Self seed flag.
const KHitTrack & startTrack() const
Track at start point.
art framework interface to geometry description
double fMinSeedSlope
Minimum seed slope (dx/dz).
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
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.
double fMaxTcut
Maximum delta ray energy in MeV for restricted dE/dx.
std::shared_ptr< Surface > makeSurface(const recob::Seed &seed, double *dir) const
method to return a seed to surface.