Skip to content

Commit 03268d3

Browse files
committed
Fix - avoid NaN when RMS around 0 (all counts in same bin)
1 parent d4d2e8a commit 03268d3

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

scripts/JSRoot3DPainter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,9 +2467,9 @@
24672467
res.meanx = stat_sumx1 / stat_sum0;
24682468
res.meany = stat_sumy1 / stat_sum0;
24692469
res.meanz = stat_sumz1 / stat_sum0;
2470-
res.rmsx = Math.sqrt(stat_sumx2 / stat_sum0 - res.meanx * res.meanx);
2471-
res.rmsy = Math.sqrt(stat_sumy2 / stat_sum0 - res.meany * res.meany);
2472-
res.rmsz = Math.sqrt(stat_sumz2 / stat_sum0 - res.meanz * res.meanz);
2470+
res.rmsx = Math.sqrt(Math.max(0, stat_sumx2 / stat_sum0 - res.meanx * res.meanx));
2471+
res.rmsy = Math.sqrt(Math.max(0, stat_sumy2 / stat_sum0 - res.meany * res.meany));
2472+
res.rmsz = Math.sqrt(Math.max(0, stat_sumz2 / stat_sum0 - res.meanz * res.meanz));
24732473
}
24742474

24752475
res.integral = stat_sum0;

scripts/JSRootPainter.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7094,8 +7094,8 @@
70947094
if (stat_sumw > 0) {
70957095
res.meanx = stat_sumwx / stat_sumw;
70967096
res.meany = stat_sumwy / stat_sumw;
7097-
res.rmsx = Math.sqrt(stat_sumwx2 / stat_sumw - res.meanx * res.meanx);
7098-
res.rmsy = Math.sqrt(stat_sumwy2 / stat_sumw - res.meany * res.meany);
7097+
res.rmsx = Math.sqrt(Math.max(0, stat_sumwx2 / stat_sumw - res.meanx * res.meanx));
7098+
res.rmsy = Math.sqrt(Math.max(0, stat_sumwy2 / stat_sumw - res.meany * res.meany));
70997099
}
71007100

71017101
if (xmax!=null) {
@@ -7144,27 +7144,20 @@
71447144
if (print_entries > 0)
71457145
pave.AddText("Entries = " + stat.Format(data.entries,"entries"));
71467146

7147-
if (print_mean > 0) {
7147+
if (print_mean > 0)
71487148
pave.AddText("Mean = " + stat.Format(data.meanx));
7149-
}
71507149

7151-
if (print_rms > 0) {
7150+
if (print_rms > 0)
71527151
pave.AddText("Std Dev = " + stat.Format(data.rmsx));
7153-
}
71547152

7155-
if (print_under > 0) {
7156-
var res = (this.histo.fArray.length > 0) ? this.histo.fArray[0] : 0;
7157-
pave.AddText("Underflow = " + stat.Format(res,"entries"));
7158-
}
7153+
if (print_under > 0)
7154+
pave.AddText("Underflow = " + stat.Format((this.histo.fArray.length > 0) ? this.histo.fArray[0] : 0,"entries"));
71597155

7160-
if (print_over > 0) {
7161-
var res = (this.histo.fArray.length > 0) ? this.histo.fArray[this.histo.fArray.length - 1] : 0;
7162-
pave.AddText("Overflow = " + stat.Format(res,"entries"));
7163-
}
7156+
if (print_over > 0)
7157+
pave.AddText("Overflow = " + stat.Format((this.histo.fArray.length > 0) ? this.histo.fArray[this.histo.fArray.length - 1] : 0,"entries"));
71647158

7165-
if (print_integral > 0) {
7159+
if (print_integral > 0)
71667160
pave.AddText("Integral = " + stat.Format(data.integral,"entries"));
7167-
}
71687161

71697162
if (print_skew > 0)
71707163
pave.AddText("Skew = <not avail>");

scripts/JSRootPainter.more.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,8 +3308,8 @@
33083308
if (stat_sum0 > 0) {
33093309
res.meanx = stat_sumx1 / stat_sum0;
33103310
res.meany = stat_sumy1 / stat_sum0;
3311-
res.rmsx = Math.sqrt(stat_sumx2 / stat_sum0 - res.meanx * res.meanx);
3312-
res.rmsy = Math.sqrt(stat_sumy2 / stat_sum0 - res.meany * res.meany);
3311+
res.rmsx = Math.sqrt(Math.max(0, stat_sumx2 / stat_sum0 - res.meanx * res.meanx));
3312+
res.rmsy = Math.sqrt(Math.max(0, stat_sumy2 / stat_sum0 - res.meany * res.meany));
33133313
}
33143314

33153315
if (res.wmax===null) res.wmax = 0;
@@ -3351,9 +3351,8 @@
33513351
pave.AddText("Std Dev y = " + stat.Format(data.rmsy));
33523352
}
33533353

3354-
if (print_integral > 0) {
3354+
if (print_integral > 0)
33553355
pave.AddText("Integral = " + stat.Format(data.matrix[4],"entries"));
3356-
}
33573356

33583357
if (print_skew > 0) {
33593358
pave.AddText("Skewness x = <undef>");

0 commit comments

Comments
 (0)