Compress 2D histogram?

Hello ROOTers,

I am using a TH2* histogram in ROOT that contains 6108192 = 491520 bins. They are data members of my class and because of the number of bins, these histograms tend to get huge in terms of memory. Is there a way to compress a histogram? Do we have some TObject called TCompress?

Thank you!
Marco

Have a look at THNsparse

Rene

Okay, this is indeed very useful and will save me some memory if I can put it to the correct use. Thanks. However, I have problem, that I think can be fixed. I just don’t know how.

In my macro I want to store the THnSparse in some file. (This is why I wanted to compress the information in the first place. The file has to be small.) This is done by making the THnSparse a datamember of my class and filling it in some other function. However, it seems I cannot store my THnSparse as a (global) data member of my class. So, let me show you the code.

The class in my macro.

[code]//=========================================================
ClassName::ClassName():TObject(){
//=========================================================
// Constructor. Sets values to data members.
//=========================================================

// DEFAULT CONSTRUCTOR
[…]

Int_t bins[5] = {20,6,10,32,256};
Double_t xmin[5] = {0.,0.,0.,0.,0.};
Double_t xmax[5] = {20,6,10,32,256};
THnSparseI fTest(“test”,“test”,5,bins,xmin,xmax);

[…]
} // ClassName::ClassName:TObject[/code]

Header file.

[..] #include <THnSparse.h> [..] class ClassName:public TObject{ [..] protected: THnSparseI fTest; [..] }

So, if I now try to use the THnSparse in some class function, it doesn’t work. The object exists, but it has 0 dimensions and it doesn’t save my data. Does anyone see what I am doing wrong?

Ah, also -this is I think related to it- when I try to save the THnSparse to a file, it doesn’t work. In ROOT:

root [0] Int_t bins[5]          = {20,6,10,32,256};
root [1] Double_t xmin[5]       = {0.,0.,0.,0.,0.};
root [2] Double_t xmax[5]       = {20,6,10,32,256};
root [3] THnSparseI fTest("test","test",5,bins,xmin,xmax);
root [4] TFile *f = TFile::Open("file.root","recreate");
root [5] f->WriteObjectAny(&fTest,"THnSparse","histo")
Warning in <TKey::TKey>: since THnSparse has no public constructor
        which can be called without argument, objects of this class
        can not be read with the current library. You will need to
        add a default constructor before attempting to read it.

Hi,

just use fTest.Write() or specify the correct class name to WriteObjectAny (THnSparseI). Many THnSparses have been saved and read before :slight_smile:

Are you sure you want ints as bin content counters (THnSparseI)?

Cheers, Axel.