-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Description
Calling cross_section is much slower than accessing the inel_or_prod_cross_section since cross_sections uses the temporary_kinematics context manager which resets the kinematic to the initial one. For all models the reset to the old kinematics also recalculates the cross section of the old kinematics, hence its way faster to set the kinematics by hand and access the already computed once.
In [2]: from chromo.kinematics import FixedTarget
...: from chromo.models import Sibyll23e
In [3]: kin_init = FixedTarget(100, 2212, 'O16')
...: kin = FixedTarget(80, 2212, 'O16')
...:
...:
...: sib = Sibyll23e(kin_init)
In [4]: def cs(mod, kin):
...: return mod.cross_section(kin).prod
...:
...: def cs_fast(mod, kin):
...: mod.kinematics = kin
...: return mod._inel_or_prod_cross_section
...:
In [5]: %timeit cs(sib, kin)
992 μs ± 252 ns per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
In [6]: %timeit cs_fast(sib, kin)
332 μs ± 219 ns per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
In [8]: cs(sib, kin) == cs_fast(sib, kin)
Out[8]: TrueMetadata
Metadata
Assignees
Labels
No labels