File indexing completed on 2024-04-06 12:04:43
0001 #include <cmath>
0002 inline float __attribute__((always_inline)) __attribute__((pure)) eta(float x, float y, float z) {
0003 float t(z / std::sqrt(x * x + y * y));
0004 return ::asinhf(t);
0005 }
0006
0007 struct Vector {
0008 Vector() {}
0009 Vector(float ia, float ib, float ic) : a(ia), b(ib), c(ic) {}
0010 float a, b, c;
0011
0012 float x() const { return a; }
0013 float y() const { return b; }
0014 float z() const { return c; }
0015 float phi() const { return std::atan2(y(), x()); }
0016 float perp2() const { return a * a + b * b; }
0017 float eta() const { return ::eta(a, b, c); }
0018 };
0019
0020 #include "DataFormats/Math/interface/deltaR.h"
0021
0022 #include "DataFormats/Math/interface/approx_log.h"
0023
0024 inline int diff(float a, float b) {
0025 approx_math::binary32 ba(a);
0026 approx_math::binary32 bb(b);
0027 return ba.i32 - bb.i32;
0028 }
0029
0030 #include <cstdio>
0031 #include <iostream>
0032 #include <vector>
0033 int main() {
0034 for (float q = -10.; q < 10.; q += 0.5)
0035 std::cout << q << ' ' << q - std::copysign(2 * M_PI, q) << ' ' << reco::reduceRange(q) << std::endl;
0036
0037 std::cout << reco::reduceRange(std::sqrt(-1)) << std::endl;
0038
0039 std::vector<Vector> vs;
0040 for (float x = -1000.; x <= 1010.; x += 100)
0041 for (float y = -1000.; y <= 1010.; y += 100)
0042 for (float z = -1000.; z <= 1010.; z += 100)
0043 vs.emplace_back(x, y, z);
0044 std::cout << "testing " << vs.size() << " vectors" << std::endl;
0045
0046 for (auto v1 : vs)
0047 for (auto v2 : vs) {
0048 float drv = reco::deltaR2(v1, v2);
0049 float dro = reco::deltaR2(v1.eta(), v1.phi(), v2.eta(), v2.phi());
0050 if (std::abs(diff(drv, dro)) > 1)
0051 printf("%d %a %a\n", diff(drv, dro), drv, dro);
0052 }
0053
0054 return 0;
0055 }