1857 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1869 sample_comparisons_holder sch;
1871 if (match_perfectly)
1874 clusters_1, clusters_2, moments_1, moments_2, match_without_shared) );
1879 clusters_1, clusters_2, moments_1, moments_2, match_in_energy, match_without_shared) );
1882 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1884 std::unordered_map<std::string, long long int> cell_counts;
1886 std::vector<double> ref_size_vec(clusters_1.
number, 0.), test_size_vec(clusters_2.
number, 0.),
1887 ref_weighted_size_vec(clusters_1.
number, 0.), test_weighted_size_vec(clusters_2.
number, 0.),
1888 ref_diff_cells(clusters_1.
number, 0.), test_diff_cells(clusters_2.
number, 0.),
1889 ref_diff_cells_weight(clusters_1.
number, 0.), test_diff_cells_weight(clusters_2.
number, 0.);
1892 long long int same_energy_1 = 0, same_energy_2 = 0,
1893 same_abs_energy_1 = 0, same_abs_energy_2 = 0,
1894 same_snr_1 = 0, same_snr_2 = 0,
1895 same_abs_snr_1 = 0, same_abs_snr_2 = 0,
1896 same_cluster_cells_count = 0, diff_cluster_cells_count = 0;
1898 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1909 apply_to_multi_class([&](
const auto & prop,
const size_t i)
1913 const auto prop_1 = prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1,
cell);
1914 const auto prop_2 = prop.get_property(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
cell);
1916 cell_properties[prop.name() +
"_ref"].push_back(prop_1);
1917 cell_properties[prop.name() +
"_test"].push_back(prop_2);
1919 cell_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1920 cell_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_1)));
1921 cell_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_2)));
1923 }, BasicCellProperties{});
1925 apply_to_multi_class([&](
const auto & prop,
const size_t i)
1929 const auto is_1 = prop.is_type(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1,
cell);
1930 const auto is_2 = prop.is_type(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
cell);
1932 cell_counts[
"num_" + prop.name() +
"_cells_ref"] += is_1;
1933 cell_counts[
"num_" + prop.name() +
"_cells_test"] += is_2;
1934 cell_counts[
"delta_num_" + prop.name() +
"_cells"] += is_2 - is_1;
1936 }, BasicCellTypes{});
1938 const float this_energy_1 = cell_info_1.
energy[
cell];
1939 const float this_energy_2 = cell_info_2.
energy[
cell];
1944 if (energies_1.count(this_energy_1))
1947 ++same_abs_energy_1;
1949 else if (energies_1.count(-this_energy_1))
1951 ++same_abs_energy_1;
1953 energies_1.insert(this_energy_1);
1955 if (energies_2.count(this_energy_2))
1958 ++same_abs_energy_2;
1960 else if (energies_2.count(-this_energy_2))
1962 ++same_abs_energy_2;
1964 energies_2.insert(this_energy_2);
1969 const float this_snr_1 = this_energy_1 / protect_from_zero(constant_data.
m_cell_noise->get_noise(
cell, cell_info_1.
gain[
cell]));
1971 if (snrs_1.count(this_snr_1))
1976 else if (snrs_1.count(-this_snr_1))
1980 snrs_1.insert(this_snr_1);
1983 const float this_snr_2 = this_energy_2 / protect_from_zero(constant_data.
m_cell_noise->get_noise(
cell, cell_info_2.
gain[
cell]));
1985 if (snrs_2.count(this_snr_2))
1990 else if (snrs_2.count(-this_snr_2))
1994 snrs_2.insert(this_snr_2);
2002 int ref_c1 = -3, ref_c2 = -3, test_c1 = -3, test_c2 = -3;
2015 const int match_1 = test_c1 < 0 ? -1 : sch.t2r(test_c1);
2016 const int match_2 = test_c2 < 0 ? -1 : sch.t2r(test_c2);
2021 const float ref_weight = 1.0f - ref_rev_weight;
2022 const float test_weight = 1.0f - test_rev_weight;
2024 bool cell_is_diff =
false;
2028 ref_size_vec[ref_c1] += 1;
2029 ref_weighted_size_vec[ref_c1] += ref_weight;
2030 #if CALORECGPU_DISABLE_STRICT_MATCHING
2031 if (!(ref_c1 == match_1 || ref_c1 == match_2 || (match_1 < 0 || match_2 < 0)))
2033 if (!(ref_c1 == match_1 || ref_c1 == match_2))
2036 cell_is_diff =
true;
2037 ref_diff_cells[ref_c1] += 1;
2038 ref_diff_cells_weight[ref_c1] += ref_weight;
2044 ref_size_vec[ref_c2] += 1;
2045 ref_weighted_size_vec[ref_c2] += ref_rev_weight;
2046 #if CALORECGPU_DISABLE_STRICT_MATCHING
2047 if (!(ref_c2 == match_1 || ref_c2 == match_2 || (match_1 < 0 || match_2 < 0)))
2049 if (!(ref_c2 == match_1 || ref_c2 == match_2))
2052 cell_is_diff =
true;
2053 ref_diff_cells[ref_c2] += 1;
2054 ref_diff_cells_weight[ref_c2] += ref_rev_weight;
2060 test_size_vec[test_c1] += 1;
2061 test_weighted_size_vec[test_c1] += test_weight;
2062 #if CALORECGPU_DISABLE_STRICT_MATCHING
2063 if (match_1 >= 0 && !(match_1 == ref_c1 || match_1 == ref_c2 || (ref_c1 < 0 || ref_c2 < 0)))
2065 if (match_1 < 0 || !(match_1 == ref_c1 || match_1 == ref_c2))
2068 cell_is_diff =
true;
2069 test_diff_cells[test_c1] += 1;
2070 test_diff_cells_weight[test_c1] += test_weight;
2076 test_size_vec[test_c2] += 1;
2077 test_weighted_size_vec[test_c2] += test_rev_weight;
2078 #if CALORECGPU_DISABLE_STRICT_MATCHING
2079 if (match_2 >= 0 && !(match_2 == ref_c1 || match_2 == ref_c2 || (ref_c1 < 0 || ref_c2 < 0)))
2081 if (match_2 < 0 || !(match_2 == ref_c1 || match_2 == ref_c2))
2084 cell_is_diff =
true;
2085 test_diff_cells[test_c2] += 1;
2086 test_diff_cells_weight[test_c2] += test_rev_weight;
2090 if (!cell_is_diff && (ref_c1 >= 0 || ref_c2 >= 0 || test_c1 >= 0 || test_c2 >= 0))
2092 ++same_cluster_cells_count;
2094 else if (cell_is_diff)
2096 char message_buffer[256];
2097 snprintf(message_buffer, 256,
2098 "%7d | %18f || %6d | %6d | %6d | %6d || %6d | %6d || %016llX | %016llX",
2100 ref_c1, ref_c2, test_c1, test_c2,
2104 ++diff_cluster_cells_count;
2116 const int match = sch.r2t(cluster);
2123 apply_to_multi_class([&](
const auto & prop,
const size_t i)
2127 const auto prop_1 = prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1, cluster);
2128 const auto prop_2 = prop.get_property(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
match);
2130 cluster_properties[prop.name() +
"_ref"].push_back(prop_1);
2131 cluster_properties[prop.name() +
"_test"].push_back(prop_2);
2133 cluster_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
2134 cluster_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_1)));
2135 cluster_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_2)));
2137 }, BasicClusterProperties{});
2139 apply_to_multi_class([&](
const auto & prop,
const size_t i)
2143 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1, cluster,
2144 cell_info_2, cell_state_2, clusters_2, moments_2,
match));
2146 }, ComparedClusterProperties{});
2150 cluster_properties[
"size_ref"].push_back(ref_size_vec[cluster]);
2151 cluster_properties[
"size_test"].push_back(test_size_vec[
match]);
2152 cluster_properties[
"delta_size"].push_back(ref_size_vec[cluster] - test_size_vec[
match]);
2153 cluster_properties[
"delta_size_rel_ref"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) / protect_from_zero(ref_size_vec[cluster]));
2154 cluster_properties[
"delta_size_rel_test"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) / protect_from_zero(test_size_vec[
match]));
2156 cluster_properties[
"weighted_size_ref"].push_back(ref_weighted_size_vec[cluster]);
2157 cluster_properties[
"weighted_size_test"].push_back(test_weighted_size_vec[
match]);
2158 cluster_properties[
"delta_weighted_size"].push_back(ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]);
2159 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]));
2160 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]));
2165 cluster_properties[
"diff_cells_ref"].push_back(ref_diff_cells[cluster]);
2166 cluster_properties[
"diff_cells_ref_rel_size"].push_back(ref_diff_cells[cluster] / protect_from_zero(ref_size_vec[cluster]));
2167 cluster_properties[
"diff_cells_test"].push_back(test_diff_cells[
match]);
2168 cluster_properties[
"diff_cells_test_rel_size"].push_back(test_diff_cells[
match] / protect_from_zero(test_size_vec[
match]));
2169 cluster_properties[
"diff_cells"].push_back(ref_diff_cells[cluster] + test_diff_cells[
match]);
2171 cluster_properties[
"weighted_diff_cells_ref"].push_back(ref_diff_cells_weight[cluster]);
2172 cluster_properties[
"weighted_diff_cells_ref_rel_size"].push_back(ref_diff_cells_weight[cluster] / protect_from_zero(ref_weighted_size_vec[cluster]));
2173 cluster_properties[
"weighted_diff_cells_test"].push_back(test_diff_cells_weight[
match]);
2174 cluster_properties[
"weighted_diff_cells_test_rel_size"].push_back(test_diff_cells_weight[
match] / protect_from_zero(test_weighted_size_vec[
match]));
2175 cluster_properties[
"weighted_diff_cells"].push_back(ref_diff_cells_weight[cluster] + test_diff_cells_weight[
match]);
2181 using scalar_type = decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
2183 std::vector<coll_type> collections;
2184 std::vector<scalar_type> count_scalars;
2185 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
2187 collections.reserve(cluster_properties.size() + cell_properties.size());
2188 count_scalars.reserve(cell_counts.size() + 6 * 3);
2189 cluster_group.reserve(cluster_properties.size());
2190 cell_group.reserve(cell_properties.size());
2191 counts_group.reserve(cell_counts.size() + 3 + 6 * 3);
2193 auto add_count_vars = [&](
const std::string &
name,
const long long int ref_num,
const long long int test_num)
2196 counts_group.push_back(
std::ref(count_scalars.back()));
2199 counts_group.push_back(
std::ref(count_scalars.back()));
2202 counts_group.push_back(
std::ref(count_scalars.back()));
2205 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2206 add_count_vars(
"num_unmatched_clusters", sch.ref_unmatched(), sch.test_unmatched());
2208 add_count_vars(
"num_same_E_cells", same_energy_1, same_energy_2);
2209 add_count_vars(
"num_same_abs_E_cells", same_abs_energy_1, same_abs_energy_2);
2210 add_count_vars(
"num_same_SNR_cells", same_snr_1, same_snr_2);
2211 add_count_vars(
"num_same_abs_SNR_cells", same_abs_snr_1, same_abs_snr_2);
2213 auto mon_total_unmatched =
Monitored::Scalar(
prefix +
"_num_unmatched_clusters", sch.ref_unmatched() + sch.test_unmatched());
2217 counts_group.push_back(
std::ref(mon_total_unmatched));
2218 counts_group.push_back(
std::ref(mon_same_cluster_cell));
2219 counts_group.push_back(
std::ref(mon_diff_cluster_cell));
2221 for (
const auto & k_v : cluster_properties)
2224 cluster_group.push_back(
std::ref(collections.back()));
2227 for (
const auto & k_v : cell_properties)
2230 cell_group.push_back(
std::ref(collections.back()));
2233 for (
const auto & k_v : cell_counts)
2236 counts_group.push_back(
std::ref(count_scalars.back()));
2243 return StatusCode::SUCCESS;