# Filter option in RDataFrame

**URL:** <https://root-forum.cern.ch/t/filter-option-in-rdataframe/59109>\
**Category:** Newbie\
**Tags:** tree, python, rdataframe\
**Created:** [April 24, 2024, 2:38am UTC](https://root-forum.cern.ch/t/filter-option-in-rdataframe/59109 "2024-04-24T02:38:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cristian\_Andres\_Alle](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/cristian_andres_alle/32/21806_2.png) [@Cristian\_Andres\_Alle](https://root-forum.cern.ch/u/Cristian_Andres_Alle)\
**Post date:** [April 24, 2024, 2:38am UTC](https://root-forum.cern.ch/t/filter-option-in-rdataframe/59109/1 "2024-04-24T02:38:47Z")

</div>

Hello everyone, im here trying to learn about RDataFrame. i don’t quite understand the filter process for example if i define this:  
df\_Mass3 = ROOT.RDataFrame(“DecayTree”,str(path)+“/”+“SG\_Bc2HNplusleptons\_Mass3\_tree.root”)

# Filter apllied

df\_muon1\_Mass3\_PTcut = df\_Mass3.Filter(“mu2\_PT \> 5”, “Muons1 Events for Mass3 with Pt \> 5 GeV”)  
df\_muon2\_Mass3\_PTcut = df\_Mass3.Filter(“mu1\_PT \> 5”, “Muons2 Events for Mass3 with Pt \> 5 GeV”)

# Filter report

report1 = df\_muon1\_Mass3\_PTcut.Report()  
report2 = df\_muon2\_Mass3\_PTcut.Report()  
i get:  
Muons1 Events for Mass3 with Pt \> 5 GeV: pass=130 all=3530 – eff=3.68 % cumulative eff=3.68 %  
Muons2 Events for Mass3 with Pt \> 5 GeV: pass=589 all=3530 – eff=16.69 % cumulative eff=16.69 %  
Thing i corroborate it passing the RDataframe to a csv file. But if i use the filter condition like this:

df\_mu1\_Mass3\_PTcut = df\_Mass3.Filter(“mu2\_PT \> 5”, “Muons2 Events for Mass3 with Pt \> 5 GeV”)  
df\_mu2\_Mass3\_PTcut = df\_mu1\_Mass3\_PTcut.Filter(“mu1\_PT \> 5”, “Muons1 Events for Mass3 with Pt \> 5 GeV”)

# Solicitar el informe de flujo de corte

report = df\_mu2\_Mass3\_PTcut.Report()

# Imprimir el informe de flujo de corte

report.Print()  
i get: Muons2 Events for Mass3 with Pt \> 5 GeV: pass=130 all=3530 – eff=3.68 % cumulative eff=3.68 %  
Muons1 Events for Mass3 with Pt \> 5 GeV: pass=43 all=130 – eff=33.08 % cumulative eff=1.22 %  
Wish is different from the first one. Even though mu1\_PT and mu2\_PT are two different branches with the same entries 3533, but the second filer applied to the first give me all=130 . That are the mu1\_PT that pass the first condition. And i do not understand that.  
Thank you very much before hand. I hope its not an to basic of a question.  
Sorry to bother.

ROOT Version: 6.30/04

---

<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:** [April 24, 2024, 5:28am UTC](https://root-forum.cern.ch/t/filter-option-in-rdataframe/59109/2 "2024-04-24T05:28:47Z")

</div>

Hi Christian,

Welcome to the ROOT community!  
The argument of Filter, when one uses a string to select entries, it’s the cut. Therefore, if you have a column called “mu2\_PT” and “mu1\_PT”, your filters would simply look like:

```auto
df_muon1_Mass3_PTcut = df_Mass3.Filter(“mu2_PT > 5”)
df_muon2_Mass3_PTcut = df_Mass3.Filter(“mu1_PT > 5”)

```

I hope this helps!

Cheers,  
D
