SetPalette not working for TH2 in TFiles

Hi all,

I was trying to save some TH2s in a TFile. In order to make them nice, I decided to make some changes to gStyle (SetPalette(1), SetOptStat(000000000)). To apply this new style I use UseCurrentStyle().

{ TFile *f = TFile::Open("file.root", "RECREATE"); TH2D *h = new TH2D("hist","testhist",100, -3, 3, 100, -3, 3); h->FillRandom("gaus", 1000); h->SetOption("COLZ"); gStyle->SetPalette(1); gStyle->SetOptStat(000000000); h->UseCurrentStyle(); h->Write(); f->Close(); }

When I open the root-file and the TH2 from the ROOT Browser I get a plot without StatBox (as expected) but without the chosen colour Palette (not expected).
Does anyone know why this is and how I could change it?

Thanks for your help.



The TStyle is a global object not attached to any particular object. In particular the color attributes are identified by a color index, not a color value (in rgb, hls,etc). Only the color index is saved with the objects.
You must save the TStyle or better reexecute the script setting the style in the following session.