A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://multithreadcorner.github.io/Hydra/basic_fit_range_semantics_8inl-example.html below:

Hydra: basic_fit_range_semantics.inl

This example shows how to generate a normal distributed dataset and fit a hydra::Gaussian distribution using hydra's range semantics.

#ifndef BASIC_FIT_RANGE_SEMANTICS_INL_

#define BASIC_FIT_RANGE_SEMANTICS_INL_

#include <iostream>

#include <assert.h>

#include <time.h>

#include <chrono>

#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;

}

#ifdef _ROOT_AVAILABLE_

TH1D hist_gaussian_d(

"gaussian_d"

,

"Gaussian"

, 100,

min

,

max

);

TH1D hist_fitted_gaussian_d(

"fitted_gaussian_d"

,

"Gaussian"

, 100,

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;

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

[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 <<

"| GPU Time (ms) ="

<<

elapsed_d

.count() <<std::endl;

std::cout << "-----------------------------------------"<<std::endl;

#ifdef _ROOT_AVAILABLE_

for(size_t i=0; i<100; i++){

hist_gaussian_d.SetBinContent(i+1,

Hist_Data

.GetBinContent(i) );

}

hist_fitted_gaussian_d.Sumw2();

for (size_t i=0 ; i<=100 ; i++) {

double x = hist_fitted_gaussian_d.GetBinCenter(i);

hist_fitted_gaussian_d.SetBinContent(i,

fcn

.GetPDF()(x) );

}

hist_fitted_gaussian_d.Scale(hist_gaussian_d.Integral()/hist_fitted_gaussian_d.Integral() );

#endif //_ROOT_AVAILABLE_

}

#ifdef _ROOT_AVAILABLE_

TApplication *myapp=new TApplication("myapp",0,0);

TCanvas canvas_d("canvas_d" ,"Distributions - Device", 500, 500);

hist_gaussian_d.Draw("hist");

hist_fitted_gaussian_d.Draw("histsameC");

hist_fitted_gaussian_d.SetLineColor(2);

myapp->Run();

#endif //_ROOT_AVAILABLE_

return 0;

}

#endif


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4