ROOT   Reference Guide
Searching...
No Matches
multivarGaus.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_math
3/// \notebook
4/// Tutorial illustrating the multivariate gaussian random number generation
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Jorge Lopez
10
11void multivarGaus() {
13 rnd.Initialize();
14
15 const int dim = 3;
16 double pars[dim] = {0, 0, 0.5};
17 double genpars[dim] = {0, 0, 0};
18 double cov[dim * dim] = {1.0, -0.2, 0.0, -0.2, 1.0, 0.5, 0.0, 0.5, 0.75};
19
20 TH1F* hX = new TH1F("hX", "hX;x;Counts", 100, -5, 5);
21 TH1F* hY = new TH1F("hY", "hY;y;Counts", 100, -5, 5);
22 TH1F* hZ = new TH1F("hZ", "hZ;z;Counts", 100, -5, 5);
23
24 TH2F* hXY = new TH2F("hXY", "hXY;x;y;Counts", 100, -5, 5, 100, -5, 5);
25 TH2F* hXZ = new TH2F("hXZ", "hXZ;x;z;Counts", 100, -5, 5, 100, -5, 5);
26 TH2F* hYZ = new TH2F("hYZ", "hYZ;y;z;Counts", 100, -5, 5, 100, -5, 5);
27
28 const int MAX = 10000;
29 for (int iEvent = 0; iEvent < MAX; ++iEvent) {
30 rnd.GaussianND(dim, pars, cov, genpars);
31 auto x = genpars[0];
32 auto y = genpars[1];
33 auto z = genpars[2];
34 hX->Fill(x);
35 hY->Fill(y);
36 hZ->Fill(z);
37 hXY->Fill(x, y);
38 hXZ->Fill(x, z);
39 hYZ->Fill(y, z);
40 }
41
42 TCanvas* c = new TCanvas("c", "Multivariate gaussian random numbers");
43 c->Divide(3, 2);
44 c->cd(1);
45 hX->Draw();
46 c->cd(2);
47 hY->Draw();
48 c->cd(3);
49 hZ->Draw();
50 c->cd(4);
51 hXY->Draw("COL");
52 c->cd(5);
53 hXZ->Draw("COL");
54 c->cd(6);
55 hYZ->Draw("COL");
56}
#define c(i)
Definition RSha256.hxx:101
GSLRandomEngine Base class for all GSL random engines, normally user instantiate the derived classes ...
void GaussianND(size_t dim, const double *pars, const double *covmat, double *genpars, double *lmat=nullptr) const
Multivariate Gaussian distribution.
void Initialize()
initialize the generator If no rng is present the default one based on Mersenne and Twister is create...
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:622
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3344
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:393
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
#define MAX(x, y)
Definition sweep.c:94