Combining histograms

Hello, people
I just want to put two histograms in one, and I am struggling with this since I am new to root. The histograms have the same name but they are in different root files. I am trying the code below:

TFile *f2=new TFile("higgspythiaM.root");
TH1::AddDirectory(kFALSE);
TCanvas *c1=new TCanvas("c1","Combines Histograms",500,500,500,500);
TH1F *h_common=(TH1F*)f1->Get("hist_transversemass_HiggsLeptonic");
TH1F *h_second = (TH1F*)f2->Get("hist_transversemass_HiggsLeptonic");
 h_common->Draw();
h_second->Draw("SAME");

After entering the line: h_common->Draw(); I get this message: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
What does that mean?
Thank you, have a nice day!

_ROOT Version: ROOT 6.14.04
_Platform: Ubuntu 18.04.2 LTS
_Compiler:g++


f1->ls();
f2->ls();
2 Likes

It means that the histogram didn’t exist in the file. When you ask for it with Get, the file returns a nullptr, as there’s no other way to signify that such a histogram doesn’t exist in the file. As @Wile_E_Coyote already mentioned, list the contents of the files to find out the correct name.

1 Like

Thank you both of you! Actually I didn’t include the “;1” after the name of the histograms!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.