Error's fitting parameters are the same, status:failed

Hi, I tried to excuse this program, but it doesn’t fitting and doesn’t drawing the function. Parameters fitting errors are the same, and status from Hesse is failed. Anyone can help?

Here are the data and the program I wrote. What’s wrong with it?

0.0 5.0
0.2969 12.11
0.6533 18.65
1.164 24.96
1.532 29.21
2.013 34.01
2.433 37.89
2.915 42.08
3.354 45.57
3.791 48.85
4.302 52.52
4.757 55.58
5.23 58.68
5.688 61.58
6.167 63.77
6.632 66.55
7.08 69.1
7.616 72.12
8.088 74.73
8.551 77.22
9.057 79.87
9.514 82.19
9.993 84.54
10.5 87.56
10.99 89.97
#include <fstream>
#include <iostream>
#include <TGraphErrors.h>
#include <TAxis.h>
#include <TH1F.h>
#include <TCanvas.h>
#include <TF1.h>
#include <iomanip>
#include <TMath.h>
#include "TFile.h"
#include "TStyle.h"
using namespace std;

void Pranalisi (){
ifstream parInput("Histo_1_phe_gain24_1mv_15Oms.txt");
    
    static const int nBins = 25;
    float V[nBins];  float I[nBins];
    int i;
    if (parInput.is_open()) {
      while ( parInput.good() ) {
          for (i = 0; i< nBins; i++){
        parInput >> V[i] >> I[i];
        cout << "bin " << i << " " << V[i] << " " << I[i] << endl;
        if (i == nBins-1) break;
      }
      parInput.close();
    }
}
    
    float sV[nBins];
    float sI[nBins];
    float R[nBins];
    float sR[nBins];
    float P[nBins];
    float sP[nBins];
    
    
    for (int j=0; j<nBins; j++){
        
        if (V[j]<1) sV[j] = V[j]*0.01 + 5e-4;
        else if (V[j]<10) sV[j] = V[j]*0.01 + 5e-3;
        else sV[j] = V[j]*0.01 + 5e-2;
        
        sI[j] = I[j]*0.005 + 5e-2;
        R[j] = (V[j]/I[j])*1000;
        sR[j] = pow(pow((1000/I[j])*sV[j], 2) + pow((V[j]*1000*sI[j])/(I[j]*I[j]),2), 0.5);
        
        P[j] = V[j] * I[j]/1000;
        sP[j] = pow(pow(I[j]*sV[j]/1000,2) + pow(V[j]*sI[j]/1000,2),0.5);
        
        
        cout << "Misura numero " << j+1 << ":\t V = (" << V[j] << " +- " << sV[j] << ") V, :\t i = (" << I[j] << " +- " << sI[j] << ") mA,:\t R = (" << R[j] << " +- " << sR[j] << ") Ohm,:\t P = (" << P[j] << " +- " << sP[j] << ") W." << endl;
        
    }
    //Disegno P(R) conv
    TCanvas *cPRconv1 = new TCanvas("cPRconv1","P(R)conv",200,10,600,400);
    cPRconv1->SetFillColor(0);
    cPRconv1->cd();
    TGraphErrors *gPRconv1 = new TGraphErrors(nBins,R,P,sR,sP);
    gPRconv1->SetMarkerSize(0.6);
    gPRconv1->SetMarkerStyle(22);
    gPRconv1->SetTitle("P(R)conv");
    gPRconv1->GetXaxis()->SetTitle("R [Ohm]");
    gPRconv1->GetYaxis()->SetTitle("P [Watt]");
    gPRconv1->Draw("AP");

    //Fit P(R) conv
    TF1 *PRconv = new TF1("PRconv","[0]*pow(x,[1])+[2]*pow(x,[3])+[4]",50,125);
    PRconv->SetParameter(0,1.21590e+02);
    PRconv->SetParameter(1,6.00411e+00);
    PRconv->SetParameter(2,1.21590e+02);
    PRconv->SetParameter(3,1.12272e+02);
    PRconv->SetParameter(4,1.21590e+02);
    PRconv->SetParNames("a","q","b","q/4","c");
    PRconv->SetLineColor(6);
    gPRconv1->Fit(PRconv,"WQRN");
    gPRconv1->Fit(PRconv,"Q");
    gPRconv1->Fit(PRconv,"RM+");
  
    
    
    cout << "Chi^2:" << PRconv->GetChisquare() << ", number of DoF: " << PRconv->GetNDF() << " (Probability: " << PRconv->GetProb() << ")."  << endl;
    
    
    
    
    
}

Sorry for not uploading the files. forum’s rules doesn’t allow me.
Thanks for help.

Schermata 2022-12-13 alle 17.30.12

The fitting results

Hi,

Can you post the full log of Minuit ? Maybe some parameters are 100% correlated ?
A suspicious thing is that the chi2 function value is 0.

Lorenzo

Hi, how can I find the full log?
Thanks for help,

Costa

Hi,
Instead of using the fit option "Q", use the option "V" and please send me the output you get on the screen. You can re-direct the output in a text file by doing this if you are running from the ROOT prompt or by using the tee command if you are running from a Unix terminal.

Lorenzo

Hi,
That’s the output. I saved it in a .txt file, but I just copy-pasted the output in the file, I hope it’s readable.
I tried to use TFile and TTree class but I wasn’t really able to implement the coding lines in the link to my program (sorry I’m a real beginner in this).

Thanks,
Costa


outlog.txt (7.6 KB)

If you can help me in getting the output: what I do wrong?

myt-scan.txt (449 Bytes)

Hi,
Thank you for the log. I see from the output that the fit fails, I think because the initial parameters are too far way from the solution. Can you try fitting with better initial parameters ?

Lorenzo

Hi,
thank you for help, I resolved it. The problem was right the initial parameters. I resolved it not setting them, setting only the parameter I was sure the value.

Thanks again,
Costabile

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