How to fit a vector on a graph

Hi all,

I created a function which returns to vector. I read a data in to graph. Then, I need to fit that function on to a data.

Basically, I want to fit the Stopping Power Function onto a Stopping Power Data.

I attach the user-defined function here. In that function, only the vector parameters are changing depending on the kinetic energy of an electron. size is the number of kinetic energies I read from a file. The rest are just constant values.

vector <double> StoppingPower_Electron( double N_medium, double Z_medium, double MEP_medium, double RME, int size, vector<double> Beta, vector <double>LorentzFactor){ 

    vector <double> StoppingPower2 ; 

    for (int i=0; i< size ; i++){
        StoppingPower2.push_back( FourPiRsquare * RME* N_Si * Z_Si*(1./pow(Beta[i],2.))*
                                (log(Beta[i]*LorentzFactor[i]*sqrt(LorentzFactor[i]-1.)*RME /MEP_medium) + ((1.0/(2.0*pow(LorentzFactor[i],2.)) )*
                                    ((pow(LorentzFactor[i]-1, 2.)/8.0)+1.0 -
                                     (log(2.)*(pow(LorentzFactor[i],2.)+(2.*LorentzFactor[i])-1.))))  )  ) ;
        
    }
    return StoppingPower2;
}

I am just stuck what to write on TF1 as a function.

  //Choose the right function to fit on a data
    TF1*f1 = new TF1("f1", ?????? , Xmin , Xmax); 
    f1->Draw();
    gr1->Fit("f1");
    gr1->Draw("AP");

How should I construct the ??? part.

Cheers.

There are a few options on how to define your own functions, just choose what works for you:
https://root.cern/doc/master/classTF1.html

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