Skip to content

Commit

Permalink
Merge pull request cms-analysis#739 from amarini/102x_port661
Browse files Browse the repository at this point in the history
102x port 661
  • Loading branch information
amarini authored Apr 5, 2022
2 parents 05652ed + 82c1f68 commit 81e2576
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions python/DatacardParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def addDatacardParserOptions(parser):
parser.add_option("--no-wrappers", dest="noHistFuncWrappers", default=False, action="store_true", help="Do not create and save the CMSHistFuncWrapper objects for autoMCStats-based models (saves time)")
parser.add_option("--use-histsum", dest="useCMSHistSum", default=False, action="store_true", help="Use memory-optimized CMSHistSum instead of CMSHistErrorPropagator")
parser.add_option("--no-optimize-pdfs", dest="noOptimizePdf", default=False, action="store_true", help="Do not save the RooSimultaneous as RooSimultaneousOpt and Gaussian constraints as SimpleGaussianConstraint")
parser.add_option("--no-data", dest="noData", default=False, action="store_true", help="Do not save the RooDataSet in the ouput workspace")
parser.add_option("--optimize-simpdf-constraints", dest="moreOptimizeSimPdf", default="none", type="string", help="Handling of constraints in simultaneous pdf: 'none' = add all constraints on all channels (default); 'lhchcg' = add constraints on only the first channel; 'cms' = add constraints to the RooSimultaneousOpt.")
#parser.add_option("--use-HistPdf", dest="useHistPdf", type="string", default="always", help="Use RooHistPdf for TH1s: 'always' (default), 'never', 'when-constant' (i.e. not when doing template morphing)")
parser.add_option("--channel-masks", dest="doMasks", default=False, action="store_true", help="Create channel-masking RooRealVars")
Expand Down
15 changes: 11 additions & 4 deletions python/ShapeTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def doObservables(self):
else:
self.out.obs = self.out.binVars
self.doSet("observables",self.out.obs)
if len(self.DC.obs) != 0:
if len(self.DC.obs) != 0 and not self.options.noData:
self.doCombinedDataset()
def doIndividualModels(self):
if self.options.verbose:
Expand Down Expand Up @@ -158,7 +158,10 @@ def doIndividualModels(self):
parname = n
self.out._import(arg)
if arg.getAttribute("createGaussianConstraint"):
self.doObj("%s_Pdf" % n, "SimpleGaussianConstraint", "%s, %s_In[0,%s], %s" % (n, n, '-7,7', '1.0'), True)
if self.options.noOptimizePdf:
self.doObj("%s_Pdf" % n, "Gaussian", "%s, %s_In[0,%s], %s" % (n, n, '-7,7', '1.0'), True)
else:
self.doObj("%s_Pdf" % n, "SimpleGaussianConstraint", "%s, %s_In[0,%s], %s" % (n, n, '-7,7', '1.0'), True)
self.out.var(n).setVal(0)
self.out.var(n).setError(1)
if self.options.optimizeBoundNuisances: self.out.var(n).setAttribute("optimizeBounds")
Expand Down Expand Up @@ -202,7 +205,11 @@ def doIndividualModels(self):
if not self.options.noBOnly: sum_b.setAttribute('forceGen'+self.pdfModes[b].title())
addSyst = False
if self.options.moreOptimizeSimPdf == "none": addSyst = True
elif self.options.moreOptimizeSimPdf == "lhchcg": addSyst = (i > 1)
# New behaviour for "lhchcg" mode - since autoMCStats constraints are only added to their respective channels,
# we can't get away with only adding a constraint production to the first channel. Instead we will always enter
# the code block below (addSyst=True), and only add the normal nuisPdfs on i==0, while the binconstraints will
# always be added.
elif self.options.moreOptimizeSimPdf == "lhchcg": addSyst = True
elif self.options.moreOptimizeSimPdf == "cms":
if self.options.noOptimizePdf: raise RuntimeError, "--optimize-simpdf-constraints=cms is incompatible with --no-optimize-pdfs"
addSyst = False
Expand All @@ -213,7 +220,7 @@ def doIndividualModels(self):
self.renameObj("pdf_bin%s_bonly" % b, "pdf_bin%s_bonly_nuis" % b)
# now we multiply by all the nuisances, but avoiding nested products
# so we first make a list of all nuisances plus the RooAddPdf
if len(self.DC.systs):
if len(self.DC.systs) and not (self.options.moreOptimizeSimPdf == "lhchcg" and i > 0):
sumPlusNuis_s = ROOT.RooArgList(self.out.nuisPdfs)
else:
sumPlusNuis_s = ROOT.RooArgList()
Expand Down

0 comments on commit 81e2576

Please sign in to comment.