18 base_class(
type, name, parent)
28 return StatusCode::SUCCESS;
35 unsigned int total = 0, seed = 0, grow = 0, term = 0, invalid = 0, shared = 0;
37 friend Str &
operator << (Str & s,
const size_struct & sst)
39 s << sst.total <<
" " << sst.seed <<
" " << sst.grow <<
" " << sst.term <<
" " << sst.invalid <<
" " << sst.shared;
44struct cluster_info_struct
47 float seed_snr = -9e99;
48 float seed_energy = -9e99;
51 friend Str &
operator << (Str & s,
const cluster_info_struct & cis)
53 s << cis.seed_index <<
" " << cis.size <<
" (" << cis.seed_snr <<
" " << cis.seed_energy <<
")";
64 if ( !cell_collection.
isValid() )
66 ATH_MSG_ERROR(
" Cannot retrieve CaloCellContainer: " << cell_collection.
name() );
67 return StatusCode::FAILURE;
72 const CaloNoise * noise_tool = *noise_handle;
76 size_struct global_counts, global_cluster_counts;
82 const float energy = cell->energy();
84 float SNR = energy / noise_tool->
getNoise(
m_calo_id->calo_cell_hash(cell->ID()), cell->gain());
102 ++global_counts.term;
106 ++global_counts.invalid;
110 struct cluster_cell_info
113 double w_1 = -1, w_2 = -1, energy = -9e99, SNR = -9e99;
114 void add_cluster(
const int cell_id,
const xAOD::CaloCluster * cl,
const double w)
121 else if (cl_2 ==
nullptr)
128 std::cout <<
"WARNING! Multiple shared cell: " << cell_id <<
" " << cl_1 <<
" " << cl_2 <<
" " << cl << std::endl;
132 bool is_shared()
const
134 return cl_1 !=
nullptr && cl_2 !=
nullptr;
139 std::map<int, cluster_cell_info> cluster_cells;
148 ATH_MSG_ERROR(
"Can't get valid links to CaloCells (CaloClusterCellLink)!");
149 return StatusCode::FAILURE;
152 for (
auto it = cell_links->
begin(); it != cell_links->
end(); ++it)
155 const float weight = it.weight();
157 const float this_energy = std::abs(cell->energy());
159 const float this_snr = std::abs(this_energy / noise_tool->
getNoise(
m_calo_id->calo_cell_hash(cell->ID()), cell->gain()));
163 auto & info = cluster_cells[this_hash];
165 info.energy = this_energy;
168 info.add_cluster(this_hash, cluster, weight);
173 std::unordered_map<const xAOD::CaloCluster *, cluster_info_struct> cluster_sizes;
175 auto update_clusters = [&](
const cluster_cell_info & cci,
const int cell)
181 auto & c_info = cluster_sizes[cl];
197 ++c_info.size.invalid;
202 ++c_info.size.shared;
206 if (cci.SNR > c_info.seed_snr || (cci.SNR == c_info.seed_snr && cell > c_info.seed_index))
208 c_info.seed_index = cell;
209 c_info.seed_snr = cci.SNR;
210 c_info.seed_energy = cci.energy;
216 if (cci.cl_1 !=
nullptr || cci.cl_2 !=
nullptr)
218 ++global_cluster_counts.total;
221 ++global_cluster_counts.seed;
225 ++global_cluster_counts.grow;
229 ++global_cluster_counts.term;
233 ++global_cluster_counts.invalid;
237 ++global_cluster_counts.shared;
241 update_one(cci.cl_1);
242 update_one(cci.cl_2);
245 for (
auto & it : cluster_cells)
247 update_clusters(it.second, it.first);
250 std::vector<cluster_info_struct> sorted_info;
252 sorted_info.reserve(cluster_sizes.size());
254 for (
auto & v : cluster_sizes)
256 sorted_info.push_back(v.second);
259 std::sort(sorted_info.begin(), sorted_info.end(),
260 [](
const auto &
a,
const auto & b)
262 return a.seed_index < b.seed_index;
269 return StatusCode::FAILURE;
275 std::ofstream out_file(save_file);
277 if (!out_file.is_open())
279 return StatusCode::FAILURE;
282 out_file <<
"Cell counts: " << global_counts <<
"\n\n";
284 out_file <<
"Cells in clusters count: " << global_cluster_counts <<
"\n\n";
285 out_file <<
"Clusters:\n\n";
287 for (
const auto & info : sorted_info)
289 out_file << info <<
"\n";
292 out_file << std::endl;
294 if (!out_file.good())
296 return StatusCode::FAILURE;
301 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Data object for each calorimeter readout cell.
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
vector of names of the cell containers to use as input.
Gaudi::Property< float > m_growThreshold
Value to consider for the seed threshold.
Gaudi::Property< float > m_cellThreshold
Value to consider for the seed threshold.
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
Key of the CaloNoise Conditions data object.
virtual StatusCode initialize() override
Gaudi::Property< unsigned int > m_numWidth
The number of digits to reserve for the events.
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *cluster_collection) const override
const CaloCell_ID * m_calo_id
Pointer to Calo ID Helper.
Gaudi::Property< std::string > m_savePath
The path specifying the folder to which the files should be saved.
CaloCellsCounterCPU(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< std::string > m_filePrefix
The prefix of the saved files.
Gaudi::Property< float > m_seedThreshold
Value to consider for the seed threshold.
Gaudi::Property< std::string > m_fileSuffix
The suffix of the saved files.
Bookkeeping of cells that make up a cluster Simplified replacement for CaloCellLink,...
const_iterator end() const
const end method
const_iterator begin() const
const begin method
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
static constexpr GainType from_standard_gain(const int gain)
static constexpr GainType min_gain_value()
static constexpr GainType num_gain_values()
DataModel_detail::const_iterator< DataVector > const_iterator
This is a "hash" representation of an Identifier.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const std::string & name() const
Return the StoreGate ID for the referenced object.
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
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.
static std::string build_filename(const std::string &prefix, const std::string &text, const std::string &suffix, const std::string &ext)
static ErrorState prepare_folder_for_output(const std::filesystem::path &folder, const bool output_errors=true)