Substracting two variables in root

Please provide the following information:

ROOT Version (e.g. 6.12/02):
Platform, compiler (e.g. CentOS 7.3, gcc6.2):

I have two variables in my tree. Now I want to substract them. Can you please provide a macro for me ?

Thanks in Advance

It depends on what you want to do with them.
The simplest thing to try would be: tree->Draw("var1 - var2");

Thank you very much.

I can substract them with that command. Can you please tell me how do I save ā€œvar1 - var2ā€ inside another tree ?

Thanks in Advance

You can use RDataFrame for that:

ROOT::RDataFrame df("input.root");
df.Define("diff", "var1 - var2").Snapshot("diffTree", "output.root", {{"diff"}});

or if you want to keep the original ones, use:

...Snapshot("diffTree", "output.root", {{"var1", "var2", "diff"}});

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