Skip to content

Commit

Permalink
[THRatio] fix update of histograms with bin labels (#2449)
Browse files Browse the repository at this point in the history
A direct copy of the axis objects from the numerator to the ratio histograms,
that was introduced in a recent commit, breaks the preservation of the
bin labels that are eventually set in the ratio histogram.

The code in this commit replaces the copy with an explicit update of the
number and limits of the bins, such that it works also if the numerator
is filled with `TH1::kCanRebin` set, and therefore the axis range can
change after the histogram creation.
  • Loading branch information
aferrero2707 authored Oct 7, 2024
1 parent 69c7893 commit c495d62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Modules/Common/include/Common/TH1Ratio.inl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ void TH1Ratio<T>::update()
}

T::Reset();
mHistoNum->GetXaxis()->Copy(*T::GetXaxis());
if (mHistoNum->GetXaxis()->IsVariableBinSize()) {
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXbins()->GetArray());
} else {
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax());
}
T::SetBinsLength();

// Copy bin labels between histograms.
Expand Down
12 changes: 10 additions & 2 deletions Modules/Common/include/Common/TH2Ratio.inl
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,16 @@ void TH2Ratio<T>::update()
}

T::Reset();
mHistoNum->GetXaxis()->Copy(*T::GetXaxis());
mHistoNum->GetYaxis()->Copy(*T::GetYaxis());
if (mHistoNum->GetXaxis()->IsVariableBinSize()) {
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXbins()->GetArray());
} else {
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax());
}
if (mHistoNum->GetYaxis()->IsVariableBinSize()) {
T::GetYaxis()->Set(mHistoNum->GetYaxis()->GetNbins(), mHistoNum->GetYaxis()->GetXbins()->GetArray());
} else {
T::GetYaxis()->Set(mHistoNum->GetYaxis()->GetNbins(), mHistoNum->GetYaxis()->GetXmin(), mHistoNum->GetYaxis()->GetXmax());
}
T::SetBinsLength();

// Copy bin labels between histograms.
Expand Down

0 comments on commit c495d62

Please sign in to comment.