def create_plot(self,mode='ResolutionSingle'): self.plots ={} self.normPlots={} ROOT.gStyle.SetOptStat('e') c1 = TCanvas() c1.SetObjectStat(False) title = '' if self.config and self.config.has_option('PlotResolutionSingle','Title'): title = self.config.get('PlotResolutionSingle','Title') hs = ROOT.THStack("hs",title); hs_norm = ROOT.THStack("hs_norm",title); for runno in self.runnos: if self.config: name = self.config.get('MainResolutionSingle','histoName') else: name = 'hDiaTranspAnaPulseHeightOf2HighestIn10Strips' section = 'Main'+mode plot = utilities.get_plot(config,section,runno,self.rundes[runno],name) if plot == 0: print 'cannot find plot for %s'%runno continue plot.SetName(str(plot.GetName)+'%s'%runno) newPlot = plot newPlot.SetObjectStat(False) if self.config and self.config.has_option('PlotResolutionSingle','XTitle'): newPlot.GetXaxis().SetTitle(self.config.get('PlotResolutionSingle','XTitle')) if self.config and self.config.has_option('PlotResolutionSingle','YTitle'): newPlot.GetYaxis().SetTitle(self.config.get('PlotResolutionSingle','YTitle')) if self.config and self.config.has_option('PlotResolutionSingle','LegendTitle'): irr = self.get_irradiation(runno) newPlot.SetTitle(self.config.get('PlotResolutionSingle','LegendTitle') + '#Phi = %.2e p/cm^{2}'%irr ) for key in newPlot.GetListOfFunctions(): print key if 'stats' in key.GetName() : stats = newPlot.GetFunction(key.GetName()) stats.Delete() self.plots[runno] = newPlot c1.cd() index = self.runnos.index(runno) color = utilities.get_color(index) newPlot.SetLineColor(color) self.plots[runno] = newPlot norm = newPlot.GetBinContent(newPlot.GetMaximumBin()) newPlot.Scale(1./norm) normPlot = newPlot.DrawNormalized("") print normPlot normPlot = normPlot.Clone() normPlot.SetObjectStat(False) self.normPlots[runno]= normPlot hs.Add(newPlot) hs_norm.Add(normPlot) stacks = [hs,hs_norm] for stack in stacks: c1.Clear() c1.Update() c1.SetObjectStat(False) c1.Clear() stack.SetObjectStat(False) stack.Draw('nostack') print stack,type(stack) if stack: axis = stack.GetXaxis() if axis: if self.config and self.config.has_option('PlotResolutionSingle','XTitle'): axis.SetTitle(self.config.get('PlotResolutionSingle','XTitle')) if self.config and self.config.has_option('PlotResolutionSingle','XMin'): if self.config.has_option('PlotResolutionSingle','XMax'): minX = self.config.getfloat('PlotResolutionSingle','XMin') maxX = self.config.getfloat('PlotResolutionSingle','XMax') axis.SetRangeUser(minX,maxX) if self.config and self.config.has_option('PlotResolutionSingle','YTitle'): axis = stack.GetYaxis() if axis: axis.SetTitle(self.config.get('PlotResolutionSingle','YTitle')) stack.Draw('nostack') c1.Update() leg = c1.BuildLegend() leg.SetFillColor(ROOT.kWhite) c1.Update() self.canvas = c1 fileName = 'PW205B_resolution_%d'%stacks.index(stack) c1.SaveAs('%s_%s.png'%(fileName,self.mode)) c1.SaveAs('%s_%s.pdf'%(fileName,self.mode)) c1.SaveAs('%s_%s.root'%(fileName,self.mode))
def create_plot(self,mode='LandauSingle'): self.plots ={} self.normPlots={} c1 = TCanvas() title = '' if self.config and self.config.has_option('PlotLandauSingle','Title'): title = self.config.get('PlotLandauSingle','Title') hs = ROOT.THStack("hs",title); hs_norm = ROOT.THStack("hs_norm",title); for runno in self.runnos: if self.config: try: name = self.config.get('MainLandauSingle','histoName') except Exception as e: print self.config.options('MainLandauSingle') raise e else: name = 'hDiaTranspAnaPulseHeightOf2HighestIn10Strips' section = 'Main'+mode plot = utilities.get_plot(config,section,runno,self.rundes[runno],name) if plot == 0: print 'cannot find plot for %s'%runno continue plot.SetName(str(plot.GetName)+'%s'%runno) newPlot = utilities.convert_x_to_electrons(plot,self.get_conversion(runno)) if self.config and self.config.has_option('PlotLandauSingle','XTitle'): newPlot.GetXaxis().SetTitle(self.config.get('PlotLandauSingle','XTitle')) if self.config and self.config.has_option('PlotLandauSingle','YTitle'): newPlot.GetYaxis().SetTitle(self.config.get('PlotLandauSingle','YTitle')) if self.config and self.config.has_option('PlotLandauSingle','LegendTitle'): irr = self.get_irradiation(runno) newPlot.SetTitle(self.config.get('PlotLandauSingle','LegendTitle') + '#Phi = %.2e p/cm^{2}'%irr ) self.plots[runno] = newPlot c1.cd() index = self.runnos.index(runno) color = utilities.get_color(index) newPlot.SetLineColor(color) self.plots[runno] = newPlot norm = newPlot.GetBinContent(newPlot.GetMaximumBin()) newPlot.Scale(1./norm) normPlot = newPlot.DrawNormalized("") print normPlot normPlot = normPlot.Clone() self.normPlots[runno]= normPlot hs.Add(newPlot) hs_norm.Add(normPlot) stacks = [hs,hs_norm] for stack in stacks: c1.Clear() stack.Draw('nostack') if self.config and self.config.has_option('PlotLandauSingle','XTitle'): stack.GetXaxis().SetTitle(self.config.get('PlotLandauSingle','XTitle')) if self.config and self.config.has_option('PlotLandauSingle','YTitle'): stack.GetYaxis().SetTitle(self.config.get('PlotLandauSingle','YTitle')) stack.Draw('nostack') c1.Update() leg = c1.BuildLegend() leg.SetFillColor(ROOT.kWhite) c1.Update() self.canvas = c1 dia_name = self.config.get('Main','diamond') outputdir = './output/' fileName = outputdir+'%s_irradiation_%d'%(dia_name,stacks.index(stack)) c1.SaveAs('%s.png'%(fileName)) c1.SaveAs('%s.pdf'%(fileName)) c1.SaveAs('%s.root'%(fileName))