-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: ```python 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.
- Loading branch information
Showing
3 changed files
with
149 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import chromo | ||
from chromo.common import EventData | ||
from .util import run_in_separate_process | ||
import pytest | ||
import sys | ||
import numpy as np | ||
|
||
if sys.platform == "win32": | ||
pytest.skip("Pythia8 does not run on windows", allow_module_level=True) | ||
|
||
|
||
def init_events(nevents): | ||
evt_kin = chromo.kinematics.FixedTarget(1e7, "p", "p") | ||
evt_gen = chromo.models.Sibyll23d(evt_kin) | ||
|
||
events = [] | ||
for event in evt_gen(nevents): | ||
event = event.final_state() | ||
events.append(event.copy()) | ||
|
||
return events | ||
|
||
|
||
def get_pythia_event(pythia, evt_kin): | ||
pevent = pythia.event | ||
res = EventData( | ||
("pythia", "pythia"), | ||
evt_kin, | ||
0, | ||
0.0, | ||
(0, 0), | ||
pevent.pid(), | ||
pevent.status(), | ||
pythia.charge(), | ||
pevent.px(), | ||
pevent.py(), | ||
pevent.pz(), | ||
pevent.en(), | ||
pevent.m(), | ||
pevent.vx(), | ||
pevent.vy(), | ||
pevent.vz(), | ||
pevent.vt(), | ||
np.maximum(pevent.mothers() - 1, -1), | ||
np.maximum(pevent.daughters() - 1, -1), | ||
) | ||
return res.copy() | ||
|
||
|
||
def append_result(pythia, event): | ||
pythia.event.reset() | ||
for i in range(len(event)): | ||
pythia.event.append( | ||
event.pid[i], | ||
91, | ||
0, | ||
0, | ||
event.px[i], | ||
event.py[i], | ||
event.pz[i], | ||
event.en[i], | ||
event.m[i], | ||
) | ||
return get_pythia_event(pythia, event.kin) | ||
|
||
|
||
def fill_result(pythia, event): | ||
pythia.event.fill( | ||
event.pid, event.status + 90, event.px, event.py, event.pz, event.en, event.m | ||
) | ||
return get_pythia_event(pythia, event.kin) | ||
|
||
|
||
def run_event_fill(): | ||
""" | ||
Tests that `pythia.event.fill` and `pythia.event.append` | ||
produce the same event stack | ||
`pythia.event.fill` is optimized version of `pythia.event.append` | ||
`pythia.event.fill` accepts numpy arrays instead of scalar value | ||
as for `pythia.event.append`. | ||
`pythia.event.fill` resets event stack by `pythia.event.reset()` | ||
and uses `pythia.event.append` in C++ loop | ||
""" | ||
|
||
config = ["ProcessLevel:all = off" "ParticleDecays:tau0Max = 1e100"] | ||
pythia8 = chromo.models.Pythia8(None, seed=1, config=config, banner=False) | ||
pythia = pythia8._pythia | ||
|
||
for event in init_events(10): | ||
fill_res = fill_result(pythia, event) | ||
append_res = append_result(pythia, event) | ||
assert fill_res == append_res | ||
|
||
|
||
def test_event_fill(): | ||
run_in_separate_process(run_event_fill) |