3 #ifndef FEATURETRACKER_H 4 #define FEATURETRACKER_H 38 class BezierTrackerAlgorithm;
68 void GetProjectedEnds(TVector3 xyz, std::vector<double>& uvw, std::vector<double>& t,
int tpc=0,
int cryo=0);
70 std::map<int, std::vector<double> > ExtractEndPointTimes(std::vector<recob::EndPoint2D> EndPoints);
74 std::vector<recob::Seed> GetValidLines(std::vector<recob::SpacePoint>& sps,
75 bool ApplyFilter =
true);
77 void RemoveDuplicatePaths(std::vector<recob::Seed>& Seeds,
78 std::vector<int>& ConnectionPoint1,
79 std::vector<int>& ConnectionPoint2);
84 std::map<int, std::map<int, double> > GetConnectionMap(std::vector<recob::Seed>& Seeds,
double ADCThresh,
double FracThresh);
86 std::vector<trkf::BezierTrack> GenerateBezierTracks(std::map<
int,std::map<int,double> > , std::vector<recob::Seed>);
129 fSP(pset.get<
fhicl::ParameterSet>(
"SpacepointPset")),
130 fCorner(pset.get<
fhicl::ParameterSet>(
"CornerPset"))
133 produces< std::vector<recob::Seed> >();
162 for(
unsigned int i = 0; i < hith->size(); ++i){
170 std::vector<recob::Wire>
const& wireVec(*wireHandle);
175 std::vector<recob::EndPoint2D> EndPoints;
182 std::vector<recob::Seed> SeedsToStore =
GetValidLines( sps,
true );
184 std::map<int, std::map<int, double> > ConnMap =
GetConnectionMap(SeedsToStore, 3, 0.90);
197 std::unique_ptr< std::vector<recob::Seed > >
seeds (
new std::vector<recob::Seed>);
199 for(
size_t i=0; i!=SeedsToStore.size(); ++i)
200 seeds->push_back(SeedsToStore.at(i));
202 evt.
put(std::move(seeds));
212 std::map<int, std::vector<double> > EndPointTimesInPlane;
213 for(
size_t i=0; i!=EndPoints.size(); ++i)
215 EndPointTimesInPlane[EndPoints.at(i).View()].push_back(EndPoints.at(i).DriftTime());
218 for(std::map<
int, std::vector<double> >::
iterator itEpTime = EndPointTimesInPlane.begin();
219 itEpTime != EndPointTimesInPlane.end(); ++itEpTime)
221 std::sort(itEpTime->second.begin(), itEpTime->second.end());
223 return EndPointTimesInPlane;
232 std::vector<recob::Seed> SeedsToReturn;
234 std::vector<int> ConnectionPoint1;
235 std::vector<int> ConnectionPoint2;
236 std::map<int, std::vector<int> > SeedConnections;
238 for(
size_t i=0; i!=spts.size(); ++i)
240 for(
size_t j=0; j!=i; ++j)
247 std::vector<double> t_i, t_j;
249 std::vector<double> uvw_i;
250 std::vector<double> uvw_j;
252 for(
size_t d=0;
d!=3; ++
d)
254 xyz_i[
d] = spts.at(i).XYZ()[
d];
255 xyz_j[
d] = spts.at(j).XYZ()[
d];
262 bool ThisLineGood=
true;
264 for(
size_t p=0; p!=uvw_i.size(); ++p)
270 uvw_i.at(p), t_i.at(p),
271 uvw_j.at(p), t_j.at(p),
286 for(
size_t d=0;
d!=3; ++
d)
288 Pos[
d] = 0.5*(xyz_i[
d] + xyz_j[
d]);
289 Dir[
d] = 0.5*(xyz_i[
d] - xyz_j[
d]);
293 ConnectionPoint1.push_back(i);
294 ConnectionPoint2.push_back(j);
296 SeedsToReturn.push_back(
recob::Seed(Pos,Dir,Err,Err));
306 mf::LogInfo(
"FeatureTracker") <<
"Seeds after filter " << SeedsToReturn.size()<<
" seeds"<<std::endl;
309 return SeedsToReturn;
315 std::vector<int>& ConnectionPoint1,
316 std::vector<int>& ConnectionPoint2)
319 std::map<int, bool> MarkedForRemoval;
321 std::map<int, std::vector<int> > SeedsSharingPoint;
322 for(
size_t i=0; i!=Seeds.size(); ++i)
324 SeedsSharingPoint[ConnectionPoint1[i] ].push_back(i);
325 SeedsSharingPoint[ConnectionPoint2[i] ].push_back(i);
328 for(
size_t s=0;
s!=Seeds.size(); ++
s)
331 int StartPt = ConnectionPoint1.at(
s);
332 int EndPt = ConnectionPoint2.at(
s);
335 for(
size_t SeedsWithThisStart =0; SeedsWithThisStart!=SeedsSharingPoint[StartPt].size(); SeedsWithThisStart++)
337 int i = SeedsSharingPoint[StartPt].at(SeedsWithThisStart);
338 if(ConnectionPoint1.at(i)==StartPt)
339 MidPt = ConnectionPoint2.at(i);
340 else if(ConnectionPoint2.at(i)==StartPt)
341 MidPt = ConnectionPoint1.at(i);
343 for(
size_t SeedsWithThisMid =0; SeedsWithThisMid!=SeedsSharingPoint[MidPt].size(); SeedsWithThisMid++)
345 int j = SeedsSharingPoint[MidPt].at(SeedsWithThisMid);
346 if((ConnectionPoint1.at(j)==EndPt)||(ConnectionPoint2.at(j)==EndPt))
349 double Lengthi = Seeds.at(i).GetLength();
350 double Lengthj = Seeds.at(j).GetLength();
351 double Lengths = Seeds.at(
s).GetLength();
353 if((Lengths>Lengthi)&&(Lengths>Lengthj))
355 MarkedForRemoval[i]=
true;
356 MarkedForRemoval[j]=
true;
359 if((Lengthi>Lengths)&&(Lengthi>Lengthj))
361 MarkedForRemoval[
s]=
true;
362 MarkedForRemoval[j]=
true;
364 if((Lengthj>Lengthi)&&(Lengthj>Lengths))
366 MarkedForRemoval[
s]=
true;
367 MarkedForRemoval[i]=
true;
373 for(std::map<int,bool>::reverse_iterator itrem = MarkedForRemoval.rbegin();
374 itrem != MarkedForRemoval.rend(); ++itrem)
376 if(itrem->second==
true)
378 Seeds.erase( Seeds.begin() + itrem->first);
379 ConnectionPoint1.erase( ConnectionPoint1.begin() + itrem->first);
380 ConnectionPoint2.erase( ConnectionPoint2.begin() + itrem->first);
398 int NPlanes=geo->Cryostat(cryo).TPC(tpc).Nplanes();
403 for(
int plane = 0; plane != NPlanes; plane++)
405 uvw[plane] = geo->NearestWire(xyz, plane, tpc, cryo);
428 (itEP->View() == (*itHit)->View()) &&
429 (itEP->WireID().Wire == (*itHit)->WireID().Wire))
438 std::vector<recob::SpacePoint> spts;
444 for(
size_t i=0; i!=spts.size(); ++i)
446 for(
size_t p=0; p!=3; ++p)
448 double Closest =100000;
471 double ExtendFrac=1.1;
474 bool SuccessfulExtend =
true;
475 while(SuccessfulExtend)
478 double Dir[3], Err[3];
482 for(
size_t i=0; i!=3; ++i)
484 Dir[i] *= ExtendFrac;
485 Pt[i] += Dir[i] * ( ExtendFrac - 1. ) * 0.5;
490 if(SuccessfulExtend) TheSeed = NewSeed;
494 SuccessfulExtend =
true;
495 while(SuccessfulExtend)
498 double Dir[3], Err[3];
502 for(
size_t i=0; i!=3; ++i)
504 Dir[i] *= ExtendFrac;
505 Pt[i] -= Dir[i] * ( ExtendFrac - 1. ) * 0.5;
510 if(SuccessfulExtend) TheSeed = NewSeed;
520 double Pt[3],Dir[3],Err[3];
526 for(
size_t i=0; i!=3; ++i)
528 endi[i] = Pt[i]+Dir[i];
529 endj[i] = Pt[i]-Dir[i];
532 std::vector<double> t_i, t_j;
534 std::vector<double> uvw_i;
535 std::vector<double> uvw_j;
540 for(
size_t p=0; p!=uvw_i.size(); ++p)
546 uvw_i.at(p), t_i.at(p),
547 uvw_j.at(p), t_j.at(p),
564 std::vector<TVector3> WireDirs;
566 double EndThresh = 0.5;
568 std::map<int,bool> RedundantSeeds;
570 std::map<int, std::map<int, double> > ConnectionMap;
572 for(
size_t i=0; i!=Seeds.size(); ++i)
574 for(
size_t j=0; j!=i; ++j)
576 std::vector<recob::Seed > SeedsVec;
577 SeedsVec.push_back(Seeds.at(i));
578 SeedsVec.push_back(Seeds.at(j));
584 bool HasConnection=
true;
586 for(
size_t view =0; view!=LineScore.size(); ++view)
588 if(LineScore.at(view)<FracThresh)
593 double Seed1Pt[3], Seed2Pt[3], Seed1Dir[3], Seed2Dir[3], Err[3];
595 Seeds.at(i).GetPoint(Seed1Pt,Err);
596 Seeds.at(j).GetPoint(Seed2Pt,Err);
597 Seeds.at(i).GetDirection(Seed1Dir,Err);
598 Seeds.at(j).GetDirection(Seed2Dir,Err);
600 TVector3 Seed1End1, Seed1End2, Seed2End1, Seed2End2;
602 for(
size_t index=0; index!=3; ++index)
604 Seed1End1[index]=Seed1Pt[index]+Seed1Dir[index];
605 Seed1End2[index]=Seed1Pt[index]-Seed1Dir[index];
606 Seed2End1[index]=Seed2Pt[index]+Seed2Dir[index];
607 Seed2End2[index]=Seed2Pt[index]-Seed2Dir[index];
610 if( ( (Seed1End1-Seed2End1).Mag() < EndThresh)
611 ||( (Seed1End2-Seed2End1).Mag() < EndThresh)
612 ||( (Seed1End1-Seed2End2).Mag() < EndThresh)
613 ||( (Seed1End2-Seed2End2).Mag() < EndThresh))
619 double Pt[3];
double Dir[3];
double Err[3];
620 TVector3 End1; TVector3 End2;
622 ConnectionMap[i][j] = ConnectionMap[j][i] = TestTrack.
GetLength();
623 for(
size_t isd=0; isd!=Seeds.size(); ++isd)
625 if((isd!=i)&&(isd!=j)&&(RedundantSeeds[i]!=
true)&&(RedundantSeeds[j]!=
true)&&(RedundantSeeds[isd]!=
true))
627 Seeds.at(isd).GetPoint(Pt,Err);
628 Seeds.at(isd).GetDirection(Dir,Err);
631 for(
size_t index=0; index!=3; ++index)
633 End1[index]=Pt[index]+Dir[index];
634 End2[index]=Pt[index]-Dir[index];
636 double s1, s2, d1,d2;
643 std::cout<<
" meets 3D throw condition"<<std::endl;
647 for(
size_t p=0; p!=3; ++p)
652 double dp1, sp1, dp2, sp2;
656 if((dp1>1.0)||(dp2>1.0)) NoFails =
false;
661 std::cout<<
"Propose throwing out seed " << isd<<std::endl;
662 RedundantSeeds[isd]=
true;
673 std::map<int, std::map<int, double> > FilteredMap;
675 std::vector<int> OldNew;
676 for(
size_t i=0; i!=Seeds.size(); ++i)
681 for(
int i=Seeds.size()-1; i!=-1; --i)
683 if(RedundantSeeds[i])
685 Seeds.erase(Seeds.begin()+i);
686 OldNew.erase(OldNew.begin()+i);
690 for(
size_t i=0; i!=OldNew.size(); ++i)
692 for(
size_t j=0; j!=OldNew.size(); ++j)
694 FilteredMap[i][j] = ConnectionMap[OldNew[i]][OldNew[j]];
698 ConnectionMap = FilteredMap;
702 for(
size_t i=0; i!=Seeds.size(); ++i)
704 for(
size_t j=0; j!=i; ++j)
706 if(ConnectionMap[i][j]>0)
708 for(
size_t k=0; k!=Seeds.size(); ++k)
710 if((ConnectionMap[i][k]>0)&&(ConnectionMap[k][j]>0))
712 if( ( ConnectionMap[i][k] > ConnectionMap[i][j]) && ( ConnectionMap[i][k] > ConnectionMap[j][k]))
713 ConnectionMap[i][j] = ConnectionMap[j][i] = ConnectionMap[k][j] = ConnectionMap[j][k] = 0;
714 else if( ( ConnectionMap[i][j] > ConnectionMap[i][k]) && ( ConnectionMap[i][j] > ConnectionMap[j][k]))
715 ConnectionMap[j][k] = ConnectionMap[k][j] = ConnectionMap[i][k] = ConnectionMap[k][i] = 0;
717 ConnectionMap[i][j] = ConnectionMap[j][i] = ConnectionMap[i][k] = ConnectionMap[k][i] = 0;
725 for(
size_t i=0; i!=Seeds.size(); ++i)
728 for(
size_t j=0; j!=Seeds.size(); ++j)
730 if(ConnectionMap[i][j]>0)
733 std::cout<<
" After delooping, seed " << i <<
" is connected " << Count <<
" times"<<std::endl;
744 std::vector<trkf::BezierTrack> ReturnVec;
746 std::vector<std::vector<int> > CollectedSeeds;
747 std::map<int, bool> AlreadyCounted;
751 bool StillFinding=
true;
754 for(
size_t baseseed=0; baseseed!=Seeds.size(); ++baseseed)
756 if(!AlreadyCounted[baseseed])
758 std::vector<int> SeedsThisTrack;
759 SeedsThisTrack.clear();
761 SeedsThisTrack.push_back(baseseed);
765 for(
size_t i=0; i!=SeedsThisTrack.size(); ++i)
767 for(
size_t j=0; j!=Seeds.size(); ++j)
769 if((!AlreadyCounted[j])&&(ConnMap[SeedsThisTrack[i]][j]>0))
771 SeedsThisTrack.push_back(j);
772 AlreadyCounted[j]=
true;
778 CollectedSeeds.push_back(SeedsThisTrack);
781 std::cout<<
"Found " << CollectedSeeds.size()<<
" sensible collections. Sizes:"<<std::endl;
782 for(
size_t i=0; i!=CollectedSeeds.size(); ++i)
783 std::cout<<
" " << CollectedSeeds.at(i).size()<<std::endl;
785 return std::vector<trkf::BezierTrack>();
std::vector< float > line_integrals(trkf::BezierTrack &, size_t Steps, float threshold)
std::map< int, std::map< int, double > > GetConnectionMap(std::vector< recob::Seed > &Seeds, double ADCThresh, double FracThresh)
Reconstruction base classes.
void RemoveDuplicatePaths(std::vector< recob::Seed > &Seeds, std::vector< int > &ConnectionPoint1, std::vector< int > &ConnectionPoint2)
Encapsulate the construction of a single cyostat.
bool CheckSeedLineInt(recob::Seed &TheSeed)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
void GetPoint(double *Pt, double *Err) const
float line_integral(TH2F const &hist, int x1, float y1, int x2, float y2, float threshold)
recob::Seed ExtendSeed(recob::Seed TheSeed)
void get_feature_points(std::vector< recob::EndPoint2D > &, geo::Geometry const &)
std::map< int, std::vector< double > > ExtractEndPointTimes(std::vector< recob::EndPoint2D > EndPoints)
std::vector< recob::Seed > GetValidLines(std::vector< recob::SpacePoint > &sps, bool ApplyFilter=true)
virtual double ConvertXToTicks(double X, int p, int t, int c) const =0
void GetProjectedEnds(TVector3 xyz, std::vector< double > &uvw, std::vector< double > &t, int tpc=0, int cryo=0)
ProductID put(std::unique_ptr< PROD > &&product)
std::string fTruthModuleLabel
void GrabWires(std::vector< recob::Wire > const &wireVec, geo::Geometry const &)
std::vector< trkf::BezierTrack > GenerateBezierTracks(std::map< int, std::map< int, double > >, std::vector< recob::Seed >)
TH2F const & GetWireDataHist(unsigned int)
#define DEFINE_ART_MODULE(klass)
void SetPoint(double *Pt, double *Err)
void push_back(Ptr< U > const &p)
algorithm to find feature 2D points
T get(std::string const &key) const
geo::WireID::WireID_t NearestWire(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the index of wire closest to position in the specified TPC.
std::string fCalDataModuleLabel
std::vector< recob::SpacePoint > Get3DFeaturePoints(std::vector< recob::EndPoint2D > EndPoints, art::PtrVector< recob::Hit > Hits)
std::map< int, std::vector< double > > fEndPointTimes
data_t::const_iterator const_iterator
std::string fHitModuleLabel
std::vector< TrajPoint > seeds
void makeSpacePoints(const art::PtrVector< recob::Hit > &hits, std::vector< recob::SpacePoint > &spts) const
Utility object to perform functions of association.
void reconfigure(fhicl::ParameterSet const &pset)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
art::ServiceHandle< geo::Geometry > fGeometryHandle
Declaration of basic channel signal object.
virtual ~FeatureTracker()
void GetClosestApproach(recob::Hit const &hit, double &s, double &Distance) const
void produce(art::Event &evt)
Algorithm for generating space points from hits.
Namespace collecting geometry-related classes utilities.
void GetDirection(double *Dir, double *Err) const
art framework interface to geometry description
Encapsulate the construction of a single detector plane.
corner::CornerFinderAlg fCorner
void SetDirection(double *Dir, double *Err)