Hi all,
The simplest example I could create which represents the problem is the following:
import ROOT
vectors = '''
#include "Math/Vector3D.h"
#include "Math/Vector4D.h"
#include "TFile.h"
#include "TTree.h"
#include <vector>
using namespace ROOT::Math;
using namespace ROOT::VecOps;
RVec <double> getArrX(const RVec<XYZTVector>& vec){
auto getItemX = [](const XYZTVector& item) { return item.X(); };
return Map(vec, getItemX);
}
'''
ROOT.gInterpreter.Declare(vectors)
if __name__ == "__main__":
ROOT.RDataFrame(1).Define("vec", "XYZVector(10, 10, 10)").Snapshot("Particle", "f1.root")
ROOT.RDataFrame(1).Define("vec", "XYZVector(20, 20, 20)").Snapshot("Cluster", "f2.root")
ROOT.RDataFrame(1).Define("vec", "std::vector<XYZTVector>{XYZTVector(30, 30, 30, 30)}").Snapshot("Vertex", "f3.root")
ch1 = ROOT.TChain("Particle")
ch1.Add("f1.root")
ch2 = ROOT.TChain("Cluster")
ch2.Add("f2.root")
ch3 = ROOT.TChain("Vertex")
ch3.Add("f3.root")
ch1.AddFriend(ch2, "cluster")
ch1.AddFriend(ch3, "vertex")
df = ROOT.RDataFrame(ch1)
print(df.Define("particle_z", "vec.Z()").Histo1D("particle_z").GetMean())
print(df.Define("cluster_z", "cluster.vec.Z()").Histo1D("cluster_z").GetMean())
print(df.Define("vertex_z", "getArrX(vertex.vec)").Histo1D("vertex_z").GetMean())
I would expect it to output:
10
20
30
However the error occurs:
$ python test.py
10.0
20.0
input_line_99:2:142: error: no matching function for call to 'getArrX'
auto lambda4 = [](ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<Double32_t>,ROOT::Math::DefaultCoordinateSystemTag>& var0){return getArrX(var0)
^~~~~~~
input_line_42:10:15: note: candidate function not viable: no known conversion from 'ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<Double32_t>, ROOT::Math::DefaultCoordinateSystemTag>' (aka
'DisplacementVector3D<Cartesian3D<double>, ROOT::Math::DefaultCoordinateSystemTag>') to 'const RVec<ROOT::Math::XYZTVector>' (aka 'const RVec<LorentzVector<PxPyPzE4D<double> > >') for 1st argument
RVec <double> getArrX(const RVec<XYZTVector>& vec){
^
What I have tried so far:
- Commenting “Cluster” friend tree results in the correct output
$python test.py
10.0
30.0
meaning this is something to do with identical branch names
- I have tried to make more simple example with int, vector<int> instead of XYZVector, vector<XYZTVector> and everything seem to work
I spent 3 days understanding what is wrong.
Why is this happening no matter different tree names/tree aliases/file names…
cheers,
Bohdan
ROOT Version: 6.22/00
Platform: CentOS 7.9.2009
Python: 3.7.6