50 fSepTol = pset.
get<
double >(
"SpptSepTolerance", 10.0);
69 for(
int ii = 0; ii < ntrack; ++ii) {
72 const TVector3 start1(track1.
Vertex<TVector3>());
73 const TVector3 end1(track1.
End<TVector3>());
77 std::vector< std::tuple< std::string, int, int, double, double> > headvv;
78 std::vector< std::tuple< std::string, int, int, double, double> > tailvv;
81 std::vector< std::vector<std::pair< double, double>> > matchhead;
82 std::vector< std::vector<std::pair< double, double>> > matchtail;
86 std::vector<art::Ptr <recob::Track> >
::iterator ith, itt;
88 for(
int jj = ii+1; jj < ntrack; ++jj) {
91 const TVector3& start2(track2.
Vertex<TVector3>());
92 const TVector3& end2(track2.
End<TVector3>());
94 const TVector3& end2Dir(track2.
EndDirection<TVector3>());
95 std::string sHT2(
"NA");
98 bool c12((std::abs(start1Dir.Dot(end2Dir))>
fCosAngTol) && ((start1-end2).Mag()<
fSepTol));
99 bool c21((std::abs(end1Dir.Dot(start2Dir))>
fCosAngTol) && ((start2-end1).Mag()<
fSepTol));
100 bool c11((std::abs(start1Dir.Dot(start2Dir))>
fCosAngTol) && ((start1-start2).Mag()<
fSepTol));
101 bool c22((std::abs(end1Dir.Dot(end2Dir))>
fCosAngTol) && ((end1-end2).Mag()<
fSepTol));
103 if ( c12 || c21 || c11 || c22 )
107 if (c12||c11) { head=
true; }
108 if (c11) { sHT2 =
"H"; }
else if (c12) { sHT2 =
"T"; }
109 if (c21||c22) { tail=
true; }
110 if (c21) { sHT2 =
"H"; }
else if (c22) { sHT2 =
"T"; }
114 head =
false; tail =
false;
115 if ( ((start1-end2).Mag() < (start2-end1).Mag()) || ((start1-end2).Mag() < (start2-end2).Mag()) || ((start1-start2).Mag() < (start2-end1).Mag()) || ((start1-start2).Mag() < (start2-end2).Mag()) )
116 { head =
true; tail =
false; }
118 { head =
false; tail =
true; }
124 std::vector< std::pair <double,double> > headv;
125 headv.push_back(std::pair<double,double>(abs(start1Dir.Dot(start2Dir)), (start1-start2).Mag()) );
126 headv.push_back(std::pair<double,double>(abs(start1Dir.Dot(end2Dir)), (start1-end2).Mag()) );
128 matchhead.push_back( headv );
130 if ( ((matchhead.size() > 1) && ( (matchhead.back().at(0).second < matchhead.front().at(0).second) || (matchhead.back().at(1).second < matchhead.front().at(1).second ) ) ) || matchhead.size()==1 )
132 if (matchhead.size()>1) matchhead.erase(matchhead.begin());
133 if (headvv.size()>1) headvv.erase(headvv.begin());
134 if (!sHT2.compare(
"H"))
136 auto tupTmp =std::make_tuple(sHT2,ii,jj,matchhead.back().at(0).first,matchhead.back().at(0).second);
137 headvv.push_back (tupTmp);
141 auto tupTmp = std::make_tuple(sHT2,ii,jj,matchhead.back().at(1).first,matchhead.back().at(1).second);
142 headvv.push_back (tupTmp);
146 matchhead.pop_back();
157 std::vector< std::pair <double,double> > tailv;
158 tailv.push_back(std::pair<double,double>( abs(end1Dir.Dot(start2Dir)),(start2-end1).Mag() ) );
159 tailv.push_back(std::pair<double,double>( abs(end1Dir.Dot(end2Dir)),(end1-end2).Mag() ) );
160 matchtail.push_back( tailv );
162 if ( ((matchtail.size() > 1) && ( (matchtail.back().at(0).second < matchtail.front().at(0).second) || (matchtail.back().at(1).second < matchtail.front().at(1).second ) ) ) || matchtail.size()==1 )
164 if (matchtail.size()>1) matchtail.erase(matchtail.begin());
165 if (tailvv.size()>1) tailvv.erase(tailvv.begin());
166 if (!sHT2.compare(
"T"))
168 auto tupTmp = std::make_tuple(sHT2,ii,jj,matchtail.back().at(0).first,matchtail.back().at(0).second);
169 tailvv.push_back(tupTmp);
173 auto tupTmp = std::make_tuple(sHT2,ii,jj,matchtail.back().at(1).first,matchtail.back().at(1).second);
174 tailvv.push_back(tupTmp);
178 matchtail.pop_back();
195 int otrk = std::get<2>(headvv.back());
197 std::string sotrkht(std::get<0>(headvv.back()));
198 for (
int kk=0;kk<ii;++kk)
200 if (std::get<2>(
fh.at(kk)) == otrk && !sotrkht.compare(std::get<0>(
fh.at(kk)) ) )
205 if (std::get<4>(headvv.back()) < std::get<4>(
fh.at(kk)) && std::get<4>(headvv.back())!=0.0)
207 auto tupTmp2 = std::make_tuple(std::string(
"NA"),kk,-12,0.0,0.0);
210 else if (std::get<4>(headvv.back())!=0.0)
220 int otrk = std::get<2>(tailvv.back());
222 std::string sotrkht(std::get<0>(tailvv.back()));
223 for (
int kk=0;kk<ii;++kk)
225 if (std::get<2>(
ft.at(kk)) == otrk && !sotrkht.compare(std::get<0>(
ft.at(kk)) ) )
229 if (std::get<4>(tailvv.back()) < std::get<4>(
ft.at(kk)) && std::get<4>(tailvv.back())!=0.0)
231 auto tupTmp2 = std::make_tuple(std::string(
"NA"),kk,-12,0.0,0.0);
234 else if (std::get<4>(tailvv.back())!=0.0)
247 auto tupTmp2 = std::make_tuple(std::string(
"NA"),ii,-12,0.0,0.0);
249 if (!headvv.size()) headvv.push_back(tupTmp2);
250 if (!tailvv.size()) tailvv.push_back(tupTmp2);
252 fh.push_back(headvv.back());
253 ft.push_back(tailvv.back());
266 std::vector<recob::tracking::Point_t> xyz;
267 std::vector<recob::tracking::Vector_t> dxdydz;
268 std::vector<recob::tracking::SMatrixSym55> cov;
269 std::vector<recob::TrackTrajectory::PointFlags_t> flgs;
272 bool hasMomentum =
true;
273 for (
auto it = (*itvvArg).begin(); it!=(*itvvArg).end(); ++it)
275 if ((*it).get()->HasMomentum()==
false) {
282 for (
auto it = (*itvvArg).begin(); it!=(*itvvArg).end(); ++it)
287 for (
size_t pt = 0;
pt!=(*it).get()->NumberTrajectoryPoints();
pt++)
295 auto itvfHT =
fHT.begin() + size_t (itvArg -
fTrackVec.begin());
296 if ( (*itvfHT).size() &&
299 (cnt==1 && !(*itvfHT).at(cnt-1).compare(0,1,
"H")) ||
300 (cnt>1 && !(*itvfHT).at(cnt-2).compare(1,1,
"T"))
303 ptHere = (*it).get()->NumberTrajectoryPoints() -
pt - 1;
307 xyz.push_back((*it).get()->LocationAtPoint(ptHere));
309 dxdydz.push_back( (hasMomentum ? (*it).get()->MomentumVectorAtPoint(ptHere) : (*it).get()->DirectionAtPoint(ptHere)) );
310 flgs.push_back((*it).get()->FlagsAtPoint(ptHere));
311 cov.push_back( (ptHere==0 ? (*it).get()->VertexCovariance() : (*it).get()->EndCovariance()));
315 mf::LogVerbatim(
"TrackStitcher bailing. ") <<
" One or more of xyz, dxdydz, cov, mom, dQdx elements from original Track is out of range..." << e.what() << __LINE__;
327 0, -1., 0, cov.front(), cov.back(),
ftNo++);
337 std::vector <std::string> trackStatus (
fh.size(),
"NotDone");
338 std::vector <std::string> HT2 ;
341 for (
unsigned int ii=0; ii<
fh.size(); ++ii)
344 if (!trackStatus.at(ii).compare(
"Done"))
continue;
355 std::string sh(std::get<0>(
fh.at(walk)));
356 std::string st(
"NA");
363 sh = std::get<0>(
fh.at(walk));
364 st = std::get<0>(
ft.at(walk));
368 if (!sh.compare(
"H") || !sh.compare(
"T"))
371 hInd = std::get<2>(
fh.at(walk));
376 HT2.push_back(
"H"+sh);
379 if ((!st.compare(
"H") || !st.compare(
"T")))
381 tInd = std::get<2>(
ft.at(walk));
385 HT2.push_back(
"T"+st);
387 if (hInd!=-12) walk = hInd;
388 if (tInd!=-12) walk = tInd;
389 if (!sh.compare(
"NA") && !st.compare(
"NA"))
392 trackStatus.at(walk) =
"Done";
400 st = std::get<0>(
ft.at(walk));
407 sh = std::get<0>(
fh.at(walk));
408 st = std::get<0>(
ft.at(walk));
412 if (!sh.compare(
"H") || !sh.compare(
"T"))
415 hInd = std::get<2>(
fh.at(walk));
420 HT2.insert(HT2.begin(),sh+
"H");
423 if ((!st.compare(
"H") || !st.compare(
"T")))
425 tInd = std::get<2>(
ft.at(walk));
429 HT2.insert(HT2.begin(),st+
"T");
431 if (hInd!=-12) walk = hInd;
432 if (tInd!=-12) walk = tInd;
433 if (!sh.compare(
"NA") && !st.compare(
"NA"))
436 trackStatus.at(walk) =
"Done";
441 if (compTrack.
size())
445 for (
auto iit = compTrack.
begin(); iit!=compTrack.
end();++iit)
448 for (
auto jit = iit+1; jit!=compTrack.
end();++jit)
454 compTrack.
erase(jit);
455 HT2.erase(HT2.begin()+cjit);
491 int osciit(-12), oscjit(-12);
492 std::vector < art::PtrVector<recob::Track> >
::iterator osiComposite, osjComposite;
505 for (
auto iiit = iit->begin(); iiit!=iit->end()&&!match; ++iiit)
507 for (
auto jjit = jit->begin(); jjit!=jit->end()&&!match; ++jjit)
528 if (!match)
return match;
535 (*osiComposite).
erase(osiAgg);
545 std::vector< std::vector<std::string> >
::iterator siit(
fHT.begin()+osciit-1);
546 std::vector< std::vector<std::string> >
::iterator sjit(
fHT.begin()+oscjit-1);
547 size_t itdiff(osiComposite->end()-osiComposite->begin());
548 if (osjAgg == osjComposite->begin())
555 (*osjComposite).insert(osjComposite->begin(),osiComposite->begin(),osiComposite->begin()+itdiff);
558 (*sjit).insert(sjit->begin(),siit->begin(),siit->begin()+itdiff);
561 else if (osjAgg == (osjComposite->end()-1))
564 (*osjComposite).insert(osjComposite->end(),osiComposite->begin(),osiComposite->begin()+itdiff);
565 (*sjit).insert(sjit->end(),siit->begin(),siit->begin()+itdiff);
580 fHT.erase(
fHT.begin()+osciit-1);
std::vector< std::tuple< std::string, int, int, double, double > > fh
StitchAlg(fhicl::ParameterSet const &pset)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
art::Handle< std::vector< recob::Track > > ftListHandle
std::vector< recob::Track > fTrackVec
void FindHeadsAndTails(const art::Event &e, const std::string &t)
bool CommonComponentStitch()
iterator erase(iterator position)
Vector_t VertexDirection() const
Access to track direction at different points.
void FirstStitch(const std::vector< art::PtrVector< recob::Track >>::iterator itvvArg, const std::vector< recob::Track >::iterator itvArg)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< std::vector< std::string > > fHT
void push_back(Ptr< U > const &p)
A trajectory in space reconstructed from hits.
T get(std::string const &key) const
Point_t const & Vertex() const
Access to track position at different points.
void reconfigure(fhicl::ParameterSet const &pset)
Definition of data types for geometry description.
data_t::iterator iterator
iterator insert(iterator position, Ptr< U > const &p)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Vector_t EndDirection() const
Access to track direction at different points.
std::vector< std::tuple< std::string, int, int, double, double > > ft
Point_t const & End() const
Access to track position at different points.
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception