Creating histo from data stored in different files

I want to create histograms from trees of the same tipe, and to compare results I would like to create an histogram of difference. But this code doesn’t seem to work.

[code]TCanvas ci;
TH2I* h_is3= new TH2I(“h_is3”,“difference”,7,2,9,12,5,17);
ci->Divide(2,1);
ci->cd(1)->Divide(1,2);

TFile f = TFile::Open(“firstsim.root”);
TH2I
h_is1= new TH2I(“h_is1”," first",7,2,9,12,5,17);
ci->cd(1)->cd(1);
DoPET_ion->Draw(“Na:Nz>>h_is1”);
h_is3=(TH2I*)gROOT->Get(“h_is3”);
DoPET_ion->Draw(“Na:Nz>>h_is3”);
h_is1->Draw(“lego2Z”);

TFile g = TFile::Open(“secondsim.root”);
TH2I
h_is2= new TH2I(“h_is2”," second",7,2,9,12,5,17);
ci->cd(1)->cd(2);
DoPET_ion->Draw(“Na:Nz>>h_is2”);
h_is3=(TH2I*)gROOT->Get(“h_is3”);
DoPET_ion->Draw(“Na:Nz>>+h_is3”,"(1==1)*(-1));
//to set a negative weight
h_is2->Draw(“lego2Z”);

ci->cd(2);
h_is3=(TH2I*)gROOT->Get(“h_is3”);
h_is3->Draw(“lego2Z”);[/code]

Can someone explain me why h_is3 is always empty?[/code]

Do something like

[code]TCanvas ci;
ci->Divide(2,1);
ci->cd(1)->Divide(1,2);

TFile *f1 = TFile::Open(“firstsim.root”);
TTree DoPET_ion1 = (TTree)f1->Get(“DoPET_ion”);

TFile f2 = TFile::Open(“secondsim.root”);
TTree DoPET_ion12 = (TTree)f2->Get(“DoPET_ion”);
gROOT->cd();
TH2I
h_is3= new TH2I(“h_is3”,“difference”,7,2,9,12,5,17);
TH2I* h_is2= new TH2I(“h_is2”," second",7,2,9,12,5,17);
TH2I* h_is1= new TH2I(“h_is1”," first",7,2,9,12,5,17);
ci->cd(1)->cd(1);
DoPET_ion1->Draw(“Na:Nz>>h_is1”);
DoPET_ion1->Draw(“Na:Nz>>h_is3”);
h_is1->Draw(“lego2Z”);

ci->cd(1)->cd(2);
DoPET_ion2->Draw(“Na:Nz>>h_is2”);
DoPET_ion2->Draw(“Na:Nz>>+h_is3”,"(1==1)*(-1));
//to set a negative weight
h_is2->Draw(“lego2Z”);

ci->cd(2);
h_is3->Draw(“lego2Z”);
[/code]

I Strongly suggest to read the two pages of the chapter about Object ownership in the Users Guide

Rene