Fit histograms from root file

Hey,

I have a root file called “mass_T1.root” and I want to redraw it in macro “lognormal_fit.C” and fit it.
My fit function is ready, but I don’t know how to call the histograms root file.
any ideas?
lognormal_fit.C (1.2 KB)

mass_T4.root (31.4 KB)

You have 50 TH1F histograms (each of them with the name “h1” and the title “Mass”) in 50 pads in 1 TCanvas.

{
  TFile *f = TFile::Open("mass_T4.root");
  // f->ls();
  TCanvas *c; f->GetObject("Topology1 4", c);
  // c->ls();
  delete f; // no longer needed
  c->Draw(); // must be drawn first
  for (Int_t i = 1; i <= 50; i++) { // 50 pads
    c->cd(i);
    TH1F *h = ((TH1F*)(gPad->FindObject("h1"))); // histogram in "current" pad
    if (h) {
      h->SetName(h->GetName() + TString("_") + i); // set unique name
      h->SetDirectory(gROOT); // connect to "ROOT Memory"
      h->Print();
      // ... do here whatever you want with this histogram ...
    }
  }
  c->cd(0);
}

still not working complaining about "use of undeclared identifier ‘h1’.

My simple example macro demonstrates how you can access all individual histograms (it just “prints” some of their global quantities).

@Wile_E_Coyote Thank you very much.

@Wile_E_Coyote Hey again, can you help me, please?
I updated my mass_T3.root file, and now the fitting is not working.
lognormal_fit.C (2.7 KB)

mass_T3.root (36.8 KB)

TH1F *h1 = ((TH1F*)(gPad->FindObject(TString("3000") + (i - 1))));

Note: All histograms have now different names so you can comment out the “h1->SetName(...);” line.