1722{
1723
1724
1725
1726
1727
1728
1729 std::vector<per_tool_storage> & store_vec = m_storageHolder.get_for_thread();
1730
1731 const CaloRecGPU::CellInfoArr & cell_info_1 = store_vec[index_1].cell_info;
1732 const CaloRecGPU::ClusterInfoArr & clusters_1 = store_vec[index_1].clusters;
1733 const std::vector<int> & cells_prefix_sum_1 = store_vec[index_1].cells_prefix_sum;
1734
1735 const CaloRecGPU::CellInfoArr & cell_info_2 = store_vec[index_2].cell_info;
1736 const CaloRecGPU::ClusterInfoArr & clusters_2 = store_vec[index_2].clusters;
1737 const std::vector<int> & cells_prefix_sum_2 = store_vec[index_2].cells_prefix_sum;
1738
1740
1741 if (match_perfectly)
1742 {
1744 cell_info_1, cell_info_2,
1745 cells_prefix_sum_1, cells_prefix_sum_2,
1746 clusters_1, clusters_2,
1747 match_without_shared) );
1748 }
1749 else
1750 {
1752 cell_info_1, cell_info_2,
1753 cells_prefix_sum_1, cells_prefix_sum_2,
1754 clusters_1, clusters_2,
1755 match_in_energy, match_without_shared) );
1756 }
1757
1758 std::unordered_map<std::string, std::vector<double>> cluster_properties, cell_properties;
1759
1760 std::unordered_map<std::string, long long int> cell_counts;
1761
1762 std::vector<double> ref_size_vec(clusters_1.
number, 0.), test_size_vec(clusters_2.
number, 0.),
1763 ref_weighted_size_vec(clusters_1.
number, 0.), test_weighted_size_vec(clusters_2.
number, 0.),
1764 ref_diff_cells(clusters_1.
number, 0.), test_diff_cells(clusters_2.
number, 0.),
1765 ref_diff_cells_weight(clusters_1.
number, 0.), test_diff_cells_weight(clusters_2.
number, 0.);
1766
1767
1768 long long int same_energy_1 = 0, same_energy_2 = 0,
1769 same_abs_energy_1 = 0, same_abs_energy_2 = 0,
1770 same_snr_1 = 0, same_snr_2 = 0,
1771 same_abs_snr_1 = 0, same_abs_snr_2 = 0,
1772 same_cluster_cells_count = 0, diff_cluster_cells_count = 0;
1773
1774 std::set<double> energies_1, energies_2, snrs_1, snrs_2;
1775
1777 {
1779
1780
1781 {
1782 if ( cell >= cell_info_1.
number ||
1783 cell >= cell_info_2.
number ||
1786 {
1787 continue;
1788 }
1789
1791 {
1793 {
1794 const auto prop_1 = prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cell);
1795 const auto prop_2 = prop.get_property(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2, cell);
1796
1797 cell_properties[prop.name() + "_ref"].push_back(prop_1);
1798 cell_properties[prop.name() + "_test"].push_back(prop_2);
1799
1800 cell_properties["delta_" + prop.name()].push_back(prop_2 - prop_1);
1801 cell_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_1)));
1802 cell_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_2)));
1803 }
1804 }, BasicCellProperties{});
1805
1807 {
1809 {
1810 const auto is_1 = prop.is_type(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cell);
1811 const auto is_2 = prop.is_type(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2, cell);
1812
1813 cell_counts["num_" + prop.name() + "_cells_ref"] += is_1;
1814 cell_counts["num_" + prop.name() + "_cells_test"] += is_2;
1815 cell_counts["delta_num_" + prop.name() + "_cells"] += is_2 - is_1;
1816 }
1817 }, BasicCellTypes{});
1818
1819 const float this_energy_1 = cell_info_1.
energy[
cell];
1820 const float this_energy_2 = cell_info_2.
energy[
cell];
1821
1823 {
1824 if (energies_1.count(this_energy_1))
1825 {
1826 ++same_energy_1;
1827 ++same_abs_energy_1;
1828 }
1829 else if (energies_1.count(-this_energy_1))
1830 {
1831 ++same_abs_energy_1;
1832 }
1833 energies_1.insert(this_energy_1);
1834
1835 if (energies_2.count(this_energy_2))
1836 {
1837 ++same_energy_2;
1838 ++same_abs_energy_2;
1839 }
1840 else if (energies_2.count(-this_energy_2))
1841 {
1842 ++same_abs_energy_2;
1843 }
1844 energies_2.insert(this_energy_2);
1845 }
1846
1848 {
1850
1851 if (snrs_1.count(this_snr_1))
1852 {
1853 ++same_snr_1;
1854 ++same_abs_snr_1;
1855 }
1856 else if (snrs_1.count(-this_snr_1))
1857 {
1858 ++same_abs_snr_1;
1859 }
1860 snrs_1.insert(this_snr_1);
1861
1862
1864
1865 if (snrs_2.count(this_snr_2))
1866 {
1867 ++same_snr_2;
1868 ++same_abs_snr_2;
1869 }
1870 else if (snrs_2.count(-this_snr_2))
1871 {
1872 ++same_abs_snr_2;
1873 }
1874 snrs_2.insert(this_snr_2);
1875 }
1876
1878 {
1879 bool cell_is_diff = false;
1880
1881 for (
int i = cells_prefix_sum_1[cell];
i < cells_prefix_sum_1[
cell + 1] &&
i < cell_info_1.
number; ++
i)
1882 {
1885 bool found_match = false;
1886 for (
int j = cells_prefix_sum_2[cell];
j < cells_prefix_sum_2[
cell + 1] &&
j < cell_info_2.
number; ++
j)
1887 {
1889 {
1890 found_match = true;
1891 break;
1892 }
1893 }
1894 ref_size_vec[this_index] += 1;
1895 ref_weighted_size_vec[this_index] += this_weight;
1896 if (!found_match)
1897 {
1898 ref_diff_cells[this_index] += 1;
1899 ref_diff_cells_weight[this_index] += this_weight;
1900 cell_is_diff = true;
1901 }
1902 }
1903
1904 for (
int i = cells_prefix_sum_2[cell];
i < cells_prefix_sum_2[
cell + 1] &&
i < cell_info_2.
number; ++
i)
1905 {
1908 bool found_match = false;
1909 for (
int j = cells_prefix_sum_1[cell];
j < cells_prefix_sum_1[
cell + 1] &&
j < cell_info_1.
number; ++
j)
1910 {
1912 {
1913 found_match = true;
1914 break;
1915 }
1916 }
1917 test_size_vec[this_index] += 1;
1918 test_weighted_size_vec[this_index] += this_weight;
1919 if (!found_match)
1920 {
1921 test_diff_cells[this_index] += 1;
1922 test_diff_cells_weight[this_index] += this_weight;
1923 cell_is_diff = true;
1924 }
1925 }
1926
1927 if (cell_is_diff)
1928 {
1929#if CALORECGPU_DATA_MONITOR_EXTRA_PRINTOUTS
1930 msg(MSG::INFO) <<
"Diff: " <<
cell <<
" |";
1931 for (
int i = cells_prefix_sum_1[cell];
i < cells_prefix_sum_1[
cell + 1] &&
i < cell_info_1.
number; ++
i)
1932 {
1934 }
1936 for (
int i = cells_prefix_sum_2[cell];
i < cells_prefix_sum_2[
cell + 1] &&
i < cell_info_2.
number; ++
i)
1937 {
1939 }
1941#endif
1942
1943 ++diff_cluster_cells_count;
1944 }
1945 else if ((cells_prefix_sum_1[cell + 1] > cells_prefix_sum_1[cell]) || (cells_prefix_sum_2[cell + 1] > cells_prefix_sum_2[cell]))
1946 {
1947 ++same_cluster_cells_count;
1948 }
1949 }
1950 }
1951 }
1952
1954 {
1955
1956 for (
int cluster = 0; cluster < clusters_1.
number; ++cluster)
1957 {
1958 const int match = sch.r2t(cluster);
1960
1961 {
1962 continue;
1963 }
1964
1966 {
1968 {
1969 const auto prop_1 = prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cluster);
1970 const auto prop_2 = prop.get_property(constant_data, cell_info_2, clusters_2, cells_prefix_sum_2,
match);
1971
1972 cluster_properties[prop.name() + "_ref"].push_back(prop_1);
1973 cluster_properties[prop.name() + "_test"].push_back(prop_2);
1974
1975 cluster_properties["delta_" + prop.name()].push_back(prop_2 - prop_1);
1976 cluster_properties[
"delta_" + prop.name() +
"_rel_ref"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_1)));
1977 cluster_properties[
"delta_" + prop.name() +
"_rel_test"].push_back((prop_2 - prop_1) /
protect_from_zero(std::abs(prop_2)));
1978 }
1979 }, BasicClusterProperties{});
1980
1982 {
1984 {
1985 cluster_properties[prop.name()].push_back(prop.get_property(constant_data, cell_info_1, clusters_1, cells_prefix_sum_1, cluster,
1986 cell_info_2, clusters_2, cells_prefix_sum_2,
match));
1987 }
1988 }, ComparedClusterProperties{});
1989
1991 {
1992 cluster_properties["size_ref"].push_back(ref_size_vec[cluster]);
1993 cluster_properties[
"size_test"].push_back(test_size_vec[
match]);
1994 cluster_properties[
"delta_size"].push_back(ref_size_vec[cluster] - test_size_vec[
match]);
1995 cluster_properties[
"delta_size_rel_ref"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) /
protect_from_zero(ref_size_vec[cluster]));
1996 cluster_properties[
"delta_size_rel_test"].push_back((ref_size_vec[cluster] - test_size_vec[
match]) /
protect_from_zero(test_size_vec[
match]));
1997
1998 cluster_properties["weighted_size_ref"].push_back(ref_weighted_size_vec[cluster]);
1999 cluster_properties[
"weighted_size_test"].push_back(test_weighted_size_vec[
match]);
2000 cluster_properties[
"delta_weighted_size"].push_back(ref_weighted_size_vec[cluster] - test_weighted_size_vec[
match]);
2001 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]));
2002 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]));
2003 }
2004
2006 {
2007 cluster_properties["diff_cells_ref"].push_back(ref_diff_cells[cluster]);
2008 cluster_properties[
"diff_cells_ref_rel_size"].push_back(ref_diff_cells[cluster] /
protect_from_zero(ref_size_vec[cluster]));
2009 cluster_properties[
"diff_cells_test"].push_back(test_diff_cells[
match]);
2011 cluster_properties[
"diff_cells"].push_back(ref_diff_cells[cluster] + test_diff_cells[
match]);
2012
2013 cluster_properties["weighted_diff_cells_ref"].push_back(ref_diff_cells_weight[cluster]);
2014 cluster_properties[
"weighted_diff_cells_ref_rel_size"].push_back(ref_diff_cells_weight[cluster] /
protect_from_zero(ref_weighted_size_vec[cluster]));
2015 cluster_properties[
"weighted_diff_cells_test"].push_back(test_diff_cells_weight[
match]);
2016 cluster_properties[
"weighted_diff_cells_test_rel_size"].push_back(test_diff_cells_weight[
match] /
protect_from_zero(test_weighted_size_vec[
match]));
2017 cluster_properties[
"weighted_diff_cells"].push_back(ref_diff_cells_weight[cluster] + test_diff_cells_weight[
match]);
2018 }
2019 }
2020 }
2021
2023 using scalar_type = decltype(Monitored::Scalar("", std::declval<long long int>()));
2024
2025 std::vector<coll_type> collections;
2026 std::vector<scalar_type> count_scalars;
2027 std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> cluster_group, cell_group, counts_group;
2028
2029 collections.reserve(cluster_properties.size() + cell_properties.size());
2030 count_scalars.reserve(cell_counts.size() + 6 * 3);
2031 cluster_group.reserve(cluster_properties.size());
2032 cell_group.reserve(cell_properties.size());
2033 counts_group.reserve(cell_counts.size() + 3 + 6 * 3);
2034
2035 auto add_count_vars = [&](
const std::string &
name,
const long long int ref_num,
const long long int test_num)
2036 {
2037 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + name + "_ref", ref_num));
2038 counts_group.push_back(std::ref(count_scalars.back()));
2039
2040 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + name + "_test", test_num));
2041 counts_group.push_back(std::ref(count_scalars.back()));
2042
2043 count_scalars.emplace_back(Monitored::Scalar(prefix + "_delta_" + name, test_num - ref_num));
2044 counts_group.push_back(std::ref(count_scalars.back()));
2045 };
2046
2047 add_count_vars(
"num_clusters", clusters_1.
number, clusters_2.
number);
2048 add_count_vars("num_unmatched_clusters", sch.ref_unmatched(), sch.test_unmatched());
2049
2050 add_count_vars("num_same_E_cells", same_energy_1, same_energy_2);
2051 add_count_vars("num_same_abs_E_cells", same_abs_energy_1, same_abs_energy_2);
2052 add_count_vars("num_same_SNR_cells", same_snr_1, same_snr_2);
2053 add_count_vars("num_same_abs_SNR_cells", same_abs_snr_1, same_abs_snr_2);
2054
2055 auto mon_total_unmatched = Monitored::Scalar(prefix + "_num_unmatched_clusters", sch.ref_unmatched() + sch.test_unmatched());
2056 auto mon_same_cluster_cell = Monitored::Scalar(prefix + "_same_cluster_cells", same_cluster_cells_count);
2057 auto mon_diff_cluster_cell = Monitored::Scalar(prefix + "_diff_cluster_cells", diff_cluster_cells_count);
2058
2060 {
2061 ATH_MSG_INFO(
"Different cells: " << diff_cluster_cells_count);
2062 }
2063
2064 counts_group.push_back(std::ref(mon_total_unmatched));
2065 counts_group.push_back(std::ref(mon_same_cluster_cell));
2066 counts_group.push_back(std::ref(mon_diff_cluster_cell));
2067
2068 for (const auto & k_v : cluster_properties)
2069 {
2071 cluster_group.push_back(std::ref(collections.back()));
2072 }
2073
2074 for (const auto & k_v : cell_properties)
2075 {
2077 cell_group.push_back(std::ref(collections.back()));
2078 }
2079
2080 for (const auto & k_v : cell_counts)
2081 {
2082 count_scalars.emplace_back(Monitored::Scalar(prefix + "_" + k_v.first, k_v.second));
2083 counts_group.push_back(std::ref(count_scalars.back()));
2084 }
2085
2086
2087
2088
2089 auto monitor_clusters = Monitored::Group(
m_moniTool, cluster_group);
2090 auto monitor_cells = Monitored::Group(
m_moniTool, cell_group);
2091 auto monitor_counts = Monitored::Group(
m_moniTool, counts_group);
2092
2093 return StatusCode::SUCCESS;
2094}
#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]