# 2d gaussian fit

hello i need some help with a two dimension gaussian fit.

the code is as follows.

#include "TF2.h"
#include "TH2.h"

Double_t g2(Double_t *x, Double_t *par) {
if (par[2]>0 && par[4]>0)
{   Double_t r1 = Double_t((x[0]-par[1])/par[2]);
Double_t r2 = Double_t((x[1]-par[3])/par[4]);
return par[0]*TMath::Exp(-0.5*(r1*r1+r2*r2));
}
else return 0;				}
Double_t fun2(Double_t *x, Double_t *par) {
Double_t *p1 = &par[0];
Double_t *p2 = &par[5];
Double_t *p3 = &par[10];
Double_t result = g2(x,p1) + g2(x,p2) + g2(x,p3);
return result;
}

void g2(){
/
gROOT->Reset();

// -----------------------------------------------------------
c0= new TCanvas("c0","ssd",0,0,800,600);

gROOT->SetStyle("Plain");
gStyle->SetOptStat(0);
gStyle->SetFrameLineColor(0);

c0->Range(0,0,1,1);
c0->SetFillColor(0);

TFile *ftf  = new TFile("w.root");

ftf->cd();
int nl,i, n;
double gpar[3], parA[99][3],parB[99][3];

double pp[10][5];

TH1F *hsi= new TH1F("hsi","",2000,0,2000);
TH1F *hpd= new TH1F("hpd","",2000,0,2000);

TH2F *hh= new TH2F("hh","",133,0,2000,133,0,2000);
TH2F *ss= new TH2F("ss","",100,0,2200,100,0,2200);

tr->Draw("si1>>hsi","");
TF1 *gsi= new TF1("gsi","gaus",hsi->GetMaximumBin()-250,hsi->GetMaximumBin()+250);
hsi->Fit("gsi","Rq"); gsi->GetParameters(parA[nl]);
gsi->SetRange(parA[nl][1]-2*parA[nl][2],parA[nl][1]+2*parA[nl][2]);
hsi->Fit("gsi","Rq"); gsi->GetParameters(parA[nl]);

tr->Draw("pd2>>hpd","");
TF1 *gpd= new TF1("gpd","gaus",hpd->GetMaximumBin()-250,hpd->GetMaximumBin()+250);
hpd->Fit("gpd","Rq"); gpd->GetParameters(parB[nl]);
gpd->SetRange(parB[nl][1]-2*parB[nl][2],parB[nl][1]+2*parB[nl][2]);
hpd->Fit("gpd","Rq"); gpd->GetParameters(parB[nl]);

tr->Draw("pd2:si1>>ss","","");
//TF2  *g2d = new TF2("g2d",fun2,1350,1650,1500,1900,25);
//g2d->SetRange(1350,1650,1500,1900);
//ss->Fit("g2d","N");
//ss->Draw("lego");
//g2d->Draw("surf,same");

}
i get stuck right at  TF2  *g2d = ...etc

thanks

-Remove the statement "gROOT->Reset();
This statement SHOULD NOT BE USED IN a NAMED script

-you have a function called “g2” and also your main function called g2.
Give it another name.

Rene