def _obtainShapeHistograms(self, i, dataPath, ewkPath, dsetMgr, plotName, luminosity, normFactors): self.Verbose("_obtainShapeHistograms()", True) if self._verbose: self.PrintShapeInputSummary(dataPath, ewkPath, dsetMgr, plotName, luminosity, normFactors) self.Verbose("Obtain the (pre-normFactor) shape %s as \"DataDrivenQCDShape\" type object" % (plotName), True) myShape = dataDrivenQCDCount.DataDrivenQCDShape(dsetMgr, "Data", "EWK", plotName, dataPath, ewkPath, luminosity, self._useInclusiveNorm, self._verbose) if self._verbose: msg = "Printing TH1s (before NormFactors) of \"Data\", \"Data-Driven QCD\", \"EWK\", and \"Bin-by\Bin Purity\" and \"Integrated Purity\"" self.Print(msg, True) PrintTH1Info(myShape.getIntegratedDataHisto()) PrintTH1Info(myShape.getIntegratedDataDrivenQCDHisto()) #Data-EWK. NormFactor not applied PrintTH1Info(myShape.getIntegratedEwkHisto()) PrintTH1Info(myShape.getPurityHisto()) # Splitted-bin (disabled for Inclusive mode) PrintTH1Info(myShape.getIntegratedPurityForShapeHisto()) self.PrintShapePuritySummary(myShape) self.Verbose("Obtain the (post-normFactor) shape %s as \"QCDInvertedShape\" type object (Takes \"DataDrivenQCDShape\" type object as argument)" % (plotName), True) moduleInfo = self._moduleInfoString + "_" + plotName myPlot= QCDInvertedShape(myShape, moduleInfo, normFactors, optionUseInclusiveNorm=self._useInclusiveNorm) myPlot.PrintSettings(printHistos=self._verbose, verbose=self._verbose) # Define histogram name as will be written in the ROOT file self.Verbose("%sDefining the name of histogram objects, as they will appear in the ROOT file%s" % (ShellStyles.WarningStyle(), ShellStyles.NormalStyle()), True) hName = plotName + "%d" %i hTitle = plotName.replace("CRSelections", "AllSelections").replace("Baseline_", "").replace("Inverted_", "")#FIXME: not elegant! # DataDriven myShape.delete() myPlotHisto = aux.Clone(myPlot.getResultShape(), "ctrlPlotShapeInManager") myPlot.delete() myPlotHisto.SetName(hName) myPlotHisto.SetTitle(hTitle) self._shapePlots.append(myPlotHisto) self._shapePlotLabels.append(myPlotHisto.GetTitle())# this is the name the object will have in the ROOT file # MC EWK hName = plotName + "%d_MCEWK" %i myPlotMCEWKHisto = aux.Clone(myPlot.getResultMCEWK(), "ctrlPlotMCEWKInManager") myPlotMCEWKHisto.SetName(hName) myPlotMCEWKHisto.SetTitle(hTitle + "_MCEWK") self._shapePlots.append(myPlotMCEWKHisto) self._shapePlotLabels.append(myPlotMCEWKHisto.GetTitle())# this is the name the object will have in the ROOT file # Purity hName = plotName + "%d_Purity" %i #self.Print("myPlot.getResultPurity().GetName() = %s" % myPlot.getResultPurity().GetName(), True) #self.Print("myPlot.getResultPurity().GetIntegral() = %s" % myPlot.getResultPurity().Integral(), True) myPlotPurityHisto = aux.Clone(myPlot.getResultPurity(), "ctrlPlotPurityInManager") myPlotPurityHisto.SetName(hName) myPlotPurityHisto.SetTitle(hTitle + "_Purity") self._shapePlots.append(myPlotPurityHisto) self._shapePlotLabels.append(myPlotPurityHisto.GetTitle())# this is the name the object will have in the ROOT file return myPlotHisto
import HiggsAnalysis.NtupleAnalysis.tools.plots as plots import HiggsAnalysis.NtupleAnalysis.tools.styles as styles import HiggsAnalysis.Keras_ANN.results as _results import HiggsAnalysis.NtupleAnalysis.tools.ShellStyles as ShellStyles import HiggsAnalysis.NtupleAnalysis.tools.aux as aux #================================================================================================ # Shell Types #================================================================================================ sh_e = ShellStyles.ErrorStyle() sh_s = ShellStyles.SuccessStyle() sh_h = ShellStyles.HighlightStyle() sh_a = ShellStyles.HighlightAltStyle() sh_t = ShellStyles.NoteStyle() sh_n = ShellStyles.NormalStyle() sh_w = ShellStyles.WarningStyle() #================================================================================================ # Function definition #================================================================================================ def Verbose(msg, printHeader=False): ''' Calls Print() only if verbose options is set to true. ''' if not opts.verbose: return Print(msg, printHeader) return
def doPlot(opts, mass, nameList, allShapeNuisances, luminosity, myDatacardPattern, rootFilePattern, signalTable): fName = rootFilePattern % mass Verbose("Opening ROOT file %s" % (fName), True) f = ROOT.TFile.Open(fName) content = f.GetListOfKeys() # Suppress the warning message of missing dictionary for some iterator backup = ROOT.gErrorIgnoreLevel ROOT.gErrorIgnoreLevel = ROOT.kError diriter = content.MakeIterator() ROOT.gErrorIgnoreLevel = backup # Find the datacard and nuisance names myCardReader = DatacardReader.DataCardReader(".", mass, myDatacardPattern, rootFilePattern) myDatasetNames = myCardReader.getDatasetNames() # Find the name stem and the name of the uncertainties datasets = [] shapes = [] for d in myDatasetNames: myLabel = d myStatus = not d in nameList if d == myDatasetNames[0]: myStatus = True if not str(mass) in d: myLabel = "%sm%d" % (d, mass) myShapeNuisanceNames = myCardReader.getShapeNuisanceNames(d) myFilteredShapeNuisances = [] for n in myShapeNuisanceNames: if not "statBin" in n and not n.endswith( "_statUp") and not n.endswith("_statDown"): myFilteredShapeNuisances.append(n) if myStatus: myDataset = DatasetContainer(column=d, label=myLabel, nuisances=myFilteredShapeNuisances, cardReader=myCardReader, verbose=opts.verbose) datasets.append(myDataset) nameList.append(d) for n in myFilteredShapeNuisances: if not n in shapes: shapes.append(n) rebinList = None if opts.h2tb: rebinList = systematics._dataDrivenCtrlPlotBinning[ "LdgTetrajetMass_AfterAllSelections"] ## Do the actual plots myDsets = [ "Hp%s" % (mass), "FakeB", "TT_GenuineB", "SingleTop_GenuineB", "EWK_GenuineB", "ttX_GenuineB" ] for i, d in enumerate(datasets, 1): if d.GetName() not in myDsets: msg = "Skipping dataset %s" % (d.GetName()) Print(ShellStyles.WarningStyle() + msg + ShellStyles.NormalStyle(), False) continue if opts.verbose: d.debug() msg = "{:>10}, {:<20}".format("m = %d GeV" % (mass), d.GetName()) if i < len(datasets): Print( ShellStyles.HighlightAltStyle() + msg + ShellStyles.NormalStyle(), False) else: Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), False) d.doPlot(opts, shapes, f, mass, luminosity, signalTable, rebinList) Verbose("Closing ROOT file %s" % (fName), True) f.Close()