TFcnAdapter.cxx

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: TFcnAdapter.cxx 20880 2007-11-19 11:23:41Z rdm $
00002 // Author: L. Moneta    10/2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 ROOT Foundation,  CERN/PH-SFT                   *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 #include "TFcnAdapter.h"
00011 
00012 #include <cassert>
00013 //#include <iostream>
00014 
00015 double TFcnAdapter::operator()(const std::vector<double>& par) const {
00016    // adapt ROOT FCN interface to be called by Minuit2 (to have a FCNBase signature)
00017    //   assert(par.size() == theNPar);
00018    //   std::cout<<"TFcnAdapter::operator()"<<std::endl;
00019    assert(fFCN != 0);
00020    double fs = 0.;
00021    //   double* theCache = new double[par.size()];
00022    //   copy(par.begin(), par.end(), theCache);
00023    
00024    double* theCache = (double*)(&(par.front()));
00025    
00026    int npar = par.size();
00027    (*fFCN)(npar, 0, fs, theCache, 4);
00028    //   delete [] theCache;
00029    
00030    return fs;
00031 }
00032 
00033 std::vector<double> TFcnAdapter::Gradient(const std::vector<double>& par) const {
00034    // adapt ROOT FCN interface (for gradient) to be called by Minuit2 (to have a FCNBase signature)   
00035 
00036    //     std::cout<<"TFcnAdapter::gradient "<<std::endl;
00037    //   assert(par.size() == theNPar);
00038    assert(fFCN != 0);
00039    double fs = 0.;
00040    int npar = par.size();
00041 
00042    double* theCache = (double*)(&(par.front()));
00043    if (fGradCache.size() != par.size() ) 
00044       fGradCache = std::vector<double>(par.size() );
00045 
00046    for(int i = 0; i < npar; i++) theCache[i] = par[i];
00047    //   (*theFcn)(npar, theGradCache, fs, theCache, 2);
00048    (*fFCN)(npar, &fGradCache[0], fs, theCache, 4);
00049    return fGradCache;
00050 }
00051 
00052 
00053 double TFcnAdapter::operator()(int npar, double* params,int iflag) const {
00054    // interface using double * instead of std::vector 
00055    
00056    //   std::cout<<"TFcnAdapter::operator()(int npar,"<<std::endl;
00057    //   assert(npar == int(theNPar));
00058    assert(fFCN != 0);
00059    double fs = 0.;
00060    (*fFCN)(npar, 0, fs, params, iflag);
00061    return fs;
00062 }
00063 

Generated on Tue Jul 5 14:37:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1