Applying TCuts to branches and saving them to new TFile

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!

Hi,

I would point you to RDataFrame for columnar datasets manipulation.

Cheers,
Danilo

1 Like

Thanks Danilo,

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

#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;
}
1 Like

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

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