Try:
{
TFile *f = TFile::Open("ppepembbar_4FNS_LO_all_results.root");
if ((!f) || f->IsZombie()) { delete f; return; }
gROOT->cd();
TProfile *hp = 0;
for (int i = 0; i < 199; i++) {
TH1 *h; f->GetObject(TString::Format("AFB_Mll_%d", i), h);
if (h) {
TAxis *a = h->GetXaxis();
if (!hp) {
// ... assuming all "AFB_Mll_*" are "akin" fix bin sizes histograms ...
hp = new TProfile("AFB_Mll_profile", "AFB Mll profile;X;Y",
a->GetNbins(), a->GetXmin(), a->GetXmax(),
""); // e.g., "", "s", "i" or "g"
if (! hp->GetSumw2N()) hp->Sumw2(kTRUE);
}
for (int j = 0; j <= a->GetNbins() + 1; j++)
hp->Fill(a->GetBinCenter(j), h->GetBinContent(j), h->GetBinError(j));
delete h;
}
}
delete f;
if (hp) hp->Draw();
}