PyRoot & RDataFrame: adding resulting Histograms

Hi,
I am trying to add two histograms created with RDataFrame in PyRoot:

from ROOT import RDataFrame, TH1, TH1D

frame1 = RDataFrame('sig_ma1000_mDM10_MH600_tb1_st035','test/files/sig_ma1000_mDM10_MH600_tb1_st035.root')
frame2 = RDataFrame('sig_ma150_mDM10_MH1000_tb1_st070','test/files/sig_ma150_mDM10_MH1000_tb1_st070.root') 

histo1 = frame1.Histo1D('jet0_pt')
histo2 = frame2.Histo1D('jet0_pt')

histo1.Add(histo2)

Unfortunately, I get following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: none of the 3 overloaded methods succeeded. Full details:
  bool TH1::Add(TF1* h1, double c1 = 1, const char* option = "") =>
    could not convert argument 1
  bool TH1::Add(const TH1* h1, double c1 = 1) =>
    could not convert argument 1
  bool TH1::Add(const TH1* h, const TH1* h2, double c1 = 1, double c2 = 1) =>
    takes at least 2 arguments (1 given)

Does anybody understand, what I am doing wrong?

Cheers,
Ben


ROOT Version: 6.14
Platform: CC7
Compiler: GCC 4.8


Hi Ben

can you try

from ROOT import RDataFrame, TH1, TH1D

frame1 = RDataFrame('sig_ma1000_mDM10_MH600_tb1_st035','test/files/sig_ma1000_mDM10_MH600_tb1_st035.root')
frame2 = RDataFrame('sig_ma150_mDM10_MH1000_tb1_st070','test/files/sig_ma150_mDM10_MH1000_tb1_st070.root') 

histo1 = frame1.Histo1D('jet0_pt')
histo2 = frame2.Histo1D('jet0_pt')

histo1.Add(histo2.GetPtr())

The point here is that the return type of actions is a RResultPtr, which is a smart pointer. This is nicely treated in PyROOT, you almost don’t notice it except when you bump into interfaces requiring types for which no automatic conversion works: at that point you need to be explicit.

Cheers,
D

1 Like

Thank you, that worked!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.