Not plotting zero bins in TH2 with negative entries

If the error is 0 it is considered as empty, so bin #2 will be consider as empty

@couet
But thatā€™s what we want to avoid, I think. There are measurable quantities that can be zero (e.g. temperature in C or F, speed, voltage, current, depth,ā€¦), so some bins may be filled with zero and thus provide information that we donā€™t want to hide; Iā€™d say that the drawn, filled ā€œzeroā€ bins should include both cases of the final bin content being zero: because it was filled with zeros, or because positives and negatives cancelled out. Since ROOT currently sets the error to zero whether the bin was not filled or filled with zero, I suppose this probably requires some careful changes (to avoid affecting other methods!) to somehow signal whether a bin has been filled or not (independently of the value).

Yes, but I do not see how we can identify a bin which has been filled with 0 like bin #2 in your example.

One way that wouldnā€™t touch the current error values could be to introduce and associate a ā€œfill flagā€ to each bin (just like each bin has errors), with default value 0 for all bins (on creation the of the histo), and then change it to 1 whenever the bin is filled (Fill or SetBinContent); this, as I mentioned, will mean changes in other places, but I suppose only in places (like in Draw) where we need to know if the bin was filled or not. Then, there may also be some changes needed in Adding histos and othersā€¦ as I said, will require some care.

Thatā€™s certainly an option, but it would require significant modifications to the histogram data structure. I believe @moneta might have some insights to share at this stage of the discussion.

1 Like

Creating an extra fill flag introduces some overhead (loss of performance, lots of work, etc.).
A hacky workaround could be just to define an extra ā€œfill functionā€ FillWithError(x, error) that calls Fill(x); SetBinError(1e-12); that way the user that needs this functionality can ensure that these bins are drawn.
Other options (maybe for RHist?) could be to default-construct the errors as NaN and only set them to 0 if fill was called, so Draw-bins only if error!=NaN but this needs extra-care in AddBinContent, etc.

I wonder if the special cases that would have to be introduced are worth the possible gains.
@dastudillo has a very good point but in these cases, if you wanted to make a bin seen in the plots, you could always use SetBinError(bin, 1.).

ā€¦ if my PR is applied because right now a bin with 0 content (what ever the errors are) is not drawn.

I have a ROOT Version: 6.32.00 installed via conda on my local.
Is there a simple way to apply this PR ?

you compile ROOT yourself ? Note the PR is still not applied on master. The PR is merged in master.