# Applying TCuts to branches and saving them to new TFile

**URL:** <https://root-forum.cern.ch/t/applying-tcuts-to-branches-and-saving-them-to-new-tfile/33940>\
**Category:** Newbie\
**Created:** [May 7, 2019, 1:19pm UTC](https://root-forum.cern.ch/t/applying-tcuts-to-branches-and-saving-them-to-new-tfile/33940 "2019-05-07T13:19:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unlucky](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/unlucky/32/19553_2.png) [@Unlucky](https://root-forum.cern.ch/u/Unlucky)\
**Post date:** [May 7, 2019, 1:19pm UTC](https://root-forum.cern.ch/t/applying-tcuts-to-branches-and-saving-them-to-new-tfile/33940/1 "2019-05-07T13:19:25Z")

</div>

Hi,

Quite new here.

I have a TTree object stored within a NTuple. I have also generated some appropriate TCut that I would like to apply. Currently I am using -\>Draw(“branch”, TCuts) to produce histograms for different variables.

Is there a way to apply a TCut to a branch and then save the resulting branch to a new TTree without it being a TH1F object?

Any help would be great!

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 7, 2019, 6:25pm UTC](https://root-forum.cern.ch/t/applying-tcuts-to-branches-and-saving-them-to-new-tfile/33940/2 "2019-05-07T18:25:40Z")

</div>

Hi,

I would point you to [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) for columnar datasets manipulation.

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![Unlucky](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/unlucky/32/19553_2.png) [@Unlucky](https://root-forum.cern.ch/u/Unlucky)\
**Post date:** [May 8, 2019, 12:53pm UTC](https://root-forum.cern.ch/t/applying-tcuts-to-branches-and-saving-them-to-new-tfile/33940/3 "2019-05-08T12:53:05Z")

</div>

Thanks Danilo,

this worked as intended. For anyone looking to do the same I made the following macro.

```auto
#include <ROOT/RDataFrame.hxx>

int dataFrame(){
    TCut *filter = new TCut("Some Cut"); //I use TCut's for another part of my code not featured.
    ROOT:RDataFrame d1("Tree", "FilePath"); 
    d1.Filter(filter->GetTitle()) //Do not use ; here! GetTitle converts the cut to string for the FIlter.
      .Snapshot("NewTree","NewFilePath"); //Save the resulting NTuple.
    return 0;
}
```

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 8, 2019, 2:11pm UTC](https://root-forum.cern.ch/t/applying-tcuts-to-branches-and-saving-them-to-new-tfile/33940/4 "2019-05-08T14:11:49Z")

</div>

Great, well done! You are officially not a newbie any more 🙂

---

<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:** [May 8, 2019, 2:17pm UTC](https://root-forum.cern.ch/t/applying-tcuts-to-branches-and-saving-them-to-new-tfile/33940/5 "2019-05-08T14:17:11Z")

</div>

To improve the readability of your posts and ease the copy/pasting of your nice example, it would be nice to follow the tips listed here (in particular the way to post code):  
[https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292/2](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292/2)
