1858 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1870 sample_comparisons_holder sch;
1872 if (match_perfectly)
1875 clusters_1, clusters_2, moments_1, moments_2, match_without_shared) );
1880 clusters_1, clusters_2, moments_1, moments_2, match_in_energy, match_without_shared) );
1883 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1885 std::unordered_map<std::string, long long int> cell_counts;
1887 std::vector<double> ref_size_vec(clusters_1.
number, 0.), test_size_vec(clusters_2.
number, 0.),
1888 ref_weighted_size_vec(clusters_1.
number, 0.), test_weighted_size_vec(clusters_2.
number, 0.),
1889 ref_diff_cells(clusters_1.
number, 0.), test_diff_cells(clusters_2.
number, 0.),
1890 ref_diff_cells_weight(clusters_1.
number, 0.), test_diff_cells_weight(clusters_2.
number, 0.);
1893 long long int same_energy_1 = 0, same_energy_2 = 0,
1894 same_abs_energy_1 = 0, same_abs_energy_2 = 0,
1895 same_snr_1 = 0, same_snr_2 = 0,
1896 same_abs_snr_1 = 0, same_abs_snr_2 = 0,
1897 same_cluster_cells_count = 0, diff_cluster_cells_count = 0;
1899 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1910 apply_to_multi_class([&](
const auto & prop,
const size_t i)
1914 const auto prop_1 = prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1,
cell);
1915 const auto prop_2 = prop.get_property(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
cell);
1917 cell_properties[prop.name() +
"_ref"].push_back(prop_1);
1918 cell_properties[prop.name() +
"_test"].push_back(prop_2);
1920 cell_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1921 cell_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_1)));
1922 cell_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_2)));
1924 }, BasicCellProperties{});
1926 apply_to_multi_class([&](
const auto & prop,
const size_t i)
1930 const auto is_1 = prop.is_type(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1,
cell);
1931 const auto is_2 = prop.is_type(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
cell);
1933 cell_counts[
"num_" + prop.name() +
"_cells_ref"] += is_1;
1934 cell_counts[
"num_" + prop.name() +
"_cells_test"] += is_2;
1935 cell_counts[
"delta_num_" + prop.name() +
"_cells"] += is_2 - is_1;
1937 }, BasicCellTypes{});
1939 const float this_energy_1 = cell_info_1.
energy[
cell];
1940 const float this_energy_2 = cell_info_2.
energy[
cell];
1945 if (energies_1.count(this_energy_1))
1948 ++same_abs_energy_1;
1950 else if (energies_1.count(-this_energy_1))
1952 ++same_abs_energy_1;
1954 energies_1.insert(this_energy_1);
1956 if (energies_2.count(this_energy_2))
1959 ++same_abs_energy_2;
1961 else if (energies_2.count(-this_energy_2))
1963 ++same_abs_energy_2;
1965 energies_2.insert(this_energy_2);
1970 const float this_snr_1 = this_energy_1 / protect_from_zero(constant_data.
m_cell_noise->get_noise(
cell, cell_info_1.
gain[
cell]));
1972 if (snrs_1.count(this_snr_1))
1977 else if (snrs_1.count(-this_snr_1))
1981 snrs_1.insert(this_snr_1);
1984 const float this_snr_2 = this_energy_2 / protect_from_zero(constant_data.
m_cell_noise->get_noise(
cell, cell_info_2.
gain[
cell]));
1986 if (snrs_2.count(this_snr_2))
1991 else if (snrs_2.count(-this_snr_2))
1995 snrs_2.insert(this_snr_2);
2003 int ref_c1 = -3, ref_c2 = -3, test_c1 = -3, test_c2 = -3;
2016 const int match_1 = test_c1 < 0 ? -1 : sch.t2r(test_c1);
2017 const int match_2 = test_c2 < 0 ? -1 : sch.t2r(test_c2);
2022 const float ref_weight = 1.0f - ref_rev_weight;
2023 const float test_weight = 1.0f - test_rev_weight;
2025 bool cell_is_diff =
false;
2029 ref_size_vec[ref_c1] += 1;
2030 ref_weighted_size_vec[ref_c1] += ref_weight;
2031 #if CALORECGPU_DISABLE_STRICT_MATCHING
2032 if (!(ref_c1 == match_1 || ref_c1 == match_2 || (match_1 < 0 || match_2 < 0)))
2034 if (!(ref_c1 == match_1 || ref_c1 == match_2))
2037 cell_is_diff =
true;
2038 ref_diff_cells[ref_c1] += 1;
2039 ref_diff_cells_weight[ref_c1] += ref_weight;
2045 ref_size_vec[ref_c2] += 1;
2046 ref_weighted_size_vec[ref_c2] += ref_rev_weight;
2047 #if CALORECGPU_DISABLE_STRICT_MATCHING
2048 if (!(ref_c2 == match_1 || ref_c2 == match_2 || (match_1 < 0 || match_2 < 0)))
2050 if (!(ref_c2 == match_1 || ref_c2 == match_2))
2053 cell_is_diff =
true;
2054 ref_diff_cells[ref_c2] += 1;
2055 ref_diff_cells_weight[ref_c2] += ref_rev_weight;
2061 test_size_vec[test_c1] += 1;
2062 test_weighted_size_vec[test_c1] += test_weight;
2063 #if CALORECGPU_DISABLE_STRICT_MATCHING
2064 if (match_1 >= 0 && !(match_1 == ref_c1 || match_1 == ref_c2 || (ref_c1 < 0 || ref_c2 < 0)))
2066 if (match_1 < 0 || !(match_1 == ref_c1 || match_1 == ref_c2))
2069 cell_is_diff =
true;
2070 test_diff_cells[test_c1] += 1;
2071 test_diff_cells_weight[test_c1] += test_weight;
2077 test_size_vec[test_c2] += 1;
2078 test_weighted_size_vec[test_c2] += test_rev_weight;
2079 #if CALORECGPU_DISABLE_STRICT_MATCHING
2080 if (match_2 >= 0 && !(match_2 == ref_c1 || match_2 == ref_c2 || (ref_c1 < 0 || ref_c2 < 0)))
2082 if (match_2 < 0 || !(match_2 == ref_c1 || match_2 == ref_c2))
2085 cell_is_diff =
true;
2086 test_diff_cells[test_c2] += 1;
2087 test_diff_cells_weight[test_c2] += test_rev_weight;
2091 if (!cell_is_diff && (ref_c1 >= 0 || ref_c2 >= 0 || test_c1 >= 0 || test_c2 >= 0))
2093 ++same_cluster_cells_count;
2095 else if (cell_is_diff)
2097 char message_buffer[256];
2098 snprintf(message_buffer, 256,
2099 "%7d | %18f || %6d | %6d | %6d | %6d || %6d | %6d || %016llX | %016llX",
2101 ref_c1, ref_c2, test_c1, test_c2,
2105 ++diff_cluster_cells_count;
2115 for (
int cluster = 0; cluster < clusters_1.
number; ++cluster)
2117 const int match = sch.r2t(cluster);
2124 apply_to_multi_class([&](
const auto & prop,
const size_t i)
2128 const auto prop_1 = prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1, cluster);
2129 const auto prop_2 = prop.get_property(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
match);
2131 cluster_properties[prop.name() +
"_ref"].push_back(prop_1);
2132 cluster_properties[prop.name() +
"_test"].push_back(prop_2);
2134 cluster_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
2135 cluster_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_1)));
2136 cluster_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_2)));
2138 }, BasicClusterProperties{});
2140 apply_to_multi_class([&](
const auto & prop,
const size_t i)
2144 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1, cluster,
2145 cell_info_2, cell_state_2, clusters_2, moments_2,
match));
2147 }, ComparedClusterProperties{});
2151 cluster_properties[
"size_ref"].push_back(ref_size_vec[cluster]);
2152 cluster_properties[
"size_test"].push_back(test_size_vec[
match]);
2153 cluster_properties[
"delta_size"].push_back(ref_size_vec[cluster] - test_size_vec[
match]);
2154 cluster_properties[
"delta_size_rel_ref"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) / protect_from_zero(ref_size_vec[cluster]));
2155 cluster_properties[
"delta_size_rel_test"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) / protect_from_zero(test_size_vec[
match]));
2157 cluster_properties[
"weighted_size_ref"].push_back(ref_weighted_size_vec[cluster]);
2158 cluster_properties[
"weighted_size_test"].push_back(test_weighted_size_vec[
match]);
2159 cluster_properties[
"delta_weighted_size"].push_back(ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]);
2160 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]));
2161 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]));
2166 cluster_properties[
"diff_cells_ref"].push_back(ref_diff_cells[cluster]);
2167 cluster_properties[
"diff_cells_ref_rel_size"].push_back(ref_diff_cells[cluster] / protect_from_zero(ref_size_vec[cluster]));
2168 cluster_properties[
"diff_cells_test"].push_back(test_diff_cells[
match]);
2169 cluster_properties[
"diff_cells_test_rel_size"].push_back(test_diff_cells[
match] / protect_from_zero(test_size_vec[
match]));
2170 cluster_properties[
"diff_cells"].push_back(ref_diff_cells[cluster] + test_diff_cells[
match]);
2172 cluster_properties[
"weighted_diff_cells_ref"].push_back(ref_diff_cells_weight[cluster]);
2173 cluster_properties[
"weighted_diff_cells_ref_rel_size"].push_back(ref_diff_cells_weight[cluster] / protect_from_zero(ref_weighted_size_vec[cluster]));
2174 cluster_properties[
"weighted_diff_cells_test"].push_back(test_diff_cells_weight[
match]);
2175 cluster_properties[
"weighted_diff_cells_test_rel_size"].push_back(test_diff_cells_weight[
match] / protect_from_zero(test_weighted_size_vec[
match]));
2176 cluster_properties[
"weighted_diff_cells"].push_back(ref_diff_cells_weight[cluster] + test_diff_cells_weight[
match]);
2182 using scalar_type = decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
2184 std::vector<coll_type> collections;
2185 std::vector<scalar_type> count_scalars;
2186 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
2188 collections.reserve(cluster_properties.size() + cell_properties.size());
2189 count_scalars.reserve(cell_counts.size() + 6 * 3);
2190 cluster_group.reserve(cluster_properties.size());
2191 cell_group.reserve(cell_properties.size());
2192 counts_group.reserve(cell_counts.size() + 3 + 6 * 3);
2194 auto add_count_vars = [&](
const std::string &
name,
const long long int ref_num,
const long long int test_num)
2197 counts_group.push_back(
std::ref(count_scalars.back()));
2200 counts_group.push_back(
std::ref(count_scalars.back()));
2203 counts_group.push_back(
std::ref(count_scalars.back()));
2206 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2207 add_count_vars(
"num_unmatched_clusters", sch.ref_unmatched(), sch.test_unmatched());
2209 add_count_vars(
"num_same_E_cells", same_energy_1, same_energy_2);
2210 add_count_vars(
"num_same_abs_E_cells", same_abs_energy_1, same_abs_energy_2);
2211 add_count_vars(
"num_same_SNR_cells", same_snr_1, same_snr_2);
2212 add_count_vars(
"num_same_abs_SNR_cells", same_abs_snr_1, same_abs_snr_2);
2214 auto mon_total_unmatched =
Monitored::Scalar(
prefix +
"_num_unmatched_clusters", sch.ref_unmatched() + sch.test_unmatched());
2218 counts_group.push_back(
std::ref(mon_total_unmatched));
2219 counts_group.push_back(
std::ref(mon_same_cluster_cell));
2220 counts_group.push_back(
std::ref(mon_diff_cluster_cell));
2222 for (
const auto & k_v : cluster_properties)
2225 cluster_group.push_back(
std::ref(collections.back()));
2228 for (
const auto & k_v : cell_properties)
2231 cell_group.push_back(
std::ref(collections.back()));
2234 for (
const auto & k_v : cell_counts)
2237 counts_group.push_back(
std::ref(count_scalars.back()));
2244 return StatusCode::SUCCESS;