TLines and histograms

Dear all,

The setup : a framework and a module; the latter adds lines to a histo which is then handled by the framework. The framework might, or might not, reset the histogram.

The problem : if the framework resets the histo, the lines are removed and deleted. When the module gets back control of the histos, he needs to update the lines but they might not be there anymore.

Question : is it possible to tell the histo that he should not own the lines ? Ideally it should not touch them but at least I would like that it does not delete them. I tried to do h->GetListOfFunctions()->SetOwner(false) and
line->ResetBit(kCanDelete) to no avail.

Thank you,
Barth

Hi Barth,

I can reproduce what you describe here with the following macro.
I confirm that the two solutions you tried (commented) do not work.

{
   TH1F *h = new TH1F("h","h",100,-4,4);
   h->FillRandom("gaus",10000);
   TLine *line = new TLine(-3.180516,325.5566,3.309456,83.87704);
   h->GetListOfFunctions()->Add(line);
   //h->GetListOfFunctions()->SetOwner(kFALSE);
   //line->SetBit(TObject::kCanDelete,false);

   TCanvas *C = new TCanvas("C","C",800,1000);
   C->Divide(1,2);
   C->cd(1);
   h->Draw();

   C->cd(2);
   gPad->DrawFrame(-4.,0.,4.,350);
   line->Draw();

   delete h;
}

I have no solution for the time being…

Cheers,
Olivier

Hi Olivier,
Thank you for the quick confirmation. I will work around for the time being.
Cheers,
Barth

Hi Barth,

I think I found an easy workaround. In my example do:

h->GetListOfFunctions()->Clear();

Before:

delete h;

Hi,

Good idea, thank you.

I will use this. Do you want to create a JIRA issue any ways ?
Cheers,
Barth

I am not sure it is a bug or an issue as the TH1 destructor is implemented this way explicitly.
So I do not think a Jira report is needed unless you think another behavior would be better,
and in that case you can submit a request for new developments.