417 mf::LogError(
"pma::VtxCandidate") <<
"Tracks already attached to the vertex.";
423 <<
"JoinTracks (" <<
fAssigned.size() <<
") at:" 428 while (t < src.
size()) {
429 if (
c.first.Track() == src[
t].Track()) {
440 for (
auto&
c : fAssigned)
441 for (
auto const& t : tracks.
tracks())
442 if (
c.first.Track() == t.Track()) {
443 c.first.SetTreeId(t.TreeId());
448 std::vector<int> treeIds;
452 bool hasInnerCenter =
false;
454 for (
size_t i = 0; i < fAssigned.size(); i++) {
458 int key = fAssigned[i].first.Key();
459 int tid = fAssigned[i].first.TreeId();
460 size_t idx = fAssigned[i].second;
463 <<
" (nodes:" << trk->
Nodes().size() <<
")";
465 if (!
has(treeIds, tid))
467 treeIds.push_back(tid);
472 mf::LogError(
"pma::VtxCandidate") <<
"Root of the tree not found in tracks collection.";
475 TVector3 p0(trk->
Nodes()[idx]->Point3D());
476 TVector3 p1(trk->
Nodes()[idx + 1]->Point3D());
478 int tpc0 = trk->
Nodes()[idx]->TPC();
479 int tpc1 = trk->
Nodes()[idx + 1]->TPC();
481 int cryo0 = trk->
Nodes()[idx]->Cryo();
482 int cryo1 = trk->
Nodes()[idx + 1]->Cryo();
493 vtxCenter = trk->
Nodes().front();
499 if (trk->
AttachTo(vtxCenter)) nOK++;
505 mf::LogVerbatim(
"pma::VtxCandidate") <<
" flip trk to make new center";
507 vtxCenter = trk->
Nodes().front();
511 vtxCenter = trk->
Nodes().back();
518 mf::LogVerbatim(
"pma::VtxCandidate") <<
" flip trk to attach to inner";
520 if (trk->
AttachTo(vtxCenter)) nOK++;
529 bool canFlipPrev =
true;
530 if (vtxCenter && vtxCenter->
Prev()) {
538 if (hasInnerCenter || !canFlipPrev) {
559 mf::LogVerbatim(
"pma::VtxCandidate") <<
" add center at end of segment";
563 mf::LogVerbatim(
"pma::VtxCandidate") <<
" center at start of segment - no action";
571 <<
" trk size:" << trk->
size() <<
" (nodes:" << trk->
Nodes().size() <<
")";
576 <<
" t0 size:" << t0->
size() <<
" (nodes:" << t0->
Nodes().size() <<
")";
580 tracks.
tracks().emplace_back(t0, key, tid);
583 vtxCenter = trk->
Nodes().front();
588 if (trk->
AttachTo(vtxCenter)) nOK += 2;
595 hasInnerCenter =
true;
615 mf::LogVerbatim(
"pma::VtxCandidate") <<
" add center at end of segment";
619 mf::LogVerbatim(
"pma::VtxCandidate") <<
" center at start of segment - no action";
630 rootBranch = seg->
Parent();
637 for (
size_t j = 0; j < branches.size(); ++j) {
638 if (branches[j]->AttachTo(innerCenter,
true)) {}
640 vtxCenter = innerCenter;
643 vtxCenter = innerCenter;
657 rootSeg = static_cast<pma::Segment3D*>(vtxCenter->
Next(0));
658 else if (vtxCenter->
Prev())
659 rootSeg = static_cast<pma::Segment3D*>(vtxCenter->
Prev());
661 throw cet::exception(
"pma::VtxCandidate") <<
"Vertex with no segments attached.";
664 if (!rootTrk) rootTrk = rootSeg->
Parent();
666 std::vector<pma::Track3D const*> branchesToRemove;
667 bool noLoops = rootTrk->
GetBranches(branchesToRemove);
670 if (noLoops && (nOK > 1)) {
687 if (noLoops && tuneOK) {
689 for (
auto&
c : backupTracks.
tracks())
693 mf::LogVerbatim(
"pma::VtxCandidate") <<
"restore tracks from backup....";
694 for (
int tid : treeIds) {
696 while (t < tracks.
size()) {
697 if (tracks[t].TreeId() == tid) {
698 tracks[
t].DeleteTrack();
705 for (
const auto&
c : backupTracks.
tracks())
711 mf::LogError(
"pma::VtxCandidate") <<
"Cannot create common vertex";
code to link reconstructed objects back to the MC truth information
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
TVector3 const & Point3D() const
pma::Track3D * getTreeCopy(pma::TrkCandidateColl &dst, size_t trkIdx, bool isRoot=true)
bool AttachTo(pma::Node3D *vStart, bool noFlip=false)
static constexpr double g
double Dist2(const TVector2 &v1, const TVector2 &v2)
void erase_at(size_t pos)
bool GetBranches(std::vector< pma::Track3D const * > &branches, bool skipFirst=false) const
std::vector< std::pair< pma::TrkCandidate, size_t > > fAssigned
virtual unsigned int NextCount(void) const
std::vector< pma::Track3D * > GetBranches() const
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double TuneFullTree(double eps=0.001, double gmax=50.0)
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.
TVector2 GetProjectionToSegment(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
static constexpr double kMinDistToNode
int getCandidateIndex(pma::Track3D const *candidate) const
bool SetPoint3D(const TVector3 &p3d)
void InsertNode(detinfo::DetectorPropertiesData const &detProp, TVector3 const &p3d, size_t at_idx, unsigned int tpc, unsigned int cryo)
virtual pma::SortedObjectBase * Next(unsigned int index=0) const
double GetSegmentProjVector(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
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 * Parent(void) const
bool AttachBackTo(pma::Node3D *vStart)
pma::Segment3D * NextSegment(pma::Node3D *vtx) const
void push_back(const TrkCandidate &trk)
std::vector< TrkCandidate > const & tracks() const
cet::coded_exception< error, detail::translate > exception
bool has(const std::vector< int > &v, int id) const