CMS 3D CMS Logo

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