# Problem with Gaussian Distribution

**URL:** <https://root-forum.cern.ch/t/problem-with-gaussian-distribution/37200>\
**Category:** Newbie\
**Created:** [December 14, 2019, 6:21pm UTC](https://root-forum.cern.ch/t/problem-with-gaussian-distribution/37200 "2019-12-14T18:21:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@Abh](https://root-forum.cern.ch/u/Abh)\
**Post date:** [December 14, 2019, 6:21pm UTC](https://root-forum.cern.ch/t/problem-with-gaussian-distribution/37200/1 "2019-12-14T18:21:42Z")

</div>

Hello All  
I am trying to plot gaussian distribution on transverse momentum distribution. But after normalizing the pt histogram, the function does not match with the histogram. The function and normalized histograms are written like this.

//Function3 (Gaussian Function)  
Double\_t myfunction3(Double\_t _a,Double\_t par)  
{  
Int\_t s=par[0];//sigma  
Double\_t w=a[0];//variable  
Double\_t m=par[1];//mean value  
// Double\_t Func3=TMath::Exp((-1.0/2.0)TMath::Power(((w-m)/s),2.0))(1/(sqrt(2TMath::Pi()))); //b=alpha  
Double\_t Func3 =(TMath::Exp(-0.5_((w-m)/s)_((w-m)/s)))/(s_TMath::Sqrt(2\*TMath::Pi()));  
return Func3;  
}

//Histogram  
TH1D \*Trns\_Mom = new TH1D(“Trns\_Mom”,“Transverse\_Momentum;p\_{T};N”,100,-10,60);

//Normalisation  
Double\_t norm1 = Trns\_Mom -\>GetEntries();  
Trns\_Mom-\>Scale(1/norm1);

//Plot  
TCanvas \*c3 = new TCanvas(“c3”,“Transverse Momentum”);  
Trns\_Mom-\>SetLineWidth(3);  
Trns\_Mom-\>SetFillColor(5);  
Double\_t mean1=Trns\_Mom-\>GetMean();  
Double\_t sigma=Trns\_Mom-\>GetStdDev();  
Trns\_Mom-\>Draw();

//Plot of Function  
TF1 \*Gaussian\_Distribution = new TF1(“Gaussian\_Distribution”,myfunction3,-10,50,2);  
Gaussian\_Distribution-\>SetParameters(sigma,mean1);  
TCanvas \*c6 = new TCanvas(“c6”,“Gaussian\_Distribution”);  
Gaussian\_Distribution-\>Draw();

And I am getting graph like this. ![Canvas_1](https://root-forum.cern.ch/uploads/default/original/3X/6/f/6ffd8130085d8196f286e39dac7df57b667682d8.jpeg)

Can Anyone help ?  
Thanks in Advance

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [December 16, 2019, 9:30am UTC](https://root-forum.cern.ch/t/problem-with-gaussian-distribution/37200/2 "2019-12-16T09:30:14Z")

</div>

Hi,  
during the scale process, you should divide for the bin width in addition to the number of entries.  
Then should work.

Cheers,  
Stefano
