MINT2
CyclicPhaseBins.cpp
Go to the documentation of this file.
1 #include "Mint/CyclicPhaseBins.h"
2 
4 
5 }
6 
7 CyclicPhaseBins::CyclicPhaseBins(std::vector<double> binEdges){
8 
9  double min = binEdges.at(0);
10  for (unsigned i = 1; i < binEdges.size(); i++){
11 
12  double val = binEdges.at(i);
13  if ( val < min ){
14  ERROR_LOG << "CyclicPhaseBins::CyclicPhaseBins The bin edges MUST increase" << std::endl;
15  }
16  if ( val > min + TMath::Pi()*2.0 ){
17  ERROR_LOG << "CyclicPhaseBins::CyclicPhaseBins This bin edge is more than 2pi bigger than the smallest bin edge!" << std::endl;
18  }
19 
20  }
21 
22  _binEdges = binEdges;
23 
24 }
25 
26 int CyclicPhaseBins::getBinNumber(double phase) const{
27 
28  double min = _binEdges.at(0);
29 
30  bool tooSmall = (phase - min) < 0.0;
31  bool tooBig = (phase - min) > TMath::Pi()*2.0;
32 
33  while (tooSmall || tooBig){
34  if (tooSmall) {
35  phase += 2.0*TMath::Pi();
36  tooSmall = (phase - min) < 0.0;
37  }
38  if (tooBig ) {
39  phase -= 2.0*TMath::Pi();
40  tooBig = (phase - min) > TMath::Pi()*2.0;
41  }
42  }
43 
44  for (unsigned i = 1; i < _binEdges.size(); i++){
45  if (phase < _binEdges.at(i)) return i - 1;
46  }
47 
48  return _binEdges.size() - 1;
49 
50 }
51 
53 
54  std::vector<double> binEdges;
55 
56  for (int i = 0; i < 2*nBinPairs; i++){
57  binEdges.push_back( - TMath::Pi() + (TMath::Pi()/double(nBinPairs))*i );
58  }
59 
60  _binEdges = binEdges;
61 }
62 
63 void CyclicPhaseBins::setBinEdges (std::vector<double> binEdges){
64  _binEdges = binEdges;
65 }
66 
67 double CyclicPhaseBins::getLowBinBoundary (int bin) const{
68 
69  return _binEdges.at(bin);
70 
71 }
72 
73 double CyclicPhaseBins::getHighBinBoundary (int bin) const{
74 
75  double highEdge = 0.0;
76 
77  if (bin == ((int)_binEdges.size() - 1) ){
78  highEdge = _binEdges.at(0) + TMath::Pi()*2.0;
79  }
80  else{
81  highEdge = _binEdges.at(bin+1);
82  }
83 
84  return highEdge;
85 }
86 
87 double CyclicPhaseBins::getLowBinBoundary (double phase) const{
88 
89  int binNum = getBinNumber(phase);
90 
91  double lowEdge = getLowBinBoundary(binNum);
92 
93  while (phase < lowEdge){
94  lowEdge -= TMath::Pi()*2.0;
95  }
96 
97  while (phase > lowEdge + TMath::Pi()*2.0){
98  lowEdge += TMath::Pi()*2.0;
99  }
100 
101  return lowEdge;
102 }
103 
104 double CyclicPhaseBins::getHighBinBoundary(double phase) const{
105 
106  int binNum = getBinNumber(phase);
107 
108  double highEdge = getHighBinBoundary(binNum);
109 
110  while (phase > highEdge){
111  highEdge += TMath::Pi()*2.0;
112  }
113 
114  while (phase < highEdge - TMath::Pi()*2.0){
115  highEdge -= TMath::Pi()*2.0;
116  }
117 
118  return highEdge;
119 }
120 
122 
123  return (int)_binEdges.size();
124 
125 }
126 
127 
129 
130 }
int getNumBins() const
#define ERROR_LOG
void setBinEdges(std::vector< double > binEdges)
double getHighBinBoundary(int bin) const
double getLowBinBoundary(int bin) const
int getBinNumber(double phase) const
std::vector< double > _binEdges
void setUniformCiSiBins(int nBinPairs)