Simple macro loading histograms crash

Dear ROOTers,

I have a simple macro (ROOT5.26), which simply loops on files, loads one histogram per file and plot them,
but this one has two curious problems:

  1. when plotting the histogram I get a blank canvas, I can look at the plot only if I save it and open with with ghostview e.g.
  2. when setting the property of the histograms (color…) it gives out a segmentation violation

here is my macro

void kinplots()
{
  gStyle->SetPalette(1);
  gStyle->SetPaintTextFormat("5.1f");
  gROOT->SetStyle("Plain");


  TH1F* h[11]; 
  int M0, M12, A0, TanBeta;  
  int index = 0;

  ifstream f( "ListOfParameterPoints_mSUGRA.txt" );
  while( f >> M0 >> M12 >> A0 >> TanBeta ){

    TString link = Form( "%i_%i_%i_%i", M0, M12, A0, TanBeta );

    TString w = link + "/2jets.root";
    TFile file ( w );
    h[index] = (TH1F*) file.Get("h_cutflow_cumeff");

   index++;
  }
  f.close();

  h[1]->SetLineColor(2);
  h[2]->SetLineColor(4);
  h[3]->SetLineColor(6);
  h[4]->SetLineColor(8);
  h[5]->SetLineColor(94);

  h[0]->SetStats(0);
  h[0]->SetYTitle("Effiency");
  h[0]->SetTitle("M_{0}=500, M_{1/2}=500");
  h[0]->GetYaxis()->SetLabelSize(0.03);

  h[0]->Draw();
  for( int i = 1; i < 6; i++ ) h[i]->Draw("same");

return;
}

I cannot find what I do wrong,
thanks in advance,

cheers,
Xavier

Hi Xavier,

Try to add h[index]->SetDirectory(0);in the loop, or add

TH1::AddDirectory(kFALSE); at the top of your script. And read the chapter about Object Ownership in the Users Guide… :wink:

Cheers, Bertrand.