def correction_factor(rt, lt, icr=None, ocr=None):
    """
    Calculate the deadtime correction factor.

    Parameters:
    -----------
    * rt  = real time, time the detector was requested to count for
    * lt  = live time, actual time the detector was active and
            processing counts
    * icr = true input count rate (TOC_t/lt, where TOC_t = true total counts
            impinging the detector)
    * ocr = output count rate (TOC_s/lt, where TOC_s = total processed
            {slow filter for dxp} counts output by the detector)

    If icr and/or ocr are None then only lt correction is applied

    Outputs:
    -------
    * cor = (icr/ocr)*(rt/lt)
      the correction factor. the correction is applied as:
        corrected_counts = counts * cor
    """
    if icr is not None and ocr is not None:
        return (icr/ocr)*(rt/lt)
    return (rt/lt)