RDataFrame Histo2D X and Y Projections


ROOT Version:_ 6.24/02
Platform:Linux/Fedora 34
Compiler:
gcc version 11.3.1 20220421


Hello,
I have generated a 2-D histogram using Histo2D method of RDataFrame. Now, when I try to display the projections with:

auto px = dMultF->ProjectionX("px")->DrawClone();
auto py = dMultF->ProjectionY("py")->SetLineColor(kRed)->DrawClone("same");

I get the following error:

root [0] .x rdf_his2D.cxx+
Info in <TUnixSystem::ACLiC>: creating shared library /home/ajay/./rdf_his2D_cxx.so
In file included from input_line_9:6:
././rdf_his2D.cxx:82:59: error: member reference type 'void' is not a pointer
        auto py = dMultF->ProjectionY("py")->SetLineColor(kRed)->Draw("same");
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ^
Error in <ACLiC>:

However, the following works!

auto px = dMultF->ProjectionX("px")->DrawClone();
auto py = dMultF->ProjectionY("py")->DrawClone("same");

But, then I’m not able to distinguish the two projections. I need the X- and Y-projection histograms in different colors.

Am I missing something?

Regards,

Ajay

use:

auto py = dMultF->ProjectionY("py");
py->SetLineColor(kRed);
py->Draw("same");

Dear @pcanal,

Thank you very much for the suggestion.
I knew that this works. What I want to understand is why the 1st method mentioned in my post doesn’t work?

Regards,

Ajay

The signature of the function SetLineColor is:

void   SetLineColor(Color_t c)

it does not return a pointer to the object it is applied to.

1 Like

@pcanal Thank you!

Dear @pcanal,

I am also trying to draw two 1-D histograms generated with RDataFrame on same canvas using:

auto h_D = dMultF.Histo1D(hmod1D_D, "dTDiff");
auto h_AD = dMultF.Histo1D(hmod1D_AD, "adTDiff");

h_D->DrawClone();
h_AD->SetLineColor(kRed);
h_AD->DrawClone("same");

But, no matter what I do, those are being drawn on two canvas with names c1 & c1_n.

Can you please tell how can I draw both h_D and h_AD on the same canvas?

Many thanks,

Ajay

I solved it as follows:

auto h_D = dMultF.Histo1D(hmod1D_D, "dTDiff");
auto h_AD = dMultF.Histo1D(hmod1D_AD, "adTDiff");

auto c1 = new TCanvas();
c1->cd();
h_D->DrawClone();
h_AD->SetLineColor(kRed);
h_AD->DrawClone("same");

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