# Retaining multiple gaussian fits on a histogram

**URL:** <https://root-forum.cern.ch/t/retaining-multiple-gaussian-fits-on-a-histogram/58022>\
**Category:** Newbie\
**Created:** [February 1, 2024, 9:56am UTC](https://root-forum.cern.ch/t/retaining-multiple-gaussian-fits-on-a-histogram/58022 "2024-02-01T09:56:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [February 1, 2024, 9:56am UTC](https://root-forum.cern.ch/t/retaining-multiple-gaussian-fits-on-a-histogram/58022/1 "2024-02-01T09:56:24Z")

</div>

Hi I am trying to fit the same gaussian function to multiple regions of the histogram, different peaks basically.  
Is there any way I can draw all the fits on the histogram simultaneously.

Presently as soon as I fit the second region and draw a histogram the fit function from first location disappears. I understand this is pretty much obvious since I a using a single function for the fi, but is there any workaround to basically show all the fit in different regions of the histograms at once? That will be really helpful.

Please let me know if I am not able to clarify myself  
Here is the macro if it helps

```auto
TF1* fit0 = new TF1("nfit0","gaus(0)",20,1000); 
 //Fitting
	 for(Int_t k=0; k<2; k++) {	
	 	//Fit region 1
	 	if (100. < xpeaks[k] && xpeaks[k]< 140.) {
	 	  his -> GetXaxis() -> SetRangeUser(xpeaks[k]-30, xpeaks[k]+40);
                  his -> Fit("nfit0"); //Fitting	 				
	 	}
	 	
	 	//Fit region 2
	 	if (3220. < xpeaks[k] && xpeaks[k]< 3260.) {
	 	  his -> GetXaxis() -> SetRangeUser(xpeaks[k]-30, xpeaks[k]+40);
                  his -> Fit("nfit0"); //Fitting				
	 	}
	 }

```

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![mdessole](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mdessole/32/34021_2.png) [@mdessole](https://root-forum.cern.ch/u/mdessole)\
**Post date:** [February 1, 2024, 10:30am UTC](https://root-forum.cern.ch/t/retaining-multiple-gaussian-fits-on-a-histogram/58022/2 "2024-02-01T10:30:26Z")

</div>

Hi @utkarsh-2000,  
thank you for posting on the ROOT forum!

I think that @Jonas could help with this, but in the meanwhile I suggest you to have a look at [this tutorial](https://root.cern/doc/master/multifit_8C.html).

Cheers,  
Monica

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [February 1, 2024, 10:36am UTC](https://root-forum.cern.ch/t/retaining-multiple-gaussian-fits-on-a-histogram/58022/3 "2024-02-01T10:36:05Z")

</div>

Hi @mdessole,  
Thanks for sharing the tutorial.
