Logo ROOT   6.16/01
Reference Guide
RooMinimizer.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * AL, Alfio Lazzaro, INFN Milan, alfio.lazzaro@mi.infn.it *
9 * *
10 * Redistribution and use in source and binary forms, *
11 * with or without modification, are permitted according to the terms *
12 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
13 *****************************************************************************/
14
15/**
16\file RooMinimizer.cxx
17\class RooMinimizer
18\ingroup Roofitcore
19
20RooMinimizer is a wrapper class around ROOT::Fit:Fitter that
21provides a seamless interface between the minimizer functionality
22and the native RooFit interface.
23By default the Minimizer is MINUIT.
24RooMinimizer can minimize any RooAbsReal function with respect to
25its parameters. Usual choices for minimization are RooNLLVar
26and RooChi2Var
27RooMinimizer has methods corresponding to MINUIT functions like
28hesse(), migrad(), minos() etc. In each of these function calls
29the state of the MINUIT engine is synchronized with the state
30of the RooFit variables: any change in variables, change
31in the constant status etc is forwarded to MINUIT prior to
32execution of the MINUIT call. Afterwards the RooFit objects
33are resynchronized with the output state of MINUIT: changes
34parameter values, errors are propagated.
35Various methods are available to control verbosity, profiling,
36automatic PDF optimization.
37**/
38
39#ifndef __ROOFIT_NOROOMINIMIZER
40
41#include "RooFit.h"
42#include "Riostream.h"
43
44#include "TClass.h"
45
46#include <fstream>
47
48#include "TH1.h"
49#include "TH2.h"
50#include "TMarker.h"
51#include "TGraph.h"
52#include "Fit/FitConfig.h"
53#include "TStopwatch.h"
54#include "TDirectory.h"
55#include "TMatrixDSym.h"
56
57#include "RooArgSet.h"
58#include "RooArgList.h"
59#include "RooAbsReal.h"
60#include "RooAbsRealLValue.h"
61#include "RooRealVar.h"
62#include "RooAbsPdf.h"
63#include "RooSentinel.h"
64#include "RooMsgService.h"
65#include "RooPlot.h"
66
67
68#include "RooMinimizer.h"
69#include "RooFitResult.h"
70
71#include "Math/Minimizer.h"
72
73#if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3)
74char* operator+( streampos&, char* );
75#endif
76
77using namespace std;
78
80;
81
83
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// Cleanup method called by atexit handler installed by RooSentinel
88/// to delete all global heap objects when the program is terminated
89
91{
92 if (_theFitter) {
93 delete _theFitter ;
94 _theFitter =0 ;
95 }
96}
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Construct MINUIT interface to given function. Function can be anything,
102/// but is typically a -log(likelihood) implemented by RooNLLVar or a chi^2
103/// (implemented by RooChi2Var). Other frequent use cases are a RooAddition
104/// of a RooNLLVar plus a penalty or constraint term. This class propagates
105/// all RooFit information (floating parameters, their values and errors)
106/// to MINUIT before each MINUIT call and propagates all MINUIT information
107/// back to the RooFit object at the end of each call (updated parameter
108/// values, their (asymmetric errors) etc. The default MINUIT error level
109/// for HESSE and MINOS error analysis is taken from the defaultErrorLevel()
110/// value of the input function.
111
113{
115
116 // Store function reference
117 _extV = 0 ;
118 _func = &function ;
119 _optConst = kFALSE ;
120 _verbose = kFALSE ;
121 _profile = kFALSE ;
123 _printLevel = 1 ;
124 _minimizerType = "Minuit"; // default minimizer
125
126 if (_theFitter) delete _theFitter ;
130 setEps(1.0); // default tolerance
131 // default max number of calls
134
135 // Shut up for now
136 setPrintLevel(-1) ;
137
138 // Use +0.5 for 1-sigma errors
140
141 // Declare our parameters to MINUIT
144
145 // Now set default verbosity
146 if (RooMsgService::instance().silentMode()) {
147 setPrintLevel(-1) ;
148 } else {
149 setPrintLevel(1) ;
150 }
151}
152
153
154
155////////////////////////////////////////////////////////////////////////////////
156/// Destructor
157
159{
160 if (_extV) {
161 delete _extV ;
162 }
163
164 if (_fcn) {
165 delete _fcn;
166 }
167
168}
169
170
171
172////////////////////////////////////////////////////////////////////////////////
173/// Change MINUIT strategy to istrat. Accepted codes
174/// are 0,1,2 and represent MINUIT strategies for dealing
175/// most efficiently with fast FCNs (0), expensive FCNs (2)
176/// and 'intermediate' FCNs (1)
177
179{
181
182}
183
184
185
186////////////////////////////////////////////////////////////////////////////////
187/// Change maximum number of MINUIT iterations
188/// (RooMinimizer default 500 * #parameters)
189
191{
193}
194
195
196
197
198////////////////////////////////////////////////////////////////////////////////
199/// Change maximum number of likelihood function calss from MINUIT
200/// (RooMinimizer default 500 * #parameters)
201
203{
205}
206
207
208
209
210////////////////////////////////////////////////////////////////////////////////
211/// Set the level for MINUIT error analysis to the given
212/// value. This function overrides the default value
213/// that is taken in the RooMinimizer constructor from
214/// the defaultErrorLevel() method of the input function
215
217{
219
220}
221
222
223
224////////////////////////////////////////////////////////////////////////////////
225/// Change MINUIT epsilon
226
228{
230
231}
232
233
234////////////////////////////////////////////////////////////////////////////////
235/// Enable internal likelihood offsetting for enhanced numeric precision
236
238{
239 _func->enableOffsetting(flag) ;
240}
241
242
243
244
245////////////////////////////////////////////////////////////////////////////////
246/// Choose the minimzer algorithm.
247
249{
251}
252
253
254
255
256////////////////////////////////////////////////////////////////////////////////
257/// Return underlying ROOT fitter object
258
260{
261 return _theFitter ;
262}
263
264
265////////////////////////////////////////////////////////////////////////////////
266/// Return underlying ROOT fitter object
267
269{
270 return _theFitter ;
271}
272
273
274
275////////////////////////////////////////////////////////////////////////////////
276/// Parse traditional RooAbsPdf::fitTo driver options
277///
278/// m - Run Migrad only
279/// h - Run Hesse to estimate errors
280/// v - Verbose mode
281/// l - Log parameters after each Minuit steps to file
282/// t - Activate profile timer
283/// r - Save fit result
284/// 0 - Run Migrad with strategy 0
285
286RooFitResult* RooMinimizer::fit(const char* options)
287{
288 TString opts(options) ;
289 opts.ToLower() ;
290
291 // Initial configuration
292 if (opts.Contains("v")) setVerbose(1) ;
293 if (opts.Contains("t")) setProfile(1) ;
294 if (opts.Contains("l")) setLogFile(Form("%s.log",_func->GetName())) ;
295 if (opts.Contains("c")) optimizeConst(1) ;
296
297 // Fitting steps
298 if (opts.Contains("0")) setStrategy(0) ;
299 migrad() ;
300 if (opts.Contains("0")) setStrategy(1) ;
301 if (opts.Contains("h")||!opts.Contains("m")) hesse() ;
302 if (!opts.Contains("m")) minos() ;
303
304 return (opts.Contains("r")) ? save() : 0 ;
305}
306
307
308
309
310////////////////////////////////////////////////////////////////////////////////
311
312Int_t RooMinimizer::minimize(const char* type, const char* alg)
313{
316
318
319 profileStart() ;
322
323 bool ret = _theFitter->FitFCN(*_fcn);
324 _status = ((ret) ? _theFitter->Result().Status() : -1);
325
327 profileStop() ;
329
330 saveStatus("MINIMIZE",_status) ;
331
332 return _status ;
333}
334
335
336
337////////////////////////////////////////////////////////////////////////////////
338/// Execute MIGRAD. Changes in parameter values
339/// and calculated errors are automatically
340/// propagated back the RooRealVars representing
341/// the floating parameters in the MINUIT operation
342
344{
347 profileStart() ;
350
351 _theFitter->Config().SetMinimizer(_minimizerType.c_str(),"migrad");
352 bool ret = _theFitter->FitFCN(*_fcn);
353 _status = ((ret) ? _theFitter->Result().Status() : -1);
354
356 profileStop() ;
358
359 saveStatus("MIGRAD",_status) ;
360
361 return _status ;
362}
363
364
365
366////////////////////////////////////////////////////////////////////////////////
367/// Execute HESSE. Changes in parameter values
368/// and calculated errors are automatically
369/// propagated back the RooRealVars representing
370/// the floating parameters in the MINUIT operation
371
373{
374 if (_theFitter->GetMinimizer()==0) {
375 coutW(Minimization) << "RooMinimizer::hesse: Error, run Migrad before Hesse!"
376 << endl ;
377 _status = -1;
378 }
379 else {
380
383 profileStart() ;
386
388 bool ret = _theFitter->CalculateHessErrors();
389 _status = ((ret) ? _theFitter->Result().Status() : -1);
390
392 profileStop() ;
394
395 saveStatus("HESSE",_status) ;
396
397 }
398
399 return _status ;
400
401}
402
403////////////////////////////////////////////////////////////////////////////////
404/// Execute MINOS. Changes in parameter values
405/// and calculated errors are automatically
406/// propagated back the RooRealVars representing
407/// the floating parameters in the MINUIT operation
408
410{
411 if (_theFitter->GetMinimizer()==0) {
412 coutW(Minimization) << "RooMinimizer::minos: Error, run Migrad before Minos!"
413 << endl ;
414 _status = -1;
415 }
416 else {
417
420 profileStart() ;
423
425 bool ret = _theFitter->CalculateMinosErrors();
426 _status = ((ret) ? _theFitter->Result().Status() : -1);
427
429 profileStop() ;
431
432 saveStatus("MINOS",_status) ;
433
434 }
435
436 return _status ;
437
438}
439
440
441////////////////////////////////////////////////////////////////////////////////
442/// Execute MINOS for given list of parameters. Changes in parameter values
443/// and calculated errors are automatically
444/// propagated back the RooRealVars representing
445/// the floating parameters in the MINUIT operation
446
447Int_t RooMinimizer::minos(const RooArgSet& minosParamList)
448{
449 if (_theFitter->GetMinimizer()==0) {
450 coutW(Minimization) << "RooMinimizer::minos: Error, run Migrad before Minos!"
451 << endl ;
452 _status = -1;
453 }
454 else if (minosParamList.getSize()>0) {
455
458 profileStart() ;
461
462 // get list of parameters for Minos
463 TIterator* aIter = minosParamList.createIterator() ;
464 RooAbsArg* arg ;
465 std::vector<unsigned int> paramInd;
466 while((arg=(RooAbsArg*)aIter->Next())) {
467 RooAbsArg* par = _fcn->GetFloatParamList()->find(arg->GetName());
468 if (par && !par->isConstant()) {
469 Int_t index = _fcn->GetFloatParamList()->index(par);
470 paramInd.push_back(index);
471 }
472 }
473 delete aIter ;
474
475 if (paramInd.size()) {
476 // set the parameter indeces
477 _theFitter->Config().SetMinosErrors(paramInd);
478
480 bool ret = _theFitter->CalculateMinosErrors();
481 _status = ((ret) ? _theFitter->Result().Status() : -1);
482 // to avoid that following minimization computes automatically the Minos errors
484
485 }
486
488 profileStop() ;
490
491 saveStatus("MINOS",_status) ;
492
493 }
494
495 return _status ;
496}
497
498
499
500////////////////////////////////////////////////////////////////////////////////
501/// Execute SEEK. Changes in parameter values
502/// and calculated errors are automatically
503/// propagated back the RooRealVars representing
504/// the floating parameters in the MINUIT operation
505
507{
510 profileStart() ;
513
514 _theFitter->Config().SetMinimizer(_minimizerType.c_str(),"seek");
515 bool ret = _theFitter->FitFCN(*_fcn);
516 _status = ((ret) ? _theFitter->Result().Status() : -1);
517
519 profileStop() ;
521
522 saveStatus("SEEK",_status) ;
523
524 return _status ;
525}
526
527
528
529////////////////////////////////////////////////////////////////////////////////
530/// Execute SIMPLEX. Changes in parameter values
531/// and calculated errors are automatically
532/// propagated back the RooRealVars representing
533/// the floating parameters in the MINUIT operation
534
536{
539 profileStart() ;
542
543 _theFitter->Config().SetMinimizer(_minimizerType.c_str(),"simplex");
544 bool ret = _theFitter->FitFCN(*_fcn);
545 _status = ((ret) ? _theFitter->Result().Status() : -1);
546
548 profileStop() ;
550
551 saveStatus("SEEK",_status) ;
552
553 return _status ;
554}
555
556
557
558////////////////////////////////////////////////////////////////////////////////
559/// Execute IMPROVE. Changes in parameter values
560/// and calculated errors are automatically
561/// propagated back the RooRealVars representing
562/// the floating parameters in the MINUIT operation
563
565{
568 profileStart() ;
571
572 _theFitter->Config().SetMinimizer(_minimizerType.c_str(),"migradimproved");
573 bool ret = _theFitter->FitFCN(*_fcn);
574 _status = ((ret) ? _theFitter->Result().Status() : -1);
575
577 profileStop() ;
579
580 saveStatus("IMPROVE",_status) ;
581
582 return _status ;
583}
584
585
586
587////////////////////////////////////////////////////////////////////////////////
588/// Change the MINUIT internal printing level
589
591{
592 Int_t ret = _printLevel ;
594 _printLevel = newLevel+1 ;
595 return ret ;
596}
597
598////////////////////////////////////////////////////////////////////////////////
599/// If flag is true, perform constant term optimization on
600/// function being minimized.
601
603{
605
606 if (_optConst && !flag){
607 if (_printLevel>-1) coutI(Minimization) << "RooMinimizer::optimizeConst: deactivating const optimization" << endl ;
609 _optConst = flag ;
610 } else if (!_optConst && flag) {
611 if (_printLevel>-1) coutI(Minimization) << "RooMinimizer::optimizeConst: activating const optimization" << endl ;
613 _optConst = flag ;
614 } else if (_optConst && flag) {
615 if (_printLevel>-1) coutI(Minimization) << "RooMinimizer::optimizeConst: const optimization already active" << endl ;
616 } else {
617 if (_printLevel>-1) coutI(Minimization) << "RooMinimizer::optimizeConst: const optimization wasn't active" << endl ;
618 }
619
621
622}
623
624
625
626////////////////////////////////////////////////////////////////////////////////
627/// Save and return a RooFitResult snaphot of current minimizer status.
628/// This snapshot contains the values of all constant parameters,
629/// the value of all floating parameters at RooMinimizer construction and
630/// after the last MINUIT operation, the MINUIT status, variance quality,
631/// EDM setting, number of calls with evaluation problems, the minimized
632/// function value and the full correlation matrix
633
634RooFitResult* RooMinimizer::save(const char* userName, const char* userTitle)
635{
636 if (_theFitter->GetMinimizer()==0) {
637 coutW(Minimization) << "RooMinimizer::save: Error, run minimization before!"
638 << endl ;
639 return 0;
640 }
641
642 TString name,title ;
643 name = userName ? userName : Form("%s", _func->GetName()) ;
644 title = userTitle ? userTitle : Form("%s", _func->GetTitle()) ;
645 RooFitResult* fitRes = new RooFitResult(name,title) ;
646
647 // Move eventual fixed parameters in floatList to constList
648 Int_t i ;
649 RooArgList saveConstList(*(_fcn->GetConstParamList())) ;
650 RooArgList saveFloatInitList(*(_fcn->GetInitFloatParamList())) ;
651 RooArgList saveFloatFinalList(*(_fcn->GetFloatParamList())) ;
652 for (i=0 ; i<_fcn->GetFloatParamList()->getSize() ; i++) {
653 RooAbsArg* par = _fcn->GetFloatParamList()->at(i) ;
654 if (par->isConstant()) {
655 saveFloatInitList.remove(*saveFloatInitList.find(par->GetName()),kTRUE) ;
656 saveFloatFinalList.remove(*par) ;
657 saveConstList.add(*par) ;
658 }
659 }
660 saveConstList.sort() ;
661
662 fitRes->setConstParList(saveConstList) ;
663 fitRes->setInitParList(saveFloatInitList) ;
664
665 fitRes->setStatus(_status) ;
667 fitRes->setMinNLL(_theFitter->Result().MinFcnValue()) ;
669 fitRes->setEDM(_theFitter->Result().Edm()) ;
670 fitRes->setFinalParList(saveFloatFinalList) ;
671 if (!_extV) {
672 std::vector<double> globalCC;
673 TMatrixDSym corrs(_theFitter->Result().Parameters().size()) ;
674 TMatrixDSym covs(_theFitter->Result().Parameters().size()) ;
675 for (UInt_t ic=0; ic<_theFitter->Result().Parameters().size(); ic++) {
676 globalCC.push_back(_theFitter->Result().GlobalCC(ic));
677 for (UInt_t ii=0; ii<_theFitter->Result().Parameters().size(); ii++) {
678 corrs(ic,ii) = _theFitter->Result().Correlation(ic,ii);
679 covs(ic,ii) = _theFitter->Result().CovMatrix(ic,ii);
680 }
681 }
682 fitRes->fillCorrMatrix(globalCC,corrs,covs) ;
683 } else {
684 fitRes->setCovarianceMatrix(*_extV) ;
685 }
686
688
689 return fitRes ;
690
691}
692
693////////////////////////////////////////////////////////////////////////////////
694/// Create and draw a TH2 with the error contours in parameters var1 and v2 at up to 6 'sigma' settings
695/// where 'sigma' is calculated as n*n*errorLevel
696
698 Double_t n1, Double_t n2, Double_t n3,
699 Double_t n4, Double_t n5, Double_t n6)
700{
701
702
703 RooArgList* params = _fcn->GetFloatParamList() ;
704 RooArgList* paramSave = (RooArgList*) params->snapshot() ;
705
706 // Verify that both variables are floating parameters of PDF
707 Int_t index1= _fcn->GetFloatParamList()->index(&var1);
708 if(index1 < 0) {
709 coutE(Minimization) << "RooMinimizer::contour(" << GetName()
710 << ") ERROR: " << var1.GetName()
711 << " is not a floating parameter of "
712 << _func->GetName() << endl ;
713 return 0;
714 }
715
716 Int_t index2= _fcn->GetFloatParamList()->index(&var2);
717 if(index2 < 0) {
718 coutE(Minimization) << "RooMinimizer::contour(" << GetName()
719 << ") ERROR: " << var2.GetName()
720 << " is not a floating parameter of PDF "
721 << _func->GetName() << endl ;
722 return 0;
723 }
724
725 // create and draw a frame
726 RooPlot* frame = new RooPlot(var1,var2) ;
727
728 // draw a point at the current parameter values
729 TMarker *point= new TMarker(var1.getVal(), var2.getVal(), 8);
730 frame->addObject(point) ;
731
732 // check first if a inimizer is available. If not means
733 // the minimization is not done , so do it
734 if (_theFitter->GetMinimizer()==0) {
735 coutW(Minimization) << "RooMinimizer::contour: Error, run Migrad before contours!"
736 << endl ;
737 return frame;
738 }
739
740
741 // remember our original value of ERRDEF
743
744 Double_t n[6] ;
745 n[0] = n1 ; n[1] = n2 ; n[2] = n3 ; n[3] = n4 ; n[4] = n5 ; n[5] = n6 ;
746 unsigned int npoints(50);
747
748 for (Int_t ic = 0 ; ic<6 ; ic++) {
749 if(n[ic] > 0) {
750
751 // set the value corresponding to an n1-sigma contour
752 _theFitter->GetMinimizer()->SetErrorDef(n[ic]*n[ic]*errdef);
753
754 // calculate and draw the contour
755 Double_t *xcoor = new Double_t[npoints+1];
756 Double_t *ycoor = new Double_t[npoints+1];
757 bool ret = _theFitter->GetMinimizer()->Contour(index1,index2,npoints,xcoor,ycoor);
758
759 if (!ret) {
760 coutE(Minimization) << "RooMinimizer::contour("
761 << GetName()
762 << ") ERROR: MINUIT did not return a contour graph for n="
763 << n[ic] << endl ;
764 } else {
765 xcoor[npoints] = xcoor[0];
766 ycoor[npoints] = ycoor[0];
767 TGraph* graph = new TGraph(npoints+1,xcoor,ycoor);
768
769 graph->SetName(Form("contour_%s_n%f",_func->GetName(),n[ic])) ;
770 graph->SetLineStyle(ic+1) ;
771 graph->SetLineWidth(2) ;
772 graph->SetLineColor(kBlue) ;
773 frame->addObject(graph,"L") ;
774 }
775
776 delete [] xcoor;
777 delete [] ycoor;
778 }
779 }
780
781
782 // restore the original ERRDEF
784
785 // restore parameter values
786 *params = *paramSave ;
787 delete paramSave ;
788
789 return frame ;
790
791}
792
793
794////////////////////////////////////////////////////////////////////////////////
795/// Start profiling timer
796
798{
799 if (_profile) {
800 _timer.Start() ;
803 }
804}
805
806
807////////////////////////////////////////////////////////////////////////////////
808/// Stop profiling timer and report results of last session
809
811{
812 if (_profile) {
813 _timer.Stop() ;
814 _cumulTimer.Stop() ;
815 coutI(Minimization) << "Command timer: " ; _timer.Print() ;
816 coutI(Minimization) << "Session timer: " ; _cumulTimer.Print() ;
817 }
818}
819
820
821
822
823
824////////////////////////////////////////////////////////////////////////////////
825/// Apply results of given external covariance matrix. i.e. propagate its errors
826/// to all RRV parameter representations and give this matrix instead of the
827/// HESSE matrix at the next save() call
828
830{
831 _extV = (TMatrixDSym*) V.Clone() ;
833
834}
835
836
837
839{
840 // Import the results of the last fit performed, interpreting
841 // the fit parameters as the given varList of parameters.
842
843 if (_theFitter==0 || _theFitter->GetMinimizer()==0) {
844 oocoutE((TObject*)0,InputArguments) << "RooMinimizer::save: Error, run minimization before!"
845 << endl ;
846 return 0;
847 }
848
849 // Verify length of supplied varList
850 if (varList.getSize()>0 && varList.getSize()!=Int_t(_theFitter->Result().NTotalParameters())) {
852 << "RooMinimizer::lastMinuitFit: ERROR: supplied variable list must be either empty " << endl
853 << " or match the number of variables of the last fit ("
854 << _theFitter->Result().NTotalParameters() << ")" << endl ;
855 return 0 ;
856 }
857
858
859 // Verify that all members of varList are of type RooRealVar
860 TIterator* iter = varList.createIterator() ;
861 RooAbsArg* arg ;
862 while((arg=(RooAbsArg*)iter->Next())) {
863 if (!dynamic_cast<RooRealVar*>(arg)) {
864 oocoutE((TObject*)0,InputArguments) << "RooMinimizer::lastMinuitFit: ERROR: variable '"
865 << arg->GetName() << "' is not of type RooRealVar" << endl ;
866 return 0 ;
867 }
868 }
869 delete iter ;
870
871 RooFitResult* res = new RooFitResult("lastMinuitFit","Last MINUIT fit") ;
872
873 // Extract names of fit parameters
874 // and construct corresponding RooRealVars
875 RooArgList constPars("constPars") ;
876 RooArgList floatPars("floatPars") ;
877
878 UInt_t i ;
879 for (i = 0; i < _theFitter->Result().NTotalParameters(); ++i) {
880
881 TString varName(_theFitter->Result().GetParameterName(i));
883
886 Double_t xerr = _theFitter->Result().Error(i);
887 Double_t xval = _theFitter->Result().Value(i);
888
889 RooRealVar* var ;
890 if (varList.getSize()==0) {
891
892 if ((xlo<xhi) && !isConst) {
893 var = new RooRealVar(varName,varName,xval,xlo,xhi) ;
894 } else {
895 var = new RooRealVar(varName,varName,xval) ;
896 }
897 var->setConstant(isConst) ;
898 } else {
899
900 var = (RooRealVar*) varList.at(i)->Clone() ;
901 var->setConstant(isConst) ;
902 var->setVal(xval) ;
903 if (xlo<xhi) {
904 var->setRange(xlo,xhi) ;
905 }
906
907 if (varName.CompareTo(var->GetName())) {
908 oocoutI((TObject*)0,Eval) << "RooMinimizer::lastMinuitFit: fit parameter '" << varName
909 << "' stored in variable '" << var->GetName() << "'" << endl ;
910 }
911
912 }
913
914 if (isConst) {
915 constPars.addOwned(*var) ;
916 } else {
917 var->setError(xerr) ;
918 floatPars.addOwned(*var) ;
919 }
920 }
921
922 res->setConstParList(constPars) ;
923 res->setInitParList(floatPars) ;
924 res->setFinalParList(floatPars) ;
926 res->setEDM(_theFitter->Result().Edm()) ;
928 res->setStatus(_theFitter->Result().Status()) ;
929 std::vector<double> globalCC;
930 TMatrixDSym corrs(_theFitter->Result().Parameters().size()) ;
931 TMatrixDSym covs(_theFitter->Result().Parameters().size()) ;
932 for (UInt_t ic=0; ic<_theFitter->Result().Parameters().size(); ic++) {
933 globalCC.push_back(_theFitter->Result().GlobalCC(ic));
934 for (UInt_t ii=0; ii<_theFitter->Result().Parameters().size(); ii++) {
935 corrs(ic,ii) = _theFitter->Result().Correlation(ic,ii);
936 covs(ic,ii) = _theFitter->Result().CovMatrix(ic,ii);
937 }
938 }
939 res->fillCorrMatrix(globalCC,corrs,covs) ;
940
941 return res;
942
943}
944
945#endif
#define coutI(a)
Definition: RooMsgService.h:31
#define coutW(a)
Definition: RooMsgService.h:33
#define oocoutE(o, a)
Definition: RooMsgService.h:47
#define oocoutI(o, a)
Definition: RooMsgService.h:44
#define coutE(a)
Definition: RooMsgService.h:34
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
@ kBlue
Definition: Rtypes.h:63
int type
Definition: TGX11.cxx:120
char * Form(const char *fmt,...)
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
Definition: TString.cxx:1449
void SetMinosErrors(bool on=true)
set Minos erros computation to be performed after fitting
Definition: FitConfig.h:226
void SetMinimizer(const char *type, const char *algo=0)
set minimizer type
Definition: FitConfig.h:180
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
Definition: FitConfig.h:85
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
Definition: FitConfig.h:75
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
Definition: FitConfig.h:166
bool IsParameterFixed(unsigned int ipar) const
query if a parameter is fixed
Definition: FitResult.cxx:422
double Error(unsigned int i) const
parameter error by index
Definition: FitResult.h:187
double CovMatrix(unsigned int i, unsigned int j) const
retrieve covariance matrix element
Definition: FitResult.h:217
double Value(unsigned int i) const
parameter value by index
Definition: FitResult.h:180
const std::vector< double > & Parameters() const
parameter values (return std::vector)
Definition: FitResult.h:175
std::string GetParameterName(unsigned int ipar) const
get name of parameter (deprecated)
Definition: FitResult.h:320
double MinFcnValue() const
Return value of the objective function (chi2 or likelihood) used in the fit.
Definition: FitResult.h:121
double Edm() const
Expected distance from minimum.
Definition: FitResult.h:127
double Correlation(unsigned int i, unsigned int j) const
retrieve correlation elements
Definition: FitResult.h:227
unsigned int NTotalParameters() const
get total number of parameters
Definition: FitResult.h:130
int Status() const
minimizer status code
Definition: FitResult.h:138
double GlobalCC(unsigned int i) const
parameter global correlation coefficient
Definition: FitResult.h:211
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
bool FitFCN(unsigned int npar, Function &fcn, const double *params=0, unsigned int dataSize=0, bool chi2fit=false)
Fit using the a generic FCN function as a C++ callable object implementing double () (const double *)...
Definition: Fitter.h:590
ROOT::Math::Minimizer * GetMinimizer() const
return pointer to last used minimizer (is NULL in case fit is not yet done) This pointer is guranteed...
Definition: Fitter.h:415
const FitResult & Result() const
get fit result
Definition: Fitter.h:365
const FitConfig & Config() const
access to the fit configuration (const method)
Definition: Fitter.h:393
bool CalculateMinosErrors()
perform an error analysis on the result using MINOS To be called only after fitting and when a minimi...
Definition: Fitter.cxx:695
bool CalculateHessErrors()
perform an error analysis on the result using the Hessian Errors are obtaied from the inverse of the ...
Definition: Fitter.cxx:619
double LowerLimit() const
return lower limit value
double UpperLimit() const
return upper limit value
void SetMaxFunctionCalls(unsigned int maxfcn)
set maximum of function calls
void SetStrategy(int stra)
set the strategy
void SetMaxIterations(unsigned int maxiter)
set maximum iterations (one iteration can have many function calls)
void SetErrorDef(double err)
set error def
void SetPrintLevel(int level)
set print level
void SetTolerance(double tol)
set the tolerance
void SetErrorDef(double up)
set scale for calculating the errors
Definition: Minimizer.h:464
virtual int CovMatrixStatus() const
return status of covariance matrix using Minuit convention {0 not calculated 1 approximated 2 made po...
Definition: Minimizer.h:318
double ErrorDef() const
return the statistical scale used for calculate the error is typically 1 for Chi2 and 0....
Definition: Minimizer.h:434
virtual bool Contour(unsigned int ivar, unsigned int jvar, unsigned int &npoints, double *xi, double *xj)
find the contour points (xi, xj) of the function for parameter ivar and jvar around the minimum The c...
Definition: Minimizer.h:379
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:75
virtual void constOptimizeTestStatistic(ConstOpCode opcode, Bool_t doAlsoTrackingOpt=kTRUE)
Interface function signaling a request to perform constant term optimization.
Definition: RooAbsArg.cxx:1731
@ DeActivate
Definition: RooAbsArg.h:299
Bool_t isConstant() const
Definition: RooAbsArg.h:266
Int_t getSize() const
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
TIterator * createIterator(Bool_t dir=kIterForward) const
RooAbsArg * find(const char *name) const
Find object with given name in list.
void setConstant(Bool_t value=kTRUE)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
virtual Double_t defaultErrorLevel() const
Definition: RooAbsReal.h:190
virtual void enableOffsetting(Bool_t)
Definition: RooAbsReal.h:308
Double_t getVal(const RooArgSet *set=0) const
Evaluate object. Returns either cached value or triggers a recalculation.
Definition: RooAbsReal.h:64
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
Int_t index(const RooAbsArg *arg) const
Definition: RooArgList.h:76
void sort(Bool_t reverse=kFALSE)
Definition: RooArgList.h:72
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Definition: RooFitResult.h:40
void fillCorrMatrix()
Internal utility method to extract the correlation matrix and the global correlation coefficients fro...
void setCovQual(Int_t val)
Definition: RooFitResult.h:170
void setMinNLL(Double_t val)
Definition: RooFitResult.h:167
void setNumInvalidNLL(Int_t val)
Definition: RooFitResult.h:171
void setStatus(Int_t val)
Definition: RooFitResult.h:169
void setConstParList(const RooArgList &list)
Fill the list of constant parameters.
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
void setEDM(Double_t val)
Definition: RooFitResult.h:168
void setStatusHistory(std::vector< std::pair< std::string, int > > &hist)
Definition: RooFitResult.h:176
void setInitParList(const RooArgList &list)
Fill the list of initial values of the floating parameters.
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
Int_t GetNumInvalidNLL()
RooArgList * GetInitFloatParamList()
void ApplyCovarianceMatrix(TMatrixDSym &V)
virtual unsigned int NDim() const
Retrieve the dimension of the function.
Bool_t Synchronize(std::vector< ROOT::Fit::ParameterSettings > &parameters, Bool_t optConst, Bool_t verbose)
void BackProp(const ROOT::Fit::FitResult &results)
RooArgList * GetFloatParamList()
RooArgList * GetConstParamList()
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:38
Int_t _printLevel
Definition: RooMinimizer.h:108
RooMinimizerFcn * _fcn
Definition: RooMinimizer.h:121
std::vector< std::pair< std::string, int > > _statusHistory
Definition: RooMinimizer.h:126
RooMinimizer(RooAbsReal &function)
Construct MINUIT interface to given function.
Int_t hesse()
Execute HESSE.
void setMaxIterations(Int_t n)
Change maximum number of MINUIT iterations (RooMinimizer default 500 * #parameters)
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snaphot of current minimizer status.
void setMinimizerType(const char *type)
Choose the minimzer algorithm.
Bool_t _verbose
Definition: RooMinimizer.h:114
void saveStatus(const char *label, Int_t status)
Definition: RooMinimizer.h:83
Int_t improve()
Execute IMPROVE.
void profileStart()
Start profiling timer.
Int_t migrad()
Execute MIGRAD.
Int_t minimize(const char *type, const char *alg=0)
RooPlot * contour(RooRealVar &var1, RooRealVar &var2, Double_t n1=1, Double_t n2=2, Double_t n3=0, Double_t n4=0, Double_t n5=0, Double_t n6=0)
Create and draw a TH2 with the error contours in parameters var1 and v2 at up to 6 'sigma' settings w...
void profileStop()
Stop profiling timer and report results of last session.
static RooFitResult * lastMinuitFit(const RooArgList &varList=RooArgList())
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
void setOffsetting(Bool_t flag)
Enable internal likelihood offsetting for enhanced numeric precision.
TMatrixDSym * _extV
Definition: RooMinimizer.h:119
Int_t seek()
Execute SEEK.
Bool_t setLogFile(const char *logf=0)
Definition: RooMinimizer.h:76
void setProfile(Bool_t flag=kTRUE)
Definition: RooMinimizer.h:75
void setEps(Double_t eps)
Change MINUIT epsilon.
void setErrorLevel(Double_t level)
Set the level for MINUIT error analysis to the given value.
static ROOT::Fit::Fitter * _theFitter
Definition: RooMinimizer.h:124
static void cleanup()
Cleanup method called by atexit handler installed by RooSentinel to delete all global heap objects wh...
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
TStopwatch _timer
Definition: RooMinimizer.h:115
void setMaxFunctionCalls(Int_t n)
Change maximum number of likelihood function calss from MINUIT (RooMinimizer default 500 * #parameter...
Int_t minos()
Execute MINOS.
RooAbsReal * _func
Definition: RooMinimizer.h:112
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
Int_t simplex()
Execute SIMPLEX.
Bool_t _optConst
Definition: RooMinimizer.h:110
Bool_t _profileStart
Definition: RooMinimizer.h:117
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
std::string _minimizerType
Definition: RooMinimizer.h:122
TStopwatch _cumulTimer
Definition: RooMinimizer.h:116
Bool_t _profile
Definition: RooMinimizer.h:111
void setVerbose(Bool_t flag=kTRUE)
Definition: RooMinimizer.h:74
virtual ~RooMinimizer()
Destructor.
static RooMsgService & instance()
Return reference to singleton instance.
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
void addObject(TObject *obj, Option_t *drawOptions="", Bool_t invisible=kFALSE)
Add a generic object to this plot.
Definition: RooPlot.cxx:391
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
void setError(Double_t value)
Definition: RooRealVar.h:55
void setRange(const char *name, Double_t min, Double_t max)
Set range named 'name to [min,max].
Definition: RooRealVar.cxx:448
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:204
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
Definition: RooSentinel.cxx:73
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
Iterator abstract base class.
Definition: TIterator.h:30
virtual TObject * Next()=0
Manages Markers.
Definition: TMarker.h:23
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:77
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
Definition: TStopwatch.cxx:219
const Int_t n
Definition: legend1.C:16
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
RooCmdArg Parameters(const RooArgSet &params)
@ Minimization
Definition: RooGlobalFunc.h:57
@ InputArguments
Definition: RooGlobalFunc.h:58
Definition: graph.py:1
STL namespace.