Convert canvas to histogram in the same plot

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

Hi Expert,

I sent three message but I don’t receive any reply! I hope that you see my problem.

I want to convert 2 canvas to 2 histograms and put them in the same plot .
This is my code:

   TFile f1("acceptboostedZp1.root","read");
   TCanvas c1 = (TCanvas)f1.Get("cacc");
   TH1F h = (TH1F)c1->GetPrimitive("hr_be_copy");

   TFile f2("acceptboostedZp.root","read");
   TCanvas c2 = (TCanvas)f2.Get("cacc");
   TH1F h1;
   TIter next(l);
   //h1 = (TH1F)c2->GetPrimitive("hr_be_copy");
   TCanvas c3;


But when I compile the code I have got the following break segmentation and give me just one plot
ERrot message:

*** Break *** segmentation violation

There was a crash.
This is the entire stack trace of all threads:

#0 0x00007f5fe298795c in __libc_waitpid (pid=4687, stat_loc=stat_loc
entry=0x7fff1451cc80, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:31
#1 0x00007f5fe2909232 in do_system (line=) at …/sysdeps/posix/system.c:148
#2 0x00007f5fe363e5c3 in TUnixSystem::StackTrace() () from /home/souad/Downloads/root/lib/
#3 0x00007f5fe36402cc in TUnixSystem::DispatchSignals(ESignals) () from /home/souad/Downloads/root/lib/
#5 __memmove_ssse3_back () at …/sysdeps/x86_64/multiarch/memcpy-ssse3-back.S:2683
#6 0x00007f5fe35b3ae2 in TString::Replace(int, int, char const*, int) () from /home/souad/Downloads/root/lib/
#7 0x00007f5fe37fd608 in G__G__Base2_10_0_15(G__value*, char const*, G__param*, int) () from /home/souad/Downloads/root/lib/
#8 0x00007f5fe1f8f8cd in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /home/souad/Downloads/root/lib/
#9 0x00007f5fe2033797 in G__execute_call () from /home/souad/Downloads/root/lib/
#10 0x00007f5fe2033b55 in G__call_cppfunc () from /home/souad/Downloads/root/lib/
#11 0x00007f5fe20130c7 in G__interpret_func () from /home/souad/Downloads/root/lib/
#12 0x00007f5fe20009f1 in G__getfunction () from /home/souad/Downloads/root/lib/
#13 0x00007f5fe20e6e05 in G__getstructmem(int, G__FastAllocString&, char*, int, char*, int*, G__var_array*, int) () from /home/souad/Downloads/root/lib/
#14 0x00007f5fe20de33a in G__getvariable () from /home/souad/Downloads/root/lib/
#15 0x00007f5fe1fdaaa9 in G__getitem () from /home/souad/Downloads/root/lib/
#16 0x00007f5fe1fe0425 in G__getexpr () from /home/souad/Downloads/root/lib/
#17 0x00007f5fe20625f3 in G__exec_statement () from /home/souad/Downloads/root/lib/
#18 0x00007f5fe201462c in G__interpret_func () from /home/souad/Downloads/root/lib/
#19 0x00007f5fe2000a4f in G__getfunction () from /home/souad/Downloads/root/lib/
#20 0x00007f5fe1fdafb6 in G__getitem () from /home/souad/Downloads/root/lib/
#21 0x00007f5fe1fe0425 in G__getexpr () from /home/souad/Downloads/root/lib/
#22 0x00007f5fe1febcfb in G__calc_internal () from /home/souad/Downloads/root/lib/
#23 0x00007f5fe206fe5f in G__process_cmd () from /home/souad/Downloads/root/lib/
#24 0x00007f5fe3602130 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/souad/Downloads/root/lib/
#25 0x00007f5fe35fe7cb in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/souad/Downloads/root/lib/
#26 0x00007f5fe356c08c in TApplication::ExecuteFile(char const*, int*, bool) () from /home/souad/Downloads/root/lib/
#27 0x00007f5fe356b5c0 in TApplication::ProcessLine(char const*, bool, int*) () from /home/souad/Downloads/root/lib/
#28 0x00007f5fe31b8239 in TRint::HandleTermInput() () from /home/souad/Downloads/root/lib/
#29 0x00007f5fe363fa95 in TUnixSystem::CheckDescriptors() () from /home/souad/Downloads/root/lib/
#30 0x00007f5fe36405ba in TUnixSystem::DispatchOneEvent(bool) () from /home/souad/Downloads/root/lib/
#31 0x00007f5fe35c3536 in TSystem::InnerLoop() () from /home/souad/Downloads/root/lib/
#32 0x00007f5fe35c4140 in TSystem::Run() () from /home/souad/Downloads/root/lib/
#33 0x00007f5fe35697bf in TApplication::Run(bool) () from /home/souad/Downloads/root/lib/
#34 0x00007f5fe31b945e in TRint::Run(bool) () from /home/souad/Downloads/root/lib/
#35 0x0000000000400fdc in main ()
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
#5 __memmove_ssse3_back () at …/sysdeps/x86_64/multiarch/memcpy-ssse3-back.S:2683
#6 0x00007f5fe35b3ae2 in TString::Replace(int, int, char const*, int) () from /home/souad/Downloads/root/lib/

Root > Function macro_canvas() busy flag cleared

Can Someone please help me to fix this error.

Please can someone help me

Can you post the root file used by this macro ?

Hi couet,

Thanks for your reply!
please find in attached the macro.

macro.c (1.2 KB)

This macro is using two root files. can you provide them ?

Please find below the outputs:

acceptboostedZp.root (8.5 KB)
acceptboostedZp1.root (8.5 KB)

void macro()
   TFile *f1 = new TFile("acceptboostedZp1.root");
   TCanvas *c1 = (TCanvas*)f1->Get("cacc");
   TH1F *h1 = (TH1F*)c1->GetPrimitive("hr_be_copy");

   TFile f2("acceptboostedZp.root");
   TCanvas *c2 = (TCanvas*)f2.Get("cacc");
   TH1F *h2;
   TList* l = c2-> GetListOfPrimitives();
   TIter next(l);
   TObject *obj;
   while ((obj=next())) {
      if (obj->InheritsFrom("TH1")) {
         // obj->Draw();
         h2 = (TH1F*)obj;
   TCanvas *C = new TCanvas();

Hi couet thanks it worked

1 Like

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