13 #include <HelixHough/HelixKalmanState.h>
14 #include <HelixHough/HelixRange.h>
15 #include <HelixHough/SimpleHit3D.h>
16 #include <HelixHough/SimpleTrack3D.h>
17 #include <HelixHough/sPHENIXSeedFinder.h>
50 #include <Eigen/Dense>
67 #define LogDebug(exp) std::cout << "DEBUG: " << __FILE__ << ": " << __LINE__ << ": " << exp
68 #define LogError(exp) std::cout << "ERROR: " << __FILE__ << ": " << __LINE__ << ": " << exp
69 #define LogWarning(exp) std::cout << "WARNING: " << __FILE__ << ": " << __LINE__ << ": " << exp
74 #define _USE_ALAN_TRACK_REFITTING_
87 unsigned int nlayers_maps,
88 unsigned int nlayers_intt,
89 unsigned int nlayers_tpc,
90 unsigned int nlayers_seeding,
91 unsigned int min_nlayers_seeding)
94 , _t_seed_init1(nullptr)
95 , _t_seed_init2(nullptr)
96 , _t_seed_init3(nullptr)
97 , _t_seeds_cleanup(nullptr)
98 , _t_translate_to_PHGenFitTrack(nullptr)
99 , _t_translate1(nullptr)
100 , _t_translate2(nullptr)
101 , _t_translate3(nullptr)
102 , _t_kalman_pat_rec(nullptr)
103 , _t_search_clusters(nullptr)
104 , _t_search_clusters_encoding(nullptr)
105 , _t_search_clusters_map_iter(nullptr)
106 , _t_track_propagation(nullptr)
107 , _t_full_fitting(nullptr)
108 , _t_output_io(nullptr)
110 , _nlayers_seeding(nlayers_seeding)
111 , _min_nlayers_seeding(min_nlayers_seeding)
116 , _reject_ghosts(
true)
117 , _remove_hits(
false)
125 , _chi2_cut_fast_par0(10.0)
126 , _chi2_cut_fast_par1(50.0)
127 , _chi2_cut_fast_max(75.0)
128 , _chi2_cut_full(5.0)
130 , _cos_angle_cut(0.985)
133 , _min_combo_hits(min_nlayers_seeding)
134 , _max_combo_hits(nlayers_seeding * 4)
135 , _pt_rescale(0.9972 / 1.00117)
137 _fit_error_scale(_nlayers_seeding, 1.0 / sqrt(12.0))
138 , _vote_error_scale(_nlayers_seeding, 1.0)
139 , _layer_ilayer_map()
146 , _tracker_vertex(nullptr)
147 , _tracker_etap_seed(nullptr)
148 , _tracker_etam_seed(nullptr)
150 , _bbc_vertexes(nullptr)
151 , _hit_used_map(nullptr)
152 , _hit_used_map_size(0)
153 , _geom_container_intt(nullptr)
154 , _geom_container_maps(nullptr)
155 , _analyzing_mode(
false)
156 , _analyzing_file(nullptr)
157 , _analyzing_ntuple(nullptr)
158 , _max_merging_dphi(0.1)
159 , _max_merging_deta(0.1)
160 , _max_merging_dr(0.1)
161 , _max_merging_dz(0.1)
164 , _nlayers_maps(nlayers_maps)
165 , _nlayers_intt(nlayers_intt)
166 , _nlayers_tpc(nlayers_tpc)
167 , _nlayers_all(_nlayers_maps + _nlayers_intt + _nlayers_tpc)
168 , _layer_ilayer_map_all()
176 for (
unsigned int i = _nlayers_maps; i < _nlayers_maps +
_nlayers_intt; ++i)
182 int seeding_layers[] = {
184 ninner_layer + incr_layer * 1,
185 ninner_layer + incr_layer * 2,
186 ninner_layer + incr_layer * 3,
187 ninner_layer + incr_layer * 4,
188 ninner_layer + incr_layer * 5,
197 cout <<
"Ana Mode, creating ntuples! " << endl;
199 _analyzing_ntuple =
new TNtuple(
"ana_nt",
"ana_nt",
"pt:kappa:d:phi:dzdl:z0:nhit:ml:rec:dt");
200 cout <<
"Done" << endl;
217 int seeding_layers[] = {
239 int seeding_layers[] = {
318 <<
"====================== PHHoughSeeding::InitRun() ======================"
320 cout <<
" Magnetic field set to: " <<
_magField <<
" Tesla" << endl;
324 cout <<
" Tracking layer #" << i <<
" "
329 cout <<
" Tracking layer #" << i <<
" "
330 <<
"vote error scale = "
332 <<
"fit error scale = "
336 cout <<
" Minimum pT: " <<
_min_pt << endl;
337 cout <<
" Fast fit chisq cut min(par0+par1/pt,max): min( "
340 cout <<
" Maximum chisq (kalman fit): " <<
_chi2_cut_full << endl;
341 cout <<
" Cell automaton chisq: " <<
_ca_chi2_cut << endl;
344 << noboolalpha << endl;
345 cout <<
" Hit removal: " << boolalpha <<
_remove_hits << noboolalpha
347 cout <<
" Maximum DCA: " << boolalpha <<
_cut_on_dca << noboolalpha
351 cout <<
" Maximum DCA cut: " <<
_dcaxy_cut << endl;
353 cout <<
" Maximum DCAZ cut: " <<
_dcaz_cut << endl;
354 cout <<
" Phi bin scale: " <<
_bin_scale << endl;
356 cout <<
" Momentum rescale factor: " <<
_pt_rescale << endl;
358 <<
"==========================================================================="
369 cout <<
"PHHoughSeeding::process_event -- entered" << endl;
413 for(
unsigned int ivert = 0; ivert <
_vertex.size(); ++ivert)
421 if(
Verbosity() > 1) cout <<
"Call full_track_seeding for ivert = " << ivert <<
" at Z = " <<
_vertex[ivert][2] << endl;
453 std::cout <<
"=============== PHHoughSeeding::print_timers: ===============" << std::endl;
470 std::cout <<
"=======================================" << std::endl;
502 cout <<
" cleaning up " << endl;
550 map<float, int> radius_layer_map;
561 layeriter != layerrange.second; ++layeriter)
563 radius_layer_map.insert(
564 make_pair(layeriter->second->get_radius(),
565 layeriter->second->get_layer()));
573 laddergeos->get_begin_end();
576 layeriter != layerrange.second; ++layeriter)
578 radius_layer_map.insert(
579 make_pair(layeriter->second->get_radius(),
580 layeriter->second->get_layer()));
588 mapsladdergeos->get_begin_end();
591 layeriter != layerrange.second; ++layeriter)
593 radius_layer_map.insert(
594 make_pair(layeriter->second->get_radius(),
595 layeriter->second->get_layer()));
601 for (map<float, int>::const_iterator iter = radius_layer_map.begin();
602 iter != radius_layer_map.end(); ++iter) {
612 for (map<float, int>::iterator iter = radius_layer_map.begin();
613 iter != radius_layer_map.end(); ++iter)
640 for (; miter != begin_end.second; miter++)
664 laddergeos->get_begin_end();
666 for (; miter != begin_end.second; miter++)
688 mapsladdergeos->get_begin_end();
690 for (; miter != begin_end.second; miter++)
713 map<int, float>::iterator mat_it;
779 std::vector<unsigned int> onezoom(5, 0);
780 std::vector<vector<unsigned int> > zoomprofile;
781 zoomprofile.assign(5, onezoom);
782 zoomprofile[0][0] = 16;
783 zoomprofile[0][1] = 1;
784 zoomprofile[0][2] = 4;
785 zoomprofile[0][3] = 8;
786 zoomprofile[0][4] = 1;
788 zoomprofile[1][0] = 16;
789 zoomprofile[1][1] = 1;
790 zoomprofile[1][2] = 4;
791 zoomprofile[1][3] = 4;
792 zoomprofile[1][4] = 2;
794 zoomprofile[2][0] = 4;
795 zoomprofile[2][1] = 3;
796 zoomprofile[2][2] = 2;
797 zoomprofile[2][3] = 1;
798 zoomprofile[2][4] = 3;
800 for (
unsigned int i = 2; i <= 3; ++i)
802 zoomprofile[i][0] = 3;
803 zoomprofile[i][1] = 3;
804 zoomprofile[i][2] = 3;
805 zoomprofile[i][3] = 3;
806 zoomprofile[i][4] = 3;
840 float scale = scale1 / scale2;
878 float scale = scale1 / scale2;
905 vector<unsigned int> onezoom(5, 0);
906 vector<vector<unsigned int> > zoomprofile;
907 zoomprofile.assign(5, onezoom);
908 zoomprofile[0][0] = 16;
909 zoomprofile[0][1] = 1;
910 zoomprofile[0][2] = 4;
911 zoomprofile[0][3] = 8;
912 zoomprofile[0][4] = 1;
914 zoomprofile[1][0] = 16;
915 zoomprofile[1][1] = 1;
916 zoomprofile[1][2] = 4;
917 zoomprofile[1][3] = 4;
918 zoomprofile[1][4] = 2;
920 zoomprofile[2][0] = 4;
921 zoomprofile[2][1] = 3;
922 zoomprofile[2][2] = 2;
923 zoomprofile[2][3] = 1;
924 zoomprofile[2][4] = 3;
926 for (
unsigned int i = 2; i <= 3; ++i)
928 zoomprofile[i][0] = 3;
929 zoomprofile[i][1] = 3;
930 zoomprofile[i][2] = 3;
931 zoomprofile[i][3] = 3;
932 zoomprofile[i][4] = 3;
960 float scale = scale1 / scale2;
982 vector<unsigned int> onezoom(5, 0);
983 vector<vector<unsigned int> > zoomprofile;
984 zoomprofile.assign(5, onezoom);
985 zoomprofile[0][0] = 16;
986 zoomprofile[0][1] = 1;
987 zoomprofile[0][2] = 4;
988 zoomprofile[0][3] = 8;
989 zoomprofile[0][4] = 1;
991 zoomprofile[1][0] = 16;
992 zoomprofile[1][1] = 1;
993 zoomprofile[1][2] = 4;
994 zoomprofile[1][3] = 4;
995 zoomprofile[1][4] = 2;
997 zoomprofile[2][0] = 4;
998 zoomprofile[2][1] = 3;
999 zoomprofile[2][2] = 2;
1000 zoomprofile[2][3] = 1;
1001 zoomprofile[2][4] = 3;
1003 for (
unsigned int i = 2; i <= 3; ++i)
1005 zoomprofile[i][0] = 3;
1006 zoomprofile[i][1] = 3;
1007 zoomprofile[i][2] = 3;
1008 zoomprofile[i][3] = 3;
1009 zoomprofile[i][4] = 3;
1041 float scale = scale1 / scale2;
1055 _bbc_vertexes = findNode::getClass<BbcVertexMap>(topNode,
"BbcVertexMap");
1085 for (
int i = 0; i < 60; i++)
1094 unsigned int clusid = -1;
1097 for (
auto hitsetitr = hitsetrange.first;
1098 hitsetitr != hitsetrange.second;
1101 for(
auto clusIter = range.first; clusIter != range.second; ++clusIter ){
1111 unsigned int ilayer = UINT_MAX;
1114 ilayer = it->second;
1128 cout <<
" found in seeding layer # " << ilayer <<
" layer " << layer_tmp <<
" cluskey " << cluster->
getClusKey() <<
" clusid " << clusid << endl;
1138 for (
int i = 0; i < 3; ++i)
1140 for (
int j = i; j < 3; ++j)
1163 <<
"-------------------------------------------------------------------"
1166 <<
"PHHoughSeeding::process_event has the following input clusters:"
1169 cout <<
" _clusters.size = " <<
_clusters.size() << endl;
1171 for (
unsigned int i = 0; i <
_clusters.size(); ++i)
1173 cout <<
"n init clusters = " <<
_clusters.size() << endl;
1178 <<
"-------------------------------------------------------------------"
1184 cout <<
"CPUSCALE hits: " << count << endl;
1188 for (
int i = 0; i < 60; i++)
1190 cout <<
"layer: " << i <<
" << hits: " << nhits[i] <<
" | " << nhits_all[i] << endl;
1210 cout <<
" initial bbc vertex guess: " <<
_vertex[0][0] <<
" "
1411 if(svtx_vtx->
get_z() < -30.0 || svtx_vtx->
get_z() > 30.0)
1414 std::vector<float> this_vertex_pos;
1415 this_vertex_pos.assign(3,0.0);
1416 this_vertex_pos[0] = svtx_vtx->
get_x();
1417 this_vertex_pos[1] = svtx_vtx->
get_y();
1418 this_vertex_pos[2] = svtx_vtx->
get_z();
1420 std::vector<float> this_vertex_error;
1421 this_vertex_error.assign(3,0.0);
1422 this_vertex_error[0] = sqrt(svtx_vtx->
get_error(0,0));
1423 this_vertex_error[1] = sqrt(svtx_vtx->
get_error(1,1));
1424 this_vertex_error[2] = sqrt(svtx_vtx->
get_error(2,2));
1426 _vertex.push_back(this_vertex_pos);
1435 cout << endl <<
PHWHERE <<
"Do not have a valid vertex, skip track seeding for this event " << endl << endl;
1443 if(
Verbosity() > 10) cout <<
"Entering full_track_seeding with ivert = " << ivert << endl;
1445 float shift_dx = -
_vertex[ivert][0];
1446 float shift_dy = -
_vertex[ivert][1];
1447 float shift_dz = -
_vertex[ivert][2];
1455 std::vector<SimpleTrack3D> previous_tracks =
_tracks;
1457 std::vector<Eigen::Matrix<float, 5, 5> > previous_track_covars =
_track_covars;
1470 #ifdef _USE_ALAN_TRACK_REFITTING_
1477 cout <<
"SEEDSTUDY nafter clean: " <<
_tracks.size() << endl;
1478 for (
unsigned int tt = 0; tt <
_tracks.size(); ++tt)
1480 _tracks[tt].set_vertex_id(ivert);
1489 cout <<
" final track count: " <<
_tracks.size() << endl;
1490 #ifdef _USE_ALAN_FULL_VERTEXING_
1495 cout <<
" final vertex pre-fit: " <<
_vertex[0] - shift_dx <<
" "
1507 cout <<
" final vertex post-fit: " <<
_vertex[ivert][0] - shift_dx <<
" "
1508 <<
_vertex[ivert][1] - shift_dy <<
" " <<
_vertex[ivert][2] - shift_dz
1516 #ifdef _USE_ALAN_TRACK_REFITTING_
1521 shift_dx = -
_vertex[ivert][0];
1522 shift_dy = -
_vertex[ivert][1];
1523 shift_dz = -
_vertex[ivert][2];
1529 std::vector<SimpleTrack3D> refit_tracks;
1530 std::vector<double> refit_errors;
1531 std::vector<Eigen::Matrix<float, 5, 5> > refit_covars;
1535 cout << __LINE__ <<
": Event: " <<
_event <<
": # tracks before cleanup: " <<
_tracks.size() << endl;
1542 cout << __LINE__ <<
": Event: " <<
_event <<
": # tracks after cleanup: " <<
_tracks.size() << endl;
1545 for (
unsigned int tt = 0; tt < refit_tracks.size(); ++tt)
1547 refit_tracks[tt].set_vertex_id(ivert);
1565 previous_tracks.insert( previous_tracks.end(),
_tracks.begin(),
_tracks.end() );
1573 previous_tracks.clear();
1574 previous_track_errors.clear();
1575 previous_track_covars.clear();
1579 cout <<
"Leaving full_track_seeding with ivert = " << ivert <<
" _tracks.size() = " <<
_tracks.size() <<
" list of tracks:" << endl;
1580 for(
unsigned int itrack = 0; itrack <
_tracks.size(); ++itrack)
1582 cout <<
" trackid " << itrack <<
" vertexid " <<
_tracks[itrack].vertex_id << endl;
1610 for(
unsigned int ivert = 0; ivert <
_vertex.size(); ++ivert)
1612 if(
Verbosity() > 10) cout <<
PHWHERE <<
"processing vertex " << ivert << endl;
1616 for (
int i = 0; i < 3; ++i)
1633 vector<SimpleHit3D> track_hits;
1639 for (
unsigned int itrack = 0; itrack <
_all_tracks.size(); itrack++)
1645 if(
Verbosity() > 10) cout <<
PHWHERE <<
" processing track " << itrack << endl;
1653 for (
unsigned int ihit = 0;
ihit < track_hits.size();
ihit++)
1661 clusterkey = track_hits.at(
ihit).get_cluskey();
1671 <<
": itrack: " << itrack
1672 <<
": nhits: " << track_hits.size()
1673 <<
": cluster key: " << clusterkey
1698 float x_center = cos(phi) * (d + 1 / kappa);
1699 float y_center = sin(phi) * (d + 1 / kappa);
1703 if ((track_hits[0].get_x() - x_center) * (track_hits[track_hits.size() - 1].get_y() - y_center) - (track_hits[0].get_y() - y_center) * (track_hits[track_hits.size() - 1].get_x() - x_center) > 0)
1714 pZ = pT * dzdl / sqrt(1.0 - dzdl * dzdl);
1716 int ndf = 2 *
_all_tracks.at(itrack).hits.size() - 5;
1719 track.
set_px(pT * cos(phi - helicity *
M_PI / 2));
1720 track.
set_py(pT * sin(phi - helicity *
M_PI / 2));
1735 Eigen::Matrix<float, 6, 6> euclidean_cov =
1736 Eigen::Matrix<float, 6, 6>::Zero(6, 6);
1740 for (
unsigned int row = 0; row < 6; ++row)
1742 for (
unsigned int col = 0;
col < 6; ++
col)
1755 <<
": itrack: " << itrack
1756 <<
": nhits: " << track_hits.size()
1765 cout <<
"track " << itrack <<
" quality = " << track.
get_quality()
1767 cout <<
"px = " << track.
get_px() <<
" py = " << track.
get_py()
1768 <<
" pz = " << track.
get_pz() << endl;
1773 if(
Verbosity() > 2) cout <<
" adding vertex " << ivert <<
" to node tree" << endl;
1791 cout <<
"PHHoughSeeding::process_event -- leaving process_event"
1817 float phi,
float d,
float kappa,
float ,
float dzdl,
1818 Eigen::Matrix<float, 5, 5>
const& input,
1819 Eigen::Matrix<float, 6, 6>& output)
1821 Eigen::Matrix<float, 6, 5> J = Eigen::Matrix<float, 6, 5>::Zero(6, 5);
1827 float nu = sqrt(kappa);
1828 float dk_dnu = 2 * nu;
1830 float cosphi = cos(phi);
1831 float sinphi = sin(phi);
1833 J(0, 0) = -sinphi *
d;
1835 J(1, 0) = d * cosphi;
1839 float pt = 0.003 * B / kappa;
1840 float dpt_dk = -0.003 * B / (kappa * kappa);
1842 J(3, 0) = -cosphi *
pt;
1843 J(3, 2) = -sinphi * dpt_dk * dk_dnu;
1844 J(4, 0) = -sinphi *
pt;
1845 J(4, 2) = cosphi * dpt_dk * dk_dnu;
1848 float alpha_half = pow(alpha, 0.5);
1849 float alpha_3_half = alpha * alpha_half;
1851 J(5, 2) = dpt_dk * dzdl * alpha_half * dk_dnu;
1852 J(5, 4) = pt * (alpha_half + dzdl * dzdl * alpha_3_half) * dk_dnu;
1854 output = J * input * (J.transpose());
1858 double dz,
int ivertex)
1861 for (
unsigned int ht = 0; ht <
_clusters.size(); ++ht)
1868 for (
unsigned int tt = 0; tt <
_tracks.size(); ++tt)
1870 for (
unsigned int hh = 0;
hh <
_tracks[tt].hits.size(); ++
hh)
1889 std::vector<SimpleTrack3D> _tracks_cleanup;
1890 _tracks_cleanup.clear();
1894 cout << __LINE__ <<
": Event: " <<
_event <<
": # tracks before cleanup: " <<
_tracks.size() << endl;
1907 typedef std::tuple<int, int, int, int> KeyType;
1908 typedef std::multimap<KeyType, unsigned int> MapKeyTrkID;
1910 std::set<KeyType> keys;
1911 std::vector<bool> v_track_used;
1912 MapKeyTrkID m_key_itrack;
1914 typedef std::set<unsigned int> TrackList;
1916 std::set<unsigned int> OutputList;
1917 std::multimap<int, unsigned int> hitIdTrackList;
1919 unsigned int max_hit_id = 0;
1922 std::vector<bool> good_track;
1924 for (
unsigned int itrack = 0; itrack <
_tracks.size(); ++itrack)
1926 good_track.push_back(
true);
1930 hitIdTrackList.insert(std::make_pair(hit.
get_id(), itrack));
1931 if (hit.
get_id() > max_hit_id) max_hit_id = hit.
get_id();
1936 for (
unsigned int itrack = 0; itrack <
_tracks.size(); ++itrack)
1938 if (good_track[itrack] ==
false)
continue;
1939 if (OutputList.count(itrack) > 0)
continue;
1943 int trackid_max_nhit = itrack;
1944 unsigned int max_nhit = track.
hits.size();
1945 int onhit = track.
hits.size();
1950 int nmatch = hitIdTrackList.count(hit.
get_id());
1953 multimap<int, unsigned int>::iterator
it = hitIdTrackList.find(hit.
get_id());
1955 for (; it != hitIdTrackList.end(); ++
it)
1957 unsigned int match_trackid = (*it).second;
1958 if (match_trackid == itrack)
continue;
1959 if (good_track[match_trackid] ==
false)
continue;
1960 tList.insert(match_trackid);
1969 TrackList mergeList;
1970 for (
unsigned int match : tList)
1973 if (match == itrack)
continue;
1974 if (good_track[match] ==
false)
continue;
1977 int mnhit = mtrack.
hits.size();
1978 std::set<unsigned int> HitList;
1983 int sumnhit = HitList.size();
1984 if (sumnhit < (onhit + mnhit - 3))
1989 if (sumnhit != onhit)
1991 mergeList.insert(match);
1999 std::set<unsigned int> MergedHitList;
2000 if (mergeList.size() == 0)
2005 for (
unsigned int match : mergeList)
2007 if (match == itrack)
continue;
2008 if (good_track[match] ==
false)
continue;
2014 if (mtrack.
hits.size() > max_nhit)
2016 max_nhit = mtrack.
hits.size();
2017 trackid_max_nhit = match;
2018 good_track[itrack] =
false;
2022 good_track[match] =
false;
2035 if (OutputList.count(trackid_max_nhit) == 0)
2037 _tracks_cleanup.push_back(
_tracks[trackid_max_nhit]);
2044 OutputList.insert(trackid_max_nhit);
2046 _tracks_cleanup.back().hits.clear();
2048 for (
unsigned int hitID : MergedHitList)
2052 _tracks_cleanup.back().hits.push_back(hit);
2071 cout << __LINE__ <<
": Event: " <<
_event << endl;
2072 cout <<
": # tracks after cleanup: " <<
_tracks.size() <<
" ol:" << OutputList.size() << endl;
2080 std::vector<SimpleTrack3D> _tracks_cleanup;
2081 _tracks_cleanup.clear();
2085 cout << __LINE__ <<
": Event: " <<
_event <<
": # tracks before cleanup: " <<
_tracks.size() << endl;
2088 std::vector<double> _track_errors_cleanup;
2089 _track_errors_cleanup.clear();
2090 std::vector<Eigen::Matrix<float, 5, 5> > _track_covars_cleanup;
2091 _track_covars_cleanup.clear();
2093 std::vector<HelixKalmanState> _kalman_states_cleanup;
2094 _kalman_states_cleanup.clear();
2096 typedef std::tuple<int, int, int, int> KeyType;
2097 typedef std::multimap<KeyType, unsigned int> MapKeyTrkID;
2099 std::set<KeyType> keys;
2100 std::vector<bool> v_track_used;
2101 MapKeyTrkID m_key_itrack;
2103 typedef std::set<unsigned int> TrackList;
2105 std::set<unsigned int> OutputList;
2106 std::multimap<int, unsigned int> hitIdTrackList;
2108 unsigned int max_hit_id = 0;
2111 std::vector<bool> good_track;
2113 for (
unsigned int itrack = 0; itrack <
_tracks.size(); ++itrack)
2115 good_track.push_back(
true);
2119 hitIdTrackList.insert(std::make_pair(hit.
get_id(), itrack));
2120 if (hit.
get_id() > max_hit_id) max_hit_id = hit.
get_id();
2125 for (
unsigned int itrack = 0; itrack <
_tracks.size(); ++itrack)
2127 if (good_track[itrack] ==
false)
continue;
2128 if (OutputList.count(itrack) > 0)
continue;
2132 int trackid_max_nhit = itrack;
2133 unsigned int max_nhit = track.
hits.size();
2134 int onhit = track.
hits.size();
2139 int nmatch = hitIdTrackList.count(hit.
get_id());
2142 multimap<int, unsigned int>::iterator
it = hitIdTrackList.find(hit.
get_id());
2144 for (; it != hitIdTrackList.end(); ++
it)
2146 unsigned int match_trackid = (*it).second;
2147 if (match_trackid == itrack)
continue;
2148 if (good_track[match_trackid] ==
false)
continue;
2149 tList.insert(match_trackid);
2158 TrackList mergeList;
2159 for (
unsigned int match : tList)
2162 if (match == itrack)
continue;
2163 if (good_track[match] ==
false)
continue;
2166 int mnhit = mtrack.
hits.size();
2167 std::set<unsigned int> HitList;
2172 int sumnhit = HitList.size();
2173 if (sumnhit < (onhit + mnhit - 3))
2178 if (sumnhit != onhit)
2180 mergeList.insert(match);
2188 std::set<unsigned int> MergedHitList;
2189 if (mergeList.size() == 0)
2194 for (
unsigned int match : mergeList)
2196 if (match == itrack)
continue;
2197 if (good_track[match] ==
false)
continue;
2203 if (mtrack.
hits.size() > max_nhit)
2205 max_nhit = mtrack.
hits.size();
2206 trackid_max_nhit = match;
2207 good_track[itrack] =
false;
2211 good_track[match] =
false;
2224 if (OutputList.count(trackid_max_nhit) == 0)
2226 _tracks_cleanup.push_back(
_tracks[trackid_max_nhit]);
2232 OutputList.insert(trackid_max_nhit);
2234 _tracks_cleanup.back().hits.clear();
2236 for (
unsigned int hitID : MergedHitList)
2240 _tracks_cleanup.back().hits.push_back(hit);
2252 for (
auto& kstate : _kalman_states_cleanup)
2259 cout << __LINE__ <<
": Event: " <<
_event << endl;
2260 cout <<
": # tracks after cleanup: " <<
_tracks.size() <<
" ol:" << OutputList.size() << endl;
2268 std::vector<SimpleTrack3D> _tracks_cleanup;
2269 _tracks_cleanup.clear();
2271 typedef std::tuple<int, int, int, int> KeyType;
2272 typedef std::multimap<KeyType, unsigned int> MapKeyTrkID;
2274 std::set<KeyType> keys;
2275 std::vector<bool> v_track_used;
2276 MapKeyTrkID m_key_itrack;
2279 cout << __LINE__ <<
": CleanupSeeds: Event: " <<
_event << endl;
2282 for (
unsigned int itrack = 0; itrack <
_tracks.size(); ++itrack)
2299 KeyType key = std::make_tuple(
id, iz, iphi, idzdl);
2302 m_key_itrack.insert(
2306 v_track_used.push_back(
false);
2310 for (
auto it = m_key_itrack.begin();
2311 it != m_key_itrack.end();
2314 KeyType key =
it->first;
2315 unsigned int itrack =
it->second;
2317 int id = std::get<0>(key);
2318 int iz = std::get<1>(key);
2319 int iphi = std::get<2>(key);
2320 int idzdl = std::get<3>(key);
2324 cout << __LINE__ << endl;
2325 printf(
"itrack: %5u => {%5d, %5d, %5d, %5d} \n",
2327 id, iz, iphi, idzdl);
2331 for (KeyType key : keys)
2333 unsigned int itrack = m_key_itrack.equal_range(key).first->second;
2336 cout <<
"---------------------------------------------------\n";
2337 cout << __LINE__ <<
": processing: " << itrack << endl;
2338 cout <<
"---------------------------------------------------\n";
2341 if (v_track_used[itrack] ==
true)
2344 cout << __LINE__ <<
": itrack: " << itrack <<
": {";
2346 std::set<unsigned int> hitIDs;
2349 hitIDs.insert(hit.get_id());
2351 cout << hit.get_id() <<
", ";
2355 cout <<
"}" << endl;
2359 std::vector<unsigned int> v_related_tracks;
2360 for (
int id = std::get<0>(key) - 1; id <= std::get<0>(key) + 1;
2363 for (
int iz = std::get<1>(key) - 1;
2364 iz <= std::get<1>(key) + 1; ++iz)
2366 for (
int iphi = std::get<2>(key) - 1;
2367 iphi <= std::get<2>(key) + 1; ++iphi)
2369 for (
int idzdl = std::get<3>(key) - 1;
2370 idzdl <= std::get<3>(key) + 1; ++idzdl)
2372 KeyType key_temp = std::make_tuple(
id, iz, iphi, idzdl);
2374 if (m_key_itrack.find(key_temp) != m_key_itrack.end())
2377 m_key_itrack.equal_range(key_temp).first;
2378 it != m_key_itrack.equal_range(
2383 if (
it->second == itrack)
2386 unsigned int share_hits = 0;
2389 unsigned int hitID = hit.get_id();
2393 hitID) != hitIDs.end())
2398 v_related_tracks.push_back(
it->second);
2400 cout << __LINE__ <<
": rel track: " <<
it->second <<
": {";
2403 cout << hit_3d.get_id() <<
", ";
2405 cout <<
"}" << endl;
2425 if (v_related_tracks.size() == 0)
2427 _tracks_cleanup.push_back(
_tracks[itrack]);
2431 _tracks_cleanup.push_back(
_tracks[itrack]);
2433 _tracks_cleanup.back().hits.clear();
2436 int n_merge_track = 1;
2437 cout << __LINE__ <<
": nclusters before merge: " << hitIDs.size() << endl;
2442 for (
unsigned int irel : v_related_tracks)
2444 if (v_track_used[irel] ==
true)
continue;
2453 #ifdef _MEARGE_SEED_CLUSTER_
2457 hitIDs.insert(hit.
get_id());
2460 v_track_used[irel] =
true;
2464 cout << __LINE__ <<
": # tracks merged: " << n_merge_track << endl;
2467 for (
unsigned int hitID : hitIDs)
2472 cout << hitID <<
", ";
2474 _tracks_cleanup.back().hits.push_back(hit);
2477 cout <<
"}" << endl;
2478 cout << __LINE__ <<
": nclusters after merge: " << hitIDs.size() << endl;
2479 cout << __LINE__ <<
": nclusters after merge: " << _tracks_cleanup.back().hits.size() << endl;
2483 v_track_used[itrack] =
true;
2487 cout << __LINE__ <<
": Event: " <<
_event << endl;
2488 cout <<
": # tracks before cleanup: " <<
_tracks.size() << endl;
2489 cout <<
": # tracks after cleanup: " << _tracks_cleanup.size() << endl;