Saving characteristic of TGraph2D (like axis title)

Hi,
I would like to save TGraph2D objects on a TFile. But when some members of my TGraph2D are not saved. Specificaly title, axis specifications (axis title, title offset, color etc.).

In the TGraph2D defintion I see :

TH2D* fHistogram !2D histogram of z values linearly interpolated

And I think this is the cause of my troubles. fHistogram holds a lot specifications which interest me. But these specifications are not saved.

How can I restore easily my TGraph2D ?

I can save the fHistogram member myself, and call TGraph2D::SetHistogram() after having reading a TGraph object, but
- what is the cost in memory ?
- Is there anythings to do after and/or before TGraph2D::SetHistogram() ?

Thanks for your attention,

Pierre

Olivier will investigate this problem once back from holidays.

Rene

You said that the TGraph2D title is not saved, but the following example shows it is:

void graph2dsave()
{
   TCanvas *c = new TCanvas("c","Graph2D example",0,0,700,600);
   gfile = new TFile("graph2d.root","RECREATE","Graph2D file");
 
   Double_t x, y, z, P = 6.;
   Int_t np = 300;
 
   TGraph2D *dt = new TGraph2D();
   dt->SetTitle("a simple 2D graph");
 
   TRandom *r = new TRandom();
 
   for (Int_t N=0; N<np>Rndm(N))-P;
      y = 2*P*(r->Rndm(N))-P;
      z = (sin(x)/x)*(sin(y)/y)+0.2;
      dt->SetPoint(N,x,y,z);
   }
 
   dt->Draw("p0 tri");
 
   gfile->cd(); dt->Write();
}

execute the example and restart ROOT. Then do:

root [0] TFile g("graph2d.root");
root [1] Graph2D->Draw("tri")"

You’ll se that the title is the one set in the macro.

Hi,

thanks you for your help, I know the title of a TGraph2D is saved, but I want the axis titles to be saved too (with their offset, color …).

I send you an anormaly thing which appears when I try to do a dt->GetXaxis() after the TGraph2D is filled. In fact, if I doesn’t try to use GetXaxis(), there is no problems, but if I use GetXaxis() a “: problem setting view” appears. (I send 2 screen shoot which show that).

I don’t know if this is a problem which come from my installation, or if it is that I musn’t use GetXaxis() here.

Can you help me again ?

thanks a lot,
Strato




For TGraph2D the data member holding the underlaying histogram has been explicitely declared as not persistant in TGraph2D.h:

   TH2D       *fHistogram;   //!2D histogram of z values linearly interpolated

the character “!” starting the comment means that …

That’s not the case for TGraph.

So, for TGraph2D, all the attributes (like the axis titles) depending on the underlaying histogram (fHistogram) will not be saved. I guess the choice was made to not save this histogram because of size issues. This histogram can be quite big.

Hi,
thank you for replying so fast :slight_smile:

My original question was :

thanks again

The cost in memory should be close to a 2D matrix NPXxNPY. Where NPX and NPY are the number of bins along the X and Y axis.

There is nothing special to do after SetHistogram().