|
ATLAS Offline Software
|
Go to the documentation of this file.
20 #include "boost/chrono/chrono.hpp"
21 #include "boost/chrono/thread_clock.hpp"
30 declareInterface<ICaloClusterGPUOutputTransformer> (
this);
47 auto get_cluster_size_from_string = [](
const std::string &
str,
bool & failed)
80 bool size_failed =
false;
90 return StatusCode::FAILURE;
94 auto get_moment_from_string = [](
const std::string &
str,
bool & failed)
138 TILE_CONFIDENCE_LEVEL,
161 ENG_CALIB_DEAD_TILE0,
162 ENG_CALIB_DEAD_TILEG3,
166 ENG_CALIB_DEAD_LEAKAGE,
167 ENG_CALIB_DEAD_UNCLASS,
180 auto process_moments = [&](
const std::vector<std::string> & moment_names, std::string & invalid_names)
182 for (
const std::string & mom_name : moment_names)
191 if (invalid_names.size() == 0)
193 invalid_names =
"'" + mom_name +
"'";
197 invalid_names +=
", '" + mom_name +
"'";
207 std::string invalid_names;
211 if (invalid_names.size() > 0)
214 <<
" are not valid moments and will be ignored!" );
218 return StatusCode::SUCCESS;
227 using clock_type = boost::chrono::thread_clock;
228 auto time_cast = [](
const auto & before,
const auto & after)
230 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
237 if ( !cell_collection.
isValid() )
239 ATH_MSG_ERROR(
" Cannot retrieve CaloCellContainer: " << cell_collection.
name() );
240 return StatusCode::FAILURE;
256 std::vector<std::unique_ptr<CaloClusterCellLink>> cell_links;
270 cell_links.emplace_back(std::make_unique<CaloClusterCellLink>(cell_collection_link));
271 cell_links.back()->reserve(256);
276 cell_links.emplace_back(
nullptr);
284 const LArOnOffIdMapping *
cabling =
nullptr;
292 hvcorr = *hvScaleHdl;
303 const auto process_cell = [&](
const int cell_index,
const int cell_count)
313 std::memcpy(&tempf, &weight_pattern,
sizeof(
float));
318 const float reverse_weight = tempf;
320 const float this_weight = 1.0f - reverse_weight;
322 if (cell_links[this_index])
324 cell_links[this_index]->addCell(cell_count, this_weight);
326 if (cell_index == ed.
m_clusters->seedCellID[this_index] && cell_links[this_index]->size() > 1)
333 const unsigned int first_idx = begin_it.
index();
334 const double first_wgt = begin_it.
weight();
351 if (cell_links[other_index])
353 cell_links[other_index]->addCell(cell_count, reverse_weight);
359 HWIdentifier hwid =
cabling->createSignalChannelIDFromHash((IdentifierHash) cell_index);
363 const float abs_energy = fabsf(ed.
m_cell_info->energy[cell_index]);
364 HV_energy[this_index] += abs_energy;
365 ++HV_number[this_index];
369 HV_energy[other_index] += abs_energy;
370 ++HV_number[other_index];
380 for (
int cell_index = 0; cell_index <
NCaloCells; ++cell_index)
382 process_cell(cell_index, cell_index);
387 size_t missing_cell_count = 0;
388 for (
int cell_index = 0; cell_index <
NCaloCells; ++cell_index)
392 ++missing_cell_count;
395 process_cell(cell_index, cell_index - missing_cell_count);
403 for (
int cell_count = 0; iCells != cell_collection->
end(); ++iCells, ++cell_count)
408 const int cell_index =
cell->caloDDE()->calo_hash();
410 process_cell(cell_index, cell_count);
416 std::vector<int> cluster_order(ed.
m_clusters->number);
418 std::iota(cluster_order.begin(), cluster_order.end(), 0);
420 std::sort(cluster_order.begin(), cluster_order.end(), [&](
const int a,
const int b) ->
bool
422 const bool a_valid = ed.m_clusters->seedCellID[a] >= 0;
423 const bool b_valid = ed.m_clusters->seedCellID[b] >= 0;
424 if (a_valid && b_valid)
426 return ed.m_clusters->clusterEt[a]
427 > ed.m_clusters->clusterEt[b];
452 cluster_container->clear();
453 cluster_container->reserve(cell_links.size());
455 std::vector<int> real_cluster_order;
456 real_cluster_order.reserve(cluster_order.size());
458 for (
size_t i = 0;
i < cluster_order.size(); ++
i)
460 const int cluster_index = cluster_order[
i];
462 if (cell_links[cluster_index] !=
nullptr && cell_links[cluster_index]->
size() > 0)
465 cluster_container->push_back(cluster);
470 cluster->
setEta(ed.m_clusters->clusterEta[cluster_index]);
471 cluster->
setPhi(ed.m_clusters->clusterPhi[cluster_index]);
473 cluster->
setE(ed.m_clusters->clusterEnergy[cluster_index]);
477 if (m_saveUncalibrated)
485 real_cluster_order.push_back(cluster_index);
497 for (
size_t i = 0;
i < cluster_container->size(); ++
i)
500 const int cluster_index = real_cluster_order[
i];
502 cluster->
setTime(ed.m_moments->time[cluster_index]);
503 cluster->
setSecondTime(ed.m_moments->secondTime[cluster_index]);
509 const int cells_per_sampling = ed.m_moments->nCellSampling[sampl][cluster_index];
511 if (cells_per_sampling > 0)
513 sampling_pattern |= (0x1U << sampl);
520 const int cells_per_sampling = ed.m_moments->nCellSampling[sampl][cluster_index];
522 if (cells_per_sampling > 0)
538 #define CALORECGPU_MOMENTS_CONVERSION_HELPER(MOMENT_ENUM, MOMENT_ARRAY) \
539 if (m_momentsToDo[xAOD::CaloCluster:: MOMENT_ENUM ] ) \
541 cluster->insertMoment(xAOD::CaloCluster:: MOMENT_ENUM , ed.m_moments-> MOMENT_ARRAY [cluster_index]); \
545 #define CALORECGPU_MOMENTS_CONVERSION_INVALID(MOMENT_ENUM) \
546 if (m_momentsToDo[xAOD::CaloCluster:: MOMENT_ENUM ] ) \
548 ATH_MSG_WARNING("Moment '" << # MOMENT_ENUM << \
549 "' given as a calculated moment, but not yet supported on the GPU side..."); \
607 const int extra_sampling_count = ed.m_moments->nExtraCellSampling[cluster_index];
608 if (extra_sampling_count > 0)
658 record_times(ctx.evt(),
659 time_cast(
start, pre_processing),
660 time_cast(pre_processing, cluster_number),
661 time_cast(cluster_number,
clusters),
663 time_cast(
cells, end_cell_cycle),
664 time_cast(end_cell_cycle, ordered),
665 time_cast(ordered, pre_moments),
666 time_cast(pre_moments, post_moments),
667 time_cast(post_moments,
end)
672 return StatusCode::SUCCESS;
681 print_times(
"Preprocessing Cluster_Number Clusters Cells Cell_Cycle Ordering Cluster_Creation Moments_Transfer Moments_Fill", 9);
683 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.
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
@ 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
Fill the @xAODCaloClusterContainer with the relevant information.