<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_user_groups(user):
 """Return the set of associated TenantGroups for the given user."""

    if user.is_active and user.is_authenticated():
        if user.is_superuser:
            return TenantGroup.objects.all()
        else:
            return TenantGroup.objects.filter(tenantrole__user=user).distinct()
    else:
        return TenantGroup.objects.none()