1 package hep.aida.ref; 2 3 import hep.aida.IAxis; 4 import hep.aida.IHistogram; 5 import hep.aida.IHistogram2D; 6 import hep.aida.IHistogram3D; 7 /** 8 Abstract base class extracting and implementing most of the redundancy of the interface. 9 10 @author Wolfgang Hoschek, Tony Johnson, and others. 11 @version 1.0, 23/03/2000 12 */ 13 abstract class AbstractHistogram3D extends Histogram implements IHistogram3D 14 { 15 protected IAxis xAxis, yAxis, zAxis; AbstractHistogram3D(String title)16 AbstractHistogram3D(String title) 17 { 18 super(title); 19 } allEntries()20 public int allEntries() 21 { 22 int n = 0; 23 for (int i=xAxis.bins(); --i >= -2;) 24 for (int j=yAxis.bins(); --j >= -2;) 25 for (int k=zAxis.bins(); --k >= -2;) 26 { 27 n += binEntries(i,j,k); 28 } 29 return n; 30 } dimensions()31 public int dimensions() 32 { 33 return 3; 34 } entries()35 public int entries() 36 { 37 int n = 0; 38 for (int i=0; i<xAxis.bins(); i++) 39 for (int j=0; j<yAxis.bins(); j++) 40 for (int k=0;k<zAxis.bins(); k++) 41 { 42 n += binEntries(i,j,k); 43 } 44 return n; 45 } extraEntries()46 public int extraEntries() 47 { 48 return allEntries() - entries(); 49 } fill(double x, double y, double z)50 public void fill(double x, double y, double z) 51 { 52 fill(x,y,z,1); 53 } 54 /** 55 * The precise meaning of the arguments to the public slice 56 * methods is somewhat ambiguous, so we define this internal 57 * slice method and clearly specify its arguments. 58 * <p> 59 * <b>Note 0</b>indexX1 and indexX2 use our INTERNAL bin numbering scheme 60 * <b>Note 1</b>The slice is done between indexX1 and indexX2 INCLUSIVE 61 * <b>Note 2</b>indexX1 and indexX2 may include the use of under and over flow bins 62 * <b>Note 3</b>There is no note 3 (yet) 63 */ internalSliceXY(String title, int indexZ1, int indexZ2)64 protected abstract IHistogram2D internalSliceXY(String title, int indexZ1, int indexZ2); 65 /** 66 * The precise meaning of the arguments to the public slice 67 * methods is somewhat ambiguous, so we define this internal 68 * slice method and clearly specify its arguments. 69 * <p> 70 * <b>Note 0</b>indexY1 and indexY2 use our INTERNAL bin numbering scheme 71 * <b>Note 1</b>The slice is done between indexY1 and indexY2 INCLUSIVE 72 * <b>Note 2</b>indexY1 and indexY2 may include the use of under and over flow bins 73 * <b>Note 3</b>There is no note 3 (yet) 74 */ internalSliceXZ(String title, int indexY1, int indexY2)75 protected abstract IHistogram2D internalSliceXZ(String title, int indexY1, int indexY2); 76 /** 77 * The precise meaning of the arguments to the public slice 78 * methods is somewhat ambiguous, so we define this internal 79 * slice method and clearly specify its arguments. 80 * <p> 81 * <b>Note 0</b>indexX1 and indexX2 use our INTERNAL bin numbering scheme 82 * <b>Note 1</b>The slice is done between indexX1 and indexX2 INCLUSIVE 83 * <b>Note 2</b>indexX1 and indexX2 may include the use of under and over flow bins 84 * <b>Note 3</b>There is no note 3 (yet) 85 */ internalSliceYZ(String title, int indexX1, int indexX2)86 protected abstract IHistogram2D internalSliceYZ(String title, int indexX1, int indexX2); 87 /** 88 * Package private method to map from the external representation of bin 89 * number to our internal representation of bin number 90 */ mapX(int index)91 int mapX(int index) 92 { 93 int bins = xAxis.bins() + 2; 94 if (index >= bins) throw new IllegalArgumentException("bin="+index); 95 if (index >= 0) return index+1; 96 if (index == IHistogram.UNDERFLOW) return 0; 97 if (index == IHistogram.OVERFLOW) return bins-1; 98 throw new IllegalArgumentException("bin="+index); 99 } 100 /** 101 * Package private method to map from the external representation of bin 102 * number to our internal representation of bin number 103 */ mapY(int index)104 int mapY(int index) 105 { 106 int bins = yAxis.bins() + 2; 107 if (index >= bins) throw new IllegalArgumentException("bin="+index); 108 if (index >= 0) return index+1; 109 if (index == IHistogram.UNDERFLOW) return 0; 110 if (index == IHistogram.OVERFLOW) return bins-1; 111 throw new IllegalArgumentException("bin="+index); 112 } 113 /** 114 * Package private method to map from the external representation of bin 115 * number to our internal representation of bin number 116 */ mapZ(int index)117 int mapZ(int index) 118 { 119 int bins = zAxis.bins() + 2; 120 if (index >= bins) throw new IllegalArgumentException("bin="+index); 121 if (index >= 0) return index+1; 122 if (index == IHistogram.UNDERFLOW) return 0; 123 if (index == IHistogram.OVERFLOW) return bins-1; 124 throw new IllegalArgumentException("bin="+index); 125 } minMaxBins()126 public int[] minMaxBins() 127 { 128 double minValue = Double.MAX_VALUE; 129 double maxValue = Double.MIN_VALUE; 130 int minBinX = -1; 131 int minBinY = -1; 132 int minBinZ = -1; 133 int maxBinX = -1; 134 int maxBinY = -1; 135 int maxBinZ = -1; 136 for (int i=xAxis.bins(); --i >= 0; ) { 137 for (int j=yAxis.bins(); --j >= 0; ) { 138 for (int k=zAxis.bins(); --k >= 0; ) { 139 double value = binHeight(i,j,k); 140 if (value < minValue) { 141 minValue = value; 142 minBinX = i; 143 minBinY = j; 144 minBinZ = k; 145 } 146 if (value > maxValue) { 147 maxValue = value; 148 maxBinX = i; 149 maxBinY = j; 150 maxBinZ = k; 151 } 152 } 153 } 154 } 155 int[] result = {minBinX,minBinY,minBinZ, maxBinX,maxBinY,maxBinZ}; 156 return result; 157 } projectionXY()158 public IHistogram2D projectionXY() 159 { 160 String newTitle = title() + " (projectionXY)"; 161 return internalSliceXY(newTitle,mapZ(IHistogram.UNDERFLOW),mapZ(IHistogram.OVERFLOW)); 162 } projectionXZ()163 public IHistogram2D projectionXZ() 164 { 165 String newTitle = title() + " (projectionXZ)"; 166 return internalSliceXZ(newTitle,mapY(IHistogram.UNDERFLOW),mapY(IHistogram.OVERFLOW)); 167 } projectionYZ()168 public IHistogram2D projectionYZ() 169 { 170 String newTitle = title() + " (projectionYZ)"; 171 return internalSliceYZ(newTitle,mapX(IHistogram.UNDERFLOW),mapX(IHistogram.OVERFLOW)); 172 } sliceXY(int indexZ )173 public IHistogram2D sliceXY(int indexZ ) 174 { 175 return sliceXY(indexZ,indexZ); 176 } sliceXY(int indexZ1, int indexZ2)177 public IHistogram2D sliceXY(int indexZ1, int indexZ2) 178 { 179 int start = mapZ(indexZ1); 180 int stop = mapZ(indexZ2); 181 String newTitle = title() + " (sliceXY ["+indexZ1+":"+indexZ2+"])"; 182 return internalSliceXY(newTitle,start,stop); 183 } sliceXZ(int indexY )184 public IHistogram2D sliceXZ(int indexY ) 185 { 186 return sliceXZ(indexY,indexY); 187 } sliceXZ(int indexY1, int indexY2)188 public IHistogram2D sliceXZ(int indexY1, int indexY2) 189 { 190 int start = mapY(indexY1); 191 int stop = mapY(indexY2); 192 String newTitle = title() + " (sliceXZ ["+indexY1+":"+indexY2+"])"; 193 return internalSliceXY(newTitle,start,stop); 194 } sliceYZ(int indexX )195 public IHistogram2D sliceYZ(int indexX ) 196 { 197 return sliceYZ(indexX,indexX); 198 } sliceYZ(int indexX1, int indexX2)199 public IHistogram2D sliceYZ(int indexX1, int indexX2) 200 { 201 int start = mapX(indexX1); 202 int stop = mapX(indexX2); 203 String newTitle = title() + " (sliceYZ ["+indexX1+":"+indexX2+"])"; 204 return internalSliceYZ(newTitle,start,stop); 205 } sumAllBinHeights()206 public double sumAllBinHeights() 207 { 208 double n = 0; 209 for (int i=xAxis.bins(); --i >= -2;) 210 for (int j=yAxis.bins(); --j >= -2;) 211 for (int k=zAxis.bins(); --k >= -2;) 212 { 213 n += binHeight(i,j,k); 214 } 215 return n; 216 } sumBinHeights()217 public double sumBinHeights() 218 { 219 double n = 0; 220 for (int i=0; i<xAxis.bins(); i++) 221 for (int j=0; j<yAxis.bins(); j++) 222 for (int k=0; k<zAxis.bins(); k++) 223 { 224 n += binHeight(i,j,k); 225 } 226 return n; 227 } sumExtraBinHeights()228 public double sumExtraBinHeights() 229 { 230 return sumAllBinHeights() - sumBinHeights(); 231 } xAxis()232 public IAxis xAxis() 233 { 234 return xAxis; 235 } yAxis()236 public IAxis yAxis() 237 { 238 return yAxis; 239 } zAxis()240 public IAxis zAxis() 241 { 242 return zAxis; 243 } 244 } 245