Project

General

Profile

Using TMinuit in an Analysis Module

Example taken from GapWidth_module.cc

Ensure these two lines are in your modules CMakeFile:

${ROOT_MINUIT}
${ROOT_MINUIT2}

Create your local functions in an appropriate namespace, the format of the 'minuitFunction' cannot be changed for TMinuit to interpret it correctly.

namespace GapWidth {
class GapWidth;
double xextrap(double z) {
if (track1grad <= 0) return fabs((track1x - (track1grad)*(minz + z)) - track2x);
else return fabs((track1x + (track1grad)*(minz + z)) - track2x);
}
void minuitFunctionx(int& nDim, double* gout, double& result, double par[], int flg){
result = xextrap(par[0]);
}
}

Use TMinuit inside the Analyze() portion of your code

When instantiating a TMinuit, the int tells it the max no of parameters. This example is 1D, hence 1 parameter.
SetPrintLevel tells TMinuit not to output anything to the terminal. If higher verbosity is needed look at TMinuit in the ROOT users guide.
DefineParameter takes: parameter no, parameter name, initial value, initial error, lower limit, upper limit.
Migrad is the name of the minimising function used in this example. This can be changed as needed, documented in the ROOT users guide.
GetParameter performs the minimisation. It takes: parameter number, initial value, initial error.

double error = 0.01;
TMinuit* mingen = new TMinuit(1);
mingen->SetFCN(minuitFunctionx);
mingen->SetPrintLevel(1);
mingen
>DefineParameter(0,"gap extension", 20, 0.001, -100, 100);
mingen
>Migrad();
mingen->GetParameter(0, z, error);

ROOT TMinuit Users Guide