#ifndef FIT_CONVOLUTED_PDFS_INL_
#define FIT_CONVOLUTED_PDFS_INL_
#include <iostream>
#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>
#include <algorithm>
#include <tclap/CmdLine.h>
#if HYDRA_DEVICE_SYSTEM == CUDA
#endif
#if HYDRA_DEVICE_SYSTEM != CUDA
#endif
#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;
}
unsigned nbins = 100;
#if HYDRA_DEVICE_SYSTEM==CUDA
#endif
#if HYDRA_DEVICE_SYSTEM!=CUDA
#endif
auto convolution_signal = hydra::make_convolution<xvar>(
hydra::device::sys, fft_backend, bw_signal, gaussian_kernel,
min,
max,10112);
#ifdef _ROOT_AVAILABLE_
TH1D hist_data(
"data" ,
"", nbins,
min,
max);
TH1D hist_raw_signal("raw_signal" , "", nbins, 4.0, 6.0);
TH1D hist_signal(
"signal" ,
"", nbins,
min,
max);
TH1D hist_background(
"background",
"", nbins,
min,
max);
TH1D hist_total(
"total" ,
"", nbins,
min,
max);
#endif //_ROOT_AVAILABLE_
{
std::cout<< std::endl<< "Generated data...: "<< std::endl;
for(size_t i=0; i<10; i++)
std::cout <<
"[" << i <<
"] :" <<
data[i] << std::endl;
ROOT::Minuit2::MnPrint::SetGlobalLevel(3);
std::cout<<
fcn.GetParameters().GetMnState()<<std::endl;
auto start_d = std::chrono::high_resolution_clock::now();
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<nbins; i++)
hist_data.SetBinContent(i+1,
Hist_Data.GetBinContent(i));
hist_data.Sumw2();
for (size_t i=0 ; i<=nbins ; i++) {
hist_total.SetBinContent( i,
fcn.GetPDF()(hist_total.GetBinCenter(i) ) );
hist_raw_signal.SetBinContent( i,
fcn.GetPDF().PDF(
_0).GetFunctor().GetFunctor(
_0)(hist_raw_signal.GetBinCenter(i) ) );
hist_signal.SetBinContent( i,
fcn.GetPDF().PDF(
_0)(hist_signal.GetBinCenter(i) ) );
hist_background.SetBinContent( i,
fcn.GetPDF().PDF(
_1)(hist_background.GetBinCenter(i) ) );
}
double signal_fraction =
fcn.GetPDF().Coefficient(0)/
fcn.GetPDF().GetCoefSum();
hist_signal.Scale(hist_data.Integral()*signal_fraction/hist_signal.Integral() );
double background_fraction =
fcn.GetPDF().Coefficient(1)/
fcn.GetPDF().GetCoefSum();
hist_background.Scale(hist_data.Integral()*background_fraction/hist_background.Integral() );
hist_total.Scale(hist_data.Integral()/hist_total.Integral() );
#endif //_ROOT_AVAILABLE_
}
#ifdef _ROOT_AVAILABLE_
TApplication *myapp=new TApplication("myapp",0,0);
TCanvas canvas("canvas_d" ,"Distributions - Device", 1000, 500);
canvas.Divide(2,1);
canvas.cd(1);
hist_data.Draw("E0");
hist_data.SetMinimum(0);
hist_data.SetLineWidth(2);
hist_data.SetLineColor(1);
hist_data.SetStats(0);
hist_total.Draw("histsameC");
hist_total.SetLineColor(4);
hist_total.SetLineWidth(2);
hist_total.SetStats(0);
hist_signal.Draw("histsameC");
hist_signal.SetLineColor(8);
hist_signal.SetLineWidth(2);
hist_signal.SetStats(0);
hist_background.Draw("histsameC");
hist_background.SetLineColor(2);
hist_background.SetLineWidth(2);
hist_background.SetLineStyle(2);
hist_background.SetStats(0);
canvas.cd(2);
auto h=hist_raw_signal.DrawNormalized("histC");
h->SetLineColor(6);
h->SetLineWidth(2);
h->SetStats(0);
myapp->Run();
#endif //_ROOT_AVAILABLE_
convolution_signal.Dispose();
return 0;
}
#endif