#include #include #include #include "AIDA_Proxy/AIDA_Proxy.h" // Class declarations from CLHEP #include "CLHEP/Random/RandGauss.h" #include "CLHEP/Random/DRand48Engine.h" #include int main( int, char** ) { // Creating a histogram pi_aida::Histogram1D h1("Gaussian Distribution", 100, 0, 100); // Filling the histogram with random data following a gaussian distribution DRand48Engine randomEngine; RandGauss rgauss( randomEngine, 45, 10 ); for ( int i = 0; i < 10000; ++i ) { h1.fill( rgauss.fire() ); } std::cout << "Histogram :" << std::endl; std::cout << " Title : " << h1.title() << std::endl; std::cout << " Entries : " << h1.entries() << std::endl; std::cout << " Mean : " << h1.mean() << std::endl; std::cout << " Rms : " << h1.rms() << std::endl; // Creating the function which is going to be fitted with the histogram data pi_aida::Function gaussFun("G"); // set function initial parameters gaussFun.setParameter("mean" , 50.); gaussFun.setParameter("sigma", 10.); gaussFun.setParameter("amp" , 50.); // Creating the fitter using lcg_minit pi_aida::Fitter fitter("Chi2","lcg_minuit"); // Creating the fitter using old fortran minit //pi_aida::Fitter fitter("Chi2","minuit"); // Performing the fit AIDA::IFitResult* fitResult = fitter.fit( h1, gaussFun ); // check fit if (fitResult) { // Printing the fit results std::cout << "Fit result : chi2 / ndf : " << fitResult->quality() << " / " << fitResult->ndf() << std::endl; const std::vector& parNames = fitResult->fittedParameterNames(); const std::vector& par = fitResult->fittedParameters(); const std::vector& epar = fitResult->errors(); for ( unsigned int i = 0; i < par.size(); ++i ) { std::cout << parNames[i] << " = " << par[i] << " +/- " << epar[i] << std::endl; } // Add in the annotation of the histogram the fit result AIDA::IAnnotation& annotation = h1.annotation(); for ( unsigned int i = 0; i < par.size(); ++i ) { std::ostringstream os; os << par[i] << " +/- " << epar[i]; annotation.addItem( parNames[i], os.str() ); } // Remove some existing annotation items annotation.removeItem( "Overflow" ); annotation.removeItem( "Underflow" ); annotation.removeItem( "Extra Entries" ); } else { std::cout << "\n>>>Error: Fit failed ! " << std::endl; return 1; } return 0; }