Skip to content

THnSparse::Add() does not preserve weights #11333

@kpedro88

Description

@kpedro88

Describe the bug

When adding two histograms, the weights associated with the bin contents of those histograms should also be added appropriately. THnSparse does not do this. It still reports the weights of the first histogram, ignoring the second.

Expected behavior

The sum of weights should include the weights of both histograms that were added together.

To Reproduce

The script is here: https://www.dropbox.com/s/j5wvixrmdtdx3b5/testTHNadd.C?dl=0
(GitHub apparently does not allow attaching .C files)

root -b -l -q testTHNadd.C

This script shows the bug by comparing two cases:

  1. Filling one histogram twice
  2. Filling two histograms once and adding them

The output is:

THnSparseT<TArrayD> (*0x6c127c0): "hs" "CASE 1"
  8 dimensions, 2 entries in 2 filled bins
    axis 0 "": 10 bins (-5..10), variable bin sizes
    axis 1 "": 10 bins (-10..70), variable bin sizes
    axis 2 "": 5 bins (-1000..3000), variable bin sizes
    axis 3 "": 30 bins (-3..3), variable bin sizes
    axis 4 "": 10 bins (0..5), variable bin sizes
    axis 5 "": 4 bins (0..2), variable bin sizes
    axis 6 "": 18 bins (0..2), variable bin sizes
    axis 7 "": 12 bins (0..5), variable bin sizes
  with error calculation
    Sum(w)=2, Sum(w^2)=2.5
    axis 0: Sum(w*x)=3.5, Sum(w*x^2)=6.5
    axis 1: Sum(w*x)=3.5, Sum(w*x^2)=6.5
    axis 2: Sum(w*x)=3.5, Sum(w*x^2)=6.5
    axis 3: Sum(w*x)=3.5, Sum(w*x^2)=6.5
    axis 4: Sum(w*x)=3.5, Sum(w*x^2)=6.5
    axis 5: Sum(w*x)=3.5, Sum(w*x^2)=6.5
    axis 6: Sum(w*x)=3.5, Sum(w*x^2)=6.5
    axis 7: Sum(w*x)=3.5, Sum(w*x^2)=6.5
  coordinates stored in 1 chunks of 16384 entries
    3.07559e-09 of bins filled using 6.61576e-05 of memory compared to an array
Bin at (5,2,2,21,3,3,10,3) = 0.5 (+/- 0.5)
Bin at (5,2,2,26,5,5,19,5) = 1.5 (+/- 1.5)
2
THnSparseT<TArrayD> (*0x57c3b10): "hs" "CASE 2"
  8 dimensions, 2 entries in 2 filled bins
    axis 0 "": 10 bins (-5..10), variable bin sizes
    axis 1 "": 10 bins (-10..70), variable bin sizes
    axis 2 "": 5 bins (-1000..3000), variable bin sizes
    axis 3 "": 30 bins (-3..3), variable bin sizes
    axis 4 "": 10 bins (0..5), variable bin sizes
    axis 5 "": 4 bins (0..2), variable bin sizes
    axis 6 "": 18 bins (0..2), variable bin sizes
    axis 7 "": 12 bins (0..5), variable bin sizes
  with error calculation
    Sum(w)=0.5, Sum(w^2)=0.25
    axis 0: Sum(w*x)=0.5, Sum(w*x^2)=0.5
    axis 1: Sum(w*x)=0.5, Sum(w*x^2)=0.5
    axis 2: Sum(w*x)=0.5, Sum(w*x^2)=0.5
    axis 3: Sum(w*x)=0.5, Sum(w*x^2)=0.5
    axis 4: Sum(w*x)=0.5, Sum(w*x^2)=0.5
    axis 5: Sum(w*x)=0.5, Sum(w*x^2)=0.5
    axis 6: Sum(w*x)=0.5, Sum(w*x^2)=0.5
    axis 7: Sum(w*x)=0.5, Sum(w*x^2)=0.5
  coordinates stored in 1 chunks of 16384 entries
    3.07559e-09 of bins filled using 6.61576e-05 of memory compared to an array
Bin at (5,2,2,21,3,3,10,3) = 0.5 (+/- 0.5)
Bin at (5,2,2,26,5,5,19,5) = 1.5 (+/- 1.5)
0.5

Setup

  1. ROOT versions: tested 6.06.00, 6.12.07, 6.24.07 (all have the bug)
  2. Scientific Linux 7.9, AlmaLinux 8.6
  3. From CMSSW on cvmfs

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions