40 fSepTol = pset.
get<
double>(
"SpptSepTolerance", 10.0);
44 const std::string& trackModuleLabelArg)
59 for (
int ii = 0; ii < ntrack; ++ii) {
62 const TVector3 start1(track1.
Vertex<TVector3>());
63 const TVector3 end1(track1.
End<TVector3>());
67 std::vector<std::tuple<std::string, int, int, double, double>> headvv;
68 std::vector<std::tuple<std::string, int, int, double, double>> tailvv;
71 std::vector<std::vector<std::pair<double, double>>> matchhead;
72 std::vector<std::vector<std::pair<double, double>>> matchtail;
77 for (
int jj = ii + 1; jj < ntrack; ++jj) {
80 const TVector3& start2(track2.
Vertex<TVector3>());
81 const TVector3& end2(track2.
End<TVector3>());
83 const TVector3& end2Dir(track2.
EndDirection<TVector3>());
84 std::string sHT2(
"NA");
87 ((start1 - end2).Mag() <
fSepTol));
89 ((start2 - end1).Mag() <
fSepTol));
91 ((start1 - start2).Mag() <
fSepTol));
94 if (c12 || c21 || c11 || c22) {
97 if (c12 || c11) { head =
true; }
98 if (c11) { sHT2 =
"H"; }
102 if (c21 || c22) { tail =
true; }
103 if (c21) { sHT2 =
"H"; }
112 if (((start1 - end2).Mag() < (start2 - end1).Mag()) ||
113 ((start1 - end2).Mag() < (start2 - end2).Mag()) ||
114 ((start1 - start2).Mag() < (start2 - end1).Mag()) ||
115 ((start1 - start2).Mag() < (start2 - end2).Mag())) {
127 std::vector<std::pair<double, double>> headv;
129 std::pair<double, double>(
abs(start1Dir.Dot(start2Dir)), (start1 - start2).Mag()));
131 std::pair<double, double>(
abs(start1Dir.Dot(end2Dir)), (start1 - end2).Mag()));
133 matchhead.push_back(headv);
135 if (((matchhead.size() > 1) &&
136 ((matchhead.back().at(0).second < matchhead.front().at(0).second) ||
137 (matchhead.back().at(1).second < matchhead.front().at(1).second))) ||
138 matchhead.size() == 1) {
139 if (matchhead.size() > 1) matchhead.erase(matchhead.begin());
140 if (headvv.size() > 1) headvv.erase(headvv.begin());
141 if (!sHT2.compare(
"H")) {
142 auto tupTmp = std::make_tuple(
143 sHT2, ii, jj, matchhead.back().at(0).first, matchhead.back().at(0).second);
144 headvv.push_back(tupTmp);
147 auto tupTmp = std::make_tuple(
148 sHT2, ii, jj, matchhead.back().at(1).first, matchhead.back().at(1).second);
149 headvv.push_back(tupTmp);
153 matchhead.pop_back();
162 std::vector<std::pair<double, double>> tailv;
164 std::pair<double, double>(
abs(end1Dir.Dot(start2Dir)), (start2 - end1).Mag()));
166 std::pair<double, double>(
abs(end1Dir.Dot(end2Dir)), (end1 - end2).Mag()));
167 matchtail.push_back(tailv);
169 if (((matchtail.size() > 1) &&
170 ((matchtail.back().at(0).second < matchtail.front().at(0).second) ||
171 (matchtail.back().at(1).second < matchtail.front().at(1).second))) ||
172 matchtail.size() == 1) {
173 if (matchtail.size() > 1) matchtail.erase(matchtail.begin());
174 if (tailvv.size() > 1) tailvv.erase(tailvv.begin());
175 if (!sHT2.compare(
"T")) {
176 auto tupTmp = std::make_tuple(
177 sHT2, ii, jj, matchtail.back().at(0).first, matchtail.back().at(0).second);
178 tailvv.push_back(tupTmp);
181 auto tupTmp = std::make_tuple(
182 sHT2, ii, jj, matchtail.back().at(1).first, matchtail.back().at(1).second);
183 tailvv.push_back(tupTmp);
187 matchtail.pop_back();
203 int otrk = std::get<2>(headvv.back());
205 std::string sotrkht(std::get<0>(headvv.back()));
206 for (
int kk = 0; kk < ii; ++kk) {
207 if (std::get<2>(
fh.at(kk)) == otrk && !sotrkht.compare(std::get<0>(
fh.at(kk)))) {
211 if (std::get<4>(headvv.back()) < std::get<4>(
fh.at(kk)) &&
212 std::get<4>(headvv.back()) != 0.0) {
213 auto tupTmp2 = std::make_tuple(std::string(
"NA"), kk, -12, 0.0, 0.0);
216 else if (std::get<4>(headvv.back()) != 0.0) {
224 int otrk = std::get<2>(tailvv.back());
226 std::string sotrkht(std::get<0>(tailvv.back()));
227 for (
int kk = 0; kk < ii; ++kk) {
228 if (std::get<2>(
ft.at(kk)) == otrk && !sotrkht.compare(std::get<0>(
ft.at(kk)))) {
231 if (std::get<4>(tailvv.back()) < std::get<4>(
ft.at(kk)) &&
232 std::get<4>(tailvv.back()) != 0.0) {
233 auto tupTmp2 = std::make_tuple(std::string(
"NA"), kk, -12, 0.0, 0.0);
236 else if (std::get<4>(tailvv.back()) != 0.0) {
246 auto tupTmp2 = std::make_tuple(std::string(
"NA"), ii, -12, 0.0, 0.0);
248 if (!headvv.size()) headvv.push_back(tupTmp2);
249 if (!tailvv.size()) tailvv.push_back(tupTmp2);
251 fh.push_back(headvv.back());
252 ft.push_back(tailvv.back());
265 std::vector<recob::tracking::Point_t> xyz;
266 std::vector<recob::tracking::Vector_t> dxdydz;
267 std::vector<recob::tracking::SMatrixSym55> cov;
268 std::vector<recob::TrackTrajectory::PointFlags_t> flgs;
271 bool hasMomentum =
true;
272 for (
auto it = (*itvvArg).begin(); it != (*itvvArg).end(); ++it) {
273 if ((*it).get()->HasMomentum() ==
false) {
280 for (
auto it = (*itvvArg).begin(); it != (*itvvArg).end(); ++it) {
284 for (
size_t pt = 0;
pt != (*it).get()->NumberTrajectoryPoints();
pt++) {
291 auto itvfHT =
fHT.begin() + size_t(itvArg -
fTrackVec.begin());
292 if ((*itvfHT).size() && (
294 (cnt == 1 && !(*itvfHT).at(cnt - 1).compare(0, 1,
"H")) ||
295 (cnt > 1 && !(*itvfHT).at(cnt - 2).compare(1, 1,
"T"))))
296 ptHere = (*it).get()->NumberTrajectoryPoints() -
pt - 1;
299 xyz.push_back((*it).get()->LocationAtPoint(ptHere));
301 dxdydz.push_back((hasMomentum ? (*it).get()->MomentumVectorAtPoint(ptHere) :
302 (*it).get()->DirectionAtPoint(ptHere)));
303 flgs.push_back((*it).get()->FlagsAtPoint(ptHere));
305 (ptHere == 0 ? (*it).get()->VertexCovariance() : (*it).get()->EndCovariance()));
309 <<
" One or more of xyz, dxdydz, cov, mom, dQdx elements from original Track is out of " 311 << e.what() << __LINE__;
338 std::vector<std::string> trackStatus(
fh.size(),
"NotDone");
339 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");
360 if (walk != (
int)ii) {
361 sh = std::get<0>(
fh.at(walk));
362 st = std::get<0>(
ft.at(walk));
366 if (!sh.compare(
"H") || !sh.compare(
"T")) {
368 hInd = std::get<2>(
fh.at(walk));
373 HT2.push_back(
"H" + sh);
376 if ((!st.compare(
"H") || !st.compare(
"T"))) {
377 tInd = std::get<2>(
ft.at(walk));
381 HT2.push_back(
"T" + st);
383 if (hInd != -12) walk = hInd;
384 if (tInd != -12) walk = tInd;
385 if (!sh.compare(
"NA") && !st.compare(
"NA")) chain =
false;
387 trackStatus.at(walk) =
"Done";
395 st = std::get<0>(
ft.at(walk));
399 if (walk != (
int)ii) {
400 sh = std::get<0>(
fh.at(walk));
401 st = std::get<0>(
ft.at(walk));
405 if (!sh.compare(
"H") || !sh.compare(
"T")) {
407 hInd = std::get<2>(
fh.at(walk));
412 HT2.insert(HT2.begin(), sh +
"H");
415 if ((!st.compare(
"H") || !st.compare(
"T"))) {
416 tInd = std::get<2>(
ft.at(walk));
420 HT2.insert(HT2.begin(), st +
"T");
422 if (hInd != -12) walk = hInd;
423 if (tInd != -12) walk = tInd;
424 if (!sh.compare(
"NA") && !st.compare(
"NA")) chain =
false;
426 trackStatus.at(walk) =
"Done";
430 if (compTrack.
size()) {
433 for (
auto iit = compTrack.
begin(); iit != compTrack.
end(); ++iit) {
435 for (
auto jit = iit + 1; jit != compTrack.
end(); ++jit) {
439 compTrack.
erase(jit);
440 HT2.erase(HT2.begin() +
475 int osciit(-12), oscjit(-12);
476 std::vector<art::PtrVector<recob::Track>>
::iterator osiComposite, osjComposite;
484 for (
auto jit = iit + 1; jit !=
fTrackComposite.end() && !match; ++jit) {
486 for (
auto iiit = iit->begin(); iiit != iit->end() && !match; ++iiit) {
487 for (
auto jjit = jit->begin(); jjit != jit->end() && !match; ++jjit) {
505 if (!match)
return match;
511 (*osiComposite).
erase(osiAgg);
521 std::vector<std::vector<std::string>>
::iterator siit(
fHT.begin() + osciit - 1);
522 std::vector<std::vector<std::string>>
::iterator sjit(
fHT.begin() + oscjit - 1);
523 size_t itdiff(osiComposite->end() - osiComposite->begin());
524 if (osjAgg == osjComposite->begin()) {
531 .insert(osjComposite->begin(), osiComposite->begin(), osiComposite->begin() + itdiff);
534 (*sjit).insert(sjit->begin(), siit->begin(), siit->begin() + itdiff);
537 else if (osjAgg == (osjComposite->end() - 1)) {
540 .insert(osjComposite->end(), osiComposite->begin(), osiComposite->begin() + itdiff);
541 (*sjit).insert(sjit->end(), siit->begin(), siit->begin() + itdiff);
557 fHT.erase(
fHT.begin() + osciit - 1);
StitchAlg(fhicl::ParameterSet const &pset)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
typename data_t::iterator iterator
art::Handle< std::vector< recob::Track > > ftListHandle
std::vector< recob::Track > fTrackVec
std::vector< std::tuple< std::string, int, int, double, double > > fh
void FindHeadsAndTails(const art::Event &e, const std::string &t)
bool CommonComponentStitch()
iterator erase(iterator position)
constexpr auto abs(T v)
Returns the absolute value of the argument.
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.
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)
iterator insert(iterator position, Ptr< U > const &p)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Vector_t EndDirection() const
Access to track direction at different points.
Point_t const & End() const
Access to track position at different points.
std::vector< std::vector< std::string > > fHT
std::vector< std::tuple< std::string, int, int, double, double > > ft
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