54 for (
int i = 0; i<dim; ++i) { X[i] = x[i] - p[k]; k++; }
55 for (
int i = 0; i<dim; ++i) {
56 CovMat(i,i) = p[k]*p[k];
59 for (
int i = 0; i<dim; ++i) {
60 for (
int j = i+1; j<dim; ++j) {
62 CovMat(i,j) = p[k]*
sqrt(CovMat(i,i)*CovMat(j,j));
63 CovMat(j,i) = CovMat(i,j);
74 Fatal(
"GausND",
"Determinant is <= 0 det = %f",det);
84 std::cout <<
"det " << det << std::endl;
85 std::cout <<
"norm " << norm << std::endl;
86 std::cout <<
"fval " << fval << std::endl;
96 void multidimSampling() {
103 double xmin[] = {-10,-10,-10, -10};
104 double xmax[] = { 10, 10, 10, 10};
105 double par0[] = { 1., -1., 2, 0,
107 0.5,0.,0.,0.,0.,0.8 };
109 const int NPAR = DIM + DIM*(DIM+1)/2;
112 TF1 *
f =
new TF1(
"functionND",gaus4d,0,1,14);
115 double x0[] = {0,0,0,0};
121 for (
int i = 0; i < NPAR; ++i ) {
122 if (i < DIM) f->
SetParName(i, name.Format(
"mu_%d",i+1) );
123 else if (i < 2*DIM) f->
SetParName(i, name.Format(
"sig_%d",i-DIM+1) );
124 else if (i < 2*DIM) f->
SetParName(i, name.Format(
"sig_%d",i-2*DIM+1) );
128 DistSampler * sampler = Factory::CreateDistSampler();
130 Info(
"multidimSampling",
"Default sampler %s is not available try with Foam ",
134 sampler = Factory::CreateDistSampler();
136 Error(
"multidimSampling",
"Foam sampler is not available - exit ");
142 bool ret = sampler->
Init();
144 std::vector<double> data1(DIM*N);
149 Error(
"Sampler::Init",
"Error initializing unuran sampler");
155 for (
int i = 0; i <
N; ++i) {
157 for (
int j = 0; j < DIM; ++j)
158 data1[N*j + i] = v[j];
164 TFile *
file =
new TFile(
"multiDimSampling.root",
"RECREATE");
166 TTree *
t1 =
new TTree(
"t1",
"Tree from Unuran");
167 t1->Branch(
"x",x,
"x[4]/D");
168 for (
int i = 0; i <
N; ++i) {
169 for (
int j = 0; j < DIM; ++j) {
176 t1->Draw(
"x[0]:x[1]:x[2]:x[3]",
"",
"candle");
181 t1->
Draw(
"x[0]:x[1]");
183 t1->
Draw(
"x[0]:x[2]");
185 t1->
Draw(
"x[0]:x[3]");
187 t1->
Draw(
"x[1]:x[2]");
189 t1->
Draw(
"x[1]:x[3]");
191 t1->
Draw(
"x[2]:x[3]");
virtual void SetParameters(const Double_t *params)
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
virtual void SetParName(Int_t ipar, const char *name)
Set name of parameter number ipar.
virtual void Draw(Option_t *option="")=0
Default Draw method for all objects.
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
void Fatal(const char *location, const char *msgfmt,...)
static void SetDefaultSampler(const char *type)
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
const double * Sample()
sample one event and rerturning array x with coordinates
void Print(Option_t *option="") const
Print the vector as a list of elements.
TRObject operator()(const T1 &t1) const
void Stop()
Stop the stopwatch.
void SetFunction(Function &func, unsigned int dim)
set the parent function distribution to use for sampling (generic case)
double pow(double, double)
void Info(const char *location, const char *msgfmt,...)
void Error(const char *location, const char *msgfmt,...)
virtual Double_t Determinant() const
void SetRange(double xmin, double xmax, int icoord=0)
set range in a given dimension
Interface class for generic sampling of a distribution, i.e.
static const std::string & DefaultSampler()
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 Print(Option_t *name="") const
Print the matrix as a table of elements.
TMatrixTSym< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
virtual bool Init(const char *="")
initialize the generators with the given algorithm Implemented by derived classes who needs it (like ...
virtual Double_t EvalPar(const Double_t *x, const Double_t *params=0)
Evaluate function with given coordinates and parameters.