# 2D histogram with gaussian distribution at different points

Hello,

I would like to know how can I plot a 2D histogram, where I plot different Gaussian for corresponding center x and center y and sigma x and sigma y.
I started defining the code as follow:

[code]TH2F *h2 = new TH2F(“h2”,“distribution”, 50,0,25,50,0,25);
for (Float_t centre_x=2.7; centre_x<12.8; centre_x+=1.0) {
for (Float_t centre_y=2.7; centre_y<12.8; centre_y+=1.0) {

``````    TF2 *f2 = new TF2("f2","TMath::Gaus(1,centre_x,[1])*TMath::Gaus(1,centre_y,[1])",0,25,0,25);
``````

// code to follow the for loop

f2->SetParameter(1,h6->GetRMS());
h2->Fill(f2);
h2->Draw();
[/code]

I am writing the whole code also, in case I am not clear…

[code] TH2F *relation = new TH2F(“relation”,“intrinsic spatial resolution”, 50,0,25,50,0,25);
for (Float_t centre_x=2.7; centre_x<12.8; centre_x+=1.0) {
for (Float_t centre_y=2.7; centre_y<12.8; centre_y+=1.0) {

TF2 *rel = new TF2(“rel”,“TMath::Gaus(1,centre_x,[1])*TMath::Gaus(1,centre_y,[1])”,0,25,0,25);

``````        TH1F *h6 = new TH1F("h6", "dist", 200, 4, 20);
for (Int_t i=0; i<10; i++){ TF1 f1("f1","gaus",0,30000); f1->SetParameters(1,16000,545);

Float_t bin0 = (f1->GetRandom())*0.3;

TF1 *f7 = new TF1("f7", "TMath::Poisson(x,[5])",0,10000);
f7->SetParameter(5,bin0);

const Int_t Nx = 15;
Double_t edgesx[(Nx + 1)] = {0, 3, 3.2, 6.2, 6.4, 9.4, 9.6, 12.6, 12.8, 15.8, 16, 19, 19.2, 22.2, 22.4, 25.4};

const Int_t Ny = 15;
Double_t edgesy[(Ny + 1)] = {0, 3, 3.2, 6.2, 6.4, 9.4, 9.6, 12.6, 12.8, 15.8, 16, 19, 19.2, 22.2, 22.4, 25.4};

TH2F *h2 = new TH2F("h2","h",Nx,edgesx,Ny,edgesy); //Canvas to see the 2D distribution of optical photons over SiPM matrix
TF2 *f2 = new TF2("f2","xygaus",0,20,0,20);
f2->SetParameters(1, centre_x, 3, centre_y, 3);  //amplitude, meanx,sigmax,meany,sigmay
h2->FillRandom("f2",f7->GetRandom());

TF1 *f5 = new TF1("f5", "TMath::Poisson(x, [0])", 0, 10000);
f5->SetParameter(0, 1);

TH2F *h5 = new TH2F("h5", "d=0.8 and t=0.4mm", Nx, edgesx, Ny, edgesy);
for (Int_t ix = 1; ix <= h5->GetNbinsX(); ix+=2) {
for (Int_t iy = 1; iy <= h5->GetNbinsY(); iy+=2) {
Double_t par = 0.30 * h2->GetBinContent(ix, iy);
if (par > 0.0) {
f5->SetParameter(0, par);
h5->SetBinContent(ix, iy, f5->GetRandom());
} else {
// h5->SetBinContent(ix, iy, 0.0);
}
}
}
h6->Fill(h5->GetMean()); delete h5; delete h2;
}
rel->SetParameter(1,h6->GetRMS());

relation->Fill(rel);

}
``````

}
relation->Draw();
[/code]

Thank you.

Regards,
Kajal

Start with: ```{ TF2 *f2 = new TF2("f2", "TMath::Gaus(x,[0],[2])*TMath::Gaus(y,[1],[2])", 0, 25, 0, 25); TH2F *h2 = new TH2F("h2", "distribution", 50, 0, 25, 50, 0, 25); for (Float_t centre_x=2.7; centre_x<12.8; centre_x+=1.0) { for (Float_t centre_y=2.7; centre_y<12.8; centre_y+=1.0) { f2->SetParameters(centre_x, centre_y, 0.1); // f2->SetParameters(centre_x, centre_y, h6->GetRMS()); h2->FillRandom("f2", 1000); } } h2->Draw("SURF3"); }```

Hello Pepe Le Pew,

Thank you for your response. However, I want to plot the Gaussian with circular projection or only the projection on xy plane. Is it possible to get it?

Thank you.
Regards,
Kajal

Hello,

I tried all the options supported by TH2D. I am currently using “CONT0”.
However, I get diamond shaped projection with that. Is it possible to get a circular projection??

Thank you.

Regards,
Kajal