MINT2
Public Member Functions | Private Attributes | List of all members
CyclicPhaseBins Class Reference

#include <CyclicPhaseBins.h>

Public Member Functions

 CyclicPhaseBins (std::vector< double > binEdges)
 
 CyclicPhaseBins ()
 
void setUniformCiSiBins (int nBinPairs)
 
void setBinEdges (std::vector< double > binEdges)
 
int getBinNumber (double phase) const
 
double getLowBinBoundary (int bin) const
 
double getHighBinBoundary (int bin) const
 
double getLowBinBoundary (double phase) const
 
double getHighBinBoundary (double phase) const
 
int getNumBins () const
 
 ~CyclicPhaseBins ()
 

Private Attributes

std::vector< double > _binEdges
 

Detailed Description

HyperPlot, Author: Sam Harnew, sam.h.nosp@m.arne.nosp@m.w@gma.nosp@m.il.c.nosp@m.om , Date: Dec 2015

Dealing with cyclic bin boundaries is annoying. This class makes life easier.

Definition at line 20 of file CyclicPhaseBins.h.

Constructor & Destructor Documentation

◆ CyclicPhaseBins() [1/2]

CyclicPhaseBins::CyclicPhaseBins ( std::vector< double >  binEdges)

Constuct a phase binning with the given bin edges. Since the binning is cyclic you only need nBins edges. The edges must be given in asending order, and within 2pi of each other

Definition at line 7 of file CyclicPhaseBins.cpp.

7  {
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 }
#define ERROR_LOG
std::vector< double > _binEdges

◆ CyclicPhaseBins() [2/2]

CyclicPhaseBins::CyclicPhaseBins ( )

Empty constuctor i.e. no bins

Definition at line 3 of file CyclicPhaseBins.cpp.

3  {
4 
5 }

◆ ~CyclicPhaseBins()

CyclicPhaseBins::~CyclicPhaseBins ( )

desctructor

Definition at line 128 of file CyclicPhaseBins.cpp.

128  {
129 
130 }

Member Function Documentation

◆ getBinNumber()

int CyclicPhaseBins::getBinNumber ( double  phase) const

For a given phase, return the bin number. Note that the phase does not have to be mapped into any particular range i.e. [-pi, +pi]

Definition at line 26 of file CyclicPhaseBins.cpp.

26  {
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 }
std::vector< double > _binEdges

◆ getHighBinBoundary() [1/2]

double CyclicPhaseBins::getHighBinBoundary ( int  bin) const

Get the high bin edge for given bin number. This just uses the nmbers stored in _binEdges

Definition at line 73 of file CyclicPhaseBins.cpp.

73  {
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 }
std::vector< double > _binEdges

◆ getHighBinBoundary() [2/2]

double CyclicPhaseBins::getHighBinBoundary ( double  phase) const

Get the high bin edge for given phase. This appropriately maps the numbers stored in _binEdges so that the bin edge is below the phase given, but within 2pi

Definition at line 104 of file CyclicPhaseBins.cpp.

104  {
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 }
double getHighBinBoundary(int bin) const
int getBinNumber(double phase) const

◆ getLowBinBoundary() [1/2]

double CyclicPhaseBins::getLowBinBoundary ( int  bin) const

Get the low bin edge for given bin number. This just uses the nmbers stored in _binEdges

Definition at line 67 of file CyclicPhaseBins.cpp.

67  {
68 
69  return _binEdges.at(bin);
70 
71 }
std::vector< double > _binEdges

◆ getLowBinBoundary() [2/2]

double CyclicPhaseBins::getLowBinBoundary ( double  phase) const

Get the low bin edge for given phase. This appropriately maps the numbers stored in _binEdges so that the bin edge is below the phase given, but within 2pi

Definition at line 87 of file CyclicPhaseBins.cpp.

87  {
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 }
double getLowBinBoundary(int bin) const
int getBinNumber(double phase) const

◆ getNumBins()

int CyclicPhaseBins::getNumBins ( ) const

Get number of bins

Definition at line 121 of file CyclicPhaseBins.cpp.

121  {
122 
123  return (int)_binEdges.size();
124 
125 }
std::vector< double > _binEdges

◆ setBinEdges()

void CyclicPhaseBins::setBinEdges ( std::vector< double >  binEdges)

Set the bin edges. See constuctor for details

Definition at line 63 of file CyclicPhaseBins.cpp.

63  {
64  _binEdges = binEdges;
65 }
std::vector< double > _binEdges

◆ setUniformCiSiBins()

void CyclicPhaseBins::setUniformCiSiBins ( int  nBinPairs)

set nBinPairs*2 uniformly spaces bins between -pi and pi

Definition at line 52 of file CyclicPhaseBins.cpp.

52  {
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 }
std::vector< double > _binEdges

Member Data Documentation

◆ _binEdges

std::vector<double> CyclicPhaseBins::_binEdges
private

Definition at line 22 of file CyclicPhaseBins.h.


The documentation for this class was generated from the following files: