291 std::vector<int> & cells_prefix_sum)
const
293 if (!clusters->has_cells_per_cluster())
295 for (
int i = 0; i <= clusters->number; ++i)
297 clusters->cellsPrefixSum[i] = 0;
300 for (
int i = 0; i < clusters->number_cells; ++i)
302 clusters->get_extra_cell_info(i) = clusters->cells.tags[i];
307 const int old_num_cells = clusters->number_cells;
308 clusters->number_cells = 0;
309 for (
int i = 0; i < old_num_cells; ++i)
311 ClusterTag this_tag = clusters->get_extra_cell_info(i);
320 if (second_cluster >= 0)
322 if (second_cluster >= clusters->number)
324 ATH_MSG_WARNING(
"Impossible cell assignment: " << i <<
" " << second_cluster <<
" (" << std::hex << this_tag << std::dec <<
")");
326 clusters->cells.indices[clusters->number_cells] = i;
327 clusters->cellWeights[clusters->number_cells] = secondary_cluster_weight;
328 clusters->clusterIndices[clusters->number_cells] = second_cluster;
329 clusters->number_cells += 1;
330 clusters->cellsPrefixSum[second_cluster + 1] += 1;
333 if (first_cluster >= 0)
335 if (first_cluster >= clusters->number)
337 ATH_MSG_WARNING(
"Impossible cell assignment: " << i <<
" " << first_cluster <<
" (" << std::hex << this_tag << std::dec <<
")");
339 clusters->cells.indices[clusters->number_cells] = i;
340 clusters->cellWeights[clusters->number_cells] = 1.0f - secondary_cluster_weight;
341 clusters->clusterIndices[clusters->number_cells] = first_cluster;
342 clusters->number_cells += 1;
343 clusters->cellsPrefixSum[first_cluster + 1] += 1;
347 for (
int i = 0; i <= clusters->number; ++i)
349 prefix += clusters->cellsPrefixSum[i];
351 clusters->cellsPrefixSum[i] = prefix;
358 std::vector<int> cell_orderer(clusters->number_cells);
360 std::iota(cell_orderer.begin(), cell_orderer.end(), 0);
362 std::sort(cell_orderer.begin(), cell_orderer.end(), [&](
const int a,
const int b)
364 if (clusters->cells.indices[a] == clusters->cells.indices[b])
366 return clusters->cellWeights[a] < clusters->cellWeights[b];
370 const int hash_ID_a = cell_info->get_hash_ID(clusters->cells.indices[a]);
371 const int hash_ID_b = cell_info->get_hash_ID(clusters->cells.indices[b]);
374 ATH_MSG_WARNING(
"Attempting to sort impossible cell: " << a <<
" " << hash_ID_a);
378 ATH_MSG_WARNING(
"Attempting to sort impossible cell: " << b <<
" " << hash_ID_b);
380 return hash_ID_a < hash_ID_b;
384 auto order_array = [&](
auto *
ptr)
386 std::vector<std::decay_t<
decltype(
ptr[0])>> prev(
clusters->number_cells);
388 for (
int i = 0;
i <
clusters->number_cells; ++
i)
393 for (
int i = 0;
i <
clusters->number_cells; ++
i)
395 ptr[
i] = prev[cell_orderer[
i]];
399 order_array(
clusters->cells.indices);
401 order_array(
clusters->clusterIndices);
403 cells_prefix_sum.clear();
406 int prev_cell_index = -1;
409 for (
int i = 0;
i <
clusters->number_cells; ++
i)
411 const int this_cell_index =
clusters->cells.indices[
i];
413 if (this_cell_index != prev_cell_index)
417 const int prev_cell_ID = (prev_cell_index < 0 ? -1 : cell_info->get_hash_ID(prev_cell_index));
418 const int this_cell_ID = cell_info->get_hash_ID(this_cell_index);
420 for (
int j = prev_cell_ID + 1;
j <= this_cell_ID; ++
j)
422 cells_prefix_sum[
j] = cell_count;
428 prev_cell_index = this_cell_index;
435 cells_prefix_sum[
i + 1] = cell_count;
439 return StatusCode::SUCCESS;
494 const std::vector<int> & cells_prefix_sum_1,
495 const std::vector<int> & cells_prefix_sum_2,
498 const bool match_in_energy,
499 const bool match_without_shared)
const
507 std::vector<double> similarity_map(cluster_info_1.
number * cluster_info_2.
number, 0.);
509 std::vector<double> ref_normalization(cluster_info_1.
number, 0.);
510 std::vector<double> test_normalization(cluster_info_2.
number, 0.);
512 auto calculate_weight = [&](
const int cell)
514 double SNR = 0.00001;
516 if (!cell_info_1.
is_bad(cell))
518 const int gain = cell_info_1.
gain[cell];
521 if (std::isfinite(cellNoise) && cellNoise > 0.0f)
523 SNR = std::abs(cell_info_1.
energy[cell] / cellNoise);
527 const double quantity = ( match_in_energy ? std::abs(cell_info_1.
energy[cell]) : SNR );
528 const double weight = (quantity + 1e-7) *
538 return weight + 1e-8;
541 auto matched_clusters = [&](
const int hash_ID,
const std::vector<std::pair<int, float>> & v1,
const std::vector<std::pair<int, float>> & v2)
543#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS && CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS > 1
544 msg(MSG::INFO) <<
"MATCH: " << hash_ID <<
" " << calculate_weight(cell_info_1.
get_cell_with_hash_ID(hash_ID)) <<
" |";
545 for (
const auto & p : v1)
547 msg() <<
" (" << p.first <<
", " << p.second <<
")";
550 for (
const auto & p : v2)
552 msg() <<
" (" << p.first <<
", " << p.second <<
")";
557 if (match_without_shared && (v1.size() > 1 || v2.size() > 1))
564 for (
const auto & p1 : v1)
566 for (
const auto & p2 : v2)
568 similarity_map[p2.first * cluster_info_1.
number + p1.first] += weight * p1.second * p2.second;
572 for (
const auto & p1 : v1)
574 ref_normalization[p1.first] += weight * p1.second * p1.second;
577 for (
const auto & p2 : v2)
579 test_normalization[p2.first] += weight * p2.second * p2.second;
583 auto unmatched_clusters = [&](
const bool is_test,
const int hash_ID,
const std::vector<std::pair<int, float>> & v)
585#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS
586 msg(MSG::INFO) <<
"UNMATCH: " << hash_ID <<
" " << calculate_weight(cell_info_1.
get_cell_with_hash_ID(hash_ID)) <<
" | " << is_test <<
" |";
587 for (
const auto & p : v)
589 msg() <<
" (" << p.first <<
", " << p.second <<
")";
594 if (match_without_shared && v.size() > 1)
601 std::vector<double> & normalization = (is_test ? test_normalization : ref_normalization);
603 for (
const auto & p : v)
605 normalization[p.first] += weight * p.second * p.second;
610 cells_prefix_sum_1, cells_prefix_sum_2,
611 cluster_info_1, cluster_info_2,
612 matched_clusters, unmatched_clusters);
614 for (
int testc = 0; testc < cluster_info_2.
number; ++testc)
616 const double test_norm = test_normalization[testc] + double(test_normalization[testc] == 0.);
617 for (
int refc = 0; refc < cluster_info_1.
number; ++refc)
619 const double ref_norm = ref_normalization[refc] + double(ref_normalization[refc] == 0.);
620 similarity_map[testc * cluster_info_1.
number + refc] /= std::sqrt(ref_norm * test_norm);
626 std::vector<std::vector<int>> sorted_GPU_matches;
628 sorted_GPU_matches.reserve(cluster_info_2.
number);
630 for (
int testc = 0; testc < cluster_info_2.
number; ++testc)
632 std::vector<int> sorter(cluster_info_1.
number);
633 std::iota(sorter.begin(), sorter.end(), 0);
636 [&](
const int a,
const int b)
638 const double a_weight = similarity_map[testc * cluster_info_1.number + a];
639 const double b_weight = similarity_map[testc * cluster_info_1.number + b];
640 return a_weight > b_weight;
644 size_t wanted_size = 0;
646 for (; wanted_size < sorter.size(); ++wanted_size)
648 const double match_weight = similarity_map[testc * cluster_info_1.
number + sorter[wanted_size]];
661 sorter.resize(wanted_size);
663 sorted_GPU_matches.push_back(std::move(sorter));
668 constexpr int max_iter = 32;
670 std::vector<double> matched_weights(cluster_info_1.
number, -1.);
672 std::vector<size_t> skipped_matching(cluster_info_2.
number, 0);
674 for (
int stop_counter = 0; stop_counter < cluster_info_2.
number && num_iter < max_iter; ++num_iter)
677 for (
int testc = 0; testc < int(sorted_GPU_matches.size()); ++testc)
679 if (skipped_matching[testc] < sorted_GPU_matches[testc].size())
681 const int match_c = sorted_GPU_matches[testc][skipped_matching[testc]];
682 const double match_weight = similarity_map[testc * cluster_info_1.
number + match_c];
683 if (match_weight >=
m_min_similarity && match_weight > matched_weights[match_c])
685 const int prev_match = sch.
r2t_table[match_c];
688 ++skipped_matching[prev_match];
692 matched_weights[match_c] = match_weight;
697 ++skipped_matching[testc];
710 for (
size_t i = 0; i < sch.
r2t_table.size(); ++i)
723 for (
size_t i = 0; i < sch.
t2r_table.size(); ++i)
732 char message_buffer[256];
733 snprintf(message_buffer, 256,
734 "%2d: %5d / %5d || %5d / %5d || %3d || %5d | %5d || %5d",
746 return StatusCode::SUCCESS;
923#define CALORECGPU_BASIC_CLUSTER_PROPERTY(NAME, ...) \
924 struct clusters_ ## NAME \
926 static std::string name() \
930 static double get_property([[maybe_unused]] const ConstantDataHolder & constant_data, \
931 [[maybe_unused]] const CaloRecGPU::CellInfoArr & cell_info, \
932 [[maybe_unused]] const CaloRecGPU::ClusterInfoArr & cluster_info, \
933 [[maybe_unused]] const std::vector<int> & cells_prefix_sum, \
934 [[maybe_unused]] const int cluster_index ) \
956#define CALORECGPU_CLUSTER_MOMENT(...) CALORECGPU_CLUSTER_MOMENT_INNER(__VA_ARGS__, 1, 1)
957#define CALORECGPU_CLUSTER_MOMENT_INNER(NAME, PROPERTY, UNIT, ...) CALORECGPU_BASIC_CLUSTER_PROPERTY(moments_ ## NAME, return cluster_info.moments. PROPERTY [cluster_index] / UNIT;)
1040 clusters_number_cells,
1041 clusters_moments_time,
1042 clusters_moments_FIRST_PHI,
1043 clusters_moments_FIRST_ETA,
1044 clusters_moments_SECOND_R,
1045 clusters_moments_SECOND_LAMBDA,
1046 clusters_moments_DELTA_PHI,
1047 clusters_moments_DELTA_THETA,
1048 clusters_moments_DELTA_ALPHA,
1049 clusters_moments_CENTER_X,
1050 clusters_moments_CENTER_Y,
1051 clusters_moments_CENTER_Z,
1052 clusters_moments_CENTER_MAG,
1053 clusters_moments_CENTER_LAMBDA,
1054 clusters_moments_LATERAL,
1055 clusters_moments_LONGITUDINAL,
1056 clusters_moments_ENG_FRAC_EM,
1057 clusters_moments_ENG_FRAC_MAX,
1058 clusters_moments_ENG_FRAC_CORE,
1059 clusters_moments_FIRST_ENG_DENS,
1060 clusters_moments_SECOND_ENG_DENS,
1061 clusters_moments_ISOLATION,
1062 clusters_moments_ENG_BAD_CELLS,
1063 clusters_moments_N_BAD_CELLS,
1064 clusters_moments_N_BAD_CELLS_CORR,
1065 clusters_moments_BAD_CELLS_CORR_E,
1066 clusters_moments_BADLARQ_FRAC,
1067 clusters_moments_ENG_POS,
1068 clusters_moments_SIGNIFICANCE,
1069 clusters_moments_CELL_SIGNIFICANCE,
1070 clusters_moments_CELL_SIG_SAMPLING,
1071 clusters_moments_AVG_LAR_Q,
1072 clusters_moments_AVG_TILE_Q,
1073 clusters_moments_ENG_BAD_HV_CELLS,
1074 clusters_moments_N_BAD_HV_CELLS,
1075 clusters_moments_PTD,
1076 clusters_moments_MASS,
1077 clusters_moments_EM_PROBABILITY,
1078 clusters_moments_HAD_WEIGHT,
1079 clusters_moments_OOC_WEIGHT,
1080 clusters_moments_DM_WEIGHT,
1081 clusters_moments_TILE_CONFIDENCE_LEVEL,
1082 clusters_moments_SECOND_TIME,
1083 clusters_moments_VERTEX_FRACTION,
1084 clusters_moments_NVERTEX_FRACTION,
1085 clusters_moments_ETACALOFRAME,
1086 clusters_moments_PHICALOFRAME,
1087 clusters_moments_ETA1CALOFRAME,
1088 clusters_moments_PHI1CALOFRAME,
1089 clusters_moments_ETA2CALOFRAME,
1090 clusters_moments_PHI2CALOFRAME,
1091 clusters_moments_ENG_CALIB_TOT,
1092 clusters_moments_ENG_CALIB_OUT_L,
1093 clusters_moments_ENG_CALIB_OUT_M,
1094 clusters_moments_ENG_CALIB_OUT_T,
1095 clusters_moments_ENG_CALIB_DEAD_L,
1096 clusters_moments_ENG_CALIB_DEAD_M,
1097 clusters_moments_ENG_CALIB_DEAD_T,
1098 clusters_moments_ENG_CALIB_EMB0,
1099 clusters_moments_ENG_CALIB_EME0,
1100 clusters_moments_ENG_CALIB_TILEG3,
1101 clusters_moments_ENG_CALIB_DEAD_TOT,
1102 clusters_moments_ENG_CALIB_DEAD_EMB0,
1103 clusters_moments_ENG_CALIB_DEAD_TILE0,
1104 clusters_moments_ENG_CALIB_DEAD_TILEG3,
1105 clusters_moments_ENG_CALIB_DEAD_EME0,
1106 clusters_moments_ENG_CALIB_DEAD_HEC0,
1107 clusters_moments_ENG_CALIB_DEAD_FCAL,
1108 clusters_moments_ENG_CALIB_DEAD_LEAKAGE,
1109 clusters_moments_ENG_CALIB_DEAD_UNCLASS,
1110 clusters_moments_ENG_CALIB_FRAC_EM,
1111 clusters_moments_ENG_CALIB_FRAC_HAD,
1112 clusters_moments_ENG_CALIB_FRAC_REST
1170#define CALORECGPU_BASIC_CELL_PROPERTY(NAME, ...) \
1171 struct cells_ ## NAME \
1173 static std::string name() \
1177 static double get_property([[maybe_unused]] const ConstantDataHolder & constant_data, \
1178 [[maybe_unused]] const CaloRecGPU::CellInfoArr & cell_info, \
1179 [[maybe_unused]] const CaloRecGPU::ClusterInfoArr & cluster_info, \
1180 [[maybe_unused]] const std::vector<int> & cells_prefix_sum, \
1181 [[maybe_unused]] const int cell ) \
1195 protect_from_zero(constant_data.m_cell_noise->get_noise(cell_info.get_hash_ID(cell), cell_info.gain[cell]));
1199 protect_from_zero(constant_data.m_cell_noise->get_noise(cell_info.get_hash_ID(cell), cell_info.gain[cell])));)
1222 float max_weight = 0.f;
1224 for (
int i = cells_prefix_sum[cell]; i < cells_prefix_sum[cell + 1]; ++i)
1226 const float this_weight = cluster_info.cellWeights[i];
1227 const int this_index = cluster_info.clusterIndices[i];
1228 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1230 max_weight = this_weight;
1231 max_index = this_index;
1240 float max_weight = 0.f, second_max_weight = 0.f;
1241 int max_index = 0, second_max_index = 0;
1242 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1244 const float this_weight = cluster_info.cellWeights[
i];
1245 const int this_index = cluster_info.clusterIndices[
i];
1246 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1248 second_max_weight = max_weight;
1249 second_max_index = max_index;
1250 max_weight = this_weight;
1251 max_index = this_index;
1253 else if (this_weight > second_max_weight || (this_weight == second_max_weight && this_index > second_max_index))
1255 second_max_weight = this_weight;
1256 second_max_index = this_index;
1259 return second_max_index;
1265 float max_weight = 0.f;
1267 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1269 const float this_weight = cluster_info.cellWeights[
i];
1270 const int this_index = cluster_info.clusterIndices[
i];
1271 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1273 max_weight = this_weight;
1274 max_index = this_index;
1284 float max_weight = 0.f, second_max_weight = 0.f;
1285 int max_index = 0, second_max_index = 0;
1286 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1288 const float this_weight = cluster_info.cellWeights[
i];
1289 const int this_index = cluster_info.clusterIndices[
i];
1290 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1292 second_max_weight = max_weight;
1293 second_max_index = max_index;
1294 max_weight = this_weight;
1295 max_index = this_index;
1297 else if (this_weight > second_max_weight || (this_weight == second_max_weight && this_index > second_max_index))
1299 second_max_weight = this_weight;
1300 second_max_index = this_index;
1303 return second_max_weight;
1307 using BasicCellProperties = multi_class_holder <
1324 cells_number_of_clusters,
1325 cells_primary_cluster_index,
1326 cells_secondary_cluster_index,
1327 cells_primary_weight,
1328 cells_secondary_weight
1389 const std::vector<std::string> histo_strings =
m_moniTool->histogramService()->getHists();
1402 auto string_contains = [](std::string_view container, std::string_view contained) ->
bool
1404 return container.find(contained) != std::string::npos;
1407 auto search_lambda = [&](
const auto & prop,
const size_t count,
bool & check,
1408 const std::string &
str, std::vector<bool> & to_do,
1409 std::string_view prefix =
"", std::string_view suffix =
"")
1411 if (string_contains(
str, std::string(prefix) + prop.name() + std::string(suffix)))
1413 to_do[
count] =
true;
1418 for (
const auto &
str : histo_strings)
1465 if ( string_contains(
str,
"cluster_size_ref") ||
1466 string_contains(
str,
"cluster_size_test") ||
1467 string_contains(
str,
"cluster_delta_size") ||
1468 string_contains(
str,
"cluster_weighted_size_ref") ||
1469 string_contains(
str,
"cluster_weighted_size_test") ||
1470 string_contains(
str,
"cluster_delta_weighted_size") )
1476 else if ( string_contains(
str,
"cluster_size") ||
1477 string_contains(
str,
"cluster_weighted_size") )
1484 if (string_contains(
str,
"cluster_diff_cells"))
1491 if ( string_contains(
str,
"_num_same_E_cells_ref") ||
1492 string_contains(
str,
"_num_same_E_cells_test") ||
1493 string_contains(
str,
"delta_num_same_E_cells") ||
1494 string_contains(
str,
"_num_same_abs_E_cells_ref") ||
1495 string_contains(
str,
"_num_same_abs_E_cells_test") ||
1496 string_contains(
str,
"delta_num_same_abs_E_cells") )
1501 else if ( string_contains(
str,
"_num_same_E_cells") ||
1502 string_contains(
str,
"_num_same_abs_E_cells") )
1508 if ( string_contains(
str,
"_num_same_SNR_cells_ref") ||
1509 string_contains(
str,
"_num_same_SNR_cells_test") ||
1510 string_contains(
str,
"delta_num_same_SNR_cells") ||
1511 string_contains(
str,
"_num_same_abs_SNR_cells_ref") ||
1512 string_contains(
str,
"_num_same_abs_SNR_cells_test") ||
1513 string_contains(
str,
"delta_num_same_abs_SNR_cells") )
1518 else if ( string_contains(
str,
"_num_same_SNR_cells") ||
1519 string_contains(
str,
"_num_same_abs_SNR_cells") )
1526 return StatusCode::SUCCESS;
1535 const std::vector<int> & cells_prefix_sum,
1536 const std::string & tool_name)
const
1538 m_numClustersPerTool[tool_name].fetch_add(clusters->number);
1546 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1547 store_vec[
index].cell_info = *cell_info;
1548 store_vec[
index].clusters = *clusters;
1549 store_vec[
index].cells_prefix_sum = cells_prefix_sum;
1556 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1558 std::unordered_map<std::string, long long int> cell_counts;
1560 cluster_properties[
"size"].resize(clusters->number, 0.);
1561 cluster_properties[
"weighted_size"].resize(clusters->number, 0.);
1563 long long int same_energy = 0, same_abs_energy = 0, same_snr = 0, same_abs_snr = 0;
1565 std::set<double> energies, snrs;
1570 for (
int cell = 0; cell < cell_info->
number; ++cell)
1581 cell_properties[prop.name()].push_back(prop.get_property(constant_data, *cell_info, *clusters, cells_prefix_sum, cell));
1583 }, BasicCellProperties{});
1589 cell_counts[prop.name()] += prop.is_type(constant_data, *cell_info, *clusters, cells_prefix_sum, cell);
1591 }, BasicCellTypes{});
1593 const float this_energy = cell_info->
energy[cell];
1598 if (energies.count(this_energy))
1603 else if (energies.count(-this_energy))
1607 energies.insert(this_energy);
1615 if (snrs.count(this_snr))
1620 else if (snrs.count(-this_snr))
1624 snrs.insert(this_snr);
1630 for (
int i = 0; i < clusters->number_cells; ++i)
1632 const int this_cluster = clusters->clusterIndices[i];
1633 const float this_weight = clusters->cellWeights[i];
1635 cluster_properties[
"size"][this_cluster] += 1;
1636 cluster_properties[
"weighted_size"][this_cluster] += this_weight;
1643 for (
int cluster = 0; cluster < clusters->number; ++cluster)
1649 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, *cell_info, *clusters, cells_prefix_sum, cluster));
1651 }, BasicClusterProperties{});
1656 using scalar_type =
decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
1658 std::vector<coll_type> collections;
1659 std::vector<scalar_type> count_scalars;
1660 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
1662 collections.reserve(cluster_properties.size() + cell_properties.size());
1663 count_scalars.reserve(cell_counts.size());
1664 cluster_group.reserve(cluster_properties.size());
1665 cell_group.reserve(cell_properties.size());
1666 counts_group.reserve(cell_counts.size() + 5);
1668 auto mon_clus_num =
Monitored::Scalar(prefix +
"_num_clusters", clusters->number);
1669 auto mon_same_energy =
Monitored::Scalar(prefix +
"_num_same_E_cells", same_energy);
1670 auto mon_same_abs_energy =
Monitored::Scalar(prefix +
"_num_same_abs_E_cells", same_abs_energy);
1671 auto mon_same_snr =
Monitored::Scalar(prefix +
"_num_same_SNR_cells", same_snr);
1672 auto mon_same_abs_snr =
Monitored::Scalar(prefix +
"_num_same_abs_SNR_cells", same_abs_snr);
1674 counts_group.push_back(std::ref(mon_clus_num));
1675 counts_group.push_back(std::ref(mon_same_energy));
1676 counts_group.push_back(std::ref(mon_same_abs_energy));
1677 counts_group.push_back(std::ref(mon_same_snr));
1678 counts_group.push_back(std::ref(mon_same_abs_snr));
1684 for (
const auto & k_v : cluster_properties)
1687 cluster_group.push_back(std::ref(collections.back()));
1690 for (
const auto & k_v : cell_properties)
1693 cell_group.push_back(std::ref(collections.back()));
1696 for (
const auto & k_v : cell_counts)
1698 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_num_" + k_v.first +
"_cells", k_v.second));
1699 counts_group.push_back(std::ref(count_scalars.back()));
1710 return StatusCode::SUCCESS;
1718 const std::string & prefix,
1719 const bool match_in_energy,
1720 const bool match_without_shared,
1721 const bool match_perfectly)
const
1729 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1733 const std::vector<int> & cells_prefix_sum_1 = store_vec[index_1].cells_prefix_sum;
1737 const std::vector<int> & cells_prefix_sum_2 = store_vec[index_2].cells_prefix_sum;
1741 if (match_perfectly)
1744 cell_info_1, cell_info_2,
1745 cells_prefix_sum_1, cells_prefix_sum_2,
1746 clusters_1, clusters_2,
1747 match_without_shared) );
1752 cell_info_1, cell_info_2,
1753 cells_prefix_sum_1, cells_prefix_sum_2,
1754 clusters_1, clusters_2,
1755 match_in_energy, match_without_shared) );
1758 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1760 std::unordered_map<std::string, long long int> cell_counts;
1762 std::vector<double> ref_size_vec(clusters_1.
number, 0.), test_size_vec(clusters_2.
number, 0.),
1763 ref_weighted_size_vec(clusters_1.
number, 0.), test_weighted_size_vec(clusters_2.
number, 0.),
1764 ref_diff_cells(clusters_1.
number, 0.), test_diff_cells(clusters_2.
number, 0.),
1765 ref_diff_cells_weight(clusters_1.
number, 0.), test_diff_cells_weight(clusters_2.
number, 0.);
1768 long long int same_energy_1 = 0, same_energy_2 = 0,
1769 same_abs_energy_1 = 0, same_abs_energy_2 = 0,
1770 same_snr_1 = 0, same_snr_2 = 0,
1771 same_abs_snr_1 = 0, same_abs_snr_2 = 0,
1772 same_cluster_cells_count = 0, diff_cluster_cells_count = 0;
1774 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1778 for (
int cell = 0; cell <
NCaloCells; ++cell)
1782 if ( cell >= cell_info_1.
number ||
1783 cell >= cell_info_2.
number ||
1794 const auto prop_1 = prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cell);
1795 const auto prop_2 = prop.get_property(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2, cell);
1797 cell_properties[prop.name() +
"_ref"].push_back(prop_1);
1798 cell_properties[prop.name() +
"_test"].push_back(prop_2);
1800 cell_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1801 cell_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_1)));
1802 cell_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_2)));
1804 }, BasicCellProperties{});
1810 const auto is_1 = prop.is_type(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cell);
1811 const auto is_2 = prop.is_type(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2, cell);
1813 cell_counts[
"num_" + prop.name() +
"_cells_ref"] += is_1;
1814 cell_counts[
"num_" + prop.name() +
"_cells_test"] += is_2;
1815 cell_counts[
"delta_num_" + prop.name() +
"_cells"] += is_2 - is_1;
1817 }, BasicCellTypes{});
1819 const float this_energy_1 = cell_info_1.
energy[cell];
1820 const float this_energy_2 = cell_info_2.
energy[cell];
1824 if (energies_1.count(this_energy_1))
1827 ++same_abs_energy_1;
1829 else if (energies_1.count(-this_energy_1))
1831 ++same_abs_energy_1;
1833 energies_1.insert(this_energy_1);
1835 if (energies_2.count(this_energy_2))
1838 ++same_abs_energy_2;
1840 else if (energies_2.count(-this_energy_2))
1842 ++same_abs_energy_2;
1844 energies_2.insert(this_energy_2);
1851 if (snrs_1.count(this_snr_1))
1856 else if (snrs_1.count(-this_snr_1))
1860 snrs_1.insert(this_snr_1);
1865 if (snrs_2.count(this_snr_2))
1870 else if (snrs_2.count(-this_snr_2))
1874 snrs_2.insert(this_snr_2);
1879 bool cell_is_diff =
false;
1881 for (
int i = cells_prefix_sum_1[cell]; i < cells_prefix_sum_1[cell + 1] && i < cell_info_1.
number; ++i)
1884 const float this_weight = clusters_1.
cellWeights[i];
1885 bool found_match =
false;
1886 for (
int j = cells_prefix_sum_2[cell]; j < cells_prefix_sum_2[cell + 1] && j < cell_info_2.
number; ++j)
1894 ref_size_vec[this_index] += 1;
1895 ref_weighted_size_vec[this_index] += this_weight;
1898 ref_diff_cells[this_index] += 1;
1899 ref_diff_cells_weight[this_index] += this_weight;
1900 cell_is_diff =
true;
1904 for (
int i = cells_prefix_sum_2[cell]; i < cells_prefix_sum_2[cell + 1] && i < cell_info_2.
number; ++i)
1907 const float this_weight = clusters_2.
cellWeights[i];
1908 bool found_match =
false;
1909 for (
int j = cells_prefix_sum_1[cell]; j < cells_prefix_sum_1[cell + 1] && j < cell_info_1.
number; ++j)
1917 test_size_vec[this_index] += 1;
1918 test_weighted_size_vec[this_index] += this_weight;
1921 test_diff_cells[this_index] += 1;
1922 test_diff_cells_weight[this_index] += this_weight;
1923 cell_is_diff =
true;
1929#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS
1930 msg(MSG::INFO) <<
"Diff: " << cell <<
" |";
1931 for (
int i = cells_prefix_sum_1[cell]; i < cells_prefix_sum_1[cell + 1] && i < cell_info_1.
number; ++i)
1936 for (
int i = cells_prefix_sum_2[cell]; i < cells_prefix_sum_2[cell + 1] && i < cell_info_2.
number; ++i)
1943 ++diff_cluster_cells_count;
1945 else if ((cells_prefix_sum_1[cell + 1] > cells_prefix_sum_1[cell]) || (cells_prefix_sum_2[cell + 1] > cells_prefix_sum_2[cell]))
1947 ++same_cluster_cells_count;
1956 for (
int cluster = 0; cluster < clusters_1.
number; ++cluster)
1958 const int match = sch.
r2t(cluster);
1969 const auto prop_1 = prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cluster);
1970 const auto prop_2 = prop.get_property(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2,
match);
1972 cluster_properties[prop.name() +
"_ref"].push_back(prop_1);
1973 cluster_properties[prop.name() +
"_test"].push_back(prop_2);
1975 cluster_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1976 cluster_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_1)));
1977 cluster_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_2)));
1979 }, BasicClusterProperties{});
1985 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cluster,
1986 cell_info_2, clusters_2, cells_prefix_sum_2,
match));
1988 }, ComparedClusterProperties{});
1992 cluster_properties[
"size_ref"].push_back(ref_size_vec[cluster]);
1993 cluster_properties[
"size_test"].push_back(test_size_vec[
match]);
1994 cluster_properties[
"delta_size"].push_back(ref_size_vec[cluster] - test_size_vec[
match]);
1995 cluster_properties[
"delta_size_rel_ref"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) /
protect_from_zero(ref_size_vec[cluster]));
1996 cluster_properties[
"delta_size_rel_test"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) /
protect_from_zero(test_size_vec[
match]));
1998 cluster_properties[
"weighted_size_ref"].push_back(ref_weighted_size_vec[cluster]);
1999 cluster_properties[
"weighted_size_test"].push_back(test_weighted_size_vec[
match]);
2000 cluster_properties[
"delta_weighted_size"].push_back(ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]);
2001 cluster_properties[
"delta_weighted_size_rel_ref"].push_back((ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]) /
protect_from_zero(ref_weighted_size_vec[cluster]));
2002 cluster_properties[
"delta_weighted_size_rel_test"].push_back((ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]) /
protect_from_zero(test_weighted_size_vec[
match]));
2007 cluster_properties[
"diff_cells_ref"].push_back(ref_diff_cells[cluster]);
2008 cluster_properties[
"diff_cells_ref_rel_size"].push_back(ref_diff_cells[cluster] /
protect_from_zero(ref_size_vec[cluster]));
2009 cluster_properties[
"diff_cells_test"].push_back(test_diff_cells[
match]);
2011 cluster_properties[
"diff_cells"].push_back(ref_diff_cells[cluster] + test_diff_cells[
match]);
2013 cluster_properties[
"weighted_diff_cells_ref"].push_back(ref_diff_cells_weight[cluster]);
2014 cluster_properties[
"weighted_diff_cells_ref_rel_size"].push_back(ref_diff_cells_weight[cluster] /
protect_from_zero(ref_weighted_size_vec[cluster]));
2015 cluster_properties[
"weighted_diff_cells_test"].push_back(test_diff_cells_weight[
match]);
2016 cluster_properties[
"weighted_diff_cells_test_rel_size"].push_back(test_diff_cells_weight[
match] /
protect_from_zero(test_weighted_size_vec[
match]));
2017 cluster_properties[
"weighted_diff_cells"].push_back(ref_diff_cells_weight[cluster] + test_diff_cells_weight[
match]);
2023 using scalar_type =
decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
2025 std::vector<coll_type> collections;
2026 std::vector<scalar_type> count_scalars;
2027 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
2029 collections.reserve(cluster_properties.size() + cell_properties.size());
2030 count_scalars.reserve(cell_counts.size() + 6 * 3);
2031 cluster_group.reserve(cluster_properties.size());
2032 cell_group.reserve(cell_properties.size());
2033 counts_group.reserve(cell_counts.size() + 3 + 6 * 3);
2035 auto add_count_vars = [&](
const std::string & name,
const long long int ref_num,
const long long int test_num)
2037 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + name +
"_ref", ref_num));
2038 counts_group.push_back(std::ref(count_scalars.back()));
2040 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + name +
"_test", test_num));
2041 counts_group.push_back(std::ref(count_scalars.back()));
2043 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_delta_" + name, test_num - ref_num));
2044 counts_group.push_back(std::ref(count_scalars.back()));
2047 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2050 add_count_vars(
"num_same_E_cells", same_energy_1, same_energy_2);
2051 add_count_vars(
"num_same_abs_E_cells", same_abs_energy_1, same_abs_energy_2);
2052 add_count_vars(
"num_same_SNR_cells", same_snr_1, same_snr_2);
2053 add_count_vars(
"num_same_abs_SNR_cells", same_abs_snr_1, same_abs_snr_2);
2056 auto mon_same_cluster_cell =
Monitored::Scalar(prefix +
"_same_cluster_cells", same_cluster_cells_count);
2057 auto mon_diff_cluster_cell =
Monitored::Scalar(prefix +
"_diff_cluster_cells", diff_cluster_cells_count);
2061 ATH_MSG_INFO(
"Different cells: " << diff_cluster_cells_count);
2064 counts_group.push_back(std::ref(mon_total_unmatched));
2065 counts_group.push_back(std::ref(mon_same_cluster_cell));
2066 counts_group.push_back(std::ref(mon_diff_cluster_cell));
2068 for (
const auto & k_v : cluster_properties)
2071 cluster_group.push_back(std::ref(collections.back()));
2074 for (
const auto & k_v : cell_properties)
2077 cell_group.push_back(std::ref(collections.back()));
2080 for (
const auto & k_v : cell_counts)
2082 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + k_v.first, k_v.second));
2083 counts_group.push_back(std::ref(count_scalars.back()));
2093 return StatusCode::SUCCESS;