42 ClassImp(TMVA::MinuitFitter);
47 TMVA::MinuitFitter::MinuitFitter( IFitterTarget& target,
49 std::vector<TMVA::Interval*>& ranges,
50 const TString& theOption )
51 : TMVA::FitterBase( target, name, ranges, theOption ),
52 TMVA::IFitterTarget( )
64 TMVA::MinuitFitter::~MinuitFitter( )
72 void TMVA::MinuitFitter::DeclareOptions()
74 DeclareOptionRef(fErrorLevel = 1,
"ErrorLevel",
"TMinuit: error level: 0.5=logL fit, 1=chi-squared fit" );
75 DeclareOptionRef(fPrintLevel = -1,
"PrintLevel",
"TMinuit: output level: -1=least, 0, +1=all garbage" );
76 DeclareOptionRef(fFitStrategy = 2,
"FitStrategy",
"TMinuit: fit strategy: 2=best" );
77 DeclareOptionRef(fPrintWarnings = kFALSE,
"PrintWarnings",
"TMinuit: suppress warnings" );
78 DeclareOptionRef(fUseImprove = kTRUE,
"UseImprove",
"TMinuit: use IMPROVE" );
79 DeclareOptionRef(fUseMinos = kTRUE,
"UseMinos",
"TMinuit: use MINOS" );
80 DeclareOptionRef(fBatch = kFALSE,
"SetBatch",
"TMinuit: use batch mode" );
81 DeclareOptionRef(fMaxCalls = 1000,
"MaxCalls",
"TMinuit: approximate maximum number of function calls" );
82 DeclareOptionRef(fTolerance = 0.1,
"Tolerance",
"TMinuit: tolerance to the function value at the minimum" );
88 void TMVA::MinuitFitter::Init()
93 if (!fBatch) Log() << kINFO <<
"<MinuitFitter> Init " << Endl;
103 fMinWrap =
new MinuitWrapper( fFitterTarget, 2*GetNpars() );
106 args[0] = fPrintLevel;
107 fMinWrap->ExecuteCommand(
"SET PRINTOUT", args, 1 );
109 if (fBatch) fMinWrap->ExecuteCommand(
"SET BAT", args, 0 );
115 args[0] = fErrorLevel;
116 fMinWrap->ExecuteCommand(
"SET ERR", args, 1 );
119 if (!fPrintWarnings) fMinWrap->ExecuteCommand(
"SET NOWARNINGS", args, 0 );
122 args[0] = fFitStrategy;
123 fMinWrap->ExecuteCommand(
"SET STRATEGY", args, 1 );
129 Double_t TMVA::MinuitFitter::Run( std::vector<Double_t>& pars )
135 if ( !fBatch ) Log() << kINFO <<
"<MinuitFitter> Fitting, please be patient ... " << Endl;
138 if ((Int_t)pars.size() != GetNpars())
139 Log() << kFATAL <<
"<Run> Mismatch in number of parameters: (a)"
140 << GetNpars() <<
" != " << pars.size() << Endl;
144 if (!fBatch) timer =
new Timer();
147 for (Int_t ipar=0; ipar<fNpars; ipar++) {
148 fMinWrap->SetParameter( ipar, Form(
"Par%i",ipar ),
149 pars[ipar], fRanges[ipar]->GetWidth()/100.0,
150 fRanges[ipar]->GetMin(), fRanges[ipar]->GetMax() );
151 if (fRanges[ipar]->GetWidth() == 0.0) fMinWrap->FixParameter( ipar );
158 args[1] = fTolerance;
161 fMinWrap->ExecuteCommand(
"MIGrad", args, 2 );
164 if (fUseImprove) fMinWrap->ExecuteCommand(
"IMProve", args, 0 );
169 fMinWrap->ExecuteCommand(
"MINOs", args, 1 );
178 fMinWrap->GetStats( chi2, edm, errdef, nvpar, nparx );
181 if (GetNpars() != nparx) {
182 Log() << kFATAL <<
"<Run> Mismatch in number of parameters: "
183 << GetNpars() <<
" != " << nparx << Endl;
187 for (Int_t ipar=0; ipar<GetNpars(); ipar++) {
188 Double_t errp, errm, errsym, globcor, currVal, currErr;
189 fMinWrap->GetParameter( ipar, currVal, currErr );
190 pars[ipar] = currVal;
191 fMinWrap->GetErrors( ipar, errp, errm, errsym, globcor );
198 Log() << kINFO <<
"Elapsed time: " << timer->GetElapsedTime()
211 Double_t TMVA::MinuitFitter::EstimatorFunction( std::vector<Double_t>& pars )