Write a superimposed histogram to root file

Hi Everybody,

if I need to write a histogram to a root file I do something like this

TFile f(“histos.root”,“new”);
TH1F *h1;
h1->Fill(somedata);
h1->Write();
f.Close();
But what do I do if I want to superimpose two histograms and then write them to the root file…

Thanks for your help.

do:

TFile f("histos.root","new"); TH1F *h1, *h2; h1->Fill(somedata); h2->Fill(somedata); h1->Write(); h2->Write(); f.Close();

Rene

HI Rene,

Thanks for the fast reply.
I have tried your suggestion and that results in two plots for each of the histogram. What
I am trying to do is get the two histograms superimposed on each other on the same plot.

Thanks again for all your help,

Could you post the shortest possible script illustrating what you are attempting to do?

Rene

Hi .
It would go something like this.
TFile f(“histos.root”,“new”);
TH1F *h1, *h2;
h1->Fill(somedata);
h2->Fill(somedata);
h1->Draw();
h2->Draw(“same”);
h2->Write();//Write the superimposed histos.
f.Close();

Thanks,

My guess is that you want to save the canvas, ie

TCanvas *c1 = new TCanvas("c1"); TH1F *h1, *h2; h1->Fill(somedata); h2->Fill(somedata); h1->Draw(); h2->Draw("same"); c1->Print("amelie.root");
then in a separate session, do something like

root > TFile *f = new TFile("amelie.root"); root > c1->Draw();
Rene

It worked.

Thanks a million,