Merge Canvases from root files

Hi all,

I saved canvases in root file.
Now I would like to merge. e.g., two canvases from two root.file.
I easily access and draw each canvas separately. But how to merge?
In the code it was not like simple histogram which was saved to canvas and that canvas to root.

Can I merge for example 2 canvases in that case? Or I need to have histograms first and plot 2 hists in new canvas? But If yes, I don’t know how to take histograms from the canvases.

Thanks for the help

This is code I use:

TFile *f = new TFile("Canvas100.root");                                                                                                                     
 f.ls();                                                                                                                                                                                                     
 TCanvas *c = (TCanvas *)f->Get("MyCanvas100");                                                                                                              
 c->GetListOfPrimitives()->Print();                                                                                                                                                                          
 // Draw canvas                                                                                                                                                                                                                                                                                                                                                                                               
 c->cd();                                                                                                                                                                                                    
 c->Draw();                     

Below is the print from the canvas:

//==================================================================
TFile**		Canvas100.root	
 TFile*		Canvas100.root	
  KEY: TCanvas	MyCanvas100;1	MYCANVASTEXT
Collection name='TList', class='TList', size=8
 TFrame  X1=-6.105600 Y1=0.000000 X2=-4.694400 Y2=0.000000 FillStyle=1001
 x[0]=0, y[0]=3.02582e-07
x[1]=1, y[1]=2.67667e-07
x[2]=2, y[2]=2.25879e-07
x[3]=3, y[3]=2.06253e-07
x[4]=4, y[4]=1.86729e-07
x[5]=5, y[5]=1.81377e-07
x[6]=6, y[6]=1.81285e-07
x[7]=7, y[7]=2.03612e-07
x[8]=8, y[8]=2.35267e-07
x[9]=9, y[9]=2.75253e-07
x[10]=10, y[10]=3.0666e-07
x[11]=11, y[11]=3.64956e-07
x[12]=12, y[12]=4.06995e-07
 TLine  X1=-6.100000 Y1=0.000000 X2=-4.699713 Y2=0.000000 Style=2
 TLine  X1=-5.400000 Y1=0.000000 X2=-5.400000 Y2=0.002119 Style=2
 x[0]=6, y[0]=1.81285e-07
 x[0]=6, y[0]=1.81285e-07
 x[0]=6, y[0]=1.81285e-07
 TPaveText  X1=-6.304615 Y1=0.000000 X2=-5.038154 Y2=0.000000 FillStyle=1001
 Collection name='TList', class='TList', size=1
  Text  X=0.000000 Y=0.000000 Text=MYCANVASTEXT Font=0 Size=0.000000 Color=0 Align=0

What do you mean by “merge” exactly ? Plotting the two canvases on to of each other ?
The list of primitives in a canvas is a TLIst. You can always scan le list of primitive of one canvas and put the primitive in the other … but the result is not guarantee to produce a clear picture if the primitives’ coordinates are not in the range of the canvas you merge into

1 Like

I have 2 separate canvases with one line each. And would like to have 1canvas with 2 lines together.

You can call GetListOfPrimitives on the canvas you want to take the line from. Scan the returned TList to retrieve the line and put it in the other canvas.

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