#include "THnSparse.h"
#include "TArrayI.h"
#include "TAxis.h"
#include "TClass.h"
#include "TCollection.h"
#include "TDataMember.h"
#include "TDataType.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH3D.h"
#include "TF1.h"
#include "TInterpreter.h"
#include "TMath.h"
#include "TRandom.h"
#include "TError.h"
#include "HFitInterface.h"
#include "Fit/SparseData.h"
#include "Math/MinimizerOptions.h"
#include "Math/WrappedMultiTF1.h"
class THnSparseCoordCompression {
public:
THnSparseCoordCompression(Int_t dim, const Int_t* nbins);
THnSparseCoordCompression(const THnSparseCoordCompression& other);
~THnSparseCoordCompression();
ULong64_t GetHashFromBuffer(const Char_t* buf) const;
Int_t GetBufferSize() const { return fCoordBufferSize; }
Int_t GetNdimensions() const { return fNdimensions; }
void SetCoordFromBuffer(const Char_t* buf_in, Int_t* coord_out) const;
ULong64_t SetBufferFromCoord(const Int_t* coord_in, Char_t* buf_out) const;
protected:
Int_t GetNumBits(Int_t n) const {
Int_t r = (n > 0);
while (n/=2) ++r;
return r;
}
private:
Int_t fNdimensions;
Int_t fCoordBufferSize;
Int_t *fBitOffsets;
};
THnSparseCoordCompression::THnSparseCoordCompression(Int_t dim, const Int_t* nbins):
fNdimensions(dim), fCoordBufferSize(0), fBitOffsets(0)
{
fBitOffsets = new Int_t[dim + 1];
int shift = 0;
for (Int_t i = 0; i < dim; ++i) {
fBitOffsets[i] = shift;
shift += GetNumBits(nbins[i] + 2);
}
fBitOffsets[dim] = shift;
fCoordBufferSize = (shift + 7) / 8;
}
THnSparseCoordCompression::THnSparseCoordCompression(const THnSparseCoordCompression& other)
{
fNdimensions = other.fNdimensions;
fCoordBufferSize = other.fCoordBufferSize;
fBitOffsets = new Int_t[fNdimensions + 1];
memcpy(fBitOffsets, other.fBitOffsets, sizeof(Int_t) * fNdimensions);
}
THnSparseCoordCompression::~THnSparseCoordCompression()
{
delete [] fBitOffsets;
}
void THnSparseCoordCompression::SetCoordFromBuffer(const Char_t* buf_in,
Int_t* coord_out) const
{
for (Int_t i = 0; i < fNdimensions; ++i) {
const Int_t offset = fBitOffsets[i] / 8;
Int_t shift = fBitOffsets[i] % 8;
Int_t nbits = fBitOffsets[i + 1] - fBitOffsets[i];
const UChar_t* pbuf = (const UChar_t*) buf_in + offset;
coord_out[i] = *pbuf >> shift;
Int_t subst = (Int_t) -1;
subst = subst << nbits;
nbits -= (8 - shift);
shift = 8 - shift;
for (Int_t n = 0; n * 8 < nbits; ++n) {
++pbuf;
coord_out[i] += *pbuf << shift;
shift += 8;
}
coord_out[i] &= ~subst;
}
}
ULong64_t THnSparseCoordCompression::SetBufferFromCoord(const Int_t* coord_in,
Char_t* buf_out) const
{
if (fCoordBufferSize <= 8) {
ULong64_t l64buf = 0;
for (Int_t i = 0; i < fNdimensions; ++i) {
l64buf += ((ULong64_t)((UInt_t)coord_in[i])) << fBitOffsets[i];
}
memcpy(buf_out, &l64buf, sizeof(Long64_t));
return l64buf;
}
memset(buf_out, 0, fCoordBufferSize);
for (Int_t i = 0; i < fNdimensions; ++i) {
const Int_t offset = fBitOffsets[i] / 8;
const Int_t shift = fBitOffsets[i] % 8;
ULong64_t val = coord_in[i];
Char_t* pbuf = buf_out + offset;
*pbuf += 0xff & (val << shift);
val = val >> (8 - shift);
while (val) {
++pbuf;
*pbuf += 0xff & val;
val = val >> 8;
}
}
return GetHashFromBuffer(buf_out);
}
ULong64_t THnSparseCoordCompression::GetHashFromBuffer(const Char_t* buf) const
{
if (fCoordBufferSize <= 8) {
ULong64_t hash1 = 0;
memcpy(&hash1, buf, fCoordBufferSize);
return hash1;
}
ULong64_t hash = 5381;
const Char_t* str = buf;
while (str - buf < fCoordBufferSize) {
hash *= 5;
hash += *(str++);
}
return hash;
}
class THnSparseCompactBinCoord: public THnSparseCoordCompression {
public:
THnSparseCompactBinCoord(Int_t dim, const Int_t* nbins);
~THnSparseCompactBinCoord();
Int_t* GetCoord() { return fCurrentBin; }
const Char_t* GetBuffer() const { return fCoordBuffer; }
ULong64_t GetHash() const { return fHash; }
void UpdateCoord() {
fHash = SetBufferFromCoord(fCurrentBin, fCoordBuffer);
}
void SetCoord(const Int_t* coord) {
memcpy(fCurrentBin, coord, sizeof(Int_t) * GetNdimensions());
fHash = SetBufferFromCoord(coord, fCoordBuffer);
}
void SetBuffer(const Char_t* buf) {
memcpy(fCoordBuffer, buf, GetBufferSize());
fHash = GetHashFromBuffer(fCoordBuffer);
}
private:
ULong64_t fHash;
Char_t *fCoordBuffer;
Int_t *fCurrentBin;
};
THnSparseCompactBinCoord::THnSparseCompactBinCoord(Int_t dim, const Int_t* nbins):
THnSparseCoordCompression(dim, nbins),
fHash(0), fCoordBuffer(0), fCurrentBin(0)
{
fCurrentBin = new Int_t[dim];
size_t bufAllocSize = GetBufferSize();
if (bufAllocSize < sizeof(Long64_t))
bufAllocSize = sizeof(Long64_t);
fCoordBuffer = new Char_t[bufAllocSize];
}
THnSparseCompactBinCoord::~THnSparseCompactBinCoord()
{
delete [] fCoordBuffer;
delete [] fCurrentBin;
}
ClassImp(THnSparseArrayChunk);
THnSparseArrayChunk::THnSparseArrayChunk(Int_t coordsize, bool errors, TArray* cont):
fCoordinateAllocationSize(-1), fSingleCoordinateSize(coordsize), fCoordinatesSize(0),
fCoordinates(0), fContent(cont),
fSumw2(0)
{
fCoordinateAllocationSize = fSingleCoordinateSize * cont->GetSize();
fCoordinates = new Char_t[fCoordinateAllocationSize];
if (errors) Sumw2();
}
THnSparseArrayChunk::~THnSparseArrayChunk()
{
delete fContent;
delete [] fCoordinates;
delete fSumw2;
}
void THnSparseArrayChunk::AddBin(Int_t idx, const Char_t* coordbuf)
{
if (fCoordinateAllocationSize == -1 && fContent) {
Int_t chunksize = fSingleCoordinateSize * fContent->GetSize();
if (fCoordinatesSize < chunksize) {
Char_t *newcoord = new Char_t[chunksize];
memcpy(newcoord, fCoordinates, fCoordinatesSize);
delete [] fCoordinates;
fCoordinates = newcoord;
}
fCoordinateAllocationSize = chunksize;
}
memcpy(fCoordinates + idx * fSingleCoordinateSize, coordbuf, fSingleCoordinateSize);
fCoordinatesSize += fSingleCoordinateSize;
}
void THnSparseArrayChunk::Sumw2()
{
if (!fSumw2)
fSumw2 = new TArrayD(fContent->GetSize());
}
ClassImp(THnSparse);
THnSparse::THnSparse():
fNdimensions(0), fChunkSize(1024), fFilledBins(0), fEntries(0),
fTsumw(0), fTsumw2(-1.), fCompactCoord(0), fIntegral(0), fIntegralStatus(kNoInt)
{
fBinContent.SetOwner();
}
THnSparse::THnSparse(const char* name, const char* title, Int_t dim,
const Int_t* nbins, const Double_t* xmin, const Double_t* xmax,
Int_t chunksize):
TNamed(name, title), fNdimensions(dim), fChunkSize(chunksize), fFilledBins(0),
fAxes(dim), fEntries(0), fTsumw(0), fTsumw2(-1.), fTsumwx(dim), fTsumwx2(dim),
fCompactCoord(0), fIntegral(0), fIntegralStatus(kNoInt)
{
for (Int_t i = 0; i < fNdimensions; ++i) {
TAxis* axis = new TAxis(nbins[i], xmin ? xmin[i] : 0., xmax ? xmax[i] : 1.);
fAxes.AddAtAndExpand(axis, i);
}
SetTitle(title);
fAxes.SetOwner();
fCompactCoord = new THnSparseCompactBinCoord(dim, nbins);
fBinContent.SetOwner();
}
THnSparse::~THnSparse() {
delete fCompactCoord;
if (fIntegralStatus != kNoInt) delete [] fIntegral;
}
void THnSparse::AddBinContent(const Int_t* coord, Double_t v)
{
GetCompactCoord()->SetCoord(coord);
Long64_t bin = GetBinIndexForCurrentBin(kTRUE);
return AddBinContent(bin, v);
}
void THnSparse::AddBinContent(Long64_t bin, Double_t v)
{
THnSparseArrayChunk* chunk = GetChunk(bin / fChunkSize);
bin %= fChunkSize;
v += chunk->fContent->GetAt(bin);
return chunk->fContent->SetAt(v, bin);
}
THnSparseArrayChunk* THnSparse::AddChunk()
{
THnSparseArrayChunk* chunk =
new THnSparseArrayChunk(GetCompactCoord()->GetBufferSize(),
GetCalculateErrors(), GenerateArray());
fBinContent.AddLast(chunk);
return chunk;
}
THnSparse* THnSparse::CloneEmpty(const char* name, const char* title,
const TObjArray* axes, Int_t chunksize,
Bool_t keepTargetAxis) const
{
THnSparse* ret = (THnSparse*)IsA()->New();
ret->SetNameTitle(name, title);
ret->fNdimensions = axes->GetEntriesFast();
ret->fChunkSize = chunksize;
TIter iAxis(axes);
const TAxis* axis = 0;
Int_t pos = 0;
Int_t *nbins = new Int_t[axes->GetEntriesFast()];
while ((axis = (TAxis*)iAxis())) {
TAxis* reqaxis = (TAxis*)axis->Clone();
if (!keepTargetAxis && axis->TestBit(TAxis::kAxisRange)) {
Int_t binFirst = axis->GetFirst();
Int_t binLast = axis->GetLast();
Int_t nBins = binLast - binFirst + 1;
if (axis->GetXbins()->GetSize()) {
reqaxis->Set(nBins, axis->GetXbins()->GetArray() + binFirst - 1);
} else {
reqaxis->Set(nBins, axis->GetBinLowEdge(binFirst), axis->GetBinUpEdge(binLast));
}
reqaxis->ResetBit(TAxis::kAxisRange);
}
nbins[pos] = reqaxis->GetNbins();
ret->fAxes.AddAtAndExpand(reqaxis->Clone(), pos++);
}
ret->fAxes.SetOwner();
ret->fCompactCoord = new THnSparseCompactBinCoord(pos, nbins);
delete [] nbins;
return ret;
}
TH1* THnSparse::CreateHist(const char* name, const char* title,
const TObjArray* axes,
Bool_t keepTargetAxis ) const {
const int ndim = axes->GetSize();
TH1* hist = 0;
if (ndim == 1)
hist = new TH1D(name, title, 1, 0., 1.);
else if (ndim == 2)
hist = new TH2D(name, title, 1, 0., 1., 1, 0., 1.);
else if (ndim == 3)
hist = new TH3D(name, title, 1, 0., 1., 1, 0., 1., 1, 0., 1.);
else {
Error("CreateHist", "Cannot create histogram %s with %d dimensions!", name, ndim);
return 0;
}
TAxis* hax[3] = {hist->GetXaxis(), hist->GetYaxis(), hist->GetZaxis()};
for (Int_t d = 0; d < ndim; ++d) {
TAxis* reqaxis = (TAxis*)(*axes)[d];
hax[d]->SetTitle(reqaxis->GetTitle());
if (!keepTargetAxis && reqaxis->TestBit(TAxis::kAxisRange)) {
Int_t binFirst = reqaxis->GetFirst();
if (binFirst == 0) binFirst = 1;
Int_t binLast = reqaxis->GetLast();
Int_t nBins = binLast - binFirst + 1;
if (reqaxis->GetXbins()->GetSize()) {
hax[d]->Set(nBins, reqaxis->GetXbins()->GetArray() + binFirst - 1);
} else {
hax[d]->Set(nBins, reqaxis->GetBinLowEdge(binFirst), reqaxis->GetBinUpEdge(binLast));
}
} else {
if (reqaxis->GetXbins()->GetSize()) {
hax[d]->Set(reqaxis->GetNbins(), reqaxis->GetXbins()->GetArray());
} else {
hax[d]->Set(reqaxis->GetNbins(), reqaxis->GetXmin(), reqaxis->GetXmax());
}
}
}
hist->Rebuild();
return hist;
}
THnSparse* THnSparse::CreateSparse(const char* name, const char* title,
const TH1* h, Int_t chunkSize)
{
int ndim = h->GetDimension();
int nbins[3] = {0,0,0};
double minRange[3] = {0.,0.,0.};
double maxRange[3] = {0.,0.,0.};
TAxis* axis[3] = { h->GetXaxis(), h->GetYaxis(), h->GetZaxis() };
for (int i = 0; i < ndim; ++i) {
nbins[i] = axis[i]->GetNbins();
minRange[i] = axis[i]->GetXmin();
maxRange[i] = axis[i]->GetXmax();
}
THnSparse* s = 0;
const char* cname( h->ClassName() );
if (cname[0] == 'T' && cname[1] == 'H' && cname[2] >= '1' && cname[2] <= '3' && cname[4] == 0) {
if (cname[3] == 'F') {
s = new THnSparseF(name, title, ndim, nbins, minRange, maxRange, chunkSize);
} else if (cname[3] == 'D') {
s = new THnSparseD(name, title, ndim, nbins, minRange, maxRange, chunkSize);
} else if (cname[3] == 'I') {
s = new THnSparseI(name, title, ndim, nbins, minRange, maxRange, chunkSize);
} else if (cname[3] == 'S') {
s = new THnSparseS(name, title, ndim, nbins, minRange, maxRange, chunkSize);
} else if (cname[3] == 'C') {
s = new THnSparseC(name, title, ndim, nbins, minRange, maxRange, chunkSize);
}
}
if (!s) {
::Warning("THnSparse::CreateSparse", "Unknown Type of Histogram");
return 0;
}
for (int i = 0; i < ndim; ++i) {
s->GetAxis(i)->SetTitle(axis[i]->GetTitle());
}
const TArray *array = dynamic_cast<const TArray*>(h);
if (!array) {
::Warning("THnSparse::CreateSparse", "Unknown Type of Histogram");
return 0;
}
for (int i = 0; i < array->GetSize(); ++i) {
double value = h->GetBinContent(i);
double error = h->GetBinError(i);
if (!value && !error) continue;
int x[3] = {0,0,0};
h->GetBinXYZ(i, x[0], x[1], x[2]);
s->SetBinContent(x, value);
s->SetBinError(x, error);
}
return s;
}
void THnSparse::FillExMap()
{
TIter iChunk(&fBinContent);
THnSparseArrayChunk* chunk = 0;
THnSparseCoordCompression compactCoord(*GetCompactCoord());
Long64_t idx = 0;
if (2 * GetNbins() > fBins.Capacity())
fBins.Expand(3 * GetNbins());
while ((chunk = (THnSparseArrayChunk*) iChunk())) {
const Int_t chunkSize = chunk->GetEntries();
Char_t* buf = chunk->fCoordinates;
const Int_t singleCoordSize = chunk->fSingleCoordinateSize;
const Char_t* endbuf = buf + singleCoordSize * chunkSize;
for (; buf < endbuf; buf += singleCoordSize, ++idx) {
Long64_t hash = compactCoord.GetHashFromBuffer(buf);
Long64_t linidx = fBins.GetValue(hash);
if (linidx) {
Long64_t nextidx = linidx;
while (nextidx) {
linidx = nextidx;
nextidx = fBinsContinued.GetValue(linidx);
}
fBinsContinued.Add(linidx, idx + 1);
} else {
fBins.Add(hash, idx + 1);
}
}
}
}
TFitResultPtr THnSparse::Fit(TF1 *f ,Option_t *option ,Option_t *goption)
{
Foption_t fitOption;
if (!TH1::FitOptionsMake(option,fitOption)) return 0;
fitOption.Nostore = true;
if (!fitOption.Chi2) fitOption.Like = true;
ROOT::Fit::DataRange range(GetNdimensions());
for ( int i = 0; i < GetNdimensions(); ++i ) {
TAxis *axis = GetAxis(i);
range.AddRange(i, axis->GetXmin(), axis->GetXmax());
}
ROOT::Math::MinimizerOptions minOption;
return ROOT::Fit::FitObject(this, f , fitOption , minOption, goption, range);
}
Long64_t THnSparse::GetBin(const Double_t* x, Bool_t allocate )
{
THnSparseCompactBinCoord* cc = GetCompactCoord();
Int_t *coord = cc->GetCoord();
for (Int_t i = 0; i < fNdimensions; ++i)
coord[i] = GetAxis(i)->FindBin(x[i]);
cc->UpdateCoord();
return GetBinIndexForCurrentBin(allocate);
}
Long64_t THnSparse::GetBin(const char* name[], Bool_t allocate )
{
THnSparseCompactBinCoord* cc = GetCompactCoord();
Int_t *coord = cc->GetCoord();
for (Int_t i = 0; i < fNdimensions; ++i)
coord[i] = GetAxis(i)->FindBin(name[i]);
cc->UpdateCoord();
return GetBinIndexForCurrentBin(allocate);
}
Long64_t THnSparse::GetBin(const Int_t* coord, Bool_t allocate )
{
GetCompactCoord()->SetCoord(coord);
return GetBinIndexForCurrentBin(allocate);
}
Double_t THnSparse::GetBinContent(const Int_t *coord) const {
GetCompactCoord()->SetCoord(coord);
Long64_t idx = const_cast<THnSparse*>(this)->GetBinIndexForCurrentBin(kFALSE);
if (idx < 0) return 0.;
THnSparseArrayChunk* chunk = GetChunk(idx / fChunkSize);
return chunk->fContent->GetAt(idx % fChunkSize);
}
Double_t THnSparse::GetBinContent(Long64_t idx, Int_t* coord ) const
{
if (idx >= 0) {
THnSparseArrayChunk* chunk = GetChunk(idx / fChunkSize);
idx %= fChunkSize;
if (chunk && chunk->fContent->GetSize() > idx) {
if (coord) {
THnSparseCompactBinCoord* cc = GetCompactCoord();
Int_t sizeCompact = cc->GetBufferSize();
cc->SetCoordFromBuffer(chunk->fCoordinates + idx * sizeCompact,
coord);
}
return chunk->fContent->GetAt(idx);
}
}
if (coord)
memset(coord, -1, sizeof(Int_t) * fNdimensions);
return 0.;
}
Double_t THnSparse::GetBinError(const Int_t *coord) const {
// END_LATEX
if (!GetCalculateErrors())
return TMath::Sqrt(GetBinContent(coord));
GetCompactCoord()->SetCoord(coord);
Long64_t idx = const_cast<THnSparse*>(this)->GetBinIndexForCurrentBin(kFALSE);
if (idx < 0) return 0.;
THnSparseArrayChunk* chunk = GetChunk(idx / fChunkSize);
return TMath::Sqrt(chunk->fSumw2->GetAt(idx % fChunkSize));
}
Double_t THnSparse::GetBinError(Long64_t linidx) const {
// END_LATEX
if (!GetCalculateErrors())
return TMath::Sqrt(GetBinContent(linidx));
if (linidx < 0) return 0.;
THnSparseArrayChunk* chunk = GetChunk(linidx / fChunkSize);
linidx %= fChunkSize;
if (!chunk || chunk->fContent->GetSize() < linidx)
return 0.;
return TMath::Sqrt(chunk->fSumw2->GetAt(linidx));
}
Long64_t THnSparse::GetBinIndexForCurrentBin(Bool_t allocate)
{
THnSparseCompactBinCoord* cc = GetCompactCoord();
ULong64_t hash = cc->GetHash();
if (fBinContent.GetSize() && !fBins.GetSize())
FillExMap();
Long64_t linidx = (Long64_t) fBins.GetValue(hash);
while (linidx) {
THnSparseArrayChunk* chunk = GetChunk((linidx - 1)/ fChunkSize);
if (chunk->Matches((linidx - 1) % fChunkSize, cc->GetBuffer()))
return linidx - 1;
Long64_t nextlinidx = fBinsContinued.GetValue(linidx);
if (!nextlinidx) break;
linidx = nextlinidx;
}
if (!allocate) return -1;
++fFilledBins;
THnSparseArrayChunk *chunk = (THnSparseArrayChunk*) fBinContent.Last();
Long64_t newidx = chunk ? ((Long64_t) chunk->GetEntries()) : -1;
if (!chunk || newidx == (Long64_t)fChunkSize) {
chunk = AddChunk();
newidx = 0;
}
chunk->AddBin(newidx, cc->GetBuffer());
newidx += (fBinContent.GetEntriesFast() - 1) * fChunkSize;
if (!linidx) {
if (2 * GetNbins() > fBins.Capacity())
fBins.Expand(3 * GetNbins());
fBins.Add(hash, newidx + 1);
} else {
fBinsContinued.Add(linidx, newidx + 1);
}
return newidx;
}
THnSparseCompactBinCoord* THnSparse::GetCompactCoord() const
{
if (!fCompactCoord) {
Int_t *bins = new Int_t[fNdimensions];
for (Int_t d = 0; d < fNdimensions; ++d)
bins[d] = GetAxis(d)->GetNbins();
const_cast<THnSparse*>(this)->fCompactCoord
= new THnSparseCompactBinCoord(fNdimensions, bins);
delete [] bins;
}
return fCompactCoord;
}
void THnSparse::GetRandom(Double_t *rand, Bool_t subBinRandom )
{
if (fIntegralStatus != kValidInt)
ComputeIntegral();
Double_t p = gRandom->Rndm();
Long64_t idx = TMath::BinarySearch(GetNbins() + 1, fIntegral, p);
const Int_t nStaticBins = 40;
Int_t bin[nStaticBins];
Int_t* pBin = bin;
if (GetNdimensions() > nStaticBins) {
pBin = new Int_t[GetNdimensions()];
}
GetBinContent(idx, pBin);
for (Int_t i = 0; i < fNdimensions; i++) {
rand[i] = GetAxis(i)->GetBinCenter(pBin[i]);
if (subBinRandom)
rand[i] += (gRandom->Rndm() - 0.5) * GetAxis(i)->GetBinWidth(pBin[i]);
}
if (pBin != bin) {
delete [] pBin;
}
return;
}
Double_t THnSparse::GetSparseFractionBins() const {
Double_t nbinsTotal = 1.;
for (Int_t d = 0; d < fNdimensions; ++d)
nbinsTotal *= GetAxis(d)->GetNbins() + 2;
return fFilledBins / nbinsTotal;
}
Double_t THnSparse::GetSparseFractionMem() const {
Int_t arrayElementSize = 0;
if (fFilledBins) {
TClass* clArray = GetChunk(0)->fContent->IsA();
TDataMember* dm = clArray ? clArray->GetDataMember("fArray") : 0;
arrayElementSize = dm ? dm->GetDataType()->Size() : 0;
}
if (!arrayElementSize) {
Warning("GetSparseFractionMem", "Cannot determine type of elements!");
return -1.;
}
Double_t sizePerChunkElement = arrayElementSize + GetCompactCoord()->GetBufferSize();
if (fFilledBins && GetChunk(0)->fSumw2)
sizePerChunkElement += sizeof(Double_t);
Double_t size = 0.;
size += fBinContent.GetEntries() * (GetChunkSize() * sizePerChunkElement + sizeof(THnSparseArrayChunk));
size += + 3 * sizeof(Long64_t) * fBins.GetSize() ;
Double_t nbinsTotal = 1.;
for (Int_t d = 0; d < fNdimensions; ++d)
nbinsTotal *= GetAxis(d)->GetNbins() + 2;
return size / nbinsTotal / arrayElementSize;
}
Bool_t THnSparse::IsInRange(Int_t *coord) const
{
Int_t min = 0;
Int_t max = 0;
for (Int_t i = 0; i < fNdimensions; ++i) {
TAxis *axis = GetAxis(i);
if (!axis->TestBit(TAxis::kAxisRange)) continue;
min = axis->GetFirst();
max = axis->GetLast();
if (min == 0 && max == 0) {
min = 1;
max = axis->GetNbins();
}
if (coord[i] < min || coord[i] > max)
return kFALSE;
}
return kTRUE;
}
TH1D* THnSparse::Projection(Int_t xDim, Option_t* option ) const
{
return (TH1D*) ProjectionAny(1, &xDim, false, option);
}
TH2D* THnSparse::Projection(Int_t yDim, Int_t xDim, Option_t* option ) const
{
const Int_t dim[2] = {xDim, yDim};
return (TH2D*) ProjectionAny(2, dim, false, option);
}
TH3D* THnSparse::Projection(Int_t xDim, Int_t yDim, Int_t zDim,
Option_t* option ) const
{
const Int_t dim[3] = {xDim, yDim, zDim};
return (TH3D*) ProjectionAny(3, dim, false, option);
}
THnSparse* THnSparse::Projection(Int_t ndim, const Int_t* dim,
Option_t* option ) const
{
return (THnSparse*) ProjectionAny(ndim, dim, true, option);
}
TObject* THnSparse::ProjectionAny(Int_t ndim, const Int_t* dim,
Bool_t wantSparse, Option_t* option ) const
{
TString name(GetName());
name +="_proj";
for (Int_t d = 0; d < ndim; ++d) {
name += "_";
name += dim[d];
}
TString title(GetTitle());
Ssiz_t posInsert = title.First(';');
if (posInsert == kNPOS) {
title += " projection ";
for (Int_t d = 0; d < ndim; ++d)
title += GetAxis(dim[d])->GetTitle();
} else {
for (Int_t d = ndim - 1; d >= 0; --d) {
title.Insert(posInsert, GetAxis(d)->GetTitle());
if (d)
title.Insert(posInsert, ", ");
}
title.Insert(posInsert, " projection ");
}
TObjArray newaxes(ndim);
for (Int_t d = 0; d < ndim; ++d) {
newaxes.AddAt(GetAxis(dim[d]),d);
}
THnSparse* sparse = 0;
TH1* hist = 0;
TObject* ret = 0;
Bool_t* hadRange = 0;
Bool_t ignoreTargetRange = (option && (strchr(option, 'A') || strchr(option, 'a')));
Bool_t keepTargetAxis = ignoreTargetRange || (option && (strchr(option, 'O') || strchr(option, 'o')));
if (ignoreTargetRange) {
hadRange = new Bool_t[ndim];
for (Int_t d = 0; d < ndim; ++d){
TAxis *axis = GetAxis(dim[d]);
hadRange[d] = axis->TestBit(TAxis::kAxisRange);
axis->SetBit(TAxis::kAxisRange, kFALSE);
}
}
if (wantSparse)
ret = sparse = CloneEmpty(name, title, &newaxes, fChunkSize, keepTargetAxis);
else
ret = hist = CreateHist(name, title, &newaxes, keepTargetAxis);
if (keepTargetAxis) {
if (wantSparse) {
for (Int_t d = 0; d < ndim; ++d) {
sparse->GetAxis(d)->SetRange(0, 0);
}
} else {
hist->GetXaxis()->SetRange(0, 0);
hist->GetYaxis()->SetRange(0, 0);
hist->GetZaxis()->SetRange(0, 0);
}
}
Bool_t haveErrors = GetCalculateErrors();
Bool_t wantErrors = (option && (strchr(option, 'E') || strchr(option, 'e'))) || haveErrors;
Int_t* bins = new Int_t[ndim];
Int_t linbin = 0;
Int_t* coord = new Int_t[fNdimensions];
memset(coord, 0, sizeof(Int_t) * fNdimensions);
Double_t err = 0.;
Double_t preverr = 0.;
Double_t v = 0.;
for (Long64_t i = 0; i < GetNbins(); ++i) {
v = GetBinContent(i, coord);
if (!IsInRange(coord)) continue;
for (Int_t d = 0; d < ndim; ++d) {
bins[d] = coord[dim[d]];
if (!keepTargetAxis && GetAxis(dim[d])->TestBit(TAxis::kAxisRange)) {
bins[d] -= GetAxis(dim[d])->GetFirst() - 1;
}
}
if (!wantSparse) {
if (ndim == 1) linbin = bins[0];
else if (ndim == 2) linbin = hist->GetBin(bins[0], bins[1]);
else if (ndim == 3) linbin = hist->GetBin(bins[0], bins[1], bins[2]);
}
if (wantErrors) {
if (haveErrors) {
err = GetBinError(i);
err *= err;
} else err = v;
if (wantSparse) {
preverr = sparse->GetBinError(bins);
sparse->SetBinError(bins, TMath::Sqrt(preverr * preverr + err));
} else {
preverr = hist->GetBinError(linbin);
hist->SetBinError(linbin, TMath::Sqrt(preverr * preverr + err));
}
}
if (wantSparse)
sparse->AddBinContent(bins, v);
else
hist->AddBinContent(linbin, v);
}
delete [] bins;
delete [] coord;
if (wantSparse)
sparse->SetEntries(fEntries);
else
hist->ResetStats();
if (hadRange) {
for (Int_t d = 0; d < ndim; ++d)
GetAxis(dim[d])->SetBit(TAxis::kAxisRange, hadRange[d]);
delete [] hadRange;
}
return ret;
}
void THnSparse::Scale(Double_t c)
{
Double_t nEntries = GetEntries();
Bool_t haveErrors = GetCalculateErrors();
for (Long64_t i = 0; i < GetNbins(); ++i) {
Double_t v = GetBinContent(i);
SetBinContent(i, c * v);
if (haveErrors) {
Double_t err = GetBinError(i);
SetBinError(i, c * err);
}
}
SetEntries(nEntries);
}
void THnSparse::AddInternal(const THnSparse* h, Double_t c, Bool_t rebinned)
{
if (fNdimensions != h->GetNdimensions()) {
Warning("RebinnedAdd", "Different number of dimensions, cannot carry out operation on the histograms");
return;
}
if (!GetCalculateErrors() && h->GetCalculateErrors())
Sumw2();
Bool_t haveErrors = GetCalculateErrors();
Int_t* coord = new Int_t[fNdimensions];
memset(coord, 0, sizeof(Int_t) * fNdimensions);
Double_t* x = 0;
if (rebinned) {
x = new Double_t[fNdimensions];
}
if (!fBins.GetSize() && fBinContent.GetSize()) {
FillExMap();
}
Long64_t numTargetBins = GetNbins() + h->GetNbins();
if (2 * numTargetBins > fBins.Capacity()) {
fBins.Expand(3 * numTargetBins);
}
for (Long64_t i = 0; i < h->GetNbins(); ++i) {
Double_t v = h->GetBinContent(i, coord);
Long64_t binidx = -1;
if (rebinned) {
for (Int_t j = 0; j < fNdimensions; ++j)
x[j] = h->GetAxis(j)->GetBinCenter(coord[j]);
binidx = GetBin(x);
} else {
binidx = GetBin(coord);
}
if (haveErrors) {
Double_t err1 = GetBinError(binidx);
Double_t err2 = h->GetBinError(i) * c;
SetBinError(binidx, TMath::Sqrt(err1 * err1 + err2 * err2));
}
AddBinContent(binidx, c * v);
}
delete [] coord;
delete [] x;
Double_t nEntries = GetEntries() + c * h->GetEntries();
SetEntries(nEntries);
}
void THnSparse::Add(const THnSparse* h, Double_t c)
{
if (!CheckConsistency(h, "Add")) return;
AddInternal(h, c, kFALSE);
}
void THnSparse::RebinnedAdd(const THnSparse* h, Double_t c)
{
AddInternal(h, c, kTRUE);
}
Long64_t THnSparse::Merge(TCollection* list)
{
if (!list) return 0;
if (list->IsEmpty()) return (Long64_t)GetEntries();
Long64_t sumNbins = GetNbins();
TIter iter(list);
const TObject* addMeObj = 0;
while ((addMeObj = iter())) {
const THnSparse* addMe = dynamic_cast<const THnSparse*>(addMeObj);
if (addMe) {
sumNbins += addMe->GetNbins();
}
}
if (!fBins.GetSize() && fBinContent.GetSize()) {
FillExMap();
}
if (2 * sumNbins > fBins.Capacity()) {
fBins.Expand(3 * sumNbins);
}
iter.Reset();
while ((addMeObj = iter())) {
const THnSparse* addMe = dynamic_cast<const THnSparse*>(addMeObj);
if (!addMe)
Error("Merge", "Object named %s is not THnSpase! Skipping it.",
addMeObj->GetName());
else
Add(addMe);
}
return (Long64_t)GetEntries();
}
void THnSparse::Multiply(const THnSparse* h)
{
if(!CheckConsistency(h, "Multiply"))return;
Bool_t wantErrors = kFALSE;
if (GetCalculateErrors() || h->GetCalculateErrors())
wantErrors = kTRUE;
if (wantErrors) Sumw2();
Double_t nEntries = GetEntries();
Int_t* coord = new Int_t[fNdimensions];
for (Long64_t i = 0; i < GetNbins(); ++i) {
Double_t v1 = GetBinContent(i, coord);
Double_t v2 = h->GetBinContent(coord);
SetBinContent(coord, v1 * v2);;
if (wantErrors) {
Double_t err1 = GetBinError(coord) * v2;
Double_t err2 = h->GetBinError(coord) * v1;
SetBinError(coord,TMath::Sqrt((err2 * err2 + err1 * err1)));
}
}
SetEntries(nEntries);
delete [] coord;
}
void THnSparse::Multiply(TF1* f, Double_t c)
{
Int_t* coord = new Int_t[fNdimensions];
memset(coord, 0, sizeof(Int_t) * fNdimensions);
Double_t* points = new Double_t[fNdimensions];
Bool_t wantErrors = GetCalculateErrors();
if (wantErrors) Sumw2();
ULong64_t nEntries = GetNbins();
for (ULong64_t i = 0; i < nEntries; ++i) {
Double_t value = GetBinContent(i, coord);
for (Int_t j = 0; j < fNdimensions; ++j)
points[j] = GetAxis(j)->GetBinCenter(coord[j]);
if (!f->IsInside(points))
continue;
TF1::RejectPoint(kFALSE);
Double_t fvalue = f->EvalPar(points, NULL);
SetBinContent(coord, c * fvalue * value);
if (wantErrors) {
Double_t error(GetBinError(i));
SetBinError(coord, c * fvalue * error);
}
}
delete [] points;
delete [] coord;
}
void THnSparse::Divide(const THnSparse *h)
{
if (!CheckConsistency(h, "Divide"))return;
Bool_t wantErrors=GetCalculateErrors();
if (!GetCalculateErrors() && h->GetCalculateErrors())
wantErrors=kTRUE;
Double_t nEntries = fEntries;
if (wantErrors) Sumw2();
Bool_t didWarn = kFALSE;
Int_t* coord = new Int_t[fNdimensions];
memset(coord, 0, sizeof(Int_t) * fNdimensions);
Double_t err = 0.;
Double_t b22 = 0.;
for (Long64_t i = 0; i < GetNbins(); ++i) {
Double_t v1 = GetBinContent(i, coord);
Double_t v2 = h->GetBinContent(coord);
if (!v2) {
v1 = 0.;
v2 = 1.;
if (!didWarn) {
Warning("Divide(h)", "Histogram h has empty bins - division by zero! Setting bin to 0.");
didWarn = kTRUE;
}
}
SetBinContent(coord, v1 / v2);
if (wantErrors) {
Double_t err1 = GetBinError(coord) * v2;
Double_t err2 = h->GetBinError(coord) * v1;
b22 = v2 * v2;
err = (err1 * err1 + err2 * err2) / (b22 * b22);
SetBinError(coord, TMath::Sqrt(err));
}
}
delete [] coord;
SetEntries(nEntries);
}
void THnSparse::Divide(const THnSparse *h1, const THnSparse *h2, Double_t c1, Double_t c2, Option_t *option)
{
TString opt = option;
opt.ToLower();
Bool_t binomial = kFALSE;
if (opt.Contains("b")) binomial = kTRUE;
if (!CheckConsistency(h1, "Divide") || !CheckConsistency(h2, "Divide"))return;
if (!c2) {
Error("Divide","Coefficient of dividing histogram cannot be zero");
return;
}
Reset();
if (!GetCalculateErrors() && (h1->GetCalculateErrors()|| h2->GetCalculateErrors() != 0))
Sumw2();
Long64_t nFilledBins=0;
Int_t* coord = new Int_t[fNdimensions];
memset(coord, 0, sizeof(Int_t) * fNdimensions);
Float_t w = 0.;
Float_t err = 0.;
Float_t b22 = 0.;
Bool_t didWarn = kFALSE;
for (Long64_t i = 0; i < h1->GetNbins(); ++i) {
Double_t v1 = h1->GetBinContent(i, coord);
Double_t v2 = h2->GetBinContent(coord);
if (!v2) {
v1 = 0.;
v2 = 1.;
if (!didWarn) {
Warning("Divide(h1, h2)", "Histogram h2 has empty bins - division by zero! Setting bin to 0.");
didWarn = kTRUE;
}
}
nFilledBins++;
SetBinContent(coord, c1 * v1 / c2 / v2);
if(GetCalculateErrors()){
Double_t err1=h1->GetBinError(coord);
Double_t err2=h2->GetBinError(coord);
if (binomial) {
if (v1 != v2) {
w = v1 / v2;
err2 *= w;
err = TMath::Abs( ( (1. - 2.*w) * err1 * err1 + err2 * err2 ) / (v2 * v2) );
} else {
err = 0;
}
} else {
c1 *= c1;
c2 *= c2;
b22 = v2 * v2 * c2;
err1 *= v2;
err2 *= v1;
err = c1 * c2 * (err1 * err1 + err2 * err2) / (b22 * b22);
}
SetBinError(coord,TMath::Sqrt(err));
}
}
delete [] coord;
fFilledBins = nFilledBins;
SetEntries(h1->GetEntries());
}
Bool_t THnSparse::CheckConsistency(const THnSparse *h, const char *tag) const
{
if (fNdimensions!=h->GetNdimensions()) {
Warning(tag,"Different number of dimensions, cannot carry out operation on the histograms");
return kFALSE;
}
for (Int_t dim = 0; dim < fNdimensions; dim++){
if (GetAxis(dim)->GetNbins()!=h->GetAxis(dim)->GetNbins()) {
Warning(tag,"Different number of bins on axis %i, cannot carry out operation on the histograms", dim);
return kFALSE;
}
}
return kTRUE;
}
void THnSparse::SetBinEdges(Int_t idim, const Double_t* bins)
{
TAxis* axis = (TAxis*) fAxes[idim];
axis->Set(axis->GetNbins(), bins);
}
void THnSparse::SetBinContent(const Int_t* coord, Double_t v)
{
GetCompactCoord()->SetCoord(coord);
Long_t bin = GetBinIndexForCurrentBin(kTRUE);
SetBinContent(bin, v);
}
void THnSparse::SetBinContent(Long64_t bin, Double_t v)
{
THnSparseArrayChunk* chunk = GetChunk(bin / fChunkSize);
chunk->fContent->SetAt(v, bin % fChunkSize);
++fEntries;
}
void THnSparse::SetBinError(const Int_t* coord, Double_t e)
{
GetCompactCoord()->SetCoord(coord);
Long_t bin = GetBinIndexForCurrentBin(kTRUE);
SetBinError(bin, e);
}
void THnSparse::SetBinError(Long64_t bin, Double_t e)
{
THnSparseArrayChunk* chunk = GetChunk(bin / fChunkSize);
if (!chunk->fSumw2 ) {
if (GetCalculateErrors()) {
Error("SetBinError", "GetCalculateErrors() logic error!");
}
Sumw2();
}
chunk->fSumw2->SetAt(e * e, bin % fChunkSize);
}
void THnSparse::Sumw2()
{
if (GetCalculateErrors()) return;
fTsumw2 = 0.;
TIter iChunk(&fBinContent);
THnSparseArrayChunk* chunk = 0;
while ((chunk = (THnSparseArrayChunk*) iChunk()))
chunk->Sumw2();
}
THnSparse* THnSparse::Rebin(Int_t group) const
{
Int_t* ngroup = new Int_t[GetNdimensions()];
for (Int_t d = 0; d < GetNdimensions(); ++d)
ngroup[d] = group;
THnSparse* ret = Rebin(ngroup);
delete [] ngroup;
return ret;
}
void THnSparse::SetTitle(const char *title)
{
fTitle = title;
fTitle.ReplaceAll("#;",2,"#semicolon",10);
Int_t endHistTitle = fTitle.First(';');
if (endHistTitle >= 0) {
Int_t posTitle = endHistTitle + 1;
Int_t lenTitle = fTitle.Length();
Int_t dim = 0;
while (posTitle > 0 && posTitle < lenTitle && dim < fNdimensions){
Int_t endTitle = fTitle.Index(";", posTitle);
TString axisTitle = fTitle(posTitle, endTitle - posTitle);
axisTitle.ReplaceAll("#semicolon", 10, ";", 1);
GetAxis(dim)->SetTitle(axisTitle);
dim++;
if (endTitle > 0)
posTitle = endTitle + 1;
else
posTitle = -1;
}
fTitle.Remove(endHistTitle, lenTitle - endHistTitle);
}
fTitle.ReplaceAll("#semicolon", 10, ";", 1);
}
THnSparse* THnSparse::Rebin(const Int_t* group) const
{
Int_t ndim = GetNdimensions();
TString name(GetName());
for (Int_t d = 0; d < ndim; ++d)
name += Form("_%d", group[d]);
TString title(GetTitle());
Ssiz_t posInsert = title.First(';');
if (posInsert == kNPOS) {
title += " rebin ";
for (Int_t d = 0; d < ndim; ++d)
title += Form("{%d}", group[d]);
} else {
for (Int_t d = ndim - 1; d >= 0; --d)
title.Insert(posInsert, Form("{%d}", group[d]));
title.Insert(posInsert, " rebin ");
}
TObjArray newaxes(ndim);
newaxes.SetOwner();
for (Int_t d = 0; d < ndim; ++d) {
newaxes.AddAt(GetAxis(d)->Clone(),d);
if (group[d] > 1) {
TAxis* newaxis = (TAxis*) newaxes.At(d);
Int_t newbins = (newaxis->GetNbins() + group[d] - 1) / group[d];
if (newaxis->GetXbins() && newaxis->GetXbins()->GetSize()) {
Double_t *edges = new Double_t[newbins + 1];
for (Int_t i = 0; i < newbins + 1; ++i)
if (group[d] * i <= newaxis->GetNbins())
edges[i] = newaxis->GetXbins()->At(group[d] * i);
else edges[i] = newaxis->GetXmax();
newaxis->Set(newbins, edges);
delete [] edges;
} else {
newaxis->Set(newbins, newaxis->GetXmin(), newaxis->GetXmax());
}
}
}
THnSparse* h = CloneEmpty(name.Data(), title.Data(), &newaxes, fChunkSize, kTRUE);
Bool_t haveErrors = GetCalculateErrors();
Bool_t wantErrors = haveErrors;
Int_t* bins = new Int_t[ndim];
Int_t* coord = new Int_t[fNdimensions];
memset(coord, 0, sizeof(Int_t) * fNdimensions);
Double_t err = 0.;
Double_t preverr = 0.;
Double_t v = 0.;
for (Long64_t i = 0; i < GetNbins(); ++i) {
v = GetBinContent(i, coord);
for (Int_t d = 0; d < ndim; ++d)
bins[d] = TMath::CeilNint( (double) coord[d]/group[d] );
if (wantErrors) {
if (haveErrors) {
err = GetBinError(i);
err *= err;
} else err = v;
preverr = h->GetBinError(bins);
h->SetBinError(bins, TMath::Sqrt(preverr * preverr + err));
}
h->AddBinContent(bins, v);
}
delete [] bins;
delete [] coord;
h->SetEntries(fEntries);
return h;
}
void THnSparse::Reset(Option_t * )
{
fFilledBins = 0;
fEntries = 0.;
fTsumw = 0.;
fTsumw2 = -1.;
fBins.Delete();
fBinsContinued.Clear();
fBinContent.Delete();
if (fIntegralStatus != kNoInt) {
delete [] fIntegral;
fIntegralStatus = kNoInt;
}
}
Double_t THnSparse::ComputeIntegral()
{
if (fIntegralStatus != kNoInt) {
delete [] fIntegral;
fIntegralStatus = kNoInt;
}
if (GetNbins() == 0) {
Error("ComputeIntegral", "The histogram must have at least one bin.");
return 0.;
}
fIntegral = new Double_t [GetNbins() + 1];
fIntegral[0] = 0.;
Int_t* coord = new Int_t[fNdimensions];
for (Long64_t i = 0; i < GetNbins(); ++i) {
Double_t v = GetBinContent(i, coord);
bool regularBin = true;
for (Int_t dim = 0; dim < fNdimensions; dim++)
if (coord[dim] < 1 || coord[dim] > GetAxis(dim)->GetNbins()) {
regularBin = false;
break;
}
if (!regularBin) v = 0.;
fIntegral[i + 1] = fIntegral[i] + v;
}
delete [] coord;
if (fIntegral[GetNbins()] == 0.) {
Error("ComputeIntegral", "No hits in regular bins (non over/underflow).");
delete [] fIntegral;
return 0.;
}
for (Long64_t i = 0; i <= GetNbins(); ++i)
fIntegral[i] = fIntegral[i] / fIntegral[GetNbins()];
fIntegralStatus = kValidInt;
return fIntegral[GetNbins()];
}
void THnSparse::PrintBin(Long64_t idx, Option_t* options) const
{
Int_t* coord = new Int_t[fNdimensions];
PrintBin(idx, coord, options);
delete [] coord;
}
Bool_t THnSparse::PrintBin(Long64_t idx, Int_t* bin, Option_t* options) const
{
Double_t v = -42;
if (idx == -1) {
idx = const_cast<THnSparse*>(this)->GetBin(bin, kFALSE);
v = GetBinContent(idx);
} else {
v = GetBinContent(idx, bin);
}
if (options && strchr(options, '0') && v == 0.) {
if (GetCalculateErrors()) {
if (GetBinError(idx) == 0.) {
return kFALSE;
}
} else {
return kFALSE;
}
}
TString coord;
for (Int_t dim = 0; dim < fNdimensions; ++dim) {
coord += bin[dim];
coord += ',';
}
coord.Remove(coord.Length() - 1);
if (GetCalculateErrors()) {
Double_t err = 0.;
if (idx != -1) {
err = GetBinError(idx);
}
Printf("Bin at (%s) = %g (+/- %g)", coord.Data(), v, err);
} else {
Printf("Bin at (%s) = %g", coord.Data(), v);
}
return kTRUE;
}
void THnSparse::PrintEntries(Long64_t from , Long64_t howmany ,
Option_t* options ) const
{
if (from < 0) from = 0;
if (howmany == -1) howmany = GetNbins();
Int_t* bin = new Int_t[fNdimensions];
if (options && (strchr(options, 'x') || strchr(options, 'X'))) {
Int_t* nbins = new Int_t[fNdimensions];
for (Int_t dim = fNdimensions - 1; dim >= 0; --dim) {
nbins[dim] = GetAxis(dim)->GetNbins();
bin[dim] = from % nbins[dim];
from /= nbins[dim];
}
for (Long64_t i = 0; i < howmany; ++i) {
if (!PrintBin(-1, bin, options))
++howmany;
++bin[fNdimensions - 1];
for (Int_t dim = fNdimensions - 1; dim >= 0; --dim) {
if (bin[dim] >= nbins[dim]) {
bin[dim] = 0;
if (dim > 0) {
++bin[dim - 1];
} else {
howmany = -1;
}
}
}
}
delete [] nbins;
} else {
for (Long64_t i = from; i < from + howmany; ++i) {
if (!PrintBin(i, bin, options))
++howmany;
}
}
delete [] bin;
}
void THnSparse::Print(Option_t* options) const
{
Bool_t optAxis = options && (strchr(options, 'A') || (strchr(options, 'a')));
Bool_t optMem = options && (strchr(options, 'M') || (strchr(options, 'm')));
Bool_t optStat = options && (strchr(options, 'S') || (strchr(options, 's')));
Bool_t optContent = options && (strchr(options, 'C') || (strchr(options, 'c')));
Printf("%s (*0x%lx): \"%s\" \"%s\"", IsA()->GetName(), (unsigned long)this, GetName(), GetTitle());
Printf(" %d dimensions, %g entries in %lld filled bins", GetNdimensions(), GetEntries(), GetNbins());
if (optAxis) {
for (Int_t dim = 0; dim < fNdimensions; ++dim) {
TAxis* axis = GetAxis(dim);
Printf(" axis %d \"%s\": %d bins (%g..%g), %s bin sizes", dim,
axis->GetTitle(), axis->GetNbins(), axis->GetXmin(), axis->GetXmax(),
(axis->GetXbins() ? "variable" : "fixed"));
}
}
if (optStat) {
Printf(" %s error calculation", (GetCalculateErrors() ? "with" : "without"));
if (GetCalculateErrors()) {
Printf(" Sum(w)=%g, Sum(w^2)=%g", GetSumw(), GetSumw2());
for (Int_t dim = 0; dim < fNdimensions; ++dim) {
Printf(" axis %d: Sum(w*x)=%g, Sum(w*x^2)=%g", dim, GetSumwx(dim), GetSumwx2(dim));
}
}
}
if (optMem) {
Printf(" coordinates stored in %d chunks of %d entries\n %g of bins filled using %g of memory compared to an array",
GetNChunks(), GetChunkSize(), GetSparseFractionBins(), GetSparseFractionMem());
}
if (optContent) {
Printf(" BIN CONTENT:");
PrintEntries(0, -1, options);
}
}