@@ -368,7 +368,6 @@ RooMomentMorphFuncND::compileForNormSet(RooArgSet const &normSet, RooFit::Detail
368368 {
369369 RooArgSet branches;
370370 cache->_sum ->branchNodeServerList (&branches);
371- branches.add (*cache->_sum );
372371 for (auto *b : branches) {
373372 std::vector<std::string> toRemove;
374373 for (auto const &attr : b->attributes ()) {
@@ -408,17 +407,10 @@ RooMomentMorphFuncND::compileForNormSet(RooArgSet const &normSet, RooFit::Detail
408407 std::unique_ptr<RooAbsReal> newSum{static_cast <RooAbsReal *>(cust.build ())};
409408 newSum->addOwnedComponents (std::move (newFractions));
410409
411- // Mark every node in the freshly-cloned subtree as already compiled, so
412- // the recursive compileServers call below doesn't try to re-clone any of
413- // them. The leaves we still want compiled (the morph parameters and the
414- // observables) are reachable from these nodes' own server lists and will
415- // be visited.
416- ctx.markAsCompiled (*newSum);
417- RooArgSet allBranches;
418- newSum->branchNodeServerList (&allBranches);
419- for (auto *b : allBranches) {
420- ctx.markAsCompiled (*b);
421- }
410+ // Tell the compile context the freshly-cloned subtree is already in its
411+ // final form, so the recursive descent below only visits the leaves that
412+ // still need compiling (the morph parameters and the observables).
413+ ctx.markSubtreeAsCompiled (*newSum);
422414 ctx.compileServers (*newSum, normSet);
423415
424416 return newSum;
0 commit comments