# Problem in understanding the Complex code

**URL:** <https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486>\
**Category:** Newbie\
**Created:** [March 19, 2020, 5:39pm UTC](https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486 "2020-03-19T17:39:25Z")\
**Posts on this page:** 7\
**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:** [March 19, 2020, 5:39pm UTC](https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486/1 "2020-03-19T17:39:26Z")

</div>

Hi,  
I am a newbie.  
I was reading a code for the background elimination but unable to understand the code properly.

TSpectrum \*s = new TSpectrum();  
for (i = 0; i \< nbins; i++) source[i]=back-\>GetBinContent(i + 1);  
s-\>Background(source,nbins,10,TSpectrum::kBackDecreasingWindow,  
TSpectrum::kBackOrder8,kTRUE,  
TSpectrum::kBackSmoothing5,kTRUE);  
for (i = 0; i \< nbins; i++) d1-\>SetBinContent(i + 1,source[i]);

Elaborate a bit more.  
Thanks in advance.

_ROOT Version:_ 6.14  
_Platform:_ Ubuntu

---

<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:** [March 19, 2020, 6:01pm UTC](https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486/2 "2020-03-19T18:01:39Z")

</div>

[TH1::GetBinContent](https://root.cern.ch/doc/master/classTH1.html#ac70dcb4082bd510f5aa3e6efeb043f39)  
[TH1::SetBinContent](https://root.cern.ch/doc/master/classTH1.html#a9599e2dae40c574fd9d8970aaf638ee6)  
[TSpectrum::Background](https://root.cern.ch/doc/master/classTSpectrum.html#a7830480612d1ee301964e6c79319f444)  
[TSpectrum manual](https://root.cern.ch/root/htmldoc/guides/spectrum/Spectrum.html)

---

<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:** [March 19, 2020, 6:14pm UTC](https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486/3 "2020-03-19T18:14:12Z")

</div>

Thanks for your response @Wile_E_Coyote.  
TFile \*f = new TFile(file.Data());  
TH1F _back = (TH1F_) f-\>Get(“back3”);  
if i try to have the data points from the graph which already has all the points contained in it.  
as i have  
TGraph \*g = new TGraph(“sample.txt”);  
Int\_t n = g-\>GetN();

then how does this code should be modified?  
TH1F _back = (TH1F_) f-\>Get(“back3”);

---

<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:** [March 19, 2020, 8:22pm UTC](https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486/4 "2020-03-19T20:22:56Z")

</div>

Try:

```cpp
TGraph *g = new TGraph("sample.txt");
TSpectrum *s = new TSpectrum();
s->Background(g->GetY(), g->GetN(),
              10, TSpectrum::kBackDecreasingWindow,
              TSpectrum::kBackOrder8, kTRUE,
              TSpectrum::kBackSmoothing5, kTRUE);
g->Draw("AL");

```

---

<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:** [March 19, 2020, 9:04pm UTC](https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486/7 "2020-03-19T21:04:53Z")

</div>

Thanks @Wile_E_Coyote

 ![backg1](https://root-forum.cern.ch/uploads/default/original/3X/a/8/a8399d424404f512d86a2c611de9183d00ca868d.png)

I don’t know whether it is fine or not?  
and i don’t understand why these lines are gone below zero (see near 2000 or 4000…)  
Also, don’t know where does initial histogram has gone?

---

<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:** [March 19, 2020, 9:22pm UTC](https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486/8 "2020-03-19T21:22:35Z")

</div>

@Wile_E_Coyote  
Is the above code useful for background elimination?  
As my histogram also comprises of fitted peaks.  
How should i combine this code with histogram of the same file that i have drawn earlier?

---

<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:** [March 20, 2020, 11:22am UTC](https://root-forum.cern.ch/t/problem-in-understanding-the-complex-code/38486/9 "2020-03-20T11:22:48Z")

</div>

@Wile_E_Coyote  
May be i have got something. please look at it once.  
Tell me how should i modify the limit of y-axis.

 ![cleanback](https://root-forum.cern.ch/uploads/default/original/3X/0/2/02121bd0710984a40eab38532ce06ed9cf297d22.png)

I am already using:  
h-\>SetMaximum(1000.);//along Y  
h-\>SetMinimum(0.);
