67 double angle1 = a1.Angle(a2);
68 if (angle1 > TMath::PiOver2()) angle1 = TMath::Pi() - angle1;
69 double angle2 = a1.Angle(p1 - p2);
70 if (angle2 > TMath::PiOver2()) angle2 = TMath::Pi() - angle2;
71 if (angle1 < angcut && angle2 < angcut)
79 const std::vector<trkPoint>& trkpts2,
83 if (!trkpts1.size())
return match;
84 if (!trkpts2.size())
return match;
85 if ((trkpts1[0].
hit)->WireID().Cryostat == (trkpts2[0].hit)->
WireID().Cryostat &&
86 (trkpts1[0].hit)->
WireID().TPC == (trkpts2[0].hit)->
WireID().TPC)
109 trkpts1.back().pos, trkpts2[0].pos, trkpts1.back().dir, trkpts2[0].dir, angcut))
112 trkpts1[0].pos, trkpts2.back().pos, trkpts1[0].dir, trkpts2.back().dir, angcut))
115 trkpts1.back().pos, trkpts2.back().pos, trkpts1.back().dir, trkpts2.back().dir, angcut))
128 return tp1.
pos.X() < tp2.
pos.X();
133 return tp1.
pos.X() > tp2.
pos.X();
138 return tp1.
pos.Y() < tp2.
pos.Y();
143 return tp1.
pos.Y() > tp2.
pos.Y();
148 return tp1.
pos.Z() < tp2.
pos.Z();
153 return tp1.
pos.Z() > tp2.
pos.Z();
158 const double* xyz1 = h1.
XYZ();
159 const double* xyz2 = h2.
XYZ();
160 return xyz1[0] < xyz2[0];
165 const double* xyz1 = h1.
XYZ();
166 const double* xyz2 = h2.
XYZ();
167 return xyz1[0] > xyz2[0];
172 const double* xyz1 = h1.
XYZ();
173 const double* xyz2 = h2.
XYZ();
174 return xyz1[1] < xyz2[1];
179 const double* xyz1 = h1.
XYZ();
180 const double* xyz2 = h2.
XYZ();
181 return xyz1[1] > xyz2[1];
186 const double* xyz1 = h1.
XYZ();
187 const double* xyz2 = h2.
XYZ();
188 return xyz1[2] < xyz2[2];
193 const double* xyz1 = h1.
XYZ();
194 const double* xyz2 = h2.
XYZ();
195 return xyz1[2] > xyz2[2];
232 fSortDir = pset.get<std::string>(
"SortDirection",
"+z");
234 fAngCut = pset.get<
double>(
"AngCut");
237 produces<std::vector<recob::Track>>();
238 produces<std::vector<recob::SpacePoint>>();
239 produces<art::Assns<recob::Track, recob::Cluster>>();
240 produces<art::Assns<recob::Track, recob::SpacePoint>>();
241 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
242 produces<art::Assns<recob::Track, recob::Hit>>();
252 std::unique_ptr<std::vector<recob::Track>> tcol(
new std::vector<recob::Track>);
253 std::unique_ptr<std::vector<recob::SpacePoint>> spcol(
new std::vector<recob::SpacePoint>);
254 std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> tspassn(
256 std::unique_ptr<art::Assns<recob::Track, recob::Cluster>> tcassn(
258 std::unique_ptr<art::Assns<recob::Track, recob::Hit>> thassn(
260 std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> shassn(
275 std::vector<art::Ptr<recob::Cluster>> clusterlist;
288 std::vector<std::vector<trkPoint>> trkpts(matchedclusters.size());
289 for (
size_t itrk = 0; itrk < matchedclusters.size(); ++itrk) {
291 std::vector<art::Ptr<recob::Hit>> hitlist;
292 for (
size_t iclu = 0; iclu < matchedclusters[itrk].size(); ++iclu) {
294 std::vector<art::Ptr<recob::Hit>>
hits = fm.at(matchedclusters[itrk][iclu]);
295 for (
size_t ihit = 0; ihit < hits.size(); ++ihit) {
296 hitlist.push_back(hits[ihit]);
303 for (
size_t i = 0; i < hitlist.size(); ++i) {
307 trkpt.
hit = hitlist[i];
308 trkpts[itrk].push_back(trkpt);
320 size_t spStart = spcol->size();
321 std::vector<recob::SpacePoint> spacepoints;
332 spStart + spacepoints.size());
333 spacepoints.push_back(mysp);
334 spcol->push_back(mysp);
337 size_t spEnd = spcol->size();
339 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_x0);
340 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_x0);
343 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_x1);
344 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_x1);
347 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_y0);
348 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_y0);
351 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_y1);
352 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_y1);
355 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_z0);
356 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_z0);
359 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_z1);
360 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_z1);
363 if (spacepoints.size() > 0) {
366 std::vector<TVector3> xyz(spacepoints.size());
367 for (
size_t s = 0; s < spacepoints.size(); ++s) {
368 xyz[s] = TVector3(spacepoints[s].XYZ());
371 TVector3 startpointVec, endpointVec, DirCos;
372 startpointVec = xyz[0];
373 endpointVec = xyz.back();
374 DirCos = endpointVec - startpointVec;
380 std::cout <<
"The Spacepoint is infinitely small" << std::endl;
383 std::vector<TVector3> dircos(spacepoints.size(), DirCos);
401 std::vector<art::Ptr<recob::Hit>> trkhits;
402 for (
size_t ihit = 0; ihit < hitlist.size(); ++ihit) {
403 trkhits.push_back(hitlist[ihit]);
412 std::vector<std::vector<unsigned int>> trkidx;
415 for (
size_t itrk1 = 0; itrk1 < trkpts.size(); ++itrk1) {
416 for (
size_t itrk2 = itrk1 + 1; itrk2 < trkpts.size(); ++itrk2) {
420 for (
size_t i = 0; i < trkidx.size(); ++i) {
421 for (
size_t j = 0; j < trkidx[i].size(); ++j) {
422 if (trkidx[i][j] == itrk1) found1 = i;
423 if (trkidx[i][j] == itrk2) found2 = i;
426 if (found1 == -1 && found2 == -1) {
427 std::vector<unsigned int>
tmp;
428 tmp.push_back(itrk1);
429 tmp.push_back(itrk2);
430 trkidx.push_back(tmp);
432 else if (found1 == -1 && found2 != -1) {
433 trkidx[found2].push_back(itrk1);
435 else if (found1 != -1 && found2 == -1) {
436 trkidx[found1].push_back(itrk2);
438 else if (found1 != found2) {
439 trkidx[found1].insert(
440 trkidx[found1].
end(), trkidx[found2].
begin(), trkidx[found2].
end());
441 trkidx.erase(trkidx.begin() + found2);
446 for (
size_t itrk = 0; itrk < trkpts.size(); ++itrk) {
448 for (
size_t i = 0; i < trkidx.size(); ++i) {
449 for (
size_t j = 0; j < trkidx[i].size(); ++j) {
450 if (trkidx[i][j] == itrk) found =
true;
454 std::vector<unsigned int>
tmp;
456 trkidx.push_back(tmp);
461 trkidx.resize(trkpts.size());
462 for (
size_t i = 0; i < trkpts.size(); ++i) {
463 trkidx[i].push_back(i);
468 for (
size_t i = 0; i < trkidx.size(); ++i) {
470 std::vector<trkPoint> finaltrkpts;
472 std::vector<art::Ptr<recob::Cluster>> clustersPerTrack;
474 std::vector<art::Ptr<recob::Hit>> hitlist;
475 for (
size_t j = 0; j < trkidx[i].size(); ++j) {
476 for (
size_t k = 0; k < trkpts[trkidx[i][j]].size(); ++k) {
477 finaltrkpts.push_back(trkpts[trkidx[i][j]][k]);
478 hitlist.push_back(trkpts[trkidx[i][j]][k].
hit);
480 for (
size_t iclu = 0; iclu < matchedclusters[trkidx[i][j]].size(); ++iclu) {
482 matchedclusters[trkidx[i][j]][iclu]);
483 clustersPerTrack.push_back(cluster);
495 size_t spStart = spcol->size();
496 std::vector<recob::SpacePoint> spacepoints;
497 for (
size_t ipt = 0; ipt < finaltrkpts.size(); ++ipt) {
501 hitcoord[0] = finaltrkpts[ipt].pos.X();
502 hitcoord[1] = finaltrkpts[ipt].pos.Y();
503 hitcoord[2] = finaltrkpts[ipt].pos.Z();
508 spStart + spacepoints.size());
509 spacepoints.push_back(mysp);
510 spcol->push_back(mysp);
513 size_t spEnd = spcol->size();
514 if (spacepoints.size() > 0) {
516 std::vector<TVector3> xyz(spacepoints.size());
517 std::vector<TVector3> dircos(spacepoints.size());
518 for (
size_t s = 0; s < spacepoints.size(); ++s) {
519 xyz[s] = TVector3(spacepoints[s].XYZ());
520 dircos[s] = finaltrkpts[s].dir;
522 if (spacepoints.size() > 1) {
524 TVector3 xyz1 = TVector3(spacepoints[s + 1].XYZ());
525 TVector3
dir = xyz1 - xyz[s];
526 if (dir.Angle(dircos[s]) > 0.8 * TMath::Pi()) { dircos[s] = -dircos[s]; }
529 TVector3
dir = xyz[s] - xyz[s - 1];
530 if (dir.Angle(dircos[s]) > 0.8 * TMath::Pi()) { dircos[s] = -dircos[s]; }
553 std::vector<art::Ptr<recob::Hit>> trkhits;
554 for (
size_t ihit = 0; ihit < hitlist.size(); ++ihit) {
555 trkhits.push_back(hitlist[ihit]);
562 mf::LogVerbatim(
"Summary") << std::setfill(
'-') << std::setw(175) <<
"-" << std::setfill(
' ');
564 for (
unsigned int i = 0; i < tcol->size(); ++i)
568 evt.
put(std::move(tcol));
569 evt.
put(std::move(spcol));
570 evt.
put(std::move(tspassn));
571 evt.
put(std::move(tcassn));
572 evt.
put(std::move(thassn));
573 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
bool sp_sort_y1(const trkPoint &tp1, const trkPoint &tp2)
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
Declaration of signal hit object.
TrackTrajectory::Flags_t Flags_t
std::vector< TVector3 > trajPos
bool sp_sort_z1(const trkPoint &tp1, const trkPoint &tp2)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 >> SMatrixSym55
art::Ptr< recob::Hit > hit
std::vector< TVector3 > trkDir
WireID_t Wire
Index of the wire within its plane.
geo::WireID const & WireID() const
Initial tdc tick for hit.
bool fTrajOnly
Only use trajectory points from TrackTrajectoryAlg for debugging.
Cluster finding and building.
trkf::CosmicTrackerAlg fCTAlg
bool fStitchTracks
Stitch tracks from different TPCs.
bool MatchTrack(const std::vector< trkPoint > &trkpts1, const std::vector< trkPoint > &trkpts2, double angcut)
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)
std::vector< std::vector< unsigned int > > MatchedClusters(const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Cluster >> &clusterlist, const art::FindManyP< recob::Hit > &fm) const
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
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)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void push_back(Ptr< U > const &p)
A trajectory in space reconstructed from hits.
bool spt_sort_y0(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool spt_sort_z1(const recob::SpacePoint h1, const recob::SpacePoint h2)
Provides recob::Track data product.
void produce(art::Event &evt)
const Double32_t * XYZ() const
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
cluster::ClusterMatchTQ fClusterMatch
Declaration of cluster object.
Detector simulation of raw signals on wires.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
std::vector< TVector3 > trkPos
std::string fClusterModuleLabel
label for input cluster collection
bool spt_sort_z0(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
void SPTReco(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &fHits)
bool spt_sort_x0(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool spt_sort_y1(const recob::SpacePoint h1, const recob::SpacePoint h2)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
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