As such, all particles were sharing the same children_count default array, which was initialized only once. This means when children_count was modified for one TruthParticle instance, it simultaneously modified all TruthParticles.children_counts.
Since similar initializations happen in other places, all such mutable array initializations will make a separate copy (except for tensor-like arguments such as .points and .depositions, in which it will point to the same empty array (which is ok to be shared).
This PR fixes a bad initialization bug for
TruthParticle.children_count
.In python classes, when a class
__init__
function contains a parameter with a default mutable array-like argument, all instances of the same class will share the same reference to a single instance of the object declared for the default argument (see https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument).As such, all particles were sharing the same
children_count
default array, which was initialized only once. This means whenchildren_count
was modified for oneTruthParticle
instance, it simultaneously modified allTruthParticles.children_counts
.Since similar initializations happen in other places, all such mutable array initializations will make a separate copy (except for tensor-like arguments such as
.points
and.depositions
, in which it will point to the same empty array (which is ok to be shared).