48 ,
const unsigned short _nmincluster_match
49 ,
const float _nmincluster_ratio
50 ,
const float _cutoff_dphi
51 ,
const float _same_dphi
52 ,
const float _cutoff_deta
53 ,
const float _same_deta
54 ,
const unsigned short _max_nreco_per_truth
55 ,
const unsigned short _max_ntruth_per_reco)
56 : m_ismatcher { _ismatcher }
67 , m_max_ntruth_per_reco{_max_ntruth_per_reco}
69 m_TCEval.ismatcher = m_ismatcher;
72 std::cout <<
" Starting TruthRecoTrackMatching.cc " << std::endl;
99 if (topnode ==
nullptr)
133 auto index_reco = reco.first;
134 auto track = reco.second;
135 recoData.push_back({track->get_phi(), track->get_eta(), track->get_pt(), index_reco});
154 auto wrap_from_start = std::upper_bound(
recoData.begin(),
156 for (
auto iter =
recoData.begin(); iter != wrap_from_start; ++iter)
159 std::get<RECOphi>(
entry) = std::get<RECOphi>(
entry) + 2 * M_PI;
160 wraps.push_back(
entry);
169 std::cout <<
" ****************************************** " << std::endl;
170 std::cout <<
" This is the RECO map of tracks to match to " << std::endl;
171 std::cout <<
" ****************************************** " << std::endl;
174 std::cout << Form(
" id:%2i (phi:eta:pt) (%5.2f:%5.2f:%5.2f)", std::get<RECOid>(
E),
175 std::get<RECOphi>(
E), std::get<RECOeta>(
E), std::get<RECOpt>(
E))
178 std::cout <<
" ****end*listing*********************** " << std::endl;
194 std::vector<std::pair<unsigned short, unsigned short>> outerbox_pairs{};
195 std::vector<std::pair<unsigned short, unsigned short>> innerbox_pairs{};
197 if (topnode ==
nullptr)
206 auto& track = _pair.second;
207 std::cout << Form(
" id:%2i (phi:eta:pt) (%5.2f:%5.2f:%5.2f nclus: %i)", track->getTrackid(),
208 track->getPhi(), track->getPseudoRapidity(), track->getPt(),
209 (int) track->getClusters().size())
212 std::cout <<
" ----end-listing-truth-tracks---------- " << std::endl;
217 auto id_true = _pair.first;
218 auto track = _pair.second;
221 track->getPseudoRapidity(), track->getPt());
224 for (
auto& id_reco : match_indices.first)
226 innerbox_pairs.emplace_back(id_true, id_reco);
228 for (
auto& id_reco : match_indices.second)
230 outerbox_pairs.emplace_back(id_true, id_reco);
235 std::cout << Form(
" T(%i) find box(%5.2f:%5.2f:%5.2f)",
236 (
int) track->getTrackid(), track->getPhi(),
237 track->getPseudoRapidity(), track->getPt());
238 for (
auto& id_reco : match_indices.first)
240 std::cout <<
"->IB(" << id_reco <<
")";
242 for (
auto& id_reco : match_indices.second)
244 std::cout <<
"->OB(" << id_reco <<
")";
246 std::cout << std::endl;
252 std::cout <<
"Innerbox pairs" << std::endl;
257 std::cout <<
"Outerbox pairs" << std::endl;
264 auto id_true = _pair.first;
270 std::cout <<
" --START--print-all-stored-matches--" << std::endl;
271 std::cout <<
" --0-- Printing all matches stored (start)" << std::endl;
275 std::cout << Form(
" Match id(%2i->%2i) nClusMatch-nClusTrue-nClusReco (%2i:%2i:%2i)",
276 match->idTruthTrack(), match->idRecoTrack(),
277 match->nClustersMatched(), match->nClustersTruth(), match->nClustersReco())
280 std::cout <<
" --END--print-all-stored-matches----" << std::endl;
293 TFile* s_current = gDirectory->GetFile();
312 if (s_current !=
nullptr)
331 std::cout <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
339 std::cout <<
"Could not locate G4TruthInfo node when running "
340 <<
"\"TruthRecoTrackMatching\" module." << std::endl;
344 m_SvtxTrackMap = findNode::getClass<SvtxTrackMap>(topNode,
"SvtxTrackMap");
347 std::cout <<
"Could not locate SvtxTrackMap node when running "
348 <<
"\"TruthRecoTrackMatching\" module." << std::endl;
353 "TRKR_TRUTHCLUSTERCONTAINER");
356 std::cout <<
"Could not locate TRKR_TRUTHCLUSTERCONTAINER node when "
357 <<
"running \"TruthRecoTrackMatching\" module." << std::endl;
364 std::cout <<
"Could not locate TRKR_CLUSTER node when running "
365 <<
"\"TruthRecoTrackMatching\" module." << std::endl;
370 "TRKR_TRUTHTRACKCONTAINER");
373 std::cout <<
"Could not locate TRKR_TRUTHTRACKCONTAINER node when "
374 <<
"running \"TruthRecoTrackMatching\" module." << std::endl;
379 findNode::getClass<PHG4TpcCylinderGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
382 std::cout <<
"Could not locate CYLINDERCELLGEOM_SVTX node when "
383 <<
"running \"TruthRecoTrackMatching\" module." << std::endl;
395 "TRKR_EMBRECOMATCHCONTAINER");
400 auto DetNode =
dynamic_cast<PHCompositeNode*
>(dstiter.findFirst(
"PHCompositeNode",
"TRKR"));
409 "TRKR_EMBRECOMATCHCONTAINER",
"PHObject");
410 DetNode->addNode(newNode);
413 m_ActsGeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
418 std::pair<std::vector<unsigned short>, std::vector<unsigned short>>
429 mix_pair.first = std::lower_bound(mix_pair.first, mix_pair.second,
432 mix_pair.second = std::upper_bound(mix_pair.first, mix_pair.second,
435 if (mix_pair.first == mix_pair.second)
444 std::sort(mix_pair.first, mix_pair.second, CompRECOtoEta());
447 outer_box.first = std::lower_bound(mix_pair.first, mix_pair.second,
450 outer_box.second = std::lower_bound(outer_box.first, outer_box.second,
453 if (outer_box.first == outer_box.second)
456 std::sort(mix_pair.first, mix_pair.second, CompRECOtoPhi());
464 if (_delta_outer_pt > 0)
466 std::sort(outer_box.first, outer_box.second, CompRECOtoPt());
467 outer_box.first = std::lower_bound(outer_box.first, outer_box.second, truth_pt - _delta_outer_pt, CompRECOtoPt());
468 outer_box.second = std::upper_bound(outer_box.first, outer_box.second, truth_pt + _delta_outer_pt, CompRECOtoPt());
471 if (outer_box.first == outer_box.second)
474 std::sort(mix_pair.first, mix_pair.second, CompRECOtoPhi());
479 inner_box = outer_box;
480 if (_delta_inner_pt > 0)
483 inner_box.first = std::lower_bound(inner_box.first,
484 inner_box.second, truth_pt - _delta_inner_pt, CompRECOtoPt());
485 inner_box.second = std::upper_bound(inner_box.first,
486 inner_box.second, truth_pt + _delta_inner_pt, CompRECOtoPt());
490 std::sort(inner_box.first, inner_box.second, CompRECOtoEta());
497 if (inner_box.first != inner_box.second)
499 inner_box.first = std::lower_bound(inner_box.first, inner_box.second,
502 inner_box.second = std::lower_bound(inner_box.first, inner_box.second,
507 if (inner_box.first != inner_box.second)
509 std::sort(inner_box.first, inner_box.second, CompRECOtoPhi());
511 inner_box.first = std::lower_bound(inner_box.first, inner_box.second,
514 inner_box.second = std::lower_bound(inner_box.first, inner_box.second,
521 std::vector<unsigned short> inner_box_matches, outer_box_matches;
524 for (
auto iter = inner_box.first; iter != inner_box.second; ++iter)
526 inner_box_matches.push_back(std::get<RECOid>(*iter));
529 for (
auto iter = outer_box.first; iter != inner_box.first; ++iter)
531 outer_box_matches.push_back(std::get<RECOid>(*iter));
533 for (
auto iter = inner_box.second; iter != outer_box.second; ++iter)
535 outer_box_matches.push_back(std::get<RECOid>(*iter));
539 std::sort(mix_pair.first, mix_pair.second, CompRECOtoPhi());
542 return std::make_pair(inner_box_matches, outer_box_matches);
546 std::vector<std::pair<unsigned short, unsigned short>>& box_pairs
549 if (box_pairs.size() == 0)
554 std::sort(box_pairs.begin(), box_pairs.end());
555 std::vector<PossibleMatch> poss_matches;
557 auto ipair = box_pairs.begin();
558 while (ipair != box_pairs.end())
560 auto id_true = ipair->first;
565 while (ipair != box_pairs.end())
568 if (ipair->first != id_true)
586 while (ipair != box_pairs.end())
589 if (ipair->first != id_true)
599 SvtxTrack* reco_track = m_SvtxTrackMap->get(ipair->second);
630 "possmatch:(phi,eta,pT:id) true(%5.2f,%5.2f,%4.2f:%2i) reco(%5.2f,%5.2f,%4.2f:%2i) "
631 "nCl(match:true:reco:nomatch)(%2i-%2i-%2i-%2i)",
632 truth_track->getPhi(), truth_track->getPseudoRapidity(), truth_track->getPt(),
633 (int) truth_track->getTrackid(),
636 (int) nclus_match, (
int) nclus_true, (int) nclus_reco, (
int) nclus_nomatch)
641 poss_matches.push_back(
642 {nclus_match, nclus_true, nclus_reco,
643 ipair->first, ipair->second});
653 std::sort(poss_matches.begin(), poss_matches.end(), SortPossibleMatch());
657 std::cout <<
" All chosen possible matches (" << poss_matches.size() <<
") track pairs (nClMatched-nClTrue-nClReco : idTrue-idReco)" << std::endl;
659 for (
auto match : poss_matches)
663 std::cout << Form(
" pair(%2i): %2i-%2i-%2i-<%2i>-%2i ",
i++, (
int) std::get<PM_nmatch>(match), (
int) std::get<PM_ntrue>(match), (
int) std::get<PM_nreco>(match), (
int) std::get<PM_idtrue>(match), (
int) std::get<PM_idreco>(match)) << std::endl;
668 auto iter = poss_matches.begin();
669 while (iter != poss_matches.end())
676 std::vector<std::pair<float, int>> sigma_metric = {{0., 0}};
678 auto iter_same = iter + 1;
690 std::sort(sigma_metric.begin(), sigma_metric.end());
693 for (
auto&
sigma : sigma_metric)
703 auto match = *(iter +
sigma.second);
719 iter += sigma_metric.size();
728 float dphi = std::fabs(phi0 - phi1);
731 dphi = std::fabs(dphi - 2 * M_PI);
750 return std::numeric_limits<float>::max();
799 return -1. + pt * 0.;
803 return -1. + pt * 0.;
827 TFile* s_current = gDirectory->GetFile();
828 m_diag_file =
new TFile(file_name.c_str(),
"recreate");
831 m_diag_tree =
new TTree(
"T",
"Tree of Reco and True Clusters");
871 if (s_current !=
nullptr)
922 for (
auto& ckey : track->getClusters())
945 for (
auto& ckey : track->getClusters())
961 std::set<unsigned int> set_reco_matched;
966 set_reco_matched.insert(trkid);
968 SvtxTrack* reco_track = m_SvtxTrackMap->get(trkid);
989 for (
auto& reco : *m_SvtxTrackMap)
991 auto trkid = reco.first;
992 if (set_reco_matched.count(trkid))
997 SvtxTrack* reco_track = m_SvtxTrackMap->get(trkid);