Dear all,
I would like to perform event mixing using RDataFrame.
What I have in mind is to take some quantities from the i-th
row and some from the (i+1)-th
row to create a fictitious “mixed” event.
In the example below, I want x
from the i-th row and y
from the (i+1)-th row
# example from
# https://root-forum.cern.ch/t/saving-pandas-dataframe-as-ttree-with-rdataframe/42720/2
# Create a pandas dataframe
import pandas as pd
import numpy as np
df = pd.DataFrame()
df['x'] = np.array([1, 2, 3])
df['y'] = np.array([4, 5, 6])
# Convert data to a dictionary with numpy arrays
data = {key: df[key].values for key in df.columns}
# Write the dictionary with numpy arrays to a ROOT file
import ROOT
rdf = ROOT.RDF.MakeNumpyDataFrame(data)
# Again, have a look!
rdf.Display().Print()
this returns
+-----+---+---+
| Row | x | y |
+-----+---+---+
| 0 | 1 | 4 |
+-----+---+---+
| 1 | 2 | 5 |
+-----+---+---+
| 2 | 3 | 6 |
+-----+---+---+
my goal is to obtain
+-----+---+---+
| Row | x | y |
+-----+---+---+
| 0 | 1 | 5 |
+-----+---+---+
| 1 | 2 | 6 |
+-----+---+---+
| 2 | 3 | 4 |
+-----+---+---+
(in case, I wouldn’t care if the first/last rows are clipped because they are at the boundaries of the row range)
Do you have any suggestions how to achieve this in a smart way?
Thanks!
Riccardo