how to test for all children (including multilevel grand-childern) of page

You can use get_ancestors() to check if the post have an ancestor parent id or grandparent id etc..

But you would have to check every post for this…

function rt_before_after($content) {
    if(is_page() || is_single()) {
      global $post;
      $ancestors = get_ancestors( $post->ID, 'page' );
      if ( in_array( 27, $ancestors ) || $post->ID == '27') {
        $ntest="<div class="clearlogo"><img alt="nodal Clear logo" width="150" src="".get_stylesheet_directory_uri().'/images/nodal-clear-logo.png"></div>';
      }else{
        $ntest="";
      }
        $beforecontent = $ntest.'<h1 class="title">'.get_the_title().'</h1>';

        $fullcontent = $beforecontent . $content;
    } else {
        $fullcontent = $content;
    }

    return $fullcontent;
}
add_filter('the_content', 'rt_before_after');

You can go the other way around from the parent to children with get_pages()

And with this approach you can move it to seperate function and call it once and even cache it if you want. I would go for the second approach.

function rt_before_after($content) {
    if(is_page() || is_single()) {
      global $post;

      // get all the child pages and grandchild etc..
      $pages = get_pages( ['child_of'=>27] );
      $pages_ids = array_map( function( $item ) {
        return $item->ID;
      }, $pages );

      if ( in_array( $post->ID, $pages_ids ) || $post->ID == '27') {
        $ntest="<div class="clearlogo"><img alt="nodal Clear logo" width="150" src="".get_stylesheet_directory_uri().'/images/nodal-clear-logo.png"></div>';
      }else{
        $ntest="";
      }
        $beforecontent = $ntest.'<h1 class="title">'.get_the_title().'</h1>';

        $fullcontent = $beforecontent . $content;
    } else {
        $fullcontent = $content;
    }

    return $fullcontent;
}
add_filter('the_content', 'rt_before_after');