Skip to content

Commit

Permalink
[RF] RooStats tutorials translated into Python
Browse files Browse the repository at this point in the history
* [RF] Translate RooStats tutorials to Python

* [RF] Remove duplicate translations of RooStats tutorials

* [RF] Correct filenames for RooStats tutorials

* [RF] Code formatting of RooStats Python tutorials

Apply `black --line-length *`, as for the other Python source files.

* [RF] Fix typos is RooStats tutorials

* [RF] Delete Python HLFactory tutorials because it will be deprecated

See #17075.

* [RF] Fixup tutorial group for rs301_splot.py

* [RF] Mention authors of RooStats tutorial Python translations

* [RF] Only import ROOT module in RooStats tutorials

Don't create local variables for ever used class: this is not idiomatic
PyROOT code, and the existing tutorials also don't do it like that.

* [RF] Mention removal of Proof in the release notes

* [RF] Don't use Proof in Python versions of RooStats tutorials

* [RF] Veto ModelInspector.py tutorial as unit test

This tutorial requires a GUI, and therefore it can't be run as a unit
test.

* [RF] Correctly close file in StandardHistFactoryPlotsWithCategories.py

This fixes crashes at the end of the Python process

* [RF] Avoid using TList in RooStats tutorials

---------

Co-authored-by: Piter Amador Paye Mamani <[email protected], [email protected]>
Co-authored-by: Jonas Rembser <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2024
1 parent a560ca0 commit 66157b9
Show file tree
Hide file tree
Showing 37 changed files with 5,301 additions and 68 deletions.
1 change: 1 addition & 0 deletions README/ReleaseNotes/v636/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The following people have contributed to this new version:
* The `TPython::Eval()` function that was deprecated in ROOT 6.34 and scheduled for removal in ROOT 6.36 is removed.
* The `RooDataSet` constructors to construct a dataset from a part of an existing dataset are deprecated and will be removed in ROOT 6.38. This is to avoid interface duplication. Please use `RooAbsData::reduce()` instead, or if you need to change the weight column, use the universal constructor with the `Import()`, `Cut()`, and `WeightVar()` arguments.
* The ROOT splash screen was removed for Linux and macOS
* Proof support has been completely removed form RooFit and RooStats, after it was already not working anymore for several releases

## Python Interface

Expand Down
2 changes: 2 additions & 0 deletions tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ set(gui_veto math/fit/fitpanel_playback.C
graphics/psview.C graphics/gtime.C
graphics/graph_edit_playback.C
roostats/ModelInspector.C
roostats/ModelInspector.py
legacy/tree/tvdemo.C
eve/*.C
webgui/geom/geom_threejs.cxx
Expand Down Expand Up @@ -409,6 +410,7 @@ set(extra_veto
io/tree/tree106_tree.C
io/tree/tree108_tree.C
roostats/rs401d_FeldmanCousins.C # Takes too much time
roostats/rs401d_FeldmanCousins.py # Takes too much time
histfactory/ModifyInterpolation.C
io/tree/tree110_copy.C
io/tree/tree111_copy.C
Expand Down
14 changes: 14 additions & 0 deletions tutorials/roostats/CreateExampleFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ROOT

gROOT = ROOT.gROOT


def CreateExampleFile():

print("Preparing HistFactory ...")
gROOT.ProcessLine(".! prepareHistFactory .")
print("... done." "")

print("Moving HistoryFactory to Working Space ...")
gROOT.ProcessLine(".! hist2workspace config/example.xml")
print("... done.")
2 changes: 1 addition & 1 deletion tutorials/roostats/FourBinInstructional.C
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void FourBinInstructional(bool doBayesian = false, bool doFeldmanCousins = false
ProposalHelper ph;
ph.SetVariables((RooArgSet &)fit->floatParsFinal());
ph.SetCovMatrix(fit->covarianceMatrix());
ph.SetUpdateProposalParameters(kTRUE); // auto-create mean vars and add mappings
ph.SetUpdateProposalParameters(true); // auto-create mean vars and add mappings
ph.SetCacheSize(100);
ProposalFunction *pf = ph.GetProposalFunction();

Expand Down
2 changes: 1 addition & 1 deletion tutorials/roostats/FourBinInstructional.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
ph = ROOT.RooStats.ProposalHelper()
ph.SetVariables(fit.floatParsFinal())
ph.SetCovMatrix(fit.covarianceMatrix())
ph.SetUpdateProposalParameters(ROOT.kTRUE) # auto-create mean vars and add mappings
ph.SetUpdateProposalParameters(True) # auto-create mean vars and add mappings
ph.SetCacheSize(100)
pf = ph.GetProposalFunction()

Expand Down
7 changes: 0 additions & 7 deletions tutorials/roostats/HybridInstructional.C
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
/// - demonstrates usage of different test statistics
/// - explains subtle choices in the prior used for hybrid methods
/// - demonstrates usage of different priors for the nuisance parameters
/// - demonstrates usage of PROOF
///
/// The basic setup here is that a main measurement has observed x events with an
/// expectation of s+b. One can choose an ad hoc prior for the uncertainty on b,
Expand Down Expand Up @@ -130,9 +129,6 @@ void HybridInstructional(int ntoys = 6000)
// 5. RooStats ToyMC with an equivalent test statistic
// 6. RooStats ToyMC with simultaneous control & main measurement

// It takes ~4 min without PROOF and ~2 min with PROOF on 4 cores.
// Of course, everything looks nicer with more toys, which takes longer.

TStopwatch t;
t.Start();
TCanvas *c = new TCanvas;
Expand Down Expand Up @@ -427,9 +423,6 @@ void HybridInstructional(int ntoys = 6000)
w->var("s")->setVal(50.0); // IMPORTANT
sb_modelXY.SetSnapshot(*w->set("poi"));

// without this print, their can be a crash when using PROOF. Strange.
// w->Print();

// Test statistics like the profile likelihood ratio
// (or the ratio of profiled likelihoods (Tevatron) or the MLE for s)
// will now work, since the nuisance parameter b is constrained by y.
Expand Down
8 changes: 0 additions & 8 deletions tutorials/roostats/HybridInstructional.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# - demonstrates usage of different test statistics
# - explains subtle choices in the prior used for hybrid methods
# - demonstrates usage of different priors for the nuisance parameters
# - demonstrates usage of PROOF
#
# The basic setup here is that a main measurement has observed x events with an
# expectation of s+b. One can choose an ad hoc prior for the uncertainty on b,
Expand Down Expand Up @@ -113,10 +112,6 @@ class BinCountTestStat : public TestStatistic {
# 5. RooStats ToyMC with an equivalent test statistic
# 6. RooStats ToyMC with simultaneous control & main measurement

# It takes ~4 min without PROOF and ~2 min with PROOF on 4 cores.
# Of course, everything looks nicer with more toys, which takes longer.


t = ROOT.TStopwatch()
t.Start()
c = ROOT.TCanvas()
Expand Down Expand Up @@ -427,9 +422,6 @@ class BinCountTestStat : public TestStatistic {
# IMPORTANT
sb_modelXY.SetSnapshot(w.set("poi"))

# without this print, their can be a crash when using PROOF. Strange.
# w.Print()

# Test statistics like the profile likelihood ratio
# (or the ratio of profiled likelihoods (Tevatron) or the MLE for s)
# will now work, since the nuisance parameter b is constrained by y.
Expand Down
6 changes: 0 additions & 6 deletions tutorials/roostats/HybridStandardForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
# - demonstrates usage of different test statistics
# - explains subtle choices in the prior used for hybrid methods
# - demonstrates usage of different priors for the nuisance parameters
# - demonstrates usage of PROOF
#
# The basic setup here is that a main measurement has observed x events with an
# expectation of s+b. One can choose an ad hoc prior for the uncertainty on b,
Expand Down Expand Up @@ -135,11 +134,6 @@ class BinCountTestStat : public TestStatistic {
# 5. RooStats ToyMC with an equivalent test statistic
# 6. RooStats ToyMC with simultaneous control & main measurement

# Part 4 takes ~4 min without PROOF.
# Part 5 takes about ~2 min with PROOF on 4 cores.
# Of course, everything looks nicer with more toys, which takes longer.


t = ROOT.TStopwatch()
t.Start()
c = ROOT.TCanvas()
Expand Down
4 changes: 2 additions & 2 deletions tutorials/roostats/ModelInspector.C
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ ModelInspectorGUI::ModelInspectorGUI(RooWorkspace *w, ModelConfig *mc, RooAbsDat
TGLabel *hlabel =
new TGLabel(hframek, Form("%s = %.3f +%.3f", param->GetName(), param->getVal(), param->getError()));
TGTripleHSlider *hsliderk = new TGTripleHSlider(hframek, 190, kDoubleScaleBoth, HSId1, kHorizontalFrame,
GetDefaultFrameBackground(), kFALSE, kFALSE, kFALSE, kFALSE);
GetDefaultFrameBackground(), False, False, False, False);
hsliderk->Connect("PointerPositionChanged()", "ModelInspectorGUI", this, "DoSlider()");
hsliderk->Connect("PositionChanged()", "ModelInspectorGUI", this, "DoSlider()");
hsliderk->SetRange(param->getMin(), param->getMax());
Expand Down Expand Up @@ -508,7 +508,7 @@ void ModelInspector(const char *infile = "", const char *workspaceName = "combin
// Try to open the file
TFile *file = TFile::Open(filename);

// if input file was specified byt not found, quit
// if input file was specified but not found, quit
if (!file) {
cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
return;
Expand Down
Loading

0 comments on commit 66157b9

Please sign in to comment.