Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-10 04:02:06

0001 #include <cassert>
0002 #include <cmath>
0003 #include <iostream>
0004 
0005 #include "RecoLocalCalo/HGCalRecProducers/interface/HGCalLayerTiles.h"
0006 
0007 #define CATCH_CONFIG_MAIN
0008 #include <catch.hpp>
0009 
0010 int countEntries(const HGCalLayerTiles &t, const std::array<int, 4> &limits) {
0011   int entries = 0;
0012   for (int e = limits[0]; e <= limits[1]; ++e) {
0013     for (int p = limits[2]; p <= limits[3]; ++p) {
0014       int phi = (p % HGCalLayerTiles::type::nRowsPhi);
0015       auto global_bin = t.getGlobalBinByBinEtaPhi(e, phi);
0016       entries += t[global_bin].size();
0017     }
0018   }
0019   return entries;
0020 }
0021 
0022 TEST_CASE("Check the correct behaviour of searchBoxEtaPhi", "searchBoxEtaPhi") {
0023   using T = HGCalLayerTiles::type;
0024   auto constexpr phiBins = T::nRowsPhi;
0025   auto constexpr etaBins = T::nColumnsEta;
0026   auto constexpr phi_bin_width = 2. * M_PI / phiBins;
0027   auto constexpr eta_bin_width = (T::maxEta - T::minEta) / etaBins;
0028   auto constexpr phi_transition_left = M_PI - 3. * phi_bin_width / 2.;
0029   auto constexpr phi_transition_right = M_PI + 3. * phi_bin_width / 2.;
0030   auto constexpr phi_transition_right2 = -M_PI + 5. * phi_bin_width / 2.;
0031   auto constexpr phi_transition_right3 = M_PI + 5. * phi_bin_width / 2.;
0032   unsigned int constexpr entries_left = 11;
0033   unsigned int constexpr entries_right = 7;
0034   float constexpr eta = 2.0f;
0035   float constexpr eta_neg = -2.4f;
0036 
0037   // Force filling using eta/phi vectors
0038   std::vector<bool> isSilicon(entries_left + entries_right, false);
0039   std::vector<float> dummy(entries_left + entries_right, 0.);
0040   std::vector<float> etas(entries_left + entries_right, eta);
0041   std::vector<float> etas_neg(entries_left + entries_right, eta_neg);
0042   std::vector<float> phis_left(entries_left, phi_transition_left);
0043   std::vector<float> phis_right(entries_right, phi_transition_right);
0044   std::vector<float> phis_right2(entries_right, phi_transition_right2);
0045   std::vector<float> phis;
0046   std::vector<float> phis2;
0047   phis.reserve(entries_left + entries_right);
0048   phis.insert(phis.end(), phis_left.begin(), phis_left.end());
0049   phis.insert(phis.end(), phis_right.begin(), phis_right.end());
0050   phis2.reserve(entries_left + entries_right);
0051   phis2.insert(phis2.end(), phis_left.begin(), phis_left.end());
0052   phis2.insert(phis2.end(), phis_right2.begin(), phis_right2.end());
0053 
0054   HGCalLayerTiles t, t2, t_neg;
0055   t.fill(dummy, dummy, etas, phis, isSilicon);
0056   t2.fill(dummy, dummy, etas, phis2, isSilicon);
0057   t_neg.fill(dummy, dummy, etas_neg, phis2, isSilicon);
0058 
0059   std::cout << "Testing a Tile with " << phiBins << " phi bins with binwidth: " << phi_bin_width << " at pi transition"
0060             << std::endl;
0061   std::cout << "Testing a Tile with " << etaBins << " eta bins with binwidth: " << eta_bin_width << std::endl;
0062 
0063   std::cout << "-M_PI bin: " << t.mPiPhiBin << " M_PI bin: " << t.pPiPhiBin << std::endl;
0064   std::cout << "Filling positive eta value: " << eta << " at bin: " << t.getEtaBin(eta) << std::endl;
0065   std::cout << "Filling negative eta value: " << eta_neg << " at bin: " << t.getEtaBin(eta_neg) << std::endl;
0066   std::cout << "Filling phi value: " << phi_transition_left << " at left-pi bin: " << t.getPhiBin(phi_transition_left)
0067             << std::endl;
0068   std::cout << "Filling phi value: " << phi_transition_right
0069             << " at right-pi bin: " << t.getPhiBin(phi_transition_right) << std::endl;
0070   std::cout << "Filling phi value: " << phi_transition_right2
0071             << " at right-pi bin: " << t.getPhiBin(phi_transition_right2) << std::endl;
0072 
0073   SECTION("Phi bins from positive and negative pi") {
0074     REQUIRE(t.getPhiBin(phi_transition_right2) == t.getPhiBin(phi_transition_right3));
0075   }
0076 
0077   SECTION("Symmetric case around pi") {
0078     auto limits = t.searchBoxEtaPhi(1.95, 2.05, phi_transition_left, phi_transition_right);
0079 
0080     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0081     REQUIRE(limits[0] <= limits[1]);
0082     REQUIRE(limits[2] <= limits[3]);
0083 
0084     auto entries = countEntries(t, limits);
0085     REQUIRE(entries == entries_left + entries_right);
0086   }
0087 
0088   SECTION("Asymmetric case around pi, negative") {
0089     auto limits = t2.searchBoxEtaPhi(1.95, 2.05, phi_transition_left, phi_transition_right2);
0090 
0091     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0092     REQUIRE(limits[0] <= limits[1]);
0093     REQUIRE(limits[2] <= limits[3]);
0094 
0095     auto entries = countEntries(t2, limits);
0096     REQUIRE(entries == entries_left + entries_right);
0097   }
0098 
0099   SECTION("Asymmetric case around pi, positive") {
0100     auto limits = t2.searchBoxEtaPhi(1.95, 2.05, phi_transition_left, phi_transition_right3);
0101 
0102     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0103     REQUIRE(limits[0] <= limits[1]);
0104     REQUIRE(limits[2] <= limits[3]);
0105 
0106     auto entries = countEntries(t2, limits);
0107     REQUIRE(entries == entries_left + entries_right);
0108   }
0109 
0110   SECTION("Correct all negative eta searchRange") {
0111     auto limits = t_neg.searchBoxEtaPhi(-2.45, -2.35, phi_transition_left, phi_transition_right2);
0112 
0113     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0114     REQUIRE(limits[0] <= limits[1]);
0115     REQUIRE(limits[2] <= limits[3]);
0116 
0117     auto entries = countEntries(t_neg, limits);
0118     REQUIRE(entries == entries_left + entries_right);
0119   }
0120 
0121   SECTION("Mixed signs (neg,pos) eta with no entries searchRange") {
0122     auto limits = t.searchBoxEtaPhi(-2.05, 1.95, phi_transition_left, phi_transition_right2);
0123 
0124     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0125     REQUIRE(limits[0] <= limits[1]);
0126     REQUIRE(limits[2] <= limits[3]);
0127 
0128     auto entries = countEntries(t, limits);
0129     REQUIRE(entries == 0);
0130   }
0131 
0132   SECTION("Mixed signs (neg,pos) eta with all entries searchRange") {
0133     auto limits = t.searchBoxEtaPhi(-2.05, 2.05, phi_transition_left, phi_transition_right2);
0134 
0135     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0136     REQUIRE(limits[0] <= limits[1]);
0137     REQUIRE(limits[2] <= limits[3]);
0138 
0139     auto entries = countEntries(t, limits);
0140     REQUIRE(entries == entries_left + entries_right);
0141   }
0142 
0143   SECTION("Mixed signs (neg,pos) eta with all entries negative eta searchRange") {
0144     auto limits = t_neg.searchBoxEtaPhi(-2.45, 2.05, phi_transition_left, phi_transition_right2);
0145 
0146     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0147     REQUIRE(limits[0] <= limits[1]);
0148     REQUIRE(limits[2] <= limits[3]);
0149 
0150     auto entries = countEntries(t_neg, limits);
0151     REQUIRE(entries == entries_left + entries_right);
0152   }
0153 
0154   SECTION("Mixed signs (neg,pos) eta with all entries overflow eta searchRange") {
0155     auto limits = t_neg.searchBoxEtaPhi(-5., 5., phi_transition_left, phi_transition_right2);
0156 
0157     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0158     REQUIRE(limits[0] <= limits[1]);
0159     REQUIRE(limits[2] <= limits[3]);
0160 
0161     auto entries = countEntries(t_neg, limits);
0162     REQUIRE(entries == entries_left + entries_right);
0163   }
0164 
0165   SECTION("Wrong mixed signs (pos,neg) eta searchRange") {
0166     auto limits = t.searchBoxEtaPhi(2.05, -1.95, phi_transition_left, phi_transition_right2);
0167 
0168     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0169     REQUIRE(limits[0] == limits[1]);
0170     REQUIRE(limits[2] == limits[3]);
0171     REQUIRE(limits[0] == 0);
0172     REQUIRE(limits[2] == 0);
0173 
0174     auto entries = countEntries(t, limits);
0175     REQUIRE(entries == 0);
0176   }
0177 
0178   SECTION("Wrong all positive eta searchRange") {
0179     auto limits = t.searchBoxEtaPhi(2.05, 1.95, phi_transition_left, phi_transition_right2);
0180 
0181     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0182     REQUIRE(limits[0] == limits[1]);
0183     REQUIRE(limits[2] == limits[3]);
0184     REQUIRE(limits[0] == 0);
0185     REQUIRE(limits[2] == 0);
0186 
0187     auto entries = countEntries(t, limits);
0188     REQUIRE(entries == 0);
0189   }
0190 
0191   SECTION("Wrong all negative eta searchRange") {
0192     auto limits = t.searchBoxEtaPhi(-1.95, -2.05, phi_transition_left, phi_transition_right2);
0193 
0194     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0195     REQUIRE(limits[0] == limits[1]);
0196     REQUIRE(limits[2] == limits[3]);
0197     REQUIRE(limits[0] == 0);
0198     REQUIRE(limits[2] == 0);
0199 
0200     auto entries = countEntries(t, limits);
0201     REQUIRE(entries == 0);
0202   }
0203 }