How to make four vector?

Dear Experts,
I am a beginner to root. I have stored all four momenta(px, py, pz, E) in one root file. They are saved in different branch. Now I want to make a four momentum out of it and save it in another tree. Could you please suggest me how to do that ?

Thanks in Advance


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


assuming px, py, pz and E are floats, a solution could be:

auto createVect = [](float px, float py, float pz, float E) {
  return ROOT::Math::PxPyPzEVector(px, py, pz, E);
ROOT::RDataFrame rdf("yourtree","yourfile.root");
rdf.Define("fourVect", createVect, {"px", "py", "pz", "E"});
rdf.Snapshot("yourNewTree", "yourNewFile");


1 Like

… and at the cost of some runtime if you want to type less:

ROOT::RDataFrame rdf("yourtree","yourfile.root")
    .Define("fourVect", "ROOT::Math::PxPyPzEVector(px, py, pz, E)")
    .Snapshot("yourNewTree", "yourNewFile");


Thanks it is working.

1 Like

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