Save axis with THStack

Hi all,

in a script I create and save a large number of THStacks into a root file. Unfortunately the axes of the THStacks are not saved as they are with the histograms. When drawing, I have to add the axis titles later on by hand. Example:

{
  plot1 = new TH1F("plot1","",50,0,1);
  plot2 = new TH1F("plot2","",50,0,1);
  plot1->Fill( 0.3 );
  plot2->Fill( 0.7 );

  stack = new THStack("stack","");
  stack->Add( plot1 );
  stack->Add( plot2 );

  file = new TFile( "scratch.root", "recreate" );
  file->WriteTObject( stack );

  canvas = new TCanvas( "canvas", "" );

  stack->Draw();
  stack->GetXaxis()->SetTitle( "p_{T} [GeV]" );
  stack->GetXaxis()->DrawClone();
  stack->Draw();

  file->WriteTObject( canvas );
}

Is there a workaroud to save the information with the THStack? This bites me whenever I want to change something by hand form a TBrowser. Thanks in advance.

Cheers
Jan

Jan,

If you simply want to set the x or/and y axis title, you can specify
them in the stack title (see TH1 constructors)

stack = new THStack("stack","main title;p_{T} [GeV];y title"); when doing

stack->Draw(); the x and y axis titles will be automatically set.

Note that the same is true for a TH1 or TH2 or TH3

  Rene

Hi Rene,

thanks a lot, that works for me!

Cheers
Jan