Regarding the fit of the data

suppose i want the power fit of the form: y=Ax^c,where i want to know c from the fit,i.e how its varying with x.
here in my case,its dev=A*(rigidity)^c. my command is written as:

{TNtuple calls("calls","calls","dev:rigidity");
calls.ReadFile("ev7.dat");

TCanvas *alpha1 = new TCanvas("alpha1","canvas");
calls.Draw("dev:rigidity");

alpha1->SetFillColor(42);

auto z1 = new TF1("dev", "[A]*rigidity^[c]");

alpha1->Fit(z1);

}

now,what’s wrong in this,can you correct that pls? since i din’t find it.

Hi,

you do not fit a TCanvas but rather a TGraph or a histogram.
What is needed here is a loop over the TNtuple and the fill of a graph and the fit I think.

Cheers,
D

maybe although i don’t get that fully,but one thing i need to know is that,what’s the command to be given for doing the power fitting as of the above form for the given data file? i mean could you describe that commands ? so that i can get some idea.

   auto nentries = calls.GetEntries();
   TGraph yourgraph(nentries);
   for (Int_t i=0;i<nentries;i++) {
     calls.GetEntry(i);
     auto dev_rig = calls.GetArgs();
     yourgraph.SetPoint(i, dev_rig[0], dev_rig[1]);
  }
  yourgraph.Fit(z1);

For further clarifications, please read cerefully
https://root.cern.ch/doc/master/classTNtuple.html
and
https://root.cern.ch/doc/master/group__tutorial__fit.html

{
  TGraph *g = new TGraph("ev7.dat");
  TF1 *f = new TF1("f", "[0] * x**[1]");
  f->SetParNames("A", "c");
  f->SetParameters(1., 1.); // initial values for the fit
  g->Fit(f);
  g->Draw("A*");
}

I tried it but its showing abnormal termination of minimization maybe due to the initial values which we put here, i don’t wanna put initial values,its just i want to see how’s my y axis value varies with the power of rigidity(i.e. x axis value) with best fit.any suggestions?

In ROOT, you are expected to provide reasonable initial values of all fit parameters (except for some “built-in” functions, like “gaus”, for which the standard fit procedure can automatically “guess” them). Get used to it.

Note: if you need to swap “X” and “Y” columns, you can try:

TGraph *gYX = new TGraph("ev7.dat");
TGraph *g = new TGraph(gYX->GetN(), gYX->GetY(), gYX->GetX());
delete gYX; // no longer needed

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