This example shows how to perform S-plots using Hydra.A 2-dimensional dataset is generated. The first column is distributed as a Gaussian signal on top of an Exponential background. The signal distribution is associated to an exponentialy distributed control variable in the second colunm andd the background to the sum of two Gaussians.
#ifndef SPLOT_INL_
#define SPLOT_INL_
#include <iostream>
#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>
#include <tclap/CmdLine.h>
#include "Minuit2/FunctionMinimum.h"
#include "Minuit2/MnUserParameterState.h"
#include "Minuit2/MnPrint.h"
#include "Minuit2/MnMigrad.h"
#include "Minuit2/MnMinimize.h"
#include "Minuit2/MnMinos.h"
#include "Minuit2/MnContours.h"
#include "Minuit2/CombinedMinimizer.h"
#include "Minuit2/MnPlot.h"
#include "Minuit2/MinosError.h"
#include "Minuit2/ContoursError.h"
#include "Minuit2/VariableMetricMinimizer.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;
}
std::array<hydra::Parameter, 2> yields{ N_Gauss_p,
N_Exp_p };
#ifdef _ROOT_AVAILABLE_
TH1D hist_data_dicriminating_d(
"data_discriminating_d",
"Discriminating variable", 100,
min,
max);
TH1D hist_data_control_d(
"data_control_d",
"Control Variable", 100,
min,
max);
TH1D hist_fit_d(
"fit_d",
"Discriminating variable", 100,
min,
max);
TH1D hist_control_1_d(
"control_1_d",
"Control Variable: Gaussian PDF", 100,
min,
max);
TH1D hist_control_2_d(
"control_2_d",
"Control Variable: Exponential PDF", 100,
min,
max);
#endif //_ROOT_AVAILABLE_
{
exponential.SetParameter("Tau", 3.0);
exponential.SetParameter("Tau", exponential.Parameter("Tau").Value(5.0) );
std::cout<< std::endl<< "Generated data:"<< std::endl;
for(size_t i=0; i<10; i++)
std::cout << "[" << i << "] :"
<< data_d[i] << std::endl;
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(data_h.begin(), data_h.end(), g);
std::cout<< std::endl<< "Suffled data:"<< std::endl;
for(size_t i=0; i<10; i++)
std::cout << "[" << i << "] :" << data_d[i] << std::endl;
return (x >
min) && (x <
max );
};
std::cout<< std::endl<< "Filtered data:"<< std::endl;
for(size_t i=0; i<10; i++)
std::cout <<
"[" << i <<
"] :" <<
range.begin()[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;
auto covar_matrix = sweigts.GetCovMatrix();
std::cout << "Covariance matrix "
<< std::endl
<< covar_matrix
<< std::endl
<< std::endl;
std::cout << std::endl
<< "sWeights:"
<< std::endl;
for(size_t i = 0; i<10; i++)
std::cout << "[" << i << "] :"
<< sweigts[i]
<< std::endl
<< std::endl;
size_t nbins = 100;
start_d = std::chrono::high_resolution_clock::now();
Hist_Data.Fill(data2_d.begin(0), data2_d.end(0));
end_d = std::chrono::high_resolution_clock::now();
std::cout << "-------------------------------------------"<<std::endl;
std::cout <<
"| [Histograming data] GPU Time (ms) = " <<
elapsed_d.count() <<std::endl;
std::cout << "-------------------------------------------"<<std::endl;
start_d = std::chrono::high_resolution_clock::now();
Hist_Control.Fill(data2_d.begin(1), data2_d.end(1));
end_d = std::chrono::high_resolution_clock::now();
std::cout << "-----------------------------------------"<<std::endl;
std::cout <<
"| [Histograming control] GPU Time (ms) ="<<
elapsed_d.count() <<std::endl;
std::cout << "-----------------------------------------"<<std::endl;
start_d = std::chrono::high_resolution_clock::now();
Hist_Control_1.Fill(data2_d.begin(1), data2_d.end(1), sweigts.begin(
_0) );
end_d = std::chrono::high_resolution_clock::now();
std::cout << "-----------------------------------------"<<std::endl;
std::cout <<
"| [Histograming control 1] GPU Time (ms) ="<<
elapsed_d.count() <<std::endl;
std::cout << "-----------------------------------------"<<std::endl;
start_d = std::chrono::high_resolution_clock::now();
Hist_Control_2.Fill(data2_d.begin(1), data2_d.end(1), sweigts.begin(
_1) );
end_d = std::chrono::high_resolution_clock::now();
std::cout << "-----------------------------------------"<<std::endl;
std::cout <<
"| [Histograming control 2] GPU Time (ms) ="<<
elapsed_d.count() <<std::endl;
std::cout << "-----------------------------------------"<<std::endl;
#ifdef _ROOT_AVAILABLE_
for(size_t bin=0; bin < nbins; bin++){
hist_data_dicriminating_d.SetBinContent(bin+1,
Hist_Data[bin] );
hist_data_control_d.SetBinContent(bin+1, Hist_Control[bin] );
hist_control_1_d.SetBinContent(bin+1, Hist_Control_1[bin] );
hist_control_2_d.SetBinContent(bin+1, Hist_Control_2[bin] );
}
for (size_t i=1 ; i<=100 ; i++) {
double x = hist_fit_d.GetBinCenter(i);
hist_fit_d.SetBinContent(i,
fcn.GetPDF()(x) );
}
hist_fit_d.Scale(hist_data_dicriminating_d.Integral()/hist_fit_d.Integral() );
#endif //_ROOT_AVAILABLE_
}
#ifdef _ROOT_AVAILABLE_
TApplication *myapp=new TApplication("myapp",0,0);
TCanvas canvas_1_d("canvas_1_d" ,"Distributions - Device", 500, 500);
hist_data_dicriminating_d.Draw("hist");
hist_fit_d.Draw("histsameC");
hist_fit_d.SetLineColor(2);
TCanvas canvas_3_d("canvas_3_d" ,"Distributions - Device", 500, 500);
hist_data_control_d.Draw("hist");
hist_data_control_d.SetLineColor(2);
TCanvas canvas_2_d("canvas_2_d" ,"Distributions - Device", 1000, 500);
canvas_2_d.Divide(2,1);
canvas_2_d.cd(1);
hist_control_1_d.Draw("hist");
canvas_2_d.cd(2);
hist_control_2_d.Draw("hist");
myapp->Run();
#endif //_ROOT_AVAILABLE_
return 0;
}
#endif