/********************************************************************** * * * Copyright (c) 2003 INFN - Sezione di Napoli * * * * For more information (including a list of authors) see * * the README file * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this library (see file COPYING); if not, write to the * * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * * Boston, MA 02111-1307 USA, or contact the authors. * * * **********************************************************************/ #include "StatTools/Fit/Ext/Defaults.h" #include "StatTools/Pdf/Ext/Defaults.h" #include "StatTools/Funct/Parameter.h" #include "StatTools/Funct/Expression.h" #include "StatTools/Funct/Gaussian.h" #include "StatTools/Fit/Likelihood.h" #include "StatTools/Fit/UMLParameterFitter.h" #include "StatTools/Pdf/Pdf.h" #include "StatTools/ToyMC/Experiment.h" #include #include using namespace std; using namespace Funct; using namespace Fit; using namespace ToyMC; int main() { Parameter fit_theta( 1 ); Expression mean( fit_theta ); Expression sigma ( sqrt( num<1>() + sqr( fit_theta ) ) ); typedef Gaussian< X, Expression, Expression > Model; Model gaussian( mean, sigma ); cout << " model: " << gaussian << endl; typedef Pdf::PdfNoNormalization< X, Model > ModelPdf; ModelPdf pdf( gaussian ); Likelihood< ModelPdf > like( pdf ); UMLParameterFitter< Likelihood< ModelPdf > > fitter( like ); fitter.addParameter( "par", fit_theta.ptr() ); double par[ 1 ] = { fit_theta }; double err[ 1 ] = { 1 }; double logLike; Sample< ModelPdf::types > sample; Sample< ModelPdf::types >::tuple n; sample.push_back( boost::tuples::make_tuple( 0.1 ) ); sample.push_back( boost::tuples::make_tuple( 0.2 ) ); sample.push_back( boost::tuples::make_tuple( 0.3 ) ); sample.push_back( boost::tuples::make_tuple( 0.4 ) ); logLike = fitter.fit( par, err, sample ); cout << "parameter fitted : " << par[0] << " +/- " << err[0] << endl; fit_theta = par[ 0 ]; double m = mean(), s = sigma(); fit_theta = par[ 0 ] + err[ 0 ]; double dmp = fabs( mean() - m ), dsp = fabs( sigma() - s ); fit_theta = par[ 0 ] - err[ 0 ]; double dmm = fabs( mean() - m ), dsm = fabs( sigma() - s ); cout << " fitted mean : " << par[ 0 ] << " + " << dmp << " - " << dmm << endl; cout << " fitted sigma : " << par[ 1 ] << " + " << dsp << " - " << dsm << endl; return 0; }