Skip to content

Commit 581896c

Browse files
committed
[treeplayer] Make TTree::Draw independent of histogram registration.
In order for TTree::Draw to work as documented, histograms must be registered to gDirectory. Therefore, make it independent of TH1::AddDirectory and DisableImplicitObjectOwnership. Histograms will unconditionally be registered.
1 parent e06c162 commit 581896c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

tree/treeplayer/src/TSelectorDraw.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ void TSelectorDraw::Begin(TTree *tree)
578578
} else {
579579
hist = new TH1D(hname, htitle.Data(), fNbins[0], fVmin[0], fVmax[0]);
580580
}
581+
hist->SetDirectory(gDirectory);
581582
hist->SetLineColor(fTree->GetLineColor());
582583
hist->SetLineWidth(fTree->GetLineWidth());
583584
hist->SetLineStyle(fTree->GetLineStyle());
@@ -661,6 +662,7 @@ void TSelectorDraw::Begin(TTree *tree)
661662
} else {
662663
hp = new TProfile(hname, htitle.Data(), fNbins[1], fVmin[1], fVmax[1], "");
663664
}
665+
hp->SetDirectory(gDirectory);
664666
if (!hkeep) {
665667
hp->SetBit(kCanDelete);
666668
if (!opt.Contains("goff")) hp->SetDirectory(nullptr);
@@ -689,6 +691,7 @@ void TSelectorDraw::Begin(TTree *tree)
689691
} else {
690692
h2 = new TH2D(hname, htitle.Data(), fNbins[1], fVmin[1], fVmax[1], fNbins[0], fVmin[0], fVmax[0]);
691693
}
694+
h2->SetDirectory(gDirectory);
692695
h2->SetLineColor(fTree->GetLineColor());
693696
h2->SetLineWidth(fTree->GetLineWidth());
694697
h2->SetLineStyle(fTree->GetLineStyle());
@@ -803,6 +806,7 @@ void TSelectorDraw::Begin(TTree *tree)
803806
} else {
804807
hp = new TProfile2D(hname, htitle.Data(), fNbins[2], fVmin[2], fVmax[2], fNbins[1], fVmin[1], fVmax[1], "");
805808
}
809+
hp->SetDirectory(gDirectory);
806810
if (!hkeep) {
807811
hp->SetBit(kCanDelete);
808812
if (!opt.Contains("goff")) hp->SetDirectory(nullptr);
@@ -826,6 +830,7 @@ void TSelectorDraw::Begin(TTree *tree)
826830
h2 = (TH2F*)fOldHistogram;
827831
} else {
828832
h2 = new TH2F(hname, htitle.Data(), fNbins[1], fVmin[1], fVmax[1], fNbins[0], fVmin[0], fVmax[0]);
833+
h2->SetDirectory(gDirectory);
829834
h2->SetLineColor(fTree->GetLineColor());
830835
h2->SetLineWidth(fTree->GetLineWidth());
831836
h2->SetLineStyle(fTree->GetLineStyle());
@@ -859,6 +864,7 @@ void TSelectorDraw::Begin(TTree *tree)
859864
} else {
860865
h3 = new TH3D(hname, htitle.Data(), fNbins[2], fVmin[2], fVmax[2], fNbins[1], fVmin[1], fVmax[1], fNbins[0], fVmin[0], fVmax[0]);
861866
}
867+
h3->SetDirectory(gDirectory);
862868
h3->SetLineColor(fTree->GetLineColor());
863869
h3->SetLineWidth(fTree->GetLineWidth());
864870
h3->SetLineStyle(fTree->GetLineStyle());

0 commit comments

Comments
 (0)