PAW allowed filling histograms by bin number. Is the same functionality available in ROOT? If yes please point me at the documentation (since I can’t seem to find it on my own), if not here is my workaround for now:
I need this particularly for a TProfile2D and the histograms need to be merged later. That means AddBinContent is not an option, since it does not seem to set the proper statistics for merging histograms later.
For now I overloaded the Fill routine in a class derived from TProfile2D with two new functions. Most of the code is taken from the existing TProfile2D::Fill routines, but the FindBin search has been removed.
The header looks like this:
class TProfile2DFastFill : public TProfile2D
{
public:
// --- constructors ---
// ...
// --- use old Fill methods as well as these overloads ---
using TProfile2D:Fill;
// fast filling by global bin number
virtual Int_t Fill( const Int_t& bin, const Double_t& value, const Double_t& weight = 1. );
// fast filling by x and y bin number
Int_t Fill( const Int_t& bin_x, const Int_t& bin_y, const Double_t& value, const Double_t& weight = 1. );
// ...
};
And the source like this:
Int_t TProfile2DFastFill::Fill( const Int_t& bin, const Double_t& value, const Double_t& weight )
{
Double_t u = std::fabs( weight );
fEntries++;
AddBinContent(bin, u*value);
fSumw2.fArray[bin] += u*value*value;
fBinEntries.fArray[bin] += u;
Int_t x_bin;
Int_t y_bin;
Int_t z_bin;
GetBinXYZ( bin, x_bin, y_bin, z_bin );
Double_t x = GetXaxis()->GetBinCenter( x_bin );
Double_t y = GetYaxis()->GetBinCenter( y_bin );
if (x_bin == 0 || x_bin > fXaxis.GetNbins()) {
if (!fgStatOverflows) return -1;
}
if (y_bin == 0 || y_bin > fYaxis.GetNbins()) {
if (!fgStatOverflows) return -1;
}
fTsumw += u;
fTsumw2 += u*u;
fTsumwx += u*x;
fTsumwx2 += u*x*x;
fTsumwy += u*y;
fTsumwy2 += u*y*y;
fTsumwxy += u*x*y;
fTsumwz += u*value;
fTsumwz2 += u*value*value;
return bin;
}
Int_t TProfile2DFastFill::Fill( const Int_t& bin_x, const Int_t& bin_y, const Double_t& value, const Double_t& weight )
{
Int_t bin = GetBin( bin_x, bin_y );
return Fill( bin, value, weight );
}
This seems to do the trick, but I am certainly no root expert