Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
bucket420 committed Jul 8, 2024
1 parent 649b683 commit 183646a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 73 deletions.
103 changes: 34 additions & 69 deletions RecoTracker/LSTCore/standalone/code/core/trkCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,30 +282,25 @@ std::vector<int> matchedSimTrkIdxs(std::vector<int> hitidxs, std::vector<int> hi


//___________________________________________________________________________________________________________________________________________________________________________________________
std::vector<int> matchedSimTrkIdxs(std::vector<unsigned int> hitidxs, std::vector<unsigned int> hittypes, bool verbose, float matchfrac)
{
std::vector<int> matchedSimTrkIdxs(std::vector<unsigned int> hitidxs, std::vector<unsigned int> hittypes, bool verbose, float matchfrac) {
std::vector<int> matched_idxs;
std::vector<float> matched_idx_fracs;
std::tie(matched_idxs, matched_idx_fracs) = matchedSimTrkIdxsAndFracs(hitidxs, hittypes, verbose, matchfrac);
return matched_idxs;
}

//___________________________________________________________________________________________________________________________________________________________________________________________
std::tuple<std::vector<int>, std::vector<float>> matchedSimTrkIdxsAndFracs(std::vector<unsigned int> hitidxs, std::vector<unsigned int> hittypes, bool verbose, float matchfrac)
{
if (hitidxs.size() != hittypes.size())
{
std::tuple<std::vector<int>, std::vector<float>> matchedSimTrkIdxsAndFracs(std::vector<unsigned int> hitidxs, std::vector<unsigned int> hittypes, bool verbose, float matchfrac) {
if (hitidxs.size() != hittypes.size()) {
std::cout << "Error: matched_sim_trk_idxs() hitidxs and hittypes have different lengths" << std::endl;
std::cout << "hitidxs.size(): " << hitidxs.size() << std::endl;
std::cout << "hittypes.size(): " << hittypes.size() << std::endl;
}

std::vector<std::pair<unsigned int, unsigned int>> to_check_duplicate;
for (int i = 0; i < hitidxs.size(); i++)
{
for (int i = 0; i < hitidxs.size(); i++) {
auto item = std::make_pair(hitidxs[i], hittypes[i]);
if (std::find(to_check_duplicate.begin(), to_check_duplicate.end(), item) == to_check_duplicate.end())
{
if (std::find(to_check_duplicate.begin(), to_check_duplicate.end(), item) == to_check_duplicate.end()) {
to_check_duplicate.push_back(item);
}
}
Expand All @@ -315,34 +310,29 @@ std::tuple<std::vector<int>, std::vector<float>> matchedSimTrkIdxsAndFracs(std::
std::vector<vector<int>> simtrk_idxs;
std::vector<int> unique_idxs; // to aggregate which ones to count and test

if (verbose)
{
if (verbose) {
std::cout << " '------------------------': "
<< "------------------------" << std::endl;
}

for (int i = 0; i < nhits_input; i++)
{
for (int i = 0; i < nhits_input; i++) {
auto hitidx = to_check_duplicate[i].first;
auto hittype = to_check_duplicate[i].second;

if (verbose)
{
if (verbose) {
std::cout << " hitidx: " << hitidx << " hittype: " << hittype << std::endl;
}

std::vector<int> simtrk_idxs_per_hit;

const std::vector<vector<int>> *simHitIdxs = hittype == 4 ? &trk.ph2_simHitIdx() : &trk.pix_simHitIdx();

if (verbose)
{
if (verbose) {
std::cout << " trk.ph2_simHitIdx().size(): " << trk.ph2_simHitIdx().size() << std::endl;
std::cout << " trk.pix_simHitIdx().size(): " << trk.pix_simHitIdx().size() << std::endl;
}

if (static_cast<const unsigned int>((*simHitIdxs).size()) <= hitidx)
{
if (static_cast<const unsigned int>((*simHitIdxs).size()) <= hitidx) {
std::cout << "ERROR" << std::endl;
std::cout << " hittype: " << hittype << std::endl;
std::cout << " trk.pix_simHitIdx().size(): " << trk.pix_simHitIdx().size() << std::endl;
Expand All @@ -351,53 +341,42 @@ std::tuple<std::vector<int>, std::vector<float>> matchedSimTrkIdxsAndFracs(std::
std::cout << hitidx << " " << hittype << std::endl;
}

for (auto &simhit_idx : (*simHitIdxs).at(hitidx))
{
if (static_cast<const int>(trk.simhit_simTrkIdx().size()) <= simhit_idx)
{
for (auto &simhit_idx : (*simHitIdxs).at(hitidx)) {
if (static_cast<const int>(trk.simhit_simTrkIdx().size()) <= simhit_idx) {
std::cout << (*simHitIdxs).size() << " " << hittype << std::endl;
std::cout << hitidx << " " << hittype << std::endl;
std::cout << trk.simhit_simTrkIdx().size() << " " << simhit_idx << std::endl;
}
int simtrk_idx = trk.simhit_simTrkIdx().at(simhit_idx);
if (verbose)
{
if (verbose) {
std::cout << " hitidx: " << hitidx << " simhit_idx: " << simhit_idx << " simtrk_idx: " << simtrk_idx << std::endl;
}
simtrk_idxs_per_hit.push_back(simtrk_idx);
if (std::find(unique_idxs.begin(), unique_idxs.end(), simtrk_idx) == unique_idxs.end()) unique_idxs.push_back(simtrk_idx);
}

if (simtrk_idxs_per_hit.size() == 0)
{
if (verbose)
{
if (simtrk_idxs_per_hit.size() == 0) {
if (verbose) {
std::cout << " hitidx: " << hitidx << " -1: " << -1 << std::endl;
}
simtrk_idxs_per_hit.push_back(-1);
if (std::find(unique_idxs.begin(), unique_idxs.end(), -1) == unique_idxs.end()) unique_idxs.push_back(-1);
}

simtrk_idxs.push_back(simtrk_idxs_per_hit);
}

if (verbose)
{
if (verbose) {
std::cout << " unique_idxs.size(): " << unique_idxs.size() << std::endl;
for (auto &unique_idx : unique_idxs)
{
for (auto &unique_idx : unique_idxs) {
std::cout << " unique_idx: " << unique_idx << std::endl;
}
}

// print
if (verbose)
{
if (verbose) {
std::cout << "va print" << std::endl;
for (auto &vec : simtrk_idxs)
{
for (auto &idx : vec)
{
for (auto &vec : simtrk_idxs) {
for (auto &idx : vec) {
std::cout << idx << " ";
}
std::cout << std::endl;
Expand All @@ -408,46 +387,38 @@ std::tuple<std::vector<int>, std::vector<float>> matchedSimTrkIdxsAndFracs(std::
// Compute all permutations
std::function<void(vector<vector<int>> &, vector<int>, size_t, vector<vector<int>> &)> perm = [&](vector<vector<int>> &result, vector<int> intermediate, size_t n, vector<vector<int>> &va) {
// std::cout << " 'called': " << "called" << std::endl;
if (va.size() > n)
{
for (auto x : va[n])
{
if (va.size() > n) {
for (auto x : va[n]) {
// std::cout << " n: " << n << std::endl;
// std::cout << " intermediate.size(): " << intermediate.size() << std::endl;
std::vector<int> copy_intermediate(intermediate);
copy_intermediate.push_back(x);
perm(result, copy_intermediate, n + 1, va);
}
}
else
{
else {
result.push_back(intermediate);
}
};

vector<vector<int>> allperms;
perm(allperms, vector<int>(), 0, simtrk_idxs);

if (verbose)
{
if (verbose) {
std::cout << " allperms.size(): " << allperms.size() << std::endl;
for (unsigned iperm = 0; iperm < allperms.size(); ++iperm)
{
for (unsigned iperm = 0; iperm < allperms.size(); ++iperm) {
std::cout << " allperms[iperm].size(): " << allperms[iperm].size() << std::endl;
for (unsigned ielem = 0; ielem < allperms[iperm].size(); ++ielem)
{
for (unsigned ielem = 0; ielem < allperms[iperm].size(); ++ielem) {
std::cout << " allperms[iperm][ielem]: " << allperms[iperm][ielem] << std::endl;
}
}
}
int maxHitMatchCount = 0; // ultimate maximum of the number of matched hits
std::vector<int> matched_sim_trk_idxs;
std::vector<float> matched_sim_trk_idxs_frac;
for (auto &trkidx_perm : allperms)
{
for (auto &trkidx_perm : allperms) {
std::vector<int> counts;
for (auto &unique_idx : unique_idxs)
{
for (auto &unique_idx : unique_idxs) {
int cnt = std::count(trkidx_perm.begin(), trkidx_perm.end(), unique_idx);
counts.push_back(cnt);
}
Expand All @@ -457,32 +428,27 @@ std::tuple<std::vector<int>, std::vector<float>> matchedSimTrkIdxsAndFracs(std::
if (trkidx < 0) continue;
// std::cout << " counts[rawidx]: " << counts[rawidx] << std::endl;
// std::cout << " nhits_input: " << nhits_input << std::endl;
if (verbose)
{
if (verbose) {
float fr = ((float)counts[rawidx]) / ((float)nhits_input);
std::cout << " fr: " << fr << std::endl;
}
// std::cout << " matchfrac: " << matchfrac << std::endl;
if (counts[rawidx] > (((float)nhits_input) * matchfrac))
{
if (counts[rawidx] > (((float)nhits_input) * matchfrac)) {
matched_sim_trk_idxs.push_back(trkidx);
matched_sim_trk_idxs_frac.push_back( ((float)counts[rawidx]) / ((float)nhits_input) );
}
maxHitMatchCount = std::max(maxHitMatchCount, *std::max_element(counts.begin(), counts.end()));
}
map<int, float> pairs;
unsigned size = matched_sim_trk_idxs.size();
for (unsigned i = 0; i < size; ++i)
{
for (unsigned i = 0; i < size; ++i) {
int idx = matched_sim_trk_idxs[i];
float frac = matched_sim_trk_idxs_frac[i];
if (pairs.find(idx) != pairs.end())
{
if (pairs.find(idx) != pairs.end()) {
if (pairs[idx] < frac)
pairs[idx] = frac;
}
else
{
else {
pairs[idx] = frac;
}
// if (std::find(result.begin(), result.end(), idx) == result.end())
Expand All @@ -496,8 +462,7 @@ std::tuple<std::vector<int>, std::vector<float>> matchedSimTrkIdxsAndFracs(std::
vector<float> result_frac;

// Loop over the map using range-based for loop
for (const auto& pair : pairs)
{
for (const auto& pair : pairs) {
result.push_back(pair.first);
result_frac.push_back(pair.second);
}
Expand Down
6 changes: 2 additions & 4 deletions RecoTracker/LSTCore/standalone/code/core/write_sdl_ntuple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,9 @@ void setTripletOutputBranches(SDL::Event<SDL::Acc>* event) {
SDL::tripletsBuffer<alpaka::DevCpu>& tripletsInGPU = (*event->getTriplets());
SDL::objectRangesBuffer<alpaka::DevCpu>& rangesInGPU = (*event->getRanges());
SDL::modulesBuffer<alpaka::DevCpu>& modulesInGPU = (*event->getModules());
for (unsigned int lowerModuleIdx = 0; lowerModuleIdx < *(modulesInGPU.nLowerModules); ++lowerModuleIdx)
{
for (unsigned int lowerModuleIdx = 0; lowerModuleIdx < *(modulesInGPU.nLowerModules); ++lowerModuleIdx) {
unsigned int nTriplets = tripletsInGPU.nTriplets[lowerModuleIdx];
for (unsigned int idx = 0; idx < nTriplets; idx++)
{
for (unsigned int idx = 0; idx < nTriplets; idx++) {
unsigned int tripletIndex = rangesInGPU.tripletModuleIndices[lowerModuleIdx] + idx;

const float residual = tripletsInGPU.residual[tripletIndex];
Expand Down

0 comments on commit 183646a

Please sign in to comment.