Skip to content

Fix getRatio calculation if AlphaNumeric bin labels are set

Johannes Junggeburth requested to merge fix_ratio_with_alpha_numeric into master

Hi @goblirsc,

this MR addresses a funny bug of the TH1 class familiy. Namely, if you set a bin label and then later access either the overflow or underflow bin, ROOT simply extends the range of the histogram axis by doubling the number of bins.

std::shared_ptr<TH1D> my_memory_destroyer= std::make_shared<TH1D>("Laugh", "dummy;", 10,0,10); 
my_memory_destroyer->GetXaxis()->SetBinLabel(1, "Peter");
my_memory_destroyer->GetXaxis()->SetBinLabel(2, "Stefan");
my_memory_destroyer->GetXaxis()->SetBinLabel(3, "Alfred");
for (int = 0 ; i < 1000; ++1000){
     my_memory_destroyer->SetBinContent(my_memory_destroyer->GetNbinsX()+1, 
my_memory_destroyer->GetBinContent(my_memory_destroyer->GetNbinsX()+1) +1);
}

If you wanna watch your memory die within a glimpse of time. This MR add the isAlphaNumeric method to check whether some bin labels are set and uses them then as a guard to prevent the overflow access in the post-processing.

Anyway this MR is not that urugent to disrupt your holidays:

image

Edited by Johannes Junggeburth

Merge request reports