a
    zn„f  ã                   @  sB   d Z ddlmZ ddlZddlZddlZG dd„ dejjjƒZdS )z3
This module defines the behaviors of ``RooHist``.
é    )ÚannotationsNc                   @  sJ   e Zd ZdZedd„ ƒZedd„ ƒZddd„Zd	d
„ Zdd„ Z	dd„ Z
dS )ÚRooHistz�
    Behavior for ``RooHist``.

    This consists of ``to_boost`` (and ``to_hist``) and ``to_numpy``
    providing access to the histogram.
    c                 C  s
   |   d¡S )z,
        The name of the histogram.
        ZfName©Úmember©Úself© r   ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/behaviors/RooHist.pyÚname   s    zRooHist.namec                 C  s
   |   d¡S )z-
        The title of the histogram.
        ZfTitler   r   r   r   r	   Útitle"   s    zRooHist.titleFc                 C  s†   |   ¡ \}}|| jddd� }|| jddd� }t t |dd… |dd… ¡¡sZtdƒ‚t ||d g¡}|rz||ffS ||fS dS )	a&  
        Args:
            dd (bool): If True, the return type follows
                `numpy.histogramdd <https://numpy.org/doc/stable/reference/generated/numpy.histogramdd.html>`__;
                otherwise, it follows `numpy.histogram <https://numpy.org/doc/stable/reference/generated/numpy.histogram.html>`__
                and `numpy.histogram2d <https://numpy.org/doc/stable/reference/generated/numpy.histogram2d.html>`__.

        Converts the ``RooHist`` into a form like the ones produced by the NumPy
        histogram functions.
        ÚlowÚx©ÚwhichÚaxisÚhighé   Néÿÿÿÿú(bin_edges_low[1:] != bin_edges_high[:-1])ÚvaluesÚerrorsÚnumpyÚallÚiscloseÚ
ValueErrorÚappend)r   ÚddÚbin_centersr   Úbin_edges_lowÚbin_edges_highÚ	bin_edgesr   r   r	   Úto_numpy)   s    "
zRooHist.to_numpyc                 C  sì   t j ¡ }|  ¡ \}}|| jddd� }|| jddd� }t t |dd… |dd… ¡¡sdtdƒ‚| jd	d
d�}t 	|¡}t 
||d g¡}|jj|ddd�}	| j|	_| j|	_|j|	|j ¡ d�}
| j|
_| j|
_|
 ¡ }||_||_|
S )zI
        Converts ``RooHist`` into a ``boost-histogram`` object.
        r   r   r   r   r   Nr   r   ÚmeanÚyF)Z	underflowÚoverflow)Ústorage)ÚuprootÚextrasÚboost_histogramr   r   r   r   r   r   Zsquarer   r   ÚVariabler
   r   Z	Histogramr%   ZWeightÚviewÚvalueZvariance)r   r(   r   r   r   r   r   Z	variancesr    r   Úhistr*   r   r   r	   Úto_boost?   s.    
"
ýzRooHist.to_boostc                 C  s   t j ¡  |  ¡ ¡S )z>
        Converts ``RooHist`` into a ``hist`` object.
        )r&   r'   r,   ZHistr-   r   r   r   r	   Úto_hist^   s    zRooHist.to_histc                 C  s   |   ¡ S )N)r-   r   r   r   r	   Ú_to_boost_histogram_d   s    zRooHist._to_boost_histogram_N)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr
   r   r!   r-   r.   r/   r   r   r   r	   r      s   


r   )	r3   Ú
__future__r   r   r&   Z"uproot.behaviors.TGraphAsymmErrorsZ	behaviorsZTGraphAsymmErrorsr   r   r   r   r	   Ú<module>   s
   