1723{
1724
1725
1726
1727
1728
1729
1730 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1731
1732 const CaloRecGPU::CellInfoArr & cell_info_1 = store_vec[index_1].cell_info;
1733 const CaloRecGPU::ClusterInfoArr & clusters_1 = store_vec[index_1].clusters;
1734 const std::vector<int> & cells_prefix_sum_1 = store_vec[index_1].cells_prefix_sum;
1735
1736 const CaloRecGPU::CellInfoArr & cell_info_2 = store_vec[index_2].cell_info;
1737 const CaloRecGPU::ClusterInfoArr & clusters_2 = store_vec[index_2].clusters;
1738 const std::vector<int> & cells_prefix_sum_2 = store_vec[index_2].cells_prefix_sum;
1739
1741
1742 if (match_perfectly)
1743 {
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) );
1749 }
1750 else
1751 {
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) );
1757 }
1758
1759 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1760
1761 std::unordered_map<std::string, long long int> cell_counts;
1762
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.);
1767
1768
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;
1774
1775 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1776
1778 {
1780
1781
1782 {
1783 if ( cell >= cell_info_1.
number ||
1784 cell >= cell_info_2.
number ||
1787 {
1788 continue;
1789 }
1790
1792 {
1794 {
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);
1797
1798 cell_properties[prop.name() + "_ref"].push_back(prop_1);
1799 cell_properties[prop.name() + "_test"].push_back(prop_2);
1800
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)));
1804 }
1805 }, BasicCellProperties{});
1806
1808 {
1810 {
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);
1813
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;
1817 }
1818 }, BasicCellTypes{});
1819
1820 const float this_energy_1 = cell_info_1.
energy[
cell];
1821 const float this_energy_2 = cell_info_2.
energy[
cell];
1822
1824 {
1825 if (energies_1.count(this_energy_1))
1826 {
1827 ++same_energy_1;
1828 ++same_abs_energy_1;
1829 }
1830 else if (energies_1.count(-this_energy_1))
1831 {
1832 ++same_abs_energy_1;
1833 }
1834 energies_1.insert(this_energy_1);
1835
1836 if (energies_2.count(this_energy_2))
1837 {
1838 ++same_energy_2;
1839 ++same_abs_energy_2;
1840 }
1841 else if (energies_2.count(-this_energy_2))
1842 {
1843 ++same_abs_energy_2;
1844 }
1845 energies_2.insert(this_energy_2);
1846 }
1847
1849 {
1851
1852 if (snrs_1.count(this_snr_1))
1853 {
1854 ++same_snr_1;
1855 ++same_abs_snr_1;
1856 }
1857 else if (snrs_1.count(-this_snr_1))
1858 {
1859 ++same_abs_snr_1;
1860 }
1861 snrs_1.insert(this_snr_1);
1862
1863
1865
1866 if (snrs_2.count(this_snr_2))
1867 {
1868 ++same_snr_2;
1869 ++same_abs_snr_2;
1870 }
1871 else if (snrs_2.count(-this_snr_2))
1872 {
1873 ++same_abs_snr_2;
1874 }
1875 snrs_2.insert(this_snr_2);
1876 }
1877
1879 {
1880 bool cell_is_diff = false;
1881
1882 for (
int i = cells_prefix_sum_1[cell];
i < cells_prefix_sum_1[
cell + 1] &&
i < cell_info_1.
number; ++
i)
1883 {
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)
1888 {
1890 {
1891 found_match = true;
1892 break;
1893 }
1894 }
1895 ref_size_vec[this_index] += 1;
1896 ref_weighted_size_vec[this_index] += this_weight;
1897 if (!found_match)
1898 {
1899 ref_diff_cells[this_index] += 1;
1900 ref_diff_cells_weight[this_index] += this_weight;
1901 cell_is_diff = true;
1902 }
1903 }
1904
1905 for (
int i = cells_prefix_sum_2[cell];
i < cells_prefix_sum_2[
cell + 1] &&
i < cell_info_2.
number; ++
i)
1906 {
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)
1911 {
1913 {
1914 found_match = true;
1915 break;
1916 }
1917 }
1918 test_size_vec[this_index] += 1;
1919 test_weighted_size_vec[this_index] += this_weight;
1920 if (!found_match)
1921 {
1922 test_diff_cells[this_index] += 1;
1923 test_diff_cells_weight[this_index] += this_weight;
1924 cell_is_diff = true;
1925 }
1926 }
1927
1928 if (cell_is_diff)
1929 {
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)
1933 {
1935 }
1937 for (
int i = cells_prefix_sum_2[cell];
i < cells_prefix_sum_2[
cell + 1] &&
i < cell_info_2.
number; ++
i)
1938 {
1940 }
1942#endif
1943
1944 ++diff_cluster_cells_count;
1945 }
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]))
1947 {
1948 ++same_cluster_cells_count;
1949 }
1950 }
1951 }
1952 }
1953
1955 {
1956
1957 for (
int cluster = 0; cluster < clusters_1.
number; ++cluster)
1958 {
1959 const int match = sch.r2t(cluster);
1961
1962 {
1963 continue;
1964 }
1965
1967 {
1969 {
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);
1972
1973 cluster_properties[prop.name() + "_ref"].push_back(prop_1);
1974 cluster_properties[prop.name() + "_test"].push_back(prop_2);
1975
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)));
1979 }
1980 }, BasicClusterProperties{});
1981
1983 {
1985 {
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));
1988 }
1989 }, ComparedClusterProperties{});
1990
1992 {
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]));
1998
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]));
2004 }
2005
2007 {
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]);
2013
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]);
2019 }
2020 }
2021 }
2022
2024 using scalar_type = decltype(Monitored::Scalar("", std::declval<long long int>()));
2025
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;
2029
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);
2035
2036 auto add_count_vars = [&](
const std::string &
name,
const long long int ref_num,
const long long int test_num)
2037 {
2038 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + name + "_ref", ref_num));
2039 counts_group.push_back(std::ref(count_scalars.back()));
2040
2041 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + name + "_test", test_num));
2042 counts_group.push_back(std::ref(count_scalars.back()));
2043
2044 count_scalars.emplace_back(Monitored::Scalar(prefix + "_delta_" + name, test_num - ref_num));
2045 counts_group.push_back(std::ref(count_scalars.back()));
2046 };
2047
2048 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2049 add_count_vars("num_unmatched_clusters", sch.ref_unmatched(), sch.test_unmatched());
2050
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);
2055
2056 auto mon_total_unmatched = Monitored::Scalar(prefix + "_num_unmatched_clusters", sch.ref_unmatched() + sch.test_unmatched());
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);
2059
2061 {
2062 ATH_MSG_INFO(
"Different cells: " << diff_cluster_cells_count);
2063 }
2064
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));
2068
2069 for (const auto & k_v : cluster_properties)
2070 {
2072 cluster_group.push_back(std::ref(collections.back()));
2073 }
2074
2075 for (const auto & k_v : cell_properties)
2076 {
2078 cell_group.push_back(std::ref(collections.back()));
2079 }
2080
2081 for (const auto & k_v : cell_counts)
2082 {
2083 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + k_v.first, k_v.second));
2084 counts_group.push_back(std::ref(count_scalars.back()));
2085 }
2086
2087
2088
2089
2090 auto monitor_clusters = Monitored::Group(
m_moniTool, cluster_group);
2091 auto monitor_cells = Monitored::Group(
m_moniTool, cell_group);
2092 auto monitor_counts = Monitored::Group(
m_moniTool, counts_group);
2093
2094 return StatusCode::SUCCESS;
2095}
#define ATH_CHECK
Evaluate an expression and check for errors.
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_1, const CaloRecGPU::CellInfoArr &cell_info_2, const std::vector< int > &cells_prefix_sum_1, const std::vector< int > &cells_prefix_sum_2, 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
StatusCode match_clusters_perfectly(sample_comparisons_holder &sch, const CaloRecGPU::ConstantDataHolder &constant_data, const CaloRecGPU::CellInfoArr &cell_info_1, const CaloRecGPU::CellInfoArr &cell_info_2, const std::vector< int > &cells_prefix_sum_1, const std::vector< int > &cells_prefix_sum_2, const CaloRecGPU::ClusterInfoArr &cluster_info_1, const CaloRecGPU::ClusterInfoArr &cluster_info_2, const bool match_without_shared) const
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.
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
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]