scikit-hep / pyBumpHunter

Python implementation of the BumpHunter algorithm used by HEP community.
BSD 3-Clause "New" or "Revised" License
17 stars 9 forks source link

Missing channel index when plotting bumps in multiple channels #19

Open franciscosili opened 3 months ago

franciscosili commented 3 months ago

Hi! I encountered an issue when running the BumpHunter with multiple channels:

When calling the plot_bump method of the BumpHunter1D class, in line 1680, the index of the channel is missing from the self.bins attribute, which is used to build the histogram : H = np.histogram(data[chan], bins=self.bins, range=self.rang) This results in ValueError's. I leave the error message for reference:

  File "/afs/cern.ch/user/f/fsili/.local/lib/python3.10/site-packages/pyBumpHunter/bumphunter_1dim.py", line 1680, in plot_bump
    H = np.histogram(data[chan], bins=self.bins, range=self.rang)
  File "<__array_function__ internals>", line 180, in histogram
  File "/cvmfs/atlas.cern.ch/repo/sw/software/0.4/StatAnalysis/0.4.0/InstallArea/x86_64-el9-gcc13-opt/lib/python3.10/site-packages/numpy-1.23.5-py3.10-linux-x86_64.egg/numpy/lib/histograms.py", line 793, in histogram
    bin_edges, uniform_bins = _get_bin_edges(a, bins, range, weights)
  File "/cvmfs/atlas.cern.ch/repo/sw/software/0.4/StatAnalysis/0.4.0/InstallArea/x86_64-el9-gcc13-opt/lib/python3.10/site-packages/numpy-1.23.5-py3.10-linux-x86_64.egg/numpy/lib/histograms.py", line 430, in _get_bin_edges
    if np.any(bin_edges[:-1] > bin_edges[1:]):
ValueError: operands could not be broadcast together with shapes (85,) (119,)

I believe this could be fixed by changing:

H = np.histogram(data[chan], bins=self.bins, range=self.rang)

to

H = np.histogram(data[chan], bins=self.bins[chan], range=self.rang)

Thanks a lot! Cheers!