mctools / mcpl

Monte Carlo Particle Lists
https://mctools.github.io/mcpl/
Other
28 stars 13 forks source link

pymcpltool --stats errors with universal weight files with >1e4 particles #49

Closed tkittel closed 5 years ago

tkittel commented 5 years ago

I am not sure when this was introduced, but for instance the file at:

http://tkittel.web.cern.ch/tkittel/mcplissue49.mcpl.gz

Gives an error when combining the last block with the others:

$> pymcpltool --stats mcplissue49.mcpl.gz
Traceback (most recent call last):
  File "/home/thki/dgdepfixer_install/venv/bin/pymcpltool", line 10, in <module>
    sys.exit(main())
  File "/home/thki/dgdepfixer_install/venv/lib64/python3.5/site-packages/mcpl.py", line 1641, in main
    app_pymcpltool()
  File "/home/thki/dgdepfixer_install/venv/lib64/python3.5/site-packages/mcpl.py", line 1141, in app_pymcpltool
    dump_stats(f)
  File "/home/thki/dgdepfixer_install/venv/lib64/python3.5/site-packages/mcpl.py", line 1472, in dump_stats
    stats = collect_stats(stats,bin_data=False)
  File "/home/thki/dgdepfixer_install/venv/lib64/python3.5/site-packages/mcpl.py", line 1350, in collect_stats
    sc.add_data(getattr(pb,s),vals_weight)
  File "/home/thki/dgdepfixer_install/venv/lib64/python3.5/site-packages/mcpl.py", line 1260, in add_data
    new_sumwx = a.sum() if w is None else (a*w).sum()
ValueError: operands could not be broadcast together with shapes (17,) (10000,) 

(note: the default particle block size is 10000 and this file has 10017 particles)

tkittel commented 5 years ago

So this only affects files with universal weights. Consider the two files, differing only in whether or not they use universal weights (uw):

tkittel commented 5 years ago

I figured out a fix, I guess we need a 1.3.1 release in the near future.

tkittel commented 5 years ago

The issue actually concerns all variables not stored on-disk in a given file, but inferred from meta-data (universal pdgcode, polarisation, ...).

tkittel commented 5 years ago

I am assuming this was not discovered before since my testing now used a newer Numpy version than previously. Probably Numpy was previously more tolerant of multiplying arrays of unequal length.

tkittel commented 5 years ago

Fixed in MCPL 1.3.1.