Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill_genevent_from_hepevt not adding particles #16

Closed
janTOffermann opened this issue Jul 5, 2021 · 2 comments
Closed

fill_genevent_from_hepevt not adding particles #16

janTOffermann opened this issue Jul 5, 2021 · 2 comments

Comments

@janTOffermann
Copy link

Hi there! Thanks for creating this easy-to-install alternative to building HepMC3.

I'm currently trying to use fill_genevent_from_hepevt to fill a blank GenEvent with some particles (I'm using numpythia to generate some events to be written to a HepMC3 file for Delphes usage, but I want to do some filtering before writing since HepMC3 files are very large and I'm not interested in most of the particles in each event).

However, I can't seem to get the filling of the GenEvent to work. Here's a minimal working example demonstrating the issue:

import numpy as np
import pyhepmc_ng as hep

evt = hep.GenEvent()
evt.clear()

print(evt) # Check how things look after calling "clear".

# Get some dummy data -- here, just a single particle.
event_number = 1
p = np.array([1.,1.,1.,4.]).reshape(1,-1)
m = np.array([1.])
v = np.array([1.,1.,1.,0.]).reshape(1,-1)
pid = np.array([5])
parents = np.array([1,1]).reshape(1,-1)
status = np.array([1])

hep.fill_genevent_from_hepevt(evt,
                              event_number = event_number,
                              p = p,
                              m = m,
                              v = v,
                              pid = pid,
                              parents = parents,
                              status = status
                             )

print(evt) # See if anything changed.

And this is what I get as output:

GenEvent: #0
 Momentum units: GEV Position units: MM
 Entries in this event: 0 vertices, 0 particles, 0 weights.
 Position offset: 0, 0, 0, 0
                                    GenParticle Legend
         ID    PDG ID   ( px,       py,       pz,     E )   Stat ProdVtx
________________________________________________________________________
________________________________________________________________________

________________________________________________________________________
GenEvent: #1
 Momentum units: GEV Position units: MM
 Entries in this event: 0 vertices, 0 particles, 0 weights.
 Position offset: 0, 0, 0, 0
                                    GenParticle Legend
         ID    PDG ID   ( px,       py,       pz,     E )   Stat ProdVtx
________________________________________________________________________
________________________________________________________________________

It looks like I am modifying the event_number (trying different numbers works as well), but there doesn't appear to be any information on the particle that I've tried to add.

I think the issue might lie with HEPEVT.to_genevent(), which is called at the end of fill_genevent_from_hepevt, as I tried calling this on a HEPEVT that I created (mimicking the global buffer) and similarly didn't see any particles added to the GenEvent I passed as an argument.

I see that GenEvent has methods for explicitly adding particles and vertices, which might let me circumvent this issue for now, but it would certainly be nice to have a vectorized approach instead of adding them on the Python side of things one-by-one (I also see that there is a 2nd unused version of fill_genevent_from_hepevt that does not call HEPEVT.to_genevent).

@janTOffermann
Copy link
Author

I forgot to include some version information in the above post, here it is in case it's helpful:

OS: Ubuntu 18.04.5 LTS
Python: 3.8.10
pyhepmc: 0.4.3 (via pypi)

@HDembinski
Copy link
Member

Hi, this seems to be a bug that was introduced at some point in HepMC3. I am currently preparing a new version with the latest HepMC3 where this issue is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants