@@ -590,82 +590,67 @@ TEST_P(HFFixtureFit, Fit)
590590 auto mc = dynamic_cast <RooStats::ModelConfig *>(ws->obj (" ModelConfig" ));
591591 ASSERT_NE (mc, nullptr );
592592
593- // This tests both correct pre-caching of constant terms and (if false) that all doEval() are correct.
594- for (bool constTermOptimization : {true , false }) {
593+ std::unique_ptr<RooArgSet> pars (simPdf->getParameters (*data));
594+ // Kick parameters:
595+ for (auto par : *pars) {
596+ auto real = dynamic_cast <RooAbsRealLValue *>(par);
597+ if (real && !real->isConstant ())
598+ real->setVal (real->getVal () * 0.95 );
599+ }
600+ if (makeModelMode == MakeModelMode::StatSyst) {
601+ auto poi = dynamic_cast <RooRealVar *>(pars->find (" SigXsecOverSM" ));
602+ ASSERT_NE (poi, nullptr );
603+ poi->setVal (2 .);
604+ poi->setConstant ();
605+ }
595606
596- // constTermOptimization makes only sense in the legacy backend
597- if (constTermOptimization && evalBackend != RooFit::EvalBackend::Legacy ()) {
598- continue ;
599- }
600- SCOPED_TRACE (constTermOptimization ? " const term optimisation" : " No const term optimisation" );
601-
602- // Stop if one of the previous runs had a failure to keep the terminal clean.
603- if (HasFailure ())
604- break ;
605-
606- std::unique_ptr<RooArgSet> pars (simPdf->getParameters (*data));
607- // Kick parameters:
608- for (auto par : *pars) {
609- auto real = dynamic_cast <RooAbsRealLValue *>(par);
610- if (real && !real->isConstant ())
611- real->setVal (real->getVal () * 0.95 );
612- }
613- if (makeModelMode == MakeModelMode::StatSyst) {
614- auto poi = dynamic_cast <RooRealVar *>(pars->find (" SigXsecOverSM" ));
615- ASSERT_NE (poi, nullptr );
616- poi->setVal (2 .);
617- poi->setConstant ();
607+ using namespace RooFit ;
608+ std::unique_ptr<RooFitResult> fitResult{simPdf->fitTo (
609+ *data, evalBackend, GlobalObservables (*mc->GetGlobalObservables ()), Save (), PrintLevel (verbose ? 1 : -1 ))};
610+ ASSERT_NE (fitResult, nullptr );
611+ if (verbose)
612+ fitResult->Print (" v" );
613+ EXPECT_EQ (fitResult->status (), 0 );
614+
615+ auto checkParam = [&](const std::string ¶m, double target, double absPrecision = 1 .e -2 ) {
616+ auto par = dynamic_cast <RooRealVar *>(fitResult->floatParsFinal ().find (param.c_str ()));
617+ if (!par) {
618+ // Parameter was constant in this fit
619+ par = dynamic_cast <RooRealVar *>(fitResult->constPars ().find (param.c_str ()));
620+ ASSERT_NE (par, nullptr ) << param;
621+ EXPECT_DOUBLE_EQ (par->getVal (), target) << " Constant parameter " << param << " is off target." ;
622+ } else {
623+ EXPECT_NEAR (par->getVal (), target, par->getError ())
624+ << " Parameter " << param << " close to target " << target << " within uncertainty" ;
625+ EXPECT_NEAR (par->getVal (), target, absPrecision) << " Parameter " << param << " close to target " << target;
618626 }
627+ };
619628
620- using namespace RooFit ;
621- std::unique_ptr<RooFitResult> fitResult{simPdf->fitTo (*data, evalBackend, Optimize (constTermOptimization),
622- GlobalObservables (*mc->GetGlobalObservables ()), Save (),
623- PrintLevel (verbose ? 1 : -1 ))};
624- ASSERT_NE (fitResult, nullptr );
625- if (verbose)
626- fitResult->Print (" v" );
627- EXPECT_EQ (fitResult->status (), 0 );
628-
629- auto checkParam = [&](const std::string ¶m, double target, double absPrecision = 1 .e -2 ) {
630- auto par = dynamic_cast <RooRealVar *>(fitResult->floatParsFinal ().find (param.c_str ()));
631- if (!par) {
632- // Parameter was constant in this fit
633- par = dynamic_cast <RooRealVar *>(fitResult->constPars ().find (param.c_str ()));
634- ASSERT_NE (par, nullptr ) << param;
635- EXPECT_DOUBLE_EQ (par->getVal (), target) << " Constant parameter " << param << " is off target." ;
636- } else {
637- EXPECT_NEAR (par->getVal (), target, par->getError ())
638- << " Parameter " << param << " close to target " << target << " within uncertainty" ;
639- EXPECT_NEAR (par->getVal (), target, absPrecision) << " Parameter " << param << " close to target " << target;
640- }
641- };
642-
643- if (makeModelMode == MakeModelMode::OverallSyst) {
644- // Model is set up such that background scale factors should be close to 1, and signal == 2
645- checkParam (" SigXsecOverSM" , 2 .);
646- checkParam (" alpha_syst2" , 0 .);
647- checkParam (" alpha_syst3" , 0 .);
648- checkParam (" alpha_syst4" , 0 .);
649- checkParam (" gamma_stat_channel1_bin_0" , 1 .);
650- checkParam (" gamma_stat_channel1_bin_1" , 1 .);
651- } else if (makeModelMode == MakeModelMode::HistoSyst) {
652- // Model is set up with a -1 sigma pull on the signal shape parameter.
653- checkParam (" SigXsecOverSM" , 2 ., 1.1E-1 ); // Higher tolerance: Expect a pull due to shape syst.
654- checkParam (" gamma_stat_channel1_bin_0" , 1 .);
655- checkParam (" gamma_stat_channel1_bin_1" , 1 .);
656- checkParam (" alpha_SignalShape" , -0.9 , 5 .E -2 ); // Pull slightly lower than 1 because of constraint term
657- } else if (makeModelMode == MakeModelMode::StatSyst) {
658- // Model is set up with a -1 sigma pull on the signal shape parameter.
659- checkParam (" SigXsecOverSM" , 2 ., 1.1E-1 ); // Higher tolerance: Expect a pull due to shape syst.
660- checkParam (" gamma_stat_channel1_bin_0" , 1.09 ); // This should be pulled
661- checkParam (" gamma_stat_channel1_bin_1" , 1 .);
662- } else if (makeModelMode == MakeModelMode::ShapeSyst) {
663- // This should be pulled down
664- checkParam (" gamma_background1Shape_bin_0" , 0.8866 , 0.03 );
665- // This should be pulled up, but not so much because the free signal
666- // strength will fit the excess in this bin.
667- checkParam (" gamma_background2Shape_bin_1" , 1.0250 , 0.03 );
668- }
629+ if (makeModelMode == MakeModelMode::OverallSyst) {
630+ // Model is set up such that background scale factors should be close to 1, and signal == 2
631+ checkParam (" SigXsecOverSM" , 2 .);
632+ checkParam (" alpha_syst2" , 0 .);
633+ checkParam (" alpha_syst3" , 0 .);
634+ checkParam (" alpha_syst4" , 0 .);
635+ checkParam (" gamma_stat_channel1_bin_0" , 1 .);
636+ checkParam (" gamma_stat_channel1_bin_1" , 1 .);
637+ } else if (makeModelMode == MakeModelMode::HistoSyst) {
638+ // Model is set up with a -1 sigma pull on the signal shape parameter.
639+ checkParam (" SigXsecOverSM" , 2 ., 1.1E-1 ); // Higher tolerance: Expect a pull due to shape syst.
640+ checkParam (" gamma_stat_channel1_bin_0" , 1 .);
641+ checkParam (" gamma_stat_channel1_bin_1" , 1 .);
642+ checkParam (" alpha_SignalShape" , -0.9 , 5 .E -2 ); // Pull slightly lower than 1 because of constraint term
643+ } else if (makeModelMode == MakeModelMode::StatSyst) {
644+ // Model is set up with a -1 sigma pull on the signal shape parameter.
645+ checkParam (" SigXsecOverSM" , 2 ., 1.1E-1 ); // Higher tolerance: Expect a pull due to shape syst.
646+ checkParam (" gamma_stat_channel1_bin_0" , 1.09 ); // This should be pulled
647+ checkParam (" gamma_stat_channel1_bin_1" , 1 .);
648+ } else if (makeModelMode == MakeModelMode::ShapeSyst) {
649+ // This should be pulled down
650+ checkParam (" gamma_background1Shape_bin_0" , 0.8866 , 0.03 );
651+ // This should be pulled up, but not so much because the free signal
652+ // strength will fit the excess in this bin.
653+ checkParam (" gamma_background2Shape_bin_1" , 1.0250 , 0.03 );
669654 }
670655
671656 if (false ) {
0 commit comments