def individualPlots(self, plotSpecs, newSampleNames = {}, cms = True, preliminary = True, tdrStyle = True) : def goods(spec) : for item in ["stepName", "stepDesc", "plotName"] : if item not in spec : return histoList = [] nMasters = [step.name for step in self.someOrganizer.steps].count("master") if nMasters!=2 : print "I have %d master step(s)."%nMasters for step in self.someOrganizer.steps : if (spec["stepName"], spec["stepDesc"]) not in [(step.name, step.title), (step.name,None)] : continue if spec["plotName"] not in step : continue histoList.append(step[spec["plotName"]]) assert histoList,"Failed %s"%str(spec) histos = histoList[spec["index"] if "index" in spec else 0] if "sampleWhiteList" not in spec : return histos,None else : return histos,[not (sample["name"] in spec["sampleWhiteList"]) for sample in self.someOrganizer.samples] def onlyDumpToFile(histos, spec) : if "onlyDumpToFile" in spec and spec["onlyDumpToFile"] : rootFileName = self.pdfFileName.replace(".pdf","_%s.root"%spec["plotName"]) f = r.TFile(rootFileName, "RECREATE") for h in histos : h.Write() f.Close() print "The output file \"%s\" has been written."%rootFileName return True return False def rebin(h, spec) : if "reBinFactor" in spec : for histo in h : if histo!=None : histo.Rebin(spec["reBinFactor"]) def setTitles(h, spec) : if "newTitle" in spec : for histo in h : histo.SetTitle(spec["newTitle"]) def stylize(h) : for histo in h : histo.UseCurrentStyle() def setRanges(h, spec) : for item in ["xRange", "yRange"] : if item not in spec : continue for histo in h : method = "Get%saxis"%item[0].capitalize() getattr(histo, method)().SetRangeUser(*spec[item]) print utils.hyphens if tdrStyle : self.setupTdrStyle() for spec in plotSpecs : histos,ignoreHistos = goods(spec) if histos==None : continue if onlyDumpToFile(histos, spec) : continue rebin(histos, spec) setRanges(histos, spec) setTitles(histos, spec) stylize(histos) individual = {"legendCoords": (0.55, 0.55, 0.85, 0.85), "reverseLegend": False, "stampCoords": (0.75, 0.5), "ignoreHistos": ignoreHistos, "newSampleNames" : newSampleNames, "legendTitle" : "" } for key in spec : if key in individual.keys()+["order"] : individual[key] = spec[key] stuff,pads = self.onePlotFunction(histos, individual = individual) if ("stamp" not in spec) or spec["stamp"] : utils.cmsStamp(lumi = self.someOrganizer.lumi, cms = cms, preliminary = preliminary, coords = individual["stampCoords"]) args = {"name":spec["plotName"], "tight":False,#self.anMode "alsoC":spec["alsoC"] if "alsoC" in spec else False, } if "sampleName" in spec : sampleName = spec["sampleName"] assert sampleName in pads,str(pads) args["name"] += "_%s"%sampleName.replace(" ","_") args["padNumber"] = pads[sampleName] setTitles(histos, spec) #to allow for overwriting global title self.printOnePage(**args) print utils.hyphens
def individualPlots(self, plotSpecs, newSampleNames = {}, preliminary = True, tdrStyle = True) : def goods(spec) : for item in ["stepName", "stepDesc", "plotName"] : if item not in spec : return histoList = [] nMasters = [step.name for step in self.someOrganizer.steps].count("Master") if nMasters!=1 : print "I have %d Master step(s)."%nMasters for step in self.someOrganizer.steps : if (step.name, step.title) != (spec["stepName"], spec["stepDesc"]) : continue if spec["plotName"] not in step : continue histoList.append(step[spec["plotName"]]) assert histoList,str(spec) histos = histoList[spec["index"] if "index" in spec else 0] if "sampleWhiteList" not in spec : return histos,None else : return histos,[not (sample["name"] in spec["sampleWhiteList"]) for sample in self.someOrganizer.samples] def onlyDumpToFile(histos, spec) : if "onlyDumpToFile" in spec and spec["onlyDumpToFile"] : rootFileName = self.psFileName.replace(".ps","_%s.root"%spec["plotName"]) f = r.TFile(rootFileName, "RECREATE") for h in histos : h.Write() f.Close() print "The output file \"%s\" has been written."%rootFileName return True return False def rebin(h, spec) : if "reBinFactor" in spec : for histo in h : if histo!=None : histo.Rebin(spec["reBinFactor"]) def setTitles(h, spec) : if "newTitle" in spec : for histo in h : histo.SetTitle(spec["newTitle"]) def stylize(h) : for histo in h : histo.UseCurrentStyle() print utils.hyphens if tdrStyle : setupTdrStyle() for spec in plotSpecs : histos,ignoreHistos = goods(spec) if histos==None : continue if onlyDumpToFile(histos, spec) : continue rebin(histos, spec) setTitles(histos, spec) stylize(histos) legendCoords = spec["legendCoords"] if "legendCoords" in spec else (0.55, 0.55, 0.85, 0.85) stampCoords = spec["stampCoords"] if "stampCoords" in spec else (0.75, 0.5) stuff,pads = self.onePlotFunction(histos, ignoreHistos, newSampleNames, legendCoords, individual = True) if ("stamp" not in spec) or spec["stamp"] : utils.cmsStamp(lumi = self.someOrganizer.lumi, preliminary = preliminary, coords = stampCoords) args = {"name":spec["plotName"], "tight":False,#self.anMode } if "sampleName" in spec : sampleName = spec["sampleName"] assert sampleName in pads,str(pads) args["name"] += "_%s"%sampleName.replace(" ","_") args["padNumber"] = pads[sampleName] setTitles(histos, spec) #to allow for overwriting global title self.printOnePage(**args) print utils.hyphens
def individualPlots(self, plotSpecs, newSampleNames = {}, preliminary = True) : def goods(spec) : for item in ["stepName", "stepDesc", "plotName"] : if item not in spec : return histoList = [] for step in self.someOrganizer.steps : if (step.name, step.title) != (spec["stepName"], spec["stepDesc"]) : continue if spec["plotName"] not in step : continue histoList.append(step[spec["plotName"]]) assert histoList,str(spec) histos = histoList[spec["index"] if "index" in spec else 0] if "sampleWhiteList" not in spec : return histos,None else : return histos,[not (sample["name"] in spec["sampleWhiteList"]) for sample in self.someOrganizer.samples] def onlyDumpToFile(histos, spec) : if "onlyDumpToFile" in spec and spec["onlyDumpToFile"] : rootFileName = self.psFileName.replace(".ps","_%s.root"%spec["plotName"]) f = r.TFile(rootFileName, "RECREATE") for h in histos : h.Write() f.Close() print "The output file \"%s\" has been written."%rootFileName return True return False def rebin(h, spec) : if "reBinFactor" in spec : for histo in h : if histo!=None : histo.Rebin(spec["reBinFactor"]) def setTitles(h, spec) : if "newTitle" in spec : for histo in h : histo.SetTitle(spec["newTitle"]) def stylize(h) : for histo in h : histo.UseCurrentStyle() print utils.hyphens setupTdrStyle() for spec in plotSpecs : histos,ignoreHistos = goods(spec) if histos==None : continue if onlyDumpToFile(histos, spec) : continue rebin(histos, spec) setTitles(histos, spec) stylize(histos) legendCoords = spec["legendCoords"] if "legendCoords" in spec else (0.55, 0.55, 0.85, 0.85) stampCoords = spec["stampCoords"] if "stampCoords" in spec else (0.75, 0.5) stuff = self.onePlotFunction(histos, ignoreHistos, newSampleNames, legendCoords, individual = True) utils.cmsStamp(lumi = self.someOrganizer.lumi, preliminary = preliminary, coords = stampCoords) self.printOnePage(spec["plotName"], tight = False)#self.anMode) print utils.hyphens