impy-project / chromo

Hadronic Interaction Model interface in PYthon
Other
30 stars 7 forks source link

add refill_decay_stack #161

Closed jncots closed 1 year ago

jncots commented 1 year ago

When Pythia8 is used for decay of particles, it is required to put the particle that should be decayed on a event stack . Currently it is only possible to do like this:

for i in range(len(stack)):
    pid = stack.pid[i]
    en = stack.energy[i]
    m = self._pythia.particleData.findParticle(pid).m0
    pz = sqrt((en - m)*(en + m))
    self._pythia.event.append(pid, 91, 0, 0, 0, 0, pz, en, m)

So, to put a lot of particles from vector stack, it is needed to call append for every particle. This is time consuming because of Python for loop and the call to append itself. The time of filling loop is the same as the time required for decay in Pythia, which from calculation point of view are not comparable tasks at all.

The added function self._pythia.refill_decay_stack(stack.pid, stack.energy) accepts 2 numpy arrays with pid and energy, and calls the above loop in C++. These significanly (~40 times for my test cases) reduces the time for filling the event array.

afedynitch commented 1 year ago

To be more generic, I think that there should be a version of the function taking a vector of four-vectors and a vector of PIDs. This is also required for building a replacement for the decay afterburner, since the particles on the event stack have 4-momenta defined with px, py != 0.

Also, there should be a corresponding test ;)

jncots commented 1 year ago
jncots commented 1 year ago

I leave only bare minimum fill function.

jncots commented 1 year ago

@HDembinski, I forgot to mention that Pythia8 fill function is ready. In tests the library is initialized using Pythia8 object in "decay mode" (without loading tables).

afedynitch commented 1 year ago

Didn't this became redundant with #167 ?

HDembinski commented 1 year ago

Didn't this became redundant with #167 ?

No this should be merged first and then #167 should be rebased.

jncots commented 1 year ago

No this should be merged first and then https://github.com/impy-project/chromo/pull/167 should be rebased.

Yes, I was thinking about something like this.