Error with TGraph::SetTitle


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.26/00
Platform: arm64 apple m1
Compiler: xcode12


Dear expert,

when I run this macro without grms::SetTitle everything works.
If I define the name of each graph it gives me the error you see below.

Why does this happen?

    TCanvas *c2[M];
    TGraph *grms[M];
    for(int ttc=0; ttc<M; ttc++){
    c2[ttc] = new TCanvas( Form("c2_%d",ttc),Form("c2_%d",ttc));
    }
    for(int ttc=0; ttc<M; ttc++){
    grms[ttc]= new TGraph();
    for(int bbb=0; bbb<nt; bbb++){
    
    grms[ttc]->SetPoint(bbb, time[ttc][bbb], rms[ttc][bbb]);
    }
    grms[ttc]->SetName("RMS/t");
    //grms[ttc]->SetTitle("Graph RMS/t");    //this work fine but is generic
        grms[0]->SetTitle("Itot[uA]");
        grms[1]->SetTitle("Ie[uA]");
        grms[2]->SetTitle("Ih[uA]");
        grms[3]->SetTitle("Ieg[uA]");
        grms[4]->SetTitle("Ihg[uA]");
        grms[5]->SetTitle("BB[mV]");
        grms[6]->SetTitle("CSA[mV]");
        grms[7]->SetTitle("Charge[fC]");
        
        grms[ttc]->SetMarkerColor(4);
    grms[ttc]->SetMarkerStyle(21);
                c2[ttc]->cd();
                c2[ttc]->SetGrid();
                c2[ttc]->SetTicks();
                grms[ttc]->Draw();
    // use this methods
    grms[ttc]->GetXaxis()->SetTitle("time (ns)");
    grms[ttc]->GetYaxis()->SetTitle("rms");
        }

Problem is the “Break Segmentation Violation” ,there is only when naming curves.

Warning in <TCanvas::Constructor>: Deleting canvas with same name: c2_0
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c2_1
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c2_2
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c2_3
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c2_4
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c2_5
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c2_6
Warning in <TCanvas::Constructor>: Deleting canvas with same name: c2_7

 *** Break *** segmentation violation
 [/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/Users/roany/Downloads/landaulgad/exam5bc_C.so] graph(char const*) (no debug info)
[<unknown binary>] (no debug info)
[/Users/roany/Downloads/root2/lib/libCling.6.26.00.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)
[/Users/roany/Downloads/root2/lib/libCling.6.26.00.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/Users/roany/Downloads/root2/lib/libCling.6.26.00.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/Users/roany/Downloads/root2/lib/libCling.6.26.00.so] cling::Interpreter::process(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) (no debug info)
[/Users/roany/Downloads/root2/lib/libCling.6.26.00.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/Users/roany/Downloads/root2/lib/libCling.6.26.00.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)
[/Users/roany/Downloads/root2/lib/libCling.6.26.00.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)
[/Users/roany/Downloads/root2/lib/libRint.6.26.00.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/Users/roany/Downloads/root2/lib/libRint.6.26.00.so] TRint::HandleTermInput() (no debug info)
[/Users/roany/Downloads/root2/lib/libCore.6.26.00.so] TUnixSystem::CheckDescriptors() (no debug info)
[/Users/roany/Downloads/root2/lib/libCore.6.26.00.so] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)
[/Users/roany/Downloads/root2/lib/libCore.6.26.00.so] TSystem::InnerLoop() (no debug info)
[/Users/roany/Downloads/root2/lib/libCore.6.26.00.so] TSystem::Run() (no debug info)
[/Users/roany/Downloads/root2/lib/libCore.6.26.00.so] TApplication::Run(bool) (no debug info)
[/Users/roany/Downloads/root2/lib/libRint.6.26.00.so] TRint::Run(bool) (no debug info)
[/users/roany/downloads/root2/bin/root.exe] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)

thanks

It is because you give the same name to all the graphs.

1 Like

thanks, for answer me.
I should create 8 TCanvas?

You already create M canvases. The problem is you are trying to use SetName on graphs that you still have not created. Use a ‘good’ indentation on your code and it may be clearer to you.

thanks for answer me.


TCanvas *h2[M];
    TGraph *grms[M];
    for(int ttc=0; ttc<M; ttc++){
    h2[ttc] = new TCanvas( Form("h2_%d",ttc),Form("h2_%d",ttc));
    }
    for(int ttc=0; ttc<M; ttc++){
    //grms[ttc]= new TGraph();
        grms[0]=new TGraph();
        grms[1]=new TGraph();
        grms[2]=new TGraph();
        grms[3]=new TGraph();

        
        
    for(int bbb=0; bbb<nt; bbb++){
       
    grms[ttc]->SetPoint(bbb, time[ttc][bbb], rms[ttc][bbb]);
    }
    
        grms[0]->SetName("itot");
        grms[1]->SetName("ie");
        grms[2]->SetName("ih");
        grms[3]->SetName("ieg");
     
        
     grms[ttc]->SetLineStyle(1);
     grms[ttc]->SetLineWidth(5);
     grms[ttc]->SetLineColor(3);
     grms[ttc]->SetMarkerColor(2);
    
    grms[0]->SetTitle("Itot[uA]");
    grms[1]->SetTitle("Ie[uA]");
    grms[2]->SetTitle("Ih[uA]");
    grms[3]->SetTitle("Ieg[uA]");

   
    h2[ttc]->cd();
    h2[ttc]->SetGrid();
    h2[ttc]->SetTicks();
    grms[ttc]->Draw();
    grms[ttc]->GetXaxis()->SetTitle("time (ns)");
    grms[ttc]->GetYaxis()->SetTitle("rms");
        
        TFile *f1 = new TFile( "grms.root", "RECREATE" );
        f1->cd(); 
          
      
      for(int qq=0; qq<M; qq++){
          
          
          grms[qq]->Write();
          }
          
      f1->Close();
        

My question…

how to save all graph in one only Root file?

Create the TFile only one time, before the loop that creates the graphs (I’d say before even creating the canvases, in this case), and close it also once, outside.

1 Like