24 : fParent(-1), fTrack(0), fKey(-1), fTreeId(-1), fMse(0), fValidation(0), fGood(false)
51 for (
size_t t = 0; t < fCandidates.size(); ++t)
52 if (fCandidates[t].
Track() == candidate)
return t;
58 int id = getCandidateIndex(candidate);
60 return fCandidates[id].TreeId();
70 while (t < fCandidates.size()) {
72 fCandidates[t].SetParent(-1);
73 fCandidates[t].Daughters().clear();
77 fCandidates.erase(fCandidates.begin() + t);
80 for (t = 0; t < fCandidates.size(); ++t) {
81 if (!fCandidates[t].
IsValid())
continue;
85 if (firstNode->
Prev())
88 fCandidates[t].SetParent(getCandidateIndex(parentTrk));
90 else if (fCandidates[t].
Parent() < 0)
94 fParents.back().SetTreeId(fCandidates[t].
TreeId());
95 size_t pri_idx = fCandidates.size() + fParents.size() - 1;
97 for (
size_t i = 0; i < firstNode->
NextCount(); ++i) {
100 int idx = getCandidateIndex(daughterTrk);
102 fCandidates[(size_t)idx].
SetParent(pri_idx);
103 fParents.back().Daughters().push_back((
size_t)idx);
108 for (
size_t n = 1;
n < trk->
Nodes().size(); ++
n) {
109 auto node = trk->
Nodes()[
n];
110 for (
size_t i = 0; i < node->NextCount(); ++i) {
112 if (daughterTrk != trk) {
113 int idx = getCandidateIndex(daughterTrk);
114 if (idx >= 0) fCandidates[t].Daughters().push_back((
size_t)idx);
137 for (
size_t i = 0; i < vtx->
NextCount(); i++) {
139 if (seg != segThis) {
140 int idx = getCandidateIndex(seg->
Parent());
143 setTreeId(
id, idx,
false);
145 mf::LogError(
"pma::setTreeId") <<
"Branch of the tree not found in tracks collection.";
155 fCandidates[trkIdx].SetTreeId(
id);
160 for (
auto& t : fCandidates)
164 for (
auto& t : fCandidates) {
165 if (!t.IsValid() || (t.TreeId() >= 0))
continue;
168 int rootTrkIdx = getCandidateIndex(t.Track()->GetRoot());
171 setTreeId(
id, rootTrkIdx);
173 mf::LogError(
"pma::setTreeIds") <<
"Root of the tree not found in tracks collection.";
185 std::map<int, std::vector<pma::Track3D*>> toFlip;
186 std::map<int, double> minVal;
189 for (
auto& t : fCandidates) {
190 if (!t.IsValid())
continue;
192 int tid = t.TreeId();
193 if (minVal.find(tid) == minVal.end()) minVal[tid] = 1.0e12;
195 TVector3 pFront(t.Track()->front()->Point3D());
196 pFront.SetX(-pFront.X());
197 pFront.SetY(-pFront.Y());
198 TVector3 pBack(t.Track()->back()->Point3D());
199 pBack.SetX(-pBack.X());
200 pBack.SetY(-pBack.Y());
203 if (pFront[coordinate] < minVal[tid]) {
204 minVal[tid] = pFront[coordinate];
205 toFlip[tid].push_back(t.Track());
208 if (pBack[coordinate] < minVal[tid]) {
209 minVal[tid] = pBack[coordinate];
210 if (!pushed) toFlip[tid].push_back(t.Track());
214 for (
auto& tEntry : toFlip)
215 if (tEntry.first >= 0) {
217 while (!tEntry.second.empty()) {
219 tEntry.second.pop_back();
222 pFront.SetX(-pFront.X());
223 pFront.SetY(-pFront.Y());
225 pBack.SetX(-pBack.X());
226 pBack.SetY(-pBack.Y());
228 if (pFront[coordinate] > pBack[coordinate]) {
229 if (setTreeOriginAtBack(detProp, trk)) {
break; }
231 mf::LogWarning(
"pma::TrkCandidateColl") <<
"Flip to coordinate failed.";
235 setTreeOriginAtFront(detProp, trk);
239 if (attempts++ > 2)
break;
248 int trkIdx = getCandidateIndex(trk);
249 int treeId = getCandidateTreeId(trk);
252 <<
"Track not found in the collection." << std::endl;
260 std::vector<pma::Track3D*> newTracks;
267 newTracks.push_back(u);
268 done = u->
Flip(detProp, newTracks);
275 throw cet::exception(
"pma::Track3D") <<
"Node not found." << std::endl;
279 done = incoming->
Flip(detProp, newTracks);
282 for (
const auto ts : newTracks) {
283 fCandidates.emplace_back(ts, -1, treeId);
293 int trkIdx = getCandidateIndex(trk);
294 int treeId = getCandidateTreeId(trk);
297 <<
"Track not found in the collection." << std::endl;
301 std::vector<pma::Track3D*> newTracks;
302 bool done = incoming->
Flip(detProp, newTracks);
303 for (
const auto ts : newTracks) {
304 fCandidates.emplace_back(ts, -1, treeId);
312 std::map<int, std::vector<pma::Track3D*>> trkMap;
315 for (
auto const& t : fCandidates) {
316 if (t.IsValid()) trkMap[t.TreeId()].push_back(t.Track());
319 for (
auto& tEntry : trkMap) {
321 for (
size_t i = tEntry.second.size(); i > 0; --i) {
331 fCandidates[idx1].Track()->ExtendWith(fCandidates[idx2].
Track());
333 for (
auto c : fCandidates[idx2].
Clusters()) {
334 fCandidates[idx1].Clusters().push_back(c);
337 fCandidates.erase(fCandidates.begin() + idx2);
339 setTreeId(fCandidates[idx1].
TreeId(), idx1);
351 int key = fCandidates[trkIdx].Key();
352 int tid = fCandidates[trkIdx].TreeId();
358 dst.
tracks().emplace_back(trkCopy, key, tid);
365 if (segThisCopy) vtxCopy =
static_cast<pma::Node3D*
>(segThisCopy->
Next());
372 for (
size_t i = 0; i < vtx->
NextCount(); i++) {
374 if (seg != segThis) {
375 int idx = getCandidateIndex(seg->
Parent());
378 pma::Track3D* branchCopy = getTreeCopy(dst, idx,
false);
379 if (!branchCopy->
AttachTo(vtxCopy,
true))
380 mf::LogError(
"pma::getTreeCopy") <<
"Branch copy cannot be attached to the tree.";
383 mf::LogError(
"pma::getTreeCopy") <<
"Branch of the tree not found in source collection.";
392 if (segThisCopy) vtxCopy =
static_cast<pma::Node3D*
>(segThisCopy->
Next());
void AutoFlip(pma::Track3D::EDirection dir, double thr=0.0, unsigned int n=0)
pma::Track3D * getTreeCopy(pma::TrkCandidateColl &dst, size_t trkIdx, bool isRoot=true)
bool AttachTo(pma::Node3D *vStart, bool noFlip=false)
int getCandidateTreeId(pma::Track3D const *candidate) const
Implementation of the Projection Matching Algorithm.
pma::Hit3D const * front() const
Implementation of the Projection Matching Algorithm.
int index_of(const pma::Hit3D *hit) const
virtual unsigned int NextCount(void) const
TVector3 const & Point3D() const
Implementation of the Projection Matching Algorithm.
bool setTreeOriginAtBack(detinfo::DetectorPropertiesData const &detProp, pma::Track3D *trk)
virtual pma::SortedObjectBase * Next(unsigned int=0) const
void SetTrack(pma::Track3D *trk)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void flipTreesToCoordinate(detinfo::DetectorPropertiesData const &detProp, size_t coordinate)
pma::Track3D * Split(detinfo::DetectorPropertiesData const &detProp, size_t idx, bool try_start_at_idx=true)
bool CanFlip() const
Check if the track can be flipped without breaking any other track.
bool setTreeOriginAtFront(detinfo::DetectorPropertiesData const &detProp, pma::Track3D *trk)
void setParentDaughterConnections()
int getCandidateIndex(pma::Track3D const *candidate) const
Implementation of the Projection Matching Algorithm.
void merge(size_t idx1, size_t idx2)
Track finding helper for the Projection Matching Algorithm.
Implementation of the Projection Matching Algorithm.
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
const std::vector< size_t > & Clusters() const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
pma::Hit3D const * back() const
std::vector< pma::Node3D * > const & Nodes() const noexcept
virtual pma::SortedObjectBase * Prev(void) const
bool Flip(const detinfo::DetectorPropertiesData &detProp, std::vector< pma::Track3D * > &allTracks)
pma::Track3D * Track() const
pma::Track3D * Parent(void) const
void setTreeId(int id, size_t trkIdx, bool isRoot=true)
pma::Segment3D * NextSegment(pma::Node3D *vtx) const
std::vector< TrkCandidate > const & tracks() const
cet::coded_exception< error, detail::translate > exception