@@ -367,13 +367,29 @@ def dict_charge_conjugates(self) -> dict[str, str]:
367
367
self ._check_parsing ()
368
368
return get_charge_conjugate_defs (self ._parsed_dec_file )
369
369
370
+ def get_particle_property_definitions (self ) -> dict [str , dict [str , float ]]:
371
+ """
372
+ Return a dictionary of all particle property definitions
373
+ in the input parsed file, of the form "Particle <PARTICLE> <MASS> <WIDTH>",
374
+ as {'PARTICLE1': {'mass': MASS1, 'width': WIDTH1},
375
+ 'PARTICLE2': {'mass': MASS2, 'width': WIDTH2}, ...}.
376
+
377
+ Note
378
+ ----
379
+ Particles are often defined via aliases and post-processing may be needed
380
+ to match the mass and width to the actual particle.
381
+ """
382
+ self ._check_parsing ()
383
+ return get_particle_property_definitions (self ._parsed_dec_file )
384
+
370
385
def dict_pythia_definitions (self ) -> dict [str , str | float ]:
371
386
"""
372
- Return a dictionary of all Pythia definitions in the input parsed file,
373
- of the form
374
- "PythiaBothParam <NAME>=<LABEL>"
387
+ Return a dictionary of all Pythia definitions, of type
388
+ <PYTHIA_DEF> = "PythiaBothParam" or "PythiaAliasParam",
389
+ in the input parsed file, of the form
390
+ "<PYTHIA_DEF> <NAME>=<LABEL>"
375
391
or
376
- "PythiaBothParam <NAME>=<NUMBER>",
392
+ "<PYTHIA_DEF> <NAME>=<NUMBER>",
377
393
as {'NAME1': 'LABEL1', 'NAME2': VALUE2, ...}.
378
394
"""
379
395
self ._check_parsing ()
@@ -1500,30 +1516,52 @@ def get_charge_conjugate_defs(parsed_file: Tree) -> dict[str, str]:
1500
1516
) from err
1501
1517
1502
1518
1519
+ def get_particle_property_definitions (parsed_file : Tree ) -> dict [str , dict [str , float ]]:
1520
+ """
1521
+ Return a dictionary of all particle property definitions
1522
+ in the input parsed file, of the form "Particle <PARTICLE> <MASS> <WIDTH>",
1523
+ as {'PARTICLE1': {'mass': MASS1, 'width': WIDTH1},
1524
+ 'PARTICLE2': {'mass': MASS2, 'width': WIDTH2}, ...}.
1525
+
1526
+ Parameters
1527
+ ----------
1528
+ parsed_file: Lark Tree instance
1529
+ Input parsed file.
1530
+ """
1531
+ try :
1532
+ return {
1533
+ tree .children [0 ]
1534
+ .children [0 ]
1535
+ .value : {
1536
+ "mass" : float (tree .children [1 ].children [0 ].value ),
1537
+ "width" : float (tree .children [2 ].children [0 ].value ),
1538
+ }
1539
+ for tree in parsed_file .find_data ("particle_def" )
1540
+ }
1541
+ except Exception as err :
1542
+ raise RuntimeError (
1543
+ "Input parsed file does not seem to have the expected structure."
1544
+ ) from err
1545
+
1546
+
1503
1547
def get_pythia_definitions (parsed_file : Tree ) -> dict [str , str | float ]:
1504
1548
"""
1505
- Return a dictionary of all Pythia definitions in the input parsed file,
1506
- of the form
1507
- "PythiaBothParam <NAME>=<LABEL>"
1549
+ Return a dictionary of all Pythia definitions, of type
1550
+ <PYTHIA_DEF> = "PythiaBothParam" or "PythiaAliasParam",
1551
+ in the input parsed file, of the form
1552
+ "<PYTHIA_DEF> <NAME>=<LABEL>"
1508
1553
or
1509
- "PythiaBothParam <NAME>=<NUMBER>",
1554
+ "<PYTHIA_DEF> <NAME>=<NUMBER>",
1510
1555
as {'NAME1': 'LABEL1', 'NAME2': VALUE2, ...}.
1511
1556
1512
1557
Parameters
1513
1558
----------
1514
1559
parsed_file: Lark Tree instance
1515
1560
Input parsed file.
1516
1561
"""
1517
-
1518
- def str_or_float (arg : str ) -> str | float :
1519
- try :
1520
- return float (arg )
1521
- except Exception :
1522
- return arg
1523
-
1524
1562
try :
1525
1563
return {
1526
- f"{ tree .children [0 ].value } :{ tree .children [1 ].value } " : str_or_float (
1564
+ f"{ tree .children [0 ].value } :{ tree .children [1 ].value } " : _str_or_float (
1527
1565
tree .children [2 ].value
1528
1566
)
1529
1567
for tree in parsed_file .find_data ("pythia_def" )
@@ -1613,8 +1651,8 @@ def get_lineshape_definitions(
1613
1651
try :
1614
1652
d = []
1615
1653
for tree in parsed_file .find_data ("setlspw" ):
1616
- particles = [p .children [ 0 ]. value for p in tree .children [:- 1 ]]
1617
- val = int (tree .children [3 ].children [ 0 ]. value )
1654
+ particles = [p .value for p in tree .children [:- 1 ]]
1655
+ val = int (tree .children [3 ].value )
1618
1656
d .append ((particles , val ))
1619
1657
return d
1620
1658
except Exception as err :
@@ -1651,3 +1689,10 @@ def get_global_photos_flag(parsed_file: Tree) -> int:
1651
1689
end_item = tree [- 1 ] # Use the last one if several are present !
1652
1690
val = end_item .children [0 ].data
1653
1691
return PhotosEnum .yes if val == "yes" else PhotosEnum .no
1692
+
1693
+
1694
+ def _str_or_float (arg : str ) -> str | float :
1695
+ try :
1696
+ return float (arg )
1697
+ except Exception :
1698
+ return arg
0 commit comments