Пример #1
0
    def saveHistograms(self, d_filledHists, t_type, outFile, sample, baseDir,
                       selectOn, t_select):

        PythonUtils.Info('++++++++++++++++++++++++++++++++++++++++++++++++++')
        PythonUtils.Info('       SAVING HISTOGRAMS: ' + baseDir + '       ')
        PythonUtils.Info('++++++++++++++++++++++++++++++++++++++++++++++++++')

        for bin in t_select:
            ## Don't have a trainling slash for all - looks messy
            PythonUtils.Info('Creating Histograms for process: ' + baseDir +
                             ' in bin: ' + bin[0] + '-' + bin[1])
            if bin[0] == 'all':
                select = selectOn + '-' + bin[0]
            else:
                select = selectOn + '-' + bin[0] + '-' + bin[1]

            for i in range(len(t_type)):
                type, typeFile = t_type[i]
                t_typeFile = PythonUtils.makeTupleFromFile(typeFile, ',')
                for j in range(len(t_typeFile)):
                    rBranch, tBranch, sName, sLocation, xMin, xMax, nBuns = t_typeFile[
                        j]
                    location = baseDir + '/' + sample + '/' + select + '/' + sLocation
                    ROOTUtils.saveToFile(
                        d_filledHists[select][type][location + sName], outFile,
                        location, sName)
Пример #2
0
def twoDprofile(d_ptMean, l_histo, l_corr, l_err):

    hString,c_x, c_y, yMin, yMax, hBins, saveFile = l_histo
    cName, cVar, cDir, cColor, cMarker, cSize, cMu, cDir = l_corr
    l_bin = []
    for bin in hBins.split(';'):
        l_bin.append(float(bin))

    arrBin = numpy.asarray(l_bin)
    h_prof = TH1D('h_prof', cMu, len(l_bin) - 1, arrBin)
    gROOT.SetBatch(1) 
    c = TCanvas('c', 'c', int(c_x), int(c_y))
    gStyle.SetOptStat(0)

    for k, v in d_ptMean.iteritems():
        h_prof.Fill(float(k), float(v))
    
    for b in xrange(0, len(l_bin)):
        h_prof.SetBinError(b, l_err[b])

    h_prof.SetMarkerColor(int(cColor))
    h_prof.SetLineColor(int(cColor))
    h_prof.SetMarkerStyle(int(cMarker))
    if cSize != int(-1):
        h_prof.SetMarkerSize(float(cSize))
    
    h_prof.Draw('eps')
    h_prof.SetDirectory(0)

    if saveFile != '':
        ROOTUtils.saveToFile(h_prof, saveFile, '', 'PtCorr_' + cMu)

    l_legend = [h_prof, cName, 'p']

    return h_prof, l_legend
Пример #3
0
    def Run(self, processList):

        len_histoList = len(self.t_histoList)
        t_tagList = PythonUtils.makeTupleFromFile(processList, ',')

        l_files = []
        f = open(processList, 'r')
        for file in f:
            l_files.append(file.strip())

        for i in xrange(len(t_tagList)):
            pFile, tagText = t_tagList[i]
            PythonUtils.doesFileExist(pFile)
            t_processList = PythonUtils.makeTupleFromFile(pFile, ',')

            for j in xrange(len(self.t_histoList)):
                t_plot = []
                name = self.t_histoList[j][2]
                for k in xrange(len(t_processList)):
                    histoLocation = t_processList[k][1] + self.t_histoList[j][1]
                    t_plot.append([
                        ROOTUtils.retrieveHistogram(self.histFile,
                                                    histoLocation, name)
                    ])

                saveString = self.saveDir + self.t_histoList[j][
                    0] + '_' + t_processList[k][7]
                PlottingUtils.stackHistograms(
                    t_plot, t_processList, self.t_histoList[j],
                    self.t_legendList[j], self.t_textList[j],
                    self.t_axisList[j], self.l_saveAs, self.t_ratioList[j],
                    saveString, tagText)
Пример #4
0
    def Run(self, processList):
    
        len_histoList   = len(self.t_histoList)
        t_tagList = PythonUtils.makeTupleFromFile(processList, ',')

        l_files = []
        f = open(processList, 'r')
        for file in f:
            l_files.append(file.strip())
            
        for i in xrange(len(t_tagList)):
            pFile, tagText = t_tagList[i]
            PythonUtils.doesFileExist(pFile)
            t_processList = PythonUtils.makeTupleFromFile(pFile, ',')

            for j in xrange(len(self.t_histoList)):
                t_plot = []
                name = self.t_histoList[j][2]
                for k in xrange(len(t_processList)):
                    histoLocation = t_processList[k][1] + self.t_histoList[j][1]
                    t_plot.append([ROOTUtils.retrieveHistogram(self.histFile, histoLocation, name)])

                saveString = self.saveDir + self.t_histoList[j][0] + '_'  + t_processList[k][7]
                PlottingUtils.stackHistograms(t_plot, t_processList, self.t_histoList[j],
                                              self.t_legendList[j], self.t_textList[j],
                                              self.t_axisList[j], self.l_saveAs, 
                                              self.t_ratioList[j], saveString, tagText)
Пример #5
0
def scatterPlot(l_scatter, l_file, l_histo, l_axis, 
                l_text, treeFile, saveDir, l_saveAs):

    ## De construct the list objects
    f_str, doSave, outputFile, directory, name = l_file
    s_str, tree, xBranch, yBranch, option = l_scatter
    h_str, c_x, c_y, xMin, xMax, yMin, yMax, nBins = l_histo
    a_str, xLabel, yLabel, xOffset, yOffset, a_labelSize, a_textSize = l_axis
    t_str, plotText, t_textSize, t_alignment, t_start, t_gap, t_x = l_text

    ## Read the tree
    f = TFile(treeFile, 'READ')
    t = f.Get(tree)

    v1 = array('d', [0])
    v2 = array('d', [0])

    t.SetBranchAddress(xBranch, v1)
    t.SetBranchAddress(yBranch, v2)

    ## Setup the canvas and fill it!
    gROOT.SetBatch(1)
    c = TCanvas('c', 'c', int(c_x), int(c_y))
    c.SetTicks(1,1)
    gStyle.SetOptStat(0)
    hs = TH2D('hs', '', int(nBins), float(xMin), float(xMax), 
              int(nBins), float(yMin), float(yMax))

    for i in range(0, t.GetEntries(), 1):
        t.GetEntry(i)
        x = v1[0]
        y = v2[0]
        hs.Fill(x,y)

    if int(doSave):
        hs.Draw()
        setupAxes(hs, xLabel, yLabel, xOffset, yOffset,
                  a_textSize, xMin, xMax, 1)
        ROOTUtils.saveToFile(hs, outputFile, directory, name)

    hs.Draw(option)
    setupAxes(hs, xLabel, yLabel, xOffset, yOffset,
              a_textSize, xMin, xMax, 1)
    
    setupTextOnPlot(plotText, t_textSize, t_alignment, t_x, t_start, t_gap)
    savePlots(c, saveDir + h_str, l_saveAs)
Пример #6
0
 def labels(self):
     # ATLAS labels and other text
     if options.prelim:
         ROOTUtils.atlasLabel(options.atlasx,
                              options.atlasy,
                              True,
                              offset=options.atlasdx,
                              energy=8,
                              size=options.lsize)
     if options.approval:
         ROOTUtils.atlasLabel(options.atlasx,
                              options.atlasy,
                              False,
                              offset=options.atlasdx,
                              isForApproval=True,
                              energy=8,
                              size=options.lsize)
     if options.published:
         ROOTUtils.atlasLabel(options.atlasx,
                              options.atlasy,
                              False,
                              offset=options.atlasdx,
                              energy=8,
                              size=options.lsize)
     if options.comment:
         self.protect(
             ROOTUtils.drawText(options.commentx,
                                options.commenty,
                                0.06,
                                options.comment,
                                font=42))
Пример #7
0
    def saveHistograms(self, d_filledHists, t_var, outFile, sDir, t_muon, selectOn, t_select):

        PythonUtils.Info('Saving Histograms: ' + outFile)
        
        for sMu in t_muon:
            b_mu = 'nMu_' + sMu[0] + sMu[1]

            for bin in t_select:
                if bin[1]:
                    select = selectOn + '-' + bin[0] + '-' + bin[1]
                else:
                    select = selectOn + '-' + bin[0]
                
                PythonUtils.Info('Saving Histograms for: ' + selectOn + ' In bin range: ' 
                                 + bin[0] + ' - ' + bin[1])
                for i in xrange(len(t_var)):
                    rBranch, tBranch, sName, sLocation, xMin, xMax, nBins = t_var[i]
                    location = sDir + '/' + b_mu + '/' + select + '/' + sLocation
                    ROOTUtils.saveToFile(d_filledHists[b_mu][select][location + sName], outFile, location, sName)
Пример #8
0
    def saveHistograms(self, d_filledHists, t_type, outFile, sample, baseDir, selectOn, t_select):

        PythonUtils.Info('++++++++++++++++++++++++++++++++++++++++++++++++++')
        PythonUtils.Info('       SAVING HISTOGRAMS: ' + baseDir + '       ')
        PythonUtils.Info('++++++++++++++++++++++++++++++++++++++++++++++++++')
        
        for bin in t_select:
            ## Don't have a trainling slash for all - looks messy
            PythonUtils.Info('Creating Histograms for process: ' + baseDir +
                             ' in bin: ' + bin[0] + '-' + bin[1])
            if bin[0] == 'all':
                select = selectOn + '-' + bin[0]
            else:
                select = selectOn + '-' + bin[0] + '-' + bin[1]

            for i in range(len(t_type)):
                type, typeFile = t_type[i]
                t_typeFile = PythonUtils.makeTupleFromFile(typeFile, ',')
                for j in range(len(t_typeFile)):
                    rBranch, tBranch, sName, sLocation, xMin, xMax, nBuns = t_typeFile[j]
                    location = baseDir + '/' + sample + '/' + select + '/' + sLocation
                    ROOTUtils.saveToFile(d_filledHists[select][type][location + sName], outFile, location, sName)
Пример #9
0
    def saveHistograms(self, d_filledHists, t_var, outFile, sDir, t_muon,
                       selectOn, t_select):

        PythonUtils.Info('Saving Histograms: ' + outFile)

        for sMu in t_muon:
            b_mu = 'nMu_' + sMu[0] + sMu[1]

            for bin in t_select:
                if bin[1]:
                    select = selectOn + '-' + bin[0] + '-' + bin[1]
                else:
                    select = selectOn + '-' + bin[0]

                PythonUtils.Info('Saving Histograms for: ' + selectOn +
                                 ' In bin range: ' + bin[0] + ' - ' + bin[1])
                for i in xrange(len(t_var)):
                    rBranch, tBranch, sName, sLocation, xMin, xMax, nBins = t_var[
                        i]
                    location = sDir + '/' + b_mu + '/' + select + '/' + sLocation
                    ROOTUtils.saveToFile(
                        d_filledHists[b_mu][select][location + sName], outFile,
                        location, sName)
Пример #10
0
 def hist(self, what):
     if not what:
         return
     if options.hmin is not None or options.hmax is not None or options.hnbins is not None:
         options.hmin = options.hmin if options.hmin is not None else 0.
         options.hmax = options.hmax if options.hmax is not None else 1.
         options.hnbins = options.hnbins if options.hnbins is not None else 40
         h = ROOTUtils.protect(
             ROOT.TH1F('tmp', '%s;%s' % (what, what), options.hnbins,
                       options.hmin, options.hmax))
         vtxData.Draw('%s >> tmp' % what)
     else:
         vtxData.Draw(what)
     if options.logy:
         ROOT.gPad.SetLogy(options.logy)
Пример #11
0
 def legend(self, frame):
     legendList = []
     legendList.append([frame.getObject(0), 'Data', 'P'])
     legendList.append([frame.getObject(1), 'Fit projection', 'L'])
     if options.showbs:
         legendList.append([frame.getObject(2), 'Beam spot', 'L'])
     legendMinY = max(
         options.legendy - options.lsize * 1.4 * len(legendList), 0.2)
     self.protect(
         ROOTUtils.drawLegend(options.legendx,
                              legendMinY,
                              0.92,
                              options.legendy,
                              legendList,
                              textSize=options.lsize))
Пример #12
0
    def Run(self):

        # Create lists from config file info
        l_saveAs = PythonUtils.makeListFromString(self.saveAs, ',')

        ## Check the .list files exist!
        l_listFile = [
            self.axisList, self.histoList, self.legendList, self.overlayList,
            self.textList, self.histFile
        ]
        for file in l_listFile:
            PythonUtils.doesFileExist(file)

        ## Make the tuples from the input files
        t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',')
        t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',')
        t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',')
        t_textList = PythonUtils.makeTupleFromFile(self.textList, ',')

        ## match the first item to make sure they're compatible
        l_tuples = [t_histoList, t_legendList, t_textList]
        for item in l_tuples:
            PythonUtils.firstItemMatching(t_axisList, item)

        l_files = []
        f = open(self.overlayList, 'r')
        for line in f:
            if line.startswith('#'):
                continue
            else:
                l_files.append(line.strip())

        for i in xrange(len(l_files)):
            PythonUtils.doesFileExist(l_files[i])
            t_overlayList = PythonUtils.makeTupleFromFile(l_files[i], ',')
            t_plots = []
            for j in xrange(len(t_overlayList)):
                histoLocation = t_overlayList[j][1] + t_histoList[i][1]
                t_plots.append([
                    ROOTUtils.retrieveHistogram(self.histFile, histoLocation,
                                                t_overlayList[j][2])
                ])

            saveString = self.saveDir + t_histoList[i][0]
            PlottingUtils.overlayHistograms(t_plots, t_overlayList,
                                            t_histoList[i], t_legendList[i],
                                            t_textList[i], t_axisList[i],
                                            l_saveAs, saveString)
Пример #13
0
    def Run(self):

        # Create lists from config file info
        l_saveAs = PythonUtils.makeListFromString(self.saveAs, ',')

        ## Check the .list files exist!
        l_listFile = [self.axisList, self.histoList, self.legendList,
                      self.overlayList, self.textList, self.histFile]
        for file in l_listFile:
            PythonUtils.doesFileExist(file)

        ## Make the tuples from the input files
        t_axisList   = PythonUtils.makeTupleFromFile(self.axisList,   ',')
        t_histoList  = PythonUtils.makeTupleFromFile(self.histoList,  ',')
        t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',')
        t_textList   = PythonUtils.makeTupleFromFile(self.textList,   ',')

        ## match the first item to make sure they're compatible
        l_tuples = [t_histoList, t_legendList, t_textList]
        for item in l_tuples:
            PythonUtils.firstItemMatching(t_axisList, item)

        l_files = []
        f = open(self.overlayList, 'r')
        for line in f:
            if line.startswith('#'):
                continue
            else:
                l_files.append(line.strip())

        for i in xrange(len(l_files)):
            PythonUtils.doesFileExist(l_files[i])
            t_overlayList = PythonUtils.makeTupleFromFile(l_files[i], ',')
            t_plots = []
            for j in xrange(len(t_overlayList)):
                histoLocation = t_overlayList[j][1] + t_histoList[i][1]
                t_plots.append([ROOTUtils.retrieveHistogram(self.histFile, histoLocation, t_overlayList[j][2])])

            saveString = self.saveDir + t_histoList[i][0]
            PlottingUtils.overlayHistograms(t_plots, t_overlayList, t_histoList[i],
                                            t_legendList[i], t_textList[i], t_axisList[i],
                                            l_saveAs, saveString)
Пример #14
0
    def Run(self):

        ## Create lists from config file options
        l_saveAs = PythonUtils.makeListFromString(self.saveAs, ',')

        ## Check the .list files exist
        l_listFile = [
            self.axisList, self.fitList, self.histoList, self.legendList,
            self.textList, self.variableList, self.histFile
        ]
        for file in l_listFile:
            PythonUtils.doesFileExist(file)

        ## Create the tuples from the .list files
        t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',')
        t_fitList = PythonUtils.makeTupleFromFile(self.fitList, ',')
        t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',')
        t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',')
        t_textList = PythonUtils.makeTupleFromFile(self.textList, ',')

        ## Math the first titems
        l_tuples = [t_fitList, t_histoList, t_legendList, t_textList]
        for item in l_tuples:
            PythonUtils.firstItemMatching(t_axisList, item)

        ## Loop over the variable files to get the relevant info
        for j in xrange(len(t_axisList)):
            f_str, vRebin, vdoNorm, vXMin, vXMax, vFit, vXValue, vYValue = t_fitList[
                j]

            l_files = []
            f = open(self.variableList, 'r')
            for file in f:
                l_files.append(file.strip())

            l_twoD = []
            t_legend = []
            PythonUtils.doesFileExist(l_files[j])
            g = open(l_files[j], 'r')
            for vFile in g:
                PythonUtils.doesFileExist(vFile.strip())
                vFileParser = ConfigParser.SafeConfigParser()
                vFileParser.read(vFile.strip())
                ## Options
                vTitle = vFileParser.get('Options', 'title')
                vVariable = vFileParser.get('Options', 'variable')
                vColour = vFileParser.getint('Options', 'colour')
                vMarker = vFileParser.getint('Options', 'marker')
                vMarkerSize = vFileParser.getfloat('Options', 'markerSize')
                vFitMin = vFileParser.get('Options', 'fitMin')
                vFitMax = vFileParser.get('Options', 'fitMax')

                ## Create l_statInfo
                l_statInfo = [
                    t_histoList[j][1], t_histoList[j][1],
                    float(vRebin),
                    int(vdoNorm),
                    float(vXMin),
                    float(vXMax), vFitMin, vFitMax
                ]

                getMean = 0
                getRMS = 0
                getRES = 0
                if vXValue == 'MEAN':
                    getMean = 1
                elif vXValue == 'RMS':
                    getRMS = 1
                elif vXValue == 'RESOLUTION':
                    getRES = 1
                else:
                    getMean = getRMS = getRES = 0
                l_xOption = [getMean, getRMS, getRES]

                getMean = 0
                getRMS = 0
                getRES = 0
                if vYValue == 'MEAN':
                    getMean = 1
                elif vYValue == 'RMS':
                    getRMS = 1
                elif vYValue == 'RESOLUTION':
                    getRES = 1
                else:
                    getMean = getRMS = getRES = 0
                l_yOption = [getMean, getRMS, getRES]

                ## Get the list of stats
                l_plot = [
                    ROOTUtils.retrieveHistogram(self.histFile,
                                                t_histoList[j][1], vVariable)
                ]
                l_xValue, l_xErr = ROOTUtils.getHistoStat(
                    l_plot, l_statInfo, l_xOption, vFit, vVariable)
                l_yValue, l_yErr = ROOTUtils.getHistoStat(
                    l_plot, l_statInfo, l_yOption, vFit, vVariable)

                ## Get the value we want from the list so we can plot it!
                xValue = -1
                for stat in l_xValue:
                    if stat != -1:
                        xValue = stat

                for stat in l_yValue:
                    if stat != -1:
                        yValue = stat

                ## Create a 2D plot and save to a list so can overlay them
                twoDPlot = PlottingUtils.createTwoD(t_histoList[j], xValue,
                                                    yValue, vMarker,
                                                    vMarkerSize, vColour)
                l_twoD.append(twoDPlot)
                if vTitle:
                    l_legend = [twoDPlot, vTitle, 'p']
                    t_legend.append(l_legend)

            ## Overlay our 2D plots onto one canvas
            PlottingUtils.overlayTwoD(l_twoD, t_legend, t_histoList[j],
                                      t_legendList[j], t_textList[j],
                                      t_axisList[j], self.saveDir, l_saveAs)
Пример #15
0
    def Run(self, doProfile, createFile):

        ## Create the lists from the main configFile
        t_select = PythonUtils.makeTupleFromString(self.selectBins, ',', '?')
        t_muon = PythonUtils.makeTupleFromString(self.muBins, ',', '?')

        if createFile:
            PythonUtils.Info('Creating Histogram File for Profile Plots')
            ## Check the list files exist
            l_fList = [self.variableList, self.treeList]
            for f in l_fList:
                PythonUtils.doesFileExist(f)

            ## Make the lists from the list files
            t_var = PythonUtils.makeTupleFromFile(self.variableList, ',')
            t_tree = PythonUtils.makeTupleFromFile(self.treeList, ',')

            for i in xrange(len(t_tree)):
                tFile, tName, sDir = t_tree[i]
                PythonUtils.doesFileExist(tFile)

                d_histType = self.createHistograms(t_var, sDir, tFile, t_muon,
                                                   self.selectOn, t_select)
                d_filledHists = self.fillHistograms(d_histType, t_var, tFile,
                                                    tName, sDir, t_muon,
                                                    t_select, self.selectOn,
                                                    self.nEvents)
                self.saveHistograms(d_filledHists, t_var, self.outHist, sDir,
                                    t_muon, self.selectOn, t_select)

        if doProfile:
            PythonUtils.Info("Creating Profile Plots!")

            ## Create the Lists from profile cfg
            l_saveAs = PythonUtils.makeListFromString(self.plotType, ',')

            ## Check the list files exist
            l_pList = [
                self.axisList, self.histoList, self.legendList, self.textList,
                self.varList, self.inFile
            ]

            for f in l_pList:
                PythonUtils.doesFileExist(f)

            ## Create the list of lists from each list file
            t_axisList = PythonUtils.makeTupleFromFile(self.axisList, ',')
            t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',')
            t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',')
            t_textList = PythonUtils.makeTupleFromFile(self.textList, ',')

            ## Check teh first Item matches:
            l_tList = [t_histoList, t_legendList, t_textList]
            for l in l_tList:
                PythonUtils.firstItemMatching(l, t_axisList)

            ## Add the var list files to a list
            l_varList = []
            f = open(self.varList, 'r')
            for line in f:
                if line.startswith('#'):
                    continue
                else:
                    l_varList.append(line)

            for i in xrange(len(l_varList)):
                PythonUtils.doesFileExist(l_varList[i].strip())
                t_varList = PythonUtils.makeTupleFromFile(
                    l_varList[i].strip(), ',')
                l_prof = []
                t_legend = []
                for j in xrange(len(t_varList)):
                    d_pTMean = {}
                    l_err = []
                    for bin in t_select:
                        if bin[0] == 'all' or bin[1] == 'Inf':
                            continue
                        if bin[1]:
                            select = self.selectOn + '-' + bin[0] + '-' + bin[1]
                        else:
                            select = self.selectOn + '-' + bin[0]

                        location = t_varList[j][2] + '/' + t_varList[j][
                            6] + '/' + select + '/' + t_varList[j][7]
                        pTbin = float(
                            bin[0]) + (float(bin[1]) - float(bin[0])) / 2
                        pTMean = ROOTUtils.retrieveHistogram(
                            self.inFile, location, t_varList[j][1]).GetMean()
                        pTMeanErr = ROOTUtils.retrieveHistogram(
                            self.inFile, location,
                            t_varList[j][1]).GetMeanError()
                        l_err.append(pTMeanErr)
                        d_pTMean[pTbin] = pTMean

                    h_prof, l_legend = PlottingUtils.twoDprofile(
                        d_pTMean, t_histoList[i], t_varList[j], l_err)
                    l_prof.append(h_prof)
                    t_legend.append(l_legend)

                saveString = self.plotDir + t_histoList[i][0]
                PlottingUtils.overlayProfile(l_prof, t_axisList[i],
                                             t_histoList[i], t_legendList[i],
                                             t_textList[i], t_legend, l_saveAs,
                                             saveString)
Пример #16
0
def overlayHistograms(t_plots, t_overlayList, l_histo, l_legend, l_text, l_axis,
                      l_saveAs, s_save):

    '''
    PURPOSE:

    This Function will:
        * Rebin and alter histograms
        * Apply a fit to the histograms
        * Plot them all on the same canvas
        * Add the aesthetic features
    '''
    # Declare the variables from our lists
    h_str, location_suf, c_x, c_y, drawGrid, v_rebin, xMin, xMax, fit, doNorm = l_histo
    l_str, l_x1, l_y1, l_x2, l_y2, l_textSize = l_legend
    t_str, plotText, t_textSize, t_alignment, t_start, t_gap, t_x = l_text
    a_str, xLabel, yLabel, xOffset, yOffset, a_labelSize, a_textSize, y_scale = l_axis
    
    # Setup the canvas before filling
    gROOT.SetBatch(1)
    c = TCanvas('c', 'c', int(c_x), int(c_y))
    gStyle.SetOptStat(0)
    c.SetTickx(1)
    c.SetTicky(1)
    if int(drawGrid):
        c.SetGridx(1)
        c.SetGridy(1)
    c.Update()

    t_legend = []
    for i in xrange(len(t_plots)):
        f_min = t_overlayList[i][5]
        f_max = t_overlayList[i][6]
        colour = int(t_overlayList[i][3])
        h = rebin(t_plots[i][0], float(v_rebin))
        h.SetLineWidth(1)
        h.SetLineColor(colour)
        l_legendLine = [t_plots[i][0], t_overlayList[i][0], t_overlayList[i][4]]
        t_legend.append(l_legendLine)
        
        ## Get the numerical range for SD ranges
        if 'SIGMA' in str(f_min) or 'SIGMA' in str(f_max):
            f_min, f_max = ROOTUtils.getSigmaFitRange(h, f_min, f_max)
        
        if int(doNorm):
            scale = 1 / h.Integral()
            h.Scale(scale)

        if i == 0:
            h.Draw()
            h.SetTitle('')
            setupAxes(h, xLabel, yLabel, xOffset, yOffset, 
                      a_textSize, xMin, xMax, y_scale)
        else:
            h.GetXaxis().SetRangeUser(float(xMin), float(xMax))
            h.Draw('HIST SAME')

        if fit == 'BUKIN':
            fh = ROOTUtils.drawBukin(h, f_min, f_max)
            fh.SetLineColor(colour)
            fh.Draw('HISTSAME')
    
    setupLegend(t_legend, l_x1, l_y1, l_x2, l_y2, l_textSize)
    setupTextOnPlot(plotText, t_textSize, t_alignment, t_x, t_start, t_gap)
    savePlots(c, s_save, l_saveAs)
Пример #17
0
    def Run(self):

        ## Make the list from the config file
        l_range = PythonUtils.makeListFromString(self.plotRange, ',')
        t_select = PythonUtils.makeTupleFromString(self.selectBins, ',', '?')

        ## Check the input and process files exist
        l_file = [self.processList, self.inputFile]
        for file in l_file:
            PythonUtils.doesFileExist(file)

        ## Loop over the ProcessList files
        f = open(self.processList, 'r')
        for line in f:
            if line.startswith('#'):
                continue

            l_process = PythonUtils.makeListFromString(line.strip(), ',')
            PythonUtils.doesFileExist(l_process[0])
            t_process = PythonUtils.makeTupleFromFile(l_process[0], ',')
            l_yield = []
            ##ll
            ll_VH = ['VH']
            ll_VV = ['VV']
            ll_top = ['top']
            ll_stop = ['stop']
            ll_Wl = ['W+l']
            ll_Wcl = ['W+cl']
            ll_Whf = ['W+hf']
            ll_Zl = ['Z+l']
            ll_Zcl = ['Z+cl']
            ll_Zhf = ['Z+hf']
            ll_MJe = ['MJe']
            ll_MJm = ['MJm']
            ll_tot = ['Total']
            ll_data = ['Data']
            for bin in t_select:
                if bin[0] == 'all':
                    select = self.selectOn + '-' + bin[0]
                else:
                    select = self.selectOn + '-' + bin[0] + '-' + bin[1]

                ## nEvents
                nSignal = 0
                nTot = 0
                nTop = 0
                nStop = 0
                nWl = 0
                nWh = 0
                nWcl = 0
                nZl = 0
                nZh = 0
                nZcl = 0
                nVV = 0
                nMJe = 0
                nMJm = 0
                nData = 0
                ##nEventsErr
                eSignal = 0
                eTot = 0
                eTop = 0
                eStop = 0
                eWl = 0
                eWh = 0
                eWcl = 0
                eZl = 0
                eZh = 0
                eZcl = 0
                eVV = 0
                eMJe = 0
                eMJm = 0
                eData = 0

                for i in xrange(len(t_process)):
                    process, sLocation, pType, selection, SF = t_process[i]
                    location = sLocation + '/all/' + select + '/' + self.histLocation
                    hist = ROOTUtils.retrieveHistogram(self.inputFile,
                                                       location,
                                                       self.histogram)
                    yValue, yErr = ROOTUtils.getYield(hist, l_range[0],
                                                      l_range[1],
                                                      t_process[i][4])
                    if pType == "SIGNAL":
                        nTot += yValue
                        nSignal += yValue
                        eSignal += yErr
                        eTot += yErr
                    elif pType == "W+H":
                        nTot += yValue
                        nWh += yValue
                        eWh += yErr
                        eTot += yErr
                    elif pType == "W+CL":
                        nTot += yValue
                        nWcl += yValue
                        eWcl += yErr
                        eTot += yErr
                    elif pType == "W+L":
                        nTot += yValue
                        nWl += yValue
                        eWl += yErr
                        eTot += yErr
                    elif pType == "Z+H":
                        nTot += yValue
                        nZh += yValue
                        eZh += yErr
                        eTot += yErr
                    elif pType == "Z+CL":
                        nTot += yValue
                        nZcl += yValue
                        eZcl += yErr
                        eTot += yErr
                    elif pType == "Z+L":
                        nTot += yValue
                        nZl += yValue
                        eZl += yErr
                        eTot += yErr
                    elif pType == "TOP":
                        nTot += yValue
                        nTop += yValue
                        eTop += yErr
                        eTot += yErr
                    elif pType == "STOP":
                        nTot += yValue
                        nStop += yValue
                        nStop += yErr
                        eTot += yErr
                    elif pType == "VV":
                        nTot += yValue
                        nVV += yValue
                        eVV += yErr
                        eTot += yErr
                    elif pType == "MJe":
                        nTot += yValue
                        nMJe += yValue
                        nMJe += yErr
                        eTot += yErr
                    elif pType == "MJm":
                        nTot += yValue
                        nMJm += yValue
                        eMJm += yErr
                        eTot += yErr
                    elif pType == "DATA":
                        nData += yValue
                        eData += yErr
                    else:
                        PythonUtils.Error('Not a valid selection: ' +
                                          t_process[i][2] + '!!!\n')

                l_VH = [nSignal, eSignal]
                ll_VH.append(l_VH)
                l_VV = [nVV, eVV]
                ll_VV.append(l_VV)
                l_top = [nTop, eTop]
                ll_top.append(l_top)
                l_stop = [nStop, eStop]
                ll_stop.append(l_stop)
                l_Wl = [nWl, eWl]
                ll_Wl.append(l_Wl)
                l_Wcl = [nWcl, eWcl]
                ll_Wcl.append(l_Wcl)
                l_Whf = [nWh, eWh]
                ll_Whf.append(l_Whf)
                l_Zl = [nZl, eZl]
                ll_Zl.append(l_Zl)
                l_Zcl = [nZcl, eZcl]
                ll_Zcl.append(l_Zcl)
                l_Zhf = [nZh, eZh]
                ll_Zhf.append(l_Zhf)
                l_MJe = [nMJe, eMJe]
                ll_MJe.append(l_MJe)
                l_MJm = [nMJm, eMJm]
                ll_MJm.append(l_MJm)
                l_tot = [nTot, eTot]
                ll_tot.append(l_tot)
                l_data = [nData, eData]
                ll_data.append(l_data)

            l_yield = [
                ll_VH, ll_VV, ll_top, ll_stop, ll_Wl, ll_Wcl, ll_Whf, ll_Zl,
                ll_Zcl, ll_Zhf, ll_MJe, ll_MJm, ll_tot, ll_data
            ]

            self.printToScreen(l_yield, select + ' ' + t_process[i][3])

            if self.createTex:
                texFile = self.saveToTex(l_yield, l_process[1],
                                         self.outputFile)
                self.runLatex(self.outputFile, texFile)
Пример #18
0
if len(args) < 1:
    parser.error('wrong number of command line arguments')
if options.srcNtName and not 'extract' in args:
    parser.error('must give extract command when using -e or --srcnt')
if options.interactive:
    os.environ['PYTHONINSPECT'] = '1'
cmdList = args

# Reset DISPLAY if in batch
if options.batch:
    os.unsetenv('DISPLAY')

# Place after option parsing to avoid conflict with ROOT option parsing
import ROOT
import ROOTUtils
ROOTUtils.setStyle()
ROOT.gStyle.SetOptStat(options.optstat)


#
# Utilities
#
def logresult(cmd='', fitresult=None):
    log = open('%s.txt' % options.name, 'w')
    if cmd:
        log.write(cmd)
        log.write('\n')
    if fitresult:
        out = ROOT.std.stringstream()
        fitresult.printStream(out, fitresult.defaultPrintContents(''),
                              fitresult.defaultPrintStyle(''))
Пример #19
0
    def Run(self):

        ## Add the trailing slash to the end of latexDir
        if not self.latexDir.endswith('/'):
            latexDir = self.latexDir + '/'
            PythonUtils.doesDirExist(latexDir)
        else:
            latexDir = self.latexDir

        ## Check the .list files exist
        l_fList = [
            self.processList, self.histoList, self.corrList, self.histFile
        ]
        for file in l_fList:
            PythonUtils.doesFileExist(file)

        ## Make the lists from the list files
        t_histoList = PythonUtils.makeTupleFromFile(self.histoList, ',')
        t_corrList = PythonUtils.makeTupleFromFile(self.corrList, ',')
        t_pList = PythonUtils.makeTupleFromFile(self.processList, ',')

        ## Create the variable name dictionary
        compTo = ''
        d_nameVar = {}
        for i in xrange(len(t_corrList)):
            d_nameVar[t_corrList[i][0]] = t_corrList[i][1]
            if t_corrList[i][2] == '1':
                compTo = t_corrList[i][0]

        ## Construct the list of processes for each region

        l_pFiles = []
        f = open(self.processList, 'r')
        for line in f:
            if not line.startswith('#'):
                l_pFiles.append(line.strip())

        for i in xrange(len(t_pList)):
            pFile, tagType = t_pList[i]
            PythonUtils.doesFileExist(pFile)
            t_processList = PythonUtils.makeTupleFromFile(pFile, ',')
            ld_sens = []
            l_pTV = []
            option = ''
            for k in xrange(len(t_histoList)):
                l_pTV.append(t_histoList[k][3])
                d_sens = {}
                l_corrName = []
                #                option = t_histoList[k][2]
                for name, title in d_nameVar.iteritems():
                    t_h = []
                    l_corrName.append(name)
                    for j in xrange(len(t_processList)):
                        option = t_processList[j][0]
                        hLocation = t_processList[j][1] + t_histoList[k][1]
                        t_h.append([
                            ROOTUtils.retrieveHistogram(
                                self.histFile, hLocation,
                                title), t_processList[j][0],
                            t_processList[j][2], t_processList[j][3]
                        ])

                    sens, sensErr = ROOTUtils.calculateSensitivity(
                        t_h, t_histoList[k], name)

                    d_sens[name] = [sens, sensErr]
                    d_sens[name] = ROOTUtils.calculateSensitivity(
                        t_h, t_histoList[k], name)

                l_sens = [t_histoList[k][0] + ' ' + tagType, d_sens]
                ld_sens.append(l_sens)

            t_sens = PythonUtils.rankByValue(ld_sens, compTo, 'SENSITIVITY')
            if self.doLatex:
                latex = self.writeLatex(
                    t_sens, l_corrName, l_pTV,
                    'Sensitivity_' + tagType + '_' + option, latexDir)
                PythonUtils.runLatex(latex, latexDir)
Пример #20
0
    def Run(self):

        ## Create lists from config file options
        l_saveAs = PythonUtils.makeListFromString(self.saveAs, ',')

        ## Check the .list files exist
        l_listFile = [self.axisList, self.fitList, self.histoList, self.legendList,
                      self.textList, self.variableList, self.histFile]
        for file in l_listFile:
            PythonUtils.doesFileExist(file)

        ## Create the tuples from the .list files
        t_axisList   = PythonUtils.makeTupleFromFile(self.axisList,   ',')
        t_fitList    = PythonUtils.makeTupleFromFile(self.fitList,    ',')
        t_histoList  = PythonUtils.makeTupleFromFile(self.histoList,  ',')
        t_legendList = PythonUtils.makeTupleFromFile(self.legendList, ',')
        t_textList   = PythonUtils.makeTupleFromFile(self.textList,   ',')

        ## Math the first titems
        l_tuples = [t_fitList, t_histoList, t_legendList, t_textList]
        for item in l_tuples:
            PythonUtils.firstItemMatching(t_axisList, item)
        
        ## Loop over the variable files to get the relevant info
        for j in xrange(len(t_axisList)):
            f_str, vRebin, vdoNorm, vXMin, vXMax, vFit, vXValue, vYValue = t_fitList[j]

            l_files = []
            f = open(self.variableList, 'r')
            for file in f:
                l_files.append(file.strip())
            
            l_twoD = []
            t_legend = []
            PythonUtils.doesFileExist(l_files[j])
            g = open(l_files[j], 'r')
            for vFile in g:
                PythonUtils.doesFileExist(vFile.strip())
                vFileParser = ConfigParser.SafeConfigParser()
                vFileParser.read(vFile.strip())
                ## Options
                vTitle      = vFileParser.get('Options','title')
                vVariable   = vFileParser.get('Options','variable')
                vColour     = vFileParser.getint('Options','colour')
                vMarker     = vFileParser.getint('Options','marker')
                vMarkerSize = vFileParser.getfloat('Options','markerSize')
                vFitMin     = vFileParser.get('Options','fitMin')
                vFitMax     = vFileParser.get('Options','fitMax')

                ## Create l_statInfo
                l_statInfo = [t_histoList[j][1], t_histoList[j][1], float(vRebin), int(vdoNorm),
                              float(vXMin), float(vXMax), vFitMin, vFitMax]

                getMean = 0
                getRMS  = 0
                getRES  = 0
                if vXValue == 'MEAN':
                    getMean = 1
                elif vXValue == 'RMS':
                    getRMS = 1
                elif vXValue == 'RESOLUTION':
                    getRES = 1
                else:
                    getMean = getRMS = getRES = 0
                l_xOption = [getMean, getRMS, getRES]
                
                getMean = 0
                getRMS  = 0
                getRES  = 0
                if vYValue == 'MEAN':
                    getMean = 1
                elif vYValue == 'RMS':
                    getRMS = 1
                elif vYValue == 'RESOLUTION':
                    getRES = 1
                else:
                    getMean = getRMS = getRES = 0
                l_yOption = [getMean, getRMS, getRES]
                
                ## Get the list of stats
                l_plot =  [ROOTUtils.retrieveHistogram(self.histFile, t_histoList[j][1], vVariable)]
                l_xValue, l_xErr = ROOTUtils.getHistoStat(l_plot, l_statInfo, l_xOption, vFit, vVariable)
                l_yValue, l_yErr = ROOTUtils.getHistoStat(l_plot, l_statInfo, l_yOption, vFit, vVariable)

                ## Get the value we want from the list so we can plot it!
                xValue = -1
                for stat in l_xValue:
                    if stat != -1:
                        xValue = stat

                for stat in l_yValue:
                    if stat != -1:
                        yValue = stat
               
                ## Create a 2D plot and save to a list so can overlay them
                twoDPlot = PlottingUtils.createTwoD(t_histoList[j], xValue, yValue,
                                                    vMarker, vMarkerSize, vColour)
                l_twoD.append(twoDPlot)
                if vTitle:
                    l_legend = [twoDPlot, vTitle, 'p']
                    t_legend.append(l_legend)
            
            ## Overlay our 2D plots onto one canvas
            PlottingUtils.overlayTwoD(l_twoD, t_legend, t_histoList[j], t_legendList[j], 
                                       t_textList[j], t_axisList[j], self.saveDir, l_saveAs)
Пример #21
0
    def Run(self, doProfile, createFile):

        ## Create the lists from the main configFile
        t_select = PythonUtils.makeTupleFromString(self.selectBins, ',', '?')
        t_muon   = PythonUtils.makeTupleFromString(self.muBins,     ',', '?')

        if createFile:
            PythonUtils.Info('Creating Histogram File for Profile Plots')
            ## Check the list files exist
            l_fList = [self.variableList, self.treeList]
            for f in l_fList:
                PythonUtils.doesFileExist(f)

            ## Make the lists from the list files
            t_var  = PythonUtils.makeTupleFromFile(self.variableList, ',')
            t_tree = PythonUtils.makeTupleFromFile(self.treeList, ',')

            for i in xrange(len(t_tree)):
                tFile, tName, sDir = t_tree[i]
                PythonUtils.doesFileExist(tFile)

                d_histType    = self.createHistograms(t_var, sDir, tFile, t_muon, 
                                                      self.selectOn, t_select)
                d_filledHists = self.fillHistograms(d_histType, t_var, tFile, tName, sDir, t_muon,
                                                    t_select, self.selectOn, self.nEvents)
                self.saveHistograms(d_filledHists, t_var, self.outHist, 
                                    sDir, t_muon, self.selectOn, t_select)

        if doProfile:
            PythonUtils.Info("Creating Profile Plots!")

            ## Create the Lists from profile cfg
            l_saveAs = PythonUtils.makeListFromString(self.plotType, ',')

            ## Check the list files exist
            l_pList = [self.axisList, self.histoList, self.legendList, 
                       self.textList, self.varList, self.inFile]

            for f in l_pList:
                PythonUtils.doesFileExist(f)

            ## Create the list of lists from each list file
            t_axisList    = PythonUtils.makeTupleFromFile(self.axisList,    ',')
            t_histoList   = PythonUtils.makeTupleFromFile(self.histoList,   ',')
            t_legendList  = PythonUtils.makeTupleFromFile(self.legendList,  ',')
            t_textList    = PythonUtils.makeTupleFromFile(self.textList,    ',')
            
            ## Check teh first Item matches:
            l_tList = [t_histoList, t_legendList, t_textList]
            for l in l_tList:
                PythonUtils.firstItemMatching(l, t_axisList)

            ## Add the var list files to a list
            l_varList = []
            f = open(self.varList, 'r')
            for line in f:
                if line.startswith('#'):
                    continue
                else:
                    l_varList.append(line)
            
            for i in xrange(len(l_varList)):
                PythonUtils.doesFileExist(l_varList[i].strip())
                t_varList = PythonUtils.makeTupleFromFile(l_varList[i].strip(), ',')
                l_prof = []
                t_legend = []
                for j in xrange(len(t_varList)):
                    d_pTMean = {}
                    l_err = []
                    for bin in t_select:
                        if bin[0] == 'all' or bin[1] == 'Inf': 
                            continue
                        if bin[1]:
                            select = self.selectOn + '-' + bin[0] + '-' + bin[1]
                        else:
                            select = self.selectOn + '-' + bin[0]
                        
                        location = t_varList[j][2] + '/' + t_varList[j][6] + '/' + select + '/' + t_varList[j][7]
                        pTbin = float(bin[0]) + (float(bin[1]) - float(bin[0])) / 2
                        pTMean = ROOTUtils.retrieveHistogram(self.inFile, location, t_varList[j][1]).GetMean()
                        pTMeanErr = ROOTUtils.retrieveHistogram(self.inFile, location, t_varList[j][1]).GetMeanError()
                        l_err.append(pTMeanErr)
                        d_pTMean[pTbin] = pTMean

                    h_prof, l_legend= PlottingUtils.twoDprofile(d_pTMean, t_histoList[i], t_varList[j], l_err)
                    l_prof.append(h_prof)
                    t_legend.append(l_legend)

                saveString = self.plotDir + t_histoList[i][0] 
                PlottingUtils.overlayProfile(l_prof, t_axisList[i], t_histoList[i], t_legendList[i], t_textList[i], t_legend, l_saveAs, saveString)
Пример #22
0
    def Run(self):

        ## Make the list from the config file
        l_range  = PythonUtils.makeListFromString(self.plotRange, ',')
        t_select = PythonUtils.makeTupleFromString(self.selectBins, ',','?')
        
        ## Check the input and process files exist
        l_file = [self.processList, self.inputFile]
        for file in l_file:
            PythonUtils.doesFileExist(file)
        
        ## Loop over the ProcessList files
        f = open(self.processList, 'r')
        for line in f:
            if line.startswith('#'):
                continue
            
            l_process = PythonUtils.makeListFromString(line.strip(), ',')
            PythonUtils.doesFileExist(l_process[0])
            t_process = PythonUtils.makeTupleFromFile(l_process[0], ',')
            l_yield = []
            ##ll
            ll_VH = ['VH']
            ll_VV = ['VV']
            ll_top = ['top']
            ll_stop = ['stop']
            ll_Wl = ['W+l']
            ll_Wcl = ['W+cl']
            ll_Whf = ['W+hf']
            ll_Zl = ['Z+l']
            ll_Zcl = ['Z+cl']
            ll_Zhf = ['Z+hf']
            ll_MJe = ['MJe']
            ll_MJm = ['MJm']
            ll_tot = ['Total']
            ll_data = ['Data']
            for bin in t_select:
                if bin[0] == 'all':
                    select = self.selectOn + '-' + bin[0]
                else:
                    select = self.selectOn + '-' + bin[0] + '-' + bin[1]
           
                
                ## nEvents
                nSignal = 0
                nTot    = 0
                nTop    = 0
                nStop   = 0
                nWl     = 0
                nWh     = 0
                nWcl    = 0
                nZl     = 0
                nZh     = 0
                nZcl    = 0
                nVV     = 0
                nMJe    = 0
                nMJm    = 0
                nData   = 0
                ##nEventsErr
                eSignal = 0
                eTot    = 0
                eTop    = 0
                eStop   = 0
                eWl     = 0
                eWh     = 0
                eWcl    = 0
                eZl     = 0
                eZh     = 0
                eZcl    = 0
                eVV     = 0
                eMJe    = 0
                eMJm    = 0
                eData   = 0

                for i in xrange(len(t_process)):
                    process, sLocation, pType, selection, SF = t_process[i]
                    location = sLocation + '/all/' + select + '/' + self.histLocation
                    hist = ROOTUtils.retrieveHistogram(self.inputFile, location, self.histogram)
                    yValue, yErr = ROOTUtils.getYield(hist, l_range[0], l_range[1], t_process[i][4])
                    if pType == "SIGNAL":
                        nTot    += yValue
                        nSignal += yValue
                        eSignal += yErr
                        eTot    += yErr
                    elif pType == "W+H":
                        nTot += yValue
                        nWh  += yValue
                        eWh  += yErr
                        eTot += yErr
                    elif pType == "W+CL":
                        nTot += yValue
                        nWcl += yValue
                        eWcl  += yErr
                        eTot += yErr
                    elif pType == "W+L":
                        nTot += yValue
                        nWl  += yValue
                        eWl  += yErr
                        eTot += yErr
                    elif pType == "Z+H":
                        nTot += yValue
                        nZh  += yValue
                        eZh  += yErr
                        eTot += yErr
                    elif pType == "Z+CL":
                        nTot += yValue
                        nZcl += yValue
                        eZcl  += yErr
                        eTot += yErr
                    elif pType == "Z+L":
                        nTot += yValue
                        nZl  += yValue
                        eZl  += yErr
                        eTot += yErr
                    elif pType == "TOP":
                        nTot += yValue
                        nTop += yValue
                        eTop += yErr
                        eTot += yErr
                    elif pType == "STOP":
                        nTot  += yValue
                        nStop += yValue
                        nStop += yErr
                        eTot  += yErr
                    elif pType == "VV":
                        nTot += yValue
                        nVV  += yValue
                        eVV  += yErr
                        eTot += yErr
                    elif pType == "MJe":
                        nTot  += yValue
                        nMJe  += yValue
                        nMJe  += yErr
                        eTot  += yErr
                    elif pType == "MJm":
                        nTot  += yValue
                        nMJm  += yValue
                        eMJm  += yErr
                        eTot  += yErr
                    elif pType == "DATA":
                        nData += yValue
                        eData += yErr
                    else:
                        PythonUtils.Error('Not a valid selection: ' + t_process[i][2] + '!!!\n')

                
                l_VH =   [nSignal, eSignal]
                ll_VH.append(l_VH)
                l_VV =   [nVV,     eVV]
                ll_VV.append(l_VV)
                l_top =  [nTop,    eTop]
                ll_top.append(l_top)
                l_stop = [nStop,   eStop]
                ll_stop.append(l_stop)
                l_Wl =   [nWl,     eWl]
                ll_Wl.append(l_Wl)
                l_Wcl =  [nWcl,    eWcl]
                ll_Wcl.append(l_Wcl)
                l_Whf =  [nWh,     eWh]
                ll_Whf.append(l_Whf)
                l_Zl =   [nZl,     eZl]
                ll_Zl.append(l_Zl)
                l_Zcl =  [nZcl,    eZcl]
                ll_Zcl.append(l_Zcl)
                l_Zhf =  [nZh,     eZh]
                ll_Zhf.append(l_Zhf)
                l_MJe =  [nMJe,    eMJe]
                ll_MJe.append(l_MJe)
                l_MJm =  [nMJm,    eMJm]
                ll_MJm.append(l_MJm)
                l_tot =  [nTot,    eTot]
                ll_tot.append(l_tot)
                l_data = [nData,   eData]
                ll_data.append(l_data)

            l_yield = [ll_VH, ll_VV, ll_top, ll_stop, ll_Wl, ll_Wcl, ll_Whf, 
                       ll_Zl, ll_Zcl, ll_Zhf, ll_MJe, ll_MJm, ll_tot, ll_data]

            self.printToScreen(l_yield, select + ' ' + t_process[i][3])

            if self.createTex:
                    texFile = self.saveToTex(l_yield, l_process[1], self.outputFile)
                    self.runLatex(self.outputFile, texFile)
Пример #23
0
    def Run(self):

        ## Add the trailing slash to the end of latexDir
        if not self.latexDir.endswith('/'):
            latexDir = self.latexDir + '/'
            PythonUtils.doesDirExist(latexDir)
        else:
            latexDir = self.latexDir

        ## Check the .list files exist
        l_fList = [self.processList, self.histoList, 
                   self.corrList, self.histFile]
        for file in l_fList:
            PythonUtils.doesFileExist(file)

        ## Make the lists from the list files
        t_histoList = PythonUtils.makeTupleFromFile(self.histoList,   ',')
        t_corrList  = PythonUtils.makeTupleFromFile(self.corrList,    ',')
        t_pList     = PythonUtils.makeTupleFromFile(self.processList, ',')

        ## Create the variable name dictionary
        compTo = ''
        d_nameVar = {}
        for i in xrange(len(t_corrList)):
            d_nameVar[t_corrList[i][0]] = t_corrList[i][1]
            if t_corrList[i][2] == '1':
                compTo = t_corrList[i][0]

        ## Construct the list of processes for each region
        
        
        l_pFiles = []
        f = open(self.processList, 'r')
        for line in f:
            if not line.startswith('#'):
                l_pFiles.append(line.strip())

        for i in xrange(len(t_pList)):
            pFile, tagType = t_pList[i]
            PythonUtils.doesFileExist(pFile)
            t_processList = PythonUtils.makeTupleFromFile(pFile, ',')
            ld_sens = []
            l_pTV = []
            option = ''
            for k in xrange(len(t_histoList)):
                l_pTV.append(t_histoList[k][3])
                d_sens = {}
                l_corrName = []
#                option = t_histoList[k][2]
                for name, title in d_nameVar.iteritems():
                    t_h = []
                    l_corrName.append(name)
                    for j in xrange(len(t_processList)):
                        option = t_processList[j][0]
                        hLocation = t_processList[j][1] + t_histoList[k][1]
                        t_h.append([ROOTUtils.retrieveHistogram(self.histFile, hLocation, title), t_processList[j][0], t_processList[j][2], t_processList[j][3]])
                    
                    sens, sensErr = ROOTUtils.calculateSensitivity(t_h, t_histoList[k], name)
                    
                    d_sens[name] = [sens, sensErr] 
                    d_sens[name] = ROOTUtils.calculateSensitivity(t_h, t_histoList[k], name) 

                l_sens = [t_histoList[k][0] + ' ' + tagType, d_sens]
                ld_sens.append(l_sens)
            
            t_sens = PythonUtils.rankByValue(ld_sens, compTo, 'SENSITIVITY')
            if self.doLatex:
                latex = self.writeLatex(t_sens, l_corrName, l_pTV, 
                                'Sensitivity_' + tagType + '_' + option, latexDir)
                PythonUtils.runLatex(latex, latexDir)
Пример #24
0
    def Run(self):

        ## Check the files in the config file exist
        l_file = [self.histFile, self.correctionList, 
                  self.histoList, self.fittingList]
        for file in l_file:
            PythonUtils.doesFileExist(file)

        ## Add the trailing slash to the end of latexDir
        if not self.latexDir.endswith('/'):
            latexDir = self.latexDir + '/'
            PythonUtils.doesDirExist(latexDir)
        else:
            latexDir = self.latexDir

        ## Make tuples from the list files
        t_histoList =   PythonUtils.makeTupleFromFile(self.histoList, ',')
        t_fittingList = PythonUtils.makeTupleFromFile(self.fittingList, ',')
        
        ## Loop over the files in correctionsList each one is a new run
        l_cFiles = []
        f = open(self.correctionList, 'r')
        for file in f:
            if file.startswith('#'):
                continue
            else:
                l_cFiles.append(file.strip())
       
        for i in xrange(len(l_cFiles)):
            ld_mean = []
            ld_rms  = []
            ld_res  = []
            l_getOption = [int(t_fittingList[i][2]), int(t_fittingList[i][3]), int(t_fittingList[i][4])]
            ## Check the file in the list exists
            PythonUtils.doesFileExist(l_cFiles[i])
            t_corrList = PythonUtils.makeTupleFromFile(l_cFiles[i], ',')
            d_meanResRMS = {}
            tagType = ''
            for j in xrange(len(t_corrList)):
                h_location = t_corrList[j][1] + t_histoList[i][1]
                t_histoList[i].append(t_corrList[j][3])
                t_histoList[i].append(t_corrList[j][4])
                l_hist = [t_histoList[i][0], t_histoList[i][1], t_histoList[i][2], 
                          t_histoList[i][3], t_histoList[i][4], t_histoList[i][5], 
                          t_corrList[j][3], t_corrList[j][4]]
                
                pTVBin = t_histoList[i][6]
                tagType = t_histoList[i][7]
                l_h = [ROOTUtils.retrieveHistogram(self.histFile, 
                       h_location, t_corrList[j][2])]
                
                d_meanResRMS[t_corrList[j][0]] = ROOTUtils.getHistoStat(l_h, l_hist, l_getOption, 
                                                                        t_fittingList[i][5], t_corrList[j][0])


            ## We now have all the info to calculate the stats from the plots!

            d_mean = {}
            d_RMS  = {}
            d_res  = {}
            getMean, getRMS, getResolution = l_getOption
            compareTo = t_fittingList[i][1]
            fit = t_fittingList[i][5]
            l_corrName = []
            for k, v in d_meanResRMS.iteritems():
                l_corrName.append(k)
                if getMean:
                    d_mean[k] = [v[0][0], v[1][0]]
                if getRMS:
                    d_RMS[k]  = [v[0][1], v[1][1]]
                if getResolution:
                    d_res[k]  = [v[0][2], v[1][2]]

            ld_mean.append([t_histoList[i][0], d_mean])
            ld_rms.append([t_histoList[i][0], d_RMS])
            ld_res.append([t_histoList[i][0], d_res])
            t_mRr = []
            if getMean:
                t_mRr.append(PythonUtils.rankByValue(ld_mean, compareTo,
                                                     fit + ' Mean'))
            if getRMS:
                t_mRr.append(PythonUtils.rankByValue(ld_rms, compareTo,
                                                     fit + ' RMS'))
            if getResolution:
                t_mRr.append(PythonUtils.rankByValue(ld_res, compareTo,
                                                     fit + ' Resolution'))

            if self.doLatex:
                latex = self.writeLatex(t_mRr, l_corrName, pTVBin, t_histoList[i][0], latexDir, getMean, getRMS, getResolution)
                PythonUtils.runLatex(latex, latexDir)