Merging multiple Histogramms

Hello,

I am trying to merge multiple diagrams. To do this, I created a bunch of diagrams in a for loop and now I want to add each of these diagrams to a list, and then merge them. Like this:

TList *individualetaphi = new TList;
for (Int_t i = 6; i < 10; i++) {
  trackscanv->cd(i-5);
   // defining graphs, 0 = pt, 1 = nsigma, 2,3 = eta,phi
   TH1D* projection_p0 = (TH1D*) tracks[0]->Projection(0); // pt
   projection_p2_p3[i] = (TH2D*) tracks[0]->Projection(3,2); // eta vs phi - mb
   projection_p2_p3_trdmb[i] = (TH2D*) tracks[1]->Projection(3,2); // eta vs phi - trdmb

   //efficiency
   efficiency[i] = (TH2D*) projection_p2_p3[i]->Clone(Form("Efficiency EtaPhi %i Gev/c",i));
   efficiency[i]->Divide(projection_p2_p3_trdmb[i], projection_p2_p3[i]);

   //now add the individual pt bins again
   individualetaphi->Add(efficiency[i]);

}

TH2D *efficiency_corrected = (TH2D*) efficiency[6]->Clone("f");
efficiency_corrected->Reset();
efficiency_corrected->Merge(individualetaphi);

//drawing
TCanvas *trackscanvmerged = new TCanvas("trackscanvmerged","trackscanvmerged",900,900);
trackscanvmerged->Divide(2,1);
trackscanvmerged->cd(1);
efficiency_corrected->Draw();

However, when I do this I get the error message:

**warning:** **invalid memory pointer passed to a callee:**

TH2D *efficiency_corrected = (TH2D*) efficiency[6]->Clone("f");

There has to be a simple mistake that I am making. I would be very appreciative for help!

Hi @wfelix ,
the error seems to imply that efficiency[6] is not a valid object, but it’s impossible to say from just that snippet whether that’s the case or not.

You can debug this e.g. by running your macro as gdb --args root.exe -l -q macro.C+g and putting a breakpoint at macro.C:<linewitherror>.

Cheers,
Enrico