Cannot interact with a TCanvas created by a function

Hi all,

I have a simple function DrawGraph which I use to create a multigraph but when I use this function in the main programm and run it I can’t interact with the canvas created. The displayed content is correct but nothing is clickable. It worked before for a week or so and now it doen’t anymore. Maybe something changed in the rootrc on LXplus, I don’t know :

DrawGraph(d_time,Model_k,"Kirchner",Model_p,"ISOLDE") ;

cout << "Restart fit with new parameters ? " << endl ;
cin >> answer ;

if (answer == "y") {
	restart = true ;

	cout << "Run             " 
             << "Norm            " 
             << "Effusion [s-1]  " 
             << "Diffusion [s-1] " 
	     << "S^2             " 
             << endl ;

	for(int unsigned i=0 ; i < ResultsTable.size() ; i++) {

	printf("%-15.0f %-15.4f %-15.4f %-15.4f %-15.4f  \n",ResultsTable[i][0],ResultsTable[i][1],ResultsTable[i][2],ResultsTable[i][3],ResultsTable[i][4]) ;		
		}

	AskKirchnerParm(g_alpha, g_nu, g_mu) ;
	}
else 
	restart = false ;

first_run = false  ;

}
void DrawGraph(vector<Double_t> x, vector<Double_t> y1, char* name1, vector<Double_t> y2,char* name2){

TCanvas *c2 = new TCanvas("c2","Data plot",200,10,700,500);
TMultiGraph *mg = new TMultiGraph();
TLegend *legend = new TLegend(1,0.6,0.6,0.8);

c2->SetLogy(1);
c2->SetLogx(1);
 
mg->SetTitle("Kirchner and Isolde model vs. time");
 
TGraph *gr1 = new TGraph(x.size(),&x[0],&y1[0]);
gr1->SetMarkerColor(kBlue);
gr1->SetMarkerStyle(20); 
mg->Add(gr1);
 
TGraph *gr2 = new TGraph(x.size(),&x[0],&y2[0]);
gr2->SetMarkerColor(kRed);
gr2->SetMarkerStyle(20); 
mg->Add(gr2);
  
legend->AddEntry(gr1,name1) ;
legend->AddEntry(gr2,name2);
 
mg->Draw("ap") ;
legend->Draw();

c2->Update();
} 

create and run a TApplication object or better run your script from the ROOT prompt.

Rene

Hi,

Thank you I will try with a TApplication because it doesn’t work any better from the root prompt.

If it does not run from the ROOT prompt it will not run from your main program.
Send teh shortest possible running script reproducing your problem.

Rene

Hey,

Here it is. I can manipulate the plot only when the script exits and root returns to prompt, which means answering ‘no’ to the question, but this question depends on what the user can see from the plot …
fitRelease.cpp (9.96 KB)

Hi,

This statement:cin >> answer ;
is blocking the event handling loop, hence the frozen canvas. See possible solutions in this thread

Cheers, Bertrand.

Hi again,
Thanks ! I used the Timer trick and it worked, yet it doesn’t under Windows but I usually don’t use it so it doesn’t really matter.

Thanks again.