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

hepmc2root seems to be missing particles #2

Open
sbinet opened this issue Sep 23, 2022 · 7 comments
Open

hepmc2root seems to be missing particles #2

sbinet opened this issue Sep 23, 2022 · 7 comments

Comments

@sbinet
Copy link

sbinet commented Sep 23, 2022

trying to convert this file:

HepMC::Version 2.06.09
HepMC::IO_GenEvent-START_EVENT_LISTING
E 1 0 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 20 -3 4 0 0 0 0
U GEV MM
F 0 0 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0 0
V -1 0 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 1 1 0
P 1 2212 0.0000000000000000e+00 0.0000000000000000e+00 7.0000000000000000e+03 7.0000000000000000e+03 0.0000000000000000e+00 3 0.0000000000000000e+00 0.0000000000000000e+00 -1 0
P 3 1 7.5000000000000000e-01 -1.5690000000000000e+00 3.2191000000000003e+01 3.2238000000000000e+01 0.0000000000000000e+00 3 0.0000000000000000e+00 0.0000000000000000e+00 -3 0
V -2 0 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 1 1 0
P 2 2212 0.0000000000000000e+00 0.0000000000000000e+00 -7.0000000000000000e+03 7.0000000000000000e+03 0.0000000000000000e+00 3 0.0000000000000000e+00 0.0000000000000000e+00 -2 0
P 4 -2 -3.0470000000000002e+00 -1.9000000000000000e+01 -5.4628999999999998e+01 5.7920000000000002e+01 0.0000000000000000e+00 3 0.0000000000000000e+00 0.0000000000000000e+00 -3 0
V -3 0 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0 2 0
P 5 22 -3.8130000000000002e+00 1.1300000000000000e-01 -1.8330000000000000e+00 4.2329999999999997e+00 0.0000000000000000e+00 1 0.0000000000000000e+00 0.0000000000000000e+00 0 0
P 6 -24 1.5169999999999999e+00 -2.0680000000000000e+01 -2.0605000000000000e+01 8.5924999999999997e+01 0.0000000000000000e+00 3 0.0000000000000000e+00 0.0000000000000000e+00 -4 0
V -4 0 1.2000000000000000e-01 -2.9999999999999999e-01 5.0000000000000003e-02 4.0000000000000001e-03 0 2 0
P 7 1 -2.4449999999999998e+00 2.8815999999999999e+01 6.0819999999999999e+00 2.9552000000000000e+01 0.0000000000000000e+00 1 0.0000000000000000e+00 0.0000000000000000e+00 0 0
P 8 -2 3.9620000000000002e+00 -4.9497999999999998e+01 -2.6687000000000001e+01 5.6372999999999998e+01 0.0000000000000000e+00 1 0.0000000000000000e+00 0.0000000000000000e+00 0 0
HepMC::IO_GenEvent-END_EVENT_LISTING

(also available here)

which, AFAIK, is a valid HepMC file, will lead to:

$> root-dump ./small.root
>>> file[./small.root]
key[000]: Events;1 "created: Fri Sep 23 15:50:55 2022 HepMC 2.06.09" (TTree)
[000][Event_number]: 1
[000][Event_numberMP]: 0
[000][Event_scale]: 0
[000][Event_alphaQCD]: 0
[000][Event_alphaQED]: 0
[000][Event_barcodeSPV]: -3
[000][Event_numberV]: 4
[000][Event_barcodeBP1]: 0
[000][Event_barcodeBP2]: 0
[000][Event_numberP]: 6
[000][Xsection_value]: 0
[000][Xsection_error]: 0
[000][PDF_parton1]: 0
[000][PDF_parton2]: 0
[000][PDF_x1]: 0
[000][PDF_x2]: 0
[000][PDF_Q2]: 0
[000][PDF_x1f]: 0
[000][PDF_x2f]: 0
[000][PDF_id1]: 0
[000][PDF_id2]: 0
[000][Particle_x]: [0 0 0 0 0.12 0.12]
[000][Particle_y]: [0 0 0 0 -0.3 -0.3]
[000][Particle_z]: [0 0 0 0 0.05 0.05]
[000][Particle_ctau]: [0 0 0 0 0.004 0.004]
[000][Particle_barcode]: [1 2 5 6 7 8]
[000][Particle_pid]: [2212 2212 22 -24 1 -2]
[000][Particle_px]: [0 0 -3.813 1.517 -2.445 3.962]
[000][Particle_py]: [0 0 0.113 -20.68 28.816 -49.498]
[000][Particle_pz]: [7000 -7000 -1.833 -20.605 6.082 -26.687]
[000][Particle_energy]: [7000 7000 4.233 85.925 29.552 56.373]
[000][Particle_mass]: [0 0 0 0 0 0]
[000][Particle_status]: [3 3 1 3 1 1]
[000][Particle_d1]: [0 1 -1 4 -1 -1]
[000][Particle_d2]: [-1 -1 -1 5 -1 -1]

whereas:

$> go-hepmc-dump ./small.hepmc
________________________________________________________________________________
GenEvent: #0001 ID=   20 SignalProcessGenVertex Barcode: -3
 Momentum units:     GEV     Position units:      MM
 Entries this event: 4 vertices, 8 particles.
 Beam Particles are not defined.
 RndmState(0)=
 Wgts(0)=
 EventScale 0.00000 [energy] 	alphaQCD=0.00000000	alphaQED=0.00000000
                                    GenParticle Legend
        Barcode   PDG ID      ( Px,       Py,       Pz,     E ) Stat  DecayVtx
________________________________________________________________________________
GenVertex:       -1 ID:    0 (X,cT):0
 I: 1         1     2212 +0.00e+00,+0.00e+00,+7.00e+03,+7.00e+03   3        -1
 O: 1         3        1 +7.50e-01,-1.57e+00,+3.22e+01,+3.22e+01   3        -3
GenVertex:       -2 ID:    0 (X,cT):0
 I: 1         2     2212 +0.00e+00,+0.00e+00,-7.00e+03,+7.00e+03   3        -2
 O: 1         4       -2 -3.05e+00,-1.90e+01,-5.46e+01,+5.79e+01   3        -3
GenVertex:       -3 ID:    0 (X,cT):0
 I: 2         3        1 +7.50e-01,-1.57e+00,+3.22e+01,+3.22e+01   3        -3
              4       -2 -3.05e+00,-1.90e+01,-5.46e+01,+5.79e+01   3        -3
 O: 2         5       22 -3.81e+00,+1.13e-01,-1.83e+00,+4.23e+00   1
              6      -24 +1.52e+00,-2.07e+01,-2.06e+01,+8.59e+01   3        -4
Vertex:       -4 ID:    0 (X,cT)=+1.20e-01,-3.00e-01,+5.00e-02,+4.00e-03
 I: 1         6      -24 +1.52e+00,-2.07e+01,-2.06e+01,+8.59e+01   3        -4
 O: 2         7        1 -2.44e+00,+2.88e+01,+6.08e+00,+2.96e+01   1
              8       -2 +3.96e+00,-4.95e+01,-2.67e+01,+5.64e+01   1
________________________________________________________________________________

ie: it's missing the particles with barcodes 3 and 4.
it seems to me this is because hepmc2root.py doesn't handle the case for initial vertices with incoming particles, as it's only considering out-going particles.

(also: what are the Particle_d1 and Particle_d2 fields meant to represent ? I suspect they are meant to represent the barcodes of the production- and end-vertex of a given particle, but the logic escapes me.)

@hbprosper
Copy link
Owner

hbprosper commented Sep 23, 2022 via email

@sbinet
Copy link
Author

sbinet commented Oct 17, 2022

ping ?

in the meantime, I've implemented my own, keeping track of heavy ion stuff, vertices, and all:

@quarkquartet
Copy link

I have the same issue here. It seems the algorithm to add particles from a vertex does not work properly.

The current algorithm first read the number of outgoing particles from a V, as nout. Then use a for loop with range nout to read the next lines.

However, sometimes the hepmc also put the incoming particle under the vertex line.
Then problem happens.

For example,

HepMC::Version 2.06.09
HepMC::IO_GenEvent-START_EVENT_LISTING
E 0 -1 0 0 0 102 0 5 1 2 0 1 1.0000000000000000e+00
N 1 "Weight" 
U GEV MM
C 8.7032886702708842e+04 8.7032886702708842e+04
F 113 2212 1.0000000000000000e+00 1.0000000000000000e+00 0 0 0 0 0
V -1 0 0 0 0 0 1 2 0
P 1 13 0 0 1.5999996511238496e+02 1.6000000000000000e+02 1.0566000000000000e-01 4 0 0 -1 0
P 3 22 -3.2616654153318225e-01 3.0528576067331020e-01 7.1638470879528043e+01 7.1637313241915919e+01 -6.0452083925406741e-01 13 0 0 -3 0
P 7 13 3.2616654153318225e-01 -3.0528576067331020e-01 8.8361494232856870e+01 8.8362686758084081e+01 1.0566000000000000e-01 1 0 0 0 0
V -2 0 0 0 0 0 1 1 0
P 2 2212 0 0 1.9539925233402755e-14 9.3827000000000038e-01 9.3827000000000005e-01 4 0 0 -2 0
P 4 2212 0 0 1.9539925233402755e-14 9.3827000000000038e-01 9.3827000000000005e-01 13 0 0 -4 0
V -3 0 0 0 0 0 0 1 0
P 5 113 -3.1754411052517639e-01 3.1581346606800575e-01 7.1622182966074845e+01 7.1637073216438296e+01 1.3901776087831381e+00 2 0 0 -5 0
V -4 0 0 0 0 0 0 1 0
P 6 2212 -8.6224310080059152e-03 -1.0527705394695441e-02 1.6287913453233216e-02 9.3851002547761397e-01 9.3827000000000005e-01 1 0 0 0 0
V -5 0 0 0 0 0 0 2 0
P 8 211 2.4434629835581997e-01 6.6984929124606496e-01 4.6703417290922935e+01 4.6709068387428601e+01 1.3957000000000000e-01 1 0 0 0 0
P 9 -211 -5.6189040888099639e-01 -3.5403582517805920e-01 2.4918765675151906e+01 2.4928004829009694e+01 1.3957000000000000e-01 1 0 0 0 0

Look at this event. The particle 1 goes into vertex -1, which produces particle 3 and 7. Current algorithm cannot read it correctly.

@sbinet
Copy link
Author

sbinet commented Oct 29, 2022

FYI, I've checked that hepmc2root from Go-HEP properly handles this case as well :)

@quarkquartet
Copy link

quarkquartet commented Oct 29, 2022

FYI, I've checked that hepmc2root from Go-HEP properly handles this case as well :)

I saw it. Thanks for your work. it seems your algorithm is nice. But I'm not familiar with Go. Could you tell me how to install and run that script? Say, I'm going to convert test.hepmc to test.root.

I tried to download that github repository. But do not know how to run the hepmc2root.

@sbinet
Copy link
Author

sbinet commented Oct 29, 2022

I'll try to cut a new release shortly (by the end of next week) so one would just need to download the binary from https://go-hep.org/dist.

in the meantime, once Go has been installed, it should just be a matter of:

$> hepmc2root
bash: hepmc2root: command not found

$> go install -v go-hep.org/x/hep/cmd/hepmc2root@main
go: downloading go-hep.org/x/hep v0.32.2-0.20221003155224-87e7095463a7
go: downloading gonum.org/v1/gonum v0.12.0
[...]
$> hepmc2root -h
Usage of hepmc2root:
  -o string
    	path to output ROOT file name (default "out.root")
  -t string
    	name of the output tree (default "tree")

$> hepmc2root ./testdata/test.hepmc 
$> root-ls -t ./out.root 
=== [./out.root] ===
version: 62600
  TTree                tree                   tree    (entries=6)
    Event_processID    "Event_processID/I"    TBranch
    Event_nbr          "Event_nbr/I"          TBranch
    Event_mpi          "Event_mpi/I"          TBranch
  [...]

(I'll add some more documentation, as it is a bit terse ATM)

@quarkquartet
Copy link

@sbinet @hbprosper
I have created a pull request #4
It runs pretty well on my side.

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

3 participants