Superimpose Historgrams

I know this is a bit remedial subject but help would be greatly appreciated. So I have number of historgrams that I would like to superimpose on each other. I thought such would be sufficient:


TFile *f1 = TFile::Open("Histogram1.root");
TFile *f2 = TFile::Open("Histogram2.root");
TH1 *h1 = (TH1*)f1->Get("histo1");
TH1 *h2 = (TH1*)f2->Get("histo2");
h1->Draw();
h2.Draw("same");

In general I have 2 histograms, the 1st i want to make the base and I would like to superimpose the other on it. Is there some thing that I am doing wrong here? Any Suggestions? Thanks

Cheers,
Edwin Baldelomar

Hi,

How does your example ‘fail’?

Philippe.

Hi Philippe,

Thank you for your quick response. THe error is as follows:

root [16] h1->Draw();
Error: illegal pointer to class object h1 0x0 1211  (tmpfile):1:
*** Interpreter error recovered ***
root [17] h2.Draw("same");
Error: illegal pointer to class object h2 0x0 1211  (tmpfile):1:
*** Interpreter error recovered ***

I’m not sure what this means. Thank You for your help.

Cheers,
Edwin Baldelomar

Hi,

Those error indicates that you have not been successful in retrieving the histogram from the file (and/or you close the files). Try:

TFile *f1 = TFile::Open("Histogram1.root"); if (f1==0) { cout << "Humm no file named Histogram1.root in the current directory.\n"; } else { TH1 *h1; f1->GetObject("histo1",h1); if (h1==0) { cout << "humm no histo named histo1 in the file!\nlet's see what's in it:\n"; f1->ls(); } }
Cheers,
Philippe.