Skip to content
Open
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
22 changes: 11 additions & 11 deletions tutorials/roofit/roostats/StandardHypoTestInvDemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#
# \author Lorenzo Moneta (C++ version), and P. P. (Python translation)

import ROOT
import os

Check failure on line 37 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:36:1: I001 Import block is un-sorted or un-formatted help: Organize imports


# structure defining the options
Expand Down Expand Up @@ -176,7 +176,7 @@

# RooStats.HypoTestInvTool.SetParameter(name, value):
# def SetParameter(self, name, value):
elif (type(name) is str) and (type(value) is bool):
elif (type(name) is str) and (type(value) is int):

#
# set integer parameters
Expand Down Expand Up @@ -220,7 +220,7 @@

# RooStats.HypoTestInvTool.SetParameter(name, value):
# def SetParameter(self, name, value):
elif (type(name) is str) and (type(value) is (float or double)):
elif (type(name) is str) and (type(value) is float):

#
# set string parameters
Expand Down Expand Up @@ -268,17 +268,17 @@
# ROOT.std::cout << "DEBUG : [ " << lowerLimit << " , " << upperLimit << " ] " << ROOT.std::endl;

if lowerLimit < upperLimit * (1.0 - 1.0e-4) and lowerLimit != 0:
print(f"The computed lower limit is: ", lowerLimit, " +/- ", llError)

Check failure on line 271 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F541)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:271:19: F541 f-string without any placeholders help: Remove extraneous `f` prefix

print(f"The computed upper limit is: {upperLimit} +/- ", ulError)

# compute expected limit
print(f"Expected upper limits, using the B (alternate) model : ")

Check failure on line 276 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F541)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:276:15: F541 f-string without any placeholders help: Remove extraneous `f` prefix
print(f" expected limit (median) ", r.GetExpectedUpperLimit(0))

Check failure on line 277 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F541)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:277:15: F541 f-string without any placeholders help: Remove extraneous `f` prefix
print(f" expected limit (-1 sig) ", r.GetExpectedUpperLimit(-1))

Check failure on line 278 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F541)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:278:15: F541 f-string without any placeholders help: Remove extraneous `f` prefix
print(f" expected limit (+1 sig) ", r.GetExpectedUpperLimit(1))

Check failure on line 279 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F541)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:279:15: F541 f-string without any placeholders help: Remove extraneous `f` prefix
print(f" expected limit (-2 sig) ", r.GetExpectedUpperLimit(-2))

Check failure on line 280 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F541)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:280:15: F541 f-string without any placeholders help: Remove extraneous `f` prefix
print(f" expected limit (+2 sig) ", r.GetExpectedUpperLimit(2))

Check failure on line 281 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F541)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:281:15: F541 f-string without any placeholders help: Remove extraneous `f` prefix

# detailed output
if self.mEnableDetOutput:
Expand Down Expand Up @@ -310,11 +310,11 @@
ulDist = 0
existULDist = not ROOT.gSystem.AccessPathName(uldistFile)
if existULDist:
fileULDist = TFile.Open(uldistFile)

Check failure on line 313 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F821)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:313:30: F821 Undefined name `TFile`
if fileULDist:
ulDist = fileULDist.Get("RULDist")

fileOut = TFile(self.mResultFileName, "RECREATE")

Check failure on line 317 in tutorials/roofit/roostats/StandardHypoTestInvDemo.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F821)

tutorials/roofit/roostats/StandardHypoTestInvDemo.py:317:23: F821 Undefined name `TFile`
r.Write()
if ulDist:
ulDist.Write()
Expand Down Expand Up @@ -524,7 +524,7 @@
doFit = self.mInitialFit
if testStatType == 0 and self.mInitialFit == -1:
doFit = False # case of LEP test statistic
if type == 3 and self.mInitialFit == -1:
if Type == 3 and self.mInitialFit == -1:
doFit = False # case of Asymptoticcalculator with nominal Asimov
poihat = 0

Expand Down Expand Up @@ -765,7 +765,7 @@
hhc = HybridCalculator(hc)
assert hhc

hhc.SetToys(ntoys, ntoys / self.mNToysRatio) # can use less ntoys for b hypothesis
hhc.SetToys(ntoys, int(ntoys / self.mNToysRatio)) # can use less ntoys for b hypothesis

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hhc.SetToys(ntoys, int(ntoys / self.mNToysRatio)) # can use less ntoys for b hypothesis
hhc.SetToys(ntoys, ntoys // self.mNToysRatio) # can use less ntoys for b hypothesis

Instead of converting the result to int, I'd prefer integer division directly


# remove global observables from ModelConfig (this is probably not needed anymore in 5.32)
bModel.SetGlobalObservables(RooArgSet())
Expand Down Expand Up @@ -813,11 +813,11 @@
nuisPdf.Print()

nuisParams = (
ibModel.GetNuisanceParameters()
bModel.GetNuisanceParameters()
if (bModel.GetNuisanceParameters())
else (sbModel.GetNuisanceParameters())
)
npnuisPdf.getObservables(nuisParams)
np = npnuisPdf.getObservables(nuisParams)
if np.getSize() == 0:
ROOT.Warning(
"StandardHypoTestInvDemo",
Expand All @@ -827,21 +827,21 @@
hhc.ForcePriorNuisanceAlt(nuisPdf)
hhc.ForcePriorNuisanceNull(nuisPdf)

elif type == 2 or type == 3:
elif Type == 2 or Type == 3:
if testStatType == 3:
hc.SetOneSided(True)
if testStatType != 2 and testStatType != 3:
ROOT.Warning(
"StandardHypoTestInvDemo",
"Only the PL test statistic can be used with AsymptoticCalculator - use by default a two-sided PL",
)
elif type == 0:
hc.SetToys(ntoys, ntoys / self.mNToysRatio)
elif Type == 0:
hc.SetToys(ntoys, int(ntoys / self.mNToysRatio))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hc.SetToys(ntoys, int(ntoys / self.mNToysRatio))
hc.SetToys(ntoys, ntoys // self.mNToysRatio)

# store also the fit information for each poi point used by calculator based on toys
if self.mEnableDetOutput:
hc.StoreFitInfo(True)
elif type == 1:
hc.SetToys(ntoys, ntoys / self.mNToysRatio)
elif Type == 1:
hc.SetToys(ntoys, int(ntoys / self.mNToysRatio))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hc.SetToys(ntoys, int(ntoys / self.mNToysRatio))
hc.SetToys(ntoys, ntoys // self.mNToysRatio)

# store also the fit information for each poi point used by calculator based on toys
# if (self.mEnableDetOutput):
# hc.StoreFitInfo(True)
Expand Down
Loading