Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-24 02:10:44

0001 #include "CondFormats/EcalObjects/interface/EcalPulseSymmCovariances.h"
0002 
0003 #define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do this in one cpp file
0004 #include "catch.hpp"
0005 #include <iostream>
0006 
0007 TEST_CASE("EcalPulseSymmCovariance testing", "[EcalPulseSymmCovariance]") {
0008   EcalPulseSymmCovariance covMutable;
0009   //fill with accending values
0010   float const vMin = 0.5f;
0011   float v = vMin;
0012 
0013   std::set<float> values;
0014   for (auto& entry : covMutable.covval) {
0015     entry = v;
0016     values.insert(v);
0017     v += 1.f;
0018   }
0019 
0020   float const vMax = v - 1.f;
0021 
0022   auto const& cov = covMutable;
0023 
0024   SECTION("Check symmetry") {
0025     for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i) {
0026       for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
0027         REQUIRE(cov.val(i, j) == cov.val(j, i));
0028       }
0029     }
0030   }
0031   SECTION("Check index coverage") {
0032     std::vector<bool> hitIndices(std::size(cov.covval), false);
0033     for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i) {
0034       for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
0035         hitIndices[cov.indexFor(i, j)] = true;
0036       }
0037     }
0038     for (auto indx : hitIndices) {
0039       REQUIRE(indx == true);
0040     }
0041   }
0042   SECTION("Check bounds") {
0043     for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i) {
0044       for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
0045         REQUIRE((unsigned)cov.indexFor(i, j) < std::size(cov.covval));
0046       }
0047     }
0048   }
0049 
0050   SECTION("Check known values") {
0051     for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i) {
0052       for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
0053         REQUIRE(vMin <= cov.val(i, j));
0054         REQUIRE(cov.val(i, j) <= vMax);
0055         REQUIRE(values.end() != values.find(cov.val(i, j)));
0056       }
0057     }
0058   }
0059 
0060   SECTION("Check filling") {
0061     float v = vMin;
0062     EcalPulseSymmCovariance covNew;
0063     for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i) {
0064       for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
0065         covNew.val(i, j) = v;
0066         REQUIRE(v == covNew.val(i, j));
0067       }
0068     }
0069   }
0070 }