# Baseline for spectrum

**URL:** <https://root-forum.cern.ch/t/baseline-for-spectrum/54538>\
**Category:** Newbie\
**Created:** [April 18, 2023, 8:42am UTC](https://root-forum.cern.ch/t/baseline-for-spectrum/54538 "2023-04-18T08:42:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iRush](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/irush/32/33095_2.png) [@iRush](https://root-forum.cern.ch/u/iRush)\
**Post date:** [April 18, 2023, 8:42am UTC](https://root-forum.cern.ch/t/baseline-for-spectrum/54538/1 "2023-04-18T08:42:19Z")

</div>

\_ROOT Version: 6.26  
\_Platform: Linux  
\_Compiler: GCC 8.5.0

* * *

Hi all,

Newbie here. I want to know what class and functions should I use to calculate the baseline of the TH1F spectrum below, and also, how to constrain the gaus fit to the baseline; you can see the gaus fit (in red) extending below.

I’m looking to compute the peak area properly using the gaus fit. I have done by `hist->IntegralAndError()` & `fit->Integral()`

I found TVirtualFitter, is this a good choice? or are there better solutions for baselines?

Any other advice would be much appreciated.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/4/2/4253601154b638b94f5a5d9b17ca21e8677c6740.jpeg)

-MJ

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 18, 2023, 9:26am UTC](https://root-forum.cern.ch/t/baseline-for-spectrum/54538/2 "2023-04-18T09:26:06Z")

</div>

Welcome to the ROOT fourm.

I guess @moneta can help.

---

<div class="post-metadata">

**Author:** ![iRush](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/irush/32/33095_2.png) [@iRush](https://root-forum.cern.ch/u/iRush)\
**Post date:** [April 20, 2023, 12:31am UTC](https://root-forum.cern.ch/t/baseline-for-spectrum/54538/3 "2023-04-20T00:31:25Z")

</div>

Hi All,

It seems I overlooked an easy one.

```auto
TSpectrum *s = new TSpectrum();
TH1* backGroundOfHist = s->Background(hist0,20,"same");
hist0->Add(backGroundOfHist,-1);

```

I hope this can help others.

Kind regards,  
MJ
