Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
THistRange.h
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Lorenzo MOneta 11/2020
3
4/*************************************************************************
5 * Copyright (C) 1995-2003, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_THistRange
13#define ROOT_THistRange
14
15//////////////////////////////////////////////////////////////////////////
16// //
17// THistRange //
18// //
19// Class defining a generic range of the histogram //
20// Used to iterated between bins //
21//////////////////////////////////////////////////////////////////////////
22
23#include "TError.h" // for R__ASSERT
24
25class TH1;
26
27
28
30private:
31 int fBin; ///< Global bin number used to advanced
32 int fXbin; ///< Bin X number
33 int fYbin; ///< Bin y number
34 int fZbin; ///< Bin Z number
35
36 int fNx; ///< Total x size (nbins+2)
37 int fNy; ///< y size
38 int fNz; ///< z size
39 int fXmin; ///< Min x value
40 int fXmax; ///< Max x value
41 int fYmin; ///< Min y value
42 int fYmax; ///< Max y value
43 int fZmin; ///< Min z value
44 int fZmax; ///< Max z value
45
46 int fDim; ///< Histogram dimension
47
48 /// Compute global bin number given x,y,x bin numbers
50 {
51 if (fDim == 1)
52 fBin = fXbin;
53 else if (fDim == 2)
54 fBin = fXbin + fNx * fYbin;
55 else
56 fBin = fXbin + fNx * (fYbin + fNy * fZbin);
57 }
58
59 // private default ctor (used by THistRange)
61 : fBin(0), fXbin(0), fYbin(0), fZbin(0), fNx(0), fNy(0), fNz(0), fXmin(0), fXmax(0), fYmin(0), fYmax(0), fZmin(0),
62 fZmax(0), fDim(0)
63 {
64 }
65
66public:
67 friend class THistRange;
68
69 /// enum defining option range type:
71 kHistRange, ///< use range provided by histogram
72 kAxisBins, ///< use allbins within axis limits (no underflow/overflows)
73 kAllBins, ///< use all bins including underflows/overflows
74 kUnOfBins ///< collection of all underflow/overflow bins
75 };
76
78 // TBinIterator(TBinIterator &rhs) = default;
79 // TBinIterator &operator=(const TBinIterator &) = default;
80
81 // implement end
83 {
84 TBinIterator end;
85 end.fBin = -1;
86 return end;
87 }
88
89 // keep inline to be faster
91 {
92 if (fXbin < fXmax)
93 fXbin++;
94 else if (fDim > 1) {
95 fXbin = fXmin;
96 if (fYbin < fYmax)
97 fYbin++;
98 else if (fDim > 2) {
99 fYbin = fYmin;
100 if (fZbin < fZmax)
101 fZbin++;
102 else {
103 fBin = -1;
104 return *this;
105 }
106 } else {
107 R__ASSERT(fDim == 2);
108 fBin = -1;
109 return *this;
110 }
111 } else {
112 R__ASSERT(fDim == 1);
113 fBin = -1;
114 return *this;
115 }
116 // fXbin can be incremented to zero only in case of TH2Poly
117 // where you can start from negative bin numbers
118 // In that case fXbin = 0 will be excluded
119 if (fXbin == 0) {
120 R__ASSERT(fXmin < 0 && fDim == 1);
121 fXbin = 1; // this happens in case of TH2Poly
122 }
123 SetGlobalBin();
124 return *this;
125 }
126
128 {
129 TBinIterator tmp(*this);
130 operator++();
131 return tmp;
132 }
133
134 bool operator==(const TBinIterator &rhs) const { return fBin == rhs.fBin; }
135 bool operator!=(const TBinIterator &rhs) const { return fBin != rhs.fBin; }
136 int &operator*() { return fBin; }
137};
138
140
141public:
144
145 iterator begin() { return fBegin; }
146
147 iterator end() { return fEnd; }
148
150
151protected:
152
155};
156
157
158#endif
#define h(i)
Definition RSha256.hxx:106
#define R__ASSERT(e)
Definition TError.h:118
int type
Definition TGX11.cxx:121
static TBinIterator End()
Definition THistRange.h:82
int fYmax
Max y value.
Definition THistRange.h:42
TBinIterator operator++(int)
Definition THistRange.h:127
int fNx
Total x size (nbins+2)
Definition THistRange.h:36
int fXbin
Bin X number.
Definition THistRange.h:32
int fZmax
Max z value.
Definition THistRange.h:44
TBinIterator & operator++()
Definition THistRange.h:90
void SetGlobalBin()
Compute global bin number given x,y,x bin numbers.
Definition THistRange.h:49
int fYmin
Min y value.
Definition THistRange.h:41
int fZbin
Bin Z number.
Definition THistRange.h:34
int fBin
Global bin number used to advanced.
Definition THistRange.h:31
int & operator*()
Definition THistRange.h:136
bool operator!=(const TBinIterator &rhs) const
Definition THistRange.h:135
int fZmin
Min z value.
Definition THistRange.h:43
int fYbin
Bin y number.
Definition THistRange.h:33
int fNy
y size
Definition THistRange.h:37
int fNz
z size
Definition THistRange.h:38
int fXmax
Max x value.
Definition THistRange.h:40
int fXmin
Min x value.
Definition THistRange.h:39
ERangeType
enum defining option range type:
Definition THistRange.h:70
@ kUnOfBins
collection of all underflow/overflow bins
Definition THistRange.h:74
@ kHistRange
use range provided by histogram
Definition THistRange.h:71
@ kAxisBins
use allbins within axis limits (no underflow/overflows)
Definition THistRange.h:72
@ kAllBins
use all bins including underflows/overflows
Definition THistRange.h:73
bool operator==(const TBinIterator &rhs) const
Definition THistRange.h:134
int fDim
Histogram dimension.
Definition THistRange.h:46
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
TBinIterator iterator
Definition THistRange.h:142
iterator end()
Definition THistRange.h:147
TBinIterator fEnd
Definition THistRange.h:154
TBinIterator::ERangeType RangeType
Definition THistRange.h:143
iterator begin()
Definition THistRange.h:145
TBinIterator fBegin
Definition THistRange.h:153
TH1F * h1
Definition legend1.C:5