Hi,
I attached below a modified version of your code. (Remember to put you code between two ``` in this way will appear highlited).
there are 3 main point
- I added two
;
after the opening of the files. - When you use Get() to get the histogram recast as a TH1D and not a TCanvas, otherwise you cannot the TH1D methods.
- the Draw is made using the TH1D pointer and not the name of the histogram in the file.
void macro()
{
TFile *f1 = TFile::Open("first.root");
TH1D *h1= (TH1D*)f1->Get("h1");
h1->Draw("hist l");
h1->SetLineWidth(3);
h1->SetLineColor(2);
TFile *f2 = TFile::Open("second.root");
TH1D *h2 = (TH1D*)f2->Get("h1");
h2->SetLineWidth(2);
h2->SetLineColor(4);
h2->Draw("hist l same");
}