How to add 2 different(bins) histograms

void add_his(){

    TCanvas *c1 = new TCanvas("c1","add_2his",10,10,800,800);
    TFile *f0 = new TFile("HEPData-ins1471838-v1-root.root","READ");
    TH1F *h_1=(TH1F*)f0->Get("Table 1/Hist1D_y1;1");
    TH1F *h_2=(TH1F*)f0->Get("Table 11/Hist1D_y1;1");

    h_1->Add(h_2); //this line have error nfo in <TH1F::Add>: Attempt to add histograms with different number of bins - trying to use TH1::Merge
// Error in <Merge>: Cannot merge histograms - limits are inconsistent:  first: Hist1D_y1 (38, 0.000000, 12.000000), second: Hist1D_y1 (16, 0.400000, 8.000000)
    h_2->Draw();
}

Welcome to the ROOT Forum!
As the message says TH1F::Add() requires that both histograms have the same limits. Make sure your histograms have the same limits. Or try to use TH1F::Merge()

how to make 2 different histograms same limits ? is it possible? I don’t know that and Merge() have some additional error.

I see you didn’t create the histograms yourself. In this case, maybe @moneta has a solution

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