# Strange integral value?

Hello

Iâ€™m writing a little macro in order to compare two kind of fit: crystal ball and a combination of 2 Gaussians. The macro works fine but for the integral the value seems to be not good. The result of the integral is about 438 for the two methods. When I look the plot and the fit I expect a higher value.

Here is the code

[code]#include â€śTMath.hâ€ť
#include â€śTFile.hâ€ť
#include â€śTH1.hâ€ť
#include â€śTF1.hâ€ť
#include â€śRiostream.hâ€ť
#include â€śRiostream.hâ€ť
#include <math.h>
#include â€śTStyle.hâ€ť
#include â€śTCanvas.hâ€ť
#include <TROOT.h>

Bool_t reject;

//Crystal ball function for signal, parameters are 0:alpha,1:n,2:mean,3:sigma,4:normalization;

Double_t CrystalBall(Double_t *x,Double_t *par) {

Double_t t = (x[0]-par[2])/par[3];
if (par[0] < 0) t = -t;

Double_t absAlpha = fabs((Double_t)par[0]);

if (t >= -absAlpha) {
return par[4]exp(-0.5tt);
}
else {
Double_t a = TMath::Power(par[1]/absAlpha,par[1])exp(-0.5absAlpha
absAlpha);
Double_t b= par[1]/absAlpha - absAlpha;

``````return par[4]*(a/TMath::Power(b - t, par[1]));
``````

}
}

//Exponential background excluding the signal area

Double_t Background(Double_t *x, Double_t *par)
{
if (reject && x[0] > 2.7 && x[0] < 3.3) {
TF1::RejectPoint();
return 0;
}
return exp(-(x[0]-par[0]));
}

//Superposition of 2 gaussians

Double_t G1(Double_t *x, Double_t *par)
{
Double_t arg = 0;
if (par[2]) arg = (x[0] - par[1])/par[2];

Double_t sig = par[0]TMath::Exp(-0.5arg*arg);
return sig;
}

Double_t G2(Double_t *x, Double_t *par)
{
Double_t arg = 0;
if (par[2]) arg = (x[0] - par[1])/par[2];

Double_t sig = par[0]TMath::Exp(-0.5arg*arg);
return sig;
}

Double_t Total(Double_t *x, Double_t *par)
{
Double_t tot = G1(x,par) + G2(x,&par[3]);
}

void FitCB()
{

gStyle->SetCanvasBorderMode(0);
gStyle->SetCanvasColor(kWhite);
gStyle->SetFrameBorderMode(0);
gStyle->SetFrameFillColor(kWhite);
gStyle->SetPalette(1,0);

TFile *f = new TFile(â€śEM.AOD.rootâ€ť);

TList *t = new TList();

f->GetObject(â€ślistâ€ť,t);

TH1F* hpx = (TH1F*)t->FindObject(â€śfInvMassâ€ť);

TCanvas *c1 = new TCanvas(â€śc1â€ť,â€śthe fit canvasâ€ť,1000,800);

TF1 *func = new TF1(â€śfuncâ€ť,Background,2,4,1);
func->SetParameters(-0.85,0);
func->SetParNames(â€śslopeâ€ť);

//Fit the background

reject = kTRUE;
hpx->Fit(func,â€śrâ€ť);
reject = kFALSE;

//Crytal ball declaration

TF1 *crystal = new TF1(â€ścrystalâ€ť,CrystalBall,2.7,3.3,5);
crystal->SetParameters(1,1,3.1,0.08,2000);
crystal->SetParNames("#alpha",â€śnâ€ť,â€śMeanâ€ť,"#sigma",â€śNâ€ť);

hpx->Fit(crystal,â€śrâ€ť);

hpx->Draw();

Int_t npar = 6;
Double_t params[6] = {1500,3.096,0.08,350,3.096,1};
TF1 *theory = new TF1(â€śtheoryâ€ť,Total,2.7,3.3,npar);
theory->SetParameters(params);
theory->SetParNames(â€śN G1â€ť,â€śMean G1â€ť,"#sigma G1",â€śN G2â€ť,â€śMean G2â€ť,"#sigma G2");

hpx->Fit(â€śtheoryâ€ť,â€śrâ€ť);
func->Draw(â€śsameâ€ť);
theory->Draw(â€śsameâ€ť);

crystal->SetLineColor(kBlue);
crystal->SetLineStyle(kDashed);
crystal->Draw(â€śsameâ€ť);

Double_t numberOfJpsi = crystal->Integral(2.7,3.3);
cout << â€śNumber of JPsi by the crystal ball methodâ€ť << endl;
cout << numberOfJpsi << endl;

Double_t numberOfJpsi2 = theory->Integral(2.7,3.3);
cout << â€śNumber of JPsi by the 2 gaussians methodâ€ť << endl;
cout << numberOfJpsi2 << endl;

Int_t a = hpx->GetXaxis()->FindFixBin(2.7);
Int_t b = hpx->GetXaxis()->FindFixBin(3.3);

Double_t hpxIntegral = hpx->Integral(a,b);

cout << hpxIntegral << endl;
}
[/code]

Hi,

the integral calculated on the function is the number of events multiplied by the bin width, while the one of the histogram is the total number of events in the bin.
A value of 438 for the integral multiplied by the bin width seems ok to me looking naively at the plot. The bin width is around 0.1, so you get about 4380 events in the peak.

Regards

Lorenzo

Ok

thanks a lot