Пример #1
0
def fillBlock(procs, processes, procdict, treedir, treepath, nevents):
    blocklist = []
    for procstr in procs:
        for pname in processes:
            # fix new call name format in FCChhAnalyses/.../analysis.py
            if pname.find("sample.") >= 0: pname = pname.replace("sample.", "")
            # fix commented names in lists
            if pname.find("#") >= 0: continue
            if procstr == pname:
                xsec = procdict[pname]['crossSection']
                nev = procdict[pname]['numberOfEvents']
                if nevents > 0: nev = nevents
                sumw = procdict[pname]['sumOfWeights']
                eff = procdict[pname]['matchingEfficiency']
                kf = procdict[pname]['kfactor']
                matched_xsec = xsec * eff
                tree = '{}/{}/{}'.format(os.path.abspath(treedir), pname,
                                         treepath)

                #read from heppy yaml file job efficiency
                filestr = os.path.abspath(
                    treedir) + '/' + pname + '/processing.yaml'
                corrFac = 1.

                if not file_exist(filestr):
                    blocklist.append(
                        Process(pname, tree, nev, sumw, xsec, eff, kf))
                    continue

                with open(filestr, 'r') as stream:
                    try:
                        dico = yaml.load(stream)
                        try:
                            dico['processing']
                            corrFac *= float(
                                dico['processing']
                                ['nfiles']) / dico['processing']['ngoodfiles']
                        except TypeError, e:
                            print 'I got a  TypeError - reason "%s"' % str(e)
                    except yaml.YAMLError as exc:
                        print(exc)
                sumw *= corrFac
                nev *= corrFac
                blocklist.append(Process(pname, tree, nev, sumw, xsec, eff,
                                         kf))
    return blocklist
Пример #2
0
def fillBlock(procs, processes, procdict, treedir, treepath):
    blocklist = []
    for procstr in procs:
        for pname in processes:
            if procstr in pname:
                print(pname)
                xsec = procdict[pname]['crossSection']
                nev = procdict[pname]['numberOfEvents']
                eff = procdict[pname]['matchingEfficiency']
                kf = procdict[pname]['kfactor']
                matched_xsec = xsec * eff
                tree = '{}/{}/{}'.format(os.path.abspath(treedir), pname,
                                         treepath)
                blocklist.append(Process(pname, tree, nev, xsec, eff, kf))
    return blocklist
Пример #3
0
def main() -> None:
    parser = argparse.ArgumentParser(
        description='Genetic Algorithm for Python')
    parser.add_argument('task', help='task name', choices=get_choices())
    parser.add_argument('-f',
                        '--file',
                        help='file name',
                        default='chromosome.json')
    parser.add_argument('-r',
                        '--result',
                        help='result file name',
                        default='result.txt')
    parser.add_argument('-d',
                        '--dir',
                        help='executable file directory',
                        default='program')
    parser.add_argument('-p',
                        '--player',
                        help='player mode',
                        action='store_true')
    parser.add_argument('-l',
                        '--load',
                        help='cpu load',
                        default=15,
                        type=float)
    args = parser.parse_args()

    file: str = args.file
    result: str = args.result
    player: bool = args.player
    task_name: str = args.task
    directory: str = args.dir
    load: float = args.load

    io = IO(file, result)
    if player:
        Player(task_name, io.load_chromosome())
    else:
        Process()
        make = Make(directory)
        Runner(
            Algorithm(task_name, io.draw, io.save_chromosome, io.save_result,
                      make.generate), load)
Пример #4
0
def fillBlock(procs, processes, procdict, treedir, treepath, nevents):
    blocklist = []
    for procstr in procs:
        for pname in processes:
            # fix new call name format in FCChhAnalyses/.../analysis.py
            if pname.find("sample.") >= 0: pname = pname.replace("sample.", "")
            # fix commented names in lists
            if pname.find("#") >= 0: continue

            #print 'Process: ', pname, procstr

            if procstr == pname:
                xsec = procdict[pname]['crossSection']

                neventsDict = procdict[pname]['numberOfEvents']

                ## compute number of available events (maybe only a subset are available in heppy Tree) by checking into heppy yaml
                neventsAvailable = float(neventsDict)
                tree = '{}/{}/{}'.format(os.path.abspath(treedir), pname,
                                         treepath)
                #read from heppy yaml file job efficiency
                filestr = os.path.abspath(
                    treedir) + '/' + pname + '/processing.yaml'

                corr = 1.
                with open(filestr, 'r') as stream:
                    try:
                        dico = yaml.load(stream)
                        try:
                            dico['processing']
                            corr *= dico['processing']['ngoodfiles'] / float(
                                dico['processing']['nfiles'])
                            neventsAvailable *= corr
                        except TypeError:
                            print('I got a  TypeError - reason "%s"' % str(e))
                    except yaml.YAMLError as exc:
                        print(exc)

                sumw = procdict[pname]['sumOfWeights']
                eff = procdict[pname]['matchingEfficiency']
                kf = procdict[pname]['kfactor']
                matched_xsec = xsec * eff

                ## extract number of events present in the tree (this is different from the number of available events processed by heppy because of selection criteria)
                rf = ROOT.TFile(tree)
                t = rf.Get("events")
                numberOfEntries = t.GetEntries()

                ## first apply overall correction factor due to to heppy inefficiencies
                corrFacHeppy = corr

                ###### additional factor to be applied if requested number of events is smaller that actually contained in the trees
                corrFacUser = 1
                if nevents > 0 and float(nevents) <= float(numberOfEntries):
                    corrFacUser = float(nevents) / float(numberOfEntries)

                corrFac = corrFacHeppy * corrFacUser

                print('')
                print('==============================')
                print('Process: ', pname)
                print('Tree: ', tree)

                print('Number of events in dict: ', neventsDict)
                print('Heppy Job efficiency: ', corr)
                print('Number of processed events: ', neventsAvailable)
                print('Heppy condor correction factor: ', corr)
                print('Number of requested events: ', nevents)
                print('Number of events in the tree: ', numberOfEntries)
                print('Sum of Weights: ', sumw)
                print('Matching eff: ', eff)
                print('K-factor: ', kf)
                print('xsec (inclusive): ', xsec)
                print('xsec (effective): ', xsec * eff * kf)
                print('Heppy condor correction factor: ', corrFacHeppy)
                print('Correction factor (if nev < nevents in tree): ',
                      corrFacUser)
                print('Total Correction factor : ', corrFac)
                print('==============================')

                sumw *= corrFac

                blocklist.append(Process(pname, tree, sumw, xsec, eff, kf))
    return blocklist