With RDataFrame and python, how to fill an array in to a tree and save the tree

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Hi experts,
In brief, there is a root file containing many trees. I want to get a tree, slim it by some cuts, then add a new branch in the tree with a pdarray in ready, finally, write this tree into the file.
I chose Rdataframe, since it is convenient to add cuts. But I met problems when filling a branch with a pdfarray and save the tree to the rootfile. This is what I tried:

def array2tree(outArray, outName, outTree):
    outTree.Define(outName,"for(auto w : outArray) return w;")// wrong here!!!
    outTree.Write()//for rdataframe, no Write attribute.!!!
 As you can see above, outArray is a pdArray. outTree is a rdataframe. My doing to fill a branch is not proper...And I also don't know how to write the rdataframe into a file. 
If you have some experience, could you please share it with me? Thanks a lot!

Hi @11111,
writing an RDF into a file is simple, you can use the Snapshot method.

The problem with the Define is that RDF has no notion of the outArray python variable. Declaring a python variable to RDF is possible but not super straightforward, see e.g. the discussion at Add new column to RDataFrame


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.