16 inline double calcMagnitude(
const double *
x){
17 return std::sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
32 if(used_hits.
size() > 0) {
34 std::stable_sort(hits.
begin(), hits.
end());
35 std::stable_sort(used_hits.
begin(), used_hits.
end());
39 std::set_difference(hits.
begin(), hits.
end(),
63 fKFAlg(pset.get<
fhicl::ParameterSet>(
"KalmanFilterAlg")),
64 fSeedFinderAlg(pset.get<
fhicl::ParameterSet>(
"SeedFinderAlg")),
68 mf::LogInfo(
"Track3DKalmanHitAlg") <<
"Track3DKalmanHitAlg instantiated.";
98 std::vector<KalmanOutput> outputs(inputs.size());
100 for (
size_t i = 0; i<inputs.size(); ++i) {
101 Hits& hits = inputs[i].hits;
113 std::vector<Hits> hitsperseed;
114 std::vector<recob::Seed> seeds;
119 auto const seedsize = inputs[i].seeds.size();
120 if(first && seedsize > 0 && inputs[i].seedhits.size() > 0) {
121 seeds.reserve(seedsize);
130 if(unusedhits.
size()>0) {
133 seeds.emplace_back(
makeSeed(unusedhits));
134 hitsperseed.emplace_back();
135 hitsperseed.back().insert(hitsperseed.back().end(),
143 assert(seeds.size() == hitsperseed.size());
146 if(seeds.size() == 0)
break;
157 const std::vector<Hits> &pfseedhits,
158 std::vector<recob::Seed>& seeds,
159 std::vector<Hits>& hitsperseed){
160 for(
const auto& pseed : pfseeds) {
161 seeds.push_back(*pseed);
163 hitsperseed.insert(hitsperseed.end(),
173 const std::vector<recob::Seed>& seeds,
174 const std::vector<Hits >& hitsperseed,
177 std::deque<KGTrack>& kgtracks){
179 if (seeds.size() != hitsperseed.size()){
181 <<
"Different size containers for Seeds and Hits/Seed.\n";
183 for(
size_t i = 0; i < seeds.size(); ++i){
194 std::deque<KGTrack>& kgtracks){
204 size_t initial_unusedhits = unusedhits.
size();
205 filterHits(unusedhits, trimmedhits);
209 if(!(trimmedhits.
size() + unusedhits.
size() == initial_unusedhits))
return;
214 std::shared_ptr<Surface> psurf =
makeSurface(seed, dir);
226 const bool build_both =
fDoDedx;
229 auto ntracks = kgtracks.size();
231 if ((!ok || build_both) && ninit == 2) {
238 for(
unsigned int itrk = ntracks; itrk < kgtracks.size(); ++itrk) {
239 const KGTrack& trg = kgtracks[itrk];
258 <<
"(x,y,z) = " << xyz[0] <<
", " << xyz[1] <<
", " << xyz[2] <<
"\n" 259 <<
"(dx,dy,dz) = " << dir[0] <<
", " << dir[1] <<
", " << dir[2] <<
"\n";
262 return std::shared_ptr<Surface>(
new SurfXYZPlane(xyz[0], xyz[1], xyz[2],
263 dir[0], dir[1], dir[2]));
274 std::deque<KGTrack>& kgtracks) {
295 unsigned int prefplane = pseedcont->getPreferredPlane();
298 mf::LogDebug(
"Track3DKalmanHit") <<
"Preferred plane = " << prefplane <<
"\n";
307 << (ok?
"Find track succeeded.":
"Find track failed.") <<
"\n";
314 return std::abs(dir[0]) >=
fMinSeedSlope * calcMagnitude(dir);
322 Hits& seederhits)
const{
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);
336 hitcont->fill(hits, -1);
350 double dxds0 = mom0[0] / calcMagnitude(mom0);
351 double dxds1 = mom1[0] / calcMagnitude(mom1);
366 Hits &seedhits)
const{
367 const int nchopmax = (pfseed ||
fSelfSeed) ?
386 unsigned int prefplane,
387 std::deque<KGTrack>& kalman_tracks){
430 kalman_tracks.push_back(trg1);
438 unsigned int prefplane,
443 for(
int ix = 0; ok && ix < niter && nfail < 2; ++ix) {
448 std::vector<unsigned int> hittpindex;
449 trg1.
fillHits(goodhits, hittpindex);
452 filterHits(trackhits, goodhits);
509 for(
auto const& phit : hits) {
536 for(
auto const& phit : hits) {
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;
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;
573 sv(2) -= sphi * w*dx;
574 sv(3) += cphi * w*dx;
587 double dydx = par(2);
588 double dzdx = par(3);
592 double dsdx = std::hypot(1., std::hypot(dydx, dzdx));
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.};
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...
void reserve(size_type n)
TrackDirection
Track direction enum.
void fillHits(art::PtrVector< recob::Hit > &hits, std::vector< unsigned int > &hittpindex) const
Fill a PtrVector of Hits.
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.
const KHitTrack & endTrack() const
Track at end point.
size_t fMinSeedHits
Minimum number of hits per track seed.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
geo::WireID WireID() const
Initial tdc tick for hit.
void filterHitsOnKalmanTrack(const KGTrack &trg, Hits &hits, Hits &seederhits) const
Filter hits that are on kalman tracks.
bool smoothTrack(KGTrack &trg, KGTrack *trg1, const Propagator *prop) const
Smooth track.
void GetPoint(double *Pt, double *Err) const
std::vector< trkf::KalmanOutput > makeTracks(KalmanInputs &kalman_inputs)
iterator erase(iterator position)
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.
void reconfigure(fhicl::ParameterSet const &pset)
bool fitMomentum(const KGTrack &trg, const Propagator *prop, KETrack &tremom) const
Estimate track momentum using either range or multiple scattering.
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.
double fMaxSeedChiDF
Maximum seed track chisquare/dof.
Track3DKalmanHitAlg(const fhicl::ParameterSet &pset)
Constructor.
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.
void chopHitsOffSeeds(Hits const &hpsit, bool pfseed, Hits &seedhits) const
Chop hits off of the end of seeds.
double fInitialMomentum
Initial (or constant) momentum.
bool extendandsmoothLoop(KGTrack &trg1, unsigned int prefplane, Hits &trackhits)
SMooth and extend a track in a loop.
void push_back(Ptr< U > const &p)
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
void reconfigure(const fhicl::ParameterSet &pset)
Reconfigure method.
bool updateMomentum(const KETrack &tremom, const Propagator *prop, KGTrack &trg) const
Set track momentum at each track surface.
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.
void reconfigure(const fhicl::ParameterSet &pset)
Reconfigure method.
data_t::iterator iterator
KalmanFilterAlg fKFAlg
Kalman filter algorithm.
Detector simulation of raw signals on wires.
data_t::const_iterator const_iterator
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.
int fNumTrack
Number of tracks produced.
std::vector< recob::Seed > GetSeedsFromUnSortedHits(art::PtrVector< recob::Hit > const &, std::vector< art::PtrVector< recob::Hit > > &, unsigned int StopAfter=0)
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.
void growSeedIntoTracks(const bool pfseed, const recob::Seed &seed, const Hits &hpsit, Hits &unusedhits, Hits &hits, std::deque< KGTrack > &kgtracks)
recob::Seed makeSeed(const Hits &hits) const
Make seed method.
std::unique_ptr< KHitContainer > fillHitContainer(const Hits &hits) const
Fill hit container with either seedhits or filtered hits i.e. recob::Hit.
SeedFinderAlgorithm fSeedFinderAlg
Seed finder.
bool buildTrack(const KTrack &trk, KGTrack &trg, const Propagator *prop, const Propagator::PropDirection dir, KHitContainer &hits, bool linear) const
Make a new track.
2D representation of charge deposited in the TDC/wire plane
bool qualityCutsOnSeedTrack(const KGTrack &trg0) const
Quality cuts on seed track.
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
int fMaxChopHits
Maximum number of hits to chop from each end of seed.
void fitnupdateMomentum(KGTrack &trg1, KGTrack &trg2)
fit and update method, used twice.
std::vector< KalmanInput > KalmanInputs
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.
double fMinSeedSlope
Minimum seed slope (dx/dz).
cet::coded_exception< error, detail::translate > exception
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.
bool makeKalmanTracks(const std::shared_ptr< trkf::Surface > psurf, const Surface::TrackDirection trkdir, Hits &seedhits, Hits &hits, std::deque< KGTrack > &kalman_tracks)