File indexing completed on 2024-04-06 12:28:40
0001 #define CATCH_CONFIG_MAIN
0002 #include <catch.hpp>
0003 #include <algorithm>
0004 #include "RecoTracker/PixelTrackFitting/interface/RZLine.h"
0005
0006 TEST_CASE("test RZLine", "[RZLine]") {
0007 SECTION("Constructors") {
0008 constexpr std::array<float, 2> r{{0.001, 0.003}};
0009 constexpr std::array<float, 2> z{{0.1, 0.2}};
0010 constexpr std::array<float, 2> errz{{0.01, 0.02}};
0011 constexpr float cotTheta = 50.0f;
0012 constexpr float intercept = 0.05f;
0013 constexpr float covss = 124.99996f;
0014 constexpr float covii = 0.0003249999136f;
0015 constexpr float covsi = -0.175f;
0016 constexpr float chi2 = 0;
0017 constexpr float chi2_diff = 1e-10;
0018
0019 SECTION("array") {
0020 RZLine l(r, z, errz);
0021
0022 REQUIRE(l.cotTheta() == Approx(cotTheta));
0023 REQUIRE(l.intercept() == Approx(intercept));
0024 REQUIRE(l.covss() == Approx(covss));
0025 REQUIRE(l.covii() == Approx(covii));
0026 REQUIRE(l.covsi() == Approx(covsi));
0027 REQUIRE_THAT(l.chi2(), Catch::Matchers::WithinAbs(chi2, chi2_diff));
0028 }
0029
0030 SECTION("vector") {
0031 const std::vector<float> rv{r.begin(), r.end()};
0032 const std::vector<float> zv{z.begin(), z.end()};
0033 const std::vector<float> errzv{errz.begin(), errz.end()};
0034 RZLine l(rv, zv, errzv);
0035
0036 REQUIRE(l.cotTheta() == Approx(cotTheta));
0037 REQUIRE(l.intercept() == Approx(intercept));
0038 REQUIRE(l.covss() == Approx(covss));
0039 REQUIRE(l.covii() == Approx(covii));
0040 REQUIRE(l.covsi() == Approx(covsi));
0041 REQUIRE_THAT(l.chi2(), Catch::Matchers::WithinAbs(chi2, chi2_diff));
0042 }
0043
0044 SECTION("vector ErrZ2_tag") {
0045 const std::vector<float> rv{r.begin(), r.end()};
0046 const std::vector<float> zv{z.begin(), z.end()};
0047 std::vector<float> errzv;
0048 std::transform(errz.begin(), errz.end(), std::back_inserter(errzv), [](float v) { return v * v; });
0049 RZLine l(rv, zv, errzv, RZLine::ErrZ2_tag());
0050
0051 REQUIRE(l.cotTheta() == Approx(cotTheta));
0052 REQUIRE(l.intercept() == Approx(intercept));
0053 REQUIRE(l.covss() == Approx(covss));
0054 REQUIRE(l.covii() == Approx(covii));
0055 REQUIRE(l.covsi() == Approx(covsi));
0056 REQUIRE_THAT(l.chi2(), Catch::Matchers::WithinAbs(chi2, chi2_diff));
0057 }
0058
0059 SECTION("points&errors") {
0060 struct Error {
0061 float err_;
0062 float czz() const { return err_ * err_; }
0063 float rerr(const GlobalPoint&) const { return 0.f; }
0064 };
0065 const std::vector<GlobalPoint> p{{{std::abs(r[0]), 0., z[0]}, {std::abs(r[1]), 0., z[1]}}};
0066 REQUIRE(p[0].perp() == std::abs(r[0]));
0067 REQUIRE(p[0].z() == z[0]);
0068 REQUIRE(p[1].perp() == std::abs(r[1]));
0069 REQUIRE(p[1].z() == z[1]);
0070 const std::vector<Error> err{{{errz[0]}, {errz[1]}}};
0071 REQUIRE(err[0].czz() == errz[0] * errz[0]);
0072 REQUIRE(err[1].czz() == errz[1] * errz[1]);
0073 const std::vector<bool> barrel{{true, true}};
0074 RZLine l(p, err, barrel);
0075
0076 REQUIRE(l.cotTheta() == Approx(cotTheta));
0077 REQUIRE(l.intercept() == Approx(intercept));
0078 REQUIRE(l.covss() == Approx(covss));
0079 REQUIRE(l.covii() == Approx(covii));
0080 REQUIRE(l.covsi() == Approx(covsi));
0081 REQUIRE_THAT(l.chi2(), Catch::Matchers::WithinAbs(chi2, chi2_diff));
0082 }
0083 }
0084 SECTION("no points") {
0085 const std::vector<float> rv;
0086 const std::vector<float> zv;
0087 std::vector<float> errzv;
0088 RZLine l(rv, zv, errzv);
0089
0090
0091 REQUIRE(l.cotTheta() != l.cotTheta());
0092 REQUIRE(l.intercept() != l.intercept());
0093 REQUIRE(l.covss() != l.covss());
0094 REQUIRE(l.covii() != l.covii());
0095 REQUIRE(l.covsi() != l.covsi());
0096 REQUIRE(l.chi2() == 0.0f);
0097 }
0098 SECTION("one point") {
0099 const std::vector<float> rv = {0.001};
0100 const std::vector<float> zv = {0.1};
0101 const std::vector<float> errzv = {0.01};
0102 RZLine l(rv, zv, errzv);
0103
0104
0105 REQUIRE(l.cotTheta() != l.cotTheta());
0106 REQUIRE(l.intercept() != l.intercept());
0107 REQUIRE(l.covss() != l.covss());
0108 REQUIRE(l.covii() != l.covii());
0109 REQUIRE(l.covsi() != l.covsi());
0110 REQUIRE(l.chi2() == 0.0f);
0111 }
0112 }