# Any way of getting background data?

**URL:** <https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [April 20, 2020, 9:24am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992 "2020-04-20T09:24:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 20, 2020, 9:24am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/1 "2020-04-20T09:24:04Z")

</div>

@Wile_E_Coyote @couet  
[fithisto.C](https://root-forum.cern.ch/uploads/short-url/rudaL3yM1op7MgDpA2UasD04Vko.C) (3.6 KB)  
[eu\_gu\_1.txt](https://root-forum.cern.ch/uploads/short-url/kn9woacPX2mqQI0v5OngH2uYeGm.C) (44.1 KB)  
The above code gives final spectrum which subtract background from raw data.  
I am unable to understand how can i extract any data that was subtracted from raw data.  
Is there any possible way of doing the above and how does the area gets affected?

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<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 20, 2020, 9:44am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/2 "2020-04-20T09:44:11Z")

</div>

Your macro gives me this:

 ![Screenshot 2020-04-20 at 11.42.04](https://root-forum.cern.ch/uploads/default/original/3X/b/c/bcdb0721c277501f8580c178c31521339f22182a.png)

> [@robertfroast](#):
>
> I am unable to understand how can i extract any data that was subtracted from raw data.

I am not completely sure tu understand what you want to do exactly .

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 20, 2020, 9:48am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/3 "2020-04-20T09:48:49Z")

</div>

You can make a clone of your histogram and apply the “background estimation” to that clone. Then you can subtract that clone (which will then be the “background”) from your original (unmodified) histogram.

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 20, 2020, 11:40am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/4 "2020-04-20T11:40:03Z")

</div>

@Wile_E_Coyote @couet  
Thanks for your suggestion. I have tried something still unable to get result that i was expecting.  
Can you please help me.  
[fithisto.C](https://root-forum.cern.ch/uploads/short-url/kgzfrEfVwluwrsr23mPwJPGCtF2.C) (3.8 KB) [hist.C](https://root-forum.cern.ch/uploads/short-url/9edsOIaMQM5OtaOTe73cPe7El2r.C) (905 Bytes)  
[eu\_gu\_1.txt](https://root-forum.cern.ch/uploads/short-url/kn9woacPX2mqQI0v5OngH2uYeGm.C) (44.1 KB)

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 21, 2020, 1:39am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/5 "2020-04-21T01:39:09Z")

</div>

@Wile_E_Coyote @couet  
Can you please suggest me something because after trying so hard I am still unable to get any expected result.

---

<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 21, 2020, 7:45am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/6 "2020-04-21T07:45:41Z")

</div>

I get this plot. So it seems you managed to remove the background ?

 ![Screenshot 2020-04-21 at 09.44.20](https://root-forum.cern.ch/uploads/default/original/3X/b/a/bac8c6e0ba0413d35927ce1ae0cb708a9e6de818.png)

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 21, 2020, 7:51am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/7 "2020-04-21T07:51:22Z")

</div>

@couet @Wile_E_Coyote  
I have already remove the background in “fithisto.C” file using “TSpectrum:Background”. But I want to extract background data and in order to get that i was subtracting the data in which background was already subtracted from the raw data.  
After subtraction I should be able to get the background but the above graph doesn’t implies background.  
That’s the question.

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 21, 2020, 9:42am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/8 "2020-04-21T09:42:09Z")

</div>

@Wile_E_Coyote  
Were you able to get anything out of it?

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [April 24, 2020, 11:58am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/10 "2020-04-24T11:58:52Z")

</div>

> but the above graph doesn’t implies background.

What kind of different plot do you expect?

RAW is this:  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/f/a/fa22570affcc3f6c80a27cec2c5d2eda8e01b5ea.png)

diff is this:  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/2/5/25cf1349a0b8a37e58152a582801691e5bcc1c3d.png)

So you can see that something happened - I’d call that background subtraction 🙂

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [April 25, 2020, 9:43am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/11 "2020-04-25T09:43:45Z")

</div>

ok @Axel.  
I will come to that part later. For the time being, could you please elaborate the following part of the code? How does it works?

TSpectrum _s = new TSpectrum(2_npeaks);  
Int\_t nfound = s-\>Search(h,2,"",0.06);  
printf(“Found %d candidate peaks to fit\n”,nfound);

s-\>Background(h-\>GetArray() + 1, n,  
10, TSpectrum::kBackDecreasingWindow,  
TSpectrum::kBackOrder8, kTRUE,  
TSpectrum::kBackSmoothing15, kTRUE);

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 26, 2020, 8:42am UTC](https://root-forum.cern.ch/t/any-way-of-getting-background-data/38992/12 "2020-04-26T08:42:50Z")

</div>

[TSpectrum::TSpectrum](https://root.cern/doc/master/classTSpectrum.html#aba44d2bb23b8e5db9b495a9dafb41d3b)  
[TSpectrum::Search](https://root.cern/doc/master/classTSpectrum.html#a5f8b7b208f813670259b51a8bcdcbfc5)  
[TSpectrum::Background](https://root.cern/doc/master/classTSpectrum.html#a7830480612d1ee301964e6c79319f444)  
[printf](http://www.cplusplus.com/reference/cstdio/printf/)
