Extracting Data from TMultiGraph Object

Hi everyone,

I have been trying to extract data from a TMultiGraph object saved in a root file. I can print all of the data points out to the terminal using object->GetListOfGraphs()->Print(), but unfortunately I need the data to be stored in an array so that it can be replotted in a 2D histogram. I have been referring to the root forum posts here: Fit a TMultiGraph by loading a .root file into a script and here: How to get point values from TMultiGraph? to be able to at least print the data points one graph at a time, and then store them in an array. Using those examples, I have created some code reproduced below,

TFile *file = new TFile("myFile.root", "READ");
gDirectory->cd("Summary");
TMultiGraph *pkpos;
gDirectory->GetObject("myGraph",pkpos);

TList* grlist;
grlist = pkpos->GetListOfGraphs();
TIter next(grlist);
TObject *obj;
TGraph *gr;
  
while ((obj == next())) {
	gr = (TGraph*)obj;
	const int N_points = gr->GetN();
	double x, y;
	for(int i=0; i < N_points; i++){
		gr->GetPoint(i, x, y);  
		cout << x << y <<endl;
	}
}

but each time I run this, it gives the error

ROOT_prompt_10:1:16: error: reference to 'next' is ambiguous
while ((obj == next())) {
               ^
ROOT_prompt_7:1:7: note: candidate found by name lookup is 'next'
TIter next(grlist);
      ^

Is there something that is incorrect that I am missing? Is there another way to extract data from a TMultiGraph?

Thank you,

Stephen


ROOT Version: 6.14/00

Platform: MacOS High Sierra, v.10.13.4

Compiler: gcc version 5.1.0


Hi,
I’m not sure why next should be ambiguous in this context, but can you try giving that variable a less generic name?

Cheers,
Enrico

Hi @eguiraud,

Thank you! That worked.

Best,

Stephen

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