VecOps Construct with ROOT::Math::LorentzVector example

Hello,
Following the question in Creating a column of std::vector<ROOT::Math::PtEtaPhiEVector> with RDataFrame
I switched to ROOT 6.22.02, but the Construct example doesn’t work for me:
(https://root.cern/doc/v622/namespaceROOT_1_1VecOps.html#a0d8ddd546ccd87fe25dc7626f9d8b67d)
The order of parameters is probably swapped, but I get
using namespace ROOT::VecOps
RVec<float> etas {.3f, 2.2f, 1.32f};
RVec<float> phis {.1f, 3.02f, 2.2f};
RVec<float> pts {15.5f, 34.32f, 12.95f};
RVec<float> masses {105.65f, 105.65f, 105.65f};
Construct<ROOT::Math::PtEtaPhiMVector> fourVects(etas, phis, pts, masses);

ROOT_prompt_5:1:39: error: expected ‘;’ after expression
Construct<ROOT::Math::PtEtaPhiMVector> fourVects(etas, phis, pts, masses);
^
;
ROOT_prompt_5:1:40: error: use of undeclared identifier ‘fourVects’
Construct<ROOT::Math::PtEtaPhiMVector> fourVects(etas, phis, pts, masses);

Second question, is it possible to call directly a method from T on RVec<T> - something like
RVec<float> rapidities = fourVects.Rapidity();
or what would be the best option?

Thanks,
Zdenek

ROOT Version: 6.22.02
Platform: MacOS 10.15
Compiler: clang12


Ok, this seems to be the correct way?
RVec<ROOT::Math::PtEtaPhiMVector> fourVects =
Construct<ROOT::Math::PtEtaPhiMVector>(pts,etas, phis, masses);

To answer my second question:
ROOT::RVec<float> rapidities = ROOT::VecOps::Map(fourVects, [](ROOT::Math::PtEtaPhiMVector x){return x.Rapidity();})

Could somebody please help if this is better code-wise/performance-wise over ‘old-style’ loop?
ROOT::RVec<float> rapidities(fourVects.size());
for (int i =0; i<fourVects.size(); ++i)
{
rapidities[i] = fourVects[i].Rapidity();
//or push_back instead of rapidities[i]
}

@eguiraud could you please suggest something here? Thanks!!!

Hi,
about your first question: you are absolutely right, the code snippet in the docs is wrong (thank you very much for pointing it out), the correct line is:

auto fourVects = Construct<ROOT::Math::PtEtaPhiMVector>(pts, etas, phis, masses);

as you mention. PRs #6475 and #6476 fix the docs for ROOT version 6.22 and master.

About the second question: again you are right, VecOps::Map is how you can do something (e.g. calling a method) on each element of an RVec. It’s not more performant than a for loop, it should compile to exactly the same code.

Cheers,
Enrico