TH1 with line and fill options (root6)

Dear rooters,

The draw options don’t work well with 1D histogram filled using weights.
Without weights everything works as expected.
Can anybody explain this behaviour? Thanks.
Please, see the examples below.
I am using root-6.06.02.

Working macro:

{
  TCanvas *c1 = new TCanvas("c1","c1",600,600);
  
  TH1F *h = new TH1F("h","",20,-4,4);
  Float_t px, py;
  for (Int_t i = 0; i < 100000; i++) {
    gRandom->Rannor(px,py);
    h->Fill(px);
    h->Fill(py);
  }
  
  h->Scale(1./200000);

  h->SetFillStyle(1001);
  h->SetFillColor(kGray);
  h->SetLineWidth(2);
  h->Draw("LF2");
  
  return c1;
}

This macro produces the desired output:


Not working macro:
The only difference is that we assign a weight when filling the histograms

{
  TCanvas *c1 = new TCanvas("c1","c1",600,600);
  
  TH1F *h = new TH1F("h","",20,-4,4);
  Float_t px, py;
  for (Int_t i = 0; i < 100000; i++) {
    gRandom->Rannor(px,py);
    h->Fill(px,1./200000);
    h->Fill(py,1./200000);
  }
  h->SetFillStyle(1001);
  h->SetFillColor(kGray);
  h->SetLineWidth(2);
  h->Draw("LF2");
  
  return c1;
}

This is the wrong output:


h->Draw(“HIST LF2”);

Yes I can.

I your second case “h” contains errors. And in that case the histogram is drawn with error bars. To avoid this the option HIST should be used as explained here:
root.cern.ch/doc/master/classTH … .html#HP01

So your Draw() command becomes :

  h->Draw("LF2 HIST");

You can also keep the drawing option as it is and call:

    h->Sumw2(0);

before Draw()

Hi Couet,
Thanks a lot! it works perfectly.