forked from GooFit/GooFit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FitManagerMinuit3.cc
53 lines (43 loc) · 1.46 KB
/
FitManagerMinuit3.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
PdfBase* pdfPointer;
int numPars = 0;
vector<Variable*> vars;
FitManager::FitManager (PdfBase* dat) {
pdfPointer = dat;
}
void FitManager::fit () {
host_callnumber = 0;
pdfPointer->getParameters(vars);
numPars = vars.size();
fitter = TVirtualFitter::Fitter(0, numPars);
int maxIndex = 0;
int counter = 0;
for (std::vector<Variable*>::iterator i = vars.begin(); i != vars.end(); ++i) {
fitter->SetParameter(counter, (*i)->name.c_str(), (*i)->value, (*i)->error, (*i)->lowerlimit, (*i)->upperlimit);
if ((*i)->fixed) fitter->FixParameter(counter);
counter++;
if (maxIndex < (*i)->getIndex()) maxIndex = (*i)->getIndex();
}
numPars = maxIndex+1;
pdfPointer->copyParams();
fitter->SetFCN(FitFun);
fitter->ExecuteCommand("MIGRAD", 0, 0);
}
void FitManager::getMinuitValues () const {
int counter = 0;
for (std::vector<Variable*>::iterator i = vars.begin(); i != vars.end(); ++i) {
(*i)->value = fitter->GetParameter(counter);
(*i)->error = fitter->GetParError(counter);
counter++;
}
}
void FitFun (int &npar, double *gin, double &fun, double *fp, int iflag) { // MINUIT 3 version
vector<double> pars; // Translates from Minuit to GooFit indices
pars.resize(numPars);
int counter = 0;
for (std::vector<Variable*>::iterator i = vars.begin(); i != vars.end(); ++i) {
pars[(*i)->getIndex()] = fp[counter++];
}
pdfPointer->copyParams(pars);
fun = pdfPointer->calculateNLL();
host_callnumber++;
}