Reading text file and fit the plot

Hello experts,
I am not sure if this error related to root or C program.
Don’t understand my error.
What I wanted to do is,I have two txt files and need to create the following function and fit the plot.
rhoPiPi = |A * zOmnes00 + B * zOmnes11 |^2

//
//
//

#include "Omnes_fitting.hpp"
#include <TComplex.h>
#include <TRandom3.h>
#include <TH2D.h>
#include <TFile.h>
#include <TNtuple.h>
#include <TMath.h>
#include <TGraph.h>
#include <TCanvas.h>
#include <TH1D.h>


Double_t Omnes_fit(Double_t *par);
int main(){
   
    TLegend * legend=new TLegend();
    
    
    
  
    
//  rhoPiPi = |A * zOmnes00 + B * zOmnes11 |^2
    
    TFile *hFile=TFile::Open("plots_1.root");
    hFile->ls();
    TH1D * h_pion_invariant_mass_weight;
    TH1D * h_pion_invariant_mass_Stat_Syst;
    hFile->GetObject("h_pion_invariant_mass_weight", h_pion_invariant_mass_weight);
    hFile->GetObject("h_pion_invariant_mass_Stat_Syst", h_pion_invariant_mass_Stat_Syst);
    h_pion_invariant_mass_weight->SetLineColor(2);
    h_pion_invariant_mass_weight->SetMarkerColor(2);
    h_pion_invariant_mass_weight->SetMarkerStyle(kFullSquare);
    h_pion_invariant_mass_weight->Draw("E1");
    h_pion_invariant_mass_Stat_Syst->Draw("same E1");
    legend->AddEntry(h_pion_invariant_mass_weight,"Stat","EP");
    legend->AddEntry(h_pion_invariant_mass_Stat_Syst,"Stat+Sys","EP");
    legend->Draw();
    
    TF1 *omnes= new TF1("omnes", Omnes_fit,0.0,1.0,2);
    omnes->SetParameter(0,0.707);
    omnes->SetParameter(1,0.707);
    
    omnes->SetLineColor(4);
    omnes->Draw("sames");
    
    
    
    
    
    
}

Double_t Omnes_fit(Double_t *par){
    
    
    Double_t result=0.0;
    int mPts;
    
    const Int_t nPts = mPts;
     mPts=0;
   
    
    float  mass,re, im;
    
    
    TComplex zOmnes00[nPts],zOmnes11[nPts];
    Double_t  zOmnes11M[nPts],zOmnes00M[nPts],xOmnes11[nPts],xOmnes00[nPts],yOmnes11[nPts],yOmnes00[nPts];
    Double_t MassPiPi[nPts];
    
    char rhomeson[32] = "Omnes11.txt";
    FILE  * fOmnes;
    fOmnes=fopen(rhomeson,"r");
    char line[charLine],chars[80];
    //  Read Header lines
    fgets(line,charLine,fOmnes);
    //  How many data lines?
    fgets(line,charLine,fOmnes);
    sscanf(line,"%d", &mPts);
    // fgets(line,charLine,fOmnes);
    
    
    
    char Sigmameson[32] = "Omnes00KM.txt";
    FILE  * fOmnes1;
    fOmnes1=fopen(Sigmameson,"r");
    
    //  Read Header lines
    fgets(line,charLine,fOmnes1);
    //  How many data lines?
    fgets(line,charLine,fOmnes1);
    sscanf(line,"%d", &mPts);
   
    
    for (Int_t iPt=0; iPt< nPts; iPt++) {
        if(fgets(line,charLine,fOmnes)==NULL){
            printf("Error reading File %s line %d\n",
                   rhomeson, iPt+iHeader);
            continue;
        } else {
            sscanf(line,"%f %f %f", &mass,&re, &im);
            MassPiPi[iPt] = mass;
            xOmnes11[iPt]=re;
            yOmnes11[iPt]=im;
            zOmnes11[iPt] = TComplex(re,im);
            zOmnes11M[iPt]=sqrt(re*re+im*im);
            
        }
        
        
         mPts=0;
        if(fgets(line,charLine,fOmnes1)==NULL){
            printf("Error reading File %s line %d\n",
                   Sigmameson, iPt+iHeader);
            continue;
        } else {
            sscanf(line,"%f %f %f", &mass,&re, &im);
            xOmnes00[iPt]=re;
            yOmnes00[iPt]=im;
            zOmnes00[iPt] = TComplex(re,im);
            zOmnes00M[iPt]=sqrt(re*re+im*im);
            printf("xOmenes= %f \n", xOmnes00[iPt]);
            
              mPts++;
            
        }
        
        result = par[0]*zOmnes00M[iPt];
        result += par[1]*zOmnes11M[iPt];
        result=result* result;
        
    }
    fclose(fOmnes);
    fclose(fOmnes1);
    return mPts;
   return result;
}




this my error
root [0] .L Omnes_fitting.cpp
In file included from /Users/D/root-6-12-04-02/input_line_12:24:
In file included from /Users/D/root-6-12-04-02/etc/dictpch/allHeaders.h:774:
In file included from /Users/D/root-6-12-04-02/include/TMVA/CrossValidation.h:9:
In file included from /Users/D/root-6-12-04-02/include/TMultiGraph.h:26:
/Users/D/root-6-12-04-02/include/TF1.h:716:104: error: type ‘double (double )’ cannot be used prior to ‘::’ because it has no members
using Fnc_t = typename ROOT::Internal::GetFunctorType<decltype(ROOT::Internal::GetTheRightOp(&Func::operator()))>::type;
^
/Users/D/root-6-12-04-02/include/TF1.h:361:41: note: in instantiation of member function 'ROOT::Internal::TF1Builder<double (
)(double )>::Build’ requested here
ROOT::Internal::TF1Builder::Build(this, f);
^
/Users/D/Documents/cross_section/pipi_fitting/Omnes_fitting.cpp:43:21: note: in instantiation of function template specialization 'TF1::TF1<double (
)(double )>’ requested here
TF1 omnes= new TF1(“omnes”, Omnes_fit,0.0,1.0,2);
^
In file included from /Users/D/root-6-12-04-02/input_line_12:24:
In file included from /Users/D/root-6-12-04-02/etc/dictpch/allHeaders.h:774:
In file included from /Users/D/root-6-12-04-02/include/TMVA/CrossValidation.h:9:
In file included from /Users/D/root-6-12-04-02/include/TMultiGraph.h:26:
In file included from /Users/D/root-6-12-04-02/include/TF1.h:35:
/Users/D/root-6-12-04-02/include/Math/ParamFunctor.h:125:29: error: too many arguments to function call, expected 1, have 2
return (f)((T)x, (double
)p);
~~~~ ^~~~~~~~~~
/Users/D/root-6-12-04-02/include/Math/ParamFunctor.h:95:45: note: in instantiation of member function 'ROOT::Math::ParamFunctorHandler<ROOT::Math::ParamFunctorTempl, double (
)(double )>::FuncEvaluator<double
(
)(double ), int>::EvalConst’ requested here
return FuncEvaluator<Func, EvalType>::EvalConst(fFunc,x,p);
^
/Users/D/root-6-12-04-02/include/Math/ParamFunctor.h:73:4: note: in instantiation of member function 'ROOT::Math::ParamFunctorHandler<ROOT::Math::ParamFunctorTempl, double (
)(double )>::operator()’ requested here
ParamFunctorHandler(const Func & fun) : fFunc(fun) {}
^
/Users/D/root-6-12-04-02/include/Math/ParamFunctor.h:304:17: note: in instantiation of member function 'ROOT::Math::ParamFunctorHandler<ROOT::Math::ParamFunctorTempl, double (
)(double )>::ParamFunctorHandler’ requested
here
fImpl(new ParamFunctorHandler<ParamFunctorTempl,Func>(f) )
^
/Users/D/root-6-12-04-02/include/TF1.h:718:62: note: in instantiation of function template specialization 'ROOT::Math::ParamFunctorTempl::ParamFunctorTempl<double (
)(double )>’ requested here
f->fFunctor = new TF1::TF1FunctorPointerImpl<Fnc_t>(ROOT::Math::ParamFunctorTempl<Fnc_t>(func));
^
/Users/D/root-6-12-04-02/include/TF1.h:361:41: note: in instantiation of member function 'ROOT::Internal::TF1Builder<double (
)(double )>::Build’ requested here
ROOT::Internal::TF1Builder::Build(this, f);
^
/Users/D/Documents/cross_section/pipi_fitting/Omnes_fitting.cpp:43:21: note: in instantiation of function template specialization 'TF1::TF1<double (
)(double *)>’ requested here
TF1 omnes= new TF1(“omnes”, Omnes_fit,0.0,1.0,2);
^
In file included from /Users/D/root-6-12-04-02/input_line_12:24:
In file included from /Users/D/root-6-12-04-02/etc/dictpch/allHeaders.h:774:
In file included from /Users/D/root-6-12-04-02/include/TMVA/CrossValidation.h:9:
In file included from /Users/D/root-6-12-04-02/include/TMultiGraph.h:26:
In file included from /Users/D/root-6-12-04-02/include/TF1.h:35:
/Users/D/root-6-12-04-02/include/Math/ParamFunctor.h:121:25: error: too many arguments to function call, expected 1, have 2
return (*f)(x, p);
~~~~ ^
/Users/D/root-6-12-04-02/include/Math/ParamFunctor.h:91:45: note: in instantiation of member function 'ROOT::Math::ParamFunctorHandler<ROOT::Math::ParamFunctorTempl, double (
)(double )>::FuncEvaluator<double
(
)(double ), int>::Eval’ requested here
return FuncEvaluator<Func, EvalType>::Eval(fFunc,x,p);
^
/Users/D/root-6-12-04-02/include/Math/ParamFunctor.h:73:4: note: in instantiation of member function 'ROOT::Math::ParamFunctorHandler<ROOT::Math::ParamFunctorTempl, double (
)(double )>::operator()’ requested here
ParamFunctorHandler(const Func & fun) : fFunc(fun) {}
^
/Users/D/root-6-12-04-02/include/Math/ParamFunctor.h:304:17: note: in instantiation of member function 'ROOT::Math::ParamFunctorHandler<ROOT::Math::ParamFunctorTempl, double (
)(double )>::ParamFunctorHandler’ requested
here
fImpl(new ParamFunctorHandler<ParamFunctorTempl,Func>(f) )
^
/Users/D/root-6-12-04-02/include/TF1.h:718:62: note: in instantiation of function template specialization 'ROOT::Math::ParamFunctorTempl::ParamFunctorTempl<double (
)(double )>’ requested here
f->fFunctor = new TF1::TF1FunctorPointerImpl<Fnc_t>(ROOT::Math::ParamFunctorTempl<Fnc_t>(func));
^
/Users/D/root-6-12-04-02/include/TF1.h:361:41: note: in instantiation of member function 'ROOT::Internal::TF1Builder<double (
)(double )>::Build’ requested here
ROOT::Internal::TF1Builder::Build(this, f);
^
/Users/D/Documents/cross_section/pipi_fitting/Omnes_fitting.cpp:43:21: note: in instantiation of function template specialization 'TF1::TF1<double (
)(double *)>’ requested here
TF1 *omnes= new TF1(“omnes”, Omnes_fit,0.0,1.0,2);
^
root [1]

Any help would be greatly appreciated.

Thanks
Dil
Omnes_fitting.cpp (3.5 KB)
Omnes_fitting.hpp (236 Bytes)
Omnes00KM.txt (9.4 KB)
plots_1.root (695.2 KB)
Omnes11.txt (9.4 KB)

Should be

Double_t Omnes_fit(Double_t *x, Double_t *par){

See “Creating a TF1 with a User Function” on Chapter: FittingHistograms
Also, these returns? this won’t do what I guess you think

    return mPts;
    return result;

Thank you for the reply.That didn’t fix the issue.
Any example that uses txt files to create a function would help me.

Thanks
Dil