19#include "boost/chrono/chrono.hpp"
20#include "boost/chrono/thread_clock.hpp"
210void CaloRecGPU::EventDataHolder::importCells(
const void * p_cell_collection,
const std::vector<int> & extra_cells_to_fill)
214 m_cell_info.allocate();
216 auto export_cell = [&](
const CaloCell * cell,
const int hash_ID,
const int index_inside)
218 const float energy = cell->energy();
220 m_cell_info->energy[index_inside] = energy;
221 m_cell_info->gain[index_inside] = gain;
222 m_cell_info->time[index_inside] = cell->time();
238 m_cell_info->hashID[index_inside] = hash_ID;
239 m_cell_info->hashIDToCollection[hash_ID] = index_inside;
246 for (
auto cell_it = cell_collection->
begin(); cell_it != cell_collection->
end(); ++cell_it, ++cell_index)
248 const CaloCell *
cell = (*cell_it);
249 export_cell(cell, cell_index, cell_index);
253 m_cell_info->complete =
true;
254 m_cell_info->all_cells_valid =
true;
256 else if (cell_collection->
isOrdered() && extra_cells_to_fill.size() > 0)
261 size_t missing_cell_count = 0;
265 const CaloCell *
cell = (*cell_it);
267 if (missing_cell_count < extra_cells_to_fill.size() && cell_index == extra_cells_to_fill[missing_cell_count])
271 ++missing_cell_count;
272 m_cell_info->hashID[cell_index] = cell_index;
273 m_cell_info->hashIDToCollection[cell_index] = -1;
278 export_cell(cell, cell_index, cell_index);
283 m_cell_info->complete =
true;
284 m_cell_info->all_cells_valid =
false;
290 m_cell_info->hashIDToCollection[cell_index] = -1;
293 int index_inside = 0;
295 const auto cells_end = cell_collection->
end();
302 const CaloCell *
cell = (*cell_it);
304 const int cell_index =
cell->caloDDE()->calo_hash();
305 export_cell(cell, cell_index, index_inside);
308 m_cell_info->number = cell_collection->
size();
309 m_cell_info->complete =
false;
310 m_cell_info->all_cells_valid =
true;
315void CaloRecGPU::EventDataHolder::importClusters(
const void * p_cluster_collection,
317 const bool output_tags,
318 const bool consider_shared_cells,
319 const bool output_moments,
320 const bool output_extra_moments,
321 const std::vector<int> & extra_cells_to_fill)
325 m_clusters.allocate();
327 if (cluster_collection->
size() > 0)
329 std::vector<int> real_cells_to_fill;
333 real_cells_to_fill.reserve(extra_cells_to_fill.size());
335 for (
const int cell : extra_cells_to_fill)
337 if (m_cell_info->hashIDToCollection[cell] <= 0)
339 real_cells_to_fill.push_back(cell);
344 auto index_to_corrected_index = [&](
const int index)
346 if (m_cell_info->all_cells_valid)
353 for (
const int cell : real_cells_to_fill)
365 return m_clusters->cells.tags[
index];
369 return m_clusters->get_extra_cell_info(index);
385 m_clusters->state = (output_moments ?
388 m_clusters->cellsPrefixSum[0] = 0;
391 m_clusters->has_deleted_clusters =
false;
393 const auto cluster_end = cluster_collection->
end();
394 auto cluster_iter = cluster_collection->
begin();
396 int overall_cell_index = 0;
398 for (
int cluster_number = 0; cluster_iter != cluster_end; ++cluster_iter, ++cluster_number)
401 const CaloClusterCellLink * cell_links = cluster->
getCellLinks();
403 m_clusters->clusterEnergy[cluster_number] = cluster->
e();
404 m_clusters->clusterEt[cluster_number] = cluster->
et();
405 m_clusters->clusterEta[cluster_number] = cluster->
eta();
406 m_clusters->clusterPhi[cluster_number] = cluster->
phi();
412 m_clusters->has_deleted_clusters =
true;
413 m_clusters->seedCellIndex[cluster_number] = -1;
417 m_clusters->seedCellIndex[cluster_number] = index_to_corrected_index(seed_cell_index);
420 for (
auto it = cell_links->
begin(); it != cell_links->
end(); ++it)
422 const int cell_index_in_collection = index_to_corrected_index(
it.index());
423 if (consider_shared_cells)
428 std::memcpy(&weight_as_int, &weight,
sizeof(
float));
433 if (weight_as_int == 0)
441 const ClusterTag other_tag = get_cell_tag(cell_index_in_collection);
449 get_cell_tag(cell_index_in_collection) =
ClusterTag::make_tag(cluster_number, weight_as_int, 0);
456 else if (weight > 0.5f)
460 else if (weight == 0.5f)
463 const int max_cluster = cluster_number > other_index ? cluster_number : other_index;
464 const int min_cluster = cluster_number > other_index ? other_index : cluster_number;
465 get_cell_tag(cell_index_in_collection) =
ClusterTag::make_tag(max_cluster, weight_as_int, min_cluster);
469 get_cell_tag(cell_index_in_collection) =
ClusterTag::make_tag(other_index, weight_as_int, cluster_number);
485 for (
auto it = cell_links->
begin(); it != cell_links->
end(); ++it, ++overall_cell_index)
487 m_clusters->cells.indices[overall_cell_index] = index_to_corrected_index(
it.index());
488 m_clusters->clusterIndices[overall_cell_index] = cluster_number;
489 m_clusters->cellWeights[overall_cell_index] =
it.weight();
492 m_clusters->cellsPrefixSum[cluster_number + 1] = overall_cell_index;
502 m_clusters->moments.nExtraCellSampling[cluster_number] = cluster->
numberCellsInSampling(CaloSampling::EME2,
true);
529 m_clusters->moments.time[cluster_number] = cluster->
time();
531#define CALORECGPU_MOMENTS_INPUT_HELPER(VAR_NAME, PROPER_MOMENT, NORMAL_ASSIGN, IS_CALCULATED, MOMENT_NAME, ...) \
532 CRGPU_CONCAT(CRGPU_CONCAT(CALORECGPU_MOMENTS_INPUT_HELPER_, NORMAL_ASSIGN), IS_CALCULATED) (VAR_NAME, MOMENT_NAME)
534#define CALORECGPU_MOMENTS_INPUT_HELPER_11(VAR_NAME, MOMENT_NAME) \
535 if (moments_to_add[xAOD::CaloCluster:: MOMENT_NAME]) \
537 m_clusters->moments. VAR_NAME [cluster_number] = cluster->getMomentValue(xAOD::CaloCluster:: MOMENT_NAME ); \
540#define CALORECGPU_MOMENTS_INPUT_HELPER_10(VAR_NAME, MOMENT_NAME) \
541 if (output_extra_moments && moments_to_add[xAOD::CaloCluster:: MOMENT_NAME]) \
543 m_clusters->moments. VAR_NAME [cluster_number] = cluster->getMomentValue(xAOD::CaloCluster:: MOMENT_NAME ); \
546#define CALORECGPU_MOMENTS_INPUT_HELPER_00(...)
547#define CALORECGPU_MOMENTS_INPUT_HELPER_01(...)
551 double second_time_retriever = 0;
555 m_clusters->moments.secondTime[cluster_number] = cluster->
secondTime();
561 m_clusters->moments.secondTime[cluster_number] = second_time_retriever;
566 m_clusters->number = cluster_collection->
size();
567 m_clusters->number_cells = (output_tags ? m_cell_info->number : overall_cell_index);
572 m_clusters->has_deleted_clusters =
false;
573 m_clusters->number = 0;
574 m_clusters->number_cells = 0;
578template <
class ReadStateFrom,
class OutputCells,
class InputCells,
class CopyFunc>
580 OutputCells & output_cells,
581 InputCells & input_cells,
583 const bool full_copy,
592 copy_func(output_cells->gain,
594 sizeof(
unsigned char) * state_holder->number, stream);
596 copy_func(output_cells->energy,
598 sizeof(
float) * state_holder->number, stream);
600 copy_func(output_cells->time,
602 sizeof(
float) * state_holder->number, stream);
604 copy_func(output_cells->qualityProvenance,
605 input_cells->qualityProvenance,
608 copy_func(output_cells->hashID,
610 sizeof(
int) * state_holder->number, stream);
612 copy_func(output_cells->hashIDToCollection,
613 input_cells->hashIDToCollection,
619template <
class ReadStateFrom,
class OutputClusters,
class InputClusters,
class CopyFunc>
621 OutputClusters & output_clusters,
622 InputClusters & input_clusters,
627 if (state_holder->has_basic_info())
629 copy_func(output_clusters->clusterEnergy,
630 input_clusters->clusterEnergy,
631 sizeof(
float) * state_holder->number, stream);
633 copy_func(output_clusters->clusterEt,
634 input_clusters->clusterEt,
635 sizeof(
float) * state_holder->number, stream);
637 copy_func(output_clusters->clusterEta,
638 input_clusters->clusterEta,
639 sizeof(
float) * state_holder->number, stream);
641 copy_func(output_clusters->clusterPhi,
642 input_clusters->clusterPhi,
643 sizeof(
float) * state_holder->number, stream);
645 copy_func(output_clusters->seedCellIndex,
646 input_clusters->seedCellIndex,
647 sizeof(
int) * state_holder->number, stream);
652template <
class ReadStateFrom,
class OutputClusters,
class InputClusters,
class CopyFunc>
654 OutputClusters & output_clusters,
655 InputClusters & input_clusters,
661 if (state_holder->has_cells_per_cluster())
663 copy_func(output_clusters->cellsPrefixSum,
664 input_clusters->cellsPrefixSum,
665 sizeof(
int) * (state_holder->number + 1), stream);
667 copy_func(output_clusters->cells.indices,
668 input_clusters->cells.indices,
669 sizeof(
int) * state_holder->number_cells, stream);
671 copy_func(output_clusters->cellWeights,
672 input_clusters->cellWeights,
673 sizeof(
float) * state_holder->number_cells, stream);
675 copy_func(output_clusters->clusterIndices,
676 input_clusters->clusterIndices,
677 sizeof(
int) * state_holder->number_cells, stream);
679 int remaining_cells = num_total_cells;
681#define CALORECGPU_MOMENTS_EXTRA_TAGS_HELPER(VARNAME) \
682 if (remaining_cells > 0) \
684 constexpr int max_size_per_array = (sizeof(float) * NMaxClusters)/sizeof(tag_type); \
685 copy_func(output_clusters->moments. VARNAME, \
686 input_clusters->moments. VARNAME, \
687 sizeof(tag_type) * std::min(remaining_cells, max_size_per_array), stream); \
688 remaining_cells -= max_size_per_array; \
701 copy_func(output_clusters->cells.tags,
702 input_clusters->cells.tags,
703 sizeof(
tag_type) * state_holder->number_cells, stream);
708template <
class ReadStateFrom,
class OutputClusters,
class InputClusters,
class CopyFunc>
710 OutputClusters & output_clusters,
711 InputClusters & input_clusters,
716 if (state_holder->has_moments())
718 auto moments_copy_helper = [&](
auto & output_arr,
const auto & input_arr)
720 if constexpr(std::is_pointer_v<std::decay_t<
decltype(*input_arr)>>)
725 copy_func(output_arr[i],
727 sizeof(
decltype(input_arr[0][0])) * state_holder->number,
733 copy_func(output_arr,
735 sizeof(
decltype(input_arr[0])) * state_holder->number,
744 moments_copy_helper(output_clusters->moments.nCellSampling, input_clusters->moments.nCellSampling);
747#define CALORECGPU_MOMENTS_TO_GPU_HELPER(VAR_NAME, PROPER_MOMENT, NORMAL_ASSIGN, IS_CALCULATED, MOMENT_NAME, ...) \
748 CRGPU_CONCAT(CRGPU_CONCAT(CALORECGPU_MOMENTS_TO_GPU_HELPER_, PROPER_MOMENT), IS_CALCULATED) (VAR_NAME, MOMENT_NAME)
750#define CALORECGPU_MOMENTS_TO_GPU_HELPER_11(VAR_NAME, MOMENT_NAME) \
751 if (moments_to_add[xAOD::CaloCluster:: MOMENT_NAME ]) \
753 moments_copy_helper(output_clusters->moments. VAR_NAME, input_clusters->moments. VAR_NAME); \
756#define CALORECGPU_MOMENTS_TO_GPU_HELPER_10(VAR_NAME, MOMENT_NAME) \
757 if ( state_holder->state == CaloRecGPU::ClusterInformationState::WithExtraMoments && \
758 moments_to_add[xAOD::CaloCluster:: MOMENT_NAME ] ) \
760 moments_copy_helper(output_clusters->moments. VAR_NAME, input_clusters->moments. VAR_NAME); \
763#define CALORECGPU_MOMENTS_TO_GPU_HELPER_01(VAR_NAME, MOMENT_NAME) \
764 moments_copy_helper(output_clusters->moments. VAR_NAME, input_clusters->moments. VAR_NAME);
766#define CALORECGPU_MOMENTS_TO_GPU_HELPER_00(VAR_NAME, MOMENT_NAME) \
767 if (state_holder->state == CaloRecGPU::ClusterInformationState::WithExtraMoments) \
769 moments_copy_helper(output_clusters->moments. VAR_NAME, input_clusters->moments. VAR_NAME); \
776template <
class ReadStateFrom,
class OutputClusters,
class InputClusters,
class CopyFunc>
778 OutputClusters & output_clusters,
779 InputClusters & input_clusters,
782 const bool full_copy,
802 const bool full_copy,
803 const bool clear_CPU,
804 const bool synchronize,
805 CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream)
807 m_cell_info_dev.allocate();
808 m_clusters_dev.allocate();
827 m_cell_info->number);
836 else if (synchronize)
843 const bool full_copy,
844 const bool clear_GPU,
845 const bool synchronize,
846 CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream,
847 const bool also_return_cells)
849 if (also_return_cells)
851 m_cell_info.allocate();
853 m_clusters.allocate();
857 if (also_return_cells)
872 if (also_return_cells)
885 m_clusters_dev.clear();
886 m_cell_info_dev.clear();
888 else if (synchronize)
897 std::vector<std::unique_ptr<CaloClusterCellLink>> & cell_links,
899 const bool skip_validation)
901 cell_links.
reserve(clusters->number);
903 for (
int i = 0; i < clusters->number; ++i)
905 if (skip_validation || clusters->seedCellIndex[i] >= 0)
907 cell_links.emplace_back(std::make_unique<CaloClusterCellLink>(cell_collection_link));
908 cell_links.back()->
reserve(256);
913 cell_links.emplace_back(
nullptr);
924 std::vector<std::unique_ptr<CaloClusterCellLink>> & cell_links,
925 const std::vector<int> & extra_cells_to_fill)
928 std::vector<int> real_cells_to_fill;
932 real_cells_to_fill.reserve(extra_cells_to_fill.size());
934 for (
const int cell : extra_cells_to_fill)
936 if (cells->hashIDToCollection[cell] <= 0)
938 real_cells_to_fill.push_back(cell);
943 auto corrected_index_to_real_index = [&](
const int index)
945 if (cells->all_cells_valid)
952 for (
const int cell : real_cells_to_fill)
954 ret -= (
index > cell);
960 if (clusters->has_cells_per_cluster())
962 for (
int i = 0; i < clusters->number_cells; ++i)
964 std::unique_ptr<CaloClusterCellLink> & this_link_ptr = cell_links[clusters->clusterIndices[i]];
969 this_link_ptr->addCell(corrected_index_to_real_index(clusters->cells.indices[i]), clusters->cellWeights[i]);
975 for (
int i = 0; i < clusters->number; ++i)
979 cell_links[i]->
addCell(corrected_index_to_real_index(clusters->seedCellIndex[i]), 1);
984 for (
int i = 0; i < clusters->number_cells; ++i)
986 const ClusterTag this_tag = clusters->cells.tags[i];
990 const int this_cell_index = corrected_index_to_real_index(i);
997 std::memcpy(&tempf, &weight_pattern,
sizeof(
float));
999 const float reverse_weight = tempf;
1001 const float this_weight = 1.0f - reverse_weight;
1003 if (cell_links[this_index] && clusters->seedCellIndex[this_index] != i)
1005 cell_links[this_index]->
addCell(this_cell_index, this_weight);
1011 if (cell_links[other_index] && clusters->seedCellIndex[other_index] != i)
1013 cell_links[other_index]->
addCell(this_cell_index, reverse_weight);
1022 std::vector<int> & cluster_order,
1023 const bool really_sort)
1027 cluster_order.resize(clusters->number);
1029 std::iota(cluster_order.begin(), cluster_order.end(), 0);
1031 std::sort(cluster_order.begin(), cluster_order.end(), [&](
const int a,
const int b) ->
bool
1033 const bool a_valid = clusters->seedCellIndex[a] >= 0;
1034 const bool b_valid = clusters->seedCellIndex[b] >= 0;
1035 if (a_valid && b_valid)
1037 return (clusters->clusterEt[a] > clusters->clusterEt[b]);
1055 cluster_order.clear();
1061 std::vector<std::unique_ptr<CaloClusterCellLink>> & cell_links,
1062 std::vector<int> & cluster_order,
1063 const bool save_uncalibrated)
1065 const int total_size = (cluster_order.size() ? cluster_order.size() : clusters->number);
1066 for (
int i = 0; i < total_size; ++i)
1068 const int cluster_index = (cluster_order.size() ? cluster_order[i] : i);
1070 if (cell_links[cluster_index] !=
nullptr && cell_links[cluster_index]->size() > 0)
1075 cluster->
addCellLink(std::move(cell_links[cluster_index]));
1077 if (clusters->has_basic_info())
1080 cluster->
setE (clusters->clusterEnergy[cluster_index]);
1081 cluster->
setEta(clusters->clusterEta [cluster_index]);
1082 cluster->
setPhi(clusters->clusterPhi [cluster_index]);
1084 if (save_uncalibrated)
1098 std::vector<int> & cluster_order,
1100 const bool output_extra_moments)
1102 if (clusters->has_moments())
1104 const int total_size = (cluster_order.size() ? cluster_order.size() : clusters->number);
1105 for (
int i = 0; i < total_size; ++i)
1107 const int cluster_index = (cluster_order.size() ? cluster_order[i] : i);
1113 uint32_t sampling_pattern = 0;
1116 const int cells_per_sampling = clusters->moments.nCellSampling[sampl][cluster_index];
1118 if (cells_per_sampling > 0)
1120 sampling_pattern |= (0x1U << sampl);
1124 if (clusters->moments.nExtraCellSampling[cluster_index] > 0)
1126 sampling_pattern |= (1U <<
static_cast<unsigned int>(CaloSampling::EME2));
1133 if (sampling_pattern & (1U << s))
1139 if (clusters->moments.nExtraCellSampling[cluster_index] > 0)
1146 if (sampling_pattern & (1U << s))
1153 if (sampling_pattern & (1U << s))
1160 if (sampling_pattern & (1U << s))
1167 if (sampling_pattern & (1U << s))
1174 if (sampling_pattern & (1U << s))
1181 if (sampling_pattern & (1U << s))
1187 cluster->
setTime(clusters->moments.time[cluster_index]);
1188 cluster->
setSecondTime(clusters->moments.secondTime[cluster_index]);
1190#define CALORECGPU_MOMENTS_OUTPUT_HELPER(VAR_NAME, PROPER_MOMENT, NORMAL_ASSIGN, IS_CALCULATED, MOMENT_NAME, ...) \
1191 CRGPU_CONCAT(CRGPU_CONCAT(CALORECGPU_MOMENTS_OUTPUT_HELPER_, NORMAL_ASSIGN), IS_CALCULATED) (VAR_NAME, MOMENT_NAME)
1193#define CALORECGPU_MOMENTS_OUTPUT_HELPER_11(VAR_NAME, MOMENT_NAME) \
1194 if (moments_to_add[xAOD::CaloCluster:: MOMENT_NAME]) \
1196 cluster->insertMoment(xAOD::CaloCluster:: MOMENT_NAME , clusters->moments. VAR_NAME [cluster_index]); \
1199#define CALORECGPU_MOMENTS_OUTPUT_HELPER_10(VAR_NAME, MOMENT_NAME) \
1200 if (output_extra_moments && moments_to_add[xAOD::CaloCluster:: MOMENT_NAME]) \
1202 cluster->insertMoment(xAOD::CaloCluster:: MOMENT_NAME , clusters->moments. VAR_NAME [cluster_index]); \
1205#define CALORECGPU_MOMENTS_OUTPUT_HELPER_00(...)
1206#define CALORECGPU_MOMENTS_OUTPUT_HELPER_01(...)
1214void CaloRecGPU::EventDataHolder::exportClusters(
void * p_cluster_collection,
1215 const void * p_cell_collection_link,
1218 const bool save_uncalibrated,
1219 const bool output_extra_moments,
1220 const std::vector<int> & extra_cells_to_fill,
1221 size_t * time_measurements)
1223 using clock_type = boost::chrono::thread_clock;
1224 auto time_cast = [](
const auto & before,
const auto & after)
1226 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
1230 const DataLink<CaloCellContainer> & cell_collection_link = *(
static_cast<const DataLink<CaloCellContainer> *
>(p_cell_collection_link));
1232 const auto start = clock_type::now();
1234 std::vector<std::unique_ptr<CaloClusterCellLink>> cell_links;
1238 const auto after_link_creation = clock_type::now();
1242 const auto after_cell_processing = clock_type::now();
1244 std::vector<int> cluster_order;
1248 const auto after_sorting = clock_type::now();
1252 const auto after_basic_info = clock_type::now();
1256 const auto after_moments = clock_type::now();
1258 if (time_measurements)
1260 time_measurements[0] = time_cast(start, after_link_creation);
1261 time_measurements[1] = time_cast(after_link_creation, after_cell_processing);
1262 time_measurements[2] = time_cast(after_cell_processing, after_sorting);
1263 time_measurements[3] = time_cast(after_sorting, after_basic_info);
1264 time_measurements[4] = time_cast(after_basic_info, after_moments);
1270 const void * p_cell_collection_link,
1273 const bool save_uncalibrated,
1274 const bool output_extra_moments,
1275 const std::vector<int> & extra_cells_to_fill,
1276 size_t * time_measurements,
1279 using clock_type = boost::chrono::thread_clock;
1280 auto time_cast = [](
const auto & before,
const auto & after)
1282 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
1288 const auto start = clock_type::now();
1298 const auto after_first_transfer = clock_type::now();
1302 std::vector<std::unique_ptr<CaloClusterCellLink>> cell_links;
1306 const auto after_link_creation = clock_type::now();
1314 const auto after_cell_processing = clock_type::now();
1316 std::vector<int> cluster_order;
1320 const auto after_sorting = clock_type::now();
1328 const auto after_basic_info = clock_type::now();
1334 const auto after_moments = clock_type::now();
1336 if (time_measurements)
1338 time_measurements[0] = time_cast(start, after_first_transfer);
1339 time_measurements[1] = time_cast(after_first_transfer, after_link_creation);
1340 time_measurements[2] = time_cast(after_link_creation, after_cell_processing);
1341 time_measurements[3] = time_cast(after_cell_processing, after_sorting);
1342 time_measurements[4] = time_cast(after_sorting, after_basic_info);
1343 time_measurements[5] = time_cast(after_basic_info, after_moments);
Definition of CaloDetDescrManager.
#define CALORECGPU_MOMENTS_INPUT_HELPER(VAR_NAME, PROPER_MOMENT, NORMAL_ASSIGN, IS_CALCULATED, MOMENT_NAME,...)
static void cluster_transfer_helper_moments(ReadStateFrom &state_holder, OutputClusters &output_clusters, InputClusters &input_clusters, const MomentsOptionsArray &moments_to_add, CopyFunc copy_func, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream)
static void export_cluster_fill_moments(const ClusterInfoArr *clusters, xAOD::CaloClusterContainer *cluster_collection, std::vector< int > &cluster_order, const MomentsOptionsArray &moments_to_add, const bool output_extra_moments)
#define CALORECGPU_MOMENTS_OUTPUT_HELPER(VAR_NAME, PROPER_MOMENT, NORMAL_ASSIGN, IS_CALCULATED, MOMENT_NAME,...)
static void export_cluster_fill_cells_and_basic_info(const ClusterInfoArr *clusters, xAOD::CaloClusterContainer *cluster_collection, std::vector< std::unique_ptr< CaloClusterCellLink > > &cell_links, std::vector< int > &cluster_order, const bool save_uncalibrated)
static void cell_transfer_helper(ReadStateFrom &state_holder, OutputCells &output_cells, InputCells &input_cells, CopyFunc copy_func, const bool full_copy, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream)
static void export_cluster_sort(const ClusterInfoArr *clusters, std::vector< int > &cluster_order, const bool really_sort)
static void cluster_transfer_helper(ReadStateFrom &state_holder, OutputClusters &output_clusters, InputClusters &input_clusters, const MomentsOptionsArray &moments_to_add, CopyFunc copy_func, const bool full_copy, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream, const int num_total_cells=CaloRecGPU::NCaloCells)
static void cluster_transfer_helper_cell_assignment(ReadStateFrom &state_holder, OutputClusters &output_clusters, InputClusters &input_clusters, CopyFunc copy_func, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream, const int num_total_cells=NCaloCells)
#define CALORECGPU_MOMENTS_EXTRA_TAGS_HELPER(VARNAME)
#define CALORECGPU_MOMENTS_TO_GPU_HELPER(VAR_NAME, PROPER_MOMENT, NORMAL_ASSIGN, IS_CALCULATED, MOMENT_NAME,...)
static void export_cluster_process_cells(const ClusterInfoArr *clusters, const CellInfoArr *cells, std::vector< std::unique_ptr< CaloClusterCellLink > > &cell_links, const std::vector< int > &extra_cells_to_fill)
static void cluster_transfer_helper_basic_info(ReadStateFrom &state_holder, OutputClusters &output_clusters, InputClusters &input_clusters, CopyFunc copy_func, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream)
static void export_cluster_initialize_links(const ClusterInfoArr *clusters, std::vector< std::unique_ptr< CaloClusterCellLink > > &cell_links, const DataLink< CaloCellContainer > &cell_collection_link, const bool skip_validation)
#define CALORECGPU_FORALLMOMENTS_INSTANTIATE(MACRO,...)
Contains some helpful macros to help with repetitive code...
Container class for CaloCell.
bool isOrdered() const
tell wether container is ordered
bool isOrderedAndComplete() const
tell wether container is complete and in order
Data object for each calorimeter readout cell.
unsigned index() const
Accessor for the index of the cell in the CaloCellContainer.
bool addCell(const unsigned cellIdx, const weight_t weight=1.0)
Method to add a cell to the cluster.
const_iterator end() const
const end method
void reserve(const size_t s)
Method to reserve space the underlying vector<pair>
const_iterator begin() const
const begin method
CaloRecGPU::Helpers::CPU_object< CaloRecGPU::GeometryArr > m_geometry
void sendToGPU(const bool clear_CPU=true)
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::CellNoiseArr > m_cell_noise_dev
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::GeometryArr > m_geometry_dev
CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellNoiseArr > m_cell_noise
CaloRecGPU::Helpers::CUDA_pinned_CPU_object< CaloRecGPU::CellInfoArr > m_cell_info
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::CellInfoArr > m_cell_info_dev
CaloRecGPU::Helpers::CUDA_pinned_CPU_object< CaloRecGPU::ClusterInfoArr > m_clusters
void allocate(const bool also_GPU=true)
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::ClusterInfoArr > m_clusters_dev
void returnAndExportClusters(void *cluster_collection, const void *cell_collection_link, const MomentsOptionsArray &moments_to_add, const bool sort_clusters=true, const bool save_uncalibrated=true, const bool output_extra_moments=false, const std::vector< int > &extra_cells_to_fill={}, size_t *time_measurements=nullptr, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream={})
We are using a void* for API to make this able to compile on the GPU without Athena-specific dependen...
static constexpr GainType from_standard_gain(const int gain)
static constexpr GainType invalid_gain()
Object reference supporting deferred reading from StoreGate.
DataModel_detail::const_iterator< DataVector > const_iterator
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
uint8_t qual1(void) const
get quality of first PMT (data member)
uint8_t qbit2(void) const
get quality bits of second PMT (data member)
uint8_t qual2(void) const
get quality of second PMT (data member)
uint8_t qbit1(void) const
get quality bits of first PMT (data member)
void setRawEta(flt_t)
Set for signal state UNCALIBRATED.
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
void setRawPhi(flt_t)
Set for signal state UNCALIBRATED.
void setSecondTime(flt_t stime)
Set second moment of cell timing distribution.
bool setPhi(const CaloSample sampling, const float phi)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
flt_t calPhi() const
Get in signal state CALIBRATED.
float phiSample(const CaloSample sampling) const
Retrieve barycenter in a given sample.
float energy_max(const CaloSample sampling) const
Retrieve maximum cell energy in given sampling.
int numberCellsInSampling(const CaloSample samp, bool isInnerWheel=false) const
Returns number of cells in given sampling.
void addCellLink(CaloClusterCellLink *CCCL)
flt_t time() const
Access cluster time.
void setRawE(flt_t)
Set Energy for signal state UNCALIBRATED.
void setRawM(flt_t)
Set mass for singal state UNCALIBRATED.
virtual double eta() const
The pseudorapidity ( ) of the particle.
void setTime(flt_t)
Set cluster time.
virtual double e() const
The total energy of the particle.
bool setPhimax(const CaloSample sampling, const float phiMax)
Set the phi of the cell with the highest energy in a particular sampling.
const_cell_iterator cell_end() const
bool setEta(const CaloSample sampling, const float eta)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
bool setEmax(const CaloSample sampling, const float eMax)
Set the Energy of the cell with the highest energy in a particular sampling.
float eSample(const CaloSample sampling) const
flt_t calEta() const
Get in signal state CALIBRATED.
flt_t secondTime() const
Access second moment of cell timing distribution.
bool setEnergy(const CaloSample sampling, const float e)
Set energy for a given sampling. Returns false if the sample isn't part of the cluster.
virtual double phi() const
The azimuthal angle ( ) of the particle.
void setSamplingPattern(const unsigned sp, const bool clearSamplingVars=false)
Set sampling pattern (one bit per sampling.
float etamax(const CaloSample sampling) const
Retrieve of cell with maximum energy in given sampling.
@ ENG_CALIB_OUT_M
Attached Calibration Hit energy outside clusters but inside the calorimeter with medium matching (Ang...
@ PTD
relative spread of pT of constiuent cells = sqrt(n)*RMS/Mean
@ SECOND_ENG_DENS
Second Moment in E/V.
@ DELTA_PHI
Angular shower axis deviation ( ) from IP-to-Center.
@ ETA2CALOFRAME
Eta of sampling 2 in the calo frame (for egamma)
@ DELTA_ALPHA
Angular shower axis deviation ( ) from IP-to-Center.
@ OOC_WEIGHT
Out-of-cluster weight (E_ooc/E_w)
@ AVG_TILE_Q
Sum(E_cell_Tile^2 Q_cell_Tile)/Sum(E_cell_Tile^2)
@ DELTA_THETA
Angular shower axis deviation ( ) from IP-to-Center.
@ SECOND_LAMBDA
Second Moment in .
@ ETACALOFRAME
Eta in the calo frame (for egamma)
@ FIRST_PHI
First Moment in .
@ ENG_CALIB_OUT_L
Attached Calibration Hit energy outside clusters but inside the calorimeter with loose matching (Angl...
@ CELL_SIGNIFICANCE
Cell significance = E/sig of the cell with the largest |E|/sig.
@ CELL_SIG_SAMPLING
CaloSample of the cell with the largest |E|/sig.
@ EM_PROBABILITY
Classification probability to be em-like.
@ PHI2CALOFRAME
Phi of sampling 2 in the calo frame (for egamma)
@ VERTEX_FRACTION
Vertex fraction of this cluster wrt.
@ ENG_CALIB_DEAD_T
Attached Calibration Hit energy in dead material with tight matching (Angle < 0.3).
@ NCELL_SAMPLING
Number of cells in sampling layer.
@ NVERTEX_FRACTION
slightly updated vertex fraction more pile up independent (similar to nJVF)
@ SECOND_TIME
Second moment of cell time distribution in cluster.
@ N_BAD_CELLS_CORR
Number of bad cells with energy density average correction applied.
@ DM_WEIGHT
Dead-material weight (E_dm/E_ooc)
@ LATERAL
Normalized lateral moment.
@ N_BAD_CELLS
number of bad cells
@ LONGITUDINAL
Normalized longitudinal moment.
@ ENG_FRAC_MAX
Energy fraction of hottest cell.
@ AVG_LAR_Q
Sum(E_cell_LAr^2 Q_cell_LAr)/Sum(E_cell_LAr^2)
@ ENG_CALIB_DEAD_UNCLASS
Attached Calibration Hit energy in dead material in unclassified areas of the detector.
@ PHI1CALOFRAME
Phi of sampling 1 in the calo frame (for egamma)
@ ENG_FRAC_EM
Energy fraction in EM calorimeters.
@ SECOND_R
Second Moment in .
@ ENG_CALIB_DEAD_HEC0
Attached Calibration Hit energy in dead material between EME3 and HEC0.
@ FIRST_ETA
First Moment in .
@ PHICALOFRAME
Phi in the calo frame (for egamma)
@ ENG_BAD_HV_CELLS
Total em-scale energy of cells with bad HV in this cluster.
@ FIRST_ENG_DENS
First Moment in E/V.
@ HAD_WEIGHT
Hadronic weight (E_w/E_em)
@ ENG_CALIB_DEAD_TILEG3
Attached Calibration Hit energy in dead material before scintillator.
@ N_BAD_HV_CELLS
number of cells with bad HV
@ ENG_FRAC_CORE
Energy fraction of the sum of the hottest cells in each sampling.
@ CENTER_LAMBDA
Shower depth at Cluster Centroid.
@ SIGNIFICANCE
Cluster significance.
@ CENTER_MAG
Cluster Centroid ( )
@ MASS
cell based mass i.e. the mass of the 4-vector sum of all massless positive energetic cells
@ ENG_CALIB_DEAD_M
Attached Calibration Hit energy in dead material with medium matching (Angle < 0.5).
@ ENG_CALIB_FRAC_REST
Calibration Hit energy inside the cluster caused by other particles.
@ ENG_CALIB_DEAD_L
Attached Calibration Hit energy in dead material with loose matching (Angle < 1.0).
@ ENG_CALIB_DEAD_EME0
Attached Calibration Hit energy in dead material before EME0, between EME0 and EME1.
@ ENG_CALIB_DEAD_TILE0
Attached Calibration Hit energy in dead material between EMB3 and TILE0.
@ CENTER_Z
Cluster Centroid ( )
@ BAD_CELLS_CORR_E
Energy of bad cells with energy density average correction applied.
@ ETA1CALOFRAME
Eta of sampling 1 in the calo frame (for egamma)
@ ENG_CALIB_FRAC_EM
Calibration Hit energy inside the cluster caused by e/gamma/pi0.
@ ENG_BAD_CELLS
Total em-scale energy of bad cells in this cluster.
@ ENG_CALIB_DEAD_FCAL
Attached Calibration Hit energy in dead material before FCAL, between FCAL and HEC.
@ ENG_CALIB_TOT
Calibration Hit energy inside the cluster.
@ ENG_CALIB_OUT_T
Attached Calibration Hit energy outside clusters but inside the calorimeter with tight matching (Angl...
@ ENG_CALIB_DEAD_LEAKAGE
Attached Calibration Hit energy in dead material behind calorimeters.
@ ENG_CALIB_FRAC_HAD
Calibration Hit energy inside the cluster caused by charged pi+ and pi-.
@ ENG_CALIB_EMB0
Calibration Hit energy inside the cluster barrel presampler.
@ ENG_CALIB_EME0
Calibration Hit energy inside the cluster endcap presampler.
@ ENG_POS
Total positive Energy of this cluster.
@ BADLARQ_FRAC
Energy fraction of LAr cells with quality larger than a given cut.
@ CENTER_X
Cluster Centroid ( )
@ ENG_CALIB_DEAD_EMB0
Attached Calibration Hit energy in dead material before EMB0, between EMB0 and EMB1.
@ ISOLATION
Energy weighted fraction of non-clustered perimeter cells.
@ ENG_CALIB_DEAD_TOT
Attached Calibration Hit energy in dead material.
@ CENTER_Y
Cluster Centroid ( )
@ ENG_CALIB_TILEG3
Calibration Hit energy inside the cluster scintillator.
@ TILE_CONFIDENCE_LEVEL
Confidence Level of a tile calorimeter cluster to be noise.
const_cell_iterator cell_begin() const
Iterator of the underlying CaloClusterCellLink (const version)
float etaSample(const CaloSample sampling) const
Retrieve barycenter in a given sample.
void setNumberCellsInSampling(CaloSampling::CaloSample samp, int ncells, bool isInnerWheel=false)
Set the number of cells in a sampling layer.
float phimax(const CaloSample sampling) const
Retrieve of cell with maximum energy in given sampling.
flt_t calE() const
Geet Energy in signal state CALIBRATED.
bool setEtamax(const CaloSample sampling, const float etaMax)
Set the eta of the cell with the highest energy in a particular sampling.
void clearSamplingData()
Clear the sampling data.
flt_t calM() const
Get mass in signal state CALIBRATED.
void nextDDE(Iter iter, Iter endIter)
Prefetch next CaloDDE.
void CPU_to_GPU_async(void *dest, const void *const source, const size_t num, CUDAStreamPtrHolder stream={})
Copies num bytes from source in CPU memory to dest in GPU memory, asynchronously.
void GPU_synchronize(CUDAStreamPtrHolder stream={})
Synchronizes the stream.
void GPU_to_CPU_async(void *dest, const void *const source, const size_t num, CUDAStreamPtrHolder stream={})
Copies num bytes from source in GPU memory to dest in CPU memory, asynchronously.
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
constexpr int NumSamplings
TagBase::carrier tag_type
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Contains the fundamental information that allows interacting with CellInfoArr so that it is easier to...
Contains the per-event cell information: energy, timing, gain, quality and provenance.
Contains the fundamental information that allows interacting with ClusterInfoArr so that it is easier...
The class that actually expresses the cluster assignment.
constexpr int32_t secondary_cluster_index() const
constexpr int32_t secondary_cluster_weight() const
constexpr bool is_shared_between_clusters() const
constexpr bool is_part_of_cluster() const
constexpr int32_t cluster_index() const
static constexpr carrier make_tag(const uint16_t cluster_index=0, const int32_t weight=0, const uint16_t second_cluster_index=0)
static constexpr bool is_tile(const int cell)
Holds an array of bools to represent the different moments that may be calculated and transferred to/...
bool array[num_moments+1]
static MomentsOptionsArray all()
static int moment_to_linear(const int moment)
bool & operator[](const int moment)
static constexpr int num_moments
Just two uint16_t bit-packed onto a uint32_t.
static constexpr carrier make_invalid_tag()