/*****************************************************************************
 * 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                 *
 *   AL, Alfio Lazzaro,   INFN Milan,        alfio.lazzaro@mi.infn.it        *
 *                                                                           *
 * 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)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
//
// BEGIN_HTML
// RooMinimizer is a wrapper class around ROOT::Fit:Fitter that
// provides a seamless interface between the minimizer functionality
// and the native RooFit interface.
// <p>
// By default the Minimizer is MINUIT.
// <p>
// RooMinimizer can minimize any RooAbsReal function with respect to
// its parameters. Usual choices for minimization are RooNLLVar
// and RooChi2Var
// <p>
// RooMinimizer 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.
// <p>
// Various methods are available to control verbosity, profiling,
// automatic PDF optimization.
// END_HTML
//

#ifndef __ROOFIT_NOROOMINIMIZER

#include "RooFit.h"
#include "Riostream.h"

#include "TClass.h"

#include <fstream>
#include <iomanip>

#include "TH1.h"
#include "TH2.h"
#include "TMarker.h"
#include "TGraph.h"
#include "TStopwatch.h"
#include "TDirectory.h"
#include "TMatrixDSym.h"

#include "RooArgSet.h"
#include "RooArgList.h"
#include "RooAbsReal.h"
#include "RooAbsRealLValue.h"
#include "RooRealVar.h"
#include "RooAbsPdf.h"
#include "RooSentinel.h"
#include "RooMsgService.h"
#include "RooPlot.h"


#include "RooMinimizer.h"
#include "RooFitResult.h"

#include "Math/Minimizer.h"

#if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3)
char* operator+( streampos&, char* );
#endif

using namespace std;

ClassImp(RooMinimizer)
;

ROOT::Fit::Fitter *RooMinimizer::_theFitter = 0 ;



//_____________________________________________________________________________
void RooMinimizer::cleanup()
{
  // Cleanup method called by atexit handler installed by RooSentinel
  // to delete all global heap objects when the program is terminated
  if (_theFitter) {
    delete _theFitter ;
    _theFitter =0 ;
  }
}



//_____________________________________________________________________________
RooMinimizer::RooMinimizer(RooAbsReal& function)
{
  // 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.

  RooSentinel::activate() ;

  // Store function reference
  _extV = 0 ;
  _func = &function ;
  _optConst = kFALSE ;
  _verbose = kFALSE ;
  _profile = kFALSE ;
  _profileStart = kFALSE ;
  _printLevel = 1 ;
  _minimizerType = "Minuit"; // default minimizer

  if (_theFitter) delete _theFitter ;
  _theFitter = new ROOT::Fit::Fitter;
  _fcn = new RooMinimizerFcn(_func,this,_verbose);
  _theFitter->Config().SetMinimizer(_minimizerType.c_str());
  setEps(1.0); // default tolerance
  // default max number of calls
  _theFitter->Config().MinimizerOptions().SetMaxIterations(500*_fcn->NDim());
  _theFitter->Config().MinimizerOptions().SetMaxFunctionCalls(500*_fcn->NDim());

  // Shut up for now
  setPrintLevel(-1) ;

  // Use +0.5 for 1-sigma errors
  setErrorLevel(_func->defaultErrorLevel()) ;

  // Declare our parameters to MINUIT
  _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		    _optConst,_verbose) ;

  // Now set default verbosity
  if (RooMsgService::instance().silentMode()) {
    setPrintLevel(-1) ;
  } else {
    setPrintLevel(1) ;
  }
}



//_____________________________________________________________________________
RooMinimizer::~RooMinimizer()
{
  // Destructor

  if (_extV) {
    delete _extV ;
  }

  if (_fcn) {
    delete _fcn;
  }

}



//_____________________________________________________________________________
void RooMinimizer::setStrategy(Int_t istrat)
{
  // 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)

  _theFitter->Config().MinimizerOptions().SetStrategy(istrat);

}



//_____________________________________________________________________________
void RooMinimizer::setMaxIterations(Int_t n) 
{
  // Change maximum number of MINUIT iterations 
  // (RooMinimizer default 500 * #parameters)
  _theFitter->Config().MinimizerOptions().SetMaxIterations(n);
}




//_____________________________________________________________________________
void RooMinimizer::setMaxFunctionCalls(Int_t n) 
{
  // Change maximum number of likelihood function calss from MINUIT
  // (RooMinimizer default 500 * #parameters)
  _theFitter->Config().MinimizerOptions().SetMaxFunctionCalls(n);
}




//_____________________________________________________________________________
void RooMinimizer::setErrorLevel(Double_t level)
{
  // Set the level for MINUIT error analysis to the given
  // value. This function overrides the default value
  // that is taken in the RooMinimizer constructor from
  // the defaultErrorLevel() method of the input function

  _theFitter->Config().MinimizerOptions().SetErrorDef(level);

}



//_____________________________________________________________________________
void RooMinimizer::setEps(Double_t eps)
{
  // Change MINUIT epsilon

  _theFitter->Config().MinimizerOptions().SetTolerance(eps);

}


//_____________________________________________________________________________
void RooMinimizer::setOffsetting(Bool_t flag) 
{
  // Enable internal likelihood offsetting for enhanced numeric precision
  _func->enableOffsetting(flag) ; 
}




//_____________________________________________________________________________
void RooMinimizer::setMinimizerType(const char* type)
{
  // Choose the minimzer algorithm.
  _minimizerType = type;
}




//_____________________________________________________________________________
ROOT::Fit::Fitter* RooMinimizer::fitter()
{
  // Return underlying ROOT fitter object 
  return _theFitter ;
}


//_____________________________________________________________________________
const ROOT::Fit::Fitter* RooMinimizer::fitter() const 
{
  // Return underlying ROOT fitter object 
  return _theFitter ;
}



//_____________________________________________________________________________
RooFitResult* RooMinimizer::fit(const char* options)
{
  // Parse traditional RooAbsPdf::fitTo driver options
  //
  //  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

  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("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 ;
}




//_____________________________________________________________________________
Int_t RooMinimizer::minimize(const char* type, const char* alg)
{
  _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		    _optConst,_verbose) ;

  _theFitter->Config().SetMinimizer(type,alg);

  profileStart() ;
  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
  RooAbsReal::clearEvalErrorLog() ;

  bool ret = _theFitter->FitFCN(*_fcn);
  _status = ((ret) ? _theFitter->Result().Status() : -1);

  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
  profileStop() ;
  _fcn->BackProp(_theFitter->Result());

  saveStatus("MINIMIZE",_status) ;

  return _status ;
}



//_____________________________________________________________________________
Int_t RooMinimizer::migrad()
{
  // Execute MIGRAD. Changes in parameter values
  // and calculated errors are automatically
  // propagated back the RooRealVars representing
  // the floating parameters in the MINUIT operation

  _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		    _optConst,_verbose) ;
  profileStart() ;
  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
  RooAbsReal::clearEvalErrorLog() ;

  _theFitter->Config().SetMinimizer(_minimizerType.c_str(),"migrad");
  bool ret = _theFitter->FitFCN(*_fcn);
  _status = ((ret) ? _theFitter->Result().Status() : -1);

  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
  profileStop() ;
  _fcn->BackProp(_theFitter->Result());

  saveStatus("MIGRAD",_status) ;

  return _status ;
}



//_____________________________________________________________________________
Int_t RooMinimizer::hesse()
{
  // Execute HESSE. Changes in parameter values
  // and calculated errors are automatically
  // propagated back the RooRealVars representing
  // the floating parameters in the MINUIT operation

  if (_theFitter->GetMinimizer()==0) {
    coutW(Minimization) << "RooMinimizer::hesse: Error, run Migrad before Hesse!"
			<< endl ;
    _status = -1;
  }
  else {

    _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		    _optConst,_verbose) ;
    profileStart() ;
    RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
    RooAbsReal::clearEvalErrorLog() ;

    _theFitter->Config().SetMinimizer(_minimizerType.c_str());
    bool ret = _theFitter->CalculateHessErrors();
    _status = ((ret) ? _theFitter->Result().Status() : -1);

    RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
    profileStop() ;
    _fcn->BackProp(_theFitter->Result());

    saveStatus("HESSE",_status) ;
  
  }

  return _status ;

}

//_____________________________________________________________________________
Int_t RooMinimizer::minos()
{
  // Execute MINOS. Changes in parameter values
  // and calculated errors are automatically
  // propagated back the RooRealVars representing
  // the floating parameters in the MINUIT operation

  if (_theFitter->GetMinimizer()==0) {
    coutW(Minimization) << "RooMinimizer::minos: Error, run Migrad before Minos!"
			<< endl ;
    _status = -1;
  }
  else {

    _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		      _optConst,_verbose) ;
    profileStart() ;
    RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
    RooAbsReal::clearEvalErrorLog() ;

    _theFitter->Config().SetMinimizer(_minimizerType.c_str());
    bool ret = _theFitter->CalculateMinosErrors();
    _status = ((ret) ? _theFitter->Result().Status() : -1);

    RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
    profileStop() ;
    _fcn->BackProp(_theFitter->Result());

    saveStatus("MINOS",_status) ;

  }

  return _status ;

}


//_____________________________________________________________________________
Int_t RooMinimizer::minos(const RooArgSet& minosParamList)
{
  // 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

  if (_theFitter->GetMinimizer()==0) {
    coutW(Minimization) << "RooMinimizer::minos: Error, run Migrad before Minos!"
			<< endl ;
    _status = -1;
  }
  else if (minosParamList.getSize()>0) {

    _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		      _optConst,_verbose) ;
    profileStart() ;
    RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
    RooAbsReal::clearEvalErrorLog() ;

    // get list of parameters for Minos
    TIterator* aIter = minosParamList.createIterator() ;
    RooAbsArg* arg ;
    std::vector<unsigned int> paramInd;
    while((arg=(RooAbsArg*)aIter->Next())) {
      RooAbsArg* par = _fcn->GetFloatParamList()->find(arg->GetName());
      if (par && !par->isConstant()) {
	Int_t index = _fcn->GetFloatParamList()->index(par);
	paramInd.push_back(index);
      }
    }
    delete aIter ;

    if (paramInd.size()) {
      // set the parameter indeces
      _theFitter->Config().SetMinosErrors(paramInd);

      _theFitter->Config().SetMinimizer(_minimizerType.c_str());
      bool ret = _theFitter->CalculateMinosErrors();
      _status = ((ret) ? _theFitter->Result().Status() : -1);
      // to avoid that following minimization computes automatically the Minos errors
      _theFitter->Config().SetMinosErrors(kFALSE);

    }

    RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
    profileStop() ;
    _fcn->BackProp(_theFitter->Result());

    saveStatus("MINOS",_status) ;

  }

  return _status ;
}



//_____________________________________________________________________________
Int_t RooMinimizer::seek()
{
  // Execute SEEK. Changes in parameter values
  // and calculated errors are automatically
  // propagated back the RooRealVars representing
  // the floating parameters in the MINUIT operation

  _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		    _optConst,_verbose) ;
  profileStart() ;
  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
  RooAbsReal::clearEvalErrorLog() ;

  _theFitter->Config().SetMinimizer(_minimizerType.c_str(),"seek");
  bool ret = _theFitter->FitFCN(*_fcn);
  _status = ((ret) ? _theFitter->Result().Status() : -1);

  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
  profileStop() ;
  _fcn->BackProp(_theFitter->Result());

  saveStatus("SEEK",_status) ;

  return _status ;
}



//_____________________________________________________________________________
Int_t RooMinimizer::simplex()
{
  // Execute SIMPLEX. Changes in parameter values
  // and calculated errors are automatically
  // propagated back the RooRealVars representing
  // the floating parameters in the MINUIT operation

  _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		    _optConst,_verbose) ;
  profileStart() ;
  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
  RooAbsReal::clearEvalErrorLog() ;

  _theFitter->Config().SetMinimizer(_minimizerType.c_str(),"simplex");
  bool ret = _theFitter->FitFCN(*_fcn);
  _status = ((ret) ? _theFitter->Result().Status() : -1);

  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
  profileStop() ;
  _fcn->BackProp(_theFitter->Result());

  saveStatus("SEEK",_status) ;
    
  return _status ;
}



//_____________________________________________________________________________
Int_t RooMinimizer::improve()
{
  // Execute IMPROVE. Changes in parameter values
  // and calculated errors are automatically
  // propagated back the RooRealVars representing
  // the floating parameters in the MINUIT operation

  _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
		    _optConst,_verbose) ;
  profileStart() ;
  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;
  RooAbsReal::clearEvalErrorLog() ;

  _theFitter->Config().SetMinimizer(_minimizerType.c_str(),"migradimproved");
  bool ret = _theFitter->FitFCN(*_fcn);
  _status = ((ret) ? _theFitter->Result().Status() : -1);

  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;
  profileStop() ;
  _fcn->BackProp(_theFitter->Result());

  saveStatus("IMPROVE",_status) ;

  return _status ;
}



//_____________________________________________________________________________
Int_t RooMinimizer::setPrintLevel(Int_t newLevel)
{
  // Change the MINUIT internal printing level

  Int_t ret = _printLevel ;
  _theFitter->Config().MinimizerOptions().SetPrintLevel(newLevel+1);
  _printLevel = newLevel+1 ;
  return ret ;
}

//_____________________________________________________________________________
void RooMinimizer::optimizeConst(Int_t flag)
{
  // If flag is true, perform constant term optimization on
  // function being minimized.

  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::CollectErrors) ;

  if (_optConst && !flag){
    if (_printLevel>-1) coutI(Minimization) << "RooMinimizer::optimizeConst: deactivating const optimization" << endl ;
    _func->constOptimizeTestStatistic(RooAbsArg::DeActivate) ;
    _optConst = flag ;
  } else if (!_optConst && flag) {
    if (_printLevel>-1) coutI(Minimization) << "RooMinimizer::optimizeConst: activating const optimization" << endl ;
    _func->constOptimizeTestStatistic(RooAbsArg::Activate,flag>1) ;
    _optConst = flag ;
  } else if (_optConst && flag) {
    if (_printLevel>-1) coutI(Minimization) << "RooMinimizer::optimizeConst: const optimization already active" << endl ;
  } else {
    if (_printLevel>-1) coutI(Minimization) << "RooMinimizer::optimizeConst: const optimization wasn't active" << endl ;
  }

  RooAbsReal::setEvalErrorLoggingMode(RooAbsReal::PrintErrors) ;

}



//_____________________________________________________________________________
RooFitResult* RooMinimizer::save(const char* userName, const char* userTitle)
{
  // 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 RooMinimizer 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

  if (_theFitter->GetMinimizer()==0) {
    coutW(Minimization) << "RooMinimizer::save: Error, run minimization before!"
			<< endl ;
    return 0;
  }

  TString name,title ;
  name = userName ? userName : Form("%s", _func->GetName()) ;
  title = userTitle ? userTitle : Form("%s", _func->GetTitle()) ;
  RooFitResult* fitRes = new RooFitResult(name,title) ;

  // Move eventual fixed parameters in floatList to constList
  Int_t i ;
  RooArgList saveConstList(*(_fcn->GetConstParamList())) ;
  RooArgList saveFloatInitList(*(_fcn->GetInitFloatParamList())) ;
  RooArgList saveFloatFinalList(*(_fcn->GetFloatParamList())) ;
  for (i=0 ; i<_fcn->GetFloatParamList()->getSize() ; i++) {
    RooAbsArg* par = _fcn->GetFloatParamList()->at(i) ;
    if (par->isConstant()) {
      saveFloatInitList.remove(*saveFloatInitList.find(par->GetName()),kTRUE) ;
      saveFloatFinalList.remove(*par) ;
      saveConstList.add(*par) ;
    }
  }
  saveConstList.sort() ;

  fitRes->setConstParList(saveConstList) ;
  fitRes->setInitParList(saveFloatInitList) ;

  fitRes->setStatus(_status) ;
  fitRes->setCovQual(_theFitter->GetMinimizer()->CovMatrixStatus()) ;
  fitRes->setMinNLL(_theFitter->Result().MinFcnValue()) ;
  fitRes->setNumInvalidNLL(_fcn->GetNumInvalidNLL()) ;
  fitRes->setEDM(_theFitter->Result().Edm()) ;
  fitRes->setFinalParList(saveFloatFinalList) ;
  if (!_extV) {
    std::vector<double> globalCC;
    TMatrixDSym corrs(_theFitter->Result().Parameters().size()) ;
    TMatrixDSym covs(_theFitter->Result().Parameters().size()) ;
    for (UInt_t ic=0; ic<_theFitter->Result().Parameters().size(); ic++) {
      globalCC.push_back(_theFitter->Result().GlobalCC(ic));
      for (UInt_t ii=0; ii<_theFitter->Result().Parameters().size(); ii++) {
	corrs(ic,ii) = _theFitter->Result().Correlation(ic,ii);
	covs(ic,ii) = _theFitter->Result().CovMatrix(ic,ii);
      }
    }
    fitRes->fillCorrMatrix(globalCC,corrs,covs) ;
  } else {
    fitRes->setCovarianceMatrix(*_extV) ;
  }

  fitRes->setStatusHistory(_statusHistory) ;

  return fitRes ;

}

//_____________________________________________________________________________
RooPlot* RooMinimizer::contour(RooRealVar& var1, RooRealVar& var2,
			       Double_t n1, Double_t n2, Double_t n3,
			       Double_t n4, Double_t n5, Double_t n6)
{
  // 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



  RooArgList* params = _fcn->GetFloatParamList() ;
  RooArgList* paramSave = (RooArgList*) params->snapshot() ;

  // Verify that both variables are floating parameters of PDF
  Int_t index1= _fcn->GetFloatParamList()->index(&var1);
  if(index1 < 0) {
    coutE(Minimization) << "RooMinimizer::contour(" << GetName()
			<< ") ERROR: " << var1.GetName()
			<< " is not a floating parameter of "
			<< _func->GetName() << endl ;
    return 0;
  }

  Int_t index2= _fcn->GetFloatParamList()->index(&var2);
  if(index2 < 0) {
    coutE(Minimization) << "RooMinimizer::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) ;

  // check first if a inimizer is available. If not means
  // the minimization is not done , so do it 
  if (_theFitter->GetMinimizer()==0) {
     coutW(Minimization) << "RooMinimizer::contour: Error, run Migrad before contours!"
                         << endl ;
     return frame;
  }

  
  // remember our original value of ERRDEF  
  Double_t errdef= _theFitter->GetMinimizer()->ErrorDef();

  Double_t n[6] ;
  n[0] = n1 ; n[1] = n2 ; n[2] = n3 ; n[3] = n4 ; n[4] = n5 ; n[5] = n6 ;
  unsigned int npoints(50);

  for (Int_t ic = 0 ; ic<6 ; ic++) {
    if(n[ic] > 0) {

       // set the value corresponding to an n1-sigma contour
       _theFitter->GetMinimizer()->SetErrorDef(n[ic]*n[ic]*errdef);

      // calculate and draw the contour
      Double_t *xcoor = new Double_t[npoints+1];
      Double_t *ycoor = new Double_t[npoints+1];
      bool ret = _theFitter->GetMinimizer()->Contour(index1,index2,npoints,xcoor,ycoor);

      if (!ret) {
	coutE(Minimization) << "RooMinimizer::contour("
			    << GetName()
			    << ") ERROR: MINUIT did not return a contour graph for n="
			    << n[ic] << endl ;
      } else {
	xcoor[npoints] = xcoor[0];
	ycoor[npoints] = ycoor[0];
	TGraph* graph = new TGraph(npoints+1,xcoor,ycoor);

	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") ;
      }

      delete [] xcoor;
      delete [] ycoor;
    }
  }


  // restore the original ERRDEF
  _theFitter->Config().MinimizerOptions().SetErrorDef(errdef);

  // restore parameter values
  *params = *paramSave ;
  delete paramSave ;

  return frame ;

}


//_____________________________________________________________________________
void RooMinimizer::profileStart()
{
  // Start profiling timer
  if (_profile) {
    _timer.Start() ;
    _cumulTimer.Start(_profileStart?kFALSE:kTRUE) ;
    _profileStart = kTRUE ;
  }
}


//_____________________________________________________________________________
void RooMinimizer::profileStop()
{
  // Stop profiling timer and report results of last session
  if (_profile) {
    _timer.Stop() ;
    _cumulTimer.Stop() ;
    coutI(Minimization) << "Command timer: " ; _timer.Print() ;
    coutI(Minimization) << "Session timer: " ; _cumulTimer.Print() ;
  }
}





//_____________________________________________________________________________
void RooMinimizer::applyCovarianceMatrix(TMatrixDSym& V)
{
  // 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

  _extV = (TMatrixDSym*) V.Clone() ;
  _fcn->ApplyCovarianceMatrix(*_extV);

}



RooFitResult* RooMinimizer::lastMinuitFit(const RooArgList& varList)
{
  // Import the results of the last fit performed, interpreting
  // the fit parameters as the given varList of parameters.

  if (_theFitter==0 || _theFitter->GetMinimizer()==0) {
    oocoutE((TObject*)0,InputArguments) << "RooMinimizer::save: Error, run minimization before!"
					<< endl ;
    return 0;
  }

  // Verify length of supplied varList
  if (varList.getSize()>0 && varList.getSize()!=Int_t(_theFitter->Result().NTotalParameters())) {
    oocoutE((TObject*)0,InputArguments)
      << "RooMinimizer::lastMinuitFit: ERROR: supplied variable list must be either empty " << endl
      << "                             or match the number of variables of the last fit ("
      << _theFitter->Result().NTotalParameters() << ")" << endl ;
    return 0 ;
  }


  // Verify that all members of varList are of type RooRealVar
  TIterator* iter = varList.createIterator() ;
  RooAbsArg* arg  ;
  while((arg=(RooAbsArg*)iter->Next())) {
    if (!dynamic_cast<RooRealVar*>(arg)) {
      oocoutE((TObject*)0,InputArguments) << "RooMinimizer::lastMinuitFit: ERROR: variable '"
					  << arg->GetName() << "' is not of type RooRealVar" << endl ;
      return 0 ;
    }
  }
  delete iter ;

  RooFitResult* res = new RooFitResult("lastMinuitFit","Last MINUIT fit") ;

  // Extract names of fit parameters
  // and construct corresponding RooRealVars
  RooArgList constPars("constPars") ;
  RooArgList floatPars("floatPars") ;

  UInt_t i ;
  for (i = 0; i < _theFitter->Result().NTotalParameters(); ++i) {

    TString varName(_theFitter->Result().GetParameterName(i));
    Bool_t isConst(_theFitter->Result().IsParameterFixed(i)) ;

    Double_t xlo = _theFitter->Config().ParSettings(i).LowerLimit();
    Double_t xhi = _theFitter->Config().ParSettings(i).UpperLimit();
    Double_t xerr = _theFitter->Result().Error(i);
    Double_t xval = _theFitter->Result().Value(i);

    RooRealVar* var ;
    if (varList.getSize()==0) {

      if ((xlo<xhi) && !isConst) {
        var = new RooRealVar(varName,varName,xval,xlo,xhi) ;
      } else {
        var = new RooRealVar(varName,varName,xval) ;
      }
      var->setConstant(isConst) ;
    } else {

      var = (RooRealVar*) varList.at(i)->Clone() ;
      var->setConstant(isConst) ;
      var->setVal(xval) ;
      if (xlo<xhi) {
        var->setRange(xlo,xhi) ;
      }

      if (varName.CompareTo(var->GetName())) {
	oocoutI((TObject*)0,Eval)  << "RooMinimizer::lastMinuitFit: fit parameter '" << varName
				   << "' stored in variable '" << var->GetName() << "'" << endl ;
      }

    }

    if (isConst) {
      constPars.addOwned(*var) ;
    } else {
      var->setError(xerr) ;
      floatPars.addOwned(*var) ;
    }
  }

  res->setConstParList(constPars) ;
  res->setInitParList(floatPars) ;
  res->setFinalParList(floatPars) ;
  res->setMinNLL(_theFitter->Result().MinFcnValue()) ;
  res->setEDM(_theFitter->Result().Edm()) ;
  res->setCovQual(_theFitter->GetMinimizer()->CovMatrixStatus()) ;
  res->setStatus(_theFitter->Result().Status()) ;
  std::vector<double> globalCC;
  TMatrixDSym corrs(_theFitter->Result().Parameters().size()) ;
  TMatrixDSym covs(_theFitter->Result().Parameters().size()) ;
  for (UInt_t ic=0; ic<_theFitter->Result().Parameters().size(); ic++) {
    globalCC.push_back(_theFitter->Result().GlobalCC(ic));
    for (UInt_t ii=0; ii<_theFitter->Result().Parameters().size(); ii++) {
      corrs(ic,ii) = _theFitter->Result().Correlation(ic,ii);
      covs(ic,ii) = _theFitter->Result().CovMatrix(ic,ii);
    }
  }
  res->fillCorrMatrix(globalCC,corrs,covs) ;

  return res;

}

#endif
 RooMinimizer.cxx:1
 RooMinimizer.cxx:2
 RooMinimizer.cxx:3
 RooMinimizer.cxx:4
 RooMinimizer.cxx:5
 RooMinimizer.cxx:6
 RooMinimizer.cxx:7
 RooMinimizer.cxx:8
 RooMinimizer.cxx:9
 RooMinimizer.cxx:10
 RooMinimizer.cxx:11
 RooMinimizer.cxx:12
 RooMinimizer.cxx:13
 RooMinimizer.cxx:14
 RooMinimizer.cxx:15
 RooMinimizer.cxx:16
 RooMinimizer.cxx:17
 RooMinimizer.cxx:18
 RooMinimizer.cxx:19
 RooMinimizer.cxx:20
 RooMinimizer.cxx:21
 RooMinimizer.cxx:22
 RooMinimizer.cxx:23
 RooMinimizer.cxx:24
 RooMinimizer.cxx:25
 RooMinimizer.cxx:26
 RooMinimizer.cxx:27
 RooMinimizer.cxx:28
 RooMinimizer.cxx:29
 RooMinimizer.cxx:30
 RooMinimizer.cxx:31
 RooMinimizer.cxx:32
 RooMinimizer.cxx:33
 RooMinimizer.cxx:34
 RooMinimizer.cxx:35
 RooMinimizer.cxx:36
 RooMinimizer.cxx:37
 RooMinimizer.cxx:38
 RooMinimizer.cxx:39
 RooMinimizer.cxx:40
 RooMinimizer.cxx:41
 RooMinimizer.cxx:42
 RooMinimizer.cxx:43
 RooMinimizer.cxx:44
 RooMinimizer.cxx:45
 RooMinimizer.cxx:46
 RooMinimizer.cxx:47
 RooMinimizer.cxx:48
 RooMinimizer.cxx:49
 RooMinimizer.cxx:50
 RooMinimizer.cxx:51
 RooMinimizer.cxx:52
 RooMinimizer.cxx:53
 RooMinimizer.cxx:54
 RooMinimizer.cxx:55
 RooMinimizer.cxx:56
 RooMinimizer.cxx:57
 RooMinimizer.cxx:58
 RooMinimizer.cxx:59
 RooMinimizer.cxx:60
 RooMinimizer.cxx:61
 RooMinimizer.cxx:62
 RooMinimizer.cxx:63
 RooMinimizer.cxx:64
 RooMinimizer.cxx:65
 RooMinimizer.cxx:66
 RooMinimizer.cxx:67
 RooMinimizer.cxx:68
 RooMinimizer.cxx:69
 RooMinimizer.cxx:70
 RooMinimizer.cxx:71
 RooMinimizer.cxx:72
 RooMinimizer.cxx:73
 RooMinimizer.cxx:74
 RooMinimizer.cxx:75
 RooMinimizer.cxx:76
 RooMinimizer.cxx:77
 RooMinimizer.cxx:78
 RooMinimizer.cxx:79
 RooMinimizer.cxx:80
 RooMinimizer.cxx:81
 RooMinimizer.cxx:82
 RooMinimizer.cxx:83
 RooMinimizer.cxx:84
 RooMinimizer.cxx:85
 RooMinimizer.cxx:86
 RooMinimizer.cxx:87
 RooMinimizer.cxx:88
 RooMinimizer.cxx:89
 RooMinimizer.cxx:90
 RooMinimizer.cxx:91
 RooMinimizer.cxx:92
 RooMinimizer.cxx:93
 RooMinimizer.cxx:94
 RooMinimizer.cxx:95
 RooMinimizer.cxx:96
 RooMinimizer.cxx:97
 RooMinimizer.cxx:98
 RooMinimizer.cxx:99
 RooMinimizer.cxx:100
 RooMinimizer.cxx:101
 RooMinimizer.cxx:102
 RooMinimizer.cxx:103
 RooMinimizer.cxx:104
 RooMinimizer.cxx:105
 RooMinimizer.cxx:106
 RooMinimizer.cxx:107
 RooMinimizer.cxx:108
 RooMinimizer.cxx:109
 RooMinimizer.cxx:110
 RooMinimizer.cxx:111
 RooMinimizer.cxx:112
 RooMinimizer.cxx:113
 RooMinimizer.cxx:114
 RooMinimizer.cxx:115
 RooMinimizer.cxx:116
 RooMinimizer.cxx:117
 RooMinimizer.cxx:118
 RooMinimizer.cxx:119
 RooMinimizer.cxx:120
 RooMinimizer.cxx:121
 RooMinimizer.cxx:122
 RooMinimizer.cxx:123
 RooMinimizer.cxx:124
 RooMinimizer.cxx:125
 RooMinimizer.cxx:126
 RooMinimizer.cxx:127
 RooMinimizer.cxx:128
 RooMinimizer.cxx:129
 RooMinimizer.cxx:130
 RooMinimizer.cxx:131
 RooMinimizer.cxx:132
 RooMinimizer.cxx:133
 RooMinimizer.cxx:134
 RooMinimizer.cxx:135
 RooMinimizer.cxx:136
 RooMinimizer.cxx:137
 RooMinimizer.cxx:138
 RooMinimizer.cxx:139
 RooMinimizer.cxx:140
 RooMinimizer.cxx:141
 RooMinimizer.cxx:142
 RooMinimizer.cxx:143
 RooMinimizer.cxx:144
 RooMinimizer.cxx:145
 RooMinimizer.cxx:146
 RooMinimizer.cxx:147
 RooMinimizer.cxx:148
 RooMinimizer.cxx:149
 RooMinimizer.cxx:150
 RooMinimizer.cxx:151
 RooMinimizer.cxx:152
 RooMinimizer.cxx:153
 RooMinimizer.cxx:154
 RooMinimizer.cxx:155
 RooMinimizer.cxx:156
 RooMinimizer.cxx:157
 RooMinimizer.cxx:158
 RooMinimizer.cxx:159
 RooMinimizer.cxx:160
 RooMinimizer.cxx:161
 RooMinimizer.cxx:162
 RooMinimizer.cxx:163
 RooMinimizer.cxx:164
 RooMinimizer.cxx:165
 RooMinimizer.cxx:166
 RooMinimizer.cxx:167
 RooMinimizer.cxx:168
 RooMinimizer.cxx:169
 RooMinimizer.cxx:170
 RooMinimizer.cxx:171
 RooMinimizer.cxx:172
 RooMinimizer.cxx:173
 RooMinimizer.cxx:174
 RooMinimizer.cxx:175
 RooMinimizer.cxx:176
 RooMinimizer.cxx:177
 RooMinimizer.cxx:178
 RooMinimizer.cxx:179
 RooMinimizer.cxx:180
 RooMinimizer.cxx:181
 RooMinimizer.cxx:182
 RooMinimizer.cxx:183
 RooMinimizer.cxx:184
 RooMinimizer.cxx:185
 RooMinimizer.cxx:186
 RooMinimizer.cxx:187
 RooMinimizer.cxx:188
 RooMinimizer.cxx:189
 RooMinimizer.cxx:190
 RooMinimizer.cxx:191
 RooMinimizer.cxx:192
 RooMinimizer.cxx:193
 RooMinimizer.cxx:194
 RooMinimizer.cxx:195
 RooMinimizer.cxx:196
 RooMinimizer.cxx:197
 RooMinimizer.cxx:198
 RooMinimizer.cxx:199
 RooMinimizer.cxx:200
 RooMinimizer.cxx:201
 RooMinimizer.cxx:202
 RooMinimizer.cxx:203
 RooMinimizer.cxx:204
 RooMinimizer.cxx:205
 RooMinimizer.cxx:206
 RooMinimizer.cxx:207
 RooMinimizer.cxx:208
 RooMinimizer.cxx:209
 RooMinimizer.cxx:210
 RooMinimizer.cxx:211
 RooMinimizer.cxx:212
 RooMinimizer.cxx:213
 RooMinimizer.cxx:214
 RooMinimizer.cxx:215
 RooMinimizer.cxx:216
 RooMinimizer.cxx:217
 RooMinimizer.cxx:218
 RooMinimizer.cxx:219
 RooMinimizer.cxx:220
 RooMinimizer.cxx:221
 RooMinimizer.cxx:222
 RooMinimizer.cxx:223
 RooMinimizer.cxx:224
 RooMinimizer.cxx:225
 RooMinimizer.cxx:226
 RooMinimizer.cxx:227
 RooMinimizer.cxx:228
 RooMinimizer.cxx:229
 RooMinimizer.cxx:230
 RooMinimizer.cxx:231
 RooMinimizer.cxx:232
 RooMinimizer.cxx:233
 RooMinimizer.cxx:234
 RooMinimizer.cxx:235
 RooMinimizer.cxx:236
 RooMinimizer.cxx:237
 RooMinimizer.cxx:238
 RooMinimizer.cxx:239
 RooMinimizer.cxx:240
 RooMinimizer.cxx:241
 RooMinimizer.cxx:242
 RooMinimizer.cxx:243
 RooMinimizer.cxx:244
 RooMinimizer.cxx:245
 RooMinimizer.cxx:246
 RooMinimizer.cxx:247
 RooMinimizer.cxx:248
 RooMinimizer.cxx:249
 RooMinimizer.cxx:250
 RooMinimizer.cxx:251
 RooMinimizer.cxx:252
 RooMinimizer.cxx:253
 RooMinimizer.cxx:254
 RooMinimizer.cxx:255
 RooMinimizer.cxx:256
 RooMinimizer.cxx:257
 RooMinimizer.cxx:258
 RooMinimizer.cxx:259
 RooMinimizer.cxx:260
 RooMinimizer.cxx:261
 RooMinimizer.cxx:262
 RooMinimizer.cxx:263
 RooMinimizer.cxx:264
 RooMinimizer.cxx:265
 RooMinimizer.cxx:266
 RooMinimizer.cxx:267
 RooMinimizer.cxx:268
 RooMinimizer.cxx:269
 RooMinimizer.cxx:270
 RooMinimizer.cxx:271
 RooMinimizer.cxx:272
 RooMinimizer.cxx:273
 RooMinimizer.cxx:274
 RooMinimizer.cxx:275
 RooMinimizer.cxx:276
 RooMinimizer.cxx:277
 RooMinimizer.cxx:278
 RooMinimizer.cxx:279
 RooMinimizer.cxx:280
 RooMinimizer.cxx:281
 RooMinimizer.cxx:282
 RooMinimizer.cxx:283
 RooMinimizer.cxx:284
 RooMinimizer.cxx:285
 RooMinimizer.cxx:286
 RooMinimizer.cxx:287
 RooMinimizer.cxx:288
 RooMinimizer.cxx:289
 RooMinimizer.cxx:290
 RooMinimizer.cxx:291
 RooMinimizer.cxx:292
 RooMinimizer.cxx:293
 RooMinimizer.cxx:294
 RooMinimizer.cxx:295
 RooMinimizer.cxx:296
 RooMinimizer.cxx:297
 RooMinimizer.cxx:298
 RooMinimizer.cxx:299
 RooMinimizer.cxx:300
 RooMinimizer.cxx:301
 RooMinimizer.cxx:302
 RooMinimizer.cxx:303
 RooMinimizer.cxx:304
 RooMinimizer.cxx:305
 RooMinimizer.cxx:306
 RooMinimizer.cxx:307
 RooMinimizer.cxx:308
 RooMinimizer.cxx:309
 RooMinimizer.cxx:310
 RooMinimizer.cxx:311
 RooMinimizer.cxx:312
 RooMinimizer.cxx:313
 RooMinimizer.cxx:314
 RooMinimizer.cxx:315
 RooMinimizer.cxx:316
 RooMinimizer.cxx:317
 RooMinimizer.cxx:318
 RooMinimizer.cxx:319
 RooMinimizer.cxx:320
 RooMinimizer.cxx:321
 RooMinimizer.cxx:322
 RooMinimizer.cxx:323
 RooMinimizer.cxx:324
 RooMinimizer.cxx:325
 RooMinimizer.cxx:326
 RooMinimizer.cxx:327
 RooMinimizer.cxx:328
 RooMinimizer.cxx:329
 RooMinimizer.cxx:330
 RooMinimizer.cxx:331
 RooMinimizer.cxx:332
 RooMinimizer.cxx:333
 RooMinimizer.cxx:334
 RooMinimizer.cxx:335
 RooMinimizer.cxx:336
 RooMinimizer.cxx:337
 RooMinimizer.cxx:338
 RooMinimizer.cxx:339
 RooMinimizer.cxx:340
 RooMinimizer.cxx:341
 RooMinimizer.cxx:342
 RooMinimizer.cxx:343
 RooMinimizer.cxx:344
 RooMinimizer.cxx:345
 RooMinimizer.cxx:346
 RooMinimizer.cxx:347
 RooMinimizer.cxx:348
 RooMinimizer.cxx:349
 RooMinimizer.cxx:350
 RooMinimizer.cxx:351
 RooMinimizer.cxx:352
 RooMinimizer.cxx:353
 RooMinimizer.cxx:354
 RooMinimizer.cxx:355
 RooMinimizer.cxx:356
 RooMinimizer.cxx:357
 RooMinimizer.cxx:358
 RooMinimizer.cxx:359
 RooMinimizer.cxx:360
 RooMinimizer.cxx:361
 RooMinimizer.cxx:362
 RooMinimizer.cxx:363
 RooMinimizer.cxx:364
 RooMinimizer.cxx:365
 RooMinimizer.cxx:366
 RooMinimizer.cxx:367
 RooMinimizer.cxx:368
 RooMinimizer.cxx:369
 RooMinimizer.cxx:370
 RooMinimizer.cxx:371
 RooMinimizer.cxx:372
 RooMinimizer.cxx:373
 RooMinimizer.cxx:374
 RooMinimizer.cxx:375
 RooMinimizer.cxx:376
 RooMinimizer.cxx:377
 RooMinimizer.cxx:378
 RooMinimizer.cxx:379
 RooMinimizer.cxx:380
 RooMinimizer.cxx:381
 RooMinimizer.cxx:382
 RooMinimizer.cxx:383
 RooMinimizer.cxx:384
 RooMinimizer.cxx:385
 RooMinimizer.cxx:386
 RooMinimizer.cxx:387
 RooMinimizer.cxx:388
 RooMinimizer.cxx:389
 RooMinimizer.cxx:390
 RooMinimizer.cxx:391
 RooMinimizer.cxx:392
 RooMinimizer.cxx:393
 RooMinimizer.cxx:394
 RooMinimizer.cxx:395
 RooMinimizer.cxx:396
 RooMinimizer.cxx:397
 RooMinimizer.cxx:398
 RooMinimizer.cxx:399
 RooMinimizer.cxx:400
 RooMinimizer.cxx:401
 RooMinimizer.cxx:402
 RooMinimizer.cxx:403
 RooMinimizer.cxx:404
 RooMinimizer.cxx:405
 RooMinimizer.cxx:406
 RooMinimizer.cxx:407
 RooMinimizer.cxx:408
 RooMinimizer.cxx:409
 RooMinimizer.cxx:410
 RooMinimizer.cxx:411
 RooMinimizer.cxx:412
 RooMinimizer.cxx:413
 RooMinimizer.cxx:414
 RooMinimizer.cxx:415
 RooMinimizer.cxx:416
 RooMinimizer.cxx:417
 RooMinimizer.cxx:418
 RooMinimizer.cxx:419
 RooMinimizer.cxx:420
 RooMinimizer.cxx:421
 RooMinimizer.cxx:422
 RooMinimizer.cxx:423
 RooMinimizer.cxx:424
 RooMinimizer.cxx:425
 RooMinimizer.cxx:426
 RooMinimizer.cxx:427
 RooMinimizer.cxx:428
 RooMinimizer.cxx:429
 RooMinimizer.cxx:430
 RooMinimizer.cxx:431
 RooMinimizer.cxx:432
 RooMinimizer.cxx:433
 RooMinimizer.cxx:434
 RooMinimizer.cxx:435
 RooMinimizer.cxx:436
 RooMinimizer.cxx:437
 RooMinimizer.cxx:438
 RooMinimizer.cxx:439
 RooMinimizer.cxx:440
 RooMinimizer.cxx:441
 RooMinimizer.cxx:442
 RooMinimizer.cxx:443
 RooMinimizer.cxx:444
 RooMinimizer.cxx:445
 RooMinimizer.cxx:446
 RooMinimizer.cxx:447
 RooMinimizer.cxx:448
 RooMinimizer.cxx:449
 RooMinimizer.cxx:450
 RooMinimizer.cxx:451
 RooMinimizer.cxx:452
 RooMinimizer.cxx:453
 RooMinimizer.cxx:454
 RooMinimizer.cxx:455
 RooMinimizer.cxx:456
 RooMinimizer.cxx:457
 RooMinimizer.cxx:458
 RooMinimizer.cxx:459
 RooMinimizer.cxx:460
 RooMinimizer.cxx:461
 RooMinimizer.cxx:462
 RooMinimizer.cxx:463
 RooMinimizer.cxx:464
 RooMinimizer.cxx:465
 RooMinimizer.cxx:466
 RooMinimizer.cxx:467
 RooMinimizer.cxx:468
 RooMinimizer.cxx:469
 RooMinimizer.cxx:470
 RooMinimizer.cxx:471
 RooMinimizer.cxx:472
 RooMinimizer.cxx:473
 RooMinimizer.cxx:474
 RooMinimizer.cxx:475
 RooMinimizer.cxx:476
 RooMinimizer.cxx:477
 RooMinimizer.cxx:478
 RooMinimizer.cxx:479
 RooMinimizer.cxx:480
 RooMinimizer.cxx:481
 RooMinimizer.cxx:482
 RooMinimizer.cxx:483
 RooMinimizer.cxx:484
 RooMinimizer.cxx:485
 RooMinimizer.cxx:486
 RooMinimizer.cxx:487
 RooMinimizer.cxx:488
 RooMinimizer.cxx:489
 RooMinimizer.cxx:490
 RooMinimizer.cxx:491
 RooMinimizer.cxx:492
 RooMinimizer.cxx:493
 RooMinimizer.cxx:494
 RooMinimizer.cxx:495
 RooMinimizer.cxx:496
 RooMinimizer.cxx:497
 RooMinimizer.cxx:498
 RooMinimizer.cxx:499
 RooMinimizer.cxx:500
 RooMinimizer.cxx:501
 RooMinimizer.cxx:502
 RooMinimizer.cxx:503
 RooMinimizer.cxx:504
 RooMinimizer.cxx:505
 RooMinimizer.cxx:506
 RooMinimizer.cxx:507
 RooMinimizer.cxx:508
 RooMinimizer.cxx:509
 RooMinimizer.cxx:510
 RooMinimizer.cxx:511
 RooMinimizer.cxx:512
 RooMinimizer.cxx:513
 RooMinimizer.cxx:514
 RooMinimizer.cxx:515
 RooMinimizer.cxx:516
 RooMinimizer.cxx:517
 RooMinimizer.cxx:518
 RooMinimizer.cxx:519
 RooMinimizer.cxx:520
 RooMinimizer.cxx:521
 RooMinimizer.cxx:522
 RooMinimizer.cxx:523
 RooMinimizer.cxx:524
 RooMinimizer.cxx:525
 RooMinimizer.cxx:526
 RooMinimizer.cxx:527
 RooMinimizer.cxx:528
 RooMinimizer.cxx:529
 RooMinimizer.cxx:530
 RooMinimizer.cxx:531
 RooMinimizer.cxx:532
 RooMinimizer.cxx:533
 RooMinimizer.cxx:534
 RooMinimizer.cxx:535
 RooMinimizer.cxx:536
 RooMinimizer.cxx:537
 RooMinimizer.cxx:538
 RooMinimizer.cxx:539
 RooMinimizer.cxx:540
 RooMinimizer.cxx:541
 RooMinimizer.cxx:542
 RooMinimizer.cxx:543
 RooMinimizer.cxx:544
 RooMinimizer.cxx:545
 RooMinimizer.cxx:546
 RooMinimizer.cxx:547
 RooMinimizer.cxx:548
 RooMinimizer.cxx:549
 RooMinimizer.cxx:550
 RooMinimizer.cxx:551
 RooMinimizer.cxx:552
 RooMinimizer.cxx:553
 RooMinimizer.cxx:554
 RooMinimizer.cxx:555
 RooMinimizer.cxx:556
 RooMinimizer.cxx:557
 RooMinimizer.cxx:558
 RooMinimizer.cxx:559
 RooMinimizer.cxx:560
 RooMinimizer.cxx:561
 RooMinimizer.cxx:562
 RooMinimizer.cxx:563
 RooMinimizer.cxx:564
 RooMinimizer.cxx:565
 RooMinimizer.cxx:566
 RooMinimizer.cxx:567
 RooMinimizer.cxx:568
 RooMinimizer.cxx:569
 RooMinimizer.cxx:570
 RooMinimizer.cxx:571
 RooMinimizer.cxx:572
 RooMinimizer.cxx:573
 RooMinimizer.cxx:574
 RooMinimizer.cxx:575
 RooMinimizer.cxx:576
 RooMinimizer.cxx:577
 RooMinimizer.cxx:578
 RooMinimizer.cxx:579
 RooMinimizer.cxx:580
 RooMinimizer.cxx:581
 RooMinimizer.cxx:582
 RooMinimizer.cxx:583
 RooMinimizer.cxx:584
 RooMinimizer.cxx:585
 RooMinimizer.cxx:586
 RooMinimizer.cxx:587
 RooMinimizer.cxx:588
 RooMinimizer.cxx:589
 RooMinimizer.cxx:590
 RooMinimizer.cxx:591
 RooMinimizer.cxx:592
 RooMinimizer.cxx:593
 RooMinimizer.cxx:594
 RooMinimizer.cxx:595
 RooMinimizer.cxx:596
 RooMinimizer.cxx:597
 RooMinimizer.cxx:598
 RooMinimizer.cxx:599
 RooMinimizer.cxx:600
 RooMinimizer.cxx:601
 RooMinimizer.cxx:602
 RooMinimizer.cxx:603
 RooMinimizer.cxx:604
 RooMinimizer.cxx:605
 RooMinimizer.cxx:606
 RooMinimizer.cxx:607
 RooMinimizer.cxx:608
 RooMinimizer.cxx:609
 RooMinimizer.cxx:610
 RooMinimizer.cxx:611
 RooMinimizer.cxx:612
 RooMinimizer.cxx:613
 RooMinimizer.cxx:614
 RooMinimizer.cxx:615
 RooMinimizer.cxx:616
 RooMinimizer.cxx:617
 RooMinimizer.cxx:618
 RooMinimizer.cxx:619
 RooMinimizer.cxx:620
 RooMinimizer.cxx:621
 RooMinimizer.cxx:622
 RooMinimizer.cxx:623
 RooMinimizer.cxx:624
 RooMinimizer.cxx:625
 RooMinimizer.cxx:626
 RooMinimizer.cxx:627
 RooMinimizer.cxx:628
 RooMinimizer.cxx:629
 RooMinimizer.cxx:630
 RooMinimizer.cxx:631
 RooMinimizer.cxx:632
 RooMinimizer.cxx:633
 RooMinimizer.cxx:634
 RooMinimizer.cxx:635
 RooMinimizer.cxx:636
 RooMinimizer.cxx:637
 RooMinimizer.cxx:638
 RooMinimizer.cxx:639
 RooMinimizer.cxx:640
 RooMinimizer.cxx:641
 RooMinimizer.cxx:642
 RooMinimizer.cxx:643
 RooMinimizer.cxx:644
 RooMinimizer.cxx:645
 RooMinimizer.cxx:646
 RooMinimizer.cxx:647
 RooMinimizer.cxx:648
 RooMinimizer.cxx:649
 RooMinimizer.cxx:650
 RooMinimizer.cxx:651
 RooMinimizer.cxx:652
 RooMinimizer.cxx:653
 RooMinimizer.cxx:654
 RooMinimizer.cxx:655
 RooMinimizer.cxx:656
 RooMinimizer.cxx:657
 RooMinimizer.cxx:658
 RooMinimizer.cxx:659
 RooMinimizer.cxx:660
 RooMinimizer.cxx:661
 RooMinimizer.cxx:662
 RooMinimizer.cxx:663
 RooMinimizer.cxx:664
 RooMinimizer.cxx:665
 RooMinimizer.cxx:666
 RooMinimizer.cxx:667
 RooMinimizer.cxx:668
 RooMinimizer.cxx:669
 RooMinimizer.cxx:670
 RooMinimizer.cxx:671
 RooMinimizer.cxx:672
 RooMinimizer.cxx:673
 RooMinimizer.cxx:674
 RooMinimizer.cxx:675
 RooMinimizer.cxx:676
 RooMinimizer.cxx:677
 RooMinimizer.cxx:678
 RooMinimizer.cxx:679
 RooMinimizer.cxx:680
 RooMinimizer.cxx:681
 RooMinimizer.cxx:682
 RooMinimizer.cxx:683
 RooMinimizer.cxx:684
 RooMinimizer.cxx:685
 RooMinimizer.cxx:686
 RooMinimizer.cxx:687
 RooMinimizer.cxx:688
 RooMinimizer.cxx:689
 RooMinimizer.cxx:690
 RooMinimizer.cxx:691
 RooMinimizer.cxx:692
 RooMinimizer.cxx:693
 RooMinimizer.cxx:694
 RooMinimizer.cxx:695
 RooMinimizer.cxx:696
 RooMinimizer.cxx:697
 RooMinimizer.cxx:698
 RooMinimizer.cxx:699
 RooMinimizer.cxx:700
 RooMinimizer.cxx:701
 RooMinimizer.cxx:702
 RooMinimizer.cxx:703
 RooMinimizer.cxx:704
 RooMinimizer.cxx:705
 RooMinimizer.cxx:706
 RooMinimizer.cxx:707
 RooMinimizer.cxx:708
 RooMinimizer.cxx:709
 RooMinimizer.cxx:710
 RooMinimizer.cxx:711
 RooMinimizer.cxx:712
 RooMinimizer.cxx:713
 RooMinimizer.cxx:714
 RooMinimizer.cxx:715
 RooMinimizer.cxx:716
 RooMinimizer.cxx:717
 RooMinimizer.cxx:718
 RooMinimizer.cxx:719
 RooMinimizer.cxx:720
 RooMinimizer.cxx:721
 RooMinimizer.cxx:722
 RooMinimizer.cxx:723
 RooMinimizer.cxx:724
 RooMinimizer.cxx:725
 RooMinimizer.cxx:726
 RooMinimizer.cxx:727
 RooMinimizer.cxx:728
 RooMinimizer.cxx:729
 RooMinimizer.cxx:730
 RooMinimizer.cxx:731
 RooMinimizer.cxx:732
 RooMinimizer.cxx:733
 RooMinimizer.cxx:734
 RooMinimizer.cxx:735
 RooMinimizer.cxx:736
 RooMinimizer.cxx:737
 RooMinimizer.cxx:738
 RooMinimizer.cxx:739
 RooMinimizer.cxx:740
 RooMinimizer.cxx:741
 RooMinimizer.cxx:742
 RooMinimizer.cxx:743
 RooMinimizer.cxx:744
 RooMinimizer.cxx:745
 RooMinimizer.cxx:746
 RooMinimizer.cxx:747
 RooMinimizer.cxx:748
 RooMinimizer.cxx:749
 RooMinimizer.cxx:750
 RooMinimizer.cxx:751
 RooMinimizer.cxx:752
 RooMinimizer.cxx:753
 RooMinimizer.cxx:754
 RooMinimizer.cxx:755
 RooMinimizer.cxx:756
 RooMinimizer.cxx:757
 RooMinimizer.cxx:758
 RooMinimizer.cxx:759
 RooMinimizer.cxx:760
 RooMinimizer.cxx:761
 RooMinimizer.cxx:762
 RooMinimizer.cxx:763
 RooMinimizer.cxx:764
 RooMinimizer.cxx:765
 RooMinimizer.cxx:766
 RooMinimizer.cxx:767
 RooMinimizer.cxx:768
 RooMinimizer.cxx:769
 RooMinimizer.cxx:770
 RooMinimizer.cxx:771
 RooMinimizer.cxx:772
 RooMinimizer.cxx:773
 RooMinimizer.cxx:774
 RooMinimizer.cxx:775
 RooMinimizer.cxx:776
 RooMinimizer.cxx:777
 RooMinimizer.cxx:778
 RooMinimizer.cxx:779
 RooMinimizer.cxx:780
 RooMinimizer.cxx:781
 RooMinimizer.cxx:782
 RooMinimizer.cxx:783
 RooMinimizer.cxx:784
 RooMinimizer.cxx:785
 RooMinimizer.cxx:786
 RooMinimizer.cxx:787
 RooMinimizer.cxx:788
 RooMinimizer.cxx:789
 RooMinimizer.cxx:790
 RooMinimizer.cxx:791
 RooMinimizer.cxx:792
 RooMinimizer.cxx:793
 RooMinimizer.cxx:794
 RooMinimizer.cxx:795
 RooMinimizer.cxx:796
 RooMinimizer.cxx:797
 RooMinimizer.cxx:798
 RooMinimizer.cxx:799
 RooMinimizer.cxx:800
 RooMinimizer.cxx:801
 RooMinimizer.cxx:802
 RooMinimizer.cxx:803
 RooMinimizer.cxx:804
 RooMinimizer.cxx:805
 RooMinimizer.cxx:806
 RooMinimizer.cxx:807
 RooMinimizer.cxx:808
 RooMinimizer.cxx:809
 RooMinimizer.cxx:810
 RooMinimizer.cxx:811
 RooMinimizer.cxx:812
 RooMinimizer.cxx:813
 RooMinimizer.cxx:814
 RooMinimizer.cxx:815
 RooMinimizer.cxx:816
 RooMinimizer.cxx:817
 RooMinimizer.cxx:818
 RooMinimizer.cxx:819
 RooMinimizer.cxx:820
 RooMinimizer.cxx:821
 RooMinimizer.cxx:822
 RooMinimizer.cxx:823
 RooMinimizer.cxx:824
 RooMinimizer.cxx:825
 RooMinimizer.cxx:826
 RooMinimizer.cxx:827
 RooMinimizer.cxx:828
 RooMinimizer.cxx:829
 RooMinimizer.cxx:830
 RooMinimizer.cxx:831
 RooMinimizer.cxx:832
 RooMinimizer.cxx:833
 RooMinimizer.cxx:834
 RooMinimizer.cxx:835
 RooMinimizer.cxx:836
 RooMinimizer.cxx:837
 RooMinimizer.cxx:838
 RooMinimizer.cxx:839
 RooMinimizer.cxx:840
 RooMinimizer.cxx:841
 RooMinimizer.cxx:842
 RooMinimizer.cxx:843
 RooMinimizer.cxx:844
 RooMinimizer.cxx:845
 RooMinimizer.cxx:846
 RooMinimizer.cxx:847
 RooMinimizer.cxx:848
 RooMinimizer.cxx:849
 RooMinimizer.cxx:850
 RooMinimizer.cxx:851
 RooMinimizer.cxx:852
 RooMinimizer.cxx:853
 RooMinimizer.cxx:854
 RooMinimizer.cxx:855
 RooMinimizer.cxx:856
 RooMinimizer.cxx:857
 RooMinimizer.cxx:858
 RooMinimizer.cxx:859
 RooMinimizer.cxx:860
 RooMinimizer.cxx:861
 RooMinimizer.cxx:862
 RooMinimizer.cxx:863
 RooMinimizer.cxx:864
 RooMinimizer.cxx:865
 RooMinimizer.cxx:866
 RooMinimizer.cxx:867
 RooMinimizer.cxx:868
 RooMinimizer.cxx:869
 RooMinimizer.cxx:870
 RooMinimizer.cxx:871
 RooMinimizer.cxx:872
 RooMinimizer.cxx:873
 RooMinimizer.cxx:874
 RooMinimizer.cxx:875
 RooMinimizer.cxx:876
 RooMinimizer.cxx:877
 RooMinimizer.cxx:878
 RooMinimizer.cxx:879
 RooMinimizer.cxx:880
 RooMinimizer.cxx:881
 RooMinimizer.cxx:882
 RooMinimizer.cxx:883
 RooMinimizer.cxx:884
 RooMinimizer.cxx:885
 RooMinimizer.cxx:886
 RooMinimizer.cxx:887
 RooMinimizer.cxx:888
 RooMinimizer.cxx:889
 RooMinimizer.cxx:890
 RooMinimizer.cxx:891
 RooMinimizer.cxx:892
 RooMinimizer.cxx:893
 RooMinimizer.cxx:894
 RooMinimizer.cxx:895
 RooMinimizer.cxx:896
 RooMinimizer.cxx:897
 RooMinimizer.cxx:898
 RooMinimizer.cxx:899
 RooMinimizer.cxx:900
 RooMinimizer.cxx:901
 RooMinimizer.cxx:902
 RooMinimizer.cxx:903
 RooMinimizer.cxx:904
 RooMinimizer.cxx:905
 RooMinimizer.cxx:906
 RooMinimizer.cxx:907
 RooMinimizer.cxx:908
 RooMinimizer.cxx:909
 RooMinimizer.cxx:910
 RooMinimizer.cxx:911
 RooMinimizer.cxx:912
 RooMinimizer.cxx:913
 RooMinimizer.cxx:914
 RooMinimizer.cxx:915
 RooMinimizer.cxx:916
 RooMinimizer.cxx:917
 RooMinimizer.cxx:918
 RooMinimizer.cxx:919
 RooMinimizer.cxx:920
 RooMinimizer.cxx:921
 RooMinimizer.cxx:922
 RooMinimizer.cxx:923
 RooMinimizer.cxx:924
 RooMinimizer.cxx:925
 RooMinimizer.cxx:926
 RooMinimizer.cxx:927
 RooMinimizer.cxx:928
 RooMinimizer.cxx:929
 RooMinimizer.cxx:930
 RooMinimizer.cxx:931
 RooMinimizer.cxx:932
 RooMinimizer.cxx:933
 RooMinimizer.cxx:934
 RooMinimizer.cxx:935
 RooMinimizer.cxx:936
 RooMinimizer.cxx:937
 RooMinimizer.cxx:938