Minimize using Minuit and measured values from a Tree

Hi,
The number of entries is not too large and you can put them in memory. This will make the computation of your chi2 function much faster.
Suppose your variables are "e1" and "e2". You can do:

Long64_t nentries = fChain->GetEntriesFast();
fChain->Draw("e1:e2"); 
std::vector<double> e1(fChain->GetV1(), fChain->GetV1()+nentries); 
std::vector<double> e2(fChain->GetV1(), fChain->GetV1()+nentries); 
auto myFCN = [&](const double * par) {
    double chi2 = 0;  
    for (int i = 0; i < nentries; i++) {
       double k1 = par[0];
      double k2 = par[1];
     chi2 += pow( (e1[i]-k1) / sig1 ,2) + pow( (e2[i]-k2) / sig2 ,2);
 } 
 return chi2; 
};
ROOT::Math::Functor f(myFCN,2); // 2 is the number of dimension of the FCN 

and use f later as in the tutorial example to minimise the function.

Lorenzo

1 Like