Fit a TMultiGraph by loading a .root file into a script

Hey,

I have a .root file with with two plots using TMultiGraph. How can I write a script to load the root file and fit a function on each of the graphs?

TFile *f = new TFile("some_root_file.root"); TF1 f1("log10 fit","[0]*pow(log10(x),2)+[1]*log10(x)+[2]",0,10e+04); // this is the function I want to fit f1.SetLineColor(kRed); f1.SetLineStyle(2);

So that is what I have so far, I’m quite new to ROOT so I’m not sure how to explicitly select one of the graphs and use that fit (I would like to use the fit for both graphs on the canvas)

To get the individuals graphs from a TMultiGraph you should do a loop similar to:

   TList* grlist;
   grlist = mg->GetListOfGraphs();
   printf("This multi-graph contains %d graphs\n",grlist->GetSize());
   TIter next(grlist);
   TObject *obj;
   TGraph *gr;
  
   while ((obj = next())) {
  	gr=(TGraph*)obj;
...
   }