hepi.util

Collection of utility functions for the hepi package.

Module Contents

Classes

DictData

Functions

LD2DL(l: List, actual_dict=False) → dict

Convert a list of objects into a dictionary of lists.

DL2DF(ld: dict) → pandas.DataFrame

Convert a dict of list`s to a `pandas.DataFrame.

get_name(pid: int) → str

Get the latex name of a particle.

get_LR_partner(pid: int) → Tuple[int, int]

Transforms a PDG id to it's left-right partner.

namehash(n: any) → str

Creates a sha256 hash from the objects string representation.

lhapdf_name_to_id(name: str) → int

Converts a LHAPDF name to the sets id.

interpolate_1d(df, x, y, xrange, only_interpolation=True)

Last key is the value to be interpolated, while the rest are cooridnates.

interpolate_2d(df, x, y, z, xrange, yrange, only_interpolation=True, **kwargs)

Last key is the value to be interpolated, while the rest are cooridnates.

class hepi.util.DictData[source]
__str__(self)[source]

Returns attributes as dict as string

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.DL2DF(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'
hepi.util.lhapdf_name_to_id(name: str) int[source]

Converts a LHAPDF name to the sets id.

Parameters

name (str) – LHAPDF set name.

Returns

id of the LHAPDF set.

Return type

int

Examples

>>> lhapdf_name_to_id("CT14lo")
13200
hepi.util.interpolate_1d(df, x, y, xrange, only_interpolation=True)[source]

Last key is the value to be interpolated, while the rest are cooridnates.

Parameters

df (pandas.DataFrame) – results

hepi.util.interpolate_2d(df, x, y, z, xrange, yrange, only_interpolation=True, **kwargs)[source]

Last key is the value to be interpolated, while the rest are cooridnates.

Parameters

df (pandas.DataFrame) – results