Problem setting bin contents

Hi,

I’ve created a class using makeClass in ROOT and I’m having trouble with setting the bin contents. I fill my histogram, loop over the bins and get the bin contents. If a bin content is zero I then set that bin contents to a random number. However, instead of changing the bin contents of empty bins it changes the contents of all the bins.

sim_hwStripPhi->Fill(hwStrip);
for (int j =0; j<sim_hwStripPhi->GetXaxis()->GetNbins(); ++j){
    if(sim_hwStripPhi->GetBinContent(j)==0){
    sim_hwStripPhi->SetBinContent(j, random.Gaus(0,3));
  }
   }

Any ideas as to why this is?

Thanks,
Lisa

A running example would help.