4 pads in the same canvas


ROOT Version: 6.14.00
Platform: Ubuntu18
Compiler: Not Provided


Hello,

I have a macro that creates four different canvas, now I need a macro that displays this four into the same canvas, my attempt was:

void pads()
{
  
   
   TFile *fm = new TFile("four.root");
   TCanvas *p1 =  (TCanvas *)fm->Get("c1");
   TCanvas *p2 = (TCanvas *)fm->Get("c1_n2");
   TCanvas *p3 = (TCanvas *)fm->Get("c1_n3");
   TCanvas *p4 = (TCanvas *)fm->Get("c1_n4");
   TCanvas *C = new TCanvas();
   C->Divide(2,2);
   C->cd(1);
   p1->DrawClonePad();
   C->cd(2);
   p2->DrawClonePad();
  C->cd(3);
  p3->DrawClonePad();
  C->cd(4);
  p4->DrawClonePad();
   
  
}

Then I get nothing in the new canvas, how can I fix it?

Thanks in advance
Regards

Hi,
can you try to use just DrawClone() or Draw()

Cheers,
Stefano

I try Draw(); and I get this:
Warning in TFile::Init: file four.root probably not closed, trying to recover
Info in TFile::Recover: four.root, recovered key TCanvas:c1 at address 214
Info in TFile::Recover: four.root, recovered key TCanvas:c1_n2 at address 3353
Info in TFile::Recover: four.root, recovered key TCanvas:c1_n3 at address 6400
Info in TFile::Recover: four.root, recovered key TCanvas:c1_n4 at address 9567
Warning in TFile::Init: successfully recovered 4 keys

*** Break *** segmentation violation

Thnks

It seems to me that your macro should work fine.

In the “pads” function, try to use (this may remove the “segmentation violation”):

TCanvas *C = new TCanvas("C_four", "C_four");

Looking at the error from “Draw”, it seems to me that your “four.root” is broken (was not closed properly) and so your canvases are not properly stored.

Here is a reproducer which works fine.

void fourpads(){
   auto c1 = new TCanvas(); c1->DrawFrame(0.,0.,1.,1.);
   auto c2 = new TCanvas(); c2->DrawFrame(0.,0.,2.,2.);
   auto c3 = new TCanvas(); c3->DrawFrame(0.,0.,3.,3.);
   auto c4 = new TCanvas(); c4->DrawFrame(0.,0.,4.,4.);

   auto FourPads = new TCanvas("FourPads","FourPads");
   FourPads->Divide(2,2);
   FourPads->cd(1) ; c1->DrawClonePad();
   FourPads->cd(2) ; c2->DrawClonePad();
   FourPads->cd(3) ; c3->DrawClonePad();
   FourPads->cd(4) ; c4->DrawClonePad();
}

It works, thank you!

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