The following example is derived from the HEPInventor visualisation package - only a subset of the complete code is used. The method receives an I_Histo reference which is then used, for instance, to find out whether this is a 1D or 2D histogram. Via the same I_Histo reference, the code retrieves an interface to the underlying partition, which gives information about the beginning and end of each bin. At the end, the I_Bin interface of each bin allows us to retrieve the content and the error associated to each bin.
HIData::HIData(I_Histo &histo) {
int i,j,k=0;
switch (histo.dim()) { // Is it 1D or 2D?
case 1:
// Copy the histogram content in a local data structure
nptx = histo.bin_count();
// Use underlying histo.i_partition() interface
Xval[0] = histo.i_partition(0).i_lower_point(0);
Yval[0] = histo.i_bin(0).value();
// Had to patch this... no asymmetric errors yet...
EXval[0] = (histo.i_partition(0).i_lower_point(1)-Xval[0])/2.;
EYval[0] = histo.i_bin(0).error();
for ( i=1; i < nptx; i++) {
Xval[i] = histo.i_partition(0).i_lower_point(i);
// Use I_Bin interface to retriev value/error
Yval[i] = histo.i_bin(i).value();
EYval[i] = histo.i_bin(i).error();
}
}
}
As you can see there is no reference whatsoever to the real C++ type of the histogram, to its dimensionality, etc. The same code works with all HTL histograms!