225 using clock_type = boost::chrono::thread_clock;
226 auto time_cast = [](
const auto & before,
const auto & after)
228 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
235 if ( !cell_collection.isValid() )
237 ATH_MSG_ERROR(
" Cannot retrieve CaloCellContainer: " << cell_collection.name() );
238 return StatusCode::FAILURE;
246 ed.returnClusterNumberToCPU();
252 ed.returnSomeClustersToCPU(ed.m_clusters->number);
254 std::vector<std::unique_ptr<CaloClusterCellLink>> cell_links;
256 cell_links.reserve(ed.m_clusters->number);
262 ed.returnCellsToCPU();
264 for (
int i = 0;
i < ed.m_clusters->number; ++
i)
266 if (ed.m_clusters->seedCellID[
i] >= 0)
268 cell_links.emplace_back(std::make_unique<CaloClusterCellLink>(cell_collection_link));
269 cell_links.back()->reserve(256);
274 cell_links.emplace_back(
nullptr);
279 std::vector<float> HV_energy(ed.m_clusters->number *
m_doHVMoments, 0.f);
280 std::vector<int> HV_number(ed.m_clusters->number *
m_doHVMoments, 0 );
282 const LArOnOffIdMapping *
cabling =
nullptr;
290 hvcorr = *hvScaleHdl;
297 ed.returnSomeMomentsToCPU(ed.m_clusters->number);
301 const auto process_cell = [&](
const int cell_index,
const int cell_count)
303 const ClusterTag this_tag = ed.m_cell_state->clusterTag[cell_index];
311 std::memcpy(&tempf, &weight_pattern,
sizeof(
float));
316 const float reverse_weight = tempf;
318 const float this_weight = 1.0f - reverse_weight;
320 if (cell_links[this_index])
322 cell_links[this_index]->addCell(cell_count, this_weight);
324 if (cell_index == ed.m_clusters->seedCellID[this_index] && cell_links[this_index]->size() > 1)
331 const unsigned int first_idx = begin_it.
index();
332 const double first_wgt = begin_it.
weight();
349 if (cell_links[other_index])
351 cell_links[other_index]->addCell(cell_count, reverse_weight);
357 HWIdentifier hwid =
cabling->createSignalChannelIDFromHash((IdentifierHash) cell_index);
361 const float abs_energy = fabsf(ed.m_cell_info->energy[cell_index]);
362 HV_energy[this_index] += abs_energy;
363 ++HV_number[this_index];
367 HV_energy[other_index] += abs_energy;
368 ++HV_number[other_index];
375 if (cell_collection->isOrderedAndComplete())
378 for (
int cell_index = 0; cell_index <
NCaloCells; ++cell_index)
380 process_cell(cell_index, cell_index);
385 size_t missing_cell_count = 0;
386 for (
int cell_index = 0; cell_index <
NCaloCells; ++cell_index)
390 ++missing_cell_count;
393 process_cell(cell_index, cell_index - missing_cell_count);
401 for (
int cell_count = 0; iCells != cell_collection->end(); ++iCells, ++cell_count)
406 const int cell_index =
cell->caloDDE()->calo_hash();
408 process_cell(cell_index, cell_count);
414 std::vector<int> cluster_order(ed.m_clusters->number);
416 std::iota(cluster_order.begin(), cluster_order.end(), 0);
418 std::sort(cluster_order.begin(), cluster_order.end(), [&](
const int a,
const int b) ->
bool
420 const bool a_valid = ed.m_clusters->seedCellID[a] >= 0;
421 const bool b_valid = ed.m_clusters->seedCellID[b] >= 0;
422 if (a_valid && b_valid)
424 return ed.m_clusters->clusterEt[a]
425 > ed.m_clusters->clusterEt[b];
450 cluster_container->clear();
451 cluster_container->reserve(cell_links.size());
453 std::vector<int> real_cluster_order;
454 real_cluster_order.reserve(cluster_order.size());
456 for (
size_t i = 0;
i < cluster_order.size(); ++
i)
458 const int cluster_index = cluster_order[
i];
460 if (cell_links[cluster_index] !=
nullptr && cell_links[cluster_index]->
size() > 0)
463 cluster_container->push_back(cluster);
468 cluster->setEta(ed.m_clusters->clusterEta[cluster_index]);
469 cluster->setPhi(ed.m_clusters->clusterPhi[cluster_index]);
471 cluster->setE(ed.m_clusters->clusterEnergy[cluster_index]);
483 real_cluster_order.push_back(cluster_index);
495 for (
size_t i = 0;
i < cluster_container->size(); ++
i)
498 const int cluster_index = real_cluster_order[
i];
500 cluster->setTime(ed.m_moments->time[cluster_index]);
501 cluster->setSecondTime(ed.m_moments->secondTime[cluster_index]);
507 const int cells_per_sampling = ed.m_moments->nCellSampling[sampl][cluster_index];
509 if (cells_per_sampling > 0)
511 sampling_pattern |= (0x1U << sampl);
514 cluster->setSamplingPattern(sampling_pattern);
518 const int cells_per_sampling = ed.m_moments->nCellSampling[sampl][cluster_index];
520 if (cells_per_sampling > 0)
536 #define CALORECGPU_MOMENTS_CONVERSION_HELPER(MOMENT_ENUM, MOMENT_ARRAY) \
537 if (m_momentsToDo[xAOD::CaloCluster:: MOMENT_ENUM ] ) \
539 cluster->insertMoment(xAOD::CaloCluster:: MOMENT_ENUM , ed.m_moments-> MOMENT_ARRAY [cluster_index]); \
543 #define CALORECGPU_MOMENTS_CONVERSION_INVALID(MOMENT_ENUM) \
544 if (m_momentsToDo[xAOD::CaloCluster:: MOMENT_ENUM ] ) \
546 ATH_MSG_WARNING("Moment '" << # MOMENT_ENUM << \
547 "' given as a calculated moment, but not yet supported on the GPU side..."); \
605 const int extra_sampling_count = ed.m_moments->nExtraCellSampling[cluster_index];
606 if (extra_sampling_count > 0)
657 time_cast(
start, pre_processing),
658 time_cast(pre_processing, cluster_number),
659 time_cast(cluster_number,
clusters),
661 time_cast(
cells, end_cell_cycle),
662 time_cast(end_cell_cycle, ordered),
663 time_cast(ordered, pre_moments),
664 time_cast(pre_moments, post_moments),
665 time_cast(post_moments,
end)
670 return StatusCode::SUCCESS;