Writing data from one root file to another

I have a plot E1 vs E2 from a root file and I make two cuts “cut1” and “cut2” on the plot. Now I want to write the value of E1 from two different cuts in a separate root file in two different leaves. How can I do this task? Please suggest.

Hi,
TDataFrame, available since ROOT v6.12 (but getting a face-lift in the upcoming v6.14), offers a simple interface to do these kinds of data manipulation. The Filter method lets you perform cuts, the Define method lets you define new quantities (e.g. “E1cut1” and “E1cut2”) and the Snapshot method lets you save quantities in a new TTree.

For example:

TDataFrame d("tree", "f.root");
d.Filter("E1 > 0").Snapshot("newtree", "f2.root", "E1");

saves the variable “E1” to a new TTree “newtree” for all events in which “E1 > 0”.
Cuts can be expressed either as proper c++ functions (or lambdas) or as strings containing valid c++ using branch names as variables, as in this example.

You can check out the tutorials for more hands-on examples, both in python and C++.

I would write a more ad-hoc example for your use-case but there are a couple things I don’t think I understand:

  • you say you apply a cut to a plot. do you mean you apply a cut to the tree, and then plot a certain quantity for all the events that pass the cut?
  • two different cuts will produce in general different numbers of valid entries, so you can’t put all the "E1"s that pass a cut in one leaf and all the "E1"s that pass another cut in another: leaves must have the same number of entries
  • what’s the type of “E1” and “E2”? Are they arrays?

Hope this helps!
Enrico

Hi,

I am new to root, and your suggestion regarding the available features are helpful.
Let me elaborate the condition I have:

E1 and E2 are two leaves in a tree and after plotting E1 vs E2, I make 2 cults in different regions of the plot. Now I want to write all the value of E1 under “cut1”, and under “cut2” in different leaves in another TTree. But you say it can’t be done because leaves must have the same number of entries. Is there any other way? Those regions of cut represent 2 different particles and I want to get their individual data.

Thank You.

Kabita

Hi Kabita,
can you post the code you have and maybe we work from there?

Cheer,
Enrico

Ok, I am still working on the code. I will post it as soon as I have formed the basic structure.