Exemple #1
0
  def finalize( self ):

    from Gaugi import save, mkdir_p

    outputname = self.getProperty("OutputFile")

    for etBinIdx in range(len(self._etbins)-1):
      for etaBinIdx in range(len(self._etabins)-1):

        key =  'et%d_eta%d' % (etBinIdx,etaBinIdx)
        mkdir_p( outputname )
        if self._event[key] is None:
          continue

        d = {
            "features"  : self._event_label,
            "etBins"    : self._etbins,
            "etaBins"   : self._etabins,
            "etBinIdx"  : etBinIdx,
            "etaBinIdx" : etaBinIdx
            }

        d[ 'pattern_'+key ] = np.array( self._event[key] )
        MSG_INFO( self, 'Saving %s with : (%d, %d)', key, d['pattern_'+key].shape[0], d['pattern_'+key].shape[1] )
        save( d, outputname+'/'+outputname+"_"+key , protocol = 'savez_compressed')
    return StatusCode.SUCCESS
Exemple #2
0
    def __call__(self, **kw):
        # Cross validation configuration
        outputFolder = retrieve_kw(kw, 'outputFolder', 'jobConfig')
        sortBounds = retrieve_kw(kw, 'sortBounds', 5)
        nInits = retrieve_kw(kw, 'nInits', 10)
        nSortsPerJob = retrieve_kw(kw, 'nSortsPerJob', 1)
        nInitsPerJob = retrieve_kw(kw, 'nInitsPerJob', 10)
        nModelsPerJob = retrieve_kw(kw, 'nModelsPerJob', 1)
        models = retrieve_kw(kw, 'models', [default_model])
        model_tags = retrieve_kw(kw, 'model_tags', ['mlp_100_5_1'])
        crossval = retrieve_kw(kw, 'crossval',
                               KFold(10, shuffle=True, random_state=512))

        time_stamp = self.time_stamp()
        # creating the job mechanism file first
        mkdir_p(outputFolder)

        if type(models) is not list:
            models = [models]

        modelJobsWindowList = create_iter(
            lambda i, sorts: list(range(i, i + sorts)), nModelsPerJob,
            len(models))
        sortJobsWindowList = create_iter(
            lambda i, sorts: list(range(i, i + sorts)), nSortsPerJob,
            sortBounds)
        initJobsWindowList = create_iter(
            lambda i, sorts: list(range(i, i + sorts)), nInitsPerJob, nInits)

        nJobs = 0
        for (model_idx_list, sort_list,
             init_list) in product(modelJobsWindowList, sortJobsWindowList,
                                   initJobsWindowList):

            MSG_INFO(
                self,
                'Creating job config with sort (%d to %d) and %d inits and model Index %d to %d',
                sort_list[0], sort_list[-1], len(init_list), model_idx_list[0],
                model_idx_list[-1])

            from saphyra.core.readers.versions import Job_v1
            job = Job_v1()
            # to be user by the database table
            job.setId(nJobs)
            job.setSorts(sort_list)
            job.setInits(init_list)
            job.setModels([models[idx] for idx in model_idx_list],
                          model_idx_list)
            # save config file
            model_str = 'ml%i.mu%i' % (model_idx_list[0], model_idx_list[-1])
            sort_str = 'sl%i.su%i' % (sort_list[0], sort_list[-1])
            init_str = 'il%i.iu%i' % (init_list[0], init_list[-1])
            job.save(outputFolder + '/' + ('job_config.ID_%s.%s_%s_%s.%s') %
                     (str(nJobs).zfill(4), model_str, sort_str, init_str,
                      time_stamp))
            nJobs += 1

        MSG_INFO(self, "A total of %d jobs...", nJobs)
numberOfJobs = 1

from Gaugi import save, mkdir_p

mkdir_p('job_config_dummy')

for job_id in range(numberOfJobs):
    name = 'job_config_dummy/job_config.id%1.4d.dummy' % (job_id)
    f = open(name, 'w')
    f.write(str(job_id))
    f.close()

f = open('data.dummy', 'w')
f.close()
Exemple #4
0
    def plot(self, dirnames, pdfoutputs, pdftitles, runLabel='', doPDF=True):

        SetAtlasStyle()
        beamer_plots = {}
        global tobject_collector

        basepath = self.getProperty("Basepath")
        etBins = self.getProperty("EtBinningValues")
        etaBins = self.getProperty("EtaBinningValues")

        for idx, feat in enumerate(self.__selectionFeatures):

            dirname = os.getcwd() + '/' + dirnames[idx]
            mkdir_p(dirname)
            # hold selection name
            selection_name = feat.name_a() + '_Vs_' + feat.name_b()
            # For beamer...
            if not selection_name in beamer_plots.keys():
                beamer_plots[selection_name] = {}
                beamer_plots[selection_name]['integrated'] = {}

            ### Plot binning plots
            if (len(etBins) * len(etaBins)) > 1:
                for etBinIdx, etaBinIdx in progressbar(
                        product(range(len(etBins) - 1),
                                range(len(etaBins) - 1)),
                    (len(etBins) - 1) * (len(etaBins) - 1),
                        prefix="Plotting... ",
                        logger=self._logger):
                    # hold binning name
                    binning_name = ('et%d_eta%d') % (etBinIdx, etaBinIdx)
                    # for beamer...
                    if not binning_name in beamer_plots[selection_name].keys():
                        beamer_plots[selection_name][binning_name] = {}

                    ### loop over standard quantities
                    for key in standardQuantitiesNBins.keys():
                        outname = dirname + '/' + selection_name.replace(
                            '_Vs_', '_') + '_' + key + '_' + binning_name
                        out = PlotQuantities(basepath + '/' + selection_name +
                                             '/' + binning_name,
                                             key,
                                             outname,
                                             etidx=etBinIdx,
                                             etaidx=etaBinIdx,
                                             xlabel=electronQuantities[key],
                                             divide='b',
                                             runLabel=runLabel)
                        beamer_plots[selection_name][binning_name][key] = out
                        #del tobject_collector[:]

                    ### loop over info quantities
                    for key in basicInfoQuantities.keys():
                        outname = dirname + '/' + selection_name.replace(
                            '_Vs_', '_') + '_' + key + '_' + binning_name
                        out = PlotQuantities(basepath + '/' + selection_name +
                                             '/' + binning_name,
                                             key,
                                             outname,
                                             etidx=etBinIdx,
                                             etaidx=etaBinIdx,
                                             xlabel=basicInfoQuantities[key],
                                             divide='b',
                                             runLabel=runLabel)
                        beamer_plots[selection_name][binning_name][key] = out
                        #del tobject_collector[:]


                    beamer_plots[selection_name][binning_name]['statistics'] = GetStatistics(basepath+'/'+selection_name+'/'+binning_name, \
                                                                                                  'avgmu',etidx=etBinIdx,etaidx=etaBinIdx)

            #### Plot integrated histograms
            ### loop over standard quantities
            for key in standardQuantitiesNBins.keys():
                outname = dirname + '/' + selection_name.replace(
                    '_Vs_', '_') + '_' + key
                out = PlotQuantities(basepath + '/' + selection_name,
                                     key,
                                     outname,
                                     xlabel=electronQuantities[key],
                                     divide='b',
                                     runLabel=runLabel,
                                     addbinlines=True)
                beamer_plots[selection_name]['integrated'][key] = out
                tobject_collector = []
                gc.collect()
            ### loop over info quantities
            for key in basicInfoQuantities.keys():
                outname = dirname + '/' + selection_name.replace(
                    '_Vs_', '_') + '_' + key + '_' + binning_name
                out = PlotQuantities(basepath + '/' + selection_name,
                                     key,
                                     outname,
                                     xlabel=basicInfoQuantities[key],
                                     divide='b',
                                     runLabel=runLabel,
                                     addbinlines=True)
                beamer_plots[selection_name]['integrated'][key] = out
                tobject_collector = []
                gc.collect()

            beamer_plots[selection_name]['integrated'][
                'statistics'] = GetStatistics(basepath + '/' + selection_name,
                                              'avgmu')
Exemple #5
0
    def plot(self,
             dirnames,
             pdfoutputs,
             pdftitles,
             runLabel='',
             doPDF=True,
             legends=None):

        legends = [
            'Both Approved', 'Ringer Rejected', 'Ringer Approved',
            'Both Rejected'
        ] if legends is None else legends

        SetAtlasStyle()
        beamer_plots = {}
        global tobject_collector

        basepath = self.getProperty("Basepath")
        etBins = self.getProperty("EtBinningValues")
        etaBins = self.getProperty("EtaBinningValues")

        sg = self.getStoreGateSvc()

        for idx, feat in enumerate(self.__quadrantFeatures):

            dirname = os.getcwd() + '/' + dirnames[idx]
            mkdir_p(dirname)
            # hold quadrant name
            quadrant_name = feat.name_a() + '_Vs_' + feat.name_b()
            # For beamer...
            if not quadrant_name in beamer_plots.keys():
                beamer_plots[quadrant_name] = {}
                beamer_plots[quadrant_name]['integrated'] = {}

            ### Plot binning plots
            if (len(etBins) * len(etaBins)) > 1:
                for etBinIdx, etaBinIdx in progressbar(
                        product(range(len(etBins) - 1),
                                range(len(etaBins) - 1)),
                    (len(etBins) - 1) * (len(etaBins) - 1),
                        prefix="Plotting... ",
                        logger=self._logger):
                    # hold binning name
                    binning_name = ('et%d_eta%d') % (etBinIdx, etaBinIdx)
                    # for beamer...
                    if not binning_name in beamer_plots[quadrant_name].keys():
                        beamer_plots[quadrant_name][binning_name] = {}

                    ### loop over standard quantities
                    for key in standardQuantitiesNBins.keys():
                        outname = dirname + '/' + quadrant_name.replace(
                            '_Vs_', '_') + '_' + key + '_' + binning_name
                        out = PlotQuantities(sg,
                                             basepath + '/' + quadrant_name +
                                             '/' + binning_name,
                                             key,
                                             outname,
                                             legends,
                                             etBins=etBins,
                                             etaBins=etaBins,
                                             etidx=etBinIdx,
                                             etaidx=etaBinIdx,
                                             xlabel=electronQuantities[key],
                                             divide='b',
                                             runLabel=runLabel)
                        beamer_plots[quadrant_name][binning_name][key] = out
                        #del tobject_collector[:]

                    ### loop over info quantities
                    for key in basicInfoQuantities.keys():
                        outname = dirname + '/' + quadrant_name.replace(
                            '_Vs_', '_') + '_' + key + '_' + binning_name
                        out = PlotQuantities(sg,
                                             basepath + '/' + quadrant_name +
                                             '/' + binning_name,
                                             key,
                                             outname,
                                             legends,
                                             etBins=etBins,
                                             etaBins=etaBins,
                                             etidx=etBinIdx,
                                             etaidx=etaBinIdx,
                                             xlabel=basicInfoQuantities[key],
                                             divide='b',
                                             runLabel=runLabel)
                        beamer_plots[quadrant_name][binning_name][key] = out
                        #del tobject_collector[:]


                    beamer_plots[quadrant_name][binning_name]['statistics'] = GetStatistics(sg, basepath+'/'+quadrant_name+'/'+binning_name, \
                                                                                                  'avgmu',etidx=etBinIdx,etaidx=etaBinIdx,
                                                                                                  etBins=etBins, etaBins=etaBins)

            #### Plot integrated histograms
            ### loop over standard quantities
            for key in standardQuantitiesNBins.keys():
                outname = dirname + '/' + quadrant_name.replace(
                    '_Vs_', '_') + '_' + key
                out = PlotQuantities(sg,
                                     basepath + '/' + quadrant_name,
                                     key,
                                     outname,
                                     legends,
                                     xlabel=electronQuantities[key],
                                     divide='b',
                                     runLabel=runLabel,
                                     addbinlines=True,
                                     etBins=etBins,
                                     etaBins=etaBins)
                beamer_plots[quadrant_name]['integrated'][key] = out
                tobject_collector = []
                gc.collect()
            ### loop over info quantities
            for key in basicInfoQuantities.keys():
                outname = dirname + '/' + quadrant_name.replace(
                    '_Vs_', '_') + '_' + key + '_' + binning_name
                out = PlotQuantities(sg,
                                     basepath + '/' + quadrant_name,
                                     key,
                                     outname,
                                     legends,
                                     xlabel=basicInfoQuantities[key],
                                     divide='b',
                                     runLabel=runLabel,
                                     addbinlines=True,
                                     etBins=etBins,
                                     etaBins=etaBins)
                beamer_plots[quadrant_name]['integrated'][key] = out
                tobject_collector = []
                gc.collect()

            beamer_plots[quadrant_name]['integrated'][
                'statistics'] = GetStatistics(sg,
                                              basepath + '/' + quadrant_name,
                                              'avgmu',
                                              etBins=etBins,
                                              etaBins=etaBins)

        if doPDF:
            ### Make Latex str et/eta labels
            etbins_str = []
            etabins_str = []
            for etBinIdx in range(len(etBins) - 1):
                etbin = (etBins[etBinIdx], etBins[etBinIdx + 1])
                if etbin[1] > 100:
                    etbins_str.append(r'$E_{T}\text{[GeV]} > %d$' % etbin[0])
                else:
                    etbins_str.append(r'$%d < E_{T} \text{[Gev]}<%d$' % etbin)

            for etaBinIdx in range(len(etaBins) - 1):
                etabin = (etaBins[etaBinIdx], etaBins[etaBinIdx + 1])
                etabins_str.append(r'$%.2f<\eta<%.2f$' % etabin)

            for slideIdx, feat in enumerate(self.__quadrantFeatures):

                with BeamerTexReportTemplate1(theme='Berlin',
                                              _toPDF=True,
                                              title=pdftitles[slideIdx],
                                              outputFile=pdfoutputs[slideIdx],
                                              font='structurebold'):

                    # hold quadrant name
                    quadrant_name = feat.name_a() + '_Vs_' + feat.name_b()
                    section_name = feat.name_a() + ' Vs ' + feat.name_b()
                    #with BeamerSection( name = 'x' ):

                    with BeamerSection(name='Integrated Quantities'):
                        # prepare files for basic quantities
                        figures = []
                        for key in ['et', 'eta', 'phi', 'avgmu', 'nvtx']:
                            figures.append(
                                beamer_plots[quadrant_name]['integrated'][key])

                        BeamerMultiFigureSlide(
                            title='Basic Quantities',
                            paths=figures,
                            nDivWidth=3  # x
                            ,
                            nDivHeight=2  # y
                            ,
                            texts=None,
                            fortran=False,
                            usedHeight=0.6,
                            usedWidth=0.9)
                        # prepare files for calo standard quantities
                        figures = []
                        for key in [
                                'eratio', 'rhad', 'reta', 'rphi', 'f1', 'f3',
                                'wtots1', 'weta2'
                        ]:
                            figures.append(
                                beamer_plots[quadrant_name]['integrated'][key])

                        BeamerMultiFigureSlide(
                            title='Standard Calo Quantities',
                            paths=figures,
                            nDivWidth=4  # x
                            ,
                            nDivHeight=2  # y
                            ,
                            texts=None,
                            fortran=False,
                            usedHeight=0.6,
                            usedWidth=0.9)

                        # prepare files for calo standard quantities
                        figures = []
                        for key in [
                                'd0significance', 'trackd0pvunbiased',
                                'deltaPhiRescaled2', 'eProbabilityHT',
                                'TRT_PID', 'deltaEta1', 'DeltaPOverP'
                        ]:
                            figures.append(
                                beamer_plots[quadrant_name]['integrated'][key])

                        BeamerMultiFigureSlide(
                            title='Standard Track Quantities',
                            paths=figures,
                            nDivWidth=4  # x
                            ,
                            nDivHeight=2  # y
                            ,
                            texts=None,
                            fortran=False,
                            usedHeight=0.6,
                            usedWidth=0.9)

                    section = ['Basic Quantity'] * 2
                    section.extend(['Standard Calo Quantity'] * 8)
                    section.extend(['Standard Track Quantity'] * 7)
                    section.extend([
                        'Likelihood Discriminant', 'Ringer Neural Discriminant'
                    ])
                    for idx, key in enumerate([
                            'avgmu',
                            'nvtx',
                            'eratio',
                            'rhad',
                            'reta',
                            'rphi',
                            'f1',
                            'f3',
                            'wtots1',
                            'weta2',
                            'd0significance',
                            'trackd0pvunbiased',
                            'deltaPhiRescaled2',
                            'eProbabilityHT',
                            'TRT_PID',
                            'deltaEta1',
                            'DeltaPOverP',
                            #'lhOutput','nnOutput'
                    ]):
                        with BeamerSection(name=key.replace('_', '\_')):

                            figures = []
                            binning_name_list = []
                            for etBinIdx, etaBinIdx in product(
                                    range(len(etBins) - 1),
                                    range(len(etaBins) - 1)):
                                binning_name_list.append(
                                    ('et%d_eta%d') % (etBinIdx, etaBinIdx))

                            while len(binning_name_list) > 0:
                                figures = []
                                if len(binning_name_list) > 9:
                                    for _ in range(9):
                                        binning_name = binning_name_list.pop(0)
                                        figures.append(
                                            beamer_plots[quadrant_name]
                                            [binning_name][key])
                                else:
                                    for _ in range(len(binning_name_list)):
                                        binning_name = binning_name_list.pop(0)
                                        figures.append(
                                            beamer_plots[quadrant_name]
                                            [binning_name][key])
                                BeamerMultiFigureSlide(
                                    title=section[idx] + ' (' +
                                    key.replace('_', '\_') + ')',
                                    paths=figures,
                                    nDivWidth=4  # x
                                    ,
                                    nDivHeight=3  # y
                                    ,
                                    texts=None,
                                    fortran=False,
                                    usedHeight=0.7,
                                    usedWidth=0.8)

                    with BeamerSection(name='Statistics'):

                        ### Prepare tables
                        lines1 = []
                        lines1 += [HLine(_contextManaged=False)]
                        lines1 += [HLine(_contextManaged=False)]

                        #lines1 += [ TableLine( columns = ['kinematic region'] + reduce(lambda x,y: x+y,[ [r'\multicol{4}{*}{'+s+'}','','',''] for s in etbins_str]), \
                        lines1 += [ TableLine( columns = ['kinematic region'] + reduce(lambda x,y: x+y,[ [s,'','',''] for s in etbins_str]), \
                                                                                        _contextManaged = False ) ]

                        lines1 += [HLine(_contextManaged=False)]
                        lines1 += [ TableLine( columns = ['Det. Region'] + reduce(lambda x,y: x+y,[[r'$Q_{ij}$',r'$\rho{ij}$',r'$\kappa_{P}$',r'$dis_{ij}$'] \
            #lines1 += [ TableLine( columns = ['Det. Region'] + reduce(lambda x,y: x+y,[['a','b','c','d'] \
                                    for _ in etbins_str]), _contextManaged = False ) ]
                        lines1 += [HLine(_contextManaged=False)]

                        for etaBinIdx in range(len(etaBins) - 1):
                            str_values = []
                            for etBinIdx in range(len(etBins) - 1):
                                binning_name = ('et%d_eta%d') % (etBinIdx,
                                                                 etaBinIdx)
                                stats = beamer_plots[quadrant_name][
                                    binning_name]['statistics']
                                str_values += [
                                    '%1.2f' % stats['Qij'],
                                    '%1.2f' % stats['Pij'],
                                    '%1.2f' % stats['Kp'],
                                    '%1.2f' % stats['dis_ij']
                                ]
                            lines1 += [
                                TableLine(columns=[etabins_str[etaBinIdx]] +
                                          str_values,
                                          _contextManaged=False)
                            ]
                            lines1 += [HLine(_contextManaged=False)]

                        lines1 += [HLine(_contextManaged=False)]

                        with BeamerSlide(title="The General Statistics"):
                            with Table(
                                    caption='The statistics pair wise values.'
                            ) as table:
                                with ResizeBox(size=0.9) as rb:
                                    with Tabular(columns='|l|' + 'cccc|' *
                                                 len(etbins_str)) as tabular:
                                        tabular = tabular
                                        for line in lines1:
                                            if isinstance(line, TableLine):
                                                tabular += line
                                            else:
                                                TableLine(line, rounding=None)