Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
name: Run linter (flake8+black)
steps:
- uses: actions/checkout@master
Expand All @@ -36,11 +36,14 @@ jobs:
matrix:
python: ["3.10"]
root: ["6.26.4"]
gcc: ["10.4.0"]
include:
- python: "3.10"
root: "6.32.2"
root: "6.32.10"
gcc: "11.4.0"
- python: "3.12"
root: "6.34.4"
gcc: "11.4.0"

runs-on: ubuntu-latest
name: Compile (py${{ matrix.python }}, root${{ matrix.root }})
Expand All @@ -58,7 +61,7 @@ jobs:
shell: bash -l {0}
run: |
# Install dependencies (synchronize with cms-combine-feedstock recipe.yaml)
mamba install -c conda-forge cmake python==${{ matrix.python }} pandas gsl root==${{ matrix.root }} boost-cpp eigen
mamba install -c conda-forge cmake python==${{ matrix.python }} pandas gsl root==${{ matrix.root }} boost-cpp eigen gcc==${{ matrix.gcc }}
- name: Build
shell: bash -l {0}
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/cvmfs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ jobs:
cd test
python3 test_interference.py

- uses: ./.github/actions/run-in-cvmfs
name: FastScan template analysis CMSHistFunc
with:
script: |
text2workspace.py data/ci/template-analysis_shapeInterp.txt -o ws_template-analysis.root --mass 200
combineTool.py -M FastScan -w ws_template-analysis.root:w

- name: Prepare code coverage report
if: ${{ success() && (matrix.coverage == true) }}
run: |
Expand Down
12 changes: 6 additions & 6 deletions interface/Combine.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class Combine {

static void setNllBackend(std::string const&);

static std::unique_ptr<RooAbsReal> combineCreateNLL(RooAbsPdf &pdf,
RooAbsData &data,
RooArgSet const *constraint = nullptr,
bool offset = false,
bool warnAboutDifferentBackend = true);

private:
bool mklimit(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr) ;

Expand Down Expand Up @@ -123,10 +129,4 @@ class Combine {
static std::string textToWorkspaceString_;
};

std::unique_ptr<RooAbsReal> combineCreateNLL(RooAbsPdf &pdf,
RooAbsData &data,
RooArgSet const *constraint = nullptr,
bool offset = false,
bool warnAboutDifferentBackend = true);

#endif
3 changes: 2 additions & 1 deletion python/ShapeTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from .DataFrameWrapper import DataFrameWrapper

RooArgSet_add_original = ROOT.RooArgSet.add

if (ROOT.gROOT.GetVersionInt() > 63000 and ROOT.gROOT.GetVersionInt() < 63400):
ROOT.gSystem.Load("libHiggsAnalysisCombinedLimit")

def RooArgSet_add_patched(self, obj, *args, **kwargs):
if isinstance(obj, ROOT.RooAbsCollection):
Expand Down
7 changes: 4 additions & 3 deletions python/tool_base/FastScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def run_method(self):
data = f_d.Get(ws_d[1])
else:
data = f_d.Get(ws_d[1]).data(ws_d[2])
nll = ROOT.combineCreateNLL(pdf, data)
nll = ROOT.Combine.combineCreateNLL(pdf, data)
pars = pdf.getParameters(data)
pars.Print()
snap = pars.snapshot()
Expand Down Expand Up @@ -114,7 +114,8 @@ def run_method(self):
grd1.Write()
grd2.Write()
pars.assignValueOnly(snap)
canv = ROOT.TCanvas(self.args.output, self.args.output)
canv_name = "par_%s" % par.GetName()
canv = ROOT.TCanvas(canv_name, canv_name)
pads = plot.MultiRatioSplit([0.4, 0.3], [0.005, 0.005], [0.005, 0.005])
pads[0].cd()
plot.Set(gr, MarkerSize=0.5)
Expand Down Expand Up @@ -143,7 +144,7 @@ def run_method(self):
if page == len(doPars) - 1:
extra = ")"
print(extra)
canv.Print(".pdf%s" % extra)
canv.Print("%s.pdf%s" % (self.args.output, extra))
page += 1

outfile.Write()
3 changes: 2 additions & 1 deletion src/AsimovUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
}
if (needsFit) {
//mc->GetPdf()->fitTo(realdata, RooFit::Minimizer("Minuit2","minimize"), RooFit::Strategy(1), RooFit::Constrain(*mc->GetNuisanceParameters()));
auto nll = combineCreateNLL(*mc->GetPdf(), realdata, /*nuisances=*/mc->GetNuisanceParameters(), /*offset=*/false);
auto nll = Combine::combineCreateNLL(
*mc->GetPdf(), realdata, /*nuisances=*/mc->GetNuisanceParameters(), /*offset=*/false);

Check warning on line 57 in src/AsimovUtils.cc

View check run for this annotation

Codecov / codecov/patch

src/AsimovUtils.cc#L57

Added line #L57 was not covered by tests
CascadeMinimizer minim(*nll, CascadeMinimizer::Constrained);
minim.setStrategy(1);
minim.minimize(verbose-1);
Expand Down
9 changes: 5 additions & 4 deletions src/AsymptoticLimits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
}

RooArgSet constraints; if (withSystematics) constraints.add(*mc_s->GetNuisanceParameters());
nllD_ = combineCreateNLL(*mc_s->GetPdf(), data, &constraints, /*offset=*/false);
nllA_ = combineCreateNLL(*mc_s->GetPdf(), asimov, &constraints, /*offset=*/false);
nllD_ = Combine::combineCreateNLL(*mc_s->GetPdf(), data, &constraints, /*offset=*/false);
nllA_ = Combine::combineCreateNLL(*mc_s->GetPdf(), asimov, &constraints, /*offset=*/false);

Check warning on line 171 in src/AsymptoticLimits.cc

View check run for this annotation

Codecov / codecov/patch

src/AsymptoticLimits.cc#L170-L171

Added lines #L170 - L171 were not covered by tests

if (verbose > 0) std::cout << (qtilde_ ? "Restricting" : "Not restricting") << " " << r->GetName() << " to positive values." << std::endl;
if (verbose > 1) params_->Print("V");
Expand Down Expand Up @@ -394,8 +394,9 @@
r->setVal(0.01*r->getMax());
r->setError(0.1*r->getMax());
//r->removeMax();

auto nll = combineCreateNLL(*mc_s->GetPdf(), *asimov, /*constrain=*/mc_s->GetNuisanceParameters(), /*offset=*/false);

auto nll = Combine::combineCreateNLL(
*mc_s->GetPdf(), *asimov, /*constrain=*/mc_s->GetNuisanceParameters(), /*offset=*/false);

Check warning on line 399 in src/AsymptoticLimits.cc

View check run for this annotation

Codecov / codecov/patch

src/AsymptoticLimits.cc#L399

Added line #L399 was not covered by tests
CascadeMinimizer minim(*nll, CascadeMinimizer::Unconstrained, r);
//minim.setStrategy(minimizerStrategy_);
minim.setErrorLevel(0.5*pow(ROOT::Math::normal_quantile(1-0.5*(1-cl),1.0), 2)); // the 0.5 is because qmu is -2*NLL
Expand Down
2 changes: 1 addition & 1 deletion src/BayesianToyMC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ std::pair<double,double> BayesianToyMC::priorPredictiveDistribution(RooStats::Mo
}
std::cout << "Factorized PDF, now creating NLL" << std::endl;
// create NLL
auto nll = combineCreateNLL(
auto nll = Combine::combineCreateNLL(
*pdf, data, /*constraints*/ withSystematics ? mc->GetNuisanceParameters() : nullptr, /*offset=*/false);
std::unique_ptr<RooArgSet> params(nll->getParameters(data));

Expand Down
12 changes: 7 additions & 5 deletions src/BestFitSigmaTestStat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@
bool BestFitSigmaTestStat::createNLLWrapper(RooAbsPdf &pdf, RooAbsData &data)
{
if (typeid(pdf) == typeid(RooSimultaneousOpt)) {
if (nll_.get() == 0) nll_ = combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
else ((cacheutils::CachingSimNLL&)(*nll_)).setData(data);
return true;
if (nll_.get() == 0)
nll_ = Combine::combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);

Check warning on line 98 in src/BestFitSigmaTestStat.cc

View check run for this annotation

Codecov / codecov/patch

src/BestFitSigmaTestStat.cc#L98

Added line #L98 was not covered by tests
else
((cacheutils::CachingSimNLL &)(*nll_)).setData(data);
return true;

Check warning on line 101 in src/BestFitSigmaTestStat.cc

View check run for this annotation

Codecov / codecov/patch

src/BestFitSigmaTestStat.cc#L100-L101

Added lines #L100 - L101 were not covered by tests
} else {
nll_ = combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
return false;
nll_ = Combine::combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
return false;

Check warning on line 104 in src/BestFitSigmaTestStat.cc

View check run for this annotation

Codecov / codecov/patch

src/BestFitSigmaTestStat.cc#L103-L104

Added lines #L103 - L104 were not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Combine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ void Combine::addBranches(const std::string& trackString, RooWorkspace* w, std::
}
}

std::unique_ptr<RooAbsReal> combineCreateNLL(
std::unique_ptr<RooAbsReal> Combine::combineCreateNLL(
RooAbsPdf &pdf, RooAbsData &data, RooArgSet const *constrain, bool offset, bool warnAboutDifferentBackend) {
RooLinkedList cmdList;

Expand Down
8 changes: 4 additions & 4 deletions src/DebugProposal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
RooStats::ProposalFunction(), prop_(p), pdf_(pdf), tries_(tries)
{
if (pdf && data) {
nll_ = combineCreateNLL(*pdf, *data, /*constrain=*/nullptr, /*offset=*/false);
std::unique_ptr<RooArgSet> par{pdf->getParameters(*data)};
RooStats::RemoveConstantParameters(par.get());
params_.add(*par);
nll_ = Combine::combineCreateNLL(*pdf, *data, /*constrain=*/nullptr, /*offset=*/false);
std::unique_ptr<RooArgSet> par{pdf->getParameters(*data)};
RooStats::RemoveConstantParameters(par.get());
params_.add(*par);

Check warning on line 16 in src/DebugProposal.cc

View check run for this annotation

Codecov / codecov/patch

src/DebugProposal.cc#L13-L16

Added lines #L13 - L16 were not covered by tests
}
if (tries) {
p->Print("V");
Expand Down
6 changes: 4 additions & 2 deletions src/FitDiagnostics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ bool FitDiagnostics::runSpecific(RooWorkspace *w, RooStats::ModelConfig *mc_s, R
#else
Combine::nllBackend() = RooFit::EvalBackend(RooFit::EvalBackend::defaultValue()).name();
#endif
auto nuisanceNLL = combineCreateNLL(simNuisancePdf, *globalData, nuis, /*warnAboutDifferentBackend=*/false);
auto nuisanceNLL =
Combine::combineCreateNLL(simNuisancePdf, *globalData, nuis, /*warnAboutDifferentBackend=*/false);
Combine::nllBackend() = prevBackend;

RooFitResult *res_prefit = 0;
Expand Down Expand Up @@ -268,7 +269,8 @@ bool FitDiagnostics::runSpecific(RooWorkspace *w, RooStats::ModelConfig *mc_s, R
r->setConstant(true);

// Setup Nll before calling fits;
if (currentToy_<1) nll = combineCreateNLL(*mc_s->GetPdf(), data, constCmdArg_s.getSet(0));
if (currentToy_ < 1)
nll = Combine::combineCreateNLL(*mc_s->GetPdf(), data, constCmdArg_s.getSet(0));
// Get the nll value on the prefit
double nll0 = nll->getVal();

Expand Down
2 changes: 1 addition & 1 deletion src/FitterAlgoBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ RooFitResult *FitterAlgoBase::doFit(RooAbsPdf &pdf, RooAbsData &data, const RooA
((cacheutils::CachingSimNLL&)(*nll)).setData(data); // reuse nll but swap out the data
} else {
nll.reset(); // first delete the old one, to avoid using more memory, even if temporarily
nll = combineCreateNLL(pdf, data, constrain.getSet(0), /*offset=*/true); // make a new nll
nll = Combine::combineCreateNLL(pdf, data, constrain.getSet(0), /*offset=*/true); // make a new nll
}

double nll0 = nll->getVal();
Expand Down
6 changes: 3 additions & 3 deletions src/GoodnessOfFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@
CloseCoutSentry sentry(verbose < 2);

RooArgSet const *cPars = withSystematics ? mc_s->GetNuisanceParameters() : nullptr;
auto nominal_nll = combineCreateNLL(*pdf_nominal, data, /*constrain=*/cPars, /*offset=*/false);
auto saturated_nll = combineCreateNLL(*saturated, data, /*constrain=*/cPars, /*offset=*/false);
auto nominal_nll = Combine::combineCreateNLL(*pdf_nominal, data, /*constrain=*/cPars, /*offset=*/false);
auto saturated_nll = Combine::combineCreateNLL(*saturated, data, /*constrain=*/cPars, /*offset=*/false);

Check warning on line 190 in src/GoodnessOfFit.cc

View check run for this annotation

Codecov / codecov/patch

src/GoodnessOfFit.cc#L189-L190

Added lines #L189 - L190 were not covered by tests

if (setParametersForFit_ != "") {
utils::setModelParameters(setParametersForFit_, w->allVars());
Expand Down Expand Up @@ -257,7 +257,7 @@
*/

RooArgSet const *cPars = withSystematics ? mc_s->GetNuisanceParameters() : nullptr;
auto nll = combineCreateNLL(*pdf, data, /*constrain=*/cPars, /*offset=*/false);
auto nll = Combine::combineCreateNLL(*pdf, data, /*constrain=*/cPars, /*offset=*/false);

Check warning on line 260 in src/GoodnessOfFit.cc

View check run for this annotation

Codecov / codecov/patch

src/GoodnessOfFit.cc#L260

Added line #L260 was not covered by tests
CascadeMinimizer minim(*nll, CascadeMinimizer::Unconstrained);
//minims.setStrategy(minimizerStrategy_);
minim.minimize(verbose-2);
Expand Down
4 changes: 2 additions & 2 deletions src/HybridNew.cc
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@
r->setVal(0); pdfB = mc_s->GetPdf();
}
timer.Start();
auto nll = combineCreateNLL(*pdfB, data, mc_s->GetNuisanceParameters(), /*offset=*/false);
auto nll = Combine::combineCreateNLL(*pdfB, data, mc_s->GetNuisanceParameters(), /*offset=*/false);
{
CloseCoutSentry sentry(verbose < 3);
CascadeMinimizer minim(*nll, CascadeMinimizer::Constrained, r);
Expand All @@ -839,7 +839,7 @@
timer.Start();
if (pdfB != mc_s->GetPdf()) {
nll.reset(); // first delete old one, to avoid duplicating memory
nll = combineCreateNLL(*mc_s->GetPdf(), data, mc_s->GetNuisanceParameters(), /*offset=*/false);
nll = Combine::combineCreateNLL(*mc_s->GetPdf(), data, mc_s->GetNuisanceParameters(), /*offset=*/false);

Check warning on line 842 in src/HybridNew.cc

View check run for this annotation

Codecov / codecov/patch

src/HybridNew.cc#L842

Added line #L842 was not covered by tests
}
{
CloseCoutSentry sentry(verbose < 3);
Expand Down
2 changes: 1 addition & 1 deletion src/MultiDimFit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
std::cout << "MultiDimFit -- Skipping initial global fit" << std::endl;
// must still create the NLL
RooArgSet const *cPars = withSystematics ? mc_s->GetNuisanceParameters() : nullptr;
nll = combineCreateNLL(pdf, data, /*nuisances=*/cPars, /*offset=*/true);
nll = Combine::combineCreateNLL(pdf, data, /*nuisances=*/cPars, /*offset=*/true);

Check warning on line 220 in src/MultiDimFit.cc

View check run for this annotation

Codecov / codecov/patch

src/MultiDimFit.cc#L220

Added line #L220 was not covered by tests
}

//if(w->var("r")) {w->var("r")->Print();}
Expand Down
26 changes: 15 additions & 11 deletions src/ProfiledLikelihoodRatioTestStatExt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@
bool ProfiledLikelihoodRatioTestStatOpt::createNLLWrapper(RooAbsPdf &pdf, RooAbsData &data, std::unique_ptr<RooAbsReal> &nll_)
{
if (typeid(pdf) == typeid(RooSimultaneousOpt)) {
if (nll_.get() == 0) nll_ = combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
else ((cacheutils::CachingSimNLL&)(*nll_)).setData(data);
return true;
if (nll_.get() == 0)
nll_ = Combine::combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);

Check warning on line 102 in src/ProfiledLikelihoodRatioTestStatExt.cc

View check run for this annotation

Codecov / codecov/patch

src/ProfiledLikelihoodRatioTestStatExt.cc#L102

Added line #L102 was not covered by tests
else
((cacheutils::CachingSimNLL &)(*nll_)).setData(data);
return true;

Check warning on line 105 in src/ProfiledLikelihoodRatioTestStatExt.cc

View check run for this annotation

Codecov / codecov/patch

src/ProfiledLikelihoodRatioTestStatExt.cc#L104-L105

Added lines #L104 - L105 were not covered by tests
} else {
nll_ = combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
return false;
nll_ = Combine::combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
return false;

Check warning on line 108 in src/ProfiledLikelihoodRatioTestStatExt.cc

View check run for this annotation

Codecov / codecov/patch

src/ProfiledLikelihoodRatioTestStatExt.cc#L107-L108

Added lines #L107 - L108 were not covered by tests
}
}

Expand All @@ -112,7 +114,7 @@
{
#if defined(DBG_TestStat_NOFIT) && (DBG_TestStat_NOFIT > 0)
if (verbosity_ > 0) std::cout << "Profiling likelihood for pdf " << pdf.GetName() << std::endl;
return combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false)->getVal();
return Combine::combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false)->getVal();
#endif
CascadeMinimizer minim(*nll_, CascadeMinimizer::Constrained);
minim.setStrategy(0);
Expand Down Expand Up @@ -386,12 +388,14 @@
bool ProfiledLikelihoodTestStatOpt::createNLLWrapper(RooAbsPdf &pdf, RooAbsData &data)
{
if (typeid(pdf) == typeid(RooSimultaneousOpt)) {
if (nll_.get() == 0) nll_ = combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
else ((cacheutils::CachingSimNLL&)(*nll_)).setData(data);
return true;
if (nll_.get() == 0)
nll_ = Combine::combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
else
((cacheutils::CachingSimNLL &)(*nll_)).setData(data);
return true;
} else {
nll_ = combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
return false;
nll_ = Combine::combineCreateNLL(pdf, data, &nuisances_, /*offset=*/false);
return false;

Check warning on line 398 in src/ProfiledLikelihoodRatioTestStatExt.cc

View check run for this annotation

Codecov / codecov/patch

src/ProfiledLikelihoodRatioTestStatExt.cc#L397-L398

Added lines #L397 - L398 were not covered by tests
}
}

Expand Down
Loading
Loading