#include <cmath>
bool debug = false;
struct GausND {
GausND( int dim ) :
{}
int k = 0;
for (
int i = 0; i<dim; ++i) { X[i] =
x[i] - p[k]; k++; }
for (int i = 0; i<dim; ++i) {
CovMat(i,i) = p[k]*p[k];
k++;
}
for (int i = 0; i<dim; ++i) {
for (int j = i+1; j<dim; ++j) {
CovMat(i,j) = p[k]*
sqrt(CovMat(i,i)*CovMat(j,j));
CovMat(j,i) = CovMat(i,j);
k++;
}
}
if (debug) {
}
if (det <= 0) {
Fatal(
"GausND",
"Determinant is <= 0 det = %f",det);
return 0;
}
if (debug) {
std::cout << "det " << det << std::endl;
std::cout << "norm " << norm << std::endl;
std::cout << "fval " << fval << std::endl;
}
return fval;
}
};
void multidimSampling() {
const int DIM = 4;
double xmin[] = {-10,-10,-10, -10};
double xmax[] = { 10, 10, 10, 10};
double par0[] = { 1., -1., 2, 0,
1, 2, 1, 3,
0.5,0.,0.,0.,0.,0.8 };
const int NPAR = DIM + DIM*(DIM+1)/2;
GausND gaus4d(4);
TF1 *
f =
new TF1(
"functionND",gaus4d,0,1,14);
double x0[] = {0,0,0,0};
if (debug)
f->EvalPar(x0,0);
debug = false;
for (int i = 0; i < NPAR; ++i ) {
if (i < DIM)
f->SetParName(i,
name.Format(
"mu_%d",i+1) );
else if (i < 2*DIM)
f->SetParName(i,
name.Format(
"sig_%d",i-DIM+1) );
else if (i < 2*DIM)
f->SetParName(i,
name.Format(
"sig_%d",i-2*DIM+1) );
}
DistSampler * sampler = Factory::CreateDistSampler();
if (sampler == 0) {
Info(
"multidimSampling",
"Default sampler %s is not available try with Foam ",
}
sampler = Factory::CreateDistSampler();
if (sampler == 0) {
Error(
"multidimSampling",
"Foam sampler is not available - exit ");
return;
}
sampler->SetFunction(*
f,DIM);
bool ret = sampler->Init();
std::vector<double> data1(DIM*
N);
if (!ret) {
Error(
"Sampler::Init",
"Error initializing unuran sampler");
return;
}
for (
int i = 0; i <
N; ++i) {
for (int j = 0; j < DIM; ++j)
}
t1->Branch(
"x",
x,
"x[4]/D");
for (
int i = 0; i <
N; ++i) {
for (int j = 0; j < DIM; ++j) {
}
}
t1->Draw(
"x[0]:x[1]:x[2]:x[3]",
"",
"candle");
int ic=1;
}
void Info(const char *location, const char *msgfmt,...)
void Error(const char *location, const char *msgfmt,...)
void Fatal(const char *location, const char *msgfmt,...)
double pow(double, double)
TRObject operator()(const T1 &t1) const
static void SetDefaultSampler(const char *type)
static const std::string & DefaultSampler()
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
void Print(Option_t *name="") const
Print the matrix as a table of elements.
virtual Double_t Determinant() const
TMatrixTSym< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
TMatrixTSym< Element > & Similarity(const TMatrixT< Element > &n)
Calculate B * (*this) * B^T , final matrix will be (nrowsb x nrowsb) This is a similarity transform w...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
A TTree represents a columnar dataset.
void Print(Option_t *option="") const
Print the vector as a list of elements.