41#define __ROOFIT_SUPPRESS_ROOMINIMIZER_DEPRECATION_WARNING
43#undef __ROOFIT_SUPPRESS_ROOMINIMIZER_DEPRECATION_WARNING
63#include "../RooSentinel.h"
68#if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3)
125 std::unique_ptr<RooArgSet> paramSet{function.getParameters(
RooArgSet())};
143 coutW(Minimization) <<
"RooMinuit::RooMinuit: removing parameter " << arg->GetName()
144 <<
" from list because it is not of type RooRealVar" << endl ;
215 double stratArg(istrat) ;
417 double* arglist =
new double[
_nPar+1];
419 if (minosParamList.
getSize()>0) {
425 arglist[nMinosPar]=
index+1;
561 double arg(newLevel) ;
591 double arg(newLevel) ;
616 bool constValChange(
false) ;
617 bool constStatChange(
false) ;
627 if (!oldpar) continue ;
637 constStatChange=true ;
641 coutI(Minimization) <<
"RooMinuit::synchronize: parameter " << par->
GetName() <<
" is now floating." << endl ;
647 constValChange=true ;
649 coutI(Minimization) <<
"RooMinuit::synchronize: value of constant parameter " << par->
GetName()
650 <<
" changed from " << oldpar->
getVal() <<
" to " << par->
getVal() << endl ;
673 coutW(Minimization) <<
"RooMinuit::fit: Error, non-constant parameter " << par->
GetName()
674 <<
" is not of type RooRealVar, skipping" << endl ;
689 pstep= 0.1*(pmax-pmin);
692 if (pmax - par->
getVal() < 2*pstep) {
693 pstep = (pmax - par->
getVal())/2 ;
694 }
else if (par->
getVal() - pmin < 2*pstep) {
695 pstep = (par->
getVal() - pmin )/2 ;
700 pstep= 0.1*(pmax-pmin);
707 coutW(Minimization) <<
"RooMinuit::synchronize: WARNING: no initial error estimate available for "
708 << par->
GetName() <<
": using " << pstep << endl;
717 double oldVar,oldVerr,oldVlo,oldVhi ;
718 char oldParname[100] ;
724 bool oldFixed(
false) ;
734 if (oldVar!=par->
getVal()) {
736 arglist[0] =
index+1 ;
737 arglist[1] = par->
getVal() ;
740 coutI(Minimization) <<
"RooMinuit::synchronize: value of parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
745 constStatChange=true ;
747 coutI(Minimization) <<
"RooMinuit::synchronize: parameter " << par->
GetName() <<
" is now fixed." << endl ;
753 if (oldVar!=par->
getVal()) {
755 arglist[0] =
index+1 ;
756 arglist[1] = par->
getVal() ;
758 constValChange=true ;
761 coutI(Minimization) <<
"RooMinuit::synchronize: value of fixed parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
769 constStatChange=true ;
772 coutI(Minimization) <<
"RooMinuit::synchronize: parameter " << par->
GetName() <<
" is now floating." << endl ;
777 if (oldVar!=par->
getVal() || oldVlo!=pmin || oldVhi != pmax || oldVerr!=pstep) {
782 if (verbose && ierr>=0) {
785 if (oldVar!=par->
getVal()) {
786 coutI(Minimization) <<
"RooMinuit::synchronize: value of parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
788 if (oldVlo!=pmin || oldVhi!=pmax) {
789 coutI(Minimization) <<
"RooMinuit::synchronize: limits of parameter " << par->
GetName() <<
" changed from [" << oldVlo <<
"," << oldVhi
790 <<
"] to [" << pmin <<
"," << pmax <<
"]" << endl ;
794 if (oldVerr!=pstep && oldVerr!=0) {
795 coutI(Minimization) <<
"RooMinuit::synchronize: error/step size of parameter " << par->
GetName() <<
" changed from " << oldVerr <<
" to " << pstep << endl ;
807 if (constStatChange) {
811 coutI(Minimization) <<
"RooMinuit::synchronize: set of constant parameters changed, rerunning const optimizer" << endl ;
813 }
else if (constValChange) {
814 coutI(Minimization) <<
"RooMinuit::synchronize: constant parameter values changed, rerunning const optimizer" << endl ;
839 if (
_printLevel>-1)
coutI(Minimization) <<
"RooMinuit::optimizeConst: deactivating const optimization" << endl ;
843 if (
_printLevel>-1)
coutI(Minimization) <<
"RooMinuit::optimizeConst: activating const optimization" << endl ;
847 if (
_printLevel>-1)
coutI(Minimization) <<
"RooMinuit::optimizeConst: const optimization already active" << endl ;
849 if (
_printLevel>-1)
coutI(Minimization) <<
"RooMinuit::optimizeConst: const optimization wasn't active" << endl ;
896 saveFloatFinalList.
remove(*par) ;
897 saveConstList.
add(*par) ;
900 saveConstList.
sort() ;
905 double edm, errdef, minVal;
942 coutE(Minimization) <<
"RooMinuit::contour(" <<
GetName()
943 <<
") ERROR: " << var1.
GetName() <<
" is not a floating parameter of " <<
_func->
GetName() << endl ;
949 coutE(Minimization) <<
"RooMinuit::contour(" <<
GetName()
950 <<
") ERROR: " << var2.
GetName() <<
" is not a floating parameter of PDF " <<
_func->
GetName() << endl ;
965 n[0] = n1 ;
n[1] = n2 ;
n[2] = n3 ;
n[3] = n4 ;
n[4] = n5 ;
n[5] = n6 ;
968 for (
Int_t ic = 0 ; ic<6 ; ic++) {
975 coutE(Minimization) <<
"RooMinuit::contour(" <<
GetName() <<
") ERROR: MINUIT did not return a contour graph for n=" <<
n[ic] << endl ;
978 graph->SetLineStyle(ic+1) ;
979 graph->SetLineWidth(2) ;
1007 coutI(Minimization) <<
"RooMinuit::setLogFile: closing previous log file" << endl ;
1012 _logfile =
new ofstream(inLogfile) ;
1014 coutI(Minimization) <<
"RooMinuit::setLogFile: cannot open file " << inLogfile << endl ;
1053 if (verbose) cout << par->
GetName() <<
"=" <<
value <<
", " ;
1128 double val,err,vlo,vhi, eplus, eminus, eparab, globcc;
1139 if(eplus > 0 || eminus < 0) {
1180 cout <<
"setting parameter " << i <<
" error to " << sqrt((*
_extV)(i,i)) << endl ;
1190 double &
f,
double *par,
Int_t )
1196 ofstream* logf = context->
logfile() ;
1203 if (logf) (*logf) << par[
index] <<
" " ;
1217 oocoutW(context,Minimization) <<
"RooMinuitGlue: Minimized function has error status." << endl
1218 <<
"Returning maximum FCN so far (" <<
maxFCN
1219 <<
") to force MIGRAD to back out of this region. Error log follows" << endl ;
1221 oocoutW(context,Minimization) <<
"RooMinuitGlue: Minimized function has error status but is ignored" << endl ;
1225 ooccoutW(context,Minimization) <<
"Parameter values: " ;
1226 for(
auto * var : static_range_cast<RooRealVar*>(*context->
_floatParamList)) {
1228 ooccoutW(context,Minimization) << var->GetName() <<
"=" << var->getVal() ;
1230 ooccoutW(context,Minimization) << endl ;
1233 ooccoutW(context,Minimization) << endl ;
1247 if (logf) (*logf) << setprecision(15) <<
f << setprecision(4) << endl;
1249 cout <<
"\nprevFCN" << (context->
_func->
isOffsetting()?
"-offset":
"") <<
" = " << setprecision(10) <<
f << setprecision(4) <<
" " ;
void RooMinuitGlue(Int_t &, double *, double &f, double *par, Int_t)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
R__EXTERN TMinuit * gMinuit
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
bool isConstant() const
Check if the "Constant" attribute is set.
virtual void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true)
Interface function signaling a request to perform constant term optimization.
RooAbsCollection * selectByAttrib(const char *name, bool value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
void sort(bool reverse=false)
Sort collection using std::sort and name comparison.
void setName(const char *name)
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
bool hasMax(const char *name=nullptr) const
Check if variable has an upper bound.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
bool hasMin(const char *name=nullptr) const
Check if variable has a lower bound.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
virtual bool isOffsetting() const
static void setHideOffset(bool flag)
static Int_t numEvalErrors()
Return the number of logged evaluation errors since the last clearing.
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
static void printEvalErrors(std::ostream &os=std::cout, Int_t maxPerNode=10000000)
Print all outstanding logged evaluation error on the given ostream.
virtual void enableOffsetting(bool)
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
void setCovQual(Int_t val)
void setMinNLL(double val)
void setNumInvalidNLL(Int_t val)
void setStatus(Int_t val)
void setConstParList(const RooArgList &list)
Fill the list of constant parameters.
void fillCorrMatrix(const std::vector< double > &globalCC, const TMatrixDSym &corrs, const TMatrixDSym &covs)
Function called by RooMinimizer.
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
void setStatusHistory(std::vector< std::pair< std::string, int > > &hist)
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.
RooMinuit is a wrapper class around TFitter/TMinuit that provides a seamless interface between the MI...
Int_t hesse()
Execute HESSE.
void setEps(double eps)
Change MINUIT epsilon.
RooMinuit(RooAbsReal &function)
Construct MINUIT interface to given function.
void setProfile(bool flag=true)
RooArgList * _floatParamList
void setOffsetting(bool flag)
Enable internal likelihood offsetting for enhanced numeric precision.
~RooMinuit() override
Destructor.
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
bool synchronize(bool verbose)
Internal function to synchronize TMinuit with current information in RooAbsReal function parameters.
virtual bool setPdfParamVal(Int_t index, double value, bool verbose=false)
Modify PDF parameter value by ordinal index (needed by MINUIT)
void setErrorLevel(double level)
Set the level for MINUIT error analysis to the given value.
static void cleanup()
Cleanup method called by atexit handler installed by RooSentinel to delete all global heap objects wh...
Int_t seek()
Execute SEEK.
Int_t simplex()
Execute SIMPLEX.
RooFitResult * save(const char *name=nullptr, const char *title=nullptr)
Save and return a RooFitResult snaphot of current minimizer status.
void saveStatus(const char *label, Int_t status)
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
std::vector< std::pair< std::string, int > > _statusHistory
std::vector< RooAbsArg * > _floatParamVec
Int_t migrad()
Execute MIGRAD.
std::ofstream * logfile() const
bool setLogFile(const char *logfile=nullptr)
Change the file name for logging of a RooMinuit of all MINUIT steppings through the parameter space.
double getPdfParamVal(Int_t index)
Access PDF parameter value by ordinal index (needed by MINUIT)
Int_t setWarnLevel(Int_t newLevel)
Set MINUIT warning level to given level.
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
void backProp()
Transfer MINUIT fit results back into RooFit objects.
double getPdfParamErr(Int_t index)
Access PDF parameter error by ordinal index (needed by MINUIT)
RooArgList * _initConstParamList
friend void RooMinuitGlue(Int_t &np, double *gin, double &f, double *par, Int_t flag)
RooArgList * _initFloatParamList
void setPdfParamErr(Int_t index, double value)
Modify PDF parameter error by ordinal index (needed by MINUIT)
void profileStop()
Stop profiling timer and report results of last session.
Int_t minos()
Execute MINOS.
void clearPdfParamAsymErr(Int_t index)
Modify PDF parameter error by ordinal index (needed by MINUIT)
Int_t improve()
Execute IMPROVE.
void profileStart()
Start profiling timer.
void setNoWarn()
Instruct MINUIT to suppress warnings.
RooArgList * _constParamList
void setVerbose(bool flag=true)
RooPlot * contour(RooRealVar &var1, RooRealVar &var2, double n1=1, double n2=2, double n3=0.0, double n4=0.0, double n5=0.0, double n6=0.0)
Create and draw a TH2 with the error contours in parameters var1 and v2 at up to 6 'sigma' settings w...
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
static TVirtualFitter * _theFitter
static RooMsgService & instance()
Return reference to singleton instance.
A RooPlot is a plot frame and a container for graphics objects within that frame.
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
RooRealVar represents a variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
TClass * IsA() const override
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
<div class="legacybox"><h2>Legacy Code</h2> TFitter is a legacy interface: there will be no bug fixes...
A TGraph is an object made of two arrays X and Y with npoints each.
virtual Int_t SetErrorDef(Double_t up)
To get the n-sigma contour the error def parameter "up" has to set to n^2.
virtual TObject * Contour(Int_t npoints=10, Int_t pa1=0, Int_t pa2=1)
Creates a TGraph object describing the n-sigma contour of a TMinuit fit.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
virtual const char * GetName() const
Returns name of object.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
void Print(Option_t *option="") const override
Print the real and cpu time passed between the start and stop events.
void ToLower()
Change string to lower-case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Abstract Base Class for Fitting.
virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const =0
virtual void SetObjectFit(TObject *obj)
virtual void ReleaseParameter(Int_t ipar)=0
void Clear(Option_t *option="") override=0
Set name and title to empty strings ("").
virtual void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
To set the address of the minimization objective function called by the native compiler (see function...
virtual Int_t SetParameter(Int_t ipar, const char *parname, Double_t value, Double_t verr, Double_t vlow, Double_t vhigh)=0
virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs)=0
virtual Double_t GetParameter(Int_t ipar) const =0
virtual void FixParameter(Int_t ipar)=0
virtual Int_t GetErrors(Int_t ipar, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const =0