Hi,
I am working with a Tree that contains several properties of my particles, pT, energies, etc. creating a class from it, and working with the .C file.
I am trying to perform a chi2 minimization for each event of my Tree, where I need to minimize a function that looks like this:
chi2 = ( (e1k1)/sig1 )^2 + ( (e2k2)/sig2 )^2 + ((M  2k1k2*cost)/gam )^2,
where e1,e2, cost are measured valued that I can obtain from the Tree.
M, gam, sig1, sig2 are constant values defined inside my ::Loop(), and k1,k2 are the parameters I want to fit to make the chi2 as close to zero as possible.
The questions are:

First, I am not sure where should I be defining the fcn function. It doesnâ€™t let me do it inside the myclass::Loop, so up to now I have been doing it before the myclass:Loop function.

And second: I need to use some measured variables from the Tree to enter into the chi2 function and I donâ€™t know how to do it. I am just declaring the parameters to fit i.e. k1, and k2, but donâ€™t find a way to define e1,e2,cost.
Part of the code I have got up to now:
void fcn(int &npar, double *gin, double &f, double *par, int iflag)
{
// e1,e2,cost needed from Tree.
//M,gam,sig1,sig2 constants defined inside myclass:Loop.
double k1 = par[0];
double k2 = par[1];
double Mk12 = 2 * k1 * k2 * (1cost);
f = pow( (e1k1) / sig1 ,2) + pow( (e2k2) / sig2 ,2) + pow( (M Mk12)/gam ,2)
}
void myclass::Loop(){
if (fChain == 0) return;
Long64_t nentries = fChain>GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain>GetEntry(jentry); nbytes += nb;
double sig1=15., sig2=15., gam=2., M=100.;
double e1=jte[iq1]; //measured values from my Tree
double e2=jte[iq2];
double cost = jte[iq3];
TMinuit *gMinuit = new TMinuit(2);
gMinuit>SetFCN(fcn);
gMinuit>DefineParameter(0, "k1", e1 , 1., 0., 0.); //initial estimates equal to measured values
gMinuit>DefineParameter(1, "k2", e2 , 1., 0., 0.);
gMinuit>Command("MIGRAD");
double x,y,xerr,yerr;
gMinuit>GetParameter(0,x,xerr);
gMinuit>GetParameter(1,y,yerr);
printf("x: %+.7f + %.7f\n",x,xerr);
printf("y: %+.7f + %.7f\n",y,yerr);
}
}
And of course when I try to run this I get error like the following:
**error:** **use of undeclared identifier 'e1'**
Thanks for any help.
ROOT Version: 6.22/02
Built for macosx64 on Aug 17 2020, 12:46:52
From tags/v62202@v62202