Skip to content

Commit

Permalink
CalorimeterHitsMerger: fix for not being able to get pointers to obje…
Browse files Browse the repository at this point in the history
…cts in collections
  • Loading branch information
veprbl committed Jul 18, 2023
1 parent 8f6583f commit 5df061b
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/algorithms/calorimetry/CalorimeterHitsMerger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ std::unique_ptr<edm4eic::CalorimeterHitCollection> CalorimeterHitsMerger::execut
auto output = std::make_unique<edm4eic::CalorimeterHitCollection>();

// find the hits that belong to the same group (for merging)
std::unordered_map<long long, std::vector<const edm4eic::CalorimeterHit *>> merge_map;
std::unordered_map<uint64_t, std::vector<std::size_t>> merge_map;
std::size_t ix = 0;
for (const auto &h : input) {
int64_t id = h.getCellID() & id_mask;
merge_map[id].push_back(&h);
uint64_t id = h.getCellID() & id_mask;
merge_map[id].push_back(ix);

ix++;
}

// sort hits by energy from large to small
std::for_each(merge_map.begin(), merge_map.end(), [](auto &it) {
std::sort(it.second.begin(), it.second.end(), [](const auto &h1, const auto &h2) {
return h1->getEnergy() > h2->getEnergy();
std::for_each(merge_map.begin(), merge_map.end(), [&](auto &it) {
std::sort(it.second.begin(), it.second.end(), [&](std::size_t ix1, std::size_t ix2) {
return input[ix1].getEnergy() > input[ix2].getEnergy();
});
});

Expand All @@ -60,7 +63,7 @@ std::unique_ptr<edm4eic::CalorimeterHitCollection> CalorimeterHitsMerger::execut
auto poscon = m_geoSvc->cellIDPositionConverter();
auto volman = m_geoSvc->detector()->volumeManager();

for (const auto &[id, hits]: merge_map) {
for (const auto &[id, ixs] : merge_map) {
// reference fields id
const uint64_t ref_id = id | ref_mask;
// global positions
Expand All @@ -74,17 +77,18 @@ std::unique_ptr<edm4eic::CalorimeterHitCollection> CalorimeterHitsMerger::execut
float energyError = 0.;
float time = 0;
float timeError = 0;
for (auto &hit: hits) {
energy += hit->getEnergy();
energyError += hit->getEnergyError() * hit->getEnergyError();
time += hit->getTime();
timeError += hit->getTimeError() * hit->getTimeError();
for (auto ix : ixs) {
auto hit = input[ix];
energy += hit.getEnergy();
energyError += hit.getEnergyError() * hit.getEnergyError();
time += hit.getTime();
timeError += hit.getTimeError() * hit.getTimeError();
}
energyError = sqrt(energyError);
time /= hits.size();
timeError = sqrt(timeError) / hits.size();
time /= ixs.size();
timeError = sqrt(timeError) / ixs.size();

const auto &href = hits.front();
const auto href = input[ixs.front()];

// create const vectors for passing to hit initializer list
const decltype(edm4eic::CalorimeterHitData::position) position(
Expand All @@ -95,15 +99,15 @@ std::unique_ptr<edm4eic::CalorimeterHitCollection> CalorimeterHitsMerger::execut
);

output->create(
href->getCellID(),
href.getCellID(),
energy,
energyError,
time,
timeError,
position,
href->getDimension(),
href->getSector(),
href->getLayer(),
href.getDimension(),
href.getSector(),
href.getLayer(),
local); // Can do better here? Right now position is mapped on the central hit
}

Expand Down

0 comments on commit 5df061b

Please sign in to comment.