Errors in Double_t fit(Double_t x Double_t par) user-defined fit function

I am trying to fit a function to a TH1D histogram. I get a lot of errors, and the fit does not work:

 Error: ^ Illegal operator for real number fittest.cxx:3:
 Error: void type variable can not be declared
 Error in <ROOT::Math::FitConfig::CreateMinimizer>: Could not create the Minuit2 minimizer
 Error in <ROOT::Math::Fitter::FitFCN>: Minimizer cannot be created

I don’t understand where my code is going wrong. I’m sorry if I’m missing something really basic, I’m still kind of a beginner at C++ Root.

Double_t myfit(Double_t*x, Double_t*par)
    Double_t fitval=(6*par[0]^2+par[1]*par[2]^2)^(1/2)*TMath::Exp(-0.5*((x[0]-par[3]-par[1]*par[4])^2/(par[0]^2+par[1]*par[2]^2)));
    return fitval;
void fittest()
    TCanvas *c1=new TCanvas("c1","Test Fit",100,4500);
    TFile *f=new TFile("aptenergytest.root");"APT_Photon");
    TH1D *hpx=Pedestals->ProjectionX();

   TF1 *func=new TF1("fit",myfit,100,4500,5);


Wikipedia -> Operators in C and C++ -> C++ Language -> Basics of C++ -> Operators -> Reference -> C library -> cmath header

ROOT TMath Namespace Reference

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