ROOT Version: 6.26/04 Platform: macOS Monterey 12.4 Compiler: Not Provided
I have a set of TH1 histograms with TStrings for bin labels, and I’m trying to get the labels from the bins after they’ve been sorted and filtered as I need. I can get a THashList setup by:
THashList hash = hist->GetXaxis()->GetLabels();
but I’m unsure how to access and store the individual elements of that Hash List. Ideally I’d like to access it by bin number. There is more code below for some further context
hist->LabelsDeflate();
hist->GetXaxis()->LabelsOption(">");
hist->GetXaxis()->SetRangeUser(0,9); // Only want top 10 contributing reactions
hist->Scale(100./hist->Integral()); // Normalize top 10 bins
for(Int_t bin=1; bin<10; bin++) {
if(hist->GetBinContent(bin) > 0.1) {
THashList hash = hist->GetXaxis()->GetLabels();
// Find bin label and store into an array
}
}
For reference doing the command below outputs something like:
hist->GetXaxis()->GetLabels()->Print();
// Output
Collection name='THashList', class='THashList', size=205
TObjString = 3#gamma#pi^{#plus}#pi^{#minus}p[#pi^{0},#omega]
// Hundreds more strings here