Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-10 03:58:30

0001 #include <cassert>
0002 #include <cmath>
0003 #include <iostream>
0004 
0005 #include "DataFormats/HGCalReco/interface/TICLLayerTile.h"
0006 
0007 #define CATCH_CONFIG_MAIN
0008 #include <catch.hpp>
0009 
0010 using namespace ticl;
0011 
0012 int countEntries(const TICLLayerTile &t, const std::array<int, 4> &limits) {
0013   int entries = 0;
0014   for (int e = limits[0]; e <= limits[1]; ++e) {
0015     for (int p = limits[2]; p <= limits[3]; ++p) {
0016       int phi = (p % TICLLayerTile::type::nPhiBins);
0017       auto global_bin = t.globalBin(e, phi);
0018       entries += t[global_bin].size();
0019     }
0020   }
0021   return entries;
0022 }
0023 
0024 TEST_CASE("Check the correct phi wrapping", "searchBoxEtaPhi") {
0025   auto constexpr phiBins = TICLLayerTile::type::nPhiBins;
0026   auto constexpr phi_bin_width = 2. * M_PI / phiBins;
0027   auto constexpr phi_transition_left = M_PI - phi_bin_width / 2.;
0028   auto constexpr phi_transition_right = M_PI + phi_bin_width / 2.;
0029   auto constexpr phi_transition_right2 = -M_PI + 3. * phi_bin_width / 2.;
0030   auto constexpr phi_transition_right3 = M_PI + 3. * phi_bin_width / 2.;
0031   unsigned int constexpr entries_left = 11;
0032   unsigned int constexpr entries_right = 7;
0033   float constexpr eta = 2.0f;
0034   float constexpr eta_neg = -2.4f;
0035 
0036   TICLLayerTile t, t2, t_neg;
0037   std::cout << "Testing a Tile with " << phiBins << " bins with binwidth: " << phi_bin_width << " at bin transition"
0038             << std::endl;
0039   std::cout << "Filling left-pi bin: " << t.phiBin(phi_transition_left) << std::endl;
0040   std::cout << "Filling right-pi bin: " << t.phiBin(phi_transition_right) << std::endl;
0041   std::cout << "Filling right2-pi bin: " << t.phiBin(phi_transition_right2) << std::endl;
0042   std::cout << "Filling right3-pi bin: " << t.phiBin(phi_transition_right3) << std::endl;
0043 
0044   for (unsigned int i = 0; i < entries_left; ++i) {
0045     t.fill(eta, phi_transition_left, i);
0046     t2.fill(eta, phi_transition_left, i);
0047     t_neg.fill(eta_neg, phi_transition_left, i);
0048   }
0049 
0050   for (unsigned int i = 0; i < entries_right; ++i) {
0051     t.fill(eta, phi_transition_right, i);
0052     t2.fill(eta, phi_transition_right2, i);
0053     t_neg.fill(eta_neg, phi_transition_right, i);
0054   }
0055 
0056   SECTION("Phi bins from positive and negative pi") {
0057     REQUIRE(t.phiBin(phi_transition_right2) == t.phiBin(phi_transition_right3));
0058   }
0059 
0060   SECTION("Symmetric case around pi") {
0061     auto limits = t.searchBoxEtaPhi(1.95, 2.05, phi_transition_left, phi_transition_right);
0062 
0063     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0064     REQUIRE(limits[0] <= limits[1]);
0065     REQUIRE(limits[2] <= limits[3]);
0066 
0067     auto entries = countEntries(t, limits);
0068     REQUIRE(entries == entries_left + entries_right);
0069   }
0070 
0071   SECTION("Asymmetric case around pi, negative") {
0072     auto limits = t2.searchBoxEtaPhi(1.95, 2.05, phi_transition_left, phi_transition_right2);
0073 
0074     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0075     REQUIRE(limits[0] <= limits[1]);
0076     REQUIRE(limits[2] <= limits[3]);
0077 
0078     auto entries = countEntries(t2, limits);
0079     REQUIRE(entries == entries_left + entries_right);
0080   }
0081 
0082   SECTION("Asymmetric case around pi, positive") {
0083     auto limits = t2.searchBoxEtaPhi(1.95, 2.05, phi_transition_left, phi_transition_right3);
0084 
0085     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0086     REQUIRE(limits[0] <= limits[1]);
0087     REQUIRE(limits[2] <= limits[3]);
0088 
0089     auto entries = countEntries(t2, limits);
0090     REQUIRE(entries == entries_left + entries_right);
0091   }
0092 
0093   SECTION("Correct all negative eta searchRange") {
0094     auto limits = t_neg.searchBoxEtaPhi(-2.45, -2.35, phi_transition_left, phi_transition_right2);
0095 
0096     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0097     REQUIRE(limits[0] <= limits[1]);
0098     REQUIRE(limits[2] <= limits[3]);
0099 
0100     auto entries = countEntries(t_neg, limits);
0101     REQUIRE(entries == entries_left + entries_right);
0102   }
0103 
0104   SECTION("Correct all positive overflow eta searchRange") {
0105     auto limits = t.searchBoxEtaPhi(0., 5., phi_transition_left, phi_transition_right2);
0106 
0107     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0108     REQUIRE(limits[0] <= limits[1]);
0109     REQUIRE(limits[2] <= limits[3]);
0110 
0111     auto entries = countEntries(t, limits);
0112     REQUIRE(entries == entries_left + entries_right);
0113   }
0114 
0115   SECTION("Wrong mixed signs (neg,pos) eta searchRange") {
0116     auto limits = t.searchBoxEtaPhi(-2.05, 1.95, phi_transition_left, phi_transition_right2);
0117 
0118     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0119     REQUIRE(limits[0] == limits[1]);
0120     REQUIRE(limits[2] == limits[3]);
0121     REQUIRE(limits[0] == 0);
0122     REQUIRE(limits[2] == 0);
0123 
0124     auto entries = countEntries(t, limits);
0125     REQUIRE(entries == 0);
0126   }
0127 
0128   SECTION("Wrong mixed signs (pos,neg) eta searchRange") {
0129     auto limits = t.searchBoxEtaPhi(2.05, -1.95, phi_transition_left, phi_transition_right2);
0130 
0131     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0132     REQUIRE(limits[0] == limits[1]);
0133     REQUIRE(limits[2] == limits[3]);
0134     REQUIRE(limits[0] == 0);
0135     REQUIRE(limits[2] == 0);
0136 
0137     auto entries = countEntries(t, limits);
0138     REQUIRE(entries == 0);
0139   }
0140 
0141   SECTION("Wrong all positive eta searchRange") {
0142     auto limits = t.searchBoxEtaPhi(2.05, 1.95, phi_transition_left, phi_transition_right2);
0143 
0144     std::cout << "Limits are: " << limits[0] << " " << limits[1] << " " << limits[2] << " " << limits[3] << std::endl;
0145     REQUIRE(limits[0] == limits[1]);
0146     REQUIRE(limits[2] == limits[3]);
0147     REQUIRE(limits[0] == 0);
0148     REQUIRE(limits[2] == 0);
0149 
0150     auto entries = countEntries(t, limits);
0151     REQUIRE(entries == 0);
0152   }
0153 
0154   SECTION("Wrong all negative eta searchRange") {
0155     auto limits = t.searchBoxEtaPhi(-1.95, -2.05, 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     REQUIRE(limits[0] == 0);
0161     REQUIRE(limits[2] == 0);
0162 
0163     auto entries = countEntries(t, limits);
0164     REQUIRE(entries == 0);
0165   }
0166 }