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 const int hash_ID_a = cell_info->get_hash_ID(clusters->cells.indices[a]);
372 const int hash_ID_b = cell_info->get_hash_ID(clusters->cells.indices[b]);
375 ATH_MSG_WARNING(
"Attempting to sort impossible cell: " << a <<
" " << hash_ID_a);
379 ATH_MSG_WARNING(
"Attempting to sort impossible cell: " << b <<
" " << hash_ID_b);
381 return hash_ID_a < hash_ID_b;
385 auto order_array = [&](
auto *
ptr)
387 std::vector<std::decay_t<
decltype(
ptr[0])>> prev(
clusters->number_cells);
389 for (
int i = 0;
i <
clusters->number_cells; ++
i)
394 for (
int i = 0;
i <
clusters->number_cells; ++
i)
396 ptr[
i] = prev[cell_orderer[
i]];
400 order_array(
clusters->cells.indices);
402 order_array(
clusters->clusterIndices);
404 cells_prefix_sum.clear();
407 int prev_cell_index = -1;
410 for (
int i = 0;
i <
clusters->number_cells; ++
i)
412 const int this_cell_index =
clusters->cells.indices[
i];
414 if (this_cell_index != prev_cell_index)
418 const int prev_cell_ID = (prev_cell_index < 0 ? -1 : cell_info->get_hash_ID(prev_cell_index));
419 const int this_cell_ID = cell_info->get_hash_ID(this_cell_index);
421 for (
int j = prev_cell_ID + 1;
j <= this_cell_ID; ++
j)
423 cells_prefix_sum[
j] = cell_count;
429 prev_cell_index = this_cell_index;
436 cells_prefix_sum[
i + 1] = cell_count;
440 return StatusCode::SUCCESS;
495 const std::vector<int> & cells_prefix_sum_1,
496 const std::vector<int> & cells_prefix_sum_2,
499 const bool match_in_energy,
500 const bool match_without_shared)
const
508 std::vector<double> similarity_map(cluster_info_1.
number * cluster_info_2.
number, 0.);
510 std::vector<double> ref_normalization(cluster_info_1.
number, 0.);
511 std::vector<double> test_normalization(cluster_info_2.
number, 0.);
513 auto calculate_weight = [&](
const int cell)
515 double SNR = 0.00001;
517 if (!cell_info_1.
is_bad(cell))
519 const int gain = cell_info_1.
gain[cell];
522 if (std::isfinite(cellNoise) && cellNoise > 0.0f)
524 SNR = std::abs(cell_info_1.
energy[cell] / cellNoise);
528 const double quantity = ( match_in_energy ? std::abs(cell_info_1.
energy[cell]) : SNR );
529 const double weight = (quantity + 1e-7) *
539 return weight + 1e-8;
542 auto matched_clusters = [&](
const int hash_ID,
const std::vector<std::pair<int, float>> & v1,
const std::vector<std::pair<int, float>> & v2)
544#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS && CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS > 1
545 msg(MSG::INFO) <<
"MATCH: " << hash_ID <<
" " << calculate_weight(cell_info_1.
get_cell_with_hash_ID(hash_ID)) <<
" |";
546 for (
const auto & p : v1)
548 msg() <<
" (" << p.first <<
", " << p.second <<
")";
551 for (
const auto & p : v2)
553 msg() <<
" (" << p.first <<
", " << p.second <<
")";
558 if (match_without_shared && (v1.size() > 1 || v2.size() > 1))
565 for (
const auto & p1 : v1)
567 for (
const auto & p2 : v2)
569 similarity_map[p2.first * cluster_info_1.
number + p1.first] += weight * p1.second * p2.second;
573 for (
const auto & p1 : v1)
575 ref_normalization[p1.first] += weight * p1.second * p1.second;
578 for (
const auto & p2 : v2)
580 test_normalization[p2.first] += weight * p2.second * p2.second;
584 auto unmatched_clusters = [&](
const bool is_test,
const int hash_ID,
const std::vector<std::pair<int, float>> & v)
586#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS
587 msg(MSG::INFO) <<
"UNMATCH: " << hash_ID <<
" " << calculate_weight(cell_info_1.
get_cell_with_hash_ID(hash_ID)) <<
" | " << is_test <<
" |";
588 for (
const auto & p : v)
590 msg() <<
" (" << p.first <<
", " << p.second <<
")";
595 if (match_without_shared && v.size() > 1)
602 std::vector<double> & normalization = (is_test ? test_normalization : ref_normalization);
604 for (
const auto & p : v)
606 normalization[p.first] += weight * p.second * p.second;
611 cells_prefix_sum_1, cells_prefix_sum_2,
612 cluster_info_1, cluster_info_2,
613 matched_clusters, unmatched_clusters);
615 for (
int testc = 0; testc < cluster_info_2.
number; ++testc)
617 const double test_norm = test_normalization[testc] + double(test_normalization[testc] == 0.);
618 for (
int refc = 0; refc < cluster_info_1.
number; ++refc)
620 const double ref_norm = ref_normalization[refc] + double(ref_normalization[refc] == 0.);
621 similarity_map[testc * cluster_info_1.
number + refc] /= std::sqrt(ref_norm * test_norm);
627 std::vector<std::vector<int>> sorted_GPU_matches;
629 sorted_GPU_matches.reserve(cluster_info_2.
number);
631 for (
int testc = 0; testc < cluster_info_2.
number; ++testc)
633 std::vector<int> sorter(cluster_info_1.
number);
634 std::iota(sorter.begin(), sorter.end(), 0);
637 [&](
const int a,
const int b)
639 const double a_weight = similarity_map[testc * cluster_info_1.number + a];
640 const double b_weight = similarity_map[testc * cluster_info_1.number + b];
641 return a_weight > b_weight;
645 size_t wanted_size = 0;
647 for (; wanted_size < sorter.size(); ++wanted_size)
649 const double match_weight = similarity_map[testc * cluster_info_1.
number + sorter[wanted_size]];
662 sorter.resize(wanted_size);
664 sorted_GPU_matches.push_back(std::move(sorter));
669 constexpr int max_iter = 32;
671 std::vector<double> matched_weights(cluster_info_1.
number, -1.);
673 std::vector<size_t> skipped_matching(cluster_info_2.
number, 0);
675 for (
int stop_counter = 0; stop_counter < cluster_info_2.
number && num_iter < max_iter; ++num_iter)
678 for (
int testc = 0; testc < int(sorted_GPU_matches.size()); ++testc)
680 if (skipped_matching[testc] < sorted_GPU_matches[testc].size())
682 const int match_c = sorted_GPU_matches[testc][skipped_matching[testc]];
683 const double match_weight = similarity_map[testc * cluster_info_1.
number + match_c];
684 if (match_weight >=
m_min_similarity && match_weight > matched_weights[match_c])
686 const int prev_match = sch.
r2t_table[match_c];
689 ++skipped_matching[prev_match];
693 matched_weights[match_c] = match_weight;
698 ++skipped_matching[testc];
711 for (
size_t i = 0; i < sch.
r2t_table.size(); ++i)
724 for (
size_t i = 0; i < sch.
t2r_table.size(); ++i)
733 char message_buffer[256];
734 snprintf(message_buffer, 256,
735 "%2d: %5d / %5d || %5d / %5d || %3d || %5d | %5d || %5d",
747 return StatusCode::SUCCESS;
924#define CALORECGPU_BASIC_CLUSTER_PROPERTY(NAME, ...) \
925 struct clusters_ ## NAME \
927 static std::string name() \
931 static double get_property([[maybe_unused]] const ConstantDataHolder & constant_data, \
932 [[maybe_unused]] const CaloRecGPU::CellInfoArr & cell_info, \
933 [[maybe_unused]] const CaloRecGPU::ClusterInfoArr & cluster_info, \
934 [[maybe_unused]] const std::vector<int> & cells_prefix_sum, \
935 [[maybe_unused]] const int cluster_index ) \
957#define CALORECGPU_CLUSTER_MOMENT(...) CALORECGPU_CLUSTER_MOMENT_INNER(__VA_ARGS__, 1, 1)
958#define CALORECGPU_CLUSTER_MOMENT_INNER(NAME, PROPERTY, UNIT, ...) CALORECGPU_BASIC_CLUSTER_PROPERTY(moments_ ## NAME, return cluster_info.moments. PROPERTY [cluster_index] / UNIT;)
1041 clusters_number_cells,
1042 clusters_moments_time,
1043 clusters_moments_FIRST_PHI,
1044 clusters_moments_FIRST_ETA,
1045 clusters_moments_SECOND_R,
1046 clusters_moments_SECOND_LAMBDA,
1047 clusters_moments_DELTA_PHI,
1048 clusters_moments_DELTA_THETA,
1049 clusters_moments_DELTA_ALPHA,
1050 clusters_moments_CENTER_X,
1051 clusters_moments_CENTER_Y,
1052 clusters_moments_CENTER_Z,
1053 clusters_moments_CENTER_MAG,
1054 clusters_moments_CENTER_LAMBDA,
1055 clusters_moments_LATERAL,
1056 clusters_moments_LONGITUDINAL,
1057 clusters_moments_ENG_FRAC_EM,
1058 clusters_moments_ENG_FRAC_MAX,
1059 clusters_moments_ENG_FRAC_CORE,
1060 clusters_moments_FIRST_ENG_DENS,
1061 clusters_moments_SECOND_ENG_DENS,
1062 clusters_moments_ISOLATION,
1063 clusters_moments_ENG_BAD_CELLS,
1064 clusters_moments_N_BAD_CELLS,
1065 clusters_moments_N_BAD_CELLS_CORR,
1066 clusters_moments_BAD_CELLS_CORR_E,
1067 clusters_moments_BADLARQ_FRAC,
1068 clusters_moments_ENG_POS,
1069 clusters_moments_SIGNIFICANCE,
1070 clusters_moments_CELL_SIGNIFICANCE,
1071 clusters_moments_CELL_SIG_SAMPLING,
1072 clusters_moments_AVG_LAR_Q,
1073 clusters_moments_AVG_TILE_Q,
1074 clusters_moments_ENG_BAD_HV_CELLS,
1075 clusters_moments_N_BAD_HV_CELLS,
1076 clusters_moments_PTD,
1077 clusters_moments_MASS,
1078 clusters_moments_EM_PROBABILITY,
1079 clusters_moments_HAD_WEIGHT,
1080 clusters_moments_OOC_WEIGHT,
1081 clusters_moments_DM_WEIGHT,
1082 clusters_moments_TILE_CONFIDENCE_LEVEL,
1083 clusters_moments_SECOND_TIME,
1084 clusters_moments_VERTEX_FRACTION,
1085 clusters_moments_NVERTEX_FRACTION,
1086 clusters_moments_ETACALOFRAME,
1087 clusters_moments_PHICALOFRAME,
1088 clusters_moments_ETA1CALOFRAME,
1089 clusters_moments_PHI1CALOFRAME,
1090 clusters_moments_ETA2CALOFRAME,
1091 clusters_moments_PHI2CALOFRAME,
1092 clusters_moments_ENG_CALIB_TOT,
1093 clusters_moments_ENG_CALIB_OUT_L,
1094 clusters_moments_ENG_CALIB_OUT_M,
1095 clusters_moments_ENG_CALIB_OUT_T,
1096 clusters_moments_ENG_CALIB_DEAD_L,
1097 clusters_moments_ENG_CALIB_DEAD_M,
1098 clusters_moments_ENG_CALIB_DEAD_T,
1099 clusters_moments_ENG_CALIB_EMB0,
1100 clusters_moments_ENG_CALIB_EME0,
1101 clusters_moments_ENG_CALIB_TILEG3,
1102 clusters_moments_ENG_CALIB_DEAD_TOT,
1103 clusters_moments_ENG_CALIB_DEAD_EMB0,
1104 clusters_moments_ENG_CALIB_DEAD_TILE0,
1105 clusters_moments_ENG_CALIB_DEAD_TILEG3,
1106 clusters_moments_ENG_CALIB_DEAD_EME0,
1107 clusters_moments_ENG_CALIB_DEAD_HEC0,
1108 clusters_moments_ENG_CALIB_DEAD_FCAL,
1109 clusters_moments_ENG_CALIB_DEAD_LEAKAGE,
1110 clusters_moments_ENG_CALIB_DEAD_UNCLASS,
1111 clusters_moments_ENG_CALIB_FRAC_EM,
1112 clusters_moments_ENG_CALIB_FRAC_HAD,
1113 clusters_moments_ENG_CALIB_FRAC_REST
1171#define CALORECGPU_BASIC_CELL_PROPERTY(NAME, ...) \
1172 struct cells_ ## NAME \
1174 static std::string name() \
1178 static double get_property([[maybe_unused]] const ConstantDataHolder & constant_data, \
1179 [[maybe_unused]] const CaloRecGPU::CellInfoArr & cell_info, \
1180 [[maybe_unused]] const CaloRecGPU::ClusterInfoArr & cluster_info, \
1181 [[maybe_unused]] const std::vector<int> & cells_prefix_sum, \
1182 [[maybe_unused]] const int cell ) \
1196 protect_from_zero(constant_data.m_cell_noise->get_noise(cell_info.get_hash_ID(cell), cell_info.gain[cell]));
1200 protect_from_zero(constant_data.m_cell_noise->get_noise(cell_info.get_hash_ID(cell), cell_info.gain[cell])));)
1223 float max_weight = 0.f;
1225 for (
int i = cells_prefix_sum[cell]; i < cells_prefix_sum[cell + 1]; ++i)
1227 const float this_weight = cluster_info.cellWeights[i];
1228 const int this_index = cluster_info.clusterIndices[i];
1229 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1231 max_weight = this_weight;
1232 max_index = this_index;
1241 float max_weight = 0.f, second_max_weight = 0.f;
1242 int max_index = 0, second_max_index = 0;
1243 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1245 const float this_weight = cluster_info.cellWeights[
i];
1246 const int this_index = cluster_info.clusterIndices[
i];
1247 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1249 second_max_weight = max_weight;
1250 second_max_index = max_index;
1251 max_weight = this_weight;
1252 max_index = this_index;
1254 else if (this_weight > second_max_weight || (this_weight == second_max_weight && this_index > second_max_index))
1256 second_max_weight = this_weight;
1257 second_max_index = this_index;
1260 return second_max_index;
1266 float max_weight = 0.f;
1268 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1270 const float this_weight = cluster_info.cellWeights[
i];
1271 const int this_index = cluster_info.clusterIndices[
i];
1272 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1274 max_weight = this_weight;
1275 max_index = this_index;
1285 float max_weight = 0.f, second_max_weight = 0.f;
1286 int max_index = 0, second_max_index = 0;
1287 for (
int i = cells_prefix_sum[cell];
i < cells_prefix_sum[
cell + 1]; ++
i)
1289 const float this_weight = cluster_info.cellWeights[
i];
1290 const int this_index = cluster_info.clusterIndices[
i];
1291 if (this_weight > max_weight || (this_weight == max_weight && this_index > max_index))
1293 second_max_weight = max_weight;
1294 second_max_index = max_index;
1295 max_weight = this_weight;
1296 max_index = this_index;
1298 else if (this_weight > second_max_weight || (this_weight == second_max_weight && this_index > second_max_index))
1300 second_max_weight = this_weight;
1301 second_max_index = this_index;
1304 return second_max_weight;
1308 using BasicCellProperties = multi_class_holder <
1325 cells_number_of_clusters,
1326 cells_primary_cluster_index,
1327 cells_secondary_cluster_index,
1328 cells_primary_weight,
1329 cells_secondary_weight
1390 const std::vector<std::string> histo_strings =
m_moniTool->histogramService()->getHists();
1403 auto string_contains = [](std::string_view
container, std::string_view contained) ->
bool
1405 return container.find(contained) != std::string::npos;
1408 auto search_lambda = [&](
const auto & prop,
const size_t count,
bool & check,
1409 const std::string &
str, std::vector<bool> & to_do,
1410 std::string_view prefix =
"", std::string_view suffix =
"")
1412 if (string_contains(
str, std::string(prefix) + prop.name() + std::string(suffix)))
1414 to_do[
count] =
true;
1419 for (
const auto &
str : histo_strings)
1466 if ( string_contains(
str,
"cluster_size_ref") ||
1467 string_contains(
str,
"cluster_size_test") ||
1468 string_contains(
str,
"cluster_delta_size") ||
1469 string_contains(
str,
"cluster_weighted_size_ref") ||
1470 string_contains(
str,
"cluster_weighted_size_test") ||
1471 string_contains(
str,
"cluster_delta_weighted_size") )
1477 else if ( string_contains(
str,
"cluster_size") ||
1478 string_contains(
str,
"cluster_weighted_size") )
1485 if (string_contains(
str,
"cluster_diff_cells"))
1492 if ( string_contains(
str,
"_num_same_E_cells_ref") ||
1493 string_contains(
str,
"_num_same_E_cells_test") ||
1494 string_contains(
str,
"delta_num_same_E_cells") ||
1495 string_contains(
str,
"_num_same_abs_E_cells_ref") ||
1496 string_contains(
str,
"_num_same_abs_E_cells_test") ||
1497 string_contains(
str,
"delta_num_same_abs_E_cells") )
1502 else if ( string_contains(
str,
"_num_same_E_cells") ||
1503 string_contains(
str,
"_num_same_abs_E_cells") )
1509 if ( string_contains(
str,
"_num_same_SNR_cells_ref") ||
1510 string_contains(
str,
"_num_same_SNR_cells_test") ||
1511 string_contains(
str,
"delta_num_same_SNR_cells") ||
1512 string_contains(
str,
"_num_same_abs_SNR_cells_ref") ||
1513 string_contains(
str,
"_num_same_abs_SNR_cells_test") ||
1514 string_contains(
str,
"delta_num_same_abs_SNR_cells") )
1519 else if ( string_contains(
str,
"_num_same_SNR_cells") ||
1520 string_contains(
str,
"_num_same_abs_SNR_cells") )
1527 return StatusCode::SUCCESS;
1536 const std::vector<int> & cells_prefix_sum,
1537 const std::string & tool_name)
const
1539 m_numClustersPerTool[tool_name].fetch_add(clusters->number);
1547 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1548 store_vec[
index].cell_info = *cell_info;
1549 store_vec[
index].clusters = *clusters;
1550 store_vec[
index].cells_prefix_sum = cells_prefix_sum;
1557 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1559 std::unordered_map<std::string, long long int> cell_counts;
1561 cluster_properties[
"size"].resize(clusters->number, 0.);
1562 cluster_properties[
"weighted_size"].resize(clusters->number, 0.);
1564 long long int same_energy = 0, same_abs_energy = 0, same_snr = 0, same_abs_snr = 0;
1566 std::set<double> energies, snrs;
1571 for (
int cell = 0; cell < cell_info->
number; ++cell)
1582 cell_properties[prop.name()].push_back(prop.get_property(constant_data, *cell_info, *clusters, cells_prefix_sum, cell));
1584 }, BasicCellProperties{});
1590 cell_counts[prop.name()] += prop.is_type(constant_data, *cell_info, *clusters, cells_prefix_sum, cell);
1592 }, BasicCellTypes{});
1594 const float this_energy = cell_info->
energy[cell];
1599 if (energies.count(this_energy))
1604 else if (energies.count(-this_energy))
1608 energies.insert(this_energy);
1616 if (snrs.count(this_snr))
1621 else if (snrs.count(-this_snr))
1625 snrs.insert(this_snr);
1631 for (
int i = 0; i < clusters->number_cells; ++i)
1633 const int this_cluster = clusters->clusterIndices[i];
1634 const float this_weight = clusters->cellWeights[i];
1636 cluster_properties[
"size"][this_cluster] += 1;
1637 cluster_properties[
"weighted_size"][this_cluster] += this_weight;
1644 for (
int cluster = 0; cluster < clusters->number; ++cluster)
1650 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, *cell_info, *clusters, cells_prefix_sum, cluster));
1652 }, BasicClusterProperties{});
1657 using scalar_type =
decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
1659 std::vector<coll_type> collections;
1660 std::vector<scalar_type> count_scalars;
1661 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
1663 collections.reserve(cluster_properties.size() + cell_properties.size());
1664 count_scalars.reserve(cell_counts.size());
1665 cluster_group.reserve(cluster_properties.size());
1666 cell_group.reserve(cell_properties.size());
1667 counts_group.reserve(cell_counts.size() + 5);
1669 auto mon_clus_num =
Monitored::Scalar(prefix +
"_num_clusters", clusters->number);
1670 auto mon_same_energy =
Monitored::Scalar(prefix +
"_num_same_E_cells", same_energy);
1671 auto mon_same_abs_energy =
Monitored::Scalar(prefix +
"_num_same_abs_E_cells", same_abs_energy);
1672 auto mon_same_snr =
Monitored::Scalar(prefix +
"_num_same_SNR_cells", same_snr);
1673 auto mon_same_abs_snr =
Monitored::Scalar(prefix +
"_num_same_abs_SNR_cells", same_abs_snr);
1675 counts_group.push_back(std::ref(mon_clus_num));
1676 counts_group.push_back(std::ref(mon_same_energy));
1677 counts_group.push_back(std::ref(mon_same_abs_energy));
1678 counts_group.push_back(std::ref(mon_same_snr));
1679 counts_group.push_back(std::ref(mon_same_abs_snr));
1685 for (
const auto & k_v : cluster_properties)
1688 cluster_group.push_back(std::ref(collections.back()));
1691 for (
const auto & k_v : cell_properties)
1694 cell_group.push_back(std::ref(collections.back()));
1697 for (
const auto & k_v : cell_counts)
1699 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_num_" + k_v.first +
"_cells", k_v.second));
1700 counts_group.push_back(std::ref(count_scalars.back()));
1711 return StatusCode::SUCCESS;
1719 const std::string & prefix,
1720 const bool match_in_energy,
1721 const bool match_without_shared,
1722 const bool match_perfectly)
const
1730 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1734 const std::vector<int> & cells_prefix_sum_1 = store_vec[index_1].cells_prefix_sum;
1738 const std::vector<int> & cells_prefix_sum_2 = store_vec[index_2].cells_prefix_sum;
1742 if (match_perfectly)
1745 cell_info_1, cell_info_2,
1746 cells_prefix_sum_1, cells_prefix_sum_2,
1747 clusters_1, clusters_2,
1748 match_without_shared) );
1753 cell_info_1, cell_info_2,
1754 cells_prefix_sum_1, cells_prefix_sum_2,
1755 clusters_1, clusters_2,
1756 match_in_energy, match_without_shared) );
1759 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1761 std::unordered_map<std::string, long long int> cell_counts;
1763 std::vector<double> ref_size_vec(clusters_1.
number, 0.), test_size_vec(clusters_2.
number, 0.),
1764 ref_weighted_size_vec(clusters_1.
number, 0.), test_weighted_size_vec(clusters_2.
number, 0.),
1765 ref_diff_cells(clusters_1.
number, 0.), test_diff_cells(clusters_2.
number, 0.),
1766 ref_diff_cells_weight(clusters_1.
number, 0.), test_diff_cells_weight(clusters_2.
number, 0.);
1769 long long int same_energy_1 = 0, same_energy_2 = 0,
1770 same_abs_energy_1 = 0, same_abs_energy_2 = 0,
1771 same_snr_1 = 0, same_snr_2 = 0,
1772 same_abs_snr_1 = 0, same_abs_snr_2 = 0,
1773 same_cluster_cells_count = 0, diff_cluster_cells_count = 0;
1775 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1779 for (
int cell = 0; cell <
NCaloCells; ++cell)
1783 if ( cell >= cell_info_1.
number ||
1784 cell >= cell_info_2.
number ||
1795 const auto prop_1 = prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cell);
1796 const auto prop_2 = prop.get_property(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2, cell);
1798 cell_properties[prop.name() +
"_ref"].push_back(prop_1);
1799 cell_properties[prop.name() +
"_test"].push_back(prop_2);
1801 cell_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1802 cell_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_1)));
1803 cell_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_2)));
1805 }, BasicCellProperties{});
1811 const auto is_1 = prop.is_type(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cell);
1812 const auto is_2 = prop.is_type(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2, cell);
1814 cell_counts[
"num_" + prop.name() +
"_cells_ref"] += is_1;
1815 cell_counts[
"num_" + prop.name() +
"_cells_test"] += is_2;
1816 cell_counts[
"delta_num_" + prop.name() +
"_cells"] += is_2 - is_1;
1818 }, BasicCellTypes{});
1820 const float this_energy_1 = cell_info_1.
energy[cell];
1821 const float this_energy_2 = cell_info_2.
energy[cell];
1825 if (energies_1.count(this_energy_1))
1828 ++same_abs_energy_1;
1830 else if (energies_1.count(-this_energy_1))
1832 ++same_abs_energy_1;
1834 energies_1.insert(this_energy_1);
1836 if (energies_2.count(this_energy_2))
1839 ++same_abs_energy_2;
1841 else if (energies_2.count(-this_energy_2))
1843 ++same_abs_energy_2;
1845 energies_2.insert(this_energy_2);
1852 if (snrs_1.count(this_snr_1))
1857 else if (snrs_1.count(-this_snr_1))
1861 snrs_1.insert(this_snr_1);
1866 if (snrs_2.count(this_snr_2))
1871 else if (snrs_2.count(-this_snr_2))
1875 snrs_2.insert(this_snr_2);
1880 bool cell_is_diff =
false;
1882 for (
int i = cells_prefix_sum_1[cell]; i < cells_prefix_sum_1[cell + 1] && i < cell_info_1.
number; ++i)
1885 const float this_weight = clusters_1.
cellWeights[i];
1886 bool found_match =
false;
1887 for (
int j = cells_prefix_sum_2[cell]; j < cells_prefix_sum_2[cell + 1] && j < cell_info_2.
number; ++j)
1895 ref_size_vec[this_index] += 1;
1896 ref_weighted_size_vec[this_index] += this_weight;
1899 ref_diff_cells[this_index] += 1;
1900 ref_diff_cells_weight[this_index] += this_weight;
1901 cell_is_diff =
true;
1905 for (
int i = cells_prefix_sum_2[cell]; i < cells_prefix_sum_2[cell + 1] && i < cell_info_2.
number; ++i)
1908 const float this_weight = clusters_2.
cellWeights[i];
1909 bool found_match =
false;
1910 for (
int j = cells_prefix_sum_1[cell]; j < cells_prefix_sum_1[cell + 1] && j < cell_info_1.
number; ++j)
1918 test_size_vec[this_index] += 1;
1919 test_weighted_size_vec[this_index] += this_weight;
1922 test_diff_cells[this_index] += 1;
1923 test_diff_cells_weight[this_index] += this_weight;
1924 cell_is_diff =
true;
1930#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS
1931 msg(MSG::INFO) <<
"Diff: " << cell <<
" |";
1932 for (
int i = cells_prefix_sum_1[cell]; i < cells_prefix_sum_1[cell + 1] && i < cell_info_1.
number; ++i)
1937 for (
int i = cells_prefix_sum_2[cell]; i < cells_prefix_sum_2[cell + 1] && i < cell_info_2.
number; ++i)
1944 ++diff_cluster_cells_count;
1946 else if ((cells_prefix_sum_1[cell + 1] > cells_prefix_sum_1[cell]) || (cells_prefix_sum_2[cell + 1] > cells_prefix_sum_2[cell]))
1948 ++same_cluster_cells_count;
1957 for (
int cluster = 0; cluster < clusters_1.
number; ++cluster)
1959 const int match = sch.
r2t(cluster);
1970 const auto prop_1 = prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cluster);
1971 const auto prop_2 = prop.get_property(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2,
match);
1973 cluster_properties[prop.name() +
"_ref"].push_back(prop_1);
1974 cluster_properties[prop.name() +
"_test"].push_back(prop_2);
1976 cluster_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1977 cluster_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_1)));
1978 cluster_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_2)));
1980 }, BasicClusterProperties{});
1986 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cluster,
1987 cell_info_2, clusters_2, cells_prefix_sum_2,
match));
1989 }, ComparedClusterProperties{});
1993 cluster_properties[
"size_ref"].push_back(ref_size_vec[cluster]);
1994 cluster_properties[
"size_test"].push_back(test_size_vec[
match]);
1995 cluster_properties[
"delta_size"].push_back(ref_size_vec[cluster] - test_size_vec[
match]);
1996 cluster_properties[
"delta_size_rel_ref"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) /
protect_from_zero(ref_size_vec[cluster]));
1997 cluster_properties[
"delta_size_rel_test"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) /
protect_from_zero(test_size_vec[
match]));
1999 cluster_properties[
"weighted_size_ref"].push_back(ref_weighted_size_vec[cluster]);
2000 cluster_properties[
"weighted_size_test"].push_back(test_weighted_size_vec[
match]);
2001 cluster_properties[
"delta_weighted_size"].push_back(ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]);
2002 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]));
2003 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]));
2008 cluster_properties[
"diff_cells_ref"].push_back(ref_diff_cells[cluster]);
2009 cluster_properties[
"diff_cells_ref_rel_size"].push_back(ref_diff_cells[cluster] /
protect_from_zero(ref_size_vec[cluster]));
2010 cluster_properties[
"diff_cells_test"].push_back(test_diff_cells[
match]);
2012 cluster_properties[
"diff_cells"].push_back(ref_diff_cells[cluster] + test_diff_cells[
match]);
2014 cluster_properties[
"weighted_diff_cells_ref"].push_back(ref_diff_cells_weight[cluster]);
2015 cluster_properties[
"weighted_diff_cells_ref_rel_size"].push_back(ref_diff_cells_weight[cluster] /
protect_from_zero(ref_weighted_size_vec[cluster]));
2016 cluster_properties[
"weighted_diff_cells_test"].push_back(test_diff_cells_weight[
match]);
2017 cluster_properties[
"weighted_diff_cells_test_rel_size"].push_back(test_diff_cells_weight[
match] /
protect_from_zero(test_weighted_size_vec[
match]));
2018 cluster_properties[
"weighted_diff_cells"].push_back(ref_diff_cells_weight[cluster] + test_diff_cells_weight[
match]);
2024 using scalar_type =
decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
2026 std::vector<coll_type> collections;
2027 std::vector<scalar_type> count_scalars;
2028 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
2030 collections.reserve(cluster_properties.size() + cell_properties.size());
2031 count_scalars.reserve(cell_counts.size() + 6 * 3);
2032 cluster_group.reserve(cluster_properties.size());
2033 cell_group.reserve(cell_properties.size());
2034 counts_group.reserve(cell_counts.size() + 3 + 6 * 3);
2036 auto add_count_vars = [&](
const std::string & name,
const long long int ref_num,
const long long int test_num)
2038 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + name +
"_ref", ref_num));
2039 counts_group.push_back(std::ref(count_scalars.back()));
2041 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + name +
"_test", test_num));
2042 counts_group.push_back(std::ref(count_scalars.back()));
2044 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_delta_" + name, test_num - ref_num));
2045 counts_group.push_back(std::ref(count_scalars.back()));
2048 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2051 add_count_vars(
"num_same_E_cells", same_energy_1, same_energy_2);
2052 add_count_vars(
"num_same_abs_E_cells", same_abs_energy_1, same_abs_energy_2);
2053 add_count_vars(
"num_same_SNR_cells", same_snr_1, same_snr_2);
2054 add_count_vars(
"num_same_abs_SNR_cells", same_abs_snr_1, same_abs_snr_2);
2057 auto mon_same_cluster_cell =
Monitored::Scalar(prefix +
"_same_cluster_cells", same_cluster_cells_count);
2058 auto mon_diff_cluster_cell =
Monitored::Scalar(prefix +
"_diff_cluster_cells", diff_cluster_cells_count);
2062 ATH_MSG_INFO(
"Different cells: " << diff_cluster_cells_count);
2065 counts_group.push_back(std::ref(mon_total_unmatched));
2066 counts_group.push_back(std::ref(mon_same_cluster_cell));
2067 counts_group.push_back(std::ref(mon_diff_cluster_cell));
2069 for (
const auto & k_v : cluster_properties)
2072 cluster_group.push_back(std::ref(collections.back()));
2075 for (
const auto & k_v : cell_properties)
2078 cell_group.push_back(std::ref(collections.back()));
2081 for (
const auto & k_v : cell_counts)
2083 count_scalars.emplace_back(
Monitored::Scalar(prefix +
"_" + k_v.first, k_v.second));
2084 counts_group.push_back(std::ref(count_scalars.back()));
2094 return StatusCode::SUCCESS;