Looping over histogram

Hi,

For defining histogram in loop, I am trying following:

       for n in b[0]:
                print n
                h = ROOT.TH1F("h"+n, n , b[1] , b[2] , b[3] )
                h.SetLineColor(countBranch+1)
                h.SetLineWidth(2)
                t.Draw(n+">>"+"h"+n)
                h.GetEntries()
                if countBranch == 0:
                        h.Draw()
                else:
                        h.Draw("sames")
                countBranch+=1

But, this is showing me only one histogram not all of them, i.e., sames is not working.

Please let me know what I am doing wrong.

with regards,
Ram

The C++ version of this code works fine. It would be something like

void histloop(){
   TH1D *h;
   for (Int_t i=1; i<=5; i++) {
      h = new TH1D(Form("h%d",i),Form("h%d",i),100,-2.,2.);
      h->SetLineColor(i);
      h->FillRandom("gaus", 10000/i);
      if (i==1) h->Draw();
      else      h->Draw("sames");
   }
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.