diff --git a/roofit/roofitcore/CMakeLists.txt b/roofit/roofitcore/CMakeLists.txt index d9fc3e6ab1071..840392a09eee9 100644 --- a/roofit/roofitcore/CMakeLists.txt +++ b/roofit/roofitcore/CMakeLists.txt @@ -225,7 +225,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore RooBinWidthFunction.h RooFitLegacy/RooCatTypeLegacy.h RooFitLegacy/RooCategorySharedProperties.h - RooFitLegacy/RooMinuit.h RooFitLegacy/RooTreeData.h RooFit/TestStatistics/LikelihoodGradientWrapper.h RooFit/TestStatistics/LikelihoodWrapper.h @@ -452,7 +451,6 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore src/RooBinSamplingPdf.cxx src/RooBinWidthFunction.cxx src/RooFitLegacy/RooCatTypeLegacy.cxx - src/RooFitLegacy/RooMinuit.cxx src/RunContext.cxx src/TestStatistics/ConstantTermsOptimizer.cxx src/TestStatistics/LikelihoodGradientWrapper.cxx diff --git a/roofit/roofitcore/inc/RooAbsData.h b/roofit/roofitcore/inc/RooAbsData.h index 285e9a6a10bc2..2704af269bce7 100644 --- a/roofit/roofitcore/inc/RooAbsData.h +++ b/roofit/roofitcore/inc/RooAbsData.h @@ -25,7 +25,6 @@ #include "RooFit/UniqueId.h" #include "RooFit/Detail/DataMap.h" -#include // R__DEPRECATED #include "TNamed.h" #include @@ -216,17 +215,11 @@ class RooAbsData : public TNamed, public RooPrintable { const RooCmdArg& arg3=RooCmdArg::none(), const RooCmdArg& arg4=RooCmdArg::none(), const RooCmdArg& arg5=RooCmdArg::none(), const RooCmdArg& arg6=RooCmdArg::none(), const RooCmdArg& arg7=RooCmdArg::none(), const RooCmdArg& arg8=RooCmdArg::none()) const ; - // Developer note: the `binArgX` parameter has no default `none` value, - // because then the signature would be ambiguous with the deprecated bin - // integer overload below. When the deprecated overload is removed, a default - // value must be set (tutorial failures will remind us to do that). TH1 *createHistogram(const char* varNameList, - const RooCmdArg& binArgX, const RooCmdArg& binArgY=RooCmdArg::none(), + const RooCmdArg& binArgX=RooCmdArg::none(), const RooCmdArg& binArgY=RooCmdArg::none(), const RooCmdArg& binArgZ=RooCmdArg::none()) const; /// Create and fill a ROOT histogram TH1,TH2 or TH3 with the values of this dataset. TH1 *createHistogram(const char *name, const RooAbsRealLValue& xvar, const RooLinkedList& argList) const ; - TH1 *createHistogram(const char* varNameList, Int_t xbins=0, Int_t ybins=0, Int_t zbins=0) const - R__DEPRECATED(6, 30, "Use the overload of RooAbsData::createHistogram that takes RooFit command arguments."); TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, const char* cuts="", const char *name= "hist") const; TH2F* createHistogram(const RooAbsRealLValue& var1, const RooAbsRealLValue& var2, int nx, int ny, diff --git a/roofit/roofitcore/inc/RooFitLegacy/RooMinuit.h b/roofit/roofitcore/inc/RooFitLegacy/RooMinuit.h deleted file mode 100644 index a241cbbb33dd2..0000000000000 --- a/roofit/roofitcore/inc/RooFitLegacy/RooMinuit.h +++ /dev/null @@ -1,158 +0,0 @@ -/***************************************************************************** - * Project: RooFit * - * Package: RooFitCore * - * File: $Id: RooMinuit.h,v 1.15 2007/07/12 20:30:28 wouter Exp $ - * Authors: * - * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * - * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * - * * - * Copyright (c) 2000-2005, Regents of the University of California * - * and Stanford University. All rights reserved. * - * * - * Redistribution and use in source and binary forms, * - * with or without modification, are permitted according to the terms * - * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * - *****************************************************************************/ -#ifndef ROO_MINUIT -#define ROO_MINUIT - -#include "TObject.h" -#include "TStopwatch.h" -#include -#include "TMatrixDSymfwd.h" -#include -#include -#include - -#include - -class RooAbsReal ; -class RooFitResult ; -class RooArgList ; -class RooRealVar ; -class RooArgSet ; -class RooAbsArg ; -class TVirtualFitter ; -class TH2F ; -class RooPlot ; - -void RooMinuitGlue(Int_t& /*np*/, double* /*gin*/, double &f, double *par, Int_t /*flag*/) ; - -class RooMinuit : public TObject { -public: - - RooMinuit(RooAbsReal& function) ; - ~RooMinuit() override ; - - enum Strategy { Speed=0, Balance=1, Robustness=2 } ; - enum PrintLevel { None=-1, Reduced=0, Normal=1, ExtraForProblem=2, Maximum=3 } ; - void setStrategy(Int_t strat) ; - void setErrorLevel(double level) ; - void setEps(double eps) ; - void optimizeConst(Int_t flag) ; - void setEvalErrorWall(bool flag) { _doEvalErrorWall = flag ; } - void setOffsetting(bool flag) ; - - RooFitResult* fit(const char* options) ; - - Int_t migrad() ; - Int_t hesse() ; - Int_t minos() ; - Int_t minos(const RooArgSet& minosParamList) ; // added FMV, 08/18/03 - Int_t seek() ; - Int_t simplex() ; - Int_t improve() ; - - RooFitResult* save(const char* name=nullptr, const char* title=nullptr) ; - 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) ; - - Int_t setPrintLevel(Int_t newLevel) ; - void setNoWarn() ; - Int_t setWarnLevel(Int_t newLevel) ; - void setPrintEvalErrors(Int_t numEvalErrors) { _printEvalErrors = numEvalErrors ; } - void setVerbose(bool flag=true) { _verbose = flag ; } - void setProfile(bool flag=true) { _profile = flag ; } - void setMaxEvalMultiplier(Int_t n) { _maxEvalMult = n ; } - bool setLogFile(const char* logfile=nullptr) ; - - static void cleanup() ; - - Int_t evalCounter() const { return _evalCounter ; } - void zeroEvalCount() { _evalCounter = 0 ; } - -protected: - - friend class RooAbsPdf ; - void applyCovarianceMatrix(TMatrixDSym& V) ; - - friend void RooMinuitGlue(Int_t &np, double *gin, double &f, double *par, Int_t flag) ; - - void profileStart() ; - void profileStop() ; - - bool synchronize(bool verbose) ; - void backProp() ; - - inline Int_t getNPar() const { return _nPar ; } - inline std::ofstream* logfile() const { return _logfile ; } - inline double& maxFCN() { return _maxFCN ; } - - double getPdfParamVal(Int_t index) ; - double getPdfParamErr(Int_t index) ; - virtual bool setPdfParamVal(Int_t index, double value, bool verbose=false) ; - void setPdfParamErr(Int_t index, double value) ; - void setPdfParamErr(Int_t index, double loVal, double hiVal) ; - void clearPdfParamAsymErr(Int_t index) ; - - void saveStatus(const char* label, Int_t status) { _statusHistory.push_back(std::pair(label,status)) ; } - - void updateFloatVec() ; - -private: - - Int_t _evalCounter ; - Int_t _printLevel ; - Int_t _warnLevel ; - Int_t _status ; - Int_t _optConst ; - bool _profile ; - bool _handleLocalErrors ; - Int_t _numBadNLL ; - Int_t _nPar ; - Int_t _printEvalErrors ; - bool _doEvalErrorWall ; - Int_t _maxEvalMult ; - RooArgList* _floatParamList ; - std::vector _floatParamVec ; - RooArgList* _initFloatParamList ; - RooArgList* _constParamList ; - RooArgList* _initConstParamList ; - RooAbsReal* _func ; - - double _maxFCN ; - std::ofstream* _logfile ; - bool _verbose ; - TStopwatch _timer ; - TStopwatch _cumulTimer ; - - TMatrixDSym* _extV ; - - static TVirtualFitter *_theFitter ; - - std::vector > _statusHistory ; - - RooMinuit(const RooMinuit&) ; - -// Undocumented preprocessor define such that the implementation in -// RooMinuit.cxx can suppress the deprecation warning. -#ifndef __ROOFIT_SUPPRESS_ROOMINIMIZER_DEPRECATION_WARNING -} R__DEPRECATED(6, 30, "Please use RooMinimizer instead of RooMinuit"); -#else -}; -#endif - - -#endif - diff --git a/roofit/roofitcore/inc/RooFitResult.h b/roofit/roofitcore/inc/RooFitResult.h index 8b0bf18d5d1d7..4356f6ef93cd1 100644 --- a/roofit/roofitcore/inc/RooFitResult.h +++ b/roofit/roofitcore/inc/RooFitResult.h @@ -160,7 +160,6 @@ class RooFitResult : public TNamed, public RooPrintable, public RooDirItem { protected: friend class RooAbsPdf ; - friend class RooMinuit ; friend class RooMinimizer ; void setCovarianceMatrix(TMatrixDSym& V) ; void setConstParList(const RooArgList& list) ; diff --git a/roofit/roofitcore/inc/RooMinuit.h b/roofit/roofitcore/inc/RooMinuit.h deleted file mode 100644 index 1bb80cfe270c7..0000000000000 --- a/roofit/roofitcore/inc/RooMinuit.h +++ /dev/null @@ -1,5 +0,0 @@ -#warning "The deprecated RooMinuit class was replaced by the more general RooMinimizer. \ -The RooMinuit class will be gone in ROOT 6.30! \ -Migrating to the RooMinimizer is easy because the interface is backwards compatible. - -#include "RooFitLegacy/RooMinuit.h" diff --git a/roofit/roofitcore/src/RooAbsData.cxx b/roofit/roofitcore/src/RooAbsData.cxx index 334f8fe5a74b6..be8019c532e75 100644 --- a/roofit/roofitcore/src/RooAbsData.cxx +++ b/roofit/roofitcore/src/RooAbsData.cxx @@ -608,80 +608,6 @@ RooPlot* RooAbsData::plotOn(RooPlot* frame, const RooCmdArg& arg1, const RooCmdA return plotOn(frame,l) ; } -//////////////////////////////////////////////////////////////////////////////// -/// Create and fill a ROOT histogram TH1,TH2 or TH3 with the values of this dataset for the variables with given names -/// The range of each observable that is histogrammed is always automatically calculated from the distribution in -/// the dataset. The number of bins can be controlled using the [xyz]bins parameters. For a greater degree of control -/// use the createHistogram() method below with named arguments -/// -/// The caller takes ownership of the returned histogram -/// -/// \deprecated This function is deprecated and will be removed in ROOT v6.30. -/// Use the overload -/// RooAbsData::createHistogram(const char*, const RooCmdArg&, const RooCmdArg&, const RooCmdArg&) -/// that takes RooFit command arguments. - -TH1 *RooAbsData::createHistogram(const char* varNameList, Int_t xbins, Int_t ybins, Int_t zbins) const -{ - coutW(DataHandling) << "'RooAbsData::createHistogram' is deprecated and will be removed in ROOT v6.30: " - << "Use the overload of 'RooAbsData::createHistogram' that takes RooFit command arguments." - << std::endl; - - // Parse list of variable names - const auto varNames = ROOT::Split(varNameList, ",:"); - RooLinkedList argList; - RooRealVar* vars[3] = {nullptr, nullptr, nullptr}; - - for (unsigned int i = 0; i < varNames.size(); ++i) { - if (i >= 3) { - coutW(InputArguments) << "RooAbsData::createHistogram(" << GetName() << "): Can only create 3-dimensional histograms. Variable " - << i << " " << varNames[i] << " unused." << std::endl; - continue; - } - - vars[i] = static_cast( get()->find(varNames[i].data()) ); - if (!vars[i]) { - coutE(InputArguments) << "RooAbsData::createHistogram(" << GetName() << ") ERROR: dataset does not contain an observable named " << varNames[i] << std::endl; - return nullptr; - } - } - - if (!vars[0]) { - coutE(InputArguments) << "RooAbsData::createHistogram(" << GetName() << "): No variable to be histogrammed in list '" << varNameList << "'" << std::endl; - return nullptr; - } - - if (xbins<=0 || !vars[0]->hasMax() || !vars[0]->hasMin() ) { - argList.Add(RooFit::AutoBinning(xbins==0?vars[0]->numBins():abs(xbins)).Clone()) ; - } else { - argList.Add(RooFit::Binning(xbins).Clone()) ; - } - - if (vars[1]) { - if (ybins<=0 || !vars[1]->hasMax() || !vars[1]->hasMin() ) { - argList.Add(RooFit::YVar(*vars[1],RooFit::AutoBinning(ybins==0?vars[1]->numBins():abs(ybins))).Clone()) ; - } else { - argList.Add(RooFit::YVar(*vars[1],RooFit::Binning(ybins)).Clone()) ; - } - } - if (vars[2]) { - if (zbins<=0 || !vars[2]->hasMax() || !vars[2]->hasMin() ) { - argList.Add(RooFit::ZVar(*vars[2],RooFit::AutoBinning(zbins==0?vars[2]->numBins():abs(zbins))).Clone()) ; - } else { - argList.Add(RooFit::ZVar(*vars[2],RooFit::Binning(zbins)).Clone()) ; - } - } - - - // Call implementation function - TH1* result = createHistogram(GetName(), *vars[0], argList); - - // Delete temporary list of RooCmdArgs - argList.Delete() ; - - return result ; -} - TH1 *RooAbsData::createHistogram(const char *name, const RooAbsRealLValue& xvar, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4, diff --git a/roofit/roofitcore/src/RooFitLegacy/RooMinuit.cxx b/roofit/roofitcore/src/RooFitLegacy/RooMinuit.cxx deleted file mode 100644 index b69d0a48d3312..0000000000000 --- a/roofit/roofitcore/src/RooFitLegacy/RooMinuit.cxx +++ /dev/null @@ -1,1253 +0,0 @@ -/***************************************************************************** - * Project: RooFit * - * Package: RooFitCore * - * @(#)root/roofitcore:$Id$ - * Authors: * - * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * - * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * - * * - * Copyright (c) 2000-2005, Regents of the University of California * - * and Stanford University. All rights reserved. * - * * - * Redistribution and use in source and binary forms, * - * with or without modification, are permitted according to the terms * - * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * - *****************************************************************************/ - -/** -\file RooMinuit.cxx -\class RooMinuit -\ingroup Roofitlegacy - -RooMinuit is a wrapper class around TFitter/TMinuit that -provides a seamless interface between the MINUIT functionality -and the native RooFit interface. -RooMinuit can minimize any RooAbsReal function with respect to -its parameters. Usual choices for minimization are RooNLLVar -and RooChi2Var -RooMinuit has methods corresponding to MINUIT functions like -hesse(), migrad(), minos() etc. In each of these function calls -the state of the MINUIT engine is synchronized with the state -of the RooFit variables: any change in variables, change -in the constant status etc is forwarded to MINUIT prior to -execution of the MINUIT call. Afterwards the RooFit objects -are resynchronized with the output state of MINUIT: changes -parameter values, errors are propagated. -Various methods are available to control verbosity, profiling, -automatic PDF optimization. -**/ - -// At least for building the implementation we have to suppress the deprecation warning -#define __ROOFIT_SUPPRESS_ROOMINIMIZER_DEPRECATION_WARNING -#include "RooFitLegacy/RooMinuit.h" -#undef __ROOFIT_SUPPRESS_ROOMINIMIZER_DEPRECATION_WARNING - -#include "TClass.h" - -#include -#include -#include -#include "TMarker.h" -#include "TGraph.h" -#include "TStopwatch.h" -#include "TFitter.h" -#include "TMinuit.h" -#include "TMatrixDSym.h" -#include "RooArgSet.h" -#include "RooArgList.h" -#include "RooAbsReal.h" -#include "RooAbsRealLValue.h" -#include "RooRealVar.h" -#include "RooFitResult.h" -#include "RooAbsPdf.h" -#include "../RooSentinel.h" -#include "RooMsgService.h" -#include "RooPlot.h" - - -#if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3) -char* operator+( streampos&, char* ); -#endif - -using namespace std; - - -TVirtualFitter *RooMinuit::_theFitter = nullptr; - - - -//////////////////////////////////////////////////////////////////////////////// -/// Cleanup method called by atexit handler installed by RooSentinel -/// to delete all global heap objects when the program is terminated - -void RooMinuit::cleanup() -{ - if (_theFitter) { - delete _theFitter ; - _theFitter =0 ; - } -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Construct MINUIT interface to given function. Function can be anything, -/// but is typically a -log(likelihood) implemented by RooNLLVar or a chi^2 -/// (implemented by RooChi2Var). Other frequent use cases are a RooAddition -/// of a RooNLLVar plus a penalty or constraint term. This class propagates -/// all RooFit information (floating parameters, their values and errors) -/// to MINUIT before each MINUIT call and propagates all MINUIT information -/// back to the RooFit object at the end of each call (updated parameter -/// values, their (asymmetric errors) etc. The default MINUIT error level -/// for HESSE and MINOS error analysis is taken from the defaultErrorLevel() -/// value of the input function. - -RooMinuit::RooMinuit(RooAbsReal& function) -{ - RooSentinel::activate() ; - - // Store function reference - _evalCounter = 0 ; - _extV = 0 ; - _func = &function ; - _logfile = 0 ; - _optConst = false ; - _verbose = false ; - _profile = false ; - _handleLocalErrors = true ; - _printLevel = 1 ; - _printEvalErrors = 10 ; - _warnLevel = -999 ; - _maxEvalMult = 500 ; - _doEvalErrorWall = true ; - - // Examine parameter list - RooArgSet* paramSet = function.getParameters(RooArgSet()) ; - RooArgList paramList(*paramSet) ; - delete paramSet ; - - _floatParamList = (RooArgList*) paramList.selectByAttrib("Constant",false) ; - if (_floatParamList->getSize()>1) { - _floatParamList->sort() ; - } - _floatParamList->setName("floatParamList") ; - - _constParamList = (RooArgList*) paramList.selectByAttrib("Constant",true) ; - if (_constParamList->getSize()>1) { - _constParamList->sort() ; - } - _constParamList->setName("constParamList") ; - - // Remove all non-RooRealVar parameters from list (MINUIT cannot handle them) - for (RooAbsArg * arg : *_floatParamList) { - if (!arg->IsA()->InheritsFrom(RooAbsRealLValue::Class())) { - coutW(Minimization) << "RooMinuit::RooMinuit: removing parameter " << arg->GetName() - << " from list because it is not of type RooRealVar" << endl ; - _floatParamList->remove(*arg) ; - } - } - _nPar = _floatParamList->getSize() ; - - updateFloatVec() ; - - // Save snapshot of initial lists - _initFloatParamList = (RooArgList*) _floatParamList->snapshot(false) ; - _initConstParamList = (RooArgList*) _constParamList->snapshot(false) ; - - // Initialize MINUIT - Int_t nPar= _floatParamList->getSize() + _constParamList->getSize() ; - if (_theFitter) delete _theFitter ; - _theFitter = new TFitter(nPar*2+1) ; //WVE Kludge, nPar*2 works around TMinuit memory allocation bug - _theFitter->SetObjectFit(this) ; - - // Shut up for now - setPrintLevel(-1) ; - _theFitter->Clear(); - - // Tell MINUIT to use our global glue function - _theFitter->SetFCN(RooMinuitGlue); - - // Use +0.5 for 1-sigma errors - setErrorLevel(function.defaultErrorLevel()) ; - - // Declare our parameters to MINUIT - synchronize(false) ; - - // Reset the *largest* negative log-likelihood value we have seen so far - _maxFCN= -1e30 ; - _numBadNLL = 0 ; - - // Now set default verbosity - if (RooMsgService::instance().silentMode()) { - setWarnLevel(-1) ; - setPrintLevel(-1) ; - } else { - setWarnLevel(1) ; - setPrintLevel(1) ; - } -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Destructor - -RooMinuit::~RooMinuit() -{ - delete _floatParamList ; - delete _initFloatParamList ; - delete _constParamList ; - delete _initConstParamList ; - if (_extV) { - delete _extV ; - } -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Change MINUIT strategy to istrat. Accepted codes -/// are 0,1,2 and represent MINUIT strategies for dealing -/// most efficiently with fast FCNs (0), expensive FCNs (2) -/// and 'intermediate' FCNs (1) - -void RooMinuit::setStrategy(Int_t istrat) -{ - double stratArg(istrat) ; - _theFitter->ExecuteCommand("SET STR",&stratArg,1) ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Set the level for MINUIT error analysis to the given -/// value. This function overrides the default value -/// that is taken in the RooMinuit constructor from -/// the defaultErrorLevel() method of the input function - -void RooMinuit::setErrorLevel(double level) -{ - _theFitter->ExecuteCommand("SET ERR",&level,1); -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Change MINUIT epsilon - -void RooMinuit::setEps(double eps) -{ - _theFitter->ExecuteCommand("SET EPS",&eps,1) ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Enable internal likelihood offsetting for enhanced numeric precision - -void RooMinuit::setOffsetting(bool flag) -{ - _func->enableOffsetting(flag) ; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Parse traditional RooAbsPdf::fitTo driver options -/// -/// s - Run Hesse first to estimate initial step size -/// m - Run Migrad only -/// h - Run Hesse to estimate errors -/// v - Verbose mode -/// l - Log parameters after each Minuit steps to file -/// t - Activate profile timer -/// r - Save fit result -/// 0 - Run Migrad with strategy 0 - -RooFitResult* RooMinuit::fit(const char* options) -{ - if (_floatParamList->empty()) { - return 0 ; - } - - _theFitter->SetObjectFit(this) ; - - TString opts(options) ; - opts.ToLower() ; - - // Initial configuration - if (opts.Contains("v")) setVerbose(1) ; - if (opts.Contains("t")) setProfile(1) ; - if (opts.Contains("l")) setLogFile(Form("%s.log",_func->GetName())) ; - if (opts.Contains("c")) optimizeConst(1) ; - - // Fitting steps - if (opts.Contains("s")) hesse() ; - if (opts.Contains("0")) setStrategy(0) ; - migrad() ; - if (opts.Contains("0")) setStrategy(1) ; - if (opts.Contains("h")||!opts.Contains("m")) hesse() ; - if (!opts.Contains("m")) minos() ; - - return (opts.Contains("r")) ? save() : 0 ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Execute MIGRAD. Changes in parameter values -/// and calculated errors are automatically -/// propagated back the RooRealVars representing -/// the floating parameters in the MINUIT operation - -Int_t RooMinuit::migrad() -{ - if (_floatParamList->empty()) { - return -1 ; - } - - _theFitter->SetObjectFit(this) ; - - double arglist[2]; - arglist[0]= _maxEvalMult*_nPar; // maximum iterations - arglist[1]= 1.0; // tolerance - - synchronize(_verbose) ; - profileStart() ; - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - RooAbsReal::clearEvalErrorLog() ; - _status= _theFitter->ExecuteCommand("MIGRAD",arglist,2); - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - profileStop() ; - backProp() ; - - saveStatus("MIGRAD",_status) ; - - return _status ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Execute HESSE. Changes in parameter values -/// and calculated errors are automatically -/// propagated back the RooRealVars representing -/// the floating parameters in the MINUIT operation - -Int_t RooMinuit::hesse() -{ - if (_floatParamList->empty()) { - return -1 ; - } - - _theFitter->SetObjectFit(this) ; - - double arglist[2]; - arglist[0]= _maxEvalMult*_nPar; // maximum iterations - - synchronize(_verbose) ; - profileStart() ; - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - RooAbsReal::clearEvalErrorLog() ; - _status= _theFitter->ExecuteCommand("HESSE",arglist,1); - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - profileStop() ; - backProp() ; - - saveStatus("HESSE",_status) ; - - return _status ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Execute MINOS. Changes in parameter values -/// and calculated errors are automatically -/// propagated back the RooRealVars representing -/// the floating parameters in the MINUIT operation - -Int_t RooMinuit::minos() -{ - if (_floatParamList->empty()) { - return -1 ; - } - - _theFitter->SetObjectFit(this) ; - - double arglist[2]; - arglist[0]= _maxEvalMult*_nPar; // maximum iterations - - synchronize(_verbose) ; - profileStart() ; - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - RooAbsReal::clearEvalErrorLog() ; - _status= _theFitter->ExecuteCommand("MINOS",arglist,1); - // check also the status of Minos looking at fCstatu - if (_status == 0 && gMinuit->fCstatu != "SUCCESSFUL") { - if (gMinuit->fCstatu == "FAILURE" || - gMinuit->fCstatu == "PROBLEMS") _status = 5; - _status = 6; - } - - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - profileStop() ; - backProp() ; - - saveStatus("MINOS",_status) ; - return _status ; -} - - -// added FMV, 08/18/03 - -//////////////////////////////////////////////////////////////////////////////// -/// Execute MINOS for given list of parameters. Changes in parameter values -/// and calculated errors are automatically -/// propagated back the RooRealVars representing -/// the floating parameters in the MINUIT operation - -Int_t RooMinuit::minos(const RooArgSet& minosParamList) -{ - if (_floatParamList->empty()) { - return -1 ; - } - - _theFitter->SetObjectFit(this) ; - - Int_t nMinosPar(0) ; - double* arglist = new double[_nPar+1]; - - if (minosParamList.getSize()>0) { - for(RooAbsArg * arg : minosParamList) { - RooAbsArg* par = _floatParamList->find(arg->GetName()); - if (par && !par->isConstant()) { - Int_t index = _floatParamList->index(par); - nMinosPar++; - arglist[nMinosPar]=index+1; - } - } - } - arglist[0]= _maxEvalMult*_nPar; // maximum iterations - - synchronize(_verbose) ; - profileStart() ; - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - RooAbsReal::clearEvalErrorLog() ; - _status= _theFitter->ExecuteCommand("MINOS",arglist,1+nMinosPar); - // check also the status of Minos looking at fCstatu - if (_status == 0 && gMinuit->fCstatu != "SUCCESSFUL") { - if (gMinuit->fCstatu == "FAILURE" || - gMinuit->fCstatu == "PROBLEMS") _status = 5; - _status = 6; - } - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - profileStop() ; - backProp() ; - - delete[] arglist ; - - saveStatus("MINOS",_status) ; - - return _status ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Execute SEEK. Changes in parameter values -/// and calculated errors are automatically -/// propagated back the RooRealVars representing -/// the floating parameters in the MINUIT operation - -Int_t RooMinuit::seek() -{ - if (_floatParamList->empty()) { - return -1 ; - } - - _theFitter->SetObjectFit(this) ; - - double arglist[2]; - arglist[0]= _maxEvalMult*_nPar; // maximum iterations - - synchronize(_verbose) ; - profileStart() ; - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - RooAbsReal::clearEvalErrorLog() ; - _status= _theFitter->ExecuteCommand("SEEK",arglist,1); - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - profileStop() ; - backProp() ; - - saveStatus("SEEK",_status) ; - - return _status ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Execute SIMPLEX. Changes in parameter values -/// and calculated errors are automatically -/// propagated back the RooRealVars representing -/// the floating parameters in the MINUIT operation - -Int_t RooMinuit::simplex() -{ - if (_floatParamList->empty()) { - return -1 ; - } - - _theFitter->SetObjectFit(this) ; - - double arglist[2]; - arglist[0]= _maxEvalMult*_nPar; // maximum iterations - arglist[1]= 1.0; // tolerance - - synchronize(_verbose) ; - profileStart() ; - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - RooAbsReal::clearEvalErrorLog() ; - _status= _theFitter->ExecuteCommand("SIMPLEX",arglist,2); - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - profileStop() ; - backProp() ; - - saveStatus("SIMPLEX",_status) ; - - return _status ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Execute IMPROVE. Changes in parameter values -/// and calculated errors are automatically -/// propagated back the RooRealVars representing -/// the floating parameters in the MINUIT operation - -Int_t RooMinuit::improve() -{ - if (_floatParamList->empty()) { - return -1 ; - } - - _theFitter->SetObjectFit(this) ; - - double arglist[2]; - arglist[0]= _maxEvalMult*_nPar; // maximum iterations - - synchronize(_verbose) ; - profileStart() ; - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - RooAbsReal::clearEvalErrorLog() ; - _status= _theFitter->ExecuteCommand("IMPROVE",arglist,1); - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - profileStop() ; - backProp() ; - - saveStatus("IMPROVE",_status) ; - - return _status ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Change the MINUIT internal printing level - -Int_t RooMinuit::setPrintLevel(Int_t newLevel) -{ - Int_t ret = _printLevel ; - double arg(newLevel) ; - _theFitter->ExecuteCommand("SET PRINT",&arg,1); - _printLevel = newLevel ; - return ret ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Instruct MINUIT to suppress warnings - -void RooMinuit::setNoWarn() -{ - double arg(0) ; - _theFitter->ExecuteCommand("SET NOWARNINGS",&arg,1); - _warnLevel = -1 ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Set MINUIT warning level to given level - -Int_t RooMinuit::setWarnLevel(Int_t newLevel) -{ - if (newLevel==_warnLevel) { - return _warnLevel ; - } - - Int_t ret = _warnLevel ; - double arg(newLevel) ; - - if (newLevel>=0) { - _theFitter->ExecuteCommand("SET WARNINGS",&arg,1); - } else { - double arg2(0) ; - _theFitter->ExecuteCommand("SET NOWARNINGS",&arg2,1); - } - _warnLevel = newLevel ; - - return ret ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Internal function to synchronize TMinuit with current -/// information in RooAbsReal function parameters - -bool RooMinuit::synchronize(bool verbose) -{ - Int_t oldPrint = setPrintLevel(-1) ; - gMinuit->fNwrmes[0] = 0; // to clear buffer - Int_t oldWarn = setWarnLevel(-1) ; - - bool constValChange(false) ; - bool constStatChange(false) ; - - Int_t index(0) ; - - // Handle eventual migrations from constParamList -> floatParamList - for(index= 0; index < _constParamList->getSize() ; index++) { - RooRealVar *par= dynamic_cast(_constParamList->at(index)) ; - if (!par) continue ; - - RooRealVar *oldpar= dynamic_cast(_initConstParamList->at(index)) ; - if (!oldpar) continue ; - - // Test if constness changed - if (!par->isConstant()) { - - // Remove from constList, add to floatList - _constParamList->remove(*par) ; - _floatParamList->add(*par) ; - _initFloatParamList->addClone(*oldpar) ; - _initConstParamList->remove(*oldpar) ; - constStatChange=true ; - _nPar++ ; - - if (verbose) { - coutI(Minimization) << "RooMinuit::synchronize: parameter " << par->GetName() << " is now floating." << endl ; - } - } - - // Test if value changed - if (par->getVal()!= oldpar->getVal()) { - constValChange=true ; - if (verbose) { - coutI(Minimization) << "RooMinuit::synchronize: value of constant parameter " << par->GetName() - << " changed from " << oldpar->getVal() << " to " << par->getVal() << endl ; - } - } - - } - - // Update reference list - _initConstParamList->assign(*_constParamList) ; - - - // Synchronize MINUIT with function state - for(index= 0; index < _nPar; index++) { - RooRealVar *par= dynamic_cast(_floatParamList->at(index)) ; - if (!par) continue ; - - double pstep(0) ; - double pmin(0) ; - double pmax(0) ; - - if(!par->isConstant()) { - - // Verify that floating parameter is indeed of type RooRealVar - if (!par->IsA()->InheritsFrom(RooRealVar::Class())) { - coutW(Minimization) << "RooMinuit::fit: Error, non-constant parameter " << par->GetName() - << " is not of type RooRealVar, skipping" << endl ; - continue ; - } - - // Set the limits, if not infinite - if (par->hasMin() && par->hasMax()) { - pmin = par->getMin(); - pmax = par->getMax(); - } - - // Calculate step size - pstep= par->getError(); - if(pstep <= 0) { - // Floating parameter without error estitimate - if (par->hasMin() && par->hasMax()) { - pstep= 0.1*(pmax-pmin); - - // Trim default choice of error if within 2 sigma of limit - if (pmax - par->getVal() < 2*pstep) { - pstep = (pmax - par->getVal())/2 ; - } else if (par->getVal() - pmin < 2*pstep) { - pstep = (par->getVal() - pmin )/2 ; - } - - // If trimming results in zero error, restore default - if (pstep==0) { - pstep= 0.1*(pmax-pmin); - } - - } else { - pstep=1 ; - } - if(_verbose) { - coutW(Minimization) << "RooMinuit::synchronize: WARNING: no initial error estimate available for " - << par->GetName() << ": using " << pstep << endl; - } - } - } else { - pmin = par->getVal() ; - pmax = par->getVal() ; - } - - // Extract previous information - double oldVar,oldVerr,oldVlo,oldVhi ; - char oldParname[100] ; - Int_t ierr = _theFitter->GetParameter(index,oldParname,oldVar,oldVerr,oldVlo,oldVhi) ; - - // Determine if parameters is currently fixed in MINUIT - - Int_t ix ; - bool oldFixed(false) ; - if (ierr>=0) { - for (ix = 1; ix <= gMinuit->fNpfix; ++ix) { - if (gMinuit->fIpfix[ix-1] == index+1) oldFixed=true ; - } - } - - if (par->isConstant() && !oldFixed) { - - // Parameter changes floating -> constant : update only value if necessary - if (oldVar!=par->getVal()) { - double arglist[2] ; - arglist[0] = index+1 ; - arglist[1] = par->getVal() ; - _theFitter->ExecuteCommand("SET PAR",arglist,2) ; - if (verbose) { - coutI(Minimization) << "RooMinuit::synchronize: value of parameter " << par->GetName() << " changed from " << oldVar << " to " << par->getVal() << endl ; - } - } - - _theFitter->FixParameter(index) ; - constStatChange=true ; - if (verbose) { - coutI(Minimization) << "RooMinuit::synchronize: parameter " << par->GetName() << " is now fixed." << endl ; - } - - } else if (par->isConstant() && oldFixed) { - - // Parameter changes constant -> constant : update only value if necessary - if (oldVar!=par->getVal()) { - double arglist[2] ; - arglist[0] = index+1 ; - arglist[1] = par->getVal() ; - _theFitter->ExecuteCommand("SET PAR",arglist,2) ; - constValChange=true ; - - if (verbose) { - coutI(Minimization) << "RooMinuit::synchronize: value of fixed parameter " << par->GetName() << " changed from " << oldVar << " to " << par->getVal() << endl ; - } - } - - } else { - - if (!par->isConstant() && oldFixed) { - _theFitter->ReleaseParameter(index) ; - constStatChange=true ; - - if (verbose) { - coutI(Minimization) << "RooMinuit::synchronize: parameter " << par->GetName() << " is now floating." << endl ; - } - } - - // Parameter changes constant -> floating : update all if necessary - if (oldVar!=par->getVal() || oldVlo!=pmin || oldVhi != pmax || oldVerr!=pstep) { - _theFitter->SetParameter(index, par->GetName(), par->getVal(), pstep, pmin, pmax); - } - - // Inform user about changes in verbose mode - if (verbose && ierr>=0) { - // if ierr<0, par was moved from the const list and a message was already printed - - if (oldVar!=par->getVal()) { - coutI(Minimization) << "RooMinuit::synchronize: value of parameter " << par->GetName() << " changed from " << oldVar << " to " << par->getVal() << endl ; - } - if (oldVlo!=pmin || oldVhi!=pmax) { - coutI(Minimization) << "RooMinuit::synchronize: limits of parameter " << par->GetName() << " changed from [" << oldVlo << "," << oldVhi - << "] to [" << pmin << "," << pmax << "]" << endl ; - } - - // If oldVerr=0, then parameter was previously fixed - if (oldVerr!=pstep && oldVerr!=0) { - coutI(Minimization) << "RooMinuit::synchronize: error/step size of parameter " << par->GetName() << " changed from " << oldVerr << " to " << pstep << endl ; - } - } - } - } - - - gMinuit->fNwrmes[0] = 0; // to clear buffer - oldWarn = setWarnLevel(oldWarn) ; - oldPrint = setPrintLevel(oldPrint) ; - - if (_optConst) { - if (constStatChange) { - - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - - coutI(Minimization) << "RooMinuit::synchronize: set of constant parameters changed, rerunning const optimizer" << endl ; - _func->constOptimizeTestStatistic(RooAbsArg::ConfigChange) ; - } else if (constValChange) { - coutI(Minimization) << "RooMinuit::synchronize: constant parameter values changed, rerunning const optimizer" << endl ; - _func->constOptimizeTestStatistic(RooAbsArg::ValueChange) ; - } - - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - - } - - updateFloatVec() ; - - return 0 ; -} - - - - -//////////////////////////////////////////////////////////////////////////////// -/// If flag is true, perform constant term optimization on -/// function being minimized. - -void RooMinuit::optimizeConst(Int_t flag) -{ - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ; - - if (_optConst && !flag){ - if (_printLevel>-1) coutI(Minimization) << "RooMinuit::optimizeConst: deactivating const optimization" << endl ; - _func->constOptimizeTestStatistic(RooAbsArg::DeActivate,flag>1) ; - _optConst = flag ; - } else if (!_optConst && flag) { - if (_printLevel>-1) coutI(Minimization) << "RooMinuit::optimizeConst: activating const optimization" << endl ; - _func->constOptimizeTestStatistic(RooAbsArg::Activate,flag>1) ; - _optConst = flag ; - } else if (_optConst && flag) { - if (_printLevel>-1) coutI(Minimization) << "RooMinuit::optimizeConst: const optimization already active" << endl ; - } else { - if (_printLevel>-1) coutI(Minimization) << "RooMinuit::optimizeConst: const optimization wasn't active" << endl ; - } - - RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ; - -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Save and return a RooFitResult snaphot of current minimizer status. -/// This snapshot contains the values of all constant parameters, -/// the value of all floating parameters at RooMinuit construction and -/// after the last MINUIT operation, the MINUIT status, variance quality, -/// EDM setting, number of calls with evaluation problems, the minimized -/// function value and the full correlation matrix - -RooFitResult* RooMinuit::save(const char* userName, const char* userTitle) -{ - TString name,title ; - name = userName ? userName : Form("%s", _func->GetName()) ; - title = userTitle ? userTitle : Form("%s", _func->GetTitle()) ; - - if (_floatParamList->empty()) { - RooFitResult* fitRes = new RooFitResult(name,title) ; - fitRes->setConstParList(*_constParamList) ; - fitRes->setInitParList(RooArgList()) ; - fitRes->setFinalParList(RooArgList()) ; - fitRes->setStatus(-999) ; - fitRes->setCovQual(-999) ; - fitRes->setMinNLL(_func->getVal()) ; - fitRes->setNumInvalidNLL(0) ; - fitRes->setEDM(-999) ; - return fitRes ; - } - - RooFitResult* fitRes = new RooFitResult(name,title) ; - - // Move eventual fixed parameters in floatList to constList - Int_t i ; - RooArgList saveConstList(*_constParamList) ; - RooArgList saveFloatInitList(*_initFloatParamList) ; - RooArgList saveFloatFinalList(*_floatParamList) ; - for (i=0 ; i<_floatParamList->getSize() ; i++) { - RooAbsArg* par = _floatParamList->at(i) ; - if (par->isConstant()) { - saveFloatInitList.remove(*saveFloatInitList.find(par->GetName()),true) ; - saveFloatFinalList.remove(*par) ; - saveConstList.add(*par) ; - } - } - saveConstList.sort() ; - - fitRes->setConstParList(saveConstList) ; - fitRes->setInitParList(saveFloatInitList) ; - - double edm, errdef, minVal; - Int_t nvpar, nparx; - Int_t icode = _theFitter->GetStats(minVal, edm, errdef, nvpar, nparx); - fitRes->setStatus(_status) ; - fitRes->setCovQual(icode) ; - fitRes->setMinNLL(minVal) ; - fitRes->setNumInvalidNLL(_numBadNLL) ; - fitRes->setEDM(edm) ; - fitRes->setFinalParList(saveFloatFinalList) ; - if (!_extV) { - fitRes->fillCorrMatrix() ; - } else { - fitRes->setCovarianceMatrix(*_extV) ; - } - - fitRes->setStatusHistory(_statusHistory) ; - - return fitRes ; -} - - - - -//////////////////////////////////////////////////////////////////////////////// -/// Create and draw a TH2 with the error contours in parameters var1 and v2 at up to 6 'sigma' settings -/// where 'sigma' is calculated as n*n*errorLevel - -RooPlot* RooMinuit::contour(RooRealVar& var1, RooRealVar& var2, double n1, double n2, double n3, double n4, double n5, double n6) -{ - - _theFitter->SetObjectFit(this) ; - - RooArgList* paramSave = (RooArgList*) _floatParamList->snapshot() ; - - // Verify that both variables are floating parameters of PDF - Int_t index1= _floatParamList->index(&var1); - if(index1 < 0) { - coutE(Minimization) << "RooMinuit::contour(" << GetName() - << ") ERROR: " << var1.GetName() << " is not a floating parameter of " << _func->GetName() << endl ; - return 0; - } - - Int_t index2= _floatParamList->index(&var2); - if(index2 < 0) { - coutE(Minimization) << "RooMinuit::contour(" << GetName() - << ") ERROR: " << var2.GetName() << " is not a floating parameter of PDF " << _func->GetName() << endl ; - return 0; - } - - // create and draw a frame - RooPlot* frame = new RooPlot(var1,var2) ; - - // draw a point at the current parameter values - TMarker *point= new TMarker(var1.getVal(), var2.getVal(), 8); - frame->addObject(point) ; - - // remember our original value of ERRDEF - double errdef= gMinuit->fUp; - - double n[6] ; - n[0] = n1 ; n[1] = n2 ; n[2] = n3 ; n[3] = n4 ; n[4] = n5 ; n[5] = n6 ; - - - for (Int_t ic = 0 ; ic<6 ; ic++) { - if(n[ic] > 0) { - // set the value corresponding to an n1-sigma contour - gMinuit->SetErrorDef(n[ic]*n[ic]*errdef); - // calculate and draw the contour - TGraph* graph= (TGraph*)gMinuit->Contour(50, index1, index2); - if (!graph) { - coutE(Minimization) << "RooMinuit::contour(" << GetName() << ") ERROR: MINUIT did not return a contour graph for n=" << n[ic] << endl ; - } else { - graph->SetName(Form("contour_%s_n%f",_func->GetName(),n[ic])) ; - graph->SetLineStyle(ic+1) ; - graph->SetLineWidth(2) ; - graph->SetLineColor(kBlue) ; - frame->addObject(graph,"L") ; - } - } - } - - // restore the original ERRDEF - gMinuit->SetErrorDef(errdef); - - // restore parameter values - _floatParamList->assign(*paramSave) ; - delete paramSave ; - - - return frame ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Change the file name for logging of a RooMinuit of all MINUIT steppings -/// through the parameter space. If inLogfile is null, the current log file -/// is closed and logging is stopped. - -bool RooMinuit::setLogFile(const char* inLogfile) -{ - if (_logfile) { - coutI(Minimization) << "RooMinuit::setLogFile: closing previous log file" << endl ; - _logfile->close() ; - delete _logfile ; - _logfile = 0 ; - } - _logfile = new ofstream(inLogfile) ; - if (!_logfile->good()) { - coutI(Minimization) << "RooMinuit::setLogFile: cannot open file " << inLogfile << endl ; - _logfile->close() ; - delete _logfile ; - _logfile= 0; - } - return false ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Access PDF parameter value by ordinal index (needed by MINUIT) - -double RooMinuit::getPdfParamVal(Int_t index) -{ - return ((RooRealVar*)_floatParamList->at(index))->getVal() ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Access PDF parameter error by ordinal index (needed by MINUIT) - -double RooMinuit::getPdfParamErr(Int_t index) -{ - return ((RooRealVar*)_floatParamList->at(index))->getError() ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Modify PDF parameter value by ordinal index (needed by MINUIT) - -bool RooMinuit::setPdfParamVal(Int_t index, double value, bool verbose) -{ - //RooRealVar* par = (RooRealVar*)_floatParamList->at(index) ; - RooRealVar* par = (RooRealVar*)_floatParamVec[index] ; - - if (par->getVal()!=value) { - if (verbose) cout << par->GetName() << "=" << value << ", " ; - par->setVal(value) ; - return true ; - } - - return false ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Modify PDF parameter error by ordinal index (needed by MINUIT) - -void RooMinuit::setPdfParamErr(Int_t index, double value) -{ - ((RooRealVar*)_floatParamList->at(index))->setError(value) ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Modify PDF parameter error by ordinal index (needed by MINUIT) - -void RooMinuit::clearPdfParamAsymErr(Int_t index) -{ - ((RooRealVar*)_floatParamList->at(index))->removeAsymError() ; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// Modify PDF parameter error by ordinal index (needed by MINUIT) - -void RooMinuit::setPdfParamErr(Int_t index, double loVal, double hiVal) -{ - ((RooRealVar*)_floatParamList->at(index))->setAsymError(loVal,hiVal) ; -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Start profiling timer - -void RooMinuit::profileStart() -{ - if (_profile) { - _timer.Start() ; - _cumulTimer.Start(false) ; - } -} - - - - -//////////////////////////////////////////////////////////////////////////////// -/// Stop profiling timer and report results of last session - -void RooMinuit::profileStop() -{ - if (_profile) { - _timer.Stop() ; - _cumulTimer.Stop() ; - coutI(Minimization) << "Command timer: " ; _timer.Print() ; - coutI(Minimization) << "Session timer: " ; _cumulTimer.Print() ; - } -} - - - - - -//////////////////////////////////////////////////////////////////////////////// -/// Transfer MINUIT fit results back into RooFit objects - -void RooMinuit::backProp() -{ - double val,err,vlo,vhi, eplus, eminus, eparab, globcc; - char buffer[64000]; - Int_t index ; - for(index= 0; index < _nPar; index++) { - _theFitter->GetParameter(index, buffer, val, err, vlo, vhi); - setPdfParamVal(index, val); - _theFitter->GetErrors(index, eplus, eminus, eparab, globcc); - - // Set the parabolic error - setPdfParamErr(index, err); - - if(eplus > 0 || eminus < 0) { - // Store the asymmetric error, if it is available - setPdfParamErr(index, eminus,eplus); - } else { - // Clear the asymmetric error - clearPdfParamAsymErr(index) ; - } - } -} - - -//////////////////////////////////////////////////////////////////////////////// - -void RooMinuit::updateFloatVec() -{ - _floatParamVec.clear() ; - _floatParamVec.resize(_floatParamList->getSize()) ; - Int_t i(0) ; - for (auto* arg : *_floatParamList) { - _floatParamVec[i++] = arg ; - } -} - - - -//////////////////////////////////////////////////////////////////////////////// -/// Apply results of given external covariance matrix. i.e. propagate its errors -/// to all RRV parameter representations and give this matrix instead of the -/// HESSE matrix at the next save() call - -void RooMinuit::applyCovarianceMatrix(TMatrixDSym& V) -{ - _extV = (TMatrixDSym*) V.Clone() ; - - for (Int_t i=0 ; iat(i)->isConstant()) { - continue ; - } - RooMinuit* context = (RooMinuit*) RooMinuit::_theFitter->GetObjectFit() ; - if (context && context->_verbose) - cout << "setting parameter " << i << " error to " << sqrt((*_extV)(i,i)) << endl ; - setPdfParamErr(i, sqrt((*_extV)(i,i))) ; - } - -} - - - - -void RooMinuitGlue(Int_t& /*np*/, double* /*gin*/, - double &f, double *par, Int_t /*flag*/) -{ - // Static function that interfaces minuit with RooMinuit - - // Retrieve fit context and its components - RooMinuit* context = (RooMinuit*) RooMinuit::_theFitter->GetObjectFit() ; - ofstream* logf = context->logfile() ; - double& maxFCN = context->maxFCN() ; - bool verbose = context->_verbose ; - - // Set the parameter values for this iteration - Int_t nPar= context->getNPar(); - for(Int_t index= 0; index < nPar; index++) { - if (logf) (*logf) << par[index] << " " ; - context->setPdfParamVal(index, par[index],verbose); - } - - // Calculate the function for these parameters - RooAbsReal::setHideOffset(false) ; - f= context->_func->getVal() ; - RooAbsReal::setHideOffset(true) ; - context->_evalCounter++ ; - if (RooAbsReal::numEvalErrors()>0 || f>1e30) { - - if (context->_printEvalErrors>=0) { - - if (context->_doEvalErrorWall) { - oocoutW(context,Minimization) << "RooMinuitGlue: Minimized function has error status." << endl - << "Returning maximum FCN so far (" << maxFCN - << ") to force MIGRAD to back out of this region. Error log follows" << endl ; - } else { - oocoutW(context,Minimization) << "RooMinuitGlue: Minimized function has error status but is ignored" << endl ; - } - - bool first(true) ; - ooccoutW(context,Minimization) << "Parameter values: " ; - for(auto * var : static_range_cast(*context->_floatParamList)) { - if (first) { first = false ; } else ooccoutW(context,Minimization) << ", " ; - ooccoutW(context,Minimization) << var->GetName() << "=" << var->getVal() ; - } - ooccoutW(context,Minimization) << endl ; - - RooAbsReal::printEvalErrors(ooccoutW(context,Minimization),context->_printEvalErrors) ; - ooccoutW(context,Minimization) << endl ; - } - - if (context->_doEvalErrorWall) { - f = maxFCN+1 ; - } - - RooAbsReal::clearEvalErrorLog() ; - context->_numBadNLL++ ; - } else if (f>maxFCN) { - maxFCN = f ; - } - - // Optional logging - if (logf) (*logf) << setprecision(15) << f << setprecision(4) << endl; - if (verbose) { - cout << "\nprevFCN" << (context->_func->isOffsetting()?"-offset":"") << " = " << setprecision(10) << f << setprecision(4) << " " ; - cout.flush() ; - } -} diff --git a/roofit/roostats/inc/RooStats/FeldmanCousins.h b/roofit/roostats/inc/RooStats/FeldmanCousins.h index 2748bd7f06079..a5567c6ebaf4b 100644 --- a/roofit/roostats/inc/RooStats/FeldmanCousins.h +++ b/roofit/roostats/inc/RooStats/FeldmanCousins.h @@ -46,24 +46,6 @@ namespace RooStats { double Size() const override {return fSize;} /// Get the Confidence level for the test double ConfidenceLevel() const override {return 1.-fSize;} - /// Set the DataSet - void SetData(RooAbsData& /*data*/) override { - std::cout << "DEPRECATED, set data in constructor" << std::endl; - } - /// Set the Pdf - virtual void SetPdf(RooAbsPdf& /*pdf*/) { - std::cout << "DEPRECATED, use ModelConfig" << std::endl; - } - - /// specify the parameters of interest in the interval - virtual void SetParameters(const RooArgSet& /*set*/) { - std::cout << "DEPRECATED, use ModelConfig" << std::endl; - } - - /// specify the nuisance parameters (eg. the rest of the parameters) - virtual void SetNuisanceParameters(const RooArgSet& /*set*/) { - std::cout << "DEPRECATED, use ModelConfig" << std::endl; - } /// User-defined set of points to test void SetParameterPointsToTest(RooAbsData& pointsToTest) { diff --git a/roofit/roostats/inc/RooStats/NeymanConstruction.h b/roofit/roostats/inc/RooStats/NeymanConstruction.h index 2d0b17910df89..9e2ca07762c83 100644 --- a/roofit/roostats/inc/RooStats/NeymanConstruction.h +++ b/roofit/roostats/inc/RooStats/NeymanConstruction.h @@ -77,21 +77,6 @@ namespace RooStats { /// Set the DataSet void SetData(RooAbsData& data) override { fData = data; } - /// Set the Pdf, add to the workspace if not already there - virtual void SetPdf(RooAbsPdf& /*pdf*/) { - std::cout << "DEPRECATED, use ModelConfig"<