#ifndef BASIC_FIT_INL_
#define BASIC_FIT_INL_
#include <iostream>
#include <assert.h>
#include <time.h>
#include <chrono>
#include <tclap/CmdLine.h>
#include "Minuit2/FunctionMinimum.h"
#include "Minuit2/MnUserParameterState.h"
#include "Minuit2/MnPrint.h"
#include "Minuit2/MnMigrad.h"
#include "Minuit2/MnMinimize.h"
#ifdef _ROOT_AVAILABLE_
#include <TROOT.h>
#include <TH1D.h>
#include <TApplication.h>
#include <TCanvas.h>
#endif //_ROOT_AVAILABLE_
{
try {
TCLAP::CmdLine cmd("Command line arguments for ", '=');
TCLAP::ValueArg<size_t>
EArg(
"n",
"number-of-events",
"Number of events",
true, 10e6,
"size_t");
}
catch (TCLAP::ArgException &e) {
std::cerr << " error: " << e.error()
<< " for arg " << e.argId()
<< std::endl;
}
#ifdef _ROOT_AVAILABLE_
TH1D hist_xvar(
"hist_xvar",
"X-axis", 100,
min,
max);
TH1D hist_fit_xvar(
"hist_fit_xvar",
"X-axis", 100,
min,
max);
#endif //_ROOT_AVAILABLE_
{
std::cout<< std::endl<< "Generated data:"<< std::endl;
for(size_t i=0; i<10; i++)
std::cout << "[" << i << "] :" << dataset[i] << std::endl;
ROOT::Minuit2::MnPrint::SetGlobalLevel(3);
MnMigrad xmigrad(xfcn, xfcn.GetParameters().GetMnState() ,
strategy);
std::cout << xfcn.GetParameters().GetMnState() << std::endl;
auto start = std::chrono::high_resolution_clock::now();
auto stop = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli>
elapsed = stop -
start;
std::cout << " minimum: " << xminimum << std::endl;
std::cout << "-----------------------------------------"<<std::endl;
std::cout <<
"| Time (ms) ="<<
elapsed.count() <<std::endl;
std::cout << "-----------------------------------------"<<std::endl;
#ifdef _ROOT_AVAILABLE_
for(size_t i=0; i<100; i++){
hist_xvar.SetBinContent(i+1,
Hist_Data.GetBinContent(i) );
}
hist_fit_xvar.Sumw2();
for (size_t i=0 ; i<=100 ; i++) {
double x = hist_fit_xvar.GetBinCenter(i);
hist_fit_xvar.SetBinContent(i, xfcn.GetPDF()(x) );
}
hist_fit_xvar.Scale(hist_xvar.Integral()/hist_fit_xvar.Integral() );
#endif //_ROOT_AVAILABLE_
}
#ifdef _ROOT_AVAILABLE_
TApplication *myapp=new TApplication("myapp",0,0);
TCanvas canvas("canvas_d" ,"Distributions - Device", 500, 500);
hist_xvar.Draw("hist");
hist_fit_xvar.Draw("histsameC");
hist_fit_xvar.SetLineColor(2);
myapp->Run();
#endif //_ROOT_AVAILABLE_
return 0;
}
#endif