Source code for analyzer.modules.common.axis
from attrs import define
import abc
import hist
from cattrs.strategies import include_subclasses
@define(frozen=True)
[docs]
class Axis(abc.ABC):
@abc.abstractmethod
@define(frozen=True)
[docs]
class IntegerAxis(Axis):
[docs]
unit: str | None = None
[docs]
def toHist(self):
a = hist.axis.Integer(self.start, self.stop, name=self.name)
if self.unit:
a.unit = self.unit
return a
@define(frozen=True)
[docs]
class RegularAxis(Axis):
[docs]
unit: str | None = None
[docs]
def toHist(self):
a = hist.axis.Regular(self.bins, self.start, self.stop, name=self.name)
if self.unit:
a.unit = self.unit
return a
@define(frozen=True)
[docs]
class VariableAxis(Axis):
[docs]
edges: list[float | tuple[float, float, int]]
[docs]
unit: str | None = None
[docs]
def toHist(self):
import numpy as np
def toList(x):
if isinstance(x,tuple):
return list(float(y) for y in np.arange(*x))
else:
return [x]
a = hist.axis.Variable(
[y for x in self.edges for y in toList(x)], name=self.name
)
if self.unit:
a.unit = self.unit
return a