61 #include "TVirtualFitter.h" 70 bool AnglesConsistent(
const TVector3& p1,
const TVector3& p2,
const TVector3&
a1,
const TVector3&
a2,
double angcut){
71 double angle1 = a1.Angle(a2);
72 if (angle1>TMath::PiOver2()) angle1 = TMath::Pi() - angle1;
73 double angle2 = a1.Angle(p1-p2);
74 if (angle2>TMath::PiOver2()) angle2 = TMath::Pi() - angle2;
75 if (angle1<angcut&&angle2<angcut)
return true;
80 bool MatchTrack(
const std::vector<trkPoint>& trkpts1,
const std::vector<trkPoint>& trkpts2,
double discut,
double angcut){
82 if (!trkpts1.size())
return match;
83 if (!trkpts2.size())
return match;
84 if ((trkpts1[0].
hit)->WireID().Cryostat == (trkpts2[0].hit)->WireID().Cryostat &&
85 (trkpts1[0].hit)->WireID().TPC == (trkpts2[0].hit)->WireID().TPC)
return match;
105 trkpts1[0].
dir, trkpts2[0].dir, angcut)) match =
true;
107 trkpts1.back().dir, trkpts2[0].dir, angcut)) match =
true;
109 trkpts1[0].dir, trkpts2.back().dir, angcut)) match =
true;
111 trkpts1.back().dir, trkpts2.back().dir, angcut)) match =
true;
122 return tp1.
pos.X() < tp2.
pos.X();
127 return tp1.
pos.X() > tp2.
pos.X();
132 return tp1.
pos.Y() < tp2.
pos.Y();
137 return tp1.
pos.Y() > tp2.
pos.Y();
142 return tp1.
pos.Z() < tp2.
pos.Z();
147 return tp1.
pos.Z() > tp2.
pos.Z();
152 const double* xyz1 = h1.
XYZ();
153 const double* xyz2 = h2.
XYZ();
154 return xyz1[0] < xyz2[0];
159 const double* xyz1 = h1.
XYZ();
160 const double* xyz2 = h2.
XYZ();
161 return xyz1[0] > xyz2[0];
166 const double* xyz1 = h1.
XYZ();
167 const double* xyz2 = h2.
XYZ();
168 return xyz1[1] < xyz2[1];
173 const double* xyz1 = h1.
XYZ();
174 const double* xyz2 = h2.
XYZ();
175 return xyz1[1] > xyz2[1];
180 const double* xyz1 = h1.
XYZ();
181 const double* xyz2 = h2.
XYZ();
182 return xyz1[2] < xyz2[2];
187 const double* xyz1 = h1.
XYZ();
188 const double* xyz2 = h2.
XYZ();
189 return xyz1[2] > xyz2[2];
231 fClusterMatch(pset.get<
fhicl::ParameterSet >(
"ClusterMatch")),
232 fCTAlg(pset.get<
fhicl::ParameterSet >(
"CTAlg"))
235 produces< std::vector<recob::Track> >();
236 produces< std::vector<recob::SpacePoint> >();
237 produces< art::Assns<recob::Track, recob::Cluster> >();
238 produces< art::Assns<recob::Track, recob::SpacePoint> >();
239 produces< art::Assns<recob::SpacePoint, recob::Hit> >();
240 produces< art::Assns<recob::Track, recob::Hit> >();
248 fSortDir = pset.
get< std::string >(
"SortDirection",
"+z");
271 std::unique_ptr<std::vector<recob::Track> > tcol (
new std::vector<recob::Track>);
272 std::unique_ptr<std::vector<recob::SpacePoint> > spcol(
new std::vector<recob::SpacePoint>);
291 std::vector<art::Ptr<recob::Cluster> > clusterlist;
302 std::vector<std::vector<trkPoint>> trkpts(matchedclusters.size());
303 for (
size_t itrk = 0; itrk<matchedclusters.size(); ++itrk){
305 std::vector<art::Ptr<recob::Hit> > hitlist;
306 for (
size_t iclu = 0; iclu<matchedclusters[itrk].size(); ++iclu){
308 std::vector< art::Ptr<recob::Hit> >
hits = fm.at(matchedclusters[itrk][iclu]);
309 for (
size_t ihit = 0; ihit<hits.size(); ++ihit){
310 hitlist.push_back(hits[ihit]);
317 for (
size_t i = 0; i<hitlist.size(); ++i){
321 trkpt.
hit = hitlist[i];
322 trkpts[itrk].push_back(trkpt);
334 size_t spStart = spcol->size();
335 std::vector<recob::SpacePoint> spacepoints;
352 spStart + spacepoints.size());
353 spacepoints.push_back(mysp);
354 spcol->push_back(mysp);
358 size_t spEnd = spcol->size();
363 std::sort(spacepoints.begin(),spacepoints.end(),
spt_sort_x0);
364 std::sort(spcol->begin()+spStart,spcol->begin()+spEnd,
spt_sort_x0);
367 std::sort(spacepoints.begin(),spacepoints.end(),
spt_sort_x1);
368 std::sort(spcol->begin()+spStart,spcol->begin()+spEnd,
spt_sort_x1);
371 std::sort(spacepoints.begin(),spacepoints.end(),
spt_sort_y0);
372 std::sort(spcol->begin()+spStart,spcol->begin()+spEnd,
spt_sort_y0);
375 std::sort(spacepoints.begin(),spacepoints.end(),
spt_sort_y1);
376 std::sort(spcol->begin()+spStart,spcol->begin()+spEnd,
spt_sort_y1);
379 std::sort(spacepoints.begin(),spacepoints.end(),
spt_sort_z0);
380 std::sort(spcol->begin()+spStart,spcol->begin()+spEnd,
spt_sort_z0);
383 std::sort(spacepoints.begin(),spacepoints.end(),
spt_sort_z1);
384 std::sort(spcol->begin()+spStart,spcol->begin()+spEnd,
spt_sort_z1);
387 if(spacepoints.size()>0){
390 std::vector<TVector3> xyz(spacepoints.size());
391 for(
size_t s = 0;
s < spacepoints.size(); ++
s){
392 xyz[
s] = TVector3(spacepoints[
s].XYZ());
395 TVector3 startpointVec,endpointVec, DirCos;
396 startpointVec = xyz[0];
397 endpointVec = xyz.back();
398 DirCos = endpointVec - startpointVec;
404 catch(...){std::cout<<
"The Spacepoint is infinitely small"<<std::endl;
408 std::vector<TVector3> dircos(spacepoints.size(), DirCos);
422 std::vector<art::Ptr<recob::Hit> > trkhits;
423 for (
size_t ihit = 0; ihit<hitlist.size(); ++ihit){
425 trkhits.push_back(hitlist[ihit]);
435 std::vector<std::vector<unsigned int>> trkidx;
438 for (
size_t itrk1 = 0; itrk1<trkpts.size(); ++itrk1){
439 for (
size_t itrk2 = itrk1+1; itrk2<trkpts.size(); ++itrk2){
443 for (
size_t i = 0; i<trkidx.size(); ++i){
444 for (
size_t j = 0; j<trkidx[i].size(); ++j){
445 if (trkidx[i][j]==itrk1) found1 = i;
446 if (trkidx[i][j]==itrk2) found2 = i;
450 if (found1==-1&&found2==-1){
451 std::vector<unsigned int>
tmp;
452 tmp.push_back(itrk1);
453 tmp.push_back(itrk2);
454 trkidx.push_back(tmp);
456 else if(found1==-1&&found2!=-1){
457 trkidx[found2].push_back(itrk1);
459 else if(found1!=-1&&found2==-1){
460 trkidx[found1].push_back(itrk2);
462 else if (found1!=found2){
463 trkidx[found1].insert(trkidx[found1].
end(),
464 trkidx[found2].
begin(),
465 trkidx[found2].
end());
466 trkidx.erase(trkidx.begin()+found2);
471 for (
size_t itrk = 0; itrk<trkpts.size(); ++itrk){
473 for (
size_t i = 0; i<trkidx.size(); ++i){
474 for (
size_t j = 0; j<trkidx[i].size(); ++j){
475 if (trkidx[i][j]==itrk) found =
true;
479 std::vector<unsigned int>
tmp;
481 trkidx.push_back(tmp);
486 trkidx.resize(trkpts.size());
487 for (
size_t i = 0; i<trkpts.size(); ++i){
488 trkidx[i].push_back(i);
493 for (
size_t i = 0; i<trkidx.size(); ++i){
495 std::vector<trkPoint> finaltrkpts;
497 std::vector<art::Ptr<recob::Cluster>> clustersPerTrack;
499 std::vector<art::Ptr<recob::Hit> > hitlist;
500 for(
size_t j = 0; j<trkidx[i].size(); ++j){
501 for (
size_t k = 0; k<trkpts[trkidx[i][j]].size(); ++k){
502 finaltrkpts.push_back(trkpts[trkidx[i][j]][k]);
503 hitlist.push_back(trkpts[trkidx[i][j]][k].
hit);
505 for (
size_t iclu = 0; iclu<matchedclusters[trkidx[i][j]].size(); ++iclu){
507 clustersPerTrack.push_back(cluster);
519 size_t spStart = spcol->size();
520 std::vector<recob::SpacePoint> spacepoints;
521 for (
size_t ipt = 0; ipt<finaltrkpts.size(); ++ipt){
525 hitcoord[0] = finaltrkpts[ipt].pos.X();
526 hitcoord[1] = finaltrkpts[ipt].pos.Y();
527 hitcoord[2] = finaltrkpts[ipt].pos.Z();
533 spStart + spacepoints.size());
534 spacepoints.push_back(mysp);
535 spcol->push_back(mysp);
538 size_t spEnd = spcol->size();
539 if(spacepoints.size()>0){
541 std::vector<TVector3> xyz(spacepoints.size());
542 std::vector<TVector3> dircos(spacepoints.size());
543 for(
size_t s = 0;
s < spacepoints.size(); ++
s){
544 xyz[
s] = TVector3(spacepoints[
s].XYZ());
545 dircos[
s] = finaltrkpts[
s].dir;
547 if (spacepoints.size()>1){
549 TVector3 xyz1 = TVector3(spacepoints[
s+1].XYZ());
550 TVector3
dir = xyz1-xyz[
s];
551 if (dir.Angle(dircos[
s])>0.8*TMath::Pi()){
552 dircos[
s] = -dircos[
s];
556 TVector3
dir = xyz[
s]-xyz[
s-1];
557 if (dir.Angle(dircos[
s])>0.8*TMath::Pi()){
558 dircos[
s] = -dircos[
s];
576 std::vector<art::Ptr<recob::Hit> > trkhits;
577 for (
size_t ihit = 0; ihit<hitlist.size(); ++ihit){
579 trkhits.push_back(hitlist[ihit]);
590 << std::setfill(
' ');
592 for(
unsigned int i = 0; i<tcol->size(); ++i)
mf::LogVerbatim(
"Summary") << tcol->at(i) ;
595 evt.
put(std::move(tcol));
596 evt.
put(std::move(spcol));
597 evt.
put(std::move(tspassn));
598 evt.
put(std::move(tcassn));
599 evt.
put(std::move(thassn));
600 evt.
put(std::move(shassn));
bool spt_sort_x1(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool sp_sort_x1(const trkPoint &tp1, const trkPoint &tp2)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void SPTReco(std::vector< art::Ptr< recob::Hit > > &fHits)
bool sp_sort_y1(const trkPoint &tp1, const trkPoint &tp2)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
geo::WireID WireID() const
Initial tdc tick for hit.
Declaration of signal hit object.
TrackTrajectory::Flags_t Flags_t
std::vector< TVector3 > trajPos
bool sp_sort_z1(const trkPoint &tp1, const trkPoint &tp2)
bool MatchTrack(const std::vector< trkPoint > &trkpts1, const std::vector< trkPoint > &trkpts2, double discut, double angcut)
art::Ptr< recob::Hit > hit
std::vector< TVector3 > trkDir
WireID_t Wire
Index of the wire within its plane.
bool fTrajOnly
Only use trajectory points from TrackTrajectoryAlg for debugging.
Cluster finding and building.
trkf::CosmicTrackerAlg fCTAlg
bool fStitchTracks
Stitch tracks from different TPCs.
void reconfigure(fhicl::ParameterSet const &p)
double fAngCut
Angle cut for track merging.
bool sp_sort_z0(const trkPoint &tp1, const trkPoint &tp2)
bool sp_sort_y0(const trkPoint &tp1, const trkPoint &tp2)
ProductID put(std::unique_ptr< PROD > &&product)
bool sp_sort_x0(const trkPoint &tp1, const trkPoint &tp2)
bool AnglesConsistent(const TVector3 &p1, const TVector3 &p2, const TVector3 &a1, const TVector3 &a2, double angcut)
bool SortByWire(art::Ptr< recob::Hit > const &h1, art::Ptr< recob::Hit > const &h2)
#define DEFINE_ART_MODULE(klass)
Provides recob::Track data product.
void push_back(Ptr< U > const &p)
A trajectory in space reconstructed from hits.
T get(std::string const &key) const
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
std::vector< std::vector< unsigned int > > matchedclusters
bool spt_sort_y0(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool spt_sort_z1(const recob::SpacePoint h1, const recob::SpacePoint h2)
void ClusterMatch(const std::vector< art::Ptr< recob::Cluster > > &clusterlist, const art::FindManyP< recob::Hit > &fm)
void produce(art::Event &evt)
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
const Double32_t * XYZ() const
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
cluster::ClusterMatchTQ fClusterMatch
Declaration of cluster object.
double fDisCut
Distance cut for track merging.
Detector simulation of raw signals on wires.
Encapsulate the geometry of a wire.
std::vector< TVector3 > trkPos
std::string fClusterModuleLabel
label for input cluster collection
bool spt_sort_z0(const recob::SpacePoint h1, const recob::SpacePoint h2)
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
bool spt_sort_x0(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool spt_sort_y1(const recob::SpacePoint h1, const recob::SpacePoint h2)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
constexpr double kBogusD
obviously bogus double value
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
std::string fSortDir
sort space points
art framework interface to geometry description
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
std::vector< std::vector< art::Ptr< recob::Hit > > > trajHit