go-hep.org/x/hep@v0.38.1/hbook/bin2d.go (about) 1 // Copyright ©2016 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package hbook 6 7 // Bin2D models a bin in a 2-dim space. 8 type Bin2D struct { 9 XRange Range 10 YRange Range 11 Dist Dist2D 12 } 13 14 // Rank returns the number of dimensions for this bin. 15 func (Bin2D) Rank() int { return 2 } 16 17 // func (b *Bin2D) scaleW(f float64) { 18 // b.Dist.scaleW(f) 19 // } 20 21 func (b *Bin2D) fill(x, y, w float64) { 22 b.Dist.fill(x, y, w) 23 } 24 25 // Entries returns the number of entries in this bin. 26 func (b *Bin2D) Entries() int64 { 27 return b.Dist.Entries() 28 } 29 30 // EffEntries returns the effective number of entries \f$ = (\sum w)^2 / \sum w^2 \f$ 31 func (b *Bin2D) EffEntries() float64 { 32 return b.Dist.EffEntries() 33 } 34 35 // SumW returns the sum of weights in this bin. 36 func (b *Bin2D) SumW() float64 { 37 return b.Dist.SumW() 38 } 39 40 // SumW2 returns the sum of squared weights in this bin. 41 func (b *Bin2D) SumW2() float64 { 42 return b.Dist.SumW2() 43 } 44 45 // XEdges returns the [low,high] edges of this bin. 46 func (b *Bin2D) XEdges() Range { 47 return b.XRange 48 } 49 50 // YEdges returns the [low,high] edges of this bin. 51 func (b *Bin2D) YEdges() Range { 52 return b.YRange 53 } 54 55 // XMin returns the lower limit of the bin (inclusive). 56 func (b *Bin2D) XMin() float64 { 57 return b.XRange.Min 58 } 59 60 // YMin returns the lower limit of the bin (inclusive). 61 func (b *Bin2D) YMin() float64 { 62 return b.YRange.Min 63 } 64 65 // XMax returns the upper limit of the bin (exclusive). 66 func (b *Bin2D) XMax() float64 { 67 return b.XRange.Max 68 } 69 70 // YMax returns the upper limit of the bin (exclusive). 71 func (b *Bin2D) YMax() float64 { 72 return b.YRange.Max 73 } 74 75 // XMid returns the geometric center of the bin. 76 // i.e.: 0.5*(high+low) 77 func (b *Bin2D) XMid() float64 { 78 return 0.5 * (b.XRange.Min + b.XRange.Max) 79 } 80 81 // YMid returns the geometric center of the bin. 82 // i.e.: 0.5*(high+low) 83 func (b *Bin2D) YMid() float64 { 84 return 0.5 * (b.YRange.Min + b.YRange.Max) 85 } 86 87 // XYMid returns the (x,y) coordinates of the geometric center of the bin. 88 // i.e.: 0.5*(high+low) 89 func (b *Bin2D) XYMid() (float64, float64) { 90 return b.XMid(), b.YMid() 91 } 92 93 // XWidth returns the (signed) width of the bin 94 func (b *Bin2D) XWidth() float64 { 95 return b.XRange.Max - b.XRange.Min 96 } 97 98 // YWidth returns the (signed) width of the bin 99 func (b *Bin2D) YWidth() float64 { 100 return b.YRange.Max - b.YRange.Min 101 } 102 103 // XYWidth returns the (signed) (x,y) widths of the bin 104 func (b *Bin2D) XYWidth() (float64, float64) { 105 return b.XWidth(), b.YWidth() 106 } 107 108 // XFocus returns the mean position in the bin, or the midpoint (if the 109 // sum of weights for this bin is 0). 110 func (b *Bin2D) XFocus() float64 { 111 if b.SumW() == 0 { 112 return b.XMid() 113 } 114 return b.XMean() 115 } 116 117 // YFocus returns the mean position in the bin, or the midpoint (if the 118 // sum of weights for this bin is 0). 119 func (b *Bin2D) YFocus() float64 { 120 if b.SumW() == 0 { 121 return b.YMid() 122 } 123 return b.YMean() 124 } 125 126 // XYFocus returns the mean position in the bin, or the midpoint (if the 127 // sum of weights for this bin is 0). 128 func (b *Bin2D) XYFocus() (float64, float64) { 129 if b.SumW() == 0 { 130 return b.XMid(), b.YMid() 131 } 132 return b.XMean(), b.YMean() 133 } 134 135 // XMean returns the mean X. 136 func (b *Bin2D) XMean() float64 { 137 return b.Dist.xMean() 138 } 139 140 // YMean returns the mean Y. 141 func (b *Bin2D) YMean() float64 { 142 return b.Dist.yMean() 143 } 144 145 // XVariance returns the variance in X. 146 func (b *Bin2D) XVariance() float64 { 147 return b.Dist.xVariance() 148 } 149 150 // YVariance returns the variance in Y. 151 func (b *Bin2D) YVariance() float64 { 152 return b.Dist.yVariance() 153 } 154 155 // XStdDev returns the standard deviation in X. 156 func (b *Bin2D) XStdDev() float64 { 157 return b.Dist.xStdDev() 158 } 159 160 // YStdDev returns the standard deviation in Y. 161 func (b *Bin2D) YStdDev() float64 { 162 return b.Dist.yStdDev() 163 } 164 165 // XStdErr returns the standard error in X. 166 func (b *Bin2D) XStdErr() float64 { 167 return b.Dist.xStdErr() 168 } 169 170 // YStdErr returns the standard error in Y. 171 func (b *Bin2D) YStdErr() float64 { 172 return b.Dist.yStdErr() 173 } 174 175 // XRMS returns the RMS in X. 176 func (b *Bin2D) XRMS() float64 { 177 return b.Dist.xRMS() 178 } 179 180 // YRMS returns the RMS in Y. 181 func (b *Bin2D) YRMS() float64 { 182 return b.Dist.yRMS() 183 } 184 185 // check Bin2D implements interfaces 186 var _ Bin = (*Bin2D)(nil)