27 #include "art/Framework/Core/EDProducer.h"
28 #include "art/Framework/Core/ModuleMacros.h"
29 #include "art/Framework/Principal/Event.h"
30 #include "art/Framework/Principal/Handle.h"
31 #include "art/Framework/Services/Registry/ServiceHandle.h"
32 #include "canvas/Persistency/Common/FindManyP.h"
33 #include "canvas/Persistency/Common/Ptr.h"
34 #include "canvas/Persistency/Common/PtrVector.h"
35 #include "fhiclcpp/ParameterSet.h"
36 #include "messagefacility/MessageLogger/MessageLogger.h"
58 art::Ptr<recob::Hit>
hit;
68 double angle1 = a1.Angle(a2);
69 if (angle1 > TMath::PiOver2()) angle1 = TMath::Pi() - angle1;
70 double angle2 = a1.Angle(p1 - p2);
71 if (angle2 > TMath::PiOver2()) angle2 = TMath::Pi() - angle2;
72 if (angle1 < angcut && angle2 < angcut)
81 const std::vector<trkPoint>& trkpts2,
86 if (!trkpts1.size())
return match;
87 if (!trkpts2.size())
return match;
88 if ((trkpts1[0].
hit)->WireID().Cryostat == (trkpts2[0].hit)->
WireID().Cryostat &&
89 (trkpts1[0].hit)->
WireID().TPC == (trkpts2[0].hit)->
WireID().TPC)
109 if (
AnglesConsistent(trkpts1[0].pos, trkpts2[0].pos, trkpts1[0].
dir, trkpts2[0].dir, angcut))
112 trkpts1.back().pos, trkpts2[0].pos, trkpts1.back().dir, trkpts2[0].dir, angcut))
115 trkpts1[0].pos, trkpts2.back().pos, trkpts1[0].dir, trkpts2.back().dir, angcut))
118 trkpts1.back().pos, trkpts2.back().pos, trkpts1.back().dir, trkpts2.back().dir, angcut))
125 SortByWire(art::Ptr<recob::Hit>
const& h1, art::Ptr<recob::Hit>
const& h2)
127 return h1->WireID().Wire < h2->WireID().Wire;
133 return tp1.
pos.X() < tp2.
pos.X();
139 return tp1.
pos.X() > tp2.
pos.X();
145 return tp1.
pos.Y() < tp2.
pos.Y();
151 return tp1.
pos.Y() > tp2.
pos.Y();
157 return tp1.
pos.Z() < tp2.
pos.Z();
163 return tp1.
pos.Z() > tp2.
pos.Z();
169 const double* xyz1 = h1.
XYZ();
170 const double* xyz2 = h2.
XYZ();
171 return xyz1[0] < xyz2[0];
177 const double* xyz1 = h1.
XYZ();
178 const double* xyz2 = h2.
XYZ();
179 return xyz1[0] > xyz2[0];
185 const double* xyz1 = h1.
XYZ();
186 const double* xyz2 = h2.
XYZ();
187 return xyz1[1] < xyz2[1];
193 const double* xyz1 = h1.
XYZ();
194 const double* xyz2 = h2.
XYZ();
195 return xyz1[1] > xyz2[1];
201 const double* xyz1 = h1.
XYZ();
202 const double* xyz2 = h2.
XYZ();
203 return xyz1[2] < xyz2[2];
209 const double* xyz1 = h1.
XYZ();
210 const double* xyz2 = h2.
XYZ();
211 return xyz1[2] > xyz2[2];
245 , fClusterMatch(pset.get<fhicl::ParameterSet>(
"ClusterMatch"))
246 , fCTAlg(pset.get<fhicl::ParameterSet>(
"CTAlg"))
248 fClusterModuleLabel = pset.get<std::string>(
"ClusterModuleLabel");
249 fSortDir = pset.get<std::string>(
"SortDirection",
"+z");
250 fStitchTracks = pset.get<
bool>(
"StitchTracks");
251 fDisCut = pset.get<
double>(
"DisCut");
252 fAngCut = pset.get<
double>(
"AngCut");
253 fTrajOnly = pset.get<
bool>(
"TrajOnly");
255 produces<std::vector<recob::Track>>();
256 produces<std::vector<recob::SpacePoint>>();
257 produces<art::Assns<recob::Track, recob::Cluster>>();
258 produces<art::Assns<recob::Track, recob::SpacePoint>>();
259 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
260 produces<art::Assns<recob::Track, recob::Hit>>();
269 art::ServiceHandle<geo::Geometry const> geom;
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>);
273 std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> tspassn(
274 new art::Assns<recob::Track, recob::SpacePoint>);
275 std::unique_ptr<art::Assns<recob::Track, recob::Cluster>> tcassn(
276 new art::Assns<recob::Track, recob::Cluster>);
277 std::unique_ptr<art::Assns<recob::Track, recob::Hit>> thassn(
278 new art::Assns<recob::Track, recob::Hit>);
279 std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> shassn(
280 new art::Assns<recob::SpacePoint, recob::Hit>);
293 art::Handle<std::vector<recob::Cluster>> clusterListHandle;
294 std::vector<art::Ptr<recob::Cluster>> clusterlist;
296 art::fill_ptr_vector(clusterlist, clusterListHandle);
301 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
303 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
307 std::vector<std::vector<trkPoint>> trkpts(matchedclusters.size());
308 for (
size_t itrk = 0; itrk < matchedclusters.size(); ++itrk) {
310 std::vector<art::Ptr<recob::Hit>> hitlist;
311 for (
size_t iclu = 0; iclu < matchedclusters[itrk].size(); ++iclu) {
313 std::vector<art::Ptr<recob::Hit>> hits = fm.at(matchedclusters[itrk][iclu]);
314 for (
size_t ihit = 0; ihit < hits.size(); ++ihit) {
315 hitlist.push_back(hits[ihit]);
322 for (
size_t i = 0; i < hitlist.size(); ++i) {
326 trkpt.
hit = hitlist[i];
327 trkpts[itrk].push_back(trkpt);
339 size_t spStart = spcol->size();
340 std::vector<recob::SpacePoint> spacepoints;
342 art::PtrVector<recob::Hit> sp_hits;
351 spStart + spacepoints.size());
352 spacepoints.push_back(mysp);
353 spcol->push_back(mysp);
356 size_t spEnd = spcol->size();
358 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_x0);
359 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_x0);
362 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_x1);
363 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_x1);
366 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_y0);
367 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_y0);
370 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_y1);
371 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_y1);
374 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_z0);
375 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_z0);
378 std::sort(spacepoints.begin(), spacepoints.end(),
spt_sort_z1);
379 std::sort(spcol->begin() + spStart, spcol->begin() + spEnd,
spt_sort_z1);
382 if (spacepoints.size() > 0) {
385 std::vector<TVector3> xyz(spacepoints.size());
386 for (
size_t s = 0;
s < spacepoints.size(); ++
s) {
387 xyz[
s] = TVector3(spacepoints[
s].XYZ());
390 TVector3 startpointVec, endpointVec, DirCos;
391 startpointVec = xyz[0];
392 endpointVec = xyz.back();
393 DirCos = endpointVec - startpointVec;
399 std::cout <<
"The Spacepoint is infinitely small" << std::endl;
402 std::vector<TVector3> dircos(spacepoints.size(), DirCos);
420 std::vector<art::Ptr<recob::Hit>> trkhits;
421 for (
size_t ihit = 0; ihit < hitlist.size(); ++ihit) {
422 trkhits.push_back(hitlist[ihit]);
431 std::vector<std::vector<unsigned int>> trkidx;
434 for (
size_t itrk1 = 0; itrk1 < trkpts.size(); ++itrk1) {
435 for (
size_t itrk2 = itrk1 + 1; itrk2 < trkpts.size(); ++itrk2) {
439 for (
size_t i = 0; i < trkidx.size(); ++i) {
440 for (
size_t j = 0; j < trkidx[i].size(); ++j) {
441 if (trkidx[i][j] == itrk1) found1 = i;
442 if (trkidx[i][j] == itrk2) found2 = i;
445 if (found1 == -1 && found2 == -1) {
446 std::vector<unsigned int> tmp;
447 tmp.push_back(itrk1);
448 tmp.push_back(itrk2);
449 trkidx.push_back(tmp);
451 else if (found1 == -1 && found2 != -1) {
452 trkidx[found2].push_back(itrk1);
454 else if (found1 != -1 && found2 == -1) {
455 trkidx[found1].push_back(itrk2);
457 else if (found1 != found2) {
458 trkidx[found1].insert(
459 trkidx[found1].
end(), trkidx[found2].
begin(), trkidx[found2].
end());
460 trkidx.erase(trkidx.begin() + found2);
465 for (
size_t itrk = 0; itrk < trkpts.size(); ++itrk) {
467 for (
size_t i = 0; i < trkidx.size(); ++i) {
468 for (
size_t j = 0; j < trkidx[i].size(); ++j) {
469 if (trkidx[i][j] == itrk) found =
true;
473 std::vector<unsigned int> tmp;
475 trkidx.push_back(tmp);
480 trkidx.resize(trkpts.size());
481 for (
size_t i = 0; i < trkpts.size(); ++i) {
482 trkidx[i].push_back(i);
487 for (
size_t i = 0; i < trkidx.size(); ++i) {
489 std::vector<trkPoint> finaltrkpts;
491 std::vector<art::Ptr<recob::Cluster>> clustersPerTrack;
493 std::vector<art::Ptr<recob::Hit>> hitlist;
494 for (
size_t j = 0; j < trkidx[i].size(); ++j) {
495 for (
size_t k = 0;
k < trkpts[trkidx[i][j]].size(); ++
k) {
496 finaltrkpts.push_back(trkpts[trkidx[i][j]][
k]);
497 hitlist.push_back(trkpts[trkidx[i][j]][k].
hit);
499 for (
size_t iclu = 0; iclu < matchedclusters[trkidx[i][j]].size(); ++iclu) {
500 art::Ptr<recob::Cluster>
cluster(clusterListHandle,
501 matchedclusters[trkidx[i][j]][iclu]);
502 clustersPerTrack.push_back(cluster);
514 size_t spStart = spcol->size();
515 std::vector<recob::SpacePoint> spacepoints;
516 for (
size_t ipt = 0; ipt < finaltrkpts.size(); ++ipt) {
517 art::PtrVector<recob::Hit> sp_hits;
518 sp_hits.push_back(finaltrkpts[ipt].
hit);
520 hitcoord[0] = finaltrkpts[ipt].pos.X();
521 hitcoord[1] = finaltrkpts[ipt].pos.Y();
522 hitcoord[2] = finaltrkpts[ipt].pos.Z();
527 spStart + spacepoints.size());
528 spacepoints.push_back(mysp);
529 spcol->push_back(mysp);
532 size_t spEnd = spcol->size();
533 if (spacepoints.size() > 0) {
535 std::vector<TVector3> xyz(spacepoints.size());
536 std::vector<TVector3> dircos(spacepoints.size());
537 for (
size_t s = 0;
s < spacepoints.size(); ++
s) {
538 xyz[
s] = TVector3(spacepoints[
s].XYZ());
539 dircos[
s] = finaltrkpts[
s].dir;
541 if (spacepoints.size() > 1) {
543 TVector3 xyz1 = TVector3(spacepoints[
s + 1].XYZ());
544 TVector3
dir = xyz1 - xyz[
s];
545 if (dir.Angle(dircos[
s]) > 0.8 * TMath::Pi()) { dircos[
s] = -dircos[
s]; }
548 TVector3
dir = xyz[
s] - xyz[
s - 1];
549 if (dir.Angle(dircos[
s]) > 0.8 * TMath::Pi()) { dircos[
s] = -dircos[
s]; }
572 std::vector<art::Ptr<recob::Hit>> trkhits;
573 for (
size_t ihit = 0; ihit < hitlist.size(); ++ihit) {
574 trkhits.push_back(hitlist[ihit]);
581 mf::LogVerbatim(
"Summary") << std::setfill(
'-') << std::setw(175) <<
"-" << std::setfill(
' ');
582 mf::LogVerbatim(
"Summary") <<
"CosmicTracker Summary:";
583 for (
unsigned int i = 0; i < tcol->size(); ++i)
584 mf::LogVerbatim(
"Summary") << tcol->at(i);
585 mf::LogVerbatim(
"Summary") <<
"CosmicTracker Summary End:";
587 evt.put(std::move(tcol));
588 evt.put(std::move(spcol));
589 evt.put(std::move(tspassn));
590 evt.put(std::move(tcassn));
591 evt.put(std::move(thassn));
592 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)
CosmicTracker(fhicl::ParameterSet const &pset)
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)
Declaration of signal hit object.
EResult err(const char *call)
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
bool fTrajOnly
Only use trajectory points from TrackTrajectoryAlg for debugging.
trkf::CosmicTrackerAlg fCTAlg
bool fStitchTracks
Stitch tracks from different TPCs.
std::vector< std::vector< unsigned int > > MatchedClusters(const detinfo::DetectorClocksData &clockdata, const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Cluster >> &clusterlist, const art::FindManyP< recob::Hit > &fm) const
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)
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)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
A trajectory in space reconstructed from hits.
auto end(FixedBins< T, C > const &) noexcept
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 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.
Provides recob::Track data product.
double fDisCut
Distance cut for track merging.
auto begin(FixedBins< T, C > const &) noexcept
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)
then echo File list $list not found else cat $list while read file do echo $file sed s
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)
constexpr double kBogusD
obviously bogus double value
std::string fSortDir
sort space points
physics associatedGroupsWithLeft p1
art framework interface to geometry description
BEGIN_PROLOG could also be cout
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