Example #1
0
 def __init__(self,main,format):
     self.format  = format
     self.cmdname = ReportFormatType.convert2cmd(self.format)
     CmdBase.CmdBase.__init__(self,main,self.cmdname)
     self.forbiddenpaths=[]
     self.forbiddenpaths.append(os.path.normpath(self.main.ma5dir+'/lib'))
     self.forbiddenpaths.append(os.path.normpath(self.main.ma5dir+'/bin'))
     self.forbiddenpaths.append(os.path.normpath(self.main.ma5dir+'/madanalysis'))
Example #2
0
 def __init__(self, main, format):
     self.format = format
     self.cmdname = ReportFormatType.convert2cmd(self.format)
     CmdBase.CmdBase.__init__(self, main, self.cmdname)
     self.forbiddenpaths = []
     self.forbiddenpaths.append(os.path.normpath(self.main.ma5dir + '/lib'))
     self.forbiddenpaths.append(os.path.normpath(self.main.ma5dir + '/bin'))
     self.forbiddenpaths.append(
         os.path.normpath(self.main.ma5dir + '/madanalysis'))
Example #3
0
    def DrawDatasetPlots(self, histos, dataset, histo_path, modes,
                         output_paths, rootfiles):

        # Loop over DJR
        for i in range(0, 100):

            DJRplots = []

            # Looking for global plot
            name = "DJR" + str(i + 1) + "_total"
            test = False
            for h in range(len(histos)):
                if histos[h].name == name:
                    DJRplots.append(histos[h])
                    test = True
                    break

            # Global plot not found ?
            if not test:
                break

            # Loop over njets
            for j in range(0, 100):

                # Looking for njet plot
                name = "DJR" + str(i + 1) + "_" + str(j) + "jet"
                test = False
                for h in range(len(histos)):
                    if histos[h].name == name:
                        DJRplots.append(histos[h])
                        test = True
                        break

                # njet plot not found ?
                if not test:
                    break

            # Save the canvas in the report format
            datasetname = InstanceName.Get(dataset.name)
            index = i + 1

            filenameC = histo_path+"/merging_" +\
                        datasetname+"_"+str(index)
            rootfiles.append(filenameC)
            filenameC += '.C'
            output_files = []
            for iout in range(0, len(output_paths)):
                output_files.append(output_paths[iout]+\
                                    "/merging_" +\
                                    datasetname+"_"+str(index)+"." +\
                                    ReportFormatType.convert2filetype(modes[iout]))
            # Drawing
            self.DrawROOT(DJRplots, dataset, filenameC, output_files, index)
Example #4
0
    def DrawAll(self, histo_path, modes, output_paths, ListROOTplots):

        # Loop on each histo type
        irelhisto = 0
        for iabshisto in range(0, len(self.main.selection)):
            if self.main.selection[iabshisto].__class__.__name__ != "Histogram":
                continue
            self.color = 1
            histos = []
            scales = []

            # Name of output files
            filenameC = histo_path + "/selection_" + str(irelhisto) + ".C"
            filenamePy = histo_path + "/selection_" + str(irelhisto) + ".py"

            output_files = []
            for iout in range(0, len(output_paths)):
                output_files.append('../'+output_paths[iout].split('/')[-1]+\
                                    "/selection_"+str(irelhisto)+"."+\
                                    ReportFormatType.convert2filetype(modes[iout]))

            for iset in range(0, len(self.detail)):

                # Appending histo
                histos.append(self.detail[iset][irelhisto])
                #               if mode==2:
                scales.append(self.detail[iset][irelhisto].scale)
#               else:
#                   scales.append(1)

            logging.getLogger('MA5').debug('Producing file ' + filenameC +
                                           ' ...')
            self.DrawROOT(histos,scales,self.main.selection[iabshisto],\
                          irelhisto,filenameC,output_files)

            logging.getLogger('MA5').debug('Producing file ' + filenamePy +
                                           ' ...')
            self.DrawMATPLOTLIB\
                         (histos,scales,self.main.selection[iabshisto],\
                          irelhisto,filenamePy,output_files)

            irelhisto += 1

        # Save ROOT files
        for ind in range(0, irelhisto):
            ListROOTplots.append(histo_path + '/selection_' + str(ind))

        return True
Example #5
0
    def CopyLogo(self, mode, output_path):

        # Filename
        filename = self.main.ma5dir+"/madanalysis/input/" + \
                   "logo." + \
                   ReportFormatType.convert2filetype(mode)

        # Checking file presence
        if not os.path.isfile(filename):
            logging.error("the image '" + \
                          filename + \
                          "' is not found.")
            return False

        # Copy file
        try:
            shutil.copy(filename, output_path)
            return True
        except:
            logging.error("Errors have occured during the copy of the file ")
            logging.error(" " + filename)
            return False
Example #6
0
    def CopyLogo(self):
        
        # Filename
        filename = self.main.ma5dir+"/madanalysis/input/" + \
                   "logo." + \
                   ReportFormatType.convert2filetype(self.mode)

        # Checking file presence
        if not os.path.isfile(filename):
            logging.error("the image '" + \
                          filename + \
                          "' is not found.")
            return False

        # Copy file
        try :
            shutil.copy(filename,self.output_path)
            return True
        except:
            logging.error("Errors have occured during the copy of the file ")
            logging.error(" "+filename)
            return False
Example #7
0
 def help(self):
     logging.info("   Syntax: " + self.cmdname + " <output dir>")
     logging.info("   Creates a "+ReportFormatType.convert2string(self.format)+ \
                  " report containing the results of the performed analysis.")
Example #8
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 #9
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 : ")
Example #10
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 #11
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 : ")
Example #12
0
 def help(self):
     logging.info("   Syntax: "+self.cmdname+" <output dir>")
     logging.info("   Creates a "+ReportFormatType.convert2string(self.format)+ \
                  " report containing the results of the performed analysis.")
Example #13
0
    def DrawPlot(self,DJRplots,dataset,mode,output_path,index):

        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","")

        # Getting xsection
        xsection=dataset.measured_global.xsection
        if dataset.xsection!=0.:
            xsection=dataset.xsection

        # Setting color to the total plot
        DJRplots[0].myhisto.SetLineColor(1)
        DJRplots[0].myhisto.SetLineStyle(1)

        # Scaling the total plot
        if DJRplots[0].myhisto.GetEntries()!=0:
            DJRplots[0].myhisto.Scale( float(xsection) / \
                                       float(DJRplots[0].myhisto.GetEntries()) )

        # Loop over other DJR plots    
        for ind in range(1,len(DJRplots)):
            DJRplots[ind].myhisto.SetLineStyle(2)
            if DJRplots[ind].myhisto.GetEntries()!=0:
                DJRplots[ind].myhisto.Scale( float(xsection) / \
                                             float(DJRplots[0].myhisto.GetEntries()) )

        # Setting color an other settings to jet plots    
        if len(DJRplots)==2:
            DJRplots[1].myhisto.SetLineColor(9)
        elif len(DJRplots)==3:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
        elif len(DJRplots)==4:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
            DJRplots[3].myhisto.SetLineColor(8)
        elif len(DJRplots)==5:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
            DJRplots[3].myhisto.SetLineColor(8)
            DJRplots[4].myhisto.SetLineColor(4)
        elif len(DJRplots)==6:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
            DJRplots[3].myhisto.SetLineColor(8)
            DJRplots[4].myhisto.SetLineColor(4)
            DJRplots[5].myhisto.SetLineColor(6)
        elif len(DJRplots)==7:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
            DJRplots[3].myhisto.SetLineColor(8)
            DJRplots[4].myhisto.SetLineColor(4)
            DJRplots[5].myhisto.SetLineColor(6)
            DJRplots[6].myhisto.SetLineColor(2)
        elif len(DJRplots)==8:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
            DJRplots[3].myhisto.SetLineColor(8)
            DJRplots[4].myhisto.SetLineColor(4)
            DJRplots[5].myhisto.SetLineColor(6)
            DJRplots[6].myhisto.SetLineColor(2)
            DJRplots[7].myhisto.SetLineColor(7)
        elif len(DJRplots)==9:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
            DJRplots[3].myhisto.SetLineColor(8)
            DJRplots[4].myhisto.SetLineColor(4)
            DJRplots[5].myhisto.SetLineColor(6)
            DJRplots[6].myhisto.SetLineColor(2)
            DJRplots[7].myhisto.SetLineColor(7)
            DJRplots[8].myhisto.SetLineColor(3)
        elif len(DJRplots)==10:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
            DJRplots[3].myhisto.SetLineColor(8)
            DJRplots[4].myhisto.SetLineColor(4)
            DJRplots[5].myhisto.SetLineColor(6)
            DJRplots[6].myhisto.SetLineColor(2)
            DJRplots[7].myhisto.SetLineColor(7)
            DJRplots[8].myhisto.SetLineColor(3)
            DJRplots[9].myhisto.SetLineColor(42)
        elif len(DJRplots)==11:
            DJRplots[1].myhisto.SetLineColor(9)
            DJRplots[2].myhisto.SetLineColor(46)
            DJRplots[3].myhisto.SetLineColor(8)
            DJRplots[4].myhisto.SetLineColor(4)
            DJRplots[5].myhisto.SetLineColor(6)
            DJRplots[6].myhisto.SetLineColor(2)
            DJRplots[7].myhisto.SetLineColor(7)
            DJRplots[8].myhisto.SetLineColor(3)
            DJRplots[9].myhisto.SetLineColor(42)
            DJRplots[10].myhisto.SetLineColor(48)
        else:
            color=1
            for ind in range(1,len(DJRplots)):
                DJRplots[ind].myhisto.SetLineColor(color)
                color += 1

        # Creating and filling the stack; computing the total number of events
        stack = THStack("mystack","")
        ntot = DJRplots[0].myhisto.GetEntries()
        stack.Add(DJRplots[0].myhisto)
        for ind in range(1,len(DJRplots)):
            ntot+=DJRplots[ind].myhisto.GetEntries()
            stack.Add(DJRplots[ind].myhisto)

        # Drawing plots
        stack.Draw("nostack")
        
        # Setting Y axis label
        axis_titleY = "Cross section (pb/bin)"
        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
        stack.GetXaxis().SetTitle("log10(DJR"+str(index)+")")
        stack.GetXaxis().SetTitleSize(0.06)
        stack.GetXaxis().SetTitleFont(42)
        stack.GetXaxis().SetLabelSize(0.04)

        # Setting Log scale
        if ntot != 0:
            canvas.SetLogy()
        
        # Displaying a legend
        ymin_legend = .9-.055*(len(DJRplots)-1)
        if ymin_legend<0.1:
            ymin_legend = 0.1
        legend = TLegend(.65,ymin_legend,.9,.9)
        legend.SetTextSize(0.04); 
        legend.SetTextFont(42);
        legend.AddEntry(DJRplots[0].myhisto,"Sum")
        for ind in range(1,len(DJRplots)):
            legend.AddEntry(DJRplots[ind].myhisto,str(ind-1)+"-jet sample")
        legend.SetFillColor(0)    
        legend.Draw()

        # Save the canvas in the report format
        datasetname = InstanceName.Get(dataset.name)

        canvas.SaveAs(output_path+"/merging_" +\
                      datasetname+"_"+str(index)+"." +\
                      ReportFormatType.convert2filetype(mode))

        # Save the canvas in the C format
        canvas.SaveAs(output_path+"/merging_" +\
                      datasetname+"_"+str(index)+".C")