Skip to content

Commit c495d62

Browse files
authored
[THRatio] fix update of histograms with bin labels (#2449)
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.
1 parent 69c7893 commit c495d62

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

Modules/Common/include/Common/TH1Ratio.inl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ void TH1Ratio<T>::update()
218218
}
219219

220220
T::Reset();
221-
mHistoNum->GetXaxis()->Copy(*T::GetXaxis());
221+
if (mHistoNum->GetXaxis()->IsVariableBinSize()) {
222+
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXbins()->GetArray());
223+
} else {
224+
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax());
225+
}
222226
T::SetBinsLength();
223227

224228
// Copy bin labels between histograms.

Modules/Common/include/Common/TH2Ratio.inl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,16 @@ void TH2Ratio<T>::update()
277277
}
278278

279279
T::Reset();
280-
mHistoNum->GetXaxis()->Copy(*T::GetXaxis());
281-
mHistoNum->GetYaxis()->Copy(*T::GetYaxis());
280+
if (mHistoNum->GetXaxis()->IsVariableBinSize()) {
281+
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXbins()->GetArray());
282+
} else {
283+
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax());
284+
}
285+
if (mHistoNum->GetYaxis()->IsVariableBinSize()) {
286+
T::GetYaxis()->Set(mHistoNum->GetYaxis()->GetNbins(), mHistoNum->GetYaxis()->GetXbins()->GetArray());
287+
} else {
288+
T::GetYaxis()->Set(mHistoNum->GetYaxis()->GetNbins(), mHistoNum->GetYaxis()->GetXmin(), mHistoNum->GetYaxis()->GetXmax());
289+
}
282290
T::SetBinsLength();
283291

284292
// Copy bin labels between histograms.

0 commit comments

Comments
 (0)