TLegend color


I tried to create a legend in a histrogram plot. However the line in the legend has not the same color of line of the histogram.

Here the part of the code for my plot

        auto RoHigh = ordered_up.Filter("Bcharge == 1").Histo1D({"","",26u, 2e6, 15e6},"roHigh");
        auto RoHigh_neg = ordered_up.Filter("Bcharge == -1").Histo1D({"","",26u, 2e6, 15e6},"roHigh");

        //histogram K+K- (High)

        auto legend2 = new TLegend(0.1,0.7,0.48,0.9);
        legend2->SetHeader("#rho_{high} histogram");
        legend2->AddEntry(RoHigh.GetPtr(),"#rho_{high} from B+", "l");
        legend2->AddEntry(RoHigh_neg.GetPtr(),"#rho_{high} from B-", "l");

_ROOT Version: ROOT 6.26/10
_Platform: linuxx8664gcc

Is RoHigh.GetPtr() valid? can you try using the name of the object instead?
Do you have a small reproducer we can run?

Unfortunatelly it’s quite hard to have a small reproducer. Are you referring to the name of the Histo1d?

I tried to pass in AddEntry directly RoHigh and RoHigh_neg without .GetPtr(), but there is an error:

In file included from input_line_8:1:
/home/commodo98/programmi/CMProject/analysis/dalitz.cpp:321:11: error: no matching member function for call to 'AddEntry'
        legend2->AddEntry(RoHigh,"#rho_{high} from B+", "l");
/home/commodo98/root/builddir/include/TLegend.h:36:20: note: candidate function not viable: no known conversion from 'ROOT::RDF::RResultPtr<TH1D>' to 'const TObject *' for 1st argument
   TLegendEntry   *AddEntry(const TObject* obj, const char* label = "", Option_t* option = "lpf" );
/home/commodo98/root/builddir/include/TLegend.h:37:20: note: candidate function not viable: no known conversion from 'ROOT::RDF::RResultPtr<TH1D>' to 'const char *' for 1st argument
   TLegendEntry   *AddEntry(const char *name, const char* label = "", Option_t* option = "lpf" );

However, if I assign a name to the histrogram and pass that to AddEntry it’s working!
My question now is, why are there problems if I try to pass the pointer?

Yes, that’s what I mean. It could be the pointer vanished. Hard to tell without a reproducer.

And is it possible that also for other functions, like the Add() for adding two histograms (which requires the pointer to pass) there is the same problem?

It looks like this:

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