MCParameters.cxx

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: MCParameters.cxx 36806 2010-11-20 11:09:14Z moneta $
00002 // Author: Lorenzo Moneta  11/2010
00003 
00004  /**********************************************************************
00005   *                                                                    *
00006   * Copyright (c) 2007 ROOT Foundation,  CERN/PH-SFT                   *
00007   *                                                                    *
00008   * This library is free software; you can redistribute it and/or      *
00009   * modify it under the terms of the GNU General Public License        *
00010   * as published by the Free Software Foundation; either version 2     *
00011   * of the License, or (at your option) any later version.             *
00012   *                                                                    *
00013   * This library is distributed in the hope that it will be useful,    *
00014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00016   * General Public License for more details.                           *
00017   *                                                                    *
00018   * You should have received a copy of the GNU General Public License  *
00019   * along with this library (see file COPYING); if not, write          *
00020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
00021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
00022   *                                                                    *
00023   **********************************************************************/
00024 //
00025 // implementation file for class MCParameters
00026 // Author: Lorenzo Moneta , Nov 2010
00027 // 
00028 //
00029 
00030 #include "Math/MCParameters.h"
00031 #include "Math/GenAlgoOptions.h"
00032 
00033 #include "gsl/gsl_monte_vegas.h"
00034 
00035 namespace ROOT {
00036 namespace Math {
00037 
00038 
00039    /// default VEGAS parameters (copied from gsl/monte/vegas.c) 
00040    void VegasParameters::SetDefaultValues() {
00041       // init default values
00042       alpha        =  1.5;
00043       iterations   = 5;
00044       stage        = 0; 
00045       mode         = GSL_VEGAS_MODE_IMPORTANCE;
00046       verbose      = -1;
00047    }
00048 
00049    VegasParameters::VegasParameters(const IOptions & opt) { 
00050       SetDefaultValues();
00051       (*this) = opt;
00052    }
00053 
00054    VegasParameters & VegasParameters::operator= (const IOptions & opt) { 
00055       // set parameters from IOptions
00056       double val = 0; 
00057       int ival = 0; 
00058       bool ret = false; 
00059 
00060       ret = opt.GetRealValue("alpha",val); 
00061       if (ret) alpha = val; 
00062       ret = opt.GetIntValue("iterations",ival);
00063       if (ret) iterations = ival; 
00064       ret = opt.GetIntValue("stage",ival);
00065       if (ret) stage = ival; 
00066       ret = opt.GetIntValue("mode",ival);
00067       if (ret) mode = ival; 
00068       ret = opt.GetIntValue("verbose",ival);
00069       if (ret) verbose = ival; 
00070       return *this;
00071    }
00072 
00073    IOptions * VegasParameters::operator() () const { 
00074       // convert to options (return object is managed by the user) 
00075       GenAlgoOptions * opt = new GenAlgoOptions(); 
00076       opt->SetRealValue("alpha",alpha);
00077       opt->SetIntValue("iterations",iterations);
00078       opt->SetIntValue("stage",stage);
00079       opt->SetIntValue("mode",mode);
00080       opt->SetIntValue("verbose",verbose);
00081       return opt;
00082    }
00083 
00084 
00085 
00086    /// default MISER parameters (copied from gsl/monte/vegas.c) 
00087 
00088 
00089    void MiserParameters::SetDefaultValues(size_t dim) {
00090       // init default values
00091       estimate_frac           = 0.1;
00092       min_calls               = (dim>0) ? 16*dim : 160; // use default dim = 10
00093       min_calls_per_bisection = 32*min_calls;
00094       dither                  = 0;
00095       alpha                   = 2.0;
00096    }
00097 
00098 
00099    MiserParameters::MiserParameters(const IOptions & opt, size_t dim) { 
00100       SetDefaultValues(dim);
00101       (*this) = opt;
00102    }
00103 
00104    MiserParameters & MiserParameters::operator= (const IOptions & opt) { 
00105       // set parameters from IOptions
00106       double val = 0; 
00107       int ival = 0; 
00108       bool ret = false; 
00109 
00110       ret = opt.GetRealValue("alpha",val); 
00111       if (ret) alpha = val; 
00112       ret = opt.GetRealValue("dither",val); 
00113       if (ret) dither = val; 
00114       ret = opt.GetRealValue("estimate_frac",val); 
00115       if (ret) estimate_frac = val; 
00116       ret = opt.GetIntValue("min_calls",ival); 
00117       if (ret) min_calls = ival; 
00118       ret = opt.GetIntValue("min_calls_per_bisection",ival); 
00119       if (ret) min_calls_per_bisection = ival; 
00120       return *this;
00121    }
00122 
00123    IOptions * MiserParameters::operator() () const { 
00124       // convert to options (return object is managed by the user) 
00125       GenAlgoOptions * opt = new GenAlgoOptions(); 
00126       opt->SetRealValue("alpha",alpha);
00127       opt->SetRealValue("dither",dither);
00128       opt->SetRealValue("estimate_frac",estimate_frac);
00129       opt->SetIntValue("min_calls",min_calls);
00130       opt->SetIntValue("min_calls_per_bisection",min_calls_per_bisection);
00131       return opt;
00132    }
00133 
00134 
00135 } // namespace Math
00136 } // namespace ROOT
00137 
00138 
00139 

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