PhiInterval

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#ifndef GeometryVector_PhiInterval_H
#define GeometryVector_PhiInterval_H
#include "DataFormats/GeometryVector/interface/Basic3DVector.h"
#include "DataFormats/Math/interface/normalizedPhi.h"

class PhiInterval {
public:
  PhiInterval(float phi1, float phi2) {
    phi2 = proxim(phi2, phi1);
    constexpr float c1 = 2. * M_PI;
    if (phi2 < phi1)
      phi2 += c1;
    auto dphi = 0.5f * (phi2 - phi1);
    auto phi = phi1 + dphi;
    x = std::cos(phi);
    y = std::sin(phi);
    dcos = std::cos(dphi);
  }

  PhiInterval(float ix, float iy, float dphi) {
    auto norm = 1.f / std::sqrt(ix * ix + iy * iy);
    x = ix * norm;
    y = iy * norm;
    dcos = std::cos(dphi);
  }

  template <typename T>
  bool inside(Basic3DVector<T> const& v) const {
    return inside(v.x(), v.y());
  }

  bool inside(float ix, float iy) const { return ix * x + iy * y > dcos * std::sqrt(ix * ix + iy * iy); }

private:
  float x, y;
  float dcos;
};

#endif