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);
410 std::vector< std::vector<double> > dQdx;
412 tcol->push_back(
recob::Track(xyz, dircos, dQdx, mom, tcol->size()));
421 std::vector<art::Ptr<recob::Hit> > trkhits;
422 for (
size_t ihit = 0; ihit<hitlist.size(); ++ihit){
424 trkhits.push_back(hitlist[ihit]);
434 std::vector<std::vector<unsigned int>> trkidx;
437 for (
size_t itrk1 = 0; itrk1<trkpts.size(); ++itrk1){
438 for (
size_t itrk2 = itrk1+1; itrk2<trkpts.size(); ++itrk2){
442 for (
size_t i = 0; i<trkidx.size(); ++i){
443 for (
size_t j = 0; j<trkidx[i].size(); ++j){
444 if (trkidx[i][j]==itrk1) found1 = i;
445 if (trkidx[i][j]==itrk2) found2 = i;
449 if (found1==-1&&found2==-1){
450 std::vector<unsigned int>
tmp;
451 tmp.push_back(itrk1);
452 tmp.push_back(itrk2);
453 trkidx.push_back(tmp);
455 else if(found1==-1&&found2!=-1){
456 trkidx[found2].push_back(itrk1);
458 else if(found1!=-1&&found2==-1){
459 trkidx[found1].push_back(itrk2);
461 else if (found1!=found2){
462 trkidx[found1].insert(trkidx[found1].
end(),
463 trkidx[found2].
begin(),
464 trkidx[found2].
end());
465 trkidx.erase(trkidx.begin()+found2);
470 for (
size_t itrk = 0; itrk<trkpts.size(); ++itrk){
472 for (
size_t i = 0; i<trkidx.size(); ++i){
473 for (
size_t j = 0; j<trkidx[i].size(); ++j){
474 if (trkidx[i][j]==itrk) found =
true;
478 std::vector<unsigned int>
tmp;
480 trkidx.push_back(tmp);
485 trkidx.resize(trkpts.size());
486 for (
size_t i = 0; i<trkpts.size(); ++i){
487 trkidx[i].push_back(i);
492 for (
size_t i = 0; i<trkidx.size(); ++i){
494 std::vector<trkPoint> finaltrkpts;
496 std::vector<art::Ptr<recob::Cluster>> clustersPerTrack;
498 std::vector<art::Ptr<recob::Hit> > hitlist;
499 for(
size_t j = 0; j<trkidx[i].size(); ++j){
500 for (
size_t k = 0; k<trkpts[trkidx[i][j]].size(); ++k){
501 finaltrkpts.push_back(trkpts[trkidx[i][j]][k]);
502 hitlist.push_back(trkpts[trkidx[i][j]][k].
hit);
504 for (
size_t iclu = 0; iclu<matchedclusters[trkidx[i][j]].size(); ++iclu){
506 clustersPerTrack.push_back(cluster);
518 size_t spStart = spcol->size();
519 std::vector<recob::SpacePoint> spacepoints;
520 for (
size_t ipt = 0; ipt<finaltrkpts.size(); ++ipt){
524 hitcoord[0] = finaltrkpts[ipt].pos.X();
525 hitcoord[1] = finaltrkpts[ipt].pos.Y();
526 hitcoord[2] = finaltrkpts[ipt].pos.Z();
532 spStart + spacepoints.size());
533 spacepoints.push_back(mysp);
534 spcol->push_back(mysp);
537 size_t spEnd = spcol->size();
538 if(spacepoints.size()>0){
540 std::vector<TVector3> xyz(spacepoints.size());
541 std::vector<TVector3> dircos(spacepoints.size());
542 for(
size_t s = 0;
s < spacepoints.size(); ++
s){
543 xyz[
s] = TVector3(spacepoints[
s].XYZ());
544 dircos[
s] = finaltrkpts[
s].dir;
546 if (spacepoints.size()>1){
548 TVector3 xyz1 = TVector3(spacepoints[
s+1].XYZ());
549 TVector3
dir = xyz1-xyz[
s];
550 if (dir.Angle(dircos[
s])>0.8*TMath::Pi()){
551 dircos[
s] = -dircos[
s];
555 TVector3
dir = xyz[
s]-xyz[
s-1];
556 if (dir.Angle(dircos[
s])>0.8*TMath::Pi()){
557 dircos[
s] = -dircos[
s];
563 std::vector< std::vector<double> > dQdx;
565 tcol->push_back(
recob::Track(xyz, dircos, dQdx, mom, tcol->size()));
574 std::vector<art::Ptr<recob::Hit> > trkhits;
575 for (
size_t ihit = 0; ihit<hitlist.size(); ++ihit){
577 trkhits.push_back(hitlist[ihit]);
588 << std::setfill(
' ');
590 for(
unsigned int i = 0; i<tcol->size(); ++i)
mf::LogVerbatim(
"Summary") << tcol->at(i) ;
593 evt.
put(std::move(tcol));
594 evt.
put(std::move(spcol));
595 evt.
put(std::move(tspassn));
596 evt.
put(std::move(tcassn));
597 evt.
put(std::move(thassn));
598 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)
geo::WireID WireID() const
Initial tdc tick for hit.
Declaration of signal hit object.
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)
void push_back(Ptr< U > const &p)
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.
cluster::ClusterMatchTQ fClusterMatch
Declaration of cluster object.
Provides recob::Track data product.
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
const double * XYZ() const
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