#ifndef CRYSTAL_BALL_PLUS_EXPONENTIAL_INL_
#define CRYSTAL_BALL_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 =
"Crystal Ball + 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<100; 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() );
auto signal =
fcn.GetPDF().PDF(
_0);
double signal_fraction =
fcn.GetPDF().Coefficient(0)/
fcn.GetPDF().GetCoefSum();
for (size_t i=0 ; i<=100 ; i++) {
double x = hist_signal.GetBinCenter(i);
hist_signal.SetBinContent(i, signal(x) );
}
hist_signal.Scale(hist_data.Integral()*signal_fraction/hist_signal.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_signal.Draw("histsameC");
hist_signal.SetStats(0);
hist_signal.SetLineColor(3);
hist_background.Draw("histsameC");
hist_background.SetStats(0);
hist_background.SetLineColor(2);
hist_background.SetLineStyle(2);
hist_fit.Draw("histsameC");
hist_data.Draw("e0same");
myapp->Run();
#endif //_ROOT_AVAILABLE_
return 0;
}
#endif