That’s the wrong way round. You need to check if the the filter collection has the child:
<?php $allUsedCategories = $allUsedCategories->filter(fn ($child) => $filter->has($child)); ?>
On a side note, this if statement doesn’t make sense, you need a comparison here, not an assignment:
<?php if ($rubrikcheck === true): ?>
And the two statements can be combined into one. anyway:
<?php if ($rubrikcheck === true && $articles->count()): ?>