#ifndef DOUBLE_GAUSSIAN_PLUS_EXPONENTIAL_INL_
#define DOUBLE_GAUSSIAN_PLUS_EXPONENTIAL_INL_
#include <iostream>
#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>
#include <algorithm>
#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;
}
char const*
model_name =
"Gaussian (core) + Gaussian (tail) + Exponential";
#ifdef _ROOT_AVAILABLE_
#endif //_ROOT_AVAILABLE_
{
std::cout<< std::endl<< "Generated data:"<< std::endl;
for(size_t i=0; i< 10; i++)
std::cout <<
"[" << i <<
"] :" <<
range[i] << std::endl;
ROOT::Minuit2::MnPrint::SetGlobalLevel(3);
std::cout<<
fcn.GetParameters().GetMnState()<<std::endl;
auto start_d = std::chrono::high_resolution_clock::now();
FunctionMinimum minimum_d = FunctionMinimum(
migrad_d(5000, 5));
auto end_d = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli>
elapsed_d = end_d - start_d;
std::cout<< "Minimum: " << minimum_d << std::endl;
std::cout << "-----------------------------------------"<<std::endl;
std::cout <<
"| [Fit] GPU Time (ms) ="<<
elapsed_d.count() <<std::endl;
std::cout << "-----------------------------------------"<<std::endl;
#ifdef _ROOT_AVAILABLE_
for(size_t i=0; i<2000; i++)
hist_data.SetBinContent(i+1,
Hist_Data.GetBinContent(i));
for (size_t i=0 ; i<=100 ; i++) {
double x = hist_fit.GetBinCenter(i);
hist_fit.SetBinContent(i,
fcn.GetPDF()(x) );
}
hist_fit.Scale(hist_data.Integral()/hist_fit.Integral() );
double signal_fraction =
fcn.GetPDF().Coefficient(0)/
fcn.GetPDF().GetCoefSum();
auto core =
fcn.GetPDF().PDF(
_0).PDF(
_0);
double core_fraction = signal_fraction*
fcn.GetPDF().PDF(
_0).Coefficient(0);
for (size_t i=0 ; i<=100 ; i++) {
double x = hist_core.GetBinCenter(i);
hist_core.SetBinContent(i, core(x) );
}
hist_core.Scale(hist_data.Integral()*core_fraction/hist_core.Integral());
auto tail =
fcn.GetPDF().PDF(
_0).PDF(
_1);
double tail_fraction = signal_fraction*
fcn.GetPDF().PDF(
_0).Coefficient(1);
for (size_t i=0 ; i<=100 ; i++) {
double x = hist_tail.GetBinCenter(i);
hist_tail.SetBinContent(i, tail(x) );
}
hist_tail.Scale(hist_data.Integral()*tail_fraction/hist_tail.Integral());
auto background =
fcn.GetPDF().PDF(
_1);
double background_fraction =
fcn.GetPDF().Coefficient(1)/
fcn.GetPDF().GetCoefSum();
for (size_t i=0 ; i<=100 ; i++) {
double x = hist_background.GetBinCenter(i);
hist_background.SetBinContent(i, background(x) );
}
hist_background.Scale(hist_data.Integral()*background_fraction/hist_background.Integral());
#endif //_ROOT_AVAILABLE_
}
#ifdef _ROOT_AVAILABLE_
TApplication *myapp=new TApplication("myapp",0,0);
TCanvas canvas_d("canvas_d" ,"Distributions - Device", 500, 500);
hist_data.Draw("e0");
hist_data.SetStats(0);
hist_data.SetLineColor(1);
hist_data.SetLineWidth(2);
hist_fit.Draw("histsameC");
hist_fit.SetStats(0);
hist_fit.SetLineColor(4);
hist_core.Draw("histsameC");
hist_core.SetStats(0);
hist_core.SetLineColor(8);
hist_core.SetFillColor(8);
hist_core.SetFillStyle(1001);
hist_tail.Draw("histsameC");
hist_tail.SetStats(0);
hist_tail.SetLineColor(15);
hist_tail.SetFillColor(15);
hist_tail.SetFillStyle(3004);
hist_background.Draw("histsameC");
hist_background.SetStats(0);
hist_background.SetLineColor(2);
hist_background.SetFillColor(2);
hist_background.SetFillStyle(3003);
hist_background.SetLineStyle(2);
hist_fit.Draw("histsameC");
hist_data.Draw("e0same");
myapp->Run();
#endif //_ROOT_AVAILABLE_
return 0;
}
#endif