#include <iostream>
#include <assert.h>
#include <time.h>
#include <chrono>
#ifndef HYDRA_HOST_SYSTEM
#define HYDRA_HOST_SYSTEM CPP
#endif
#ifndef HYDRA_DEVICE_SYSTEM
#define HYDRA_DEVICE_SYSTEM TBB
#endif
#include "Minuit2/FunctionMinimum.h"
#include "Minuit2/MnUserParameterState.h"
#include "Minuit2/MnPrint.h"
#include "Minuit2/MnMigrad.h"
#include "Minuit2/MnMinimize.h"
#include <TROOT.h>
#include <TH1D.h>
#include <TApplication.h>
#include <TCanvas.h>
void fit_gaussian(
size_t nentries=1000000 )
{
TH1D* hist_xvar =
new TH1D(
"hist_xvar",
"X-axis", 100,
min,
max);
TH1D* hist_fit_xvar =
new TH1D(
"hist_fit_xvar",
"X-axis", 100,
min,
max);
{
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;
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() );
}
TCanvas* canvas = new TCanvas("canvas_d" ,"Distributions - Device", 500, 500);
hist_xvar->Draw("hist");
hist_fit_xvar->Draw("histsameC");
hist_fit_xvar->SetLineColor(2);
}