I try to use a little complex function to define a new column using ROOT.RDataFrame,
Now I can achieve it, but it’s a little complex, could you please help me to simplify it ?
The related codes are shown below
By the way , it x >10 ,I want to use fake_hist to interpolate, but if x<10, I want to use fake_hist_2 to interpolate, Is there any simple way to achieve it?
Many thanks in advance!
Let me start by saying that we are working hard to pythonise better the interface of RDataFrame: the analysis interface is very powerful, and we are aware that the experience of our users could greatly benefits if some obstacles are removed when it comes to C++ and Python interplay.
This example should show how you can simplify your code: the workaround consists in leveraging a feature of ROOT which allows to access names of objects as if they were pointers.
I hope it helps, perhaps as a start!
FF_file_name = args.FF_name
f1 = ROOT.TFile.Open(FF_file_name)
fake_hist = f1.fake_factor_hist
# Workaround: make the histos known to the interpreter
ROOT.gInterpreter.ProcessLine("auto fh1 = fake_hist")
rdf_filtered = rdf_filtered.Define('fakefactor',f"fh1->Interpolate(ph_pt)")
input_line_81:2:24: error: variable ‘fake_hist_temp’ declared with deduced type ‘auto’ cannot appear in its own initializer auto fake_hist_temp = fake_hist_temp
I used TH1F* to substitute auto, it seems OK.
/eos/home-z/zgao/H_to_Zy/samples/root_to_parquet_2_test.py:95: DeprecationWarning: The attribute syntax for TNetXNGFile is deprecated and will be removed in ROOT 6.34. Please use TNetXNGFile[“fake_factor_hist”] instead of TNetXNGFile.fake_factor_hist
fake_hist_temp = fake_file_1.fake_factor_hist