62 size_struct global_counts, global_cluster_counts;
64 std::vector<int> cluster_max_cell(clusters->number, -1);
65 std::vector<float> cluster_max_snr(clusters->number, -9e99);
66 std::vector<float> cluster_max_energy(clusters->number, -9e99);
68 std::vector<size_struct> cluster_counts(clusters->number);
70 if (clusters->has_cells_per_cluster())
72 for (
int i = 0; i < cell_info->number; ++i)
74 if (!cell_info->is_valid(i))
79 const int gain = cell_info->gain[i];
82 const float energy = cell_info->energy[i];
84 const float SNR = std::abs( energy / cell_noise->get_noise(cell_info->hashID[i], gain) );
100 ++global_counts.invalid;
104 std::vector<char> counted_cells(
NCaloCells, 0);
106 for (
int i = 0; i < clusters->number_cells; ++i)
108 const int cell_index = clusters->cells.indices[i];
109 const int cell_hash_ID = cell_info->hashID[cell_index];
112 const int gain = cell_info->gain[cell_index];
115 const float energy = cell_info->energy[cell_index];
117 const float SNR = std::abs( energy / cell_noise->get_noise(cell_hash_ID, gain) );
119 const bool is_new_cell = !counted_cells[cell_index];
123 counted_cells[cell_index] = 1;
124 ++global_cluster_counts.total;
127 const int cluster_index = clusters->clusterIndices[i];
129 if (SNR > cluster_max_snr[cluster_index] || (SNR == cluster_max_snr[cluster_index] && cell_hash_ID > cluster_max_cell[cluster_index]))
131 cluster_max_snr[cluster_index] = SNR;
132 cluster_max_cell[cluster_index] = cell_hash_ID;
133 cluster_max_energy[cluster_index] = std::abs(energy);
138 global_cluster_counts.seed += is_new_cell;
139 ++cluster_counts[cluster_index].seed;
143 global_cluster_counts.grow += is_new_cell;
144 ++cluster_counts[cluster_index].grow;
148 global_cluster_counts.term += is_new_cell;
149 ++cluster_counts[cluster_index].term;
153 global_cluster_counts.invalid += is_new_cell;
154 ++cluster_counts[cluster_index].invalid;
158 ++cluster_counts[cluster_index].total;
160 global_cluster_counts.shared += !is_new_cell;
161 cluster_counts[cluster_index].shared += !is_new_cell;
168 for (
int i = 0; i < cell_info->number; ++i)
170 if (!cell_info->is_valid(i))
175 const int gain = cell_info->gain[i];
178 const float energy = cell_info->energy[i];
180 const float SNR = std::abs( energy / cell_noise->get_noise(cell_info->hashID[i], gain) );
182 const ClusterTag tag = clusters->cells.tags[i];
184 const bool is_cluster = tag.is_part_of_cluster();
186 global_cluster_counts.total += is_cluster;
190 ++global_counts.seed;
191 global_cluster_counts.seed += is_cluster;
195 ++global_counts.grow;
196 global_cluster_counts.grow += is_cluster;
200 ++global_counts.term;
201 global_cluster_counts.term += is_cluster;
205 ++global_counts.invalid;
206 global_cluster_counts.invalid += is_cluster;
211 const int cluster = tag.cluster_index();
212 const int other_cluster = tag.is_shared_between_clusters() ? tag.secondary_cluster_index() : cluster;
213 if (!tag.is_shared_between_clusters() && (SNR > cluster_max_snr[cluster] || (SNR == cluster_max_snr[cluster] && i > cluster_max_cell[cluster])))
215 cluster_max_snr[cluster] = SNR;
216 cluster_max_cell[cluster] = i;
217 cluster_max_energy[cluster] = std::abs(energy);
219 ++cluster_counts[cluster].total;
220 cluster_counts[other_cluster].total += (cluster != other_cluster);
222 global_cluster_counts.shared += tag.is_shared_between_clusters();
223 cluster_counts[cluster].shared += tag.is_shared_between_clusters();
224 cluster_counts[other_cluster].shared += tag.is_shared_between_clusters();
228 ++cluster_counts[cluster].seed;
229 cluster_counts[other_cluster].seed += (cluster != other_cluster);
233 ++cluster_counts[cluster].grow;
234 cluster_counts[other_cluster].grow += (cluster != other_cluster);
238 ++cluster_counts[cluster].term;
239 cluster_counts[other_cluster].term += (cluster != other_cluster);
243 ++cluster_counts[cluster].invalid;
244 cluster_counts[other_cluster].invalid += (cluster != other_cluster);
250 std::map<int, cluster_info_struct> cluster_sizes;
252 for (
int i = 0; i < clusters->number; ++i)
254 if (cluster_max_cell[i] >= 0)
256 cluster_sizes[cluster_max_cell[i]] = cluster_info_struct{cluster_counts[i], cluster_max_snr[i], cluster_max_energy[i]};
263 return StatusCode::FAILURE;
269 std::ofstream out_file(save_file);
271 if (!out_file.is_open())
273 return StatusCode::FAILURE;
276 out_file <<
"Cell counts: " << global_counts <<
"\n\n";
278 out_file <<
"Cells in clusters count: " << global_cluster_counts <<
"\n\n";
279 out_file <<
"Clusters:\n\n";
281 for (
const auto & it : cluster_sizes)
283 out_file << it.first <<
" " << it.second <<
"\n";
286 out_file << std::endl;
288 if (!out_file.good())
290 return StatusCode::FAILURE;
295 return StatusCode::SUCCESS;