20#include "boost/chrono/chrono.hpp"
21#include "boost/chrono/thread_clock.hpp"
26 base_class(
type, name, parent),
45 auto get_cluster_size_from_string = [](
const std::string &
str,
bool & failed)
78 bool size_failed =
false;
88 return StatusCode::FAILURE;
92 auto get_moment_from_string = [](
const std::string &
str,
bool & failed)
136 TILE_CONFIDENCE_LEVEL,
159 ENG_CALIB_DEAD_TILE0,
160 ENG_CALIB_DEAD_TILEG3,
164 ENG_CALIB_DEAD_LEAKAGE,
165 ENG_CALIB_DEAD_UNCLASS,
178 auto process_moments = [&](
const std::vector<std::string> & moment_names, std::string & invalid_names)
180 for (
const std::string & mom_name : moment_names)
189 if (invalid_names.size() == 0)
191 invalid_names =
"'" + mom_name +
"'";
195 invalid_names +=
", '" + mom_name +
"'";
205 std::string invalid_names;
209 if (invalid_names.size() > 0)
212 <<
" are not valid moments and will be ignored!" );
216 return StatusCode::SUCCESS;
226 using clock_type = boost::chrono::thread_clock;
227 auto time_cast = [](
const auto & before,
const auto & after)
229 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
232 cluster_container->
clear();
234 const auto start = clock_type::now();
238 if ( !cell_collection.
isValid() )
240 ATH_MSG_ERROR(
" Cannot retrieve CaloCellContainer: " << cell_collection.
name() );
241 return StatusCode::FAILURE;
245 size_t extra_times[6];
247 const auto before_export = clock_type::now();
250 &cell_collection_link,
258 const auto after_export = clock_type::now();
260 for (
size_t i = 0; i < cluster_container->
size(); ++i)
265 const auto after_size = clock_type::now();
274 std::vector<double> HV_energies(ed.
m_clusters->number, 0.);
275 std::vector<int> HV_numbers(ed.
m_clusters->number, 0.);
277 for (
int i = 0; i < ed.
m_clusters->number_cells; ++i)
279 const int this_cluster = ed.
m_clusters->clusterIndices[i];
281 const int this_cell_index = ed.
m_clusters->cells.indices[i];
289 HWIdentifier hwid = cabling->createSignalChannelIDFromHash(this_hash_ID);
292 if (corr > 0.f && corr < 100.f && fabsf(corr - 1.f) >
m_HVthreshold)
294 HV_energies[this_cluster] += fabsf(ed.
m_cell_info->energy[this_cell_index]);
295 ++HV_numbers[this_cluster];
299 for (
int i = 0; i < ed.
m_clusters->number; ++i)
318 const auto after_HV = clock_type::now();
323 time_cast(start, before_export),
330 time_cast(after_export, after_size),
331 time_cast(after_size, after_HV)
335 return StatusCode::SUCCESS;
344 print_times(
"Preprocessing Number_and_State Link_Creation Cell_Processing Sorting Basic_Info Moments Cluster_Size HV_Moments", 9);
346 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition of CaloDetDescrManager.
Helpers for checking error return status codes and reporting errors.
Contains some helpful macros to help with repetitive code...
#define CRGPU_RECURSIVE_MACRO(...)
Expands recursive macros.
#define CRGPU_CHEAP_STRING_TO_ENUM(VAR, PREFIX, ONE,...)
Checks a string variable, VAR, for matching enum identifiers (ONE and the remaining variadic argument...
Gaudi::Property< bool > m_measureTimes
If true, times are recorded to the file given by m_timeFileName.
void print_times(const std::string &header, const size_t time_size) const
void record_times(const size_t event_num, const std::vector< size_t > ×) const
Holds CPU and GPU versions of the geometry and cell noise information, which are assumed to be consta...
Holds the mutable per-event information (clusters and cells) and provides utilities to convert betwee...
CaloRecGPU::Helpers::CUDA_pinned_CPU_object< CaloRecGPU::CellInfoArr > m_cell_info
CaloRecGPU::Helpers::CUDA_pinned_CPU_object< CaloRecGPU::ClusterInfoArr > m_clusters
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...
Object reference supporting deferred reading from StoreGate.
size_type size() const noexcept
Returns the number of elements in the collection.
void clear()
Erase all the elements in the collection.
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
vector of names of the cell containers to use as input.
Gaudi::Property< std::string > m_clusterSizeString
Cluster size. Should be set accordingly to the threshold.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Key for the CaloDetDescrManager in the Condition Store.
const CaloCell_ID * m_calo_id
Pointer to Calo ID Helper.
GPUToAthenaImporterWithMoments(const std::string &type, const std::string &name, const IInterface *parent)
xAOD::CaloCluster::ClusterSize m_clusterSize
virtual StatusCode convert(const EventContext &ctx, const CaloRecGPU::ConstantDataHolder &constant_data, CaloRecGPU::EventDataHolder &event_data, xAOD::CaloClusterContainer *cluster_collection) const override
Gaudi::Property< bool > m_keepGPUData
If true, do not delete the GPU data representation.
Gaudi::Property< float > m_HVthreshold
Threshold above which a cell contributes to the HV moments.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_HVCablingKey
Cabling for the CPU-based HV moments calculation.
virtual StatusCode initialize() override
SG::ReadCondHandleKey< ILArHVScaleCorr > m_HVScaleKey
HV corrections for the CPU-based HV moments.
Gaudi::Property< bool > m_saveUncalibrated
if set to true, the uncalibrated state is saved when importing the clusters.
bool m_doHVMoments
To abbreviate checks of m_momentsToDo...
Gaudi::Property< bool > m_fillHVMoments
if set to true, fill the HV-related moments using the respective tools.
Gaudi::Property< std::vector< std::string > > m_momentsNames
vector holding the input list of names of moments to calculate.
CaloRecGPU::MomentsOptionsArray m_momentsToDo
Holds (in a linearized way) the moments and whether to add them to the clusters.
virtual StatusCode finalize() override
Gaudi::Property< std::vector< int > > m_missingCellsToFill
Cell indices to fill as disabled cells (useful if the cell vector is always missing the same cells).
virtual const float & HVScaleCorr(const HWIdentifier &id) const =0
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const std::string & name() const
Return the StoreGate ID for the referenced object.
void insertMoment(MomentType type, double value)
@ ENG_BAD_HV_CELLS
Total em-scale energy of cells with bad HV in this cluster.
@ N_BAD_HV_CELLS
number of cells with bad HV
@ ENERGY_DigiHSTruth
First Moment in .
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
static constexpr bool is_tile(const int cell)
static int moment_to_linear(const int moment)
static constexpr int num_moments