# Need to remove the alpha background present in the spectrum

**URL:** <https://root-forum.cern.ch/t/need-to-remove-the-alpha-background-present-in-the-spectrum/35217>\
**Category:** Newbie\
**Created:** [July 16, 2019, 2:39pm UTC](https://root-forum.cern.ch/t/need-to-remove-the-alpha-background-present-in-the-spectrum/35217 "2019-07-16T14:39:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahina](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shahina/32/19464_2.png) [@shahina](https://root-forum.cern.ch/u/shahina)\
**Post date:** [July 16, 2019, 2:39pm UTC](https://root-forum.cern.ch/t/need-to-remove-the-alpha-background-present-in-the-spectrum/35217/1 "2019-07-16T14:39:11Z")

</div>

Hi,

I need to remove the alpha background present in the background spectrum. The run244.root is the background run. I am using the following macro to make the cut. But I don’t know how to save the spectrum. Also I want to plot the histogram of background run with the other run to see how much background I still have in the spectrum. How shall I do it?  
Here is the macro.  
[psdB0C6.C](https://root-forum.cern.ch/uploads/short-url/kYFWAXfOQ33QnJ5GGYV1VwZ9Syp.C) (752 Bytes) [run244.root](https://root-forum.cern.ch/uploads/short-url/vs3OiCrQBqTeg1b2a3Bf4ggZDuS.root) (69.9 KB) [run324.root](https://root-forum.cern.ch/uploads/short-url/nfAyv2frM1HVvmau9iSZP3rO9Jz.root) (45.0 KB) [run325.root](https://root-forum.cern.ch/uploads/short-url/jUeovfm6xfWfRmc7sEgLjulOmun.root) (47.7 KB) [run326.root](https://root-forum.cern.ch/uploads/short-url/jxlrHSV4E415y7lHP9zjsNH5Lw6.root) (64.8 KB) [run327.root](https://root-forum.cern.ch/uploads/short-url/iTGPJSNoXab9mz5AH30Ua66ZrJD.root) (38.5 KB) [run328.root](https://root-forum.cern.ch/uploads/short-url/qD0aejGrTJ5wSspaOG1l82GbUF7.root) (56.5 KB) [run329.root](https://root-forum.cern.ch/uploads/short-url/fzuJzvdQYf30iBS1kBySRFp6Pg.root) (53.0 KB) [run330.root](https://root-forum.cern.ch/uploads/short-url/dIO6EYxwvkK01pkCrhTJUzwNUHN.root) (56.2 KB) [run332.root](https://root-forum.cern.ch/uploads/short-url/vJ1dundoaqzRVegrBIkDLQojW0L.root) (55.3 KB) [run333.root](https://root-forum.cern.ch/uploads/short-url/eqcPjN8Mmo1AUcIG9DVBiIpOKPB.root) (54.5 KB) [run335.root](https://root-forum.cern.ch/uploads/short-url/t59pPxTzEwN6yM4F0ZSibd2eAmL.root) (53.0 KB) [run336.root](https://root-forum.cern.ch/uploads/short-url/6OqEnQnIC9HYdBYjxs5LbbQzy8J.root) (53.8 KB) [run338.root](https://root-forum.cern.ch/uploads/short-url/qO6DsAEE3555fKcN0RopzaTQYT8.root) (56.2 KB) [run340.root](https://root-forum.cern.ch/uploads/short-url/tAjY3NrLbCmv7aHkfponxlrYA8n.root) (53.8 KB) [run342.root](https://root-forum.cern.ch/uploads/short-url/bos9Nn4VsHFpIvGttSQMGs5BzUD.root) (57.2 KB) [run344.root](https://root-forum.cern.ch/uploads/short-url/wZxBUZKAP6RquvZbIsQ6XRMpuSy.root) (55.4 KB) [run346.root](https://root-forum.cern.ch/uploads/short-url/jmQBkfid5uoDpbM709cHgikIehO.root) (59.4 KB) [run348.root](https://root-forum.cern.ch/uploads/short-url/fAQJPI5E2dyEYbPNr9DT2wNFF01.root) (56.8 KB) [run350.root](https://root-forum.cern.ch/uploads/short-url/h5TQcQ4qdOhIHvJyUsSZPav6T8a.root) (55.7 KB) [run352.root](https://root-forum.cern.ch/uploads/short-url/nhssc0PSQPDJwcLjqc97og1CuPs.root) (56.3 KB) [run354.root](https://root-forum.cern.ch/uploads/short-url/lhhW0zaaBbdCenEjnGXMLzBinKs.root) (30.1 KB) [run355.root](https://root-forum.cern.ch/uploads/short-url/izF913UbX45QfbJlopPIF978Bah.root) (54.7 KB) [run357.root](https://root-forum.cern.ch/uploads/short-url/l8dJw0Wvkf69uU6CfFu4qpyKEc8.root) (53.1 KB) [run359.root](https://root-forum.cern.ch/uploads/short-url/9jR5PCmXbeazQFC7zWbYQbf2Qmg.root) (55.6 KB) [run361.root](https://root-forum.cern.ch/uploads/short-url/zMf5lsRITh9HaETdnTJ43GhofsN.root) (58.6 KB) [run363.root](https://root-forum.cern.ch/uploads/short-url/5I0iOUIr6xGIHKPfyvZBUxX2GH1.root) (60.6 KB) [run365.root](https://root-forum.cern.ch/uploads/short-url/dFqzlk1JlsrAjIalQxTRg4DJRjW.root) (45.9 KB) [run366.root](https://root-forum.cern.ch/uploads/short-url/12q3jvG0gIxfBXR6GRB7XeO7YUj.root) (53.1 KB) [run368.root](https://root-forum.cern.ch/uploads/short-url/tQ3VYr7lrxX8uU7Tx8iEzeJvrND.root) (54.6 KB) [run370.root](https://root-forum.cern.ch/uploads/short-url/dOlc23zU21DZ5hktQSsfxOv8OKn.root) (21.9 KB) [run371.root](https://root-forum.cern.ch/uploads/short-url/1DzAKGwpSVFuxVLzsbkJoEXNU0H.root) (25.3 KB) [run372.root](https://root-forum.cern.ch/uploads/short-url/2rCYqfG71sraQ23kP9XYGkUtmDe.root) (45.8 KB) [run373.root](https://root-forum.cern.ch/uploads/short-url/lZ85Jcg1vySpuRRJdM0qk9b9YXR.root) (57.9 KB) [run375.root](https://root-forum.cern.ch/uploads/short-url/cuSx2Mzz2Tal6sxuBM8bYkcFrc4.root) (59.3 KB) [run377.root](https://root-forum.cern.ch/uploads/short-url/aAUUcZgouhlBjTmrP3yqgUO2BOE.root) (58.2 KB) [run379.root](https://root-forum.cern.ch/uploads/short-url/uUDjqwVYI0DB8FSH9WDLmkPCnlo.root) (59.9 KB) [run381.root](https://root-forum.cern.ch/uploads/short-url/oHPBmuN0VtsjYuazTf3oPjBPWeT.root) (59.5 KB) [run383.root](https://root-forum.cern.ch/uploads/short-url/yIJUHdYFCZSprsF8e9Lp2TkGQAA.root) (59.2 KB) [run385.root](https://root-forum.cern.ch/uploads/short-url/uwYUUGgIaHSbrZeOTlHw7MZESkc.root) (66.8 KB) [run386.root](https://root-forum.cern.ch/uploads/short-url/rKxrdsHtiGiuwGpqypOMEDFqdnO.root) (64.1 KB) [run388.root](https://root-forum.cern.ch/uploads/short-url/9Wgb8fUvlvUfF9jvZbibXBbLXGo.root) (59.7 KB) [run389.root](https://root-forum.cern.ch/uploads/short-url/n09XBKJ6p66zt381rj6kybUdCS0.root) (57.6 KB) [run390.root](https://root-forum.cern.ch/uploads/short-url/irprx97rSusephLkA5iJl8Zntu9.root) (58.9 KB) [run391.root](https://root-forum.cern.ch/uploads/short-url/2PxyV8lLugmWJbXkK0YMaovoTub.root) (56.8 KB) [run392.root](https://root-forum.cern.ch/uploads/short-url/7R6OeDO53caJB8rnfUByD0LBPiq.root) (59.3 KB) [run393.root](https://root-forum.cern.ch/uploads/short-url/hhBrV95jvoEMAk59tXwbhBDAiVq.root) (57.8 KB) [run394.root](https://root-forum.cern.ch/uploads/short-url/mCHyIMcc4Qn6hGB2uHPCngHrkTE.root) (56.9 KB) [run395.root](https://root-forum.cern.ch/uploads/short-url/23xcBj0XnpxoQIeCqqAYVRLqUnr.root) (59.1 KB) [run396.root](https://root-forum.cern.ch/uploads/short-url/hngiCs0eWY7n83Fs6PA7lal4Z6L.root) (55.7 KB) [run397.root](https://root-forum.cern.ch/uploads/short-url/bmgViMQP3hwaGEFgRuKmKeQagDJ.root) (61.6 KB) [run398.root](https://root-forum.cern.ch/uploads/short-url/cUSidOVHmdXFgUCk5LiOSqLJq3G.root) (60.2 KB) [run399.root](https://root-forum.cern.ch/uploads/short-url/fGKNaJMP3RKJfGQuQSqpEvnPPL1.root) (59.4 KB) [run400.root](https://root-forum.cern.ch/uploads/short-url/usSW83xfEnIBjTactt0VP98AWME.root) (59.1 KB) [run401.root](https://root-forum.cern.ch/uploads/short-url/b1MYvN92LfQX6qaisvFWr4SNuM8.root) (60.9 KB) [run402.root](https://root-forum.cern.ch/uploads/short-url/bTYNL13XXW91H6bUnOY92rZDkwF.root) (60.5 KB) [run405.root](https://root-forum.cern.ch/uploads/short-url/wNcGHqfBZDSM8rz73bjCEBerMb0.root) (63.8 KB) [run406.root](https://root-forum.cern.ch/uploads/short-url/2RsXOK3SxHYcRCBZlM2z2cl8ASC.root) (59.8 KB) [run407.root](https://root-forum.cern.ch/uploads/short-url/rBQTdOxhK40i9cBEB4Gzzi9yiqT.root) (59.3 KB) [run408.root](https://root-forum.cern.ch/uploads/short-url/sn0pPsuPcVtdePYgptMkFkQZAWq.root) (59.5 KB) [run409.root](https://root-forum.cern.ch/uploads/short-url/gvmcksh4YBNx7USgdY7dtfLDYes.root) (58.2 KB) [run410.root](https://root-forum.cern.ch/uploads/short-url/geYs2d1sxWl06yA4GlmHrt5uBvv.root) (61.1 KB) [run411.root](https://root-forum.cern.ch/uploads/short-url/thQIKimlikB5uR5ycGGcdpISgI8.root) (61.9 KB) [run413.root](https://root-forum.cern.ch/uploads/short-url/AlBPOokahHwxq0XMbtLJCbYJ4L7.root) (61.9 KB) [run414.root](https://root-forum.cern.ch/uploads/short-url/1Ebs5kBeDRllxTbYQu9F5vf8GCg.root) (61.9 KB) [run415.root](https://root-forum.cern.ch/uploads/short-url/AdsnApMOhFqsYYjniPbn1KLuW0J.root) (59.2 KB) [run416.root](https://root-forum.cern.ch/uploads/short-url/iLGClBqae7m9XyOb6YpXDgxlNzd.root) (55.2 KB) [run418.root](https://root-forum.cern.ch/uploads/short-url/vY1skBLt9bqwkedptjCycsvMxs2.root) (57.7 KB) [run419.root](https://root-forum.cern.ch/uploads/short-url/eqm1zWPnKqdp5R0s49E662acVms.root) (56.9 KB) [run420.root](https://root-forum.cern.ch/uploads/short-url/t7eXCda1sm4Wbd1Ffp0FVUOqXCe.root) (54.5 KB) [run421.root](https://root-forum.cern.ch/uploads/short-url/7KXZpDOyb4tfmE5zQw1TgF6pioE.root) (39.4 KB) [run422.root](https://root-forum.cern.ch/uploads/short-url/6nJ4SktcwxTPP7FUTYWtfYPwicy.root) (57.1 KB) [run423.root](https://root-forum.cern.ch/uploads/short-url/Ahu161gOMxmLiQOazWxZvAo4Jru.root) (57.5 KB) [run424.root](https://root-forum.cern.ch/uploads/short-url/5P8N6QzxjQJQCPWK3QFWQpA95db.root) (58.1 KB) [run425.root](https://root-forum.cern.ch/uploads/short-url/bcTUtVqJD3aQZ7X2RNaxqwFuTTk.root) (57.3 KB) [run426.root](https://root-forum.cern.ch/uploads/short-url/3uo0m1sLd58axSBEY0tMs7Ff92v.root) (62.2 KB) [run427.root](https://root-forum.cern.ch/uploads/short-url/7KuK6g9Jgaf74cdHCrZnTvTbQRg.root) (58.3 KB) [run428.root](https://root-forum.cern.ch/uploads/short-url/o4LLOftnreh3G3O0FGb4nUOSnZb.root) (55.2 KB) [run429.root](https://root-forum.cern.ch/uploads/short-url/qQllMaZyeuYcu4WovpffpBbrVuZ.root) (56.8 KB) [run431.root](https://root-forum.cern.ch/uploads/short-url/8b6ZSeqF7REIfOW4PAIyW3wVz78.root) (56.9 KB) [run432.root](https://root-forum.cern.ch/uploads/short-url/dyNiumZQCnGsCsW6AdtYMip23N7.root) (62.2 KB) [run433.root](https://root-forum.cern.ch/uploads/short-url/3FOsspe8AMwzdUhGbcetUOhimb.root) (62.4 KB)  
Here are the different runs.

---

<div class="post-metadata">

**Author:** ![shahina](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shahina/32/19464_2.png) [@shahina](https://root-forum.cern.ch/u/shahina)\
**Post date:** [July 16, 2019, 2:48pm UTC](https://root-forum.cern.ch/t/need-to-remove-the-alpha-background-present-in-the-spectrum/35217/2 "2019-07-16T14:48:29Z")

</div>

These are the root files with trees.  
Uploading: compass\_run\_244.root… [https://drive.google.com/file/d/1ZWEnOGk-xOU3KfKQMwa-ecoJS6oI4mn2/view?usp=sharing](https://drive.google.com/file/d/1ZWEnOGk-xOU3KfKQMwa-ecoJS6oI4mn2/view?usp=sharing)

> **[compass\_run\_324.root](https://drive.google.com/file/d/1D7aZXXu5d40XRZc_dPPSujJUQfgJFotb/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

**Author:** ![shahina](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/shahina/32/19464_2.png) [@shahina](https://root-forum.cern.ch/u/shahina)\
**Post date:** [July 16, 2019, 2:49pm UTC](https://root-forum.cern.ch/t/need-to-remove-the-alpha-background-present-in-the-spectrum/35217/3 "2019-07-16T14:49:14Z")

</div>

> **[compass\_run\_244.root](https://drive.google.com/file/d/1ZWEnOGk-xOU3KfKQMwa-ecoJS6oI4mn2/view?usp=sharing)**
>
> Google Drive file.

---

<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:** [July 22, 2019, 8:27am UTC](https://root-forum.cern.ch/t/need-to-remove-the-alpha-background-present-in-the-spectrum/35217/4 "2019-07-22T08:27:04Z")

</div>

I cleaned up your macro the following way:

```auto
void psdB0C6() {
   gStyle->SetPalette(53);
   TFile *f = new TFile("compass_run_324.root");
   TTree *dataTree = static_cast<TTree*>(f->Get("Data"));

   TFile *cutFile = new TFile("alphaCut_b0c6.root");
   TCutG *alphas = dynamic_cast<TCutG*>(cutFile->Get("alphas"));
   TCanvas *c0 = new TCanvas("c0","c0");
   c0->cd();
   dataTree->Draw("(EnergyShort+rndm(1)-0.5)/(Energy+rndm(7)-0.5):Energy+rndm(3)-0.5>>hist1(1500,0,1500,50,0.9,1.0)","Energy>0 && Board==0 && Channel==6 && Energy>50 && !alphas","colz");
   TCanvas *c1 = new TCanvas("c1","c1");
   c1->cd();

   dataTree->Draw("Energy>>hist2(5000,0,5000)","!alphas && Board==0 && Channel==6");
}

```

It gives me:

```auto
Error in <TFile::TFile>: file alphaCut_b0c6.root does not exist

```
