 |
ATLAS Offline Software
|
Go to the documentation of this file.
20 #include "boost/chrono/chrono.hpp"
21 #include "boost/chrono/thread_clock.hpp"
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;
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;
254 std::vector<std::unique_ptr<CaloClusterCellLink>> cell_links;
268 cell_links.emplace_back(std::make_unique<CaloClusterCellLink>(cell_collection_link));
269 cell_links.back()->reserve(256);
274 cell_links.emplace_back(
nullptr);
282 const LArOnOffIdMapping *
cabling =
nullptr;
290 hvcorr = *hvScaleHdl;
301 const auto process_cell = [&](
const int cell_index,
const int cell_count)
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];
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]);
475 if (m_saveUncalibrated)
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);
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)
656 record_times(ctx.evt(),
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;
679 print_times(
"Preprocessing Cluster_Number Clusters Cells Cell_Cycle Ordering Cluster_Creation Moments_Transfer Moments_Fill", 9);
681 return StatusCode::SUCCESS;
def retrieve(aClass, aKey=None)
bool m_doHVMoments
To abbreviate checks of m_momentsToDo...
bool CENTER_LAMBDA(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Const iterator class for DataVector/DataList.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_HVCablingKey
Cabling for the CPU-based HV moments calculation.
void setRawM(flt_t)
Set mass for singal state UNCALIBRATED.
GPUToAthenaImporterWithMoments(const std::string &type, const std::string &name, const IInterface *parent)
constexpr int32_t secondary_cluster_index() const
bool EM_PROBABILITY(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
constexpr bool is_shared_between_clusters() const
@ ENG_BAD_HV_CELLS
Total em-scale energy of cells with bad HV in this cluster.
const std::string & name() const
Return the StoreGate ID for the referenced object.
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
flt_t calE() const
Geet Energy in signal state CALIBRATED.
Gaudi::Property< std::vector< std::string > > m_momentsNames
vector holding the input list of names of moments to calculate.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Key for the CaloDetDescrManager in the Condition Store.
void clearSamplingData()
Clear the sampling data.
flt_t calEta() const
Get in signal state CALIBRATED.
void returnClusterNumberToCPU(CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream={})
This function is asynchronous.
weight_t weight() const
Accessor for weight associated to this cell.
void GPU_synchronize(CUDAStreamPtrHolder stream={})
Synchronizes the stream.
bool isOrdered() const
tell wether container is ordered
void insertMoment(MomentType type, double value)
unsigned index() const
Accessor for the index of the cell in the CaloCellContainer.
void returnSomeMomentsToCPU(const size_t num_clusters, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream={})
We assume the cluster number is already known and thus only return num_clusters clusters.
xAOD::CaloCluster::ClusterSize m_clusterSize
void setSamplingPattern(const unsigned sp, const bool clearSamplingVars=false)
Set sampling pattern (one bit per sampling.
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.
constexpr int NumSamplings
CaloRecGPU::Helpers::CPU_object< CaloRecGPU::GeometryArr > m_geometry
flt_t calM() const
Get mass in signal state CALIBRATED.
void setTime(flt_t)
Set cluster time.
bool setEmax(const CaloSample sampling, const float eMax)
Set the Energy of the cell with the highest energy in a particular sampling.
Base class to provide some basic common infrastructure for timing measurements...
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition of CaloDetDescrManager.
@ NCELL_SAMPLING
Number of cells in sampling layer.
void setSecondTime(flt_t stime)
Set second moment of cell timing distribution.
#define CRGPU_CHEAP_STRING_TO_ENUM(VAR, PREFIX, ONE,...)
Checks a string variable, VAR, for matching enum identifiers (ONE and the remaining variadic argument...
MomentsOptionsArray m_momentsToDo
Holds (in a linearized way) the moments and whether to add them to the clusters.
constexpr int32_t cluster_index() const
bool setPhimax(const CaloSample sampling, const float phiMax)
Set the phi of the cell with the highest energy in a particular sampling.
Description of a calorimeter cluster.
void setRawE(flt_t)
Set Energy for signal state UNCALIBRATED.
#define CRGPU_RECURSIVE_MACRO(...)
Expands recursive macros.
::StatusCode StatusCode
StatusCode definition for legacy code.
void print_times(const std::string &header, const size_t time_size) const
void setRawEta(flt_t)
Set for signal state UNCALIBRATED.
flt_t calPhi() const
Get in signal state CALIBRATED.
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
vector of names of the cell containers to use as input.
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
bool SECOND_LAMBDA(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
static constexpr int num_moments
Gaudi::Property< std::string > m_clusterSizeString
Cluster size. Should be set accordingly to the threshold.
const CaloCell_ID * m_calo_id
Pointer to Calo ID Helper.
void reindex(const unsigned newIndex)
Update the index.
SG::ReadCondHandleKey< ILArHVScaleCorr > m_HVScaleKey
HV corrections for the CPU-based HV moments.
Helpers for checking error return status codes and reporting errors.
void setNumberCellsInSampling(CaloSampling::CaloSample samp, int ncells, bool isInnerWheel=false)
Set the number of cells in a sampling layer.
void returnCellsToCPU(CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream={})
This function is asynchronous.
Gaudi::Property< bool > m_fillHVMoments
if set to true, fill the HV-related moments using the respective tools.
bool SECOND_R(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
StatusCode initialize(bool used=true)
@ ENERGY_DigiHSTruth
First Moment in .
constexpr bool is_part_of_cluster() const
#define CALORECGPU_MOMENTS_CONVERSION_INVALID(MOMENT_ENUM)
bool CENTER_MAG(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
bool isOrderedAndComplete() const
tell wether container is complete and in order
void addCellLink(CaloClusterCellLink *CCCL)
Data object for each calorimeter readout cell.
void setClusterSize(const ClusterSize)
Get cluster size.
CaloRecGPU::Helpers::CUDA_pinned_CPU_object< CaloRecGPU::ClusterInfoArr > m_clusters
Gaudi::Property< bool > m_measureTimes
If true, times are recorded to the file given by m_timeFileName.
CaloRecGPU::Helpers::CUDA_pinned_CPU_object< CaloRecGPU::CellStateArr > m_cell_state
@ N_BAD_HV_CELLS
number of cells with bad HV
bool FIRST_ENG_DENS(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
bool setPhi(const CaloSample sampling, const float phi)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
bool setEtamax(const CaloSample sampling, const float etaMax)
Set the eta of the cell with the highest energy in a particular sampling.
virtual const float & HVScaleCorr(const HWIdentifier &id) const =0
void returnSomeClustersToCPU(const size_t num_clusters, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream={})
We assume the cluster number is already known and thus only return num_clusters clusters.
bool setEta(const CaloSample sampling, const float eta)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
#define CALORECGPU_MOMENTS_CONVERSION_HELPER(MOMENT_ENUM, MOMENT_ARRAY)
void reweight(const weight_t newWeight)
Update the weight.
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).
constexpr int32_t secondary_cluster_weight() const
CaloRecGPU::Helpers::CUDA_pinned_CPU_object< CaloRecGPU::CellInfoArr > m_cell_info
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
virtual StatusCode finalize() override
void setM(flt_t)
Set Mass for the current signal state.
virtual StatusCode initialize() override
void setRawPhi(flt_t)
Set for signal state UNCALIBRATED.
Gaudi::Property< float > m_HVthreshold
Threshold above which a cell contributes to the HV moments.
static constexpr int moment_to_linear(const xAOD::CaloCluster::MomentType moment)
virtual StatusCode convert(const EventContext &ctx, const CaloRecGPU::ConstantDataHolder &constant_data, CaloRecGPU::EventDataHolder &event_data, xAOD::CaloClusterContainer *cluster_collection) const override