1860 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1872 sample_comparisons_holder sch;
1874 if (match_perfectly)
1877 clusters_1, clusters_2, moments_1, moments_2, match_without_shared) );
1882 clusters_1, clusters_2, moments_1, moments_2, match_in_energy, match_without_shared) );
1885 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1887 std::unordered_map<std::string, long long int> cell_counts;
1889 std::vector<double> ref_size_vec(clusters_1.
number, 0.), test_size_vec(clusters_2.
number, 0.),
1890 ref_weighted_size_vec(clusters_1.
number, 0.), test_weighted_size_vec(clusters_2.
number, 0.),
1891 ref_diff_cells(clusters_1.
number, 0.), test_diff_cells(clusters_2.
number, 0.),
1892 ref_diff_cells_weight(clusters_1.
number, 0.), test_diff_cells_weight(clusters_2.
number, 0.);
1895 long long int same_energy_1 = 0, same_energy_2 = 0,
1896 same_abs_energy_1 = 0, same_abs_energy_2 = 0,
1897 same_snr_1 = 0, same_snr_2 = 0,
1898 same_abs_snr_1 = 0, same_abs_snr_2 = 0,
1899 same_cluster_cells_count = 0, diff_cluster_cells_count = 0;
1901 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1912 apply_to_multi_class([&](
const auto & prop,
const size_t i)
1916 const auto prop_1 = prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1,
cell);
1917 const auto prop_2 = prop.get_property(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
cell);
1919 cell_properties[prop.name() +
"_ref"].push_back(prop_1);
1920 cell_properties[prop.name() +
"_test"].push_back(prop_2);
1922 cell_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
1923 cell_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_1)));
1924 cell_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_2)));
1926 }, BasicCellProperties{});
1928 apply_to_multi_class([&](
const auto & prop,
const size_t i)
1932 const auto is_1 = prop.is_type(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1,
cell);
1933 const auto is_2 = prop.is_type(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
cell);
1935 cell_counts[
"num_" + prop.name() +
"_cells_ref"] += is_1;
1936 cell_counts[
"num_" + prop.name() +
"_cells_test"] += is_2;
1937 cell_counts[
"delta_num_" + prop.name() +
"_cells"] += is_2 - is_1;
1939 }, BasicCellTypes{});
1941 const float this_energy_1 = cell_info_1.
energy[
cell];
1942 const float this_energy_2 = cell_info_2.
energy[
cell];
1947 if (energies_1.count(this_energy_1))
1950 ++same_abs_energy_1;
1952 else if (energies_1.count(-this_energy_1))
1954 ++same_abs_energy_1;
1956 energies_1.insert(this_energy_1);
1958 if (energies_2.count(this_energy_2))
1961 ++same_abs_energy_2;
1963 else if (energies_2.count(-this_energy_2))
1965 ++same_abs_energy_2;
1967 energies_2.insert(this_energy_2);
1972 const float this_snr_1 = this_energy_1 / protect_from_zero(constant_data.
m_cell_noise->get_noise(
cell, cell_info_1.
gain[
cell]));
1974 if (snrs_1.count(this_snr_1))
1979 else if (snrs_1.count(-this_snr_1))
1983 snrs_1.insert(this_snr_1);
1986 const float this_snr_2 = this_energy_2 / protect_from_zero(constant_data.
m_cell_noise->get_noise(
cell, cell_info_2.
gain[
cell]));
1988 if (snrs_2.count(this_snr_2))
1993 else if (snrs_2.count(-this_snr_2))
1997 snrs_2.insert(this_snr_2);
2005 int ref_c1 = -3, ref_c2 = -3, test_c1 = -3, test_c2 = -3;
2018 const int match_1 = test_c1 < 0 ? -1 : sch.t2r(test_c1);
2019 const int match_2 = test_c2 < 0 ? -1 : sch.t2r(test_c2);
2024 const float ref_weight = 1.0f - ref_rev_weight;
2025 const float test_weight = 1.0f - test_rev_weight;
2027 bool cell_is_diff =
false;
2031 ref_size_vec[ref_c1] += 1;
2032 ref_weighted_size_vec[ref_c1] += ref_weight;
2033 #if CALORECGPU_DISABLE_STRICT_MATCHING
2034 if (!(ref_c1 == match_1 || ref_c1 == match_2 || (match_1 < 0 || match_2 < 0)))
2036 if (!(ref_c1 == match_1 || ref_c1 == match_2))
2039 cell_is_diff =
true;
2040 ref_diff_cells[ref_c1] += 1;
2041 ref_diff_cells_weight[ref_c1] += ref_weight;
2047 ref_size_vec[ref_c2] += 1;
2048 ref_weighted_size_vec[ref_c2] += ref_rev_weight;
2049 #if CALORECGPU_DISABLE_STRICT_MATCHING
2050 if (!(ref_c2 == match_1 || ref_c2 == match_2 || (match_1 < 0 || match_2 < 0)))
2052 if (!(ref_c2 == match_1 || ref_c2 == match_2))
2055 cell_is_diff =
true;
2056 ref_diff_cells[ref_c2] += 1;
2057 ref_diff_cells_weight[ref_c2] += ref_rev_weight;
2063 test_size_vec[test_c1] += 1;
2064 test_weighted_size_vec[test_c1] += test_weight;
2065 #if CALORECGPU_DISABLE_STRICT_MATCHING
2066 if (match_1 >= 0 && !(match_1 == ref_c1 || match_1 == ref_c2 || (ref_c1 < 0 || ref_c2 < 0)))
2068 if (match_1 < 0 || !(match_1 == ref_c1 || match_1 == ref_c2))
2071 cell_is_diff =
true;
2072 test_diff_cells[test_c1] += 1;
2073 test_diff_cells_weight[test_c1] += test_weight;
2079 test_size_vec[test_c2] += 1;
2080 test_weighted_size_vec[test_c2] += test_rev_weight;
2081 #if CALORECGPU_DISABLE_STRICT_MATCHING
2082 if (match_2 >= 0 && !(match_2 == ref_c1 || match_2 == ref_c2 || (ref_c1 < 0 || ref_c2 < 0)))
2084 if (match_2 < 0 || !(match_2 == ref_c1 || match_2 == ref_c2))
2087 cell_is_diff =
true;
2088 test_diff_cells[test_c2] += 1;
2089 test_diff_cells_weight[test_c2] += test_rev_weight;
2093 if (!cell_is_diff && (ref_c1 >= 0 || ref_c2 >= 0 || test_c1 >= 0 || test_c2 >= 0))
2095 ++same_cluster_cells_count;
2097 else if (cell_is_diff)
2099 char message_buffer[256];
2100 snprintf(message_buffer, 256,
2101 "%7d | %18f || %6d | %6d | %6d | %6d || %6d | %6d || %016llX | %016llX",
2103 ref_c1, ref_c2, test_c1, test_c2,
2107 ++diff_cluster_cells_count;
2117 for (
int cluster = 0; cluster < clusters_1.
number; ++cluster)
2119 const int match = sch.r2t(cluster);
2126 apply_to_multi_class([&](
const auto & prop,
const size_t i)
2130 const auto prop_1 = prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1, cluster);
2131 const auto prop_2 = prop.get_property(constant_data, cell_info_2, cell_state_2, clusters_2, moments_2,
match);
2133 cluster_properties[prop.name() +
"_ref"].push_back(prop_1);
2134 cluster_properties[prop.name() +
"_test"].push_back(prop_2);
2136 cluster_properties[
"delta_" + prop.name()].push_back(prop_2 - prop_1);
2137 cluster_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_1)));
2138 cluster_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) / protect_from_zero(std::abs(prop_2)));
2140 }, BasicClusterProperties{});
2142 apply_to_multi_class([&](
const auto & prop,
const size_t i)
2146 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, cell_info_1, cell_state_1, clusters_1, moments_1, cluster,
2147 cell_info_2, cell_state_2, clusters_2, moments_2,
match));
2149 }, ComparedClusterProperties{});
2153 cluster_properties[
"size_ref"].push_back(ref_size_vec[cluster]);
2154 cluster_properties[
"size_test"].push_back(test_size_vec[
match]);
2155 cluster_properties[
"delta_size"].push_back(ref_size_vec[cluster] - test_size_vec[
match]);
2156 cluster_properties[
"delta_size_rel_ref"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) / protect_from_zero(ref_size_vec[cluster]));
2157 cluster_properties[
"delta_size_rel_test"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) / protect_from_zero(test_size_vec[
match]));
2159 cluster_properties[
"weighted_size_ref"].push_back(ref_weighted_size_vec[cluster]);
2160 cluster_properties[
"weighted_size_test"].push_back(test_weighted_size_vec[
match]);
2161 cluster_properties[
"delta_weighted_size"].push_back(ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]);
2162 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]));
2163 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]));
2168 cluster_properties[
"diff_cells_ref"].push_back(ref_diff_cells[cluster]);
2169 cluster_properties[
"diff_cells_ref_rel_size"].push_back(ref_diff_cells[cluster] / protect_from_zero(ref_size_vec[cluster]));
2170 cluster_properties[
"diff_cells_test"].push_back(test_diff_cells[
match]);
2171 cluster_properties[
"diff_cells_test_rel_size"].push_back(test_diff_cells[
match] / protect_from_zero(test_size_vec[
match]));
2172 cluster_properties[
"diff_cells"].push_back(ref_diff_cells[cluster] + test_diff_cells[
match]);
2174 cluster_properties[
"weighted_diff_cells_ref"].push_back(ref_diff_cells_weight[cluster]);
2175 cluster_properties[
"weighted_diff_cells_ref_rel_size"].push_back(ref_diff_cells_weight[cluster] / protect_from_zero(ref_weighted_size_vec[cluster]));
2176 cluster_properties[
"weighted_diff_cells_test"].push_back(test_diff_cells_weight[
match]);
2177 cluster_properties[
"weighted_diff_cells_test_rel_size"].push_back(test_diff_cells_weight[
match] / protect_from_zero(test_weighted_size_vec[
match]));
2178 cluster_properties[
"weighted_diff_cells"].push_back(ref_diff_cells_weight[cluster] + test_diff_cells_weight[
match]);
2184 using scalar_type = decltype(
Monitored::Scalar(
"", std::declval<long long int>()));
2186 std::vector<coll_type> collections;
2187 std::vector<scalar_type> count_scalars;
2188 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
2190 collections.reserve(cluster_properties.size() + cell_properties.size());
2191 count_scalars.reserve(cell_counts.size() + 6 * 3);
2192 cluster_group.reserve(cluster_properties.size());
2193 cell_group.reserve(cell_properties.size());
2194 counts_group.reserve(cell_counts.size() + 3 + 6 * 3);
2196 auto add_count_vars = [&](
const std::string &
name,
const long long int ref_num,
const long long int test_num)
2199 counts_group.push_back(
std::ref(count_scalars.back()));
2202 counts_group.push_back(
std::ref(count_scalars.back()));
2205 counts_group.push_back(
std::ref(count_scalars.back()));
2208 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2209 add_count_vars(
"num_unmatched_clusters", sch.ref_unmatched(), sch.test_unmatched());
2211 add_count_vars(
"num_same_E_cells", same_energy_1, same_energy_2);
2212 add_count_vars(
"num_same_abs_E_cells", same_abs_energy_1, same_abs_energy_2);
2213 add_count_vars(
"num_same_SNR_cells", same_snr_1, same_snr_2);
2214 add_count_vars(
"num_same_abs_SNR_cells", same_abs_snr_1, same_abs_snr_2);
2216 auto mon_total_unmatched =
Monitored::Scalar(
prefix +
"_num_unmatched_clusters", sch.ref_unmatched() + sch.test_unmatched());
2220 counts_group.push_back(
std::ref(mon_total_unmatched));
2221 counts_group.push_back(
std::ref(mon_same_cluster_cell));
2222 counts_group.push_back(
std::ref(mon_diff_cluster_cell));
2224 for (
const auto & k_v : cluster_properties)
2227 cluster_group.push_back(
std::ref(collections.back()));
2230 for (
const auto & k_v : cell_properties)
2233 cell_group.push_back(
std::ref(collections.back()));
2236 for (
const auto & k_v : cell_counts)
2239 counts_group.push_back(
std::ref(count_scalars.back()));
2249 return StatusCode::SUCCESS;