Draw histos from different rootfiles in one canvas' pad

Hello rooters!!!

I am trying to draw on the same sub_canvas two different histos, coming from two different rootfiles.
I am using

[code]TFile *f1 = TFile::Open(“run169_processed.root”);
TTree *MyTree1;
f1->GetObject(“clu_mm2X”, MyTree1);
if (!MyTree1) { std::cout << “Warning: clu_mm2X TTree NOT found!” << std::endl; return; }

TFile *f1_2 = TFile::Open("run197_processed.root");
TTree *MyTree1_2;
f1_2->GetObject("clu_mm2X", MyTree1_2);
if (!MyTree1_2) { std::cout << "Warning: clu_mm2X TTree NOT found!" << std::endl; return; }

TCanvas *c = new TCanvas(“c”, “cluster number”);
c->SetFillColor(kYellow-6);//change canvas’ color
c->Divide(2,3);//divide canvas in a 2-column and 3-row multipad

c_3->cd();//another way to move around pads
c_3->SetFillColor(kAzure+1);
c_3->SetFrameFillColor(10);
c_3->SetBorderMode(1);
c_3->SetBorderSize(2);

//fill histograms with color

gStyle->SetHistFillColor(8);
MyTree1->UseCurrentStyle();

//generate and fill cl_cluster TTree variable. The histo will be named h1

MyTree1->Draw("cl_first_timebin>>h1");
MyTree1_2->Draw("cl_first_timebin>>h1_2","same");
h1_2->SetFillColor(5);
h1->SetTitle("V_{mesh}=480V");
h1->SetAxisRange(-2,12,"X");
//h1->SetAxisRange(0,1800,"Y");
h1->Draw();
h1->Fit("gaus","W",NULL,2,10);
h1->GetFunction("gaus")->SetLineColor(kRed);
//h1->Fit("gaus","W",NULL,1,3000);
//h1->GetFunction("gaus")->SetLineColor(kRed);

c->Modified(); c->Update();

[/code]

but it’s not working.

Any ideas?
Thank you in advance!

MyTree1_2->Draw(“cl_first_timebin>>h1_2”, “”, “same”);

Thank you for your reply!!!

The canvas is popping up but I can’t see the second histo.
I tried to change the color using

but I still can’t see it.
I checked if there’s sth wrong in the root file, but there isn’t.
The weird thing is that the second histo has much more entries so it cannot be “hiding” somewhere beneath the first one!

I also tried

MyTree1->Draw("cl_first_timebin>>h1"); c->Modified(); c->Update(); MyTree1_2->Draw("cl_first_timebin>>h1_2", "", "SAME"); h1_2->SetFillColor(5);

but it’s not working either…

MyTree1_2->Draw(“cl_first_timebin>>h1_2”, “”, “LF2 SAME”);
http://root.cern.ch/root/html/THistPainter.html

BTW. Looking again at the source code in your first post I can see “h1->Draw();” near its end -> this will destroy the previous canvas’es contents -> your “h1_2” will be gone -> try “h1->Draw(“SAME”);” instead.

Now I know what I was doing wrong!!!
After MyTree1_2->Draw("cl_first_timebin>>h1_2", "", "SAME");
I was using h1->Draw();.

Now it is OK.

BONUS: I didn’t want to use the stats box(the one with # of entries) so I tried

and it worked!!! :smiley:

Thank you very much Pepe for your support!!!

Sth else: When histos are printed apart from legend, I want to change plot’s title without using Text.
The default title is first histo’s title. How can I edit that?

I tried

TLegend *legend = new TLegend(0.55,0.65,0.76,0.82); legend->AddEntry(h1,"Point 1","f1"); legend->AddEntry(h2,"Point 2","f2"); legend->Draw();

it is working, but I don’t want to mess up legend and histo’s title…

http://root.cern.ch/drupal/faq#n91
http://root.cern.ch/drupal/faq#n93