Wrong scattering method called when `Scattering` container is used in python
Closed this issue · 2 comments
Inside python, I can create multiple scattering objects like this:
highland = pp.make_multiple_scattering("highland", particle, medium, cross, True)
highland_integral = pp.make_multiple_scattering("highlandintegral", particle, medium, cross, True)
If I call CalculateTheta0
on either of these objects, the correct CalculateTheta0
function will be called:
### This calls Highland::CalculateTheta0
highland.CalculateTheta0(100, 1e6, 1e5)
### This calls HighlandIntegral::CalculateTheta0
highland_integral.CalculateTheta0(100, 1e6, 1e5)
However, I can also put a multiple scattering inside a Scattering
container:
container_highland = pp.scattering.Scattering(highland)
container_highland_integral = pp.scattering.Scattering(highland_integral)
If I call the multiple_scattering
function on these containers, in both cases, the CalculateTheta0
function from Highland
is called
### This calls `Highland::CalculateTheta0`
container_highland.multiple_scattering(100, 1e6, 1e5, [0.3, 0.6, 0.4, 0.6])
### This calls `Highland::CalculateTheta0` as well, although it should call `HighlandIntegral::CalculateTheta0`
container_highland.multiple_scattering(100, 1e6, 1e5, [0.3, 0.6, 0.4, 0.6])
This means that if someone initializes a Propagator using these methods, they will use highland
scattering even if they called make_multiple_scattering
with highlandintegral
. This happend to @pascalgutjahr.
Interestingly, this issue doesn't occur when I write the code in C++, which means that something is probably wrong within the pybindings. It is very likely that this is due to the inheritance structure of the code (HighlandIntegral
inherits from Highland
, Highland
inherits from multiple_scattering::Parametrization
.
Found the bug. This issue has been caused by a missing clone function of HighlandIntegral
, which means that the clone function of Highland
has been called instead. The issue only happend when the clone function has been used, which means that the problem didn't occur for every user (but only for those using a specific code structure where clone function has been involved, as in the example above).
Opened PR #285 to fix this.