ROOT logo
/*****************************************************************************
 * 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 <fstream>
#include "TMatrixDSymfwd.h"
#include <vector>
#include <string>
#include <map>

class RooAbsReal ;
class RooFitResult ;
class RooArgList ;
class RooRealVar ;
class RooArgSet ;
class RooAbsArg ;
class TVirtualFitter ;
class TH2F ;
class RooPlot ;

void RooMinuitGlue(Int_t& /*np*/, Double_t* /*gin*/,  Double_t &f, Double_t *par, Int_t /*flag*/) ;

class RooMinuit : public TObject {
public:

  RooMinuit(RooAbsReal& function) ;
  virtual ~RooMinuit() ;

  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_t level) ;
  void setEps(Double_t eps) ;
  void optimizeConst(Int_t flag) ;
  void setEvalErrorWall(Bool_t flag) { _doEvalErrorWall = flag ; }
  void setOffsetting(Bool_t 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=0, const char* title=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) ;

  Int_t setPrintLevel(Int_t newLevel) ; 
  void setNoWarn() ;
  Int_t setWarnLevel(Int_t newLevel) ;
  void setPrintEvalErrors(Int_t numEvalErrors) { _printEvalErrors = numEvalErrors ; }
  void setVerbose(Bool_t flag=kTRUE) { _verbose = flag ; }
  void setProfile(Bool_t flag=kTRUE) { _profile = flag ; }
  void setMaxEvalMultiplier(Int_t n) { _maxEvalMult = n ; }
  Bool_t setLogFile(const char* logfile=0) ;  

  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_t *gin, Double_t &f, Double_t *par, Int_t flag) ;

  void profileStart() ;
  void profileStop() ;

  Bool_t synchronize(Bool_t verbose) ;  
  void backProp() ;

  inline Int_t getNPar() const { return _nPar ; }
  inline std::ofstream* logfile() const { return _logfile ; }
  inline Double_t& maxFCN() { return _maxFCN ; }

  Double_t getPdfParamVal(Int_t index) ;
  Double_t getPdfParamErr(Int_t index) ;	
  virtual Bool_t setPdfParamVal(Int_t index, Double_t value, Bool_t verbose=kFALSE) ;
  void setPdfParamErr(Int_t index, Double_t value) ;
  void setPdfParamErr(Int_t index, Double_t loVal, Double_t hiVal) ;
  void clearPdfParamAsymErr(Int_t index) ;

  void saveStatus(const char* label, Int_t status) { _statusHistory.push_back(std::pair<std::string,int>(label,status)) ; }

  void updateFloatVec() ;

private:

  Int_t       _evalCounter ;
  Int_t       _printLevel ;
  Int_t       _warnLevel ;
  Int_t       _status ;
  Int_t       _optConst ;
  Bool_t      _profile ;
  Bool_t      _handleLocalErrors ;
  Int_t       _numBadNLL ;
  Int_t       _nPar ;
  Int_t       _printEvalErrors ;
  Bool_t      _doEvalErrorWall ;
  Int_t       _maxEvalMult ;
  RooArgList* _floatParamList ;
  std::vector<RooAbsArg*> _floatParamVec ;
  RooArgList* _initFloatParamList ;
  RooArgList* _constParamList ;
  RooArgList* _initConstParamList ;
  RooAbsReal* _func ;

  Double_t    _maxFCN ;  
  std::ofstream*   _logfile ;
  Bool_t      _verbose ;
  TStopwatch  _timer ;
  TStopwatch  _cumulTimer ;

  TMatrixDSym* _extV ;

  static TVirtualFitter *_theFitter ; 

  std::vector<std::pair<std::string,int> > _statusHistory ;

  RooMinuit(const RooMinuit&) ;
	
  ClassDef(RooMinuit,0) // RooFit minimizer based on MINUIT
} ;


#endif

 RooMinuit.h:1
 RooMinuit.h:2
 RooMinuit.h:3
 RooMinuit.h:4
 RooMinuit.h:5
 RooMinuit.h:6
 RooMinuit.h:7
 RooMinuit.h:8
 RooMinuit.h:9
 RooMinuit.h:10
 RooMinuit.h:11
 RooMinuit.h:12
 RooMinuit.h:13
 RooMinuit.h:14
 RooMinuit.h:15
 RooMinuit.h:16
 RooMinuit.h:17
 RooMinuit.h:18
 RooMinuit.h:19
 RooMinuit.h:20
 RooMinuit.h:21
 RooMinuit.h:22
 RooMinuit.h:23
 RooMinuit.h:24
 RooMinuit.h:25
 RooMinuit.h:26
 RooMinuit.h:27
 RooMinuit.h:28
 RooMinuit.h:29
 RooMinuit.h:30
 RooMinuit.h:31
 RooMinuit.h:32
 RooMinuit.h:33
 RooMinuit.h:34
 RooMinuit.h:35
 RooMinuit.h:36
 RooMinuit.h:37
 RooMinuit.h:38
 RooMinuit.h:39
 RooMinuit.h:40
 RooMinuit.h:41
 RooMinuit.h:42
 RooMinuit.h:43
 RooMinuit.h:44
 RooMinuit.h:45
 RooMinuit.h:46
 RooMinuit.h:47
 RooMinuit.h:48
 RooMinuit.h:49
 RooMinuit.h:50
 RooMinuit.h:51
 RooMinuit.h:52
 RooMinuit.h:53
 RooMinuit.h:54
 RooMinuit.h:55
 RooMinuit.h:56
 RooMinuit.h:57
 RooMinuit.h:58
 RooMinuit.h:59
 RooMinuit.h:60
 RooMinuit.h:61
 RooMinuit.h:62
 RooMinuit.h:63
 RooMinuit.h:64
 RooMinuit.h:65
 RooMinuit.h:66
 RooMinuit.h:67
 RooMinuit.h:68
 RooMinuit.h:69
 RooMinuit.h:70
 RooMinuit.h:71
 RooMinuit.h:72
 RooMinuit.h:73
 RooMinuit.h:74
 RooMinuit.h:75
 RooMinuit.h:76
 RooMinuit.h:77
 RooMinuit.h:78
 RooMinuit.h:79
 RooMinuit.h:80
 RooMinuit.h:81
 RooMinuit.h:82
 RooMinuit.h:83
 RooMinuit.h:84
 RooMinuit.h:85
 RooMinuit.h:86
 RooMinuit.h:87
 RooMinuit.h:88
 RooMinuit.h:89
 RooMinuit.h:90
 RooMinuit.h:91
 RooMinuit.h:92
 RooMinuit.h:93
 RooMinuit.h:94
 RooMinuit.h:95
 RooMinuit.h:96
 RooMinuit.h:97
 RooMinuit.h:98
 RooMinuit.h:99
 RooMinuit.h:100
 RooMinuit.h:101
 RooMinuit.h:102
 RooMinuit.h:103
 RooMinuit.h:104
 RooMinuit.h:105
 RooMinuit.h:106
 RooMinuit.h:107
 RooMinuit.h:108
 RooMinuit.h:109
 RooMinuit.h:110
 RooMinuit.h:111
 RooMinuit.h:112
 RooMinuit.h:113
 RooMinuit.h:114
 RooMinuit.h:115
 RooMinuit.h:116
 RooMinuit.h:117
 RooMinuit.h:118
 RooMinuit.h:119
 RooMinuit.h:120
 RooMinuit.h:121
 RooMinuit.h:122
 RooMinuit.h:123
 RooMinuit.h:124
 RooMinuit.h:125
 RooMinuit.h:126
 RooMinuit.h:127
 RooMinuit.h:128
 RooMinuit.h:129
 RooMinuit.h:130
 RooMinuit.h:131
 RooMinuit.h:132
 RooMinuit.h:133
 RooMinuit.h:134
 RooMinuit.h:135
 RooMinuit.h:136
 RooMinuit.h:137
 RooMinuit.h:138
 RooMinuit.h:139
 RooMinuit.h:140
 RooMinuit.h:141
 RooMinuit.h:142
 RooMinuit.h:143
 RooMinuit.h:144
 RooMinuit.h:145
 RooMinuit.h:146
 RooMinuit.h:147
 RooMinuit.h:148
 RooMinuit.h:149
 RooMinuit.h:150
 RooMinuit.h:151