Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THRatio: fix division of histograms with different bin labels #2112

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Modules/Common/include/Common/TH1Ratio.inl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ void TH1Ratio<T>::update()
return;
}

const char* name = this->GetName();
const char* title = this->GetTitle();

T::Reset();
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax());
T::SetBinsLength();
Expand All @@ -164,6 +161,12 @@ void TH1Ratio<T>::update()
double norm = (entries > 0) ? 1.0 / entries : 0;
T::Scale(norm);
} else {
if (T::GetXaxis()->GetLabels()) {
// copy bin labels to denominator before dividing, otherwise we get a warning
for (int bin = 1; bin <= T::GetXaxis()->GetNbins(); bin++) {
mHistoDen->GetXaxis()->SetBinLabel(bin, T::GetXaxis()->GetBinLabel(bin));
}
}
T::Divide(mHistoDen);
}
}
Expand Down
14 changes: 11 additions & 3 deletions Modules/Common/include/Common/TH2Ratio.inl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ void TH2Ratio<T>::update()
return;
}

const char* name = this->GetName();
const char* title = this->GetTitle();

T::Reset();
T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax());
T::GetYaxis()->Set(mHistoNum->GetYaxis()->GetNbins(), mHistoNum->GetYaxis()->GetXmin(), mHistoNum->GetYaxis()->GetXmax());
Expand All @@ -165,6 +162,17 @@ void TH2Ratio<T>::update()
double norm = (entries > 0) ? 1.0 / entries : 0;
T::Scale(norm);
} else {
// copy bin labels to denominator before dividing, otherwise we get a warning
if (T::GetXaxis()->GetLabels()) {
for (int bin = 1; bin <= T::GetXaxis()->GetNbins(); bin++) {
mHistoDen->GetXaxis()->SetBinLabel(bin, T::GetXaxis()->GetBinLabel(bin));
}
}
if (T::GetYaxis()->GetLabels()) {
for (int bin = 1; bin <= T::GetYaxis()->GetNbins(); bin++) {
mHistoDen->GetYaxis()->SetBinLabel(bin, T::GetYaxis()->GetBinLabel(bin));
}
}
T::Divide(mHistoDen);
}
}
Expand Down
Loading