31 inline constexpr
T r(
const T&
x,
const T&
y)
65 m_outfile =
new TFile(
"PHCosmicSeeder.root",
"recreate");
66 m_tup =
new TNtuple(
"ntp_seed",
"seed",
67 "event:seed:nclus:xyint:xyslope:rzint:rzslope:"
68 "longestxyint:longestxyslope:longestrzint:longestrzslope");
81 for (
auto citer = range.first; citer != range.second; ++citer)
83 const auto ckey = citer->first;
84 const auto cluster = citer->second;
86 clusterPositions.insert(std::make_pair(ckey, global));
91 std::cout <<
"cluster map size is " << clusterPositions.size() << std::endl;
97 std::cout <<
"Initial seed candidate size is " << seeds.size() << std::endl;
101 {
return a.
ckeys.size() >
b.ckeys.size(); });
103 auto prunedSeeds =
combineSeeds(seeds, clusterPositions);
106 std::cout <<
"Pruned seed size is " << prunedSeeds.size() << std::endl;
108 std::sort(prunedSeeds.begin(), prunedSeeds.end(),
110 {
return a.
ckeys.size() >
b.ckeys.size(); });
115 std::cout <<
"final seeds are " << finalSeeds.size() << std::endl;
117 for (
auto& seed1 : finalSeeds)
123 auto chainedSeeds =
chainSeeds(finalSeeds, clusterPositions);
127 std::cout <<
"Total seeds found is " << chainedSeeds.size() << std::endl;
131 auto longestseedit = chainedSeeds.begin();
133 if (longestseedit != chainedSeeds.end())
135 longestseed = chainedSeeds.front();
137 for (
auto&
seed : chainedSeeds)
141 float seed_data[] = {
153 m_tup->Fill(seed_data);
155 auto svtxseed = std::make_unique<TrackSeed_v1>();
158 svtxseed->insert_cluster_key(key);
168 std::set<int> seedsToDelete;
170 for (
int i = 0;
i < initialSeeds.size(); ++
i)
172 auto& seed1 = initialSeeds[
i];
173 for (
int j =
i;
j < initialSeeds.size(); ++
j)
179 auto& seed2 = initialSeeds[
j];
180 std::vector<TrkrDefs::cluskey> intersection;
181 std::set_intersection(seed1.ckeys.begin(), seed1.ckeys.end(),
182 seed2.ckeys.begin(), seed2.ckeys.end(), std::back_inserter(intersection));
183 if (intersection.size() > 3)
187 for (
auto key : seed2.ckeys)
189 seed1.ckeys.insert(key);
191 seedsToDelete.insert(
j);
197 for (
int i = 0;
i < initialSeeds.size(); ++
i)
199 if (seedsToDelete.find(
i) != seedsToDelete.end())
203 if (initialSeeds[
i].ckeys.size() < 4)
207 finalSeeds.push_back(initialSeeds[
i]);
215 std::set<int> seedsToDelete;
216 for (
int i = 0;
i < initialSeeds.size(); ++
i)
218 auto& seed1 = initialSeeds[
i];
219 for (
int j =
i;
j < initialSeeds.size(); ++
j)
225 auto& seed2 = initialSeeds[
j];
231 float longestxyslope = seed1.xyslope;
232 float longestxyint = seed1.xyintercept;
233 float longestrzslope = seed1.rzslope;
234 float longestrzint = seed1.rzintercept;
235 if (seed1.ckeys.size() < seed2.ckeys.size())
237 longestxyint = seed2.xyintercept;
238 longestxyslope = seed2.xyslope;
239 longestrzint = seed2.rzintercept;
240 longestrzslope = seed2.rzslope;
243 float pdiff = fabs((seed1.xyslope - seed2.xyslope) / longestxyslope);
244 float pdiff2 = fabs((seed1.xyintercept - seed2.xyintercept) / longestxyint);
245 float pdiff3 = fabs((seed1.rzintercept - seed2.rzintercept) / longestrzint);
246 float pdiff4 = fabs((seed1.rzslope - seed2.rzslope) / longestrzslope);
247 if (pdiff < 1. && pdiff2 < 1. && pdiff3 < 1. && pdiff4 < 1.)
249 seedsToDelete.insert(
j);
250 for (
auto& key : seed2.ckeys)
252 seed1.ckeys.insert(key);
257 for (
int i = 0;
i < initialSeeds.size(); ++
i)
259 if (seedsToDelete.find(
i) != seedsToDelete.end())
263 returnseeds.push_back(initialSeeds[
i]);
272 std::set<int> seedsToDelete;
274 for (
int i = 0;
i < initialSeeds.size(); ++
i)
276 for (
int j =
i;
j < initialSeeds.size(); ++
j)
282 auto& seed1 = initialSeeds[
i];
283 auto& seed2 = initialSeeds[
j];
291 if (fabs(seed1.xyslope - seed2.xyslope) < 0.1 &&
292 fabs(seed1.xyintercept - seed2.xyintercept) < 3. &&
293 fabs(seed1.rzslope - seed2.rzslope) < 0.1 &&
294 fabs(seed1.rzintercept - seed2.rzintercept) < 3.)
296 for (
auto& key : seed2.ckeys)
298 seed1.ckeys.insert(key);
300 seedsToDelete.insert(
j);
306 std::cout <<
"seeds to delete size is " << seedsToDelete.size() << std::endl;
308 for (
int i = 0;
i < initialSeeds.size(); ++
i)
310 if (seedsToDelete.find(
i) != seedsToDelete.end())
314 prunedSeeds.push_back(initialSeeds[
i]);
323 std::set<TrkrDefs::cluskey> keys;
325 for (
auto& [key1, pos1] : clusterPositions)
327 for (
auto& [key2, pos2] : clusterPositions)
337 std::cout <<
"checking keys " << key1 <<
", " << key2 <<
" with dist apart " << dist << std::endl;
338 std::cout <<
"positions are " << pos1.transpose() <<
" , "
339 << pos2.transpose() << std::endl;
347 doub.
xyslope = (pos2.y() - pos1.y()) / (pos2.x() - pos1.x());
349 doub.
rzslope = (
r(pos2.x(), pos2.y()) -
r(pos1.x(), pos1.y())) / (pos2.z() - pos1.z());
356 seeds.push_back(doub);
362 std::cout <<
"odublet sizes " << seeds.size() << std::endl;
364 for (
auto& dub : seeds)
368 std::cout <<
"doublet has " << dub.ckeys.size() <<
" keys " << std::endl;
369 for (
auto key : dub.ckeys)
371 std::cout <<
"position is " << clusterPositions.find(key)->second.transpose() << std::endl;
374 auto begin = dub.ckeys.begin();
375 auto pos1 = clusterPositions.find(*(
begin))->second;
376 std::advance(
begin, 1);
377 auto pos2 = clusterPositions.find(*(
begin))->second;
379 for (
auto& [key,
pos] : clusterPositions)
382 if (std::find(dub.ckeys.begin(), dub.ckeys.end(), key) != dub.ckeys.end())
387 float dist1 = (pos1 -
pos).
norm();
388 float dist2 = (pos2 -
pos).
norm();
400 float predy = dub.xyslope *
pos.x() + dub.xyintercept;
401 float predr = dub.rzslope *
pos.z() + dub.rzintercept;
404 std::cout <<
"testing ckey " << key <<
" with box dca "
405 << predy <<
", " <<
pos.transpose() <<
" and " << predr <<
", " <<
r(
pos.x(),
pos.y())
412 std::cout <<
" adding ckey " << key <<
" with box dca "
413 << predy <<
", " <<
pos.y() <<
" and " << predr <<
", " <<
r(
pos.x(),
pos.y())
416 dub.ckeys.insert(key);
422 std::set<int> seedsToDelete;
423 for (
int i = 0;
i < seeds.size(); ++
i)
425 auto seed = seeds[
i];
428 std::cout <<
"keys in seed " << std::endl;
431 std::cout << key <<
", ";
433 std::cout << std::endl
434 <<
"seed pos " << std::endl;
437 std::cout << clusterPositions.find(key)->second.transpose() << std::endl;
439 std::cout <<
"Done printing seed info" << std::endl;
443 seedsToDelete.insert(
i);
448 for (
int i = 0;
i < seeds.size();
i++)
450 if (seedsToDelete.find(
i) != seedsToDelete.end())
454 returnSeeds.push_back(seeds[
i]);
464 for (
auto& key : seed.
ckeys)
466 auto glob = clusters.find(key)->second;
475 avgy +=
r(glob.x(), glob.y());
477 seedClusters.insert(std::make_pair(key, glob));
480 avgx /= seed.
ckeys.size();
481 avgy /= seed.
ckeys.size();
484 for (
auto& [key, glob] : seedClusters)
488 num += (glob.x() - avgx) * (glob.y() - avgy);
489 denom +=
square(glob.x() - avgx);
493 num += (glob.z() - avgx) * (
r(glob.x(), glob.y()) - avgy);
494 denom +=
square(glob.z() - avgx);
510 m_tGeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
513 std::cout <<
PHWHERE <<
"No acts reco geometry, bailing."
517 m_clusterContainer = findNode::getClass<TrkrClusterContainer>(topNode,
"TRKR_CLUSTER");
520 std::cout <<
PHWHERE <<
"No cluster container on node tree, bailing."
535 std::cerr <<
"DST node is missing, quitting" << std::endl;
536 throw std::runtime_error(
"Failed to find DST node in PHCosmicSeeder::createNodes");