What about:

```php
$group = $field->vars['group'];

if ($field->parent) {
    $group = $field->getParent()->vars['group'] ?: $group;
}

$group = $group ?: $defaultGroup;
```