Fitting non-equidistant bins histogram

Dear All, We have a problem to fit a non-equidistant histogram (in root file Counting.root here attached). The macro root file to do that is Counting.root also attached.

The histogram had been created, in another macro, s non-equidistant bins histogram as:
new TH1F(“Counting”,“Countingw”,NP-1,xx); where NP=150, xx[NP] is array of neutron energy, as in the attached file: .

The fit not working except at the end of the histogram. We also tried Tgraph but we have the same thing.


E_150.txt (1.8 KB)
Counting.root (4.5 KB)
Counting.C (1.8 KB)

Thank you, Rachid


_

_ROOT Version: v6-24-02
_Platform: Ubuntu 20.04.6 LTS
_Compiler: gcc version 9.4.0


Dear @rayad ,

Thanks for reaching out to the forum! Maybe @couet can help with your issue.

Cheers,
Vincenzo

Thank you Vicenzo for your answer.
Is there any thoughts about this issue, we really need to solve it to finish our results. The fitted function is needed .

Rachid

Your macro gives me a slithly diffrent plot. but still the fits does not appear to be correct. I am looking at it.

It seems pol3 works better:

void Counting() {
   char title1[255],title2[255],line[255];
   int i,j;
   char title[255],rootname[255];
   auto c1 = new TCanvas();

   c1->SetLogx();
   c1->SetFillColor(33);
   c1->SetFrameFillColor(41);
   c1->SetGrid();
   gStyle->SetOptFit(0);
   gStyle->SetOptStat(0);

   TFile *rootfile = new TFile("Counting.root");

   gStyle->SetOptStat(0);
   gStyle->SetTitleY(1.0); //title Y location
   gStyle->SetTitleH(0.1); //title height

   int ih;
   float myhmax;

   TH1F *counth = (TH1F *) rootfile->Get("Countingw");

   counth->SetLineStyle(20);
   counth->SetLineWidth(2);
   counth->SetLineColor(1);

   Float_t *bins = counth->GetArray();

   float minf=0,maxf=1.0e6;
   auto fitfunc = new TF1("fitfunc","pol3",minf,maxf); // Create the fit function

   counth->SetXTitle("Incident Neutron Energy(MeV)");
   counth->SetYTitle("Counts/cm^2");
   counth->SetMarkerColor(1);
   counth->SetMarkerStyle(20);
   counth->SetMarkerSize(0.7);
   counth->SetOption("P");
   counth->SetLineColor(1);
   counth->Fit("fitfunc","RQ"); // Fit histogram

   c1->SaveAs("Counting.pdf");
}