Problem with Root's TCanvas divisions on Mac


_ROOT Version: 6.16/00
Platform: MacOs Mojave 10.14.4
Compiler: Not Provided


I installed Root with Homebrew .
When I try to compile this macro

Double_t func1D(Double_t *x, Double_t *par){

Double_t xx=x[0];
Double_t val=TMath::Abs(par[0]*sin(par[1]*xx)/xx);
return val;
}

Double_t func2D(Double_t *x, Double_t *par){

Double_t xx=x[0];
Double_t yy=x[1];
Double_t val=par[0]*TMath::Exp(-((xx-par[1])*(xx-par[1])+(yy-par[1])*(yy-par[1])) /(2.*par[2]*par[2]));
return val;
}

void makeFunctions(){
//
//very simple TF1 and TF2 examples
//
//

TF1 *f1 = new TF1("func1D",func1D,0,10,2);
f1->SetParameters(2,1);
TCanvas *c1 = new TCanvas("c1","TF1 example",200,10,600,400);
c1->Divide(1,2); // divisioni asse x e divisoini asse y
//print out some values;
cout << "the value of f1(1.) is:" << f1->Eval(1.)<< endl;
//can get its derivative
cout << "the value of f1'(1.) is:" << f1->Derivative(1.)<< endl;
c1->cd(1);
f1->Draw();
c1->cd(2);
f1->DrawDerivative();


TF2 *f2 = new TF2("f2",func2D,-3,3,-3,3,3);
f2->SetParameters(100,0,1);
TCanvas *c2 = new TCanvas("c2","TF2 example",200,10,600,400);
  cout << "the value of f2(1.,2.) is:" << f2->Eval(1.,2.) << endl;
f2->Draw("surf");
}

I get these errors :

`*** Break *** segmentation violation`

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

[&lt;unknown binary&gt;] (no debug info)

[&lt;unknown binary&gt;] (no debug info)

[&lt;unknown binary&gt;] (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCling.so] cling::Interpreter::process(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, cling::Value*, cling::Transaction**, bool) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&amp;, cling::Value*, bool) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&amp;, cling::Value*) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libRint.so] TRint::HandleTermInput() (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCore.so] TUnixSystem::CheckDescriptors() (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCore.so] TSystem::InnerLoop() (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCore.so] TSystem::Run() (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libCore.so] TApplication::Run(bool) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/lib/root/libRint.so] TRint::Run(bool) (no debug info)

[/usr/local/Cellar/root/6.16.00_1/bin/root.exe] main (no debug info)

[/usr/lib/system/libdyld.dylib] start (no debug info)

[&lt;unknown binary&gt;] (no debug info)


**************************************

After this just one Canvas appears with just one function . The second one doesn't even do that .

Any suggestions ? Am I missing some libraries?

Try with:

TF1 *f1 = new TF1("f1", func1D, 1e-6, 10., 2);

I think there is a problem in DrawDerivative. I am looking at it.

I tried but nothing is changing . However I ran the code with a linux operative system and it works . I think it is an OS’s problem .

I think it is a problem that occours when you try to draw 2 functions on the same Canvas . I am not so sure however .

As I said there is a problem in DrawDerivative. Looking at it

Instead of DrawDerivative do:

   TGraph *gr = new TGraph(f1, "d");
   gr->Draw("al");

Yes, now, in this way, it’s working. Do you know which is the problem and if there is a way to solve it ?
Because on a linux machine the code I posted worked fine

I will try on a linux machine. The code of DrawDerivative is a bit too comple. it should be the last two lines I sent you.

Have you found out if it was a bug of root for the Os Version downloaded via HomeBrew ?

Yes it is something in the code of root which can be simplified. Meanwhile you can you the work around I gave you. It does exactly the same thing.

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