ROOT logo
#include "TROOT.h"
#include "TBackCompFitter.h"


#include "TMethodCall.h"
#include "TInterpreter.h"

#include "Math/Util.h"

#include <iostream>
#include <cassert>

//needed by GetCondifenceLevel
#include "Math/IParamFunction.h"
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TMath.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TGraph2DErrors.h"
#include "TMultiGraph.h"
#include "HFitInterface.h"
#include "Math/Minimizer.h"
#include "Fit/BinData.h"
#include "Fit/UnBinData.h"
#include "Fit/PoissonLikelihoodFCN.h"
#include "Fit/LogLikelihoodFCN.h"
#include "Fit/Chi2FCN.h"
#include "Fit/FcnAdapter.h"
#include "TFitResult.h"

//#define DEBUG 1


//______________________________________________________________________________
/**
   Backward compatible implementation of TVirtualFitter using the the class ROOT::Fit::Fitter.
   This class is created after fitting an histogram (TH1), TGraph or TTree and provides in addition to the 
   methods of the TVirtualFitter hooks to access the fit result class (ROOT::Fit::FitResult), the fit configuration
   (ROOT::Fit::FitConfig) or the fit data (ROOT::Fit::FitData) using
   <pre>
   TBackCompFitter * fitter = (TBackCompFitter *) TVirtualFitter::GetFitter();
   ROOT::Fit::FitResult & result = fitter->GetFitResult();
   result.Print(std::cout);
   </pre>
   
   Methods for getting the confidence level or contours are also provided. 
   Note that after a new calls to TH1::Fit (or similar) the class will be deleted and all reference to the FitResult, FitConfig 
   or minimizer will be invalid. One could eventually copying  the class before issuing a new fit to avoid deleting this information
*/



ClassImp(TBackCompFitter);



TBackCompFitter::TBackCompFitter( ) : 
   fMinimizer(0), 
   fObjFunc(0),
   fModelFunc(0)
{
   // Constructur needed by TVirtualFitter interface. Same behavior as default constructor.
   // initialize setting name and the global pointer
   SetName("BCFitter");
}

TBackCompFitter::TBackCompFitter(std::auto_ptr<ROOT::Fit::Fitter> fitter, std::auto_ptr<ROOT::Fit::FitData>  data) : 
   fFitData(data),
   fFitter(fitter),
   fMinimizer(0),
   fObjFunc(0),
   fModelFunc(0)
{
   // constructor used after having fit using directly ROOT::Fit::Fitter
   // will create a dummy fitter copying configuration and parameter settings
   SetName("LastFitter");
}




TBackCompFitter::~TBackCompFitter() { 
   // data are own here
   //if (fFitData) delete fFitData; 

   if (fMinimizer) delete fMinimizer; 
   if (fObjFunc) delete fObjFunc; 
   if (fModelFunc) delete fModelFunc;
}

Double_t TBackCompFitter::Chisquare(Int_t npar, Double_t *params) const {
   // do chisquare calculations in case of likelihood fits 
   // do evaluation a the minimum only 
   const std::vector<double> & minpar = fFitter->Result().Parameters(); 
   assert (npar == (int) minpar.size() ); 
   double diff = 0; 
   double s = 0; 
   for (int i =0; i < npar; ++i) { 
      diff += std::abs( params[i] - minpar[i] );  
      s += minpar[i]; 
   }

   if (diff > s * 1.E-12 ) Warning("Chisquare","given parameter values are not at minimum - chi2 at minimum is returned"); 
   return fFitter->Result().Chi2(); 
}

void TBackCompFitter::Clear(Option_t*) {
   // clear resources for consecutive fits

   // need to do something here ??? to be seen
   
   
}





Int_t TBackCompFitter::ExecuteCommand(const char *command, Double_t *args, Int_t nargs){	
   // execute the command (Fortran Minuit compatible interface)
   
#ifdef DEBUG
   std::cout<<"Execute command= "<<command<<std::endl;
#endif

   // set also number of parameters in obj function
   DoSetDimension(); 

   TString scommand(command); 
   scommand.ToUpper();

   // MIGRAD 
   if (scommand.Contains("MIG")) {
      if (!fObjFunc) { 
         Error("ExecuteCommand","FCN must set before executing this command"); 
         return -1; 
      }

      fFitter->Config().SetMinimizer(GetDefaultFitter(), "Migrad");
      bool ret = fFitter->FitFCN(*fObjFunc); 
      return  (ret) ? 0 : -1;      
   } 

   //Minimize
   if (scommand.Contains("MINI")) {

      fFitter->Config().SetMinimizer(GetDefaultFitter(), "Minimize");
      if (!fObjFunc) { 
         Error("ExecuteCommand","FCN must set before executing this command"); 
         return -1; 
      }
      bool ret = fFitter->FitFCN(*fObjFunc); 
      return  (ret) ? 0 : -1;
   }
   //Simplex
   if (scommand.Contains("SIM")) {
      
      if (!fObjFunc) { 
         Error("ExecuteCommand","FCN must set before executing this command"); 
         return -1; 
      }

      fFitter->Config().SetMinimizer(GetDefaultFitter(), "Simplex");
      bool ret = fFitter->FitFCN(*fObjFunc); 
      return  (ret) ? 0 : -1;
   }
   //SCan
   if (scommand.Contains("SCA")) {
      
      if (!fObjFunc) { 
         Error("ExecuteCommand","FCN must set before executing this command"); 
         return -1; 
      }

      fFitter->Config().SetMinimizer(GetDefaultFitter(), "Scan");
      bool ret = fFitter->FitFCN(*fObjFunc); 
      return  (ret) ? 0 : -1;
   }
   // MINOS 
   else if (scommand.Contains("MINO"))   {

      if (fFitter->Config().MinosErrors() ) return 0; 

      if (!fObjFunc) { 
         Error("ExecuteCommand","FCN must set before executing this command"); 
         return -1; 
      }
      // do only MINOS. need access to minimizer. For the moment re-run fitting with minos options 
      fFitter->Config().SetMinosErrors(true);
      // set new parameter values

      fFitter->Config().SetMinimizer(GetDefaultFitter(), "Migrad"); // redo -minimization with Minos
      bool ret = fFitter->FitFCN(*fObjFunc); 
      return  (ret) ? 0 : -1;

   } 
   //HESSE
   else if (scommand.Contains("HES"))   {

      if (fFitter->Config().ParabErrors() ) return 0; 

      if (!fObjFunc) { 
         Error("ExecuteCommand","FCN must set before executing this command"); 
         return -1; 
      }

      // do only HESSE. need access to minimizer. For the moment re-run fitting with hesse options 
      fFitter->Config().SetParabErrors(true);
      fFitter->Config().SetMinimizer(GetDefaultFitter(), "Migrad"); // redo -minimization with Minos
      bool ret = fFitter->FitFCN(*fObjFunc); 
      return  (ret) ? 0 : -1;
   } 
   
   // FIX 
   else if (scommand.Contains("FIX"))   {
      for(int i = 0; i < nargs; i++) {
         FixParameter(int(args[i])-1);
      }
      return 0;
   } 
   // SET LIMIT (upper and lower)
   else if (scommand.Contains("SET LIM"))   {
      if (nargs < 3) { 
         Error("ExecuteCommand","Invalid parameters given in SET LIMIT");
         return -1; 
      }
      int ipar = int(args[0]);
      if (!ValidParameterIndex(ipar) )  return -1;   
      double low = args[1];
      double up = args[2];
      fFitter->Config().ParSettings(ipar).SetLimits(low,up);
      return 0; 
   } 
   // SET PRINT
   else if (scommand.Contains("SET PRIN"))   {
      if (nargs < 1) return -1;  
      fFitter->Config().MinimizerOptions().SetPrintLevel(int(args[0]) );
      return 0; 
   } 
   // SET ERR
   else if (scommand.Contains("SET ERR"))   {
      if (nargs < 1) return -1;  
      fFitter->Config().MinimizerOptions().SetPrintLevel(int( args[0]) );
      return 0; 
   } 
   // SET STRATEGY
   else if (scommand.Contains("SET STR"))   {
      if (nargs < 1) return -1;  
      fFitter->Config().MinimizerOptions().SetStrategy(int(args[0]) );
      return 0; 
   } 
   //SET GRAD (not impl.) 
   else if (scommand.Contains("SET GRA"))   {
      //     not yet available
      //     fGradient = true;
      return -1;
   } 
   //SET NOW (not impl.) 
   else if (scommand.Contains("SET NOW"))   {
      //     no warning (works only for TMinuit)
      //     fGradient = true;
      return -1;
   } 
   // CALL FCN
   else if (scommand.Contains("CALL FCN"))   {
      //     call fcn function (global pointer to free function)

      if (nargs < 1 || fFCN == 0 ) return -1;
      int npar = fObjFunc->NDim();
      // use values in fit result if existing  otherwise in ParameterSettings
      std::vector<double> params(npar); 
      for (int i = 0; i < npar; ++i) 
         params[i] = GetParameter(i); 

      double fval = 0;
      (*fFCN)(npar, 0, fval, &params[0],int(args[0]) ) ;
      return 0; 
   } 
   else {
      // other commands passed 
      Error("ExecuteCommand","Invalid or not supported command given %s",command);
      return -1;
   }
   
   
}

bool TBackCompFitter::ValidParameterIndex(int ipar) const  { 
   // check if ipar is a valid parameter index
   int nps  = fFitter->Config().ParamsSettings().size(); 
   if (ipar  < 0 || ipar >= nps ) { 
      std::string msg = ROOT::Math::Util::ToString(ipar) + " is an invalid Parameter index";
      Error("ValidParameterIndex","%s",msg.c_str());
      return false;
   } 
   return true; 
}

void TBackCompFitter::FixParameter(Int_t ipar) {
   // fix the paramter
   //   std::cout<<"FixParameter"<<std::endl;
   if (ValidParameterIndex(ipar) )    
      fFitter->Config().ParSettings(ipar).Fix();
}



void TBackCompFitter::GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl)
{
//Computes point-by-point confidence intervals for the fitted function
//Parameters:
//n - number of points
//ndim - dimensions of points
//x - points, at which to compute the intervals, for ndim > 1 
//    should be in order: (x0,y0, x1, y1, ... xn, yn)
//ci - computed intervals are returned in this array
//cl - confidence level, default=0.95
//NOTE, that the intervals are approximate for nonlinear(in parameters) models
   
   if (!fFitter->Result().IsValid()) { 
      Error("GetConfidenceIntervals","Cannot compute confidence intervals with an invalide fit result");
      return; 
   }
   
   fFitter->Result().GetConfidenceIntervals(n,ndim,1,x,ci,cl);         
}

void TBackCompFitter::GetConfidenceIntervals(TObject *obj, Double_t cl)
{
//Computes confidence intervals at level cl. Default is 0.95
//The TObject parameter can be a TGraphErrors, a TGraph2DErrors or a TH1,2,3.
//For Graphs, confidence intervals are computed for each point,
//the value of the graph at that point is set to the function value at that
//point, and the graph y-errors (or z-errors) are set to the value of
//the confidence interval at that point.
//For Histograms, confidence intervals are computed for each bin center
//The bin content of this bin is then set to the function value at the bin
//center, and the bin error is set to the confidence interval value.
//NOTE: confidence intervals are approximate for nonlinear models!
//
//Allowed combinations:
//Fitted object               Passed object
//TGraph                      TGraphErrors, TH1
//TGraphErrors, AsymmErrors   TGraphErrors, TH1
//TH1                         TGraphErrors, TH1
//TGraph2D                    TGraph2DErrors, TH2
//TGraph2DErrors              TGraph2DErrors, TH2
//TH2                         TGraph2DErrors, TH2
//TH3                         TH3

   if (!fFitter->Result().IsValid() ) { 
      Error("GetConfidenceIntervals","Cannot compute confidence intervals with an invalide fit result");
      return; 
   }

   // get data dimension from fit object
   int datadim = 1; 
   TObject * fitobj = GetObjectFit(); 
   if (!fitobj) { 
      Error("GetConfidenceIntervals","Cannot compute confidence intervals without a fitting object");
      return; 
   }

   if (fitobj->InheritsFrom(TGraph2D::Class())) datadim = 2; 
   if (fitobj->InheritsFrom(TH1::Class())) { 
      TH1 * h1 = dynamic_cast<TH1*>(fitobj); 
      assert(h1 != 0); 
      datadim = h1->GetDimension(); 
   } 

   if (datadim == 1) { 
      if (!obj->InheritsFrom(TGraphErrors::Class()) && !obj->InheritsFrom(TH1::Class() ) )  {
         Error("GetConfidenceIntervals", "Invalid object passed for storing confidence level data, must be a TGraphErrors or a TH1");
         return; 
      }
   } 
   if (datadim == 2) { 
      if (!obj->InheritsFrom(TGraph2DErrors::Class()) && !obj->InheritsFrom(TH2::Class() ) )  {
         Error("GetConfidenceIntervals", "Invalid object passed for storing confidence level data, must be a TGraph2DErrors or a TH2");
         return; 
      }
   }
   if (datadim == 3) { 
      if (!obj->InheritsFrom(TH3::Class() ) )  {
         Error("GetConfidenceIntervals", "Invalid object passed for storing confidence level data, must be a TH3");
         return; 
      }
   }

   // fill bin data (for the moment use all ranges) according to object passed
   ROOT::Fit::BinData data; 
   data.Opt().fUseEmpty = true; // need to use all bins of given histograms
   // call appropriate function according to type of object
   if (obj->InheritsFrom(TGraph::Class()) ) 
      ROOT::Fit::FillData(data, dynamic_cast<TGraph *>(obj) ); 
   else if (obj->InheritsFrom(TGraph2D::Class()) ) 
      ROOT::Fit::FillData(data, dynamic_cast<TGraph2D *>(obj) ); 
//    else if (obj->InheritsFrom(TMultiGraph::Class()) ) 
//       ROOT::Fit::FillData(data, dynamic_cast<TMultiGraph *>(obj) ); 
   else if (obj->InheritsFrom(TH1::Class()) ) 
      ROOT::Fit::FillData(data, dynamic_cast<TH1 *>(obj) ); 
   

   unsigned int n = data.Size(); 

   std::vector<double> ci( n ); 

   fFitter->Result().GetConfidenceIntervals(data,&ci[0],cl);         

   const ROOT::Math::IParamMultiFunction * func =  fFitter->Result().FittedFunction(); 
   assert(func != 0); 

   // fill now the object with cl data
   for (unsigned int i = 0; i < n; ++i) {
      const double * x = data.Coords(i); 
      double y = (*func)( x ); // function is evaluated using its  parameters

      if (obj->InheritsFrom(TGraphErrors::Class()) ) { 
         TGraphErrors * gr = dynamic_cast<TGraphErrors *> (obj); 
         assert(gr != 0); 
         gr->SetPoint(i, *x, y); 
         gr->SetPointError(i, 0, ci[i]); 
      }
      if (obj->InheritsFrom(TGraph2DErrors::Class()) ) { 
         TGraph2DErrors * gr = dynamic_cast<TGraph2DErrors *> (obj); 
         assert(gr != 0); 
         gr->SetPoint(i, x[0], x[1], y); 
         gr->SetPointError(i, 0, 0, ci[i]); 
      }
      if (obj->InheritsFrom(TH1::Class()) ) { 
         TH1 * h1 = dynamic_cast<TH1 *> (obj); 
         assert(h1 != 0); 
         int ibin = 0; 
         if (datadim == 1) ibin = h1->FindBin(*x); 
         if (datadim == 2) ibin = h1->FindBin(x[0],x[1]); 
         if (datadim == 3) ibin = h1->FindBin(x[0],x[1],x[2]); 
         h1->SetBinContent(ibin, y); 
         h1->SetBinError(ibin, ci[i]); 
      }
   }

}

Double_t* TBackCompFitter::GetCovarianceMatrix() const {
   // get the error matrix in a pointer to a NxN array.  
   // excluding the fixed parameters 

   unsigned int nfreepar =   GetNumberFreeParameters();
   unsigned int ntotpar =   GetNumberTotalParameters();
   
   if (fCovar.size() !=  nfreepar*nfreepar ) 
      fCovar.resize(nfreepar*nfreepar);

   if (!fFitter->Result().IsValid() ) { 
      Warning("GetCovarianceMatrix","Invalid fit result");
      return 0; 
   }

   unsigned int l = 0; 
   for (unsigned int i = 0; i < ntotpar; ++i) { 
      if (fFitter->Config().ParSettings(i).IsFixed() ) continue;
      unsigned int m = 0; 
      for (unsigned int j = 0; j < ntotpar; ++j) {
         if (fFitter->Config().ParSettings(j).IsFixed() ) continue;
         unsigned int index = nfreepar*l + m;
         assert(index < fCovar.size() );
         fCovar[index] = fFitter->Result().CovMatrix(i,j);
         m++;
      }
      l++;
   }
   return &(fCovar.front());
}

Double_t TBackCompFitter::GetCovarianceMatrixElement(Int_t i, Int_t j) const {
   // get error matrix element (return all zero if matrix is not available)

   unsigned int np2 = fCovar.size();
   unsigned int npar = GetNumberFreeParameters(); 
   if ( np2 == 0 || np2 != npar *npar ) { 
      double * c = GetCovarianceMatrix();
      if (c == 0) return 0;  
   }
   return fCovar[i*npar + j];  
}


Int_t TBackCompFitter::GetErrors(Int_t ipar,Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const {
   // get fit errors 

   if (!ValidParameterIndex(ipar) )   return -1; 
   
   const ROOT::Fit::FitResult & result = fFitter->Result(); 
   if (!result.IsValid() ) { 
      Warning("GetErrors","Invalid fit result");
      return -1; 
   }

   eparab = result.Error(ipar); 
   eplus = result.UpperError(ipar); 
   eminus = result.LowerError(ipar); 
   globcc = result.GlobalCC(ipar); 
   return 0;
}

Int_t TBackCompFitter::GetNumberTotalParameters() const {
   // number of total parameters 
   return fFitter->Result().NTotalParameters();  
}
Int_t TBackCompFitter::GetNumberFreeParameters() const {
   // number of variable parameters
   return fFitter->Result().NFreeParameters();  
}


Double_t TBackCompFitter::GetParError(Int_t ipar) const {
   // parameter error
   if (fFitter->Result().IsEmpty() ) {
      if (ValidParameterIndex(ipar) )  return  fFitter->Config().ParSettings(ipar).StepSize();
      else return 0; 
   }
   return fFitter->Result().Error(ipar);  
}

Double_t TBackCompFitter::GetParameter(Int_t ipar) const {
   // parameter value
   if (fFitter->Result().IsEmpty() ) {
      if (ValidParameterIndex(ipar) )  return  fFitter->Config().ParSettings(ipar).Value();
      else return 0; 
   }
   return fFitter->Result().Value(ipar);  
}

Int_t TBackCompFitter::GetParameter(Int_t ipar,char *name,Double_t &value,Double_t &verr,Double_t &vlow, Double_t &vhigh) const {
   // get all parameter info (name, value, errors) 
   if (!ValidParameterIndex(ipar) )    {
      return -1; 
   }
   const std::string & pname = fFitter->Config().ParSettings(ipar).Name(); 
   const char * c = pname.c_str(); 
   std::copy(c,c + pname.size(),name);

   if (fFitter->Result().IsEmpty() ) { 
      value = fFitter->Config().ParSettings(ipar).Value(); 
      verr  = fFitter->Config().ParSettings(ipar).Value();  // error is step size in this case 
      vlow  = fFitter->Config().ParSettings(ipar).LowerLimit();  // vlow is lower limit in this case 
      vhigh   = fFitter->Config().ParSettings(ipar).UpperLimit();  // vlow is lower limit in this case 
      return 1; 
   }
   else { 
      value =  fFitter->Result().Value(ipar);  
      verr = fFitter->Result().Error(ipar);  
      vlow = fFitter->Result().LowerError(ipar);  
      vhigh = fFitter->Result().UpperError(ipar);  
   }
   return 0; 
}

const char *TBackCompFitter::GetParName(Int_t ipar) const {
   //   return name of parameter ipar
   if (!ValidParameterIndex(ipar) )    {
      return 0; 
   }
   return fFitter->Config().ParSettings(ipar).Name().c_str(); 
}

Int_t TBackCompFitter::GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const {
   // get fit statistical information
   const ROOT::Fit::FitResult & result = fFitter->Result(); 
   amin = result.MinFcnValue(); 
   edm = result.Edm(); 
   errdef = fFitter->Config().MinimizerOptions().ErrorDef(); 
   nvpar = result.NFreeParameters();  
   nparx = result.NTotalParameters();  
   return 0;
}

Double_t TBackCompFitter::GetSumLog(Int_t) {
   //   sum of log . Un-needed
   Warning("GetSumLog","Dummy  method - returned 0"); 
   return 0.;
}


Bool_t TBackCompFitter::IsFixed(Int_t ipar) const {
   // query if parameter ipar is fixed
   if (!ValidParameterIndex(ipar) )    {
      return false; 
   }
   return fFitter->Config().ParSettings(ipar).IsFixed(); 
}


void TBackCompFitter::PrintResults(Int_t level, Double_t ) const {
   // print the fit result
   // use PrintResults function in case of Minuit for old -style printing
   if (fFitter->GetMinimizer() && fFitter->Config().MinimizerType() == "Minuit")
      fFitter->GetMinimizer()->PrintResults();
   else { 
      if (level > 0) fFitter->Result().Print(std::cout); 
      if (level > 1)  fFitter->Result().PrintCovMatrix(std::cout);    
   }
   // need to print minos errors and globalCC + other info
}

void TBackCompFitter::ReleaseParameter(Int_t ipar) {
   // release a fit parameter
   if (ValidParameterIndex(ipar) )    
      fFitter->Config().ParSettings(ipar).Release(); 
}



void TBackCompFitter::SetFitMethod(const char *) {
   // set fit method (i.e. chi2 or likelihood)
   // according to the method the appropriate FCN function will be created   
   Info("SetFitMethod","non supported method");
}

Int_t TBackCompFitter::SetParameter(Int_t ipar,const char *parname,Double_t value,Double_t verr,Double_t vlow, Double_t vhigh) {
   // set (add) a new fit parameter passing initial value,  step size (verr) and parametr limits
   // if vlow > vhigh the parameter is unbounded
   // if the stepsize (verr) == 0 the parameter is treated as fixed   

   std::vector<ROOT::Fit::ParameterSettings> & parlist = fFitter->Config().ParamsSettings(); 
   if ( ipar >= (int) parlist.size() ) parlist.resize(ipar+1); 
   ROOT::Fit::ParameterSettings ps(parname, value, verr); 
   if (verr == 0) ps.Fix(); 
   if (vlow < vhigh) ps.SetLimits(vlow, vhigh); 
   parlist[ipar] = ps; 
   return 0; 
}

// static method evaluating FCN
// void TBackCompFitter::FCN( int &, double * , double & f, double * x , int /* iflag */) { 
//    // get static instance of fitter
//    TBackCompFitter * fitter = dynamic_cast<TBackCompFitter *>(TVirtualFitter::GetFitter()); 
//    assert(fitter); 
//    if (fitter->fObjFunc == 0) fitter->RecreateFCN(); 
//    assert(fitter->fObjFunc);
//    f = (*(fitter.fObjFunc) )(x);
// }

void TBackCompFitter::ReCreateMinimizer() { 
   // Recreate a minimizer instance using the function and data 
   // set objective function in minimizers function to re-create FCN from stored data object and fit options
   assert(fFitData.get());

   // case of standard fits (not made fia Fitter::FitFCN) 
   if (fFitter->Result().FittedFunction() != 0) {

      if (fModelFunc) delete fModelFunc; 
      fModelFunc =  dynamic_cast<ROOT::Math::IParamMultiFunction *>((fFitter->Result().FittedFunction())->Clone());
      assert(fModelFunc);

      // create fcn functions, should consider also gradient case
      const ROOT::Fit::BinData * bindata = dynamic_cast<const ROOT::Fit::BinData *>(fFitData.get()); 
      if (bindata) { 
         if (GetFitOption().Like ) 
            fObjFunc = new ROOT::Fit::PoissonLikelihoodFCN<ROOT::Math::IMultiGenFunction>(*bindata, *fModelFunc);
         else
            fObjFunc = new ROOT::Fit::Chi2FCN<ROOT::Math::IMultiGenFunction>(*bindata, *fModelFunc);
      }
      else { 
         const ROOT::Fit::UnBinData * unbindata = dynamic_cast<const ROOT::Fit::UnBinData *>(fFitData.get()); 
         assert(unbindata); 
         fObjFunc = new ROOT::Fit::LogLikelihoodFCN<ROOT::Math::IMultiGenFunction>(*unbindata, *fModelFunc);
      }
   }
   

   // recreate the minimizer
   fMinimizer = fFitter->Config().CreateMinimizer(); 
   if (fMinimizer == 0) { 
      Error("SetMinimizerFunction","cannot create minimizer %s",fFitter->Config().MinimizerType().c_str() );
   }
   else {
      if (!fObjFunc) {
         Error("SetMinimizerFunction","Object Function pointer is NULL");
      }
      else 
         fMinimizer->SetFunction(*fObjFunc);
   }
  
} 



void TBackCompFitter::SetFCN(void (*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
{
   // override setFCN to use the Adapter to Minuit2 FCN interface
   //*-*-*-*-*-*-*To set the address of the minimization function*-*-*-*-*-*-*-*
   //*-*          ===============================================
   //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
   fFCN = fcn;
   if (fObjFunc) delete fObjFunc;
   fObjFunc = new ROOT::Fit::FcnAdapter(fFCN);
   DoSetDimension(); 
}

// need for interactive environment


// global functions needed by interpreter 


//______________________________________________________________________________
void InteractiveFCNm2(Int_t &npar, Double_t *gin, Double_t &f, Double_t *u, Int_t flag)
{
   //*-*-*-*-*-*-*Static function called when SetFCN is called in interactive mode
   //*-*          ===============================================
   
   // get method call from static instance
   TMethodCall *m  = (TVirtualFitter::GetFitter())->GetMethodCall();
   if (!m) return;
   
   Long_t args[5];
   args[0] = (Long_t)&npar;
   args[1] = (Long_t)gin;
   args[2] = (Long_t)&f;
   args[3] = (Long_t)u;
   args[4] = (Long_t)flag;
   m->SetParamPtrs(args);
   Double_t result;
   m->Execute(result);
}


//______________________________________________________________________________
void TBackCompFitter::SetFCN(void *fcn)
{
   //*-*-*-*-*-*-*To set the address of the minimization function*-*-*-*-*-*-*-*
   //*-*          ===============================================
   //     this function is called by CINT instead of the function above
   //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
   
   if (!fcn) return;
   
   const char *funcname = gCint->Getp2f2funcname(fcn);
   if (funcname) {
      fMethodCall = new TMethodCall();
      fMethodCall->InitWithPrototype(funcname,"Int_t&,Double_t*,Double_t&,Double_t*,Int_t");
   }
   fFCN = InteractiveFCNm2;
   // set the static instance (required by InteractiveFCNm)
   TVirtualFitter::SetFitter(this); 
   
   if (fObjFunc) delete fObjFunc;
   fObjFunc = new ROOT::Fit::FcnAdapter(fFCN);
   DoSetDimension(); 
}

void TBackCompFitter::SetObjFunction(ROOT::Math::IMultiGenFunction   * fcn) { 
   // set the objective function for fitting
   // Needed if fitting directly using TBackCompFitter class
   // The class clones a copy of the function and manages it
   if (fObjFunc) delete fObjFunc;
   fObjFunc = fcn->Clone(); 
}


void TBackCompFitter::DoSetDimension() { 
   // Private method to set dimension in objective function
   if (!fObjFunc) return; 
   ROOT::Fit::FcnAdapter * fobj = dynamic_cast<ROOT::Fit::FcnAdapter*>(fObjFunc); 
   assert(fobj != 0); 
   int ndim = fFitter->Config().ParamsSettings().size(); 
   if (ndim != 0) fobj->SetDimension(ndim); 
}

ROOT::Math::IMultiGenFunction * TBackCompFitter::GetObjFunction( ) const { 
   // return a pointer to the objective function (FCN) 
   // If fitting directly using TBackCompFitter the pointer is managed by the class,
   // which has been set previously when calling SetObjFunction or SetFCN
   // Otherwise if the class is used in the backward compatible mode (e.g. after having fitted a TH1) 
   // the return pointer will be valid after fitting and as long a new fit will not be done. 
   if (fObjFunc) return fObjFunc;
   return fFitter->GetFCN(); 
}

ROOT::Math::Minimizer * TBackCompFitter::GetMinimizer( ) const { 
   // return a pointer to the minimizer.  
   // the return pointer will be valid after fitting and as long a new fit will not be done. 
   // For keeping a minimizer pointer the method ReCreateMinimizer() could eventually be used  
   if (fMinimizer) return fMinimizer;
   return fFitter->GetMinimizer();
}

TFitResult * TBackCompFitter::GetTFitResult( ) const {
   // return a new copy of the TFitResult object which needs to be deleted later by the user
   if (!fFitter.get() ) return 0; 
   return new TFitResult( fFitter->Result() );
}

//________________________________________________________________________________
bool TBackCompFitter::Scan(unsigned int ipar, TGraph * gr, double xmin, double xmax )
{
   //     scan parameter ipar between value of xmin and xmax
   //     a graph must be given which will be on return filled with the scan resul 
   //     If the graph size is zero, a default size n = 40 will be used
   //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


   if (!gr) return false; 
   ROOT::Math::Minimizer * minimizer = fFitter->GetMinimizer(); 
   if (!minimizer) {
      Error("Scan","Minimizer is not available - cannot scan before fitting");
      return false;
   }


   unsigned int npoints = gr->GetN(); 
   if (npoints == 0)  { 
      npoints = 40; 
      gr->Set(npoints);
   }
   bool ret = minimizer->Scan( ipar, npoints, gr->GetX(), gr->GetY(), xmin, xmax); 
   if ((int) npoints < gr->GetN() ) gr->Set(npoints); 
   return ret; 
}
   
// bool  TBackCompFitter::Scan2D(unsigned int ipar, unsigned int jpar, TGraph2D * gr, 
//                       double xmin = 0, double xmax = 0, double ymin = 0, double ymax = 0) { 
//    //     scan the parameters ipar between values of [xmin,xmax] and 
//    //     jpar between values of [ymin,ymax] and 
//    //     a graph2D must be given which will be on return filled with the scan resul 
//    //     If the graph size is zero, a default size n = 20x20 will be used
//    //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

//    if (!gr) return false; 
//    if (!fMinimizer) {
//       Error("Scan","Minimizer is not available - cannot scan before fitting");
//       return false;
//    }
//    unsigned int npoints = gr->GetN(); 
//    if (npoints == 0)  { 
//       npoints = 40; 
//       gr->Set(npoints);
//    }
//    // to be implemented 
//    for (unsigned int ix = 0; ix < npoints; ++ix) {       
//       return fMinimizer->Scan( ipar, npoints, gr->GetX(), gr->GetY(), xmin, xmax); 

// }

bool  TBackCompFitter::Contour(unsigned int ipar, unsigned int jpar, TGraph * gr, double confLevel) { 
   //  create a 2D contour around the minimum for the parameter ipar and jpar
   // if a minimum does not exist or is invalid it will return false
   // on exit a TGraph is filled with the contour points 
   // the number of contur points is determined by the size of the TGraph. 
   // if the size is zero a default number of points = 20 is used 
   // pass optionally the confidence level, default is 0.683
   // it is assumed that ErrorDef() defines the right error definition 
   // (i.e 1 sigma error for one parameter). If not the confidence level are scaled to new level

   if (!gr) return false; 
   ROOT::Math::Minimizer * minimizer = fFitter->GetMinimizer(); 
   if (!minimizer) {
      Error("Scan","Minimizer is not available - cannot scan before fitting");
      return false;
   }

   // get error level used for fitting
   double upScale = fFitter->Config().MinimizerOptions().ErrorDef();

   double upVal = TMath::ChisquareQuantile( confLevel, 2);  // 2 is number of parameter we do the contour
   
   // set required error definition in minimizer
   minimizer->SetErrorDef (upScale * upVal);    

   unsigned int npoints = gr->GetN(); 
   if (npoints == 0)  { 
      npoints = 40; 
      gr->Set(npoints);
   }
   bool ret =  minimizer->Contour( ipar, jpar, npoints, gr->GetX(), gr->GetY()); 
   if ((int) npoints < gr->GetN() ) gr->Set(npoints); 

   // restore the error level used for fitting
   minimizer->SetErrorDef ( upScale);

   return ret; 
}


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