50 fSepTol = pset.
get<
double >(
"SpptSepTolerance", 10.0);
69 for(
int ii = 0; ii < ntrack; ++ii) {
72 const TVector3 start1(track1.
Vertex());
73 const TVector3 end1(track1.
End());
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());
92 const TVector3& end2(track2.
End());
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<TVector3> xyz;
267 std::vector<TVector3> dxdydz;
268 std::vector<TMatrixT<double> > cov;
269 std::vector<double> mom;
270 std::vector< std::vector <double> > dQdx;
275 for (
auto it = (*itvvArg).begin(); it!=(*itvvArg).end(); ++it)
281 for (
size_t pt = 0;
pt!=(*it).get()->NumberTrajectoryPoints();
pt++)
289 auto itvfHT =
fHT.begin() + size_t (itvArg -
fTrackVec.begin());
290 if ( (*itvfHT).size() &&
293 (cnt==1 && !(*itvfHT).at(cnt-1).compare(0,1,
"H")) ||
294 (cnt>1 && !(*itvfHT).at(cnt-2).compare(1,1,
"T"))
297 ptHere = (*it).get()->NumberTrajectoryPoints() -
pt - 1;
301 xyz.push_back((*it).get()->LocationAtPoint(ptHere));
303 dxdydz.push_back((*it).get()->DirectionAtPoint(ptHere));
304 TMatrixT<double> dumc(5,5);
305 if (ptHere<(*it).get()->NumberCovariance())
306 dumc = (*it).get()->CovarianceAtPoint(ptHere);
309 if ((*it).get()->HasMomentum())
310 dumm = (*it).get()->MomentumAtPoint(ptHere);
312 std::vector <double> dum;
313 if (ptHere<(*it).get()->NumberdQdx(
geo::kZ))
314 dum.push_back((*it).get()->DQdxAtPoint(ptHere,
geo::kZ));
322 mf::LogVerbatim(
"TrackStitcher bailing. ") <<
" One or more of xyz, dxdydz, cov, mom, dQdx elements from original Track is out of range..." << e.what() << __LINE__;
342 std::vector <std::string> trackStatus (
fh.size(),
"NotDone");
343 std::vector <std::string> HT2 ;
346 for (
unsigned int ii=0; ii<
fh.size(); ++ii)
349 if (!trackStatus.at(ii).compare(
"Done"))
continue;
360 std::string sh(std::get<0>(
fh.at(walk)));
361 std::string st(
"NA");
368 sh = std::get<0>(
fh.at(walk));
369 st = std::get<0>(
ft.at(walk));
373 if (!sh.compare(
"H") || !sh.compare(
"T"))
376 hInd = std::get<2>(
fh.at(walk));
381 HT2.push_back(
"H"+sh);
384 if ((!st.compare(
"H") || !st.compare(
"T")))
386 tInd = std::get<2>(
ft.at(walk));
390 HT2.push_back(
"T"+st);
392 if (hInd!=-12) walk = hInd;
393 if (tInd!=-12) walk = tInd;
394 if (!sh.compare(
"NA") && !st.compare(
"NA"))
397 trackStatus.at(walk) =
"Done";
405 st = std::get<0>(
ft.at(walk));
412 sh = std::get<0>(
fh.at(walk));
413 st = std::get<0>(
ft.at(walk));
417 if (!sh.compare(
"H") || !sh.compare(
"T"))
420 hInd = std::get<2>(
fh.at(walk));
425 HT2.insert(HT2.begin(),sh+
"H");
428 if ((!st.compare(
"H") || !st.compare(
"T")))
430 tInd = std::get<2>(
ft.at(walk));
434 HT2.insert(HT2.begin(),st+
"T");
436 if (hInd!=-12) walk = hInd;
437 if (tInd!=-12) walk = tInd;
438 if (!sh.compare(
"NA") && !st.compare(
"NA"))
441 trackStatus.at(walk) =
"Done";
446 if (compTrack.
size())
450 for (
auto iit = compTrack.
begin(); iit!=compTrack.
end();++iit)
453 for (
auto jit = iit+1; jit!=compTrack.
end();++jit)
459 compTrack.
erase(jit);
460 HT2.erase(HT2.begin()+cjit);
496 int osciit(-12), oscjit(-12);
497 std::vector < art::PtrVector<recob::Track> >
::iterator osiComposite, osjComposite;
510 for (
auto iiit = iit->begin(); iiit!=iit->end()&&!match; ++iiit)
512 for (
auto jjit = jit->begin(); jjit!=jit->end()&&!match; ++jjit)
533 if (!match)
return match;
540 (*osiComposite).
erase(osiAgg);
550 std::vector< std::vector<std::string> >
::iterator siit(
fHT.begin()+osciit-1);
551 std::vector< std::vector<std::string> >
::iterator sjit(
fHT.begin()+oscjit-1);
552 size_t itdiff(osiComposite->end()-osiComposite->begin());
553 if (osjAgg == osjComposite->begin())
560 (*osjComposite).insert(osjComposite->begin(),osiComposite->begin(),osiComposite->begin()+itdiff);
563 (*sjit).insert(sjit->begin(),siit->begin(),siit->begin()+itdiff);
566 else if (osjAgg == (osjComposite->end()-1))
569 (*osjComposite).insert(osjComposite->end(),osiComposite->begin(),osiComposite->begin()+itdiff);
570 (*sjit).insert(sjit->end(),siit->begin(),siit->begin()+itdiff);
585 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)
TVector3 VertexDirection() const
Covariance matrices are either set or not.
bool CommonComponentStitch()
iterator erase(iterator position)
Planes which measure Z direction.
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)
T get(std::string const &key) const
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
TVector3 Vertex() const
Covariance matrices are either set or not.
TVector3 EndDirection() const
Covariance matrices are either set or not.
std::vector< std::tuple< std::string, int, int, double, double > > ft
TVector3 End() const
Covariance matrices are either set or not.
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