hepi.util
Collection of utility functions for the hepi package.
Module Contents
Classes
Functions
|
Convert a list of objects into a dictionary of lists. |
|
Convert a dict of list`s to a `pandas.DataFrame. |
|
Get the latex name of a particle. |
|
Transforms a PDG id to it's left-right partner. |
|
Creates a sha256 hash from the objects string representation. |
|
Converts a LHAPDF name to the sets id. |
- hepi.util.LD2DL(l: List, actual_dict=False) dict[source]
Convert a list of objects into a dictionary of lists.
The values of each object are first converted to a dict through the __dict__ attribute.
- Parameters
l (List) – list of objects.
actual_dict (bool) – objects are already dicts
- Returns
dictionary of numpy arrays.
- Return type
dict
Examples
>>> class Param: ... def __init__(self,a,b,c): ... self.a = a ... self.b = b ... self.c = c >>> LD2DL([ Param(1,2,3), Param(4,5,6) , Param(7,8,9) ]) {'a': array([1, 4, 7]), 'b': array([2, 5, 8]), 'c': array([3, 6, 9])}
- hepi.util.LD2DF(ld: dict) pandas.DataFrame[source]
Convert a dict of list`s to a `pandas.DataFrame.
- hepi.util.get_name(pid: int) str[source]
Get the latex name of a particle.
- Parameters
pid (int) – PDG Monte Carlo identifier for the particle.
- Returns
Latex name.
- Return type
str
Examples
>>> get_name(21) 'g' >>> get_name(1000022) '\\tilde{\\chi}_{1}^{0}'
- hepi.util.get_LR_partner(pid: int) Tuple[int, int][source]
Transforms a PDG id to it’s left-right partner.
- Parameters
pid (int) – PDG Monte Carlo identifier for the particle.
- Returns
First int is -1 for Left and 1 for Right. Second int is the PDG id.
- Return type
tuple
Examples
>>> get_LR_partner(1000002) (-1, 2000002)
- hepi.util.namehash(n: any) str[source]
Creates a sha256 hash from the objects string representation.
- Parameters
n (any) – object.
- Returns
sha256 of object.
- Return type
str
Examples
>>> p = {'a':1,'b':2} >>> str(p) "{'a': 1, 'b': 2}" >>> namehash(str(p)) '3dffaea891e5dbadb390da33bad65f509dd667779330e2720df8165a253462b8' >>> namehash(p) '3dffaea891e5dbadb390da33bad65f509dd667779330e2720df8165a253462b8'