Fitting data points with error function

Hello,

I’m having trouble fitting an error function to my plotted data points on a histogram. I’ve attempted the following:

      // Make a TTree from the data:
      TTree *T = new TTree("ntuple","csv file data");
      Long64_t nlines = T->ReadFile(TString::Format("%sdata%d.csv",dir.Data(), i),"a:b:c:d:e");
      printf(" found %lld points\n",nlines);

      // Develop the histogram:
      TH1F *H = new TH1F("H", "b vs a; a; b", 100000, -0.00001, 0.00005);

      // Draw the histogram from Tree:
      T->Draw("a>>H","b","hist p");
      
      // To see marker style/size/color options, go to: https://root.cern.ch/doc/master/classTAttMarker.html.
      H->SetMarkerStyle(kFullDotSmall);
      H->SetTitle("b vs a");
      
      // TF1 *f1 = new TF1("f1","TMath::Erf(x)",-0.00005,0.00005);
      TF1 *f1 = new TF1("f1","[0]*TMath::Erf((x-[1])/[2])",-0.00005,0.00005);
      H->Fit("f1");

      
      H->Draw("hist p");
     
      
      gSystem->ProcessEvents();
      TImage *img = TImage::Create();
      img->FromPad(c);

      // Save the histograms as .png images individually:
      img->WriteImage(TString::Format("data%d.png",i));
      

      
      
      T->Write();
      H->Write();

That which is above is a small bit of my attempt at creating a histogram from a tree. I was hoping someone could help me with fitting, as it is not showing up on my histogram.

Also, if anyone has any suggestions as to how I could improve the code, I would be extremely grateful!

Thank you!

May be setting some initial values for the parameters will help.

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