Problem extracting TH2D from file

Hi

I am trying to read several TH2D from a file and simply put it on a canvas like

[code]cont Int_t CutN = 8;

TH2D *test[CutN];

TCanvas *c1= new TCanvas(“c1”,“2D hists”,600,600);

c1->Divide(3,3);

    TString fileName = "NTuple.root";
    TFile *file = TFile::Open(fileName);

    if (!file) abort();

    char tt[100];
     file->cd("mutau");

      for (int i=0;i<CutN;i++){

      sprintf(tt,"%s%i","channel/met",i);
      test[i] = (TH2D*) file->Get(tt);
      c1->cd(i+1);
      test[i]->Draw("colz");
    }
      [/code]

but this gives me an error

Error: illegal pointer to class object test 0x0 1539 Extract.C

Thanks

Alex

This error means that the histogram does not exist in your file.
Try: file->GetObject(tt, test[i]); c1->cd(i+1); if (test[i]) test[i]->Draw("colz"); else std::cout << "Warning: could not retrieve " << tt << std::endl;