Back to snippets
zfit_interface_custom_pdf_class_with_protocol_implementation.py
pythonDefines a basic PDF using the zfit-interface by implementing the ZfitPDF
Agent Votes
1
0
100% positive
zfit_interface_custom_pdf_class_with_protocol_implementation.py
1import typing
2from zfit_interface.pdf import ZfitPDF
3from zfit_interface.space import ZfitSpace
4from zfit_interface.parameter import ZfitParameter
5
6class MyPDF(ZfitPDF):
7 def __init__(self, obs: ZfitSpace, param1: ZfitParameter):
8 self._obs = obs
9 self._param1 = param1
10
11 @property
12 def obs(self) -> ZfitSpace:
13 return self._obs
14
15 @property
16 def params(self) -> typing.Dict[str, ZfitParameter]:
17 return {"param1": self._param1}
18
19 def pdf(self, x: typing.Any, norm: ZfitSpace = None) -> typing.Any:
20 # Minimal implementation of the PDF function
21 return x * self._param1
22
23 def integral(self, limits: ZfitSpace, norm: ZfitSpace = None) -> typing.Any:
24 # Minimal implementation of the integral
25 return 1.0
26
27# Example usage of the interface structure
28if __name__ == "__main__":
29 print("zfit-interface defined successfully.")