Example #1
0
 def user_DisplayParameter(self,parameter):
     if parameter=="weight":
         logging.info("   User-imposed weight of the set = "+str(self.weight))
     elif parameter=="xsection":
         logging.info("   User-imposed cross section = "+str(self.xsection))
     elif parameter=="type":
         logging.info("   Type = "+self.GetStringTag())
     elif parameter=="weighted_events":
         if self.weighted_events:
             logging.info("   Taking account of event weight: true")
         else:
             logging.info("   Taking account of event weight: false")
     elif parameter=="title":
         logging.info("   Title = '"+self.title+"'")
     elif parameter=="linecolor":
         msg=ColorType.convert2string(self.linecolor)
         if self.lineshade!=0 and self.linecolor!=ColorType.AUTO:
             if self.lineshade>0:
                 msg+="+"+str(self.lineshade)
             else:
                 msg+=str(self.lineshade)
         logging.info("   Line color in histograms = "+msg)
     elif parameter=="linestyle":
         logging.info("   Line style in histograms = "+LineStyleType.convert2string(self.linestyle))
     elif parameter=="linewidth":
         logging.info("   Line width in histograms = "+str(self.linewidth))
     elif parameter=="backcolor":
         msg=ColorType.convert2string(self.backcolor)
         if self.backshade!=0 and self.backcolor!=ColorType.AUTO:
             if self.backshade>0:
                 msg+="+"+str(self.backshade)
             else:
                 msg+=str(self.backshade)
         logging.info("   Background color in histograms = "+msg)
     elif parameter=="backstyle":
         logging.info("   Background style in histograms = "+BackStyleType.convert2string(self.backstyle))
     else:
         logging.error(" the class dataset has no attribute denoted by '"+parameter+"'")
Example #2
0
    def Draw(self,histos,scales,ref,irelhisto,preview=False):

        from ROOT import TH1
        from ROOT import TH1F
        from ROOT import THStack
        from ROOT import TLegend
        from ROOT import TCanvas

        # Creating a canvas
        canvas = TCanvas("tempo","")

        # Special case : NPID, NAPID
        if ref.observable.name in ['NPID','NAPID']:

            # New collection with labels
            labels=[]
            
            # Loop over histos
            for ind in range(len(histos)):
                nBins = histos[ind].GetNbinsX()
                for b in range(1,nBins+1):
                    # Get the bin label
                    theLabel = histos[ind].GetXaxis().GetBinLabel(b)
                    # Add in the collection 
                    if theLabel not in labels:
                        labels.append(theLabel)
                        
            # Sorting labels (alphabetical order)
            labels = sorted(labels)

            # New histos
            newhistos = []
            for ind in range(len(histos)):

                nBins = histos[ind].GetNbinsX()

                # New histo
                newhisto = TH1F(histos[ind].GetName()+'_'+str(ind),\
                                histos[ind].GetTitle(),\
                                len(labels),
                                0,
                                len(labels))
                for ilabel in range(len(labels)):

                    # Set new labels
                    newhisto.GetXaxis().SetBinLabel(ilabel+1,labels[ilabel])
                    
                    fill=False 
                    for bin in range(1,nBins+1):
                        # Get the bin label
                        if histos[ind].GetXaxis().GetBinLabel(bin)==labels[ilabel]:
                            tmp = histos[ind].GetBinContent(bin)
                            newhisto.SetBinContent(ilabel+1,tmp)
                            fill=True
                            break
                    if not fill:
                        newhisto.SetBinContent(ilabel+1,0)
                        
                newhistos.append(newhisto)

            # overwrite histos
            histos=newhistos

        # Loop over datasets and histos
        for ind in range(0,len(histos)):

            if ref.observable.name in ['NPID','NAPID']:
                nBins = histos[ind].GetNbinsX()
                for b in range(1,nBins+1):
                    pid = int(histos[ind].GetXaxis().GetBinLabel(b))
                    if ref.observable.name=='NPID':
                        spid = self.main.multiparticles.GetName(pid)
                    else:
                        spid = self.main.multiparticles.GetAName(-pid,pid)
                    if spid!="":
                        histos[ind].GetXaxis().SetBinLabel(b,spid)

            # Scaling 
            histos[ind].Scale(scales[ind])
            
        # Stacking or superimposing histos ?
        stackmode = False
        if ref.stack==StackingMethodType.STACK or \
           ( ref.stack==StackingMethodType.AUTO and \
             self.main.stack==StackingMethodType.STACK ):
            stackmode=True

        # Setting AUTO settings
        if len(histos)==1:
            histos[0].SetLineColor(9)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
        elif len(histos)==2:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
        elif len(histos)==3:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
        elif len(histos)==4:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
        elif len(histos)==5:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
        elif len(histos)==6:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
        elif len(histos)==7:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            histos[6].SetLineColor(7)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
                histos[6].SetFillColor(7)
                histos[6].SetFillStyle(3022)
        elif len(histos)==8:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            histos[6].SetLineColor(7)
            histos[7].SetLineColor(3)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
                histos[6].SetFillColor(7)
                histos[6].SetFillStyle(3022)
                histos[7].SetFillColor(3)
                histos[7].SetFillStyle(3315)
        elif len(histos)==9:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            histos[6].SetLineColor(7)
            histos[7].SetLineColor(3)
            histos[8].SetLineColor(42)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
                histos[6].SetFillColor(7)
                histos[6].SetFillStyle(3022)
                histos[7].SetFillColor(3)
                histos[7].SetFillStyle(3315)
                histos[8].SetFillColor(42)
                histos[8].SetFillStyle(3351)
        elif len(histos)==10:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            histos[6].SetLineColor(7)
            histos[7].SetLineColor(3)
            histos[8].SetLineColor(42)
            histos[9].SetLineColor(48)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
                histos[6].SetFillColor(7)
                histos[6].SetFillStyle(3022)
                histos[7].SetFillColor(3)
                histos[7].SetFillStyle(3315)
                histos[8].SetFillColor(42)
                histos[8].SetFillStyle(3351)
                histos[9].SetFillColor(48)
                histos[9].SetFillStyle(3481)
        else:
            histos[ind].SetLineColor(self.color)
            self.color += 1

        # Setting USER color
        for ind in range(0,len(histos)):

            # linecolor
            if self.main.datasets[ind].linecolor!=ColorType.AUTO:
                histos[ind].SetLineColor(ColorType.convert2root( \
                self.main.datasets[ind].linecolor,\
                self.main.datasets[ind].lineshade))

            # lineStyle
            histos[ind].SetLineStyle(LineStyleType.convert2code( \
                self.main.datasets[ind].linestyle))

            # linewidth
            histos[ind].SetLineWidth(self.main.datasets[ind].linewidth)

            # background color  
            if self.main.datasets[ind].backcolor!=ColorType.AUTO:
                histos[ind].SetFillColor(ColorType.convert2root( \
                self.main.datasets[ind].backcolor,\
                self.main.datasets[ind].backshade))

            # background color  
            if self.main.datasets[ind].backstyle!=BackStyleType.AUTO:
                histos[ind].SetFillStyle(BackStyleType.convert2code( \
                self.main.datasets[ind].backstyle))

        # Creating and filling the stack; computing the total number of events
        stack = THStack("mystack","")
        ntot = 0
        for item in histos:
            ntot+=item.GetEntries()
            stack.Add(item)

        # Drawing
        if stackmode:
            stack.Draw()
        else:
            stack.Draw("nostack")

        # Setting Y axis label
        axis_titleY = ref.GetYaxis()

        # Scale to one ?
        scale2one = False
        if ref.stack==StackingMethodType.NORMALIZE2ONE or \
           (self.main.stack==StackingMethodType.NORMALIZE2ONE and \
           ref.stack==StackingMethodType.AUTO):
            scale2one = True

        if scale2one:
            axis_titleY += " ( scaled to one )"
        elif self.main.normalize == NormalizeType.LUMI or \
           self.main.normalize == NormalizeType.LUMI_WEIGHT:
            axis_titleY += " ( L_{int} = " + str(self.main.lumi)+ " fb^{-1} )"
        elif self.main.normalize == NormalizeType.NONE:
            axis_titleY += " (not normalized)"

        if ref.titleY!="": 
            axis_titleY = self.NiceTitle(ref.titleY)

        stack.GetYaxis().SetTitle(axis_titleY)
        if(len(axis_titleY) > 35): 
           stack.GetYaxis().SetTitleSize(0.04)
        else:
           stack.GetYaxis().SetTitleSize(0.06)
        stack.GetYaxis().SetTitleFont(22)
        stack.GetYaxis().SetLabelSize(0.04)

        # Setting X axis label
        if ref.titleX=="": 
            axis_titleX = ref.GetXaxis()
        else:
            axis_titleX = self.NiceTitle(ref.titleX)
        
        # Setting X axis label
        stack.GetXaxis().SetTitle(axis_titleX)
        stack.GetXaxis().SetTitleSize(0.06)
        stack.GetXaxis().SetTitleFont(22)
        stack.GetXaxis().SetLabelSize(0.04)

        # Setting Log scale
        if ref.logX and ntot != 0:
            canvas.SetLogx()
        if ref.logY and ntot != 0:
            canvas.SetLogy()
        
        # Displaying a legend
        if len(self.main.datasets)>1:
            ymin_legend = .9-.055*len(histos)
            if ymin_legend<0.1:
                ymin_legend = 0.1
            legend = TLegend(.65,ymin_legend,.9,.9)
            legend.SetTextSize(0.05); 
            legend.SetTextFont(22); 
            for ind in range(0,len(histos)):
                legend.AddEntry(histos[ind],self.NiceTitle(self.main.datasets[ind].title))
            legend.SetFillColor(0)    
            legend.Draw()

        if not preview:
            
            # Save the canvas in the report format
            canvas.SaveAs(self.output_path+"/selection_"+str(irelhisto)+"."+\
                               ReportFormatType.convert2filetype(self.mode))

            # Save the canvas in the C format
            canvas.SaveAs(self.output_path+"/selection_"+str(irelhisto)+".C")
            
        else:
            # break 
            answer=raw_input("Press enter to continue : ")
Example #3
0
    def Draw(self,histos,myfile,scales,ref,irelhisto,mode,output_path,preview=False):

        from ROOT import TH1
        from ROOT import TH1F
        from ROOT import THStack
        from ROOT import TLegend
	from ROOT import TPaveText #RJ
        from ROOT import TCanvas
        from ROOT import TASImage
        from ROOT import TAttImage
        from ROOT import TPad
	from ROOT import TFile  #RJ

        # Creating a canvas
        PlotFlow.counter=PlotFlow.counter+1
        canvas = TCanvas("tempo"+str(PlotFlow.counter),"")

        # Loop over datasets and histos
        for ind in range(0,len(histos)):
            # Scaling 
            histos[ind].Scale(scales[ind])
            
        # Stacking or superimposing histos ?
        stackmode = False
        if ref.stack==StackingMethodType.STACK or \
           ( ref.stack==StackingMethodType.AUTO and \
             self.main.stack==StackingMethodType.STACK ):
            stackmode=True

        # Setting AUTO settings
        if len(histos)==1:
            histos[0].SetLineColor(9)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
        elif len(histos)==2:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
        elif len(histos)==3:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
        elif len(histos)==4:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
        elif len(histos)==5:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
        elif len(histos)==6:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
        elif len(histos)==7:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            histos[6].SetLineColor(7)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
                histos[6].SetFillColor(7)
                histos[6].SetFillStyle(3022)
        elif len(histos)==8:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            histos[6].SetLineColor(7)
            histos[7].SetLineColor(3)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
                histos[6].SetFillColor(7)
                histos[6].SetFillStyle(3022)
                histos[7].SetFillColor(3)
                histos[7].SetFillStyle(3315)
        elif len(histos)==9:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            histos[6].SetLineColor(7)
            histos[7].SetLineColor(3)
            histos[8].SetLineColor(42)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
                histos[6].SetFillColor(7)
                histos[6].SetFillStyle(3022)
                histos[7].SetFillColor(3)
                histos[7].SetFillStyle(3315)
                histos[8].SetFillColor(42)
                histos[8].SetFillStyle(3351)
        elif len(histos)==10:
            histos[0].SetLineColor(9)
            histos[1].SetLineColor(46)
            histos[2].SetLineColor(8)
            histos[3].SetLineColor(4)
            histos[4].SetLineColor(6)
            histos[5].SetLineColor(2)
            histos[6].SetLineColor(7)
            histos[7].SetLineColor(3)
            histos[8].SetLineColor(42)
            histos[9].SetLineColor(48)
            if stackmode:
                histos[0].SetFillColor(9)
                histos[0].SetFillStyle(3004)
                histos[1].SetFillColor(46)
                histos[1].SetFillStyle(3005)
                histos[2].SetFillColor(8)
                histos[2].SetFillStyle(3006)
                histos[3].SetFillColor(4)
                histos[3].SetFillStyle(3007)
                histos[4].SetFillColor(6)
                histos[4].SetFillStyle(3013)
                histos[5].SetFillColor(2)
                histos[5].SetFillStyle(3017)
                histos[6].SetFillColor(7)
                histos[6].SetFillStyle(3022)
                histos[7].SetFillColor(3)
                histos[7].SetFillStyle(3315)
                histos[8].SetFillColor(42)
                histos[8].SetFillStyle(3351)
                histos[9].SetFillColor(48)
                histos[9].SetFillStyle(3481)
        else:
            histos[ind].SetLineColor(self.color)
            self.color += 1

        # Setting USER color
        for ind in range(0,len(histos)):

            # linecolor
            if self.main.datasets[ind].linecolor!=ColorType.AUTO:
                histos[ind].SetLineColor(ColorType.convert2root( \
                self.main.datasets[ind].linecolor,\
                self.main.datasets[ind].lineshade))

            # lineStyle
            histos[ind].SetLineStyle(LineStyleType.convert2code( \
                self.main.datasets[ind].linestyle))

            # linewidth
            histos[ind].SetLineWidth(self.main.datasets[ind].linewidth)

            # background color  
            if self.main.datasets[ind].backcolor!=ColorType.AUTO:
                histos[ind].SetFillColor(ColorType.convert2root( \
                self.main.datasets[ind].backcolor,\
                self.main.datasets[ind].backshade))

            # background color  
            if self.main.datasets[ind].backstyle!=BackStyleType.AUTO:
                histos[ind].SetFillStyle(BackStyleType.convert2code( \
                self.main.datasets[ind].backstyle))

        # Creating and filling the stack; computing the total number of events
        stack = THStack("mystack","")
        ntot = 0
        for item in histos:
            ntot+=item.Integral()
            stack.Add(item)

        # Drawing
        if stackmode:
            stack.Draw()
        else:
            stack.Draw("nostack")

        # Setting Y axis label
        axis_titleY = ref.GetYaxis()

        # Scale to one ?
        scale2one = False
        if ref.stack==StackingMethodType.NORMALIZE2ONE or \
           (self.main.stack==StackingMethodType.NORMALIZE2ONE and \
           ref.stack==StackingMethodType.AUTO):
            scale2one = True

        if scale2one:
            axis_titleY += " ( scaled to one )"
        elif self.main.normalize == NormalizeType.LUMI or \
           self.main.normalize == NormalizeType.LUMI_WEIGHT:
            axis_titleY += " ( L_{int} = " + str(self.main.lumi)+ " fb^{-1} )"
        elif self.main.normalize == NormalizeType.NONE:
            axis_titleY += " (not normalized)"

        if ref.titleY!="": 
            axis_titleY = PlotFlow.NiceTitle(ref.titleY)

        stack.GetYaxis().SetTitle(axis_titleY)
        if(len(axis_titleY) > 35): 
           stack.GetYaxis().SetTitleSize(0.04)
        else:
           stack.GetYaxis().SetTitleSize(0.06)
        stack.GetYaxis().SetTitleFont(42)
        stack.GetYaxis().SetLabelSize(0.04)

        # Setting X axis label
        if ref.titleX=="": 
            axis_titleX = ref.GetXaxis()
        else:
            axis_titleX = PlotFlow.NiceTitle(ref.titleX)
        
        # Setting X axis label
        stack.GetXaxis().SetTitle(axis_titleX)
        stack.GetXaxis().SetTitleSize(0.06)
        stack.GetXaxis().SetTitleFont(42)
        stack.GetXaxis().SetLabelSize(0.04)

        # Setting Log scale
        if ref.logX and ntot != 0:
            canvas.SetLogx()
        if ref.logY and ntot != 0:
            canvas.SetLogy()

        #RJ
        T = TPaveText(0.1,0.995,0.5,0.95,'NDC')
        T.AddText('#bf{CMS} Simulation')
        T.SetTextFont(42)
        T.Draw("same")
        T.SetBorderSize(0)
        T.SetFillColor(0)
        T.SetFillStyle(0)
        T.SetLineColor(0)
        T.SetTextAlign(22)        

	# Save all hists -- R.J. Wang
        # Loop over datasets and histos
        for ind in range(0,len(histos)):
	    if not myfile.GetListOfKeys().Contains(PlotFlow.NiceTitle(self.main.datasets[ind].title)):
	    	myfile.mkdir(PlotFlow.NiceTitle(self.main.datasets[ind].title))
	    myfile.cd(PlotFlow.NiceTitle(self.main.datasets[ind].title))
	    newhistosNAME = axis_titleX
	    newhistosNAME = newhistosNAME.replace('(GeV/c^{2})','')
	    newhistosNAME = newhistosNAME.replace('(GeV/c)','')
	    newhistosNAME = newhistosNAME.replace(' ','')
	    newhistosNAME = newhistosNAME.replace('+','')
	    newhistosNAME = newhistosNAME.replace('-','')
	    newhistosNAME = newhistosNAME.replace('[','')
            newhistosNAME = newhistosNAME.replace(']','')
	    newhistosNAME = newhistosNAME.replace('#it','')
	    newhistosNAME = newhistosNAME.replace('#slashET','MET')
	    newhistosNAME = newhistosNAME.replace('(GeV)','')
	    newhistosNAME = newhistosNAME.replace('{','')
	    newhistosNAME = newhistosNAME.replace('}','')
	    newhistosNAME = newhistosNAME.replace('~','')
	    newhistosNAME = newhistosNAME.replace('_','')
	    #print newhistosNAME
	    histos[ind].SetName(newhistosNAME)
	    histos[ind].SetTitle(newhistosNAME)
	    histos[ind].GetXaxis().SetTitle(axis_titleX) 
	    histos[ind].Write()
 
        # Displaying a legend
        if len(self.main.datasets)>1:
            ymin_legend = .95-.035*len(histos)
            if ymin_legend<0.1:
                ymin_legend = 0.1
	    ymin_legend = 0.8
            legend = TLegend(.65,ymin_legend,.95,.93)
	    legend.SetNColumns(3);
            #legend.SetTextSize(0.05); 
            legend.SetTextFont(42); 
            for ind in range(0,len(histos)):
                legend.AddEntry(histos[ind],PlotFlow.NiceTitle(self.main.datasets[ind].title),"L")
            legend.SetFillColor(0)    
	    legend.SetFillStyle(0)
	    legend.SetLineColor(0)
            legend.Draw("same")

        if not preview:

            # Put the MA5 logo
#            logo = TASImage.Open(self.main.ma5dir+\
#                              "/madanalysis/input/logo.eps")
#            if not logo.IsValid():
#                logging.warning("file called '"+self.main.ma5dir+\
#                                "/madanalysis/input/logo.eps' " +\
#                                "is not found")
#            else:
#                logo.SetConstRatio(0)
#                logo.SetImageQuality(TAttImage.kImgBest)
#                logo.Vectorize(256)
#                w = logo.GetWidth()
#                h = logo.GetHeight()
#                logo.Scale(int(w*0.2),int(h*0.2))
#                mypad = TPad("i1", "i1", 0.75, 0.9, 0.85, 1)
#                mypad.Draw()
#                mypad.cd()
#                logo.Draw()
               
#            # Save the canvas in the report format
#            canvas.Update()
#            
#            thepicture = TASImage.Create()
#            thepicture.FromPad(canvas)
#            thepicture.SetConstRatio(0)
#            thepicture.SetImageQuality(TAttImage.kImgBest)
#            thepicture.WriteImage(output_path+"/selection_"+str(irelhisto)+\
#                                  "."+ReportFormatType.convert2filetype(mode))
            canvas.SaveAs(output_path+"/selection_"+str(irelhisto)+\
                          "."+ReportFormatType.convert2filetype(mode))

            # Save the canvas in the C format
            canvas.SaveAs(output_path+"/selection_"+str(irelhisto)+".C")

            # Save the canvas in the pdf format
            canvas.SaveAs(output_path+"/selection_"+str(irelhisto)+".pdf")

           
        else:
            # break 
            answer=raw_input("Press enter to continue : ")