Esempio n. 1
0
    def GenerateReport(self, history):

        # Defining report writing
        if self.mode is ReportFormatType.HTML:
            report = HTMLReportWriter(self.output_path + "/index.html")
        elif self.mode is ReportFormatType.LATEX:
            report = LATEXReportWriter(self.output_path + "/main.tex", False)
        else:
            report = LATEXReportWriter(self.output_path + "/main.tex", True)

        # Opening
        if not report.Open():
            return False

        # Create text
        text = TextReport()

        # Header
        report.WriteHeader()
        report.WriteTitle('MadAnalysis 5 report')
        report.WriteSpacor()

        # History of commands
        report.WriteSubTitle('Command history')
        text.Reset()
        text.SetFont(FontType.TT)
        for item in history:
            text.Add('ma5>' + item + '\n')
        report.WriteText(text)

        # Configuration
        report.WriteSubTitle('Configuration')

        # Integrated luminosity
        text.Reset()
        text.Add('MadAnalysis version ' + self.main.version + \
                 ' (' + self.main.date + ').\n')
        report.WriteText(text)

        # Integrated luminosity
        text.Reset()

        # Normalization
        if self.main.normalize == NormalizeType.LUMI or \
           self.main.normalize == NormalizeType.LUMI_WEIGHT:
            text.Add('Histograms correspond to an integrated luminosity of ')
            text.SetColor(ColorType.BLUE)
            text.Add(str(self.main.lumi))
            text.SetColor(ColorType.BLUE)
            text.Add(' fb')
            text.SetScript(ScriptType.SUP)
            text.Add('-1')
            text.SetScript(ScriptType.none)
            text.Add('.\n')
        elif self.main.normalize == NormalizeType.NONE:
            text.Add('Histograms are not scaled.\n')

        report.WriteText(text)

        # Datasets
        report.WriteSubTitle('Datasets used')
        for ind in range(0, len(self.main.datasets)):
            datatype = "signal"
            if self.main.datasets[ind].background:
                datatype = "background"
            report.WriteSubSubTitle(
                self.main.datasets[ind].name + \
                ' (' + datatype + ')' )
            self.WriteDatasetTable(self.files[ind],report,self.main.datasets[ind].xsection,\
                                   self.main.datasets[ind].weight)

        # Plots display
        report.WriteSubTitle('Histograms / Cuts')

        # Plots
        ihisto = 0
        icut = 0
        for ind in range(0, len(self.main.selection)):
            if self.main.selection[ind].__class__.__name__ == "Histogram":
                report.WriteSubSubTitle("Histogram number " + str(ihisto + 1))
                if self.main.selection[ind].observable.name not in [
                        'NPID', 'NAPID'
                ]:
                    self.WriteStatisticsTable(ihisto, report)
                text.Reset()
                text.Add("Histogram number " + str(ihisto + 1))
                report.WriteFigure(text,self.output_path +"/"+
                           'selection_'+str(ihisto),\
                           1.0)
                ihisto += 1
            if self.main.selection[ind].__class__.__name__ == "Cut":
                report.WriteSubSubTitle("Cut number " + str(icut + 1))
                text.Reset()
                text.Add(self.main.selection[ind].GetStringDisplay() + '\n')
                report.WriteText(text)
                self.WriteEfficiencyTable(icut, report)
                icut += 1

        # Final table
        if self.main.selection.Ncuts != 0:
            report.WriteSubTitle('Signal and Background comparison')
            self.WriteFinalTable(report)

        # Foot
        report.WriteFoot()

        # Closing
        report.Close()

        return True
Esempio n. 2
0
    def GenerateReport(self, history, output_path, mode):

        # Creating production directory
        if not FolderWriter.CreateDirectory(output_path, True):
            return False

        if not self.CopyLogo(mode, output_path):
            return False

        # Draw plots
        if not self.DoPlots(mode, output_path):
            return

#       logging.info("     ** Computing cut efficiencies...")
#if not layout.DoEfficiencies():
#    return

# Find a name for PDF file
        if self.main.pdflatex:
            self.pdffile = self.main.lastjob_name + '/PDF/main.pdf'
        elif self.main.latex and self.main.dvipdf:
            self.pdffile = self.main.lastjob_name + '/DVI/main.pdf'
        else:
            self.pdffile = ''

        # Defining report writing
        if mode == ReportFormatType.HTML:
            report = HTMLReportWriter(output_path + "/index.html",
                                      self.pdffile)
        elif mode == ReportFormatType.LATEX:
            report = LATEXReportWriter(output_path+"/main.tex",\
              self.main.ma5dir+"/madanalysis/input",False)
        else:
            report = LATEXReportWriter(output_path+"/main.tex",\
              self.main.ma5dir+"/madanalysis/input",True)

        # Opening
        if not report.Open():
            return False

        # Create text
        text = TextReport()

        # Header
        report.WriteHeader()
        report.WriteTitle('MadAnalysis 5 report')

        # History of commands
        report.WriteSubTitle('Setup')
        report.WriteSubSubTitle('Command history')
        text.Reset()
        text.SetFont(FontType.TT)
        for item in history:
            text.Add('ma5>' + item + '\n\n')
        report.WriteText(text)

        # Configuration
        report.WriteSubSubTitle('Configuration')

        # Integrated luminosity
        report.OpenBullet()
        text.Reset()
        text.Add('MadAnalysis version ' + self.main.version + \
                 ' (' + self.main.date + ').\n')
        report.WriteText(text)

        # Integrated luminosity
        text.Reset()

        # Normalization
        if self.main.normalize == NormalizeType.LUMI or \
           self.main.normalize == NormalizeType.LUMI_WEIGHT:
            text.Add('Histograms given for an integrated luminosity of ')
            text.SetColor(ColorType.BLUE)
            text.Add(str(self.main.lumi))
            text.Add(' fb')
            text.SetScript(ScriptType.SUP)
            text.Add('-1')
            text.SetScript(ScriptType.none)
            text.Add('.\n')
        elif self.main.normalize == NormalizeType.NONE:
            text.Add('Histograms are not scaled.\n')
        report.WriteText(text)
        report.CloseBullet()

        # Datasets
        report.WriteSubTitle('Datasets')
        for ind in range(0, len(self.main.datasets)):
            report.WriteSubSubTitle(self.main.datasets[ind].name)
            self.WriteDatasetTable(report,\
                                   self.main.datasets[ind])

        # Merging plots
        if self.main.merging.enable:

            # Title : merging plots
            report.WriteSubTitle('Merging plots')

            # Getting all plot names
            allnames = self.merging.GetPlotNames(mode,\
                                                 output_path)

            # Loop over datasets
            for i in range(0, len(allnames)):

                # Subtitle : dataset names
                report.WriteSubSubTitle(self.main.datasets[i].name)

                # Loop over DJR plots
                for j in range(0, len(allnames[i])):
                    text.Reset()
                    title = "DJR" + str(j + 1) + " : " + str(j)
                    if j > 1:
                        title += " jets -> "
                    else:
                        title += " jet -> "
                    title += str(j + 1)
                    if j > 0:
                        title += " jets"
                    else:
                        title += " jet"
                    text.Add(title)
                    report.WriteFigure(text, allnames[i][j])

        # Plots display
        if len(self.main.selection) != 0:
            report.WriteSubTitle('Histos and cuts')

        # Plots
        ihisto = 0
        icut = 0
        for ind in range(0, len(self.main.selection)):
            if self.main.selection[ind].__class__.__name__ == "Histogram":
                report.WriteSubSubTitle("Histogram " + str(ihisto + 1))
                text.Reset()
                text.Add('  ')
                text.SetFont(FontType.BF)
                text.Add(self.main.selection[ind].GetStringDisplay() + '\n')
                report.WriteText(text)
                text.Reset()
                if self.main.selection[ind].observable.name not in [
                        'NPID', 'NAPID'
                ]:
                    self.WriteStatisticsTable(ihisto, report)
                report.WriteFigure(text,
                                   output_path + '/selection_' + str(ihisto))
                text.Add('\n\n')
                report.WriteText(text)
                text.Reset()
                ihisto += 1
            if self.main.selection[ind].__class__.__name__ == "Cut":
                report.WriteSubSubTitle("Cut " + str(icut + 1))
                text.Reset()
                text.Add('  ')
                text.SetFont(FontType.BF)
                text.Add(self.main.selection[ind].GetStringDisplay() + '\n')
                report.WriteText(text)
                text.Reset()
                self.WriteEfficiencyTable(icut, report)
                text.Add('\n\n')
                report.WriteText(text)
                text.Reset()
                icut += 1

        # Final table
        if self.main.selection.Ncuts != 0:
            report.WriteSubTitle('Summary')
            report.WriteSubSubTitle('Cut-flow chart')
            self.WriteFinalTable(report)

        # Foot
        report.WriteFoot()

        # Closing
        report.Close()

        return True
Esempio n. 3
0
    def WriteDatasetTable(self, rootfile, report, xsection, weight):

        filenames = rootfile.Get("general/filenames", "TClonesArray")
        if filenames is None:
            return False

        xsections = rootfile.Get("general/xsections", "TVectorT<float>")
        if xsections is None:
            return False

        xerrors = rootfile.Get("general/xerrors", "TVectorT<float>")
        if xerrors is None:
            return False

        nevents = rootfile.Get("general/nevents", "TVectorT<float>")
        if nevents is None:
            return False

        if filenames.GetEntries()!=xsections.GetNoElements() or \
           xsections.GetNoElements()!=xerrors.GetNoElements() or \
           xerrors.GetNoElements()!=nevents.GetNoElements() or \
           nevents.GetNoElements()!=filenames.GetEntries() :
            logging.error("the 'general' branches have different size "\
                          "in the file '"+filename+"'")
            return

        text = TextReport()

        text.Add('* Generation: ')
        text.SetColor(ColorType.BLUE)
        ngen = int(nevents[filenames.GetEntries() - 1])
        text.Add(str(ngen) + " ")
        text.SetColor(ColorType.BLACK)
        text.Add(' events.\n')
        if xsection != 0.0:
            text.Add('* Cross section imposed by the user: '******' pb.\n')
        if weight != 1.0:
            text.Add('* Event weight imposed by the user: '******'.\n')
        text.Add('* Normalization to ')
        text.Add(str(self.main.lumi))
        text.Add(' fb')
        text.SetScript(ScriptType.SUP)
        text.Add('-1')
        text.SetScript(ScriptType.none)
        text.Add(': ')
        text.SetColor(ColorType.BLUE)
        if xsection != 0.0:
            nlumi = int(xsection * 1000 * self.main.lumi)
        else:
            nlumi = int(xsections[filenames.GetEntries() - 1] * 1000 *
                        self.main.lumi * weight)
        text.Add(str(nlumi))
        text.Add(' +/- ')

        # round to the smallest integer greater than error
        if xsection != 0.0:
            elumi = 0.0
        else:
            elumi = ceil(xerrors[filenames.GetEntries() - 1] * 1000 *
                         self.main.lumi * weight)
        text.Add(str(int(elumi)) + " ")
        text.SetColor(ColorType.BLACK)
        text.Add(' events.\n')
        evw = float(nlumi) / float(ngen) * weight
        if evw > 1:
            text.SetColor(ColorType.RED)
        text.Add('* Ratio (event weight) =  ')
        if evw < 1:
            text.SetColor(ColorType.BLUE)
        text.Add(str(Layout.Round_to_Ndigits(evw, 2)) + " ")
        if evw < 1:
            text.SetColor(ColorType.BLACK)
            text.Add('.')
        if evw > 1:
            text.Add(
                ' - warning: please generate more events (weight larger than 1)!\n'
            )
            text.SetColor(ColorType.BLACK)
        else:
            text.Add(' \n')
        if self.mode is ReportFormatType.HTML:
            text.Add(' \n')
        report.WriteText(text)

        report.CreateTable([11.5, 2, 3])
        report.NewCell(ColorType.YELLOW)
        text.Reset()
        if filenames.GetEntries() > 1:
            text.Add("Event files")
        else:
            text.Add("Event file")
        report.WriteText(text)
        report.NewCell(ColorType.YELLOW)
        text.Reset()
        text.Add("Number of events")
        report.WriteText(text)
        report.NewCell(ColorType.YELLOW)
        text.Reset()
        text.Add("Cross section (pb)")
        report.WriteText(text)
        report.NewLine()

        for ind in range(0, filenames.GetEntries()):
            color = ColorType.BLACK
            if ind is filenames.GetEntries() - 1:
                color = ColorType.BLUE

            report.NewCell()
            text.Reset()
            text.SetColor(color)
            text.Add(str(filenames[ind]))
            report.WriteText(text)
            report.NewCell()
            text.Reset()
            text.SetColor(color)
            text.Add(str(int(nevents[ind])))
            report.WriteText(text)
            report.NewCell()
            text.Reset()
            text.SetColor(color)
            if xsection != 0.0:
                text.Add(str(xsection))
            else:
                text.Add(
                    Layout.DisplayXsection(xsections[ind] * weight,
                                           xerrors[ind] * weight))
            report.WriteText(text)
            report.NewLine()
        text.Reset()
        report.EndTable(text)
        text.Reset()