Plotting Error using TChain and Canvas->Divide(1,2)


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi experts, I’m using TChain to channel multiple .root files at once. The problem occurs when I try and plot.

If I do the normal

TChain ch(“TreeName”);
ch.(“file/path/*.root”)

Then try to plot using the following divided canvas:

TCanvas *c1 = new TCanvas(“c1”,“c1”,1000,1000);
c1-> Divide(1,2);
c1->cd(1);
ch.Draw(Plot1)

c1->cd(2);
ch.Draw(Plot2)

This method will allow me to plot2 on the second half canvas, but the first half of the canvas comes out blank? I feel like the ‘ch.Draw’ on the second half is overwriting the first, but I’m not sure how to fix it. I need to be able to plot both on the same canvas.

Thanks for the help.

I’m guessing that Plot1 and Plot2 are your plot commands (maybe you could post them)? Are you creating two different histograms in these commands or are you using two histograms that have been created before?

It seems to me like you are either using the same histogram name in both plot commands or you are not using a histogram name at all (which causes the default htemp to be used twice). This causes the second plot command to overwrite the first one.

1 Like

A small running reproducer macro would be useful to help you.

1 Like

Okay, yes. So when testing it, it works great for a plot like:

ch.Draw("mcRho", "(mcRho<15)&&(mcZ>-2&&mcZ<2)","");
ch.Draw("mcX:mcY>>h(1500,0,15,1500,-15,15)","(mcRho<15)&&(mcZ>--2&&mcZ<2),"COL4Z");

But once I add in the >>h(1500,0,15) to the first Plot, the first plot will no longer be created.

ch.Draw("mcRho>>h(1500,0,15)", "(mcRho<15)&&(mcZ>-2&&mcZ<2)","");
ch.Draw("mcX:mcY>>h(1500,0,15,1500,-15,15)","(mcRho<15)&&(mcZ>--2&&mcZ<2),"COL4Z");

This won’t work.

This is fine and I can work with it now, but why does adding that part overwrite it?

Thanks again.

You need to use two different names for the histograms, otherwise your second command overwrites the histogram h you’ve created with the first command. Something like this should work:

ch.Draw(“mcRho>>h1(1500,0,15)”, “(mcRho<15)&&(mcZ>-2&&mcZ<2)”,"");
ch.Draw(“mcX:mcY>>h2(1500,0,15,1500,-15,15)”,"(mcRho<15)&&(mcZ>–2&&mcZ<2),“COL4Z”);
1 Like

ah, yes, of course.
Thanks for your help.

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