Hydra  4.0.1
A header-only templated C++ framework to perform data analysis on massively parallel platforms.
multidimensional_fit.inl File Reference
#include <iostream>
#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>
#include <algorithm>
#include <future>
#include <tclap/CmdLine.h>
#include <hydra/device/System.h>
#include <hydra/host/System.h>
#include <hydra/Function.h>
#include <hydra/Lambda.h>
#include <hydra/Random.h>
#include <hydra/Algorithm.h>
#include <hydra/Tuple.h>
#include <hydra/Distance.h>
#include <hydra/multiarray.h>
#include <hydra/multivector.h>
#include <hydra/LogLikelihoodFCN.h>
#include <hydra/Parameter.h>
#include <hydra/UserParameters.h>
#include <hydra/Pdf.h>
#include <hydra/AddPdf.h>
#include <hydra/Filter.h>
#include <hydra/Plain.h>
#include <hydra/DenseHistogram.h>
#include <hydra/functions/Gaussian.h>
#include <hydra/RandomFill.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"
Include dependency graph for multidimensional_fit.inl:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MULTIDIMENSIONAL_FIT_INL_
 

Functions

cmd add (EArg)
 
 catch (TCLAP::ArgException &e)
 
 declarg (_X, double) declarg(_Y
 
double declarg (_Z, double) int main(int argv
 
TCLAP::ValueArg< size_t > EArg ("n", "number-of-events", "Number of events", true, 10e6, "size_t")
 
Hist_Data Fill (range.begin(), range.end())
 
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;hydra::DenseHistogram< double, 3, hydra::device::sys_tHist_Data ({100, 100, 100}, {min, min, min}, {max, max, max })
 
cmd parse (argv, argc)
 
GaussianX_Handler wait ()
 

Variables

double char ** argc
 
std::cout<< std::endl<< "Generated data:"<< std::endl;for(size_t i=0;i< 10;i++) std::cout<< "["<< i<< "] :"<< data_d[i]<< std::endl;auto filter=hydra::wrap_lambda([=] __hydra_dual__(_X x, _Y y, _Z z){ bool decision=((x > min) &&(x< max))&&((y > min) &&(y< max))&&((z > min) &&(z< max));return decision;});auto range=hydra::filter(data_d, filter);std::cout<< std::endl<< "Filtered data:"<< std::endl;for(size_t i=0;i< 10;i++) std::cout<< "["<< i<< "] :"<< range.begin()[i]<< std::endl;auto fcn=hydra::make_loglikehood_fcn(model, range);fcn.GetPDF().PrintRegisteredParameters();ROOT::Minuit2::MnPrint::SetGlobalLevel(3);hydra::Print::SetLevel(hydra::WARNING);MnStrategy strategy(2);MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState(), strategy);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
 
auto gaussian
 
auto GaussianX_Handler
 
auto GaussianY_Handler
 
auto GaussianZ_Handler
 
hydra::Plain< 3, hydra::device::sys_tIntegrator ({min, min, min},{ max, max, max }, 50000)
 
double max = 6.0
 
double meanx = 0.0
 
hydra::Parameter meanx_p
 
double meany = 0.0
 
hydra::Parameter meany_p
 
double meanz = 0.0
 
hydra::Parameter meanz_p
 
double min = -6.0
 
auto model = hydra::make_pdf(gaussian, Integrator)
 
 nentries = EArg.getValue()
 
 return
 
double sigmax = 0.5
 
hydra::Parameter sigmax_p
 
double sigmay = 1.5
 
hydra::Parameter sigmay_p
 
double sigmaz = 1.0
 
hydra::Parameter sigmaz_p
 
 try
 

Macro Definition Documentation

◆ MULTIDIMENSIONAL_FIT_INL_

#define MULTIDIMENSIONAL_FIT_INL_

Function Documentation

◆ add()

cmd add ( EArg  )

◆ catch()

catch ( TCLAP::ArgException &  e)

◆ declarg() [1/2]

declarg ( _X  ,
double   
)

◆ declarg() [2/2]

double declarg ( _Z  ,
double   
)

◆ EArg()

TCLAP::ValueArg< size_t > EArg ( "n"  ,
"number-of-events"  ,
"Number of events"  ,
true  ,
10e6  ,
"size_t"   
)

◆ Fill()

Hist_Data Fill ( range.  begin(),
range.  end() 
)

◆ Hist_Data()

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; hydra::DenseHistogram<double, 3, hydra::device::sys_t> Hist_Data ( {100, 100, 100}  ,
{min, min, min ,
{max, max, max  
)

◆ parse()

cmd parse ( argv  ,
argc   
)

◆ wait()

Variable Documentation

◆ argc

double char** argc
Initial value:
{
size_t nentries = 0
nentries
Definition: multidimensional_fit.inl:125
Examples:
multidimensional_fit.inl.

◆ elapsed_d

std::cout<< std::endl<< "Generated data:"<< std::endl; for (size_t i = 0; i < 10; i++) std::cout << "[" << i << "] :" << data_d[i] << std::endl; auto filter = hydra::wrap_lambda( [=] __hydra_dual__ ( _X x, _Y y, _Z z ){ bool decision = ((x > min) && (x < max ))&& ((y > min) && (y < max ))&& ((z > min) && (z < max )); return decision; }); auto range = hydra::filter(data_d, filter); std::cout << std::endl<< "Filtered data:" << std::endl; for (size_t i = 0; i < 10; i++) std::cout << "[" << i << "] :" << range.begin()[i] << std::endl; auto fcn = hydra::make_loglikehood_fcn( model, range); fcn.GetPDF().PrintRegisteredParameters(); ROOT::Minuit2::MnPrint::SetGlobalLevel(3); hydra::Print::SetLevel(hydra::WARNING); MnStrategy strategy(2); MnMigrad migrad_d(fcn, fcn.GetParameters().GetMnState(), strategy); 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

◆ gaussian

auto gaussian
Initial value:
[=] __hydra_dual__ (unsigned int npar, const hydra::Parameter* params, _X x, _Y y, _Z z ){
double g = 1.0;
double mean[3] = {params[0].GetValue(), params[2].GetValue(), params[4].GetValue()};
double sigma[3] = {params[1].GetValue(), params[3].GetValue(), params[5].GetValue()};
double X[3] = {x, y, z};
for(size_t i=0; i<3; i++) {
double m2 = (X[i] - mean[i] )*(X[i] - mean[i] );
double s2 = sigma[i]*sigma[i];
g *= exp(-m2/(2.0 * s2 ))/( sqrt(2.0*s2*PI));
}
return g;
hydra::Parameter meanx_p
Definition: multidimensional_fit.inl:147
hydra::Parameter sigmay_p
Definition: multidimensional_fit.inl:160
hydra::Parameter sigmax_p
Definition: multidimensional_fit.inl:152
hydra::Parameter sigmaz_p
Definition: multidimensional_fit.inl:169
#define __hydra_dual__
Definition: Config.h:104
hydra::Parameter meany_p
Definition: multidimensional_fit.inl:156
hydra::Parameter meanz_p
Definition: multidimensional_fit.inl:165
hydra::Lambda< LambdaType, 0 > wrap_lambda(LambdaType const &lambda)
Definition: Lambda.h:528
double mean
Definition: basic_fit_range_semantics.inl:117
,
Definition: Parameter.h:67
#define PI
Definition: Types.h:75
__hydra_host__ __hydra_device__ GReal_t GetValue() const
Definition: Parameter.h:319
auto exp
Definition: basic_distributions.inl:122
__hydra_host__ __hydra_device__ complex< T > sqrt(const complex< T > &z)
Definition: Complex.h:247
double sigma
Definition: basic_fit_range_semantics.inl:118
Examples:
multidimensional_fit.inl.

◆ GaussianX_Handler

auto GaussianX_Handler
Initial value:
= std::async(std::launch::async,
[&data_d, meanx, sigmax]( ) {
hydra::fill_random(data_d.begin<_X>(), data_d.end<_X>(), hydra::Gaussian<_X>(meanx, sigmax), 159 );
})
double meanx
Definition: multidimensional_fit.inl:136
double sigmax
Definition: multidimensional_fit.inl:137
Gaussian functions are often used to represent the probability density function of a normally dist...
Definition: Gaussian.h:62
std::enable_if< hydra::detail::has_rng_formula< FUNCTOR >::value &&std::is_convertible< decltype(std::declval< RngFormula< FUNCTOR > >).Generate(std::declval< Engine & >), std::declval< FUNCTOR const & >))), typename hydra::thrust::iterator_traits< Iterator >::value_type >::value, void >::type fill_random(hydra::detail::BackendPolicy< BACKEND > const &policy, Iterator begin, Iterator end, FUNCTOR const &functor, size_t seed=0x254a0afcf7da74a2, size_t rng_jump=0)
Fill a range with numbers distributed according a user defined distribution using a RNG analytical fo...
Definition: Random.h:558
Examples:
multidimensional_fit.inl.

◆ GaussianY_Handler

auto GaussianY_Handler
Initial value:
= std::async(std::launch::async,
[&data_d, meany, sigmay]( ) {
hydra::fill_random(data_d.begin<_Y>(), data_d.end<_Y>(), hydra::Gaussian<_Y>(meany, sigmay), 753 );
})
double sigmay
Definition: multidimensional_fit.inl:140
double meany
Definition: multidimensional_fit.inl:139
Gaussian functions are often used to represent the probability density function of a normally dist...
Definition: Gaussian.h:62
std::enable_if< hydra::detail::has_rng_formula< FUNCTOR >::value &&std::is_convertible< decltype(std::declval< RngFormula< FUNCTOR > >).Generate(std::declval< Engine & >), std::declval< FUNCTOR const & >))), typename hydra::thrust::iterator_traits< Iterator >::value_type >::value, void >::type fill_random(hydra::detail::BackendPolicy< BACKEND > const &policy, Iterator begin, Iterator end, FUNCTOR const &functor, size_t seed=0x254a0afcf7da74a2, size_t rng_jump=0)
Fill a range with numbers distributed according a user defined distribution using a RNG analytical fo...
Definition: Random.h:558
Examples:
multidimensional_fit.inl.

◆ GaussianZ_Handler

auto GaussianZ_Handler
Initial value:
= std::async(std::launch::async,
[&data_d, meanz, sigmaz]( ) {
hydra::fill_random(data_d.begin<_Z>(), data_d.end<_Z>(), hydra::Gaussian<_Z>(meanz, sigmaz), 789 );
})
Gaussian functions are often used to represent the probability density function of a normally dist...
Definition: Gaussian.h:62
double meanz
Definition: multidimensional_fit.inl:142
std::enable_if< hydra::detail::has_rng_formula< FUNCTOR >::value &&std::is_convertible< decltype(std::declval< RngFormula< FUNCTOR > >).Generate(std::declval< Engine & >), std::declval< FUNCTOR const & >))), typename hydra::thrust::iterator_traits< Iterator >::value_type >::value, void >::type fill_random(hydra::detail::BackendPolicy< BACKEND > const &policy, Iterator begin, Iterator end, FUNCTOR const &functor, size_t seed=0x254a0afcf7da74a2, size_t rng_jump=0)
Fill a range with numbers distributed according a user defined distribution using a RNG analytical fo...
Definition: Random.h:558
double sigmaz
Definition: multidimensional_fit.inl:143
Examples:
multidimensional_fit.inl.

◆ Integrator

hydra::Plain<3, hydra::device::sys_t> Integrator({min, min, min},{ max, max, max }, 50000)

◆ max

double max = 6.0

◆ meanx

double meanx = 0.0

◆ meanx_p

Initial value:
=
hydra::Parameter::Create().Name("Mean_X").Value(0.0).Error(0.0001).Limits(
-1.0, 1.0)
static __hydra_host__ Parameter Create()
Definition: Parameter.h:369
__hydra_host__ Parameter & Name(std::string const &name)
Definition: Parameter.h:382
__hydra_host__ Parameter & Error(GReal_t error)
Definition: Parameter.h:394
__hydra_host__ Parameter & Limits(GReal_t lowlim, GReal_t uplim)
Definition: Parameter.h:407
__hydra_host__ Parameter & Value(GReal_t value)
Definition: Parameter.h:401
Examples:
multidimensional_fit.inl.

◆ meany

double meany = 0.0

◆ meany_p

Initial value:
=
hydra::Parameter::Create().Name("Mean_Y").Value(0.0).Error(0.0001).Limits(-1.0, 1.0)
static __hydra_host__ Parameter Create()
Definition: Parameter.h:369
__hydra_host__ Parameter & Name(std::string const &name)
Definition: Parameter.h:382
__hydra_host__ Parameter & Error(GReal_t error)
Definition: Parameter.h:394
__hydra_host__ Parameter & Limits(GReal_t lowlim, GReal_t uplim)
Definition: Parameter.h:407
__hydra_host__ Parameter & Value(GReal_t value)
Definition: Parameter.h:401
Examples:
multidimensional_fit.inl.

◆ meanz

double meanz = 0.0

◆ meanz_p

Initial value:
=
hydra::Parameter::Create().Name("Mean_Z").Value(0.0).Error(0.0001).Limits(-1.0, 1.0)
static __hydra_host__ Parameter Create()
Definition: Parameter.h:369
__hydra_host__ Parameter & Name(std::string const &name)
Definition: Parameter.h:382
__hydra_host__ Parameter & Error(GReal_t error)
Definition: Parameter.h:394
__hydra_host__ Parameter & Limits(GReal_t lowlim, GReal_t uplim)
Definition: Parameter.h:407
__hydra_host__ Parameter & Value(GReal_t value)
Definition: Parameter.h:401
Examples:
multidimensional_fit.inl.

◆ min

double min = -6.0

◆ model

◆ nentries

nentries = EArg.getValue()

◆ return

return

◆ sigmax

◆ sigmax_p

hydra::Parameter sigmax_p
Initial value:
=
hydra::Parameter::Create().Name("Sigma_X").Value(2.0).Error(0.0001).Limits(0.1, 3.0)
static __hydra_host__ Parameter Create()
Definition: Parameter.h:369
__hydra_host__ Parameter & Name(std::string const &name)
Definition: Parameter.h:382
__hydra_host__ Parameter & Error(GReal_t error)
Definition: Parameter.h:394
__hydra_host__ Parameter & Limits(GReal_t lowlim, GReal_t uplim)
Definition: Parameter.h:407
__hydra_host__ Parameter & Value(GReal_t value)
Definition: Parameter.h:401
Examples:
multidimensional_fit.inl.

◆ sigmay

◆ sigmay_p

hydra::Parameter sigmay_p
Initial value:
=
hydra::Parameter::Create().Name("Sigma_Y").Value(2.0).Error(0.01).Limits(0.1, 3.0)
static __hydra_host__ Parameter Create()
Definition: Parameter.h:369
__hydra_host__ Parameter & Name(std::string const &name)
Definition: Parameter.h:382
__hydra_host__ Parameter & Error(GReal_t error)
Definition: Parameter.h:394
__hydra_host__ Parameter & Limits(GReal_t lowlim, GReal_t uplim)
Definition: Parameter.h:407
__hydra_host__ Parameter & Value(GReal_t value)
Definition: Parameter.h:401
Examples:
multidimensional_fit.inl.

◆ sigmaz

◆ sigmaz_p

hydra::Parameter sigmaz_p
Initial value:
=
hydra::Parameter::Create().Name("Sigma_Z").Value(2.0).Error(0.0001).Limits(0.1, 3.0)
static __hydra_host__ Parameter Create()
Definition: Parameter.h:369
__hydra_host__ Parameter & Name(std::string const &name)
Definition: Parameter.h:382
__hydra_host__ Parameter & Error(GReal_t error)
Definition: Parameter.h:394
__hydra_host__ Parameter & Limits(GReal_t lowlim, GReal_t uplim)
Definition: Parameter.h:407
__hydra_host__ Parameter & Value(GReal_t value)
Definition: Parameter.h:401
Examples:
multidimensional_fit.inl.

◆ try

try
Initial value:
{
TCLAP::CmdLine cmd("Command line arguments for ", '=')