CMS 3D CMS Logo

PeriodicBinFinderInPhi.h
Go to the documentation of this file.
1 #ifndef PeriodicBinFinderInPhi_H
2 #define PeriodicBinFinderInPhi_H
3 
5 
6 #include <algorithm>
7 #include <cmath>
8 
13 template <class T>
14 class PeriodicBinFinderInPhi final : public BaseBinFinder<T> {
15 public:
16 
18 
19  PeriodicBinFinderInPhi( T firstPhi, int nbins) :
20  theNbins( nbins), thePhiStep( twoPiC / T(nbins)), theInvPhiStep(T(1)/thePhiStep),
21  thePhiOffset( firstPhi - T(0.5)*thePhiStep) {}
22 
24  int binIndex( T phi) const override {
25  T tmp = std::fmod((phi - thePhiOffset), twoPiC)*theInvPhiStep;
26  if ( tmp < 0) tmp += theNbins;
27  return std::min( int(tmp), theNbins-1);
28  }
29 
31  int binIndex( int i) const override {
32  int ind = i % theNbins;
33  return ind < 0 ? ind+theNbins : ind;
34  }
35 
37  T binPosition( int ind) const override {
38  return thePhiOffset + thePhiStep * ( T(ind) + T(0.5));
39  }
40 
41  static constexpr T pi() { return piC;}
42  static constexpr T twoPi() { return twoPiC;}
43 
44 private:
45 
46  static constexpr T piC = 3.141592653589793238;
47  static constexpr T twoPiC = 2*piC;
48 
49 
50 
51  int theNbins=0;
55 
56 };
57 #endif
int binIndex(T phi) const override
returns an index in the valid range for the bin that contains phi
PeriodicBinFinderInPhi(T firstPhi, int nbins)
#define constexpr
static constexpr T twoPi()
int binIndex(int i) const override
returns an index in the valid range, modulo Nbins
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
long double T
T binPosition(int ind) const override
the middle of the bin in radians