292 std::vector<int> & cells_prefix_sum)
const
294 if (!clusters->has_cells_per_cluster())
296 for (
int i = 0; i <= clusters->number; ++i)
298 clusters->cellsPrefixSum[i] = 0;
301 for (
int i = 0; i < clusters->number_cells; ++i)
303 clusters->get_extra_cell_info(i) = clusters->cells.tags[i];
308 const int old_num_cells = clusters->number_cells;
309 clusters->number_cells = 0;
310 for (
int i = 0; i < old_num_cells; ++i)
312 ClusterTag this_tag = clusters->get_extra_cell_info(i);
321 if (second_cluster >= 0)
323 if (second_cluster >= clusters->number)
325 ATH_MSG_WARNING(
"Impossible cell assignment: " << i <<
" " << second_cluster <<
" (" << std::hex << this_tag << std::dec <<
")");
327 clusters->cells.indices[clusters->number_cells] = i;
328 clusters->cellWeights[clusters->number_cells] = secondary_cluster_weight;
329 clusters->clusterIndices[clusters->number_cells] = second_cluster;
330 clusters->number_cells += 1;
331 clusters->cellsPrefixSum[second_cluster + 1] += 1;
334 if (first_cluster >= 0)
336 if (second_cluster >= clusters->number)
338 ATH_MSG_WARNING(
"Impossible cell assignment: " << i <<
" " << first_cluster <<
" (" << std::hex << this_tag << std::dec <<
")");
340 clusters->cells.indices[clusters->number_cells] = i;
341 clusters->cellWeights[clusters->number_cells] = 1.0f - secondary_cluster_weight;
342 clusters->clusterIndices[clusters->number_cells] = first_cluster;
343 clusters->number_cells += 1;
344 clusters->cellsPrefixSum[first_cluster + 1] += 1;
348 for (
int i = 0; i <= clusters->number; ++i)
350 prefix += clusters->cellsPrefixSum[i];
352 clusters->cellsPrefixSum[i] = prefix;
359 std::vector<int> cell_orderer(clusters->number_cells);
361 std::iota(cell_orderer.begin(), cell_orderer.end(), 0);
363 std::sort(cell_orderer.begin(), cell_orderer.end(), [&](
const int a,
const int b)
365 if (clusters->cells.indices[a] == clusters->cells.indices[b])
367 return clusters->cellWeights[a] < clusters->cellWeights[b];
371 return clusters->cells.indices[a] < clusters->cells.indices[b];
375 auto order_array = [&](
auto * ptr)
377 std::vector<std::decay_t<
decltype(ptr[0])>> prev(clusters->number_cells);
379 for (
int i = 0; i < clusters->number_cells; ++i)
384 for (
int i = 0;
i <
clusters->number_cells; ++
i)
386 ptr[
i] = prev[cell_orderer[
i]];
390 order_array(
clusters->cells.indices);
392 order_array(
clusters->clusterIndices);
394 cells_prefix_sum.clear();
400 for (
int i = 0;
i <
clusters->number_cells; ++
i)
402 const int this_cell =
clusters->cells.indices[
i];
404 if (this_cell != prev_cell)
406 for (
int j = prev_cell + 1; j <= this_cell; ++j)
408 cells_prefix_sum[j] = cell_count;
414 prev_cell = this_cell;
421 cells_prefix_sum[
i + 1] = cell_count;
425 return StatusCode::SUCCESS;
514 const bool match_in_energy,
515 const bool match_without_shared)
const
523 std::vector<double> similarity_map(cluster_info_1.
number * cluster_info_2.
number, 0.);
525 std::vector<double> ref_normalization(cluster_info_1.
number, 0.);
526 std::vector<double> test_normalization(cluster_info_2.
number, 0.);
528 auto calculate_weight = [&](
const int cell)
530 double SNR = 0.00001;
532 if (!cell_info.
is_bad(cell))
534 const int gain = cell_info.
gain[cell];
537 if (std::isfinite(cellNoise) && cellNoise > 0.0f)
539 SNR = std::abs(cell_info.
energy[cell] / cellNoise);
543 const double quantity = ( match_in_energy ? std::abs(cell_info.
energy[cell]) : SNR );
544 const double weight = (quantity + 1e-7) *
554 return weight + 1e-8;
557 auto matched_clusters = [&](
const int cell,
const std::vector<std::pair<int, float>> & v1,
const std::vector<std::pair<int, float>> & v2)
559#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS
560 msg(MSG::INFO) <<
"MATCH: " << cell <<
" " << calculate_weight(cell) <<
" |";
561 for (
const auto & p : v1)
563 msg() <<
" (" << p.first <<
", " << p.second <<
")";
566 for (
const auto & p : v2)
568 msg() <<
" (" << p.first <<
", " << p.second <<
")";
573 if (match_without_shared && (v1.size() > 1 || v2.size() > 1))
578 const float weight = calculate_weight(cell);
580 for (
const auto & p1 : v1)
582 for (
const auto & p2 : v2)
584 similarity_map[p2.first * cluster_info_1.
number + p1.first] += weight * p1.second * p2.second;
588 for (
const auto & p1 : v1)
590 ref_normalization[p1.first] += weight * p1.second * p1.second;
593 for (
const auto & p2 : v2)
595 test_normalization[p2.first] += weight * p2.second * p2.second;
599 auto unmatched_clusters = [&](
const bool is_test,
const int cell,
const std::vector<std::pair<int, float>> & v)
601#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS
602 msg(MSG::INFO) <<
"UNMATCH: " << cell <<
" " << calculate_weight(cell) <<
" | " << is_test <<
" |";
603 for (
const auto & p : v)
605 msg() <<
" (" << p.first <<
", " << p.second <<
")";
610 if (match_without_shared && v.size() > 1)
615 const float weight = calculate_weight(cell);
617 std::vector<double> & normalization = (is_test ? test_normalization : ref_normalization);
619 for (
const auto & p : v)
621 normalization[p.first] += weight * p.second * p.second;
627 for (
int testc = 0; testc < cluster_info_2.
number; ++testc)
629 const double test_norm = test_normalization[testc] + double(test_normalization[testc] == 0.);
630 for (
int refc = 0; refc < cluster_info_1.
number; ++refc)
632 const double ref_norm = ref_normalization[refc] + double(ref_normalization[refc] == 0.);
633 similarity_map[testc * cluster_info_1.
number + refc] /= std::sqrt(ref_norm * test_norm);
639 std::vector<std::vector<int>> sorted_GPU_matches;
641 sorted_GPU_matches.reserve(cluster_info_2.
number);
643 for (
int testc = 0; testc < cluster_info_2.
number; ++testc)
645 std::vector<int> sorter(cluster_info_1.
number);
646 std::iota(sorter.begin(), sorter.end(), 0);
649 [&](
const int a,
const int b)
651 const double a_weight = similarity_map[testc * cluster_info_1.number + a];
652 const double b_weight = similarity_map[testc * cluster_info_1.number + b];
653 return a_weight > b_weight;
657 size_t wanted_size = 0;
659 for (; wanted_size < sorter.size(); ++wanted_size)
661 const double match_weight = similarity_map[testc * cluster_info_1.
number + sorter[wanted_size]];
674 sorter.resize(wanted_size);
676 sorted_GPU_matches.push_back(std::move(sorter));
681 constexpr int max_iter = 32;
683 std::vector<double> matched_weights(cluster_info_1.
number, -1.);
685 std::vector<size_t> skipped_matching(cluster_info_2.
number, 0);
687 for (
int stop_counter = 0; stop_counter < cluster_info_2.
number && num_iter < max_iter; ++num_iter)
690 for (
int testc = 0; testc < int(sorted_GPU_matches.size()); ++testc)
692 if (skipped_matching[testc] < sorted_GPU_matches[testc].size())
694 const int match_c = sorted_GPU_matches[testc][skipped_matching[testc]];
695 const double match_weight = similarity_map[testc * cluster_info_1.
number + match_c];
696 if (match_weight >=
m_min_similarity && match_weight > matched_weights[match_c])
698 const int prev_match = sch.
r2t_table[match_c];
701 ++skipped_matching[prev_match];
705 matched_weights[match_c] = match_weight;
710 ++skipped_matching[testc];
723 for (
size_t i = 0; i < sch.
r2t_table.size(); ++i)
736 for (
size_t i = 0; i < sch.
t2r_table.size(); ++i)
745 char message_buffer[256];
746 snprintf(message_buffer, 256,
747 "%2d: %5d / %5d || %5d / %5d || %3d || %5d | %5d || %5d",
759 return StatusCode::SUCCESS;
930#define CALORECGPU_BASIC_CLUSTER_PROPERTY(NAME, ...) \
931 struct clusters_ ## NAME \
933 static std::string name() \
937 static double get_property([[maybe_unused]] const ConstantDataHolder & constant_data, \
938 [[maybe_unused]] const CaloRecGPU::CellInfoArr & cell_info, \
939 [[maybe_unused]] const CaloRecGPU::ClusterInfoArr & cluster_info, \
940 [[maybe_unused]] const std::vector<int> & cells_prefix_sum, \
941 [[maybe_unused]] const int cluster_index ) \
963#define CALORECGPU_CLUSTER_MOMENT(...) CALORECGPU_CLUSTER_MOMENT_INNER(__VA_ARGS__, 1, 1)
964#define CALORECGPU_CLUSTER_MOMENT_INNER(NAME, PROPERTY, UNIT, ...) CALORECGPU_BASIC_CLUSTER_PROPERTY(moments_ ## NAME, return cluster_info.moments. PROPERTY [cluster_index] / UNIT;)
1047 clusters_number_cells,
1048 clusters_moments_time,
1049 clusters_moments_FIRST_PHI,
1050 clusters_moments_FIRST_ETA,
1051 clusters_moments_SECOND_R,
1052 clusters_moments_SECOND_LAMBDA,
1053 clusters_moments_DELTA_PHI,
1054 clusters_moments_DELTA_THETA,
1055 clusters_moments_DELTA_ALPHA,
1056 clusters_moments_CENTER_X,
1057 clusters_moments_CENTER_Y,
1058 clusters_moments_CENTER_Z,
1059 clusters_moments_CENTER_MAG,
1060 clusters_moments_CENTER_LAMBDA,
1061 clusters_moments_LATERAL,
1062 clusters_moments_LONGITUDINAL,
1063 clusters_moments_ENG_FRAC_EM,
1064 clusters_moments_ENG_FRAC_MAX,
1065 clusters_moments_ENG_FRAC_CORE,
1066 clusters_moments_FIRST_ENG_DENS,
1067 clusters_moments_SECOND_ENG_DENS,
1068 clusters_moments_ISOLATION,
1069 clusters_moments_ENG_BAD_CELLS,
1070 clusters_moments_N_BAD_CELLS,
1071 clusters_moments_N_BAD_CELLS_CORR,
1072 clusters_moments_BAD_CELLS_CORR_E,
1073 clusters_moments_BADLARQ_FRAC,
1074 clusters_moments_ENG_POS,
1075 clusters_moments_SIGNIFICANCE,
1076 clusters_moments_CELL_SIGNIFICANCE,
1077 clusters_moments_CELL_SIG_SAMPLING,
1078 clusters_moments_AVG_LAR_Q,
1079 clusters_moments_AVG_TILE_Q,
1080 clusters_moments_ENG_BAD_HV_CELLS,
1081 clusters_moments_N_BAD_HV_CELLS,
1082 clusters_moments_PTD,
1083 clusters_moments_MASS,
1084 clusters_moments_EM_PROBABILITY,
1085 clusters_moments_HAD_WEIGHT,
1086 clusters_moments_OOC_WEIGHT,
1087 clusters_moments_DM_WEIGHT,
1088 clusters_moments_TILE_CONFIDENCE_LEVEL,
1089 clusters_moments_SECOND_TIME,
1090 clusters_moments_VERTEX_FRACTION,
1091 clusters_moments_NVERTEX_FRACTION,
1092 clusters_moments_ETACALOFRAME,
1093 clusters_moments_PHICALOFRAME,
1094 clusters_moments_ETA1CALOFRAME,
1095 clusters_moments_PHI1CALOFRAME,
1096 clusters_moments_ETA2CALOFRAME,
1097 clusters_moments_PHI2CALOFRAME,
1098 clusters_moments_ENG_CALIB_TOT,
1099 clusters_moments_ENG_CALIB_OUT_L,
1100 clusters_moments_ENG_CALIB_OUT_M,
1101 clusters_moments_ENG_CALIB_OUT_T,
1102 clusters_moments_ENG_CALIB_DEAD_L,
1103 clusters_moments_ENG_CALIB_DEAD_M,
1104 clusters_moments_ENG_CALIB_DEAD_T,
1105 clusters_moments_ENG_CALIB_EMB0,
1106 clusters_moments_ENG_CALIB_EME0,
1107 clusters_moments_ENG_CALIB_TILEG3,
1108 clusters_moments_ENG_CALIB_DEAD_TOT,
1109 clusters_moments_ENG_CALIB_DEAD_EMB0,
1110 clusters_moments_ENG_CALIB_DEAD_TILE0,
1111 clusters_moments_ENG_CALIB_DEAD_TILEG3,
1112 clusters_moments_ENG_CALIB_DEAD_EME0,
1113 clusters_moments_ENG_CALIB_DEAD_HEC0,
1114 clusters_moments_ENG_CALIB_DEAD_FCAL,
1115 clusters_moments_ENG_CALIB_DEAD_LEAKAGE,
1116 clusters_moments_ENG_CALIB_DEAD_UNCLASS,
1117 clusters_moments_ENG_CALIB_FRAC_EM,
1118 clusters_moments_ENG_CALIB_FRAC_HAD,
1119 clusters_moments_ENG_CALIB_FRAC_REST
1177#define CALORECGPU_BASIC_CELL_PROPERTY(NAME, ...) \
1178 struct cells_ ## NAME \
1180 static std::string name() \
1184 static double get_property([[maybe_unused]] const ConstantDataHolder & constant_data, \
1185 [[maybe_unused]] const CaloRecGPU::CellInfoArr & cell_info, \
1186 [[maybe_unused]] const CaloRecGPU::ClusterInfoArr & cluster_info, \
1187 [[maybe_unused]] const std::vector<int> & cells_prefix_sum, \
1188 [[maybe_unused]] const int cell ) \
1202 protect_from_zero(constant_data.m_cell_noise->get_noise(cell_info.get_hash_ID(cell), cell_info.gain[cell]));
1206 protect_from_zero(constant_data.m_cell_noise->get_noise(cell_info.get_hash_ID(cell), cell_info.gain[cell])));)
1229 float max_weight = 0.f;
1231 for (
int i = cells_prefix_sum[cell]; i < cells_prefix_sum[cell + 1]; ++i)
1233 const float this_weight = cluster_info.cellWeights[i];
1234 const int this_index = cluster_info.clusterIndices[i];
1235 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1237 max_weight = this_weight;
1238 max_index = this_index;
1247 float max_weight = 0.f, second_max_weight = 0.f;
1248 int max_index = 0, second_max_index = 0;
1249 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1251 const float this_weight = cluster_info.cellWeights[
i];
1252 const int this_index = cluster_info.clusterIndices[
i];
1253 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1255 second_max_weight = max_weight;
1256 second_max_index = max_index;
1257 max_weight = this_weight;
1258 max_index = this_index;
1260 else if (this_weight > second_max_weight || (this_weight == second_max_weight && this_index > second_max_index))
1262 second_max_weight = this_weight;
1263 second_max_index = this_index;
1266 return second_max_index;
1272 float max_weight = 0.f;
1274 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1276 const float this_weight = cluster_info.cellWeights[
i];
1277 const int this_index = cluster_info.clusterIndices[
i];
1278 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1280 max_weight = this_weight;
1281 max_index = this_index;
1291 float max_weight = 0.f, second_max_weight = 0.f;
1292 int max_index = 0, second_max_index = 0;
1293 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1295 const float this_weight = cluster_info.cellWeights[
i];
1296 const int this_index = cluster_info.clusterIndices[
i];
1297 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1299 second_max_weight = max_weight;
1300 second_max_index = max_index;
1301 max_weight = this_weight;
1302 max_index = this_index;
1304 else if (this_weight > second_max_weight || (this_weight == second_max_weight && this_index > second_max_index))
1306 second_max_weight = this_weight;
1307 second_max_index = this_index;
1310 return second_max_weight;
1314 using BasicCellProperties = multi_class_holder <
1331 cells_number_of_clusters,
1332 cells_primary_cluster_index,
1333 cells_secondary_cluster_index,
1334 cells_primary_weight,
1335 cells_secondary_weight
1396 const std::vector<std::string> histo_strings =
m_moniTool->histogramService()->getHists();
1409 auto string_contains = [](std::string_view
container, std::string_view contained) ->
bool
1411 return container.find(contained) != std::string::npos;
1414 auto search_lambda = [&](
const auto & prop,
const size_t count,
bool & check,
1415 const std::string &
str, std::vector<bool> & to_do,
1416 std::string_view prefix =
"", std::string_view suffix =
"")
1418 if (string_contains(
str, std::string(prefix) + prop.name() + std::string(suffix)))
1420 to_do[
count] =
true;
1425 for (
const auto &
str : histo_strings)
1472 if ( string_contains(
str,
"cluster_size_ref") ||
1473 string_contains(
str,
"cluster_size_test") ||
1474 string_contains(
str,
"cluster_delta_size") ||
1475 string_contains(
str,
"cluster_weighted_size_ref") ||
1476 string_contains(
str,
"cluster_weighted_size_test") ||
1477 string_contains(
str,
"cluster_delta_weighted_size") )
1483 else if ( string_contains(
str,
"cluster_size") ||
1484 string_contains(
str,
"cluster_weighted_size") )
1491 if (string_contains(
str,
"cluster_diff_cells"))
1498 if ( string_contains(
str,
"_num_same_E_cells_ref") ||
1499 string_contains(
str,
"_num_same_E_cells_test") ||
1500 string_contains(
str,
"delta_num_same_E_cells") ||
1501 string_contains(
str,
"_num_same_abs_E_cells_ref") ||
1502 string_contains(
str,
"_num_same_abs_E_cells_test") ||
1503 string_contains(
str,
"delta_num_same_abs_E_cells") )
1508 else if ( string_contains(
str,
"_num_same_E_cells") ||
1509 string_contains(
str,
"_num_same_abs_E_cells") )
1515 if ( string_contains(
str,
"_num_same_SNR_cells_ref") ||
1516 string_contains(
str,
"_num_same_SNR_cells_test") ||
1517 string_contains(
str,
"delta_num_same_SNR_cells") ||
1518 string_contains(
str,
"_num_same_abs_SNR_cells_ref") ||
1519 string_contains(
str,
"_num_same_abs_SNR_cells_test") ||
1520 string_contains(
str,
"delta_num_same_abs_SNR_cells") )
1525 else if ( string_contains(
str,
"_num_same_SNR_cells") ||
1526 string_contains(
str,
"_num_same_abs_SNR_cells") )
1533 return StatusCode::SUCCESS;
1542 const std::vector<int> & cells_prefix_sum,
1543 const std::string & tool_name)
const
1545 m_numClustersPerTool[tool_name].fetch_add(clusters->number);
1553 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1554 store_vec[
index].cell_info = *cell_info;
1555 store_vec[
index].clusters = *clusters;
1556 store_vec[
index].cells_prefix_sum = cells_prefix_sum;
1563 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1565 std::unordered_map<std::string, long long int> cell_counts;
1567 cluster_properties[
"size"].resize(clusters->number, 0.);
1568 cluster_properties[
"weighted_size"].resize(clusters->number, 0.);
1570 long long int same_energy = 0, same_abs_energy = 0, same_snr = 0, same_abs_snr = 0;
1572 std::set<double> energies, snrs;
1577 for (
int cell = 0; cell < cell_info->
number; ++cell)
1588 cell_properties[prop.name()].push_back(prop.get_property(constant_data, *cell_info, *clusters, cells_prefix_sum, cell));
1590 }, BasicCellProperties{});
1596 cell_counts[prop.name()] += prop.is_type(constant_data, *cell_info, *clusters, cells_prefix_sum, cell);
1598 }, BasicCellTypes{});
1600 const float this_energy = cell_info->
energy[cell];
1605 if (energies.count(this_energy))
1610 else if (energies.count(-this_energy))
1614 energies.insert(this_energy);
1622 if (snrs.count(this_snr))
1627 else if (snrs.count(-this_snr))
1631 snrs.insert(this_snr);
1637 for (
int i = 0; i < clusters->number_cells; ++i)
1639 const int this_cluster = clusters->clusterIndices[i];
1640 const float this_weight = clusters->cellWeights[i];
1642 cluster_properties[
"size"][this_cluster] += 1;
1643 cluster_properties[
"weighted_size"][this_cluster] += this_weight;
1650 for (
int cluster = 0; cluster < clusters->number; ++cluster)
1656 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, *cell_info, *clusters, cells_prefix_sum, cluster));
1658 }, BasicClusterProperties{});
1663 using scalar_type =
decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
1665 std::vector<coll_type> collections;
1666 std::vector<scalar_type> count_scalars;
1667 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
1669 collections.reserve(cluster_properties.size() + cell_properties.size());
1670 count_scalars.reserve(cell_counts.size());
1671 cluster_group.reserve(cluster_properties.size());
1672 cell_group.reserve(cell_properties.size());
1673 counts_group.reserve(cell_counts.size() + 5);
1675 auto mon_clus_num =
Monitored::Scalar(prefix +
"_num_clusters", clusters->number);
1676 auto mon_same_energy =
Monitored::Scalar(prefix +
"_num_same_E_cells", same_energy);
1677 auto mon_same_abs_energy =
Monitored::Scalar(prefix +
"_num_same_abs_E_cells", same_abs_energy);
1678 auto mon_same_snr =
Monitored::Scalar(prefix +
"_num_same_SNR_cells", same_snr);
1679 auto mon_same_abs_snr =
Monitored::Scalar(prefix +
"_num_same_abs_SNR_cells", same_abs_snr);
1681 counts_group.push_back(std::ref(mon_clus_num));
1682 counts_group.push_back(std::ref(mon_same_energy));
1683 counts_group.push_back(std::ref(mon_same_abs_energy));
1684 counts_group.push_back(std::ref(mon_same_snr));
1685 counts_group.push_back(std::ref(mon_same_abs_snr));
1691 for (
const auto & k_v : cluster_properties)
1694 cluster_group.push_back(std::ref(collections.back()));
1697 for (
const auto & k_v : cell_properties)
1700 cell_group.push_back(std::ref(collections.back()));
1703 for (
const auto & k_v : cell_counts)
1705 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_num_" + k_v.first +
"_cells", k_v.second));
1706 counts_group.push_back(std::ref(count_scalars.back()));
1717 return StatusCode::SUCCESS;
1725 const std::string & prefix,
1726 const bool match_in_energy,
1727 const bool match_without_shared,
1728 const bool match_perfectly)
const
1736 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1740 const std::vector<int> & cells_prefix_sum_1 = store_vec[index_1].cells_prefix_sum;
1744 const std::vector<int> & cells_prefix_sum_2 = store_vec[index_2].cells_prefix_sum;
1748 if (match_perfectly)
1754 ATH_CHECK(
match_clusters(sch, constant_data, cell_info_1, clusters_1, clusters_2, match_in_energy, match_without_shared) );
1757 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1759 std::unordered_map<std::string, long long int> cell_counts;
1761 std::vector<double> ref_size_vec(clusters_1.
number, 0.), test_size_vec(clusters_2.
number, 0.),
1762 ref_weighted_size_vec(clusters_1.
number, 0.), test_weighted_size_vec(clusters_2.
number, 0.),
1763 ref_diff_cells(clusters_1.
number, 0.), test_diff_cells(clusters_2.
number, 0.),
1764 ref_diff_cells_weight(clusters_1.
number, 0.), test_diff_cells_weight(clusters_2.
number, 0.);
1767 long long int same_energy_1 = 0, same_energy_2 = 0,
1768 same_abs_energy_1 = 0, same_abs_energy_2 = 0,
1769 same_snr_1 = 0, same_snr_2 = 0,
1770 same_abs_snr_1 = 0, same_abs_snr_2 = 0,
1771 same_cluster_cells_count = 0, diff_cluster_cells_count = 0;
1773 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1777 for (
int cell = 0; cell <
NCaloCells; ++cell)
1790 const auto prop_1 = prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cell);
1791 const auto prop_2 = prop.get_property(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2, cell);
1793 cell_properties[prop.name() +
"_ref"].push_back(prop_1);
1794 cell_properties[prop.name() +
"_test"].push_back(prop_2);
1796 cell_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1797 cell_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_1)));
1798 cell_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_2)));
1800 }, BasicCellProperties{});
1806 const auto is_1 = prop.is_type(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cell);
1807 const auto is_2 = prop.is_type(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2, cell);
1809 cell_counts[
"num_" + prop.name() +
"_cells_ref"] += is_1;
1810 cell_counts[
"num_" + prop.name() +
"_cells_test"] += is_2;
1811 cell_counts[
"delta_num_" + prop.name() +
"_cells"] += is_2 - is_1;
1813 }, BasicCellTypes{});
1815 const float this_energy_1 = cell_info_1.
energy[cell];
1816 const float this_energy_2 = cell_info_2.
energy[cell];
1820 if (energies_1.count(this_energy_1))
1823 ++same_abs_energy_1;
1825 else if (energies_1.count(-this_energy_1))
1827 ++same_abs_energy_1;
1829 energies_1.insert(this_energy_1);
1831 if (energies_2.count(this_energy_2))
1834 ++same_abs_energy_2;
1836 else if (energies_2.count(-this_energy_2))
1838 ++same_abs_energy_2;
1840 energies_2.insert(this_energy_2);
1847 if (snrs_1.count(this_snr_1))
1852 else if (snrs_1.count(-this_snr_1))
1856 snrs_1.insert(this_snr_1);
1861 if (snrs_2.count(this_snr_2))
1866 else if (snrs_2.count(-this_snr_2))
1870 snrs_2.insert(this_snr_2);
1875 bool cell_is_diff =
false;
1877 for (
int i = cells_prefix_sum_1[cell]; i < cells_prefix_sum_1[cell + 1] && i < cell_info_1.
number; ++i)
1880 const float this_weight = clusters_1.
cellWeights[i];
1881 bool found_match =
false;
1882 for (
int j = cells_prefix_sum_2[cell]; j < cells_prefix_sum_2[cell + 1] && j < cell_info_2.
number; ++j)
1890 ref_size_vec[this_index] += 1;
1891 ref_weighted_size_vec[this_index] += this_weight;
1894 ref_diff_cells[this_index] += 1;
1895 ref_diff_cells_weight[this_index] += this_weight;
1896 cell_is_diff =
true;
1900 for (
int i = cells_prefix_sum_2[cell]; i < cells_prefix_sum_2[cell + 1] && i < cell_info_2.
number; ++i)
1903 const float this_weight = clusters_2.
cellWeights[i];
1904 bool found_match =
false;
1905 for (
int j = cells_prefix_sum_1[cell]; j < cells_prefix_sum_1[cell + 1] && j < cell_info_1.
number; ++j)
1913 test_size_vec[this_index] += 1;
1914 test_weighted_size_vec[this_index] += this_weight;
1917 test_diff_cells[this_index] += 1;
1918 test_diff_cells_weight[this_index] += this_weight;
1919 cell_is_diff =
true;
1925#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS
1926 msg(MSG::INFO) <<
"Diff: " << cell <<
" |";
1927 for (
int i = cells_prefix_sum_1[cell]; i < cells_prefix_sum_1[cell + 1] && i < cell_info_1.
number; ++i)
1932 for (
int i = cells_prefix_sum_2[cell]; i < cells_prefix_sum_2[cell + 1] && i < cell_info_2.
number; ++i)
1939 ++diff_cluster_cells_count;
1941 else if ((cells_prefix_sum_1[cell + 1] > cells_prefix_sum_1[cell]) || (cells_prefix_sum_2[cell + 1] > cells_prefix_sum_2[cell]))
1943 ++same_cluster_cells_count;
1952 for (
int cluster = 0; cluster < clusters_1.
number; ++cluster)
1954 const int match = sch.
r2t(cluster);
1965 const auto prop_1 = prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cluster);
1966 const auto prop_2 = prop.get_property(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2,
match);
1968 cluster_properties[prop.name() +
"_ref"].push_back(prop_1);
1969 cluster_properties[prop.name() +
"_test"].push_back(prop_2);
1971 cluster_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1972 cluster_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_1)));
1973 cluster_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_2)));
1975 }, BasicClusterProperties{});
1981 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cluster,
1982 cell_info_2, clusters_2, cells_prefix_sum_2,
match));
1984 }, ComparedClusterProperties{});
1988 cluster_properties[
"size_ref"].push_back(ref_size_vec[cluster]);
1989 cluster_properties[
"size_test"].push_back(test_size_vec[
match]);
1990 cluster_properties[
"delta_size"].push_back(ref_size_vec[cluster] - test_size_vec[
match]);
1991 cluster_properties[
"delta_size_rel_ref"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) /
protect_from_zero(ref_size_vec[cluster]));
1992 cluster_properties[
"delta_size_rel_test"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) /
protect_from_zero(test_size_vec[
match]));
1994 cluster_properties[
"weighted_size_ref"].push_back(ref_weighted_size_vec[cluster]);
1995 cluster_properties[
"weighted_size_test"].push_back(test_weighted_size_vec[
match]);
1996 cluster_properties[
"delta_weighted_size"].push_back(ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]);
1997 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]));
1998 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]));
2003 cluster_properties[
"diff_cells_ref"].push_back(ref_diff_cells[cluster]);
2004 cluster_properties[
"diff_cells_ref_rel_size"].push_back(ref_diff_cells[cluster] /
protect_from_zero(ref_size_vec[cluster]));
2005 cluster_properties[
"diff_cells_test"].push_back(test_diff_cells[
match]);
2007 cluster_properties[
"diff_cells"].push_back(ref_diff_cells[cluster] + test_diff_cells[
match]);
2009 cluster_properties[
"weighted_diff_cells_ref"].push_back(ref_diff_cells_weight[cluster]);
2010 cluster_properties[
"weighted_diff_cells_ref_rel_size"].push_back(ref_diff_cells_weight[cluster] /
protect_from_zero(ref_weighted_size_vec[cluster]));
2011 cluster_properties[
"weighted_diff_cells_test"].push_back(test_diff_cells_weight[
match]);
2012 cluster_properties[
"weighted_diff_cells_test_rel_size"].push_back(test_diff_cells_weight[
match] /
protect_from_zero(test_weighted_size_vec[
match]));
2013 cluster_properties[
"weighted_diff_cells"].push_back(ref_diff_cells_weight[cluster] + test_diff_cells_weight[
match]);
2019 using scalar_type =
decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
2021 std::vector<coll_type> collections;
2022 std::vector<scalar_type> count_scalars;
2023 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
2025 collections.reserve(cluster_properties.size() + cell_properties.size());
2026 count_scalars.reserve(cell_counts.size() + 6 * 3);
2027 cluster_group.reserve(cluster_properties.size());
2028 cell_group.reserve(cell_properties.size());
2029 counts_group.reserve(cell_counts.size() + 3 + 6 * 3);
2031 auto add_count_vars = [&](
const std::string & name,
const long long int ref_num,
const long long int test_num)
2033 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + name +
"_ref", ref_num));
2034 counts_group.push_back(std::ref(count_scalars.back()));
2036 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + name +
"_test", test_num));
2037 counts_group.push_back(std::ref(count_scalars.back()));
2039 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_delta_" + name, test_num - ref_num));
2040 counts_group.push_back(std::ref(count_scalars.back()));
2043 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2046 add_count_vars(
"num_same_E_cells", same_energy_1, same_energy_2);
2047 add_count_vars(
"num_same_abs_E_cells", same_abs_energy_1, same_abs_energy_2);
2048 add_count_vars(
"num_same_SNR_cells", same_snr_1, same_snr_2);
2049 add_count_vars(
"num_same_abs_SNR_cells", same_abs_snr_1, same_abs_snr_2);
2052 auto mon_same_cluster_cell =
Monitored::Scalar(prefix +
"_same_cluster_cells", same_cluster_cells_count);
2053 auto mon_diff_cluster_cell =
Monitored::Scalar(prefix +
"_diff_cluster_cells", diff_cluster_cells_count);
2057 ATH_MSG_INFO(
"Different cells: " << diff_cluster_cells_count);
2060 counts_group.push_back(std::ref(mon_total_unmatched));
2061 counts_group.push_back(std::ref(mon_same_cluster_cell));
2062 counts_group.push_back(std::ref(mon_diff_cluster_cell));
2064 for (
const auto & k_v : cluster_properties)
2067 cluster_group.push_back(std::ref(collections.back()));
2070 for (
const auto & k_v : cell_properties)
2073 cell_group.push_back(std::ref(collections.back()));
2076 for (
const auto & k_v : cell_counts)
2078 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + k_v.first, k_v.second));
2079 counts_group.push_back(std::ref(count_scalars.back()));
2089 return StatusCode::SUCCESS;