Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Impacts.py #996

Merged
merged 7 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 1 addition & 8 deletions python/tool_base/FastScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ def attach_args(self, group):
group.add_argument("-o", "--output", default="nll", help="Name of the output file, without the .pdf extension")
group.add_argument("-p", "--points", default=200, type=int, help="Number of NLL points to sample in each scan")

def RooColIter(self, coll):
it = coll.createIterator()
var = it.Next()
while var:
yield var
var = it.Next()

def run_method(self):
ROOT.gROOT.SetBatch(ROOT.kTRUE)
outfile = ROOT.TFile("%s.root" % self.args.output, "RECREATE")
Expand Down Expand Up @@ -83,7 +76,7 @@ def run_method(self):
page = 0
doPars = []

for par in self.RooColIter(pars):
for par in pars:
if par.isConstant():
continue
if self.args.match is not None:
Expand Down
27 changes: 20 additions & 7 deletions python/tool_base/Impacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ def run_method(self):

print("Have parameters: " + str(len(paramList)))

varList = utils.list_from_workspace(ws, "w", "variables")
if self.args.setParameters is not None:
set_parameters = self.args.setParameters.split(",")
set_parameters_str = ""
for ind, setParam in enumerate(set_parameters):
if "rgx{" in setParam:
eqs_to = setParam.split("=")[-1]
pattern = setParam.split("=")[0]
pattern = pattern.replace("'rgx{", "").replace("}'", "")
pattern = pattern.replace("rgx{", "").replace("}", "")
set_parameters[ind] = ""
for var in varList:
if re.search(pattern, var):
var_str = var + "=" + eqs_to
set_parameters_str += var_str + ","
else:
set_parameters_str += setParam + ","
self.args.setPhysicsModelParameters = set_parameters_str.rstrip(",")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is meant to be inside the if block starting on l.208, or else set_parameter_str doesn't exist.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for spotting this!


prefit = utils.prefit_from_workspace(ws, "w", paramList, self.args.setPhysicsModelParameters)
res = {}
if not self.args.noInitialFit:
Expand Down Expand Up @@ -264,15 +283,9 @@ def run_method(self):
print("Missing inputs: " + ",".join(missing))

def all_free_parameters(self, file, wsp, mc, pois):
res = []
wsFile = ROOT.TFile.Open(file)
w = wsFile.Get(wsp)
config = w.genobj(mc)
pdfvars = config.GetPdf().getParameters(config.GetObservables())
it = pdfvars.createIterator()
var = it.Next()
while var:
if var.GetName() not in pois and (not var.isConstant()) and var.InheritsFrom("RooRealVar"):
res.append(var.GetName())
var = it.Next()
res = [var.GetName() for var in pdfvars if (var.GetName() not in pois and (not var.isConstant()) and var.InheritsFrom("RooRealVar"))]
return res
9 changes: 2 additions & 7 deletions python/tool_base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ def split_vals(vals, fmt_spec=None):

def list_from_workspace(file, workspace, set):
"""Create a list of strings from a RooWorkspace set"""
res = []
wsFile = ROOT.TFile(file)
ws = wsFile.Get(workspace)
argSet = ws.set(set)
it = argSet.createIterator()
var = it.Next()
while var:
res.append(var.GetName())
var = it.Next()
argSet = ws.allVars() if set == "variables" else ws.set(set)
res = [var.GetName() for var in argSet]
return res


Expand Down
Loading