1729{
1730
1731
1732
1733
1734
1735
1736 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1737
1738 const CaloRecGPU::CellInfoArr & cell_info_1 = store_vec[index_1].cell_info;
1739 const CaloRecGPU::ClusterInfoArr & clusters_1 = store_vec[index_1].clusters;
1740 const std::vector<int> & cells_prefix_sum_1 = store_vec[index_1].cells_prefix_sum;
1741
1742 const CaloRecGPU::CellInfoArr & cell_info_2 = store_vec[index_2].cell_info;
1743 const CaloRecGPU::ClusterInfoArr & clusters_2 = store_vec[index_2].clusters;
1744 const std::vector<int> & cells_prefix_sum_2 = store_vec[index_2].cells_prefix_sum;
1745
1747
1748 if (match_perfectly)
1749 {
1751 }
1752 else
1753 {
1754 ATH_CHECK(
match_clusters(sch, constant_data, cell_info_1, clusters_1, clusters_2, match_in_energy, match_without_shared) );
1755 }
1756
1757 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1758
1759 std::unordered_map<std::string, long long int> cell_counts;
1760
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.);
1765
1766
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;
1772
1773 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1774
1776 {
1778
1779
1780 {
1782 {
1783 continue;
1784 }
1785
1787 {
1789 {
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);
1792
1793 cell_properties[prop.name() + "_ref"].push_back(prop_1);
1794 cell_properties[prop.name() + "_test"].push_back(prop_2);
1795
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)));
1799 }
1800 }, BasicCellProperties{});
1801
1803 {
1805 {
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);
1808
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;
1812 }
1813 }, BasicCellTypes{});
1814
1815 const float this_energy_1 = cell_info_1.
energy[
cell];
1816 const float this_energy_2 = cell_info_2.
energy[
cell];
1817
1819 {
1820 if (energies_1.count(this_energy_1))
1821 {
1822 ++same_energy_1;
1823 ++same_abs_energy_1;
1824 }
1825 else if (energies_1.count(-this_energy_1))
1826 {
1827 ++same_abs_energy_1;
1828 }
1829 energies_1.insert(this_energy_1);
1830
1831 if (energies_2.count(this_energy_2))
1832 {
1833 ++same_energy_2;
1834 ++same_abs_energy_2;
1835 }
1836 else if (energies_2.count(-this_energy_2))
1837 {
1838 ++same_abs_energy_2;
1839 }
1840 energies_2.insert(this_energy_2);
1841 }
1842
1844 {
1846
1847 if (snrs_1.count(this_snr_1))
1848 {
1849 ++same_snr_1;
1850 ++same_abs_snr_1;
1851 }
1852 else if (snrs_1.count(-this_snr_1))
1853 {
1854 ++same_abs_snr_1;
1855 }
1856 snrs_1.insert(this_snr_1);
1857
1858
1860
1861 if (snrs_2.count(this_snr_2))
1862 {
1863 ++same_snr_2;
1864 ++same_abs_snr_2;
1865 }
1866 else if (snrs_2.count(-this_snr_2))
1867 {
1868 ++same_abs_snr_2;
1869 }
1870 snrs_2.insert(this_snr_2);
1871 }
1872
1874 {
1875 bool cell_is_diff = false;
1876
1877 for (
int i = cells_prefix_sum_1[cell];
i < cells_prefix_sum_1[
cell + 1] &&
i < cell_info_1.
number; ++
i)
1878 {
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)
1883 {
1885 {
1886 found_match = true;
1887 break;
1888 }
1889 }
1890 ref_size_vec[this_index] += 1;
1891 ref_weighted_size_vec[this_index] += this_weight;
1892 if (!found_match)
1893 {
1894 ref_diff_cells[this_index] += 1;
1895 ref_diff_cells_weight[this_index] += this_weight;
1896 cell_is_diff = true;
1897 }
1898 }
1899
1900 for (
int i = cells_prefix_sum_2[cell];
i < cells_prefix_sum_2[
cell + 1] &&
i < cell_info_2.
number; ++
i)
1901 {
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)
1906 {
1908 {
1909 found_match = true;
1910 break;
1911 }
1912 }
1913 test_size_vec[this_index] += 1;
1914 test_weighted_size_vec[this_index] += this_weight;
1915 if (!found_match)
1916 {
1917 test_diff_cells[this_index] += 1;
1918 test_diff_cells_weight[this_index] += this_weight;
1919 cell_is_diff = true;
1920 }
1921 }
1922
1923 if (cell_is_diff)
1924 {
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)
1928 {
1930 }
1932 for (
int i = cells_prefix_sum_2[cell];
i < cells_prefix_sum_2[
cell + 1] &&
i < cell_info_2.
number; ++
i)
1933 {
1935 }
1937#endif
1938
1939 ++diff_cluster_cells_count;
1940 }
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]))
1942 {
1943 ++same_cluster_cells_count;
1944 }
1945 }
1946 }
1947 }
1948
1950 {
1951
1952 for (
int cluster = 0; cluster < clusters_1.
number; ++cluster)
1953 {
1954 const int match = sch.r2t(cluster);
1956
1957 {
1958 continue;
1959 }
1960
1962 {
1964 {
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);
1967
1968 cluster_properties[prop.name() + "_ref"].push_back(prop_1);
1969 cluster_properties[prop.name() + "_test"].push_back(prop_2);
1970
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)));
1974 }
1975 }, BasicClusterProperties{});
1976
1978 {
1980 {
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));
1983 }
1984 }, ComparedClusterProperties{});
1985
1987 {
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]));
1993
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]));
1999 }
2000
2002 {
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]);
2008
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]);
2014 }
2015 }
2016 }
2017
2019 using scalar_type = decltype(Monitored::Scalar("", std::declval<long long int>()));
2020
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;
2024
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);
2030
2031 auto add_count_vars = [&](
const std::string &
name,
const long long int ref_num,
const long long int test_num)
2032 {
2033 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + name + "_ref", ref_num));
2034 counts_group.push_back(std::ref(count_scalars.back()));
2035
2036 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + name + "_test", test_num));
2037 counts_group.push_back(std::ref(count_scalars.back()));
2038
2039 count_scalars.emplace_back(Monitored::Scalar(prefix + "_delta_" + name, test_num - ref_num));
2040 counts_group.push_back(std::ref(count_scalars.back()));
2041 };
2042
2043 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2044 add_count_vars("num_unmatched_clusters", sch.ref_unmatched(), sch.test_unmatched());
2045
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);
2050
2051 auto mon_total_unmatched = Monitored::Scalar(prefix + "_num_unmatched_clusters", sch.ref_unmatched() + sch.test_unmatched());
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);
2054
2056 {
2057 ATH_MSG_INFO(
"Different cells: " << diff_cluster_cells_count);
2058 }
2059
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));
2063
2064 for (const auto & k_v : cluster_properties)
2065 {
2067 cluster_group.push_back(std::ref(collections.back()));
2068 }
2069
2070 for (const auto & k_v : cell_properties)
2071 {
2073 cell_group.push_back(std::ref(collections.back()));
2074 }
2075
2076 for (const auto & k_v : cell_counts)
2077 {
2078 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + k_v.first, k_v.second));
2079 counts_group.push_back(std::ref(count_scalars.back()));
2080 }
2081
2082
2083
2084
2085 auto monitor_clusters = Monitored::Group(
m_moniTool, cluster_group);
2086 auto monitor_cells = Monitored::Group(
m_moniTool, cell_group);
2087 auto monitor_counts = Monitored::Group(
m_moniTool, counts_group);
2088
2089 return StatusCode::SUCCESS;
2090}
#define ATH_CHECK
Evaluate an expression and check for errors.
StatusCode match_clusters_perfectly(sample_comparisons_holder &sch, const CaloRecGPU::ConstantDataHolder &constant_data, const CaloRecGPU::CellInfoArr &cell_info, const CaloRecGPU::ClusterInfoArr &cluster_info_1, const CaloRecGPU::ClusterInfoArr &cluster_info_2, const bool match_without_shared) const
std::vector< bool > m_comparedClusterPropertiesToDo
std::vector< bool > m_comparedCellPropertiesToDo
std::vector< bool > m_extraComparedClusterPropertiesToDo
std::vector< bool > m_comparedCellTypesToDo
ToolHandle< GenericMonitoringTool > m_moniTool
Monitoring tool.
bool m_doCombinedClusters
StatusCode match_clusters(sample_comparisons_holder &sch, const CaloRecGPU::ConstantDataHolder &constant_data, const CaloRecGPU::CellInfoArr &cell_info, const CaloRecGPU::ClusterInfoArr &cluster_info_1, const CaloRecGPU::ClusterInfoArr &cluster_info_2, const bool match_in_energy, const bool match_without_shared) const
std::vector< bool > m_extraThingsToDo
CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellNoiseArr > m_cell_noise
bool match(std::string s1, std::string s2)
match the individual directories of two strings
double protect_from_zero(const double x)
void apply_to_multi_class(F &&f, multi_class_holder< Types... >, Args &... args)
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
constexpr int get_hash_ID(const int cell, const bool is_complete=false) const
unsigned char gain[NCaloCells]
constexpr bool is_valid(const int hash_ID, const bool is_complete=false, const bool all_cells_are_valid=false) const
int clusterIndices[2 *NCaloCells]
float cellWeights[2 *NCaloCells]