File indexing completed on 2025-01-18 10:12:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_THistRange
0013 #define ROOT_THistRange
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "TError.h" // for R__ASSERT
0024
0025 class TH1;
0026
0027
0028
0029 class TBinIterator {
0030 private:
0031 int fBin;
0032 int fXbin;
0033 int fYbin;
0034 int fZbin;
0035
0036 int fNx;
0037 int fNy;
0038 int fNz;
0039 int fXmin;
0040 int fXmax;
0041 int fYmin;
0042 int fYmax;
0043 int fZmin;
0044 int fZmax;
0045
0046 int fDim;
0047
0048
0049 void SetGlobalBin()
0050 {
0051 if (fDim == 1)
0052 fBin = fXbin;
0053 else if (fDim == 2)
0054 fBin = fXbin + fNx * fYbin;
0055 else
0056 fBin = fXbin + fNx * (fYbin + fNy * fZbin);
0057 }
0058
0059
0060 TBinIterator()
0061 : fBin(0), fXbin(0), fYbin(0), fZbin(0), fNx(0), fNy(0), fNz(0), fXmin(0), fXmax(0), fYmin(0), fYmax(0), fZmin(0),
0062 fZmax(0), fDim(0)
0063 {
0064 }
0065
0066 public:
0067 friend class THistRange;
0068
0069
0070 enum ERangeType {
0071 kHistRange,
0072 kAxisBins,
0073 kAllBins,
0074 kUnOfBins
0075 };
0076
0077 TBinIterator(const TH1 *h, ERangeType type);
0078
0079
0080
0081
0082 static TBinIterator End()
0083 {
0084 TBinIterator end;
0085 end.fBin = -1;
0086 return end;
0087 }
0088
0089
0090 TBinIterator &operator++()
0091 {
0092 if (fXbin < fXmax)
0093 fXbin++;
0094 else if (fDim > 1) {
0095 fXbin = fXmin;
0096 if (fYbin < fYmax)
0097 fYbin++;
0098 else if (fDim > 2) {
0099 fYbin = fYmin;
0100 if (fZbin < fZmax)
0101 fZbin++;
0102 else {
0103 fBin = -1;
0104 return *this;
0105 }
0106 } else {
0107 R__ASSERT(fDim == 2);
0108 fBin = -1;
0109 return *this;
0110 }
0111 } else {
0112 R__ASSERT(fDim == 1);
0113 fBin = -1;
0114 return *this;
0115 }
0116
0117
0118
0119 if (fXbin == 0) {
0120 R__ASSERT(fXmin < 0 && fDim == 1);
0121 fXbin = 1;
0122 }
0123 SetGlobalBin();
0124 return *this;
0125 }
0126
0127 TBinIterator operator++(int)
0128 {
0129 TBinIterator tmp(*this);
0130 operator++();
0131 return tmp;
0132 }
0133
0134 bool operator==(const TBinIterator &rhs) const { return fBin == rhs.fBin; }
0135 bool operator!=(const TBinIterator &rhs) const { return fBin != rhs.fBin; }
0136 int &operator*() { return fBin; }
0137 };
0138
0139 class THistRange {
0140
0141 public:
0142 typedef TBinIterator iterator;
0143 typedef TBinIterator::ERangeType RangeType;
0144
0145 iterator begin() { return fBegin; }
0146
0147 iterator end() { return fEnd; }
0148
0149 THistRange(const TH1 *h1, TBinIterator::ERangeType type = TBinIterator::kHistRange);
0150
0151 protected:
0152
0153 TBinIterator fBegin;
0154 TBinIterator fEnd;
0155 };
0156
0157
0158 #endif