Access particle charge using PDG-ID scikit-hep particle package in RDataFrame


I have a Monte Carlo simulation with all truth particles and their PDG-ID.
I would like to know the charge of the particle for the PDG-ID.
In do this there is a handy packages called particle that allows to get the particle charge for a given PDG-ID,
e.g. for pion
pid = PDGID(211)
print ('charge= ',three_charge(211))

Now I would like to use the three_charge function using my array in the tree something like
The resulting charge would then be a RVec

The questions can be posed more general:
If I would like to have a function in a python package having as input an integer and output an integer,
how can I run it on an RVec such that a vector is returned ?

I have made an example that you can execute like

Before running you need to install the particle package via
python3 -m pip install particle --user
This package should be predefined somewhere on lxplus, but I do not know here. Anybody knows ?

Here it my example code (775 Bytes)


Please read tips for efficient and successful posting and posting code

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

Hi Tancredi,
see my reply at Running fast-jet and fast-jet contrib in RDataFrame - #3 by eguiraud regarding Python functions and RDF.

We expect to make this more nice and flexible in the future, but basically the requirement for injecting pure Python code in the RDF event loop is that it must be compilable to machine code by numba (with nopython=True).