How to slim the branch array in RDataFrame

Hi!

You have to define a new column (=branch) with the slimmed version of the collection. See the following snipplet!

import ROOT

# Make dataframe from part of the original file
filename = "root://eospublic.cern.ch//eos/opendata/cms/derived-data/AOD2NanoAODOutreachTool/Run2012BC_DoubleMuParked_Muons.root"
df = ROOT.RDataFrame("Events", filename).Range(1000)

# Slim down the branches
df2 = df.Define("mask", "Muon_pt > 10")\
        .Define("nSlimmedMuon", "Sum(mask)")\
        .Define("SlimmedMuon_pt", "Muon_pt[mask]")\
        .Define("SlimmedMuon_eta", "Muon_eta[mask]")

# Snapshot the branches to a new file
columns = ROOT.std.vector("string")()
for c in ("nMuon", "Muon_pt", "Muon_eta", "nSlimmedMuon", "SlimmedMuon_pt", "SlimmedMuon_eta"):
    columns.push_back(c)
df2.Snapshot("Events", "slimmed.root", columns)

Is this the solution you are looking for?

Best
Stefan