Example #1
0
def create_python_script(opts, dt_type, mode, label):
    content =  '''#!/usr/bin/env python

from fit import sidebands

sidebands.fit_sidebands_single_mode("%s", "%s", "%s", %s)

'''% (dt_type, mode, label, opts.test)

    mode_sign = tools.get_modekey_sign(mode)

    ms = tools.pair_to_str(mode_sign)

    filename = 'sidebands-%s-%s-%s.py' % (dt_type, ms, label)

    filename = filename.replace('/', '-')
    
    file_ = os.path.join(attr.datpath, dt_type, label, 'src', filename)
    
    verbose = opts.verbose
    if opts.test:
        verbose = 1

    f = UserFile()
    f.append(content) 
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)
    return filename
Example #2
0
def main(opts, args):
    parsed = parse_args(args)
    datatype  = parsed[0]
    tag       = parsed[1]
    modes     = parsed[2]
    label     = parsed[3]

    figname = '_'.join(args).replace('/', '_')

    org = UserFile()
    org.append(attr.fig_web_header)

    if 'allinone' in opts.set:
        msg = create_fig(datatype, label)
        org.append(msg)
    else:
        for mode in modes:
            msg = create_fig_mode(tag, datatype, mode, label)
            org.append(msg)
        
    org.append(attr.fig_web_footer)
    orgname = '%s.org' % figname
    orgfile = os.path.join(attr.figpath, orgname)
    org.output(orgfile)
    tools.org_export_as_html(orgfile)

    orglink = '[[./%s/fig/%s][figure]]' %(attr.analysis, orgname)
    sys.stdout.write('\n%s\n\n' % orglink)
Example #3
0
File: kkmass2.py Project: xshi/dhad
def create_python_script(opts, datatype, mode, label, lowmass, highmass):
    content =  '''#!/usr/bin/env python

from fit import kkmass2

kkmass2.fit_single_mode("%s", "%s", "%s", %s, %s, %s)

'''% (datatype, mode, label, lowmass, highmass, opts.test)

    mode_sign = tools.get_modekey_sign(mode)

    ms = tools.pair_to_str(mode_sign)

    filename = 'fit-%s.py' % ms

    filename = filename.replace('/', '-')
    
    file_ = os.path.join(attr.datpath, datatype, label, 'src',
                         'kkmass2/%s_%s' % (lowmass, highmass) , filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1
        
    f = UserFile()
    f.append(content) 
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)
    return filename
Example #4
0
def create_script_logfile_jobname(var, datatype, tag, mode, label, test):
    logname = '%s_%s.log' %(datatype, mode)
    logpath = os.path.join(attr.yldlogpath, label, 'var', var)
    logfile = tools.set_file(extbase=logpath, comname=logname)

    content =  '''#!/usr/bin/env python

from yld import var

var.single_tag_mode("%s", "%s", "%s", "%s", test=%s)

'''% (var, datatype, mode, label, test)

    mode, sign = tools.get_modekey_sign(mode)

    if tag == 'single':
        if sign == 1:
            sign = 'p'
        else:
            sign = 'm'
        filename = 'var-%s-%s-m%s-%s-%s.py' % (datatype, tag, mode, sign, label)
        qjobname = 'var%s,%s' % (mode, sign)
    else:
        filename = 'var-%s-%s-m%s-%s-%s.py' % (datatype, tag, mode[0], mode[1], label)
        qjobname = 'var%s,%s' % (mode[0], mode[1])

    file_ = os.path.join(attr.base, 'src', attr.src, 'yld', filename)

    f = UserFile()
    f.data.append(content) 
    f.output(file_)
    os.chmod(file_, 0755)

    return filename, logfile, qjobname
Example #5
0
File: cleog.py Project: xshi/dhad
def check_decfile_double(opts, label, toppath, decfile, headername, modename):
    headerfile = os.path.join(toppath, 'tag_fragments', headername)
    modenames = modename.split('__')
    fragfile = os.path.join(toppath, 'tag_fragments', modenames[0])
    
    try:
        frag = open(fragfile, 'r')
    except IOError:
        tag_fragments(opts, [label])
        frag = open(fragfile, 'r')
         
    f = UserFile()
    fin = open(headerfile, 'r')
    f.extend(fin.readlines())
    f.extend(frag.readlines())
    fin.close()
    frag.close()

    fragfile2 = os.path.join(toppath, 'tag_fragments', modenames[1])
    frag2 = open(fragfile2, 'r')
    f.extend(frag2.readlines())
    frag2.close()
    
    f.append('End\n')
    verbose = opts.verbose
    if opts.test:
        verbose = 1
    
    f.output(decfile, verbose=verbose)
    frag2.close()
Example #6
0
def create_python_script_nondiag(opts, dt_type, stage, label, x, y):
    if stage not in ['nondiag'] :
        raise NameError(stage)

    content =  '''#!/usr/bin/env python

from fit import crossfeeds

crossfeeds.stage_%s("%s", "%s", %s, %s)

'''% (stage, dt_type, label, x, y)

    xstr = pair_to_str(x)
    ystr = pair_to_str(y)
    
    filename = 'crossfeeds-%s-%s-%s-%s.py' % (stage, dt_type, xstr, ystr)
    file_ = os.path.join(attr.datpath, dt_type, label, 'src', 'csf', filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1 
    
    f = UserFile()
    f.append(content) 
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)
    return filename
Example #7
0
File: kkmass.py Project: xshi/dhad
def main(opts, args):
    parsed = parse_args(args)
    datatype  = parsed[0]
    tag       = parsed[1]
    modes     = parsed[2]
    label     = parsed[3]

    figname = 'kkmass_'+'_'.join(args[:-1]).replace('/', '_')

    org = UserFile()
    org.append(attr.fig_web_header)

    binbase = parse_opts_set(opts.set, 'binbase')
    binwidth =  parse_opts_set(opts.set, 'binwidth')
    numbins = parse_opts_set(opts.set, 'numbins')
    
    for i in xrange(numbins):
        lowmass = binbase+i*binwidth
        highmass = binbase+(i+1)*binwidth

        for mode in modes:
            msg = create_fig_mode(opts, tag, datatype, mode,
                                  lowmass, highmass, label)
            org.append(msg)
    
    org.append(attr.fig_web_footer)
    orgname = '%s.org' % figname
    orgfile = os.path.join(attr.figpath, label, orgname)
    org.output(orgfile, verbose=1)

    orglink = '[[./fig/%s/%s][figure]]' %(label, orgname)
    sys.stdout.write('\n%s\n\n' % orglink)

    tools.org_export_as_html(orgfile)
Example #8
0
def create_python_script(opts, datatype, mode, label, lowmass, highmass):
    content = '''#!/usr/bin/env python

from fit import kkmass2

kkmass2.fit_single_mode("%s", "%s", "%s", %s, %s, %s)

''' % (datatype, mode, label, lowmass, highmass, opts.test)

    mode_sign = tools.get_modekey_sign(mode)

    ms = tools.pair_to_str(mode_sign)

    filename = 'fit-%s.py' % ms

    filename = filename.replace('/', '-')

    file_ = os.path.join(attr.datpath, datatype, label, 'src',
                         'kkmass2/%s_%s' % (lowmass, highmass), filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1

    f = UserFile()
    f.append(content)
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)
    return filename
Example #9
0
def main(opts, args):
    parsed = parse_args(args)
    datatype = parsed[0]
    tag = parsed[1]
    modes = parsed[2]
    label = parsed[3]

    figname = 'kpimass_' + '_'.join(args[:-1]).replace('/', '_')

    org = UserFile()
    org.append(attr.fig_web_header)

    binbase = parse_opts_set(opts.set, 'binbase')
    binwidth = parse_opts_set(opts.set, 'binwidth')
    numbins = parse_opts_set(opts.set, 'numbins')

    for i in xrange(numbins):
        lowmass = binbase + i * binwidth
        highmass = binbase + (i + 1) * binwidth

        for mode in modes:
            msg = create_fig_mode(opts, tag, datatype, mode, lowmass, highmass,
                                  label)
            org.append(msg)

    org.append(attr.fig_web_footer)
    orgname = '%s.org' % figname
    orgfile = os.path.join(attr.figpath, label, orgname)
    org.output(orgfile, verbose=1)

    orglink = '[[./fig/%s/%s][figure]]' % (label, orgname)
    sys.stdout.write('\n%s\n\n' % orglink)

    tools.org_export_as_html(orgfile)
Example #10
0
def get_data_statonly_crosssectionsdef(prefix):
    filename = 'data_statonly_crosssectionsdef'
    file_ = tools.set_file(extbase=attr.brfpath, prefix=prefix, 
                           comname=filename)
    if '281ipb' in prefix:
        lumi = '281.50'
    elif '537ipb' in prefix:
        lumi = '536.57'
    elif '818ipb' in prefix or 'v13' in prefix:
        lumi = '818.10'
    else:
        raise NameError(prefix)

    content = '''0
4
%s
0.
0
n
0
n
n
n
''' % lumi

    f = UserFile()
    f.append(content)
    f.output(file_, verbose=1)
Example #11
0
def create_data_skim_tcl(dataset, label):

    if _debug:
        sys.stdout.write('\ndebug: dataset %s\n' % dataset)

    tclname = 'HadronicDNtupleProc/Test/DataSkim_%s.tcl' % dataset
    tclfile = os.path.join(attr.srcprocpath, tclname)
    sys.stdout.write('Writing %s...' % tclfile)

    datatype = 'data'
    run_event_set = Set([])
    for mode in attr.single_mode_list:
        evtname = '%s_%s_unqiue_%s.evt' % (datatype, mode, label)
        evtpath = os.path.join(attr.datpath, 'evt', label, 'events')
        unique_file = os.path.join(evtpath, evtname)
        f = UserFile(unique_file)
        events = Set(f.data)
        run_event_set.update(events)

    events = sorted(list(run_event_set))
    fo = UserFile()
    for event in events:
        run = int(event.split(' ')[0])
        if dataset == attr.get_dataset_by_run(run):
            fo.data.append('goto %sgo 1\n' % event)

    fo.output(tclfile)
    sys.stdout.write(' done.\n')
Example #12
0
def create_python_script(opts, dt_type, mode, label):
    content = '''#!/usr/bin/env python

from fit import sidebands

sidebands.fit_sidebands_single_mode("%s", "%s", "%s", %s)

''' % (dt_type, mode, label, opts.test)

    mode_sign = tools.get_modekey_sign(mode)

    ms = tools.pair_to_str(mode_sign)

    filename = 'sidebands-%s-%s-%s.py' % (dt_type, ms, label)

    filename = filename.replace('/', '-')

    file_ = os.path.join(attr.datpath, dt_type, label, 'src', filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1

    f = UserFile()
    f.append(content)
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)
    return filename
Example #13
0
def check_decfile_double(opts, label, toppath, decfile, headername, modename):
    headerfile = os.path.join(toppath, 'tag_fragments', headername)
    modenames = modename.split('__')
    fragfile = os.path.join(toppath, 'tag_fragments', modenames[0])

    try:
        frag = open(fragfile, 'r')
    except IOError:
        tag_fragments(opts, [label])
        frag = open(fragfile, 'r')

    f = UserFile()
    fin = open(headerfile, 'r')
    f.extend(fin.readlines())
    f.extend(frag.readlines())
    fin.close()
    frag.close()

    fragfile2 = os.path.join(toppath, 'tag_fragments', modenames[1])
    frag2 = open(fragfile2, 'r')
    f.extend(frag2.readlines())
    frag2.close()

    f.append('End\n')
    verbose = opts.verbose
    if opts.test:
        verbose = 1

    f.output(decfile, verbose=verbose)
    frag2.close()
Example #14
0
def main(opts, args):
    parsed = parse_args(args)
    datatype = parsed[0]
    tag = parsed[1]
    modes = parsed[2]
    label = parsed[3]

    figname = '_'.join(args).replace('/', '_')

    org = UserFile()
    org.append(attr.fig_web_header)

    if 'allinone' in opts.set:
        msg = create_fig(datatype, label)
        org.append(msg)
    else:
        for mode in modes:
            msg = create_fig_mode(tag, datatype, mode, label)
            org.append(msg)

    org.append(attr.fig_web_footer)
    orgname = '%s.org' % figname
    orgfile = os.path.join(attr.figpath, orgname)
    org.output(orgfile)
    tools.org_export_as_html(orgfile)

    orglink = '[[./%s/fig/%s][figure]]' % (attr.analysis, orgname)
    sys.stdout.write('\n%s\n\n' % orglink)
Example #15
0
def create_python_script(opts, dt_type, tag, mode, label):

    if tag not in ['single', 'double']:
        raise NameError(tag)

    content = '''#!/usr/bin/env python

import fit

fit.%s_tag_mode("%s", %s, "%s")

''' % (tag, dt_type, mode, label)

    if tag == 'single':
        filename = '%s-%s-m%s-%s.py' % (dt_type, tag, mode, label)
    else:
        filename = '%s-%s-m%s-%s-%s.py' % (dt_type, tag, mode[0], mode[1],
                                           label)

    file_ = os.path.join(attr.datpath, dt_type, label, 'src', filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1
    f = UserFile()
    f.append(content)
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)
    return filename
Example #16
0
def create_python_script(opts, dt_type, tag, mode, label):

    if tag not in ['single', 'double'] :
        raise NameError(tag)

    content =  '''#!/usr/bin/env python

import fit

fit.%s_tag_mode("%s", %s, "%s")

'''% (tag, dt_type, mode, label)

    if tag == 'single':
        filename = '%s-%s-m%s-%s.py' % (dt_type, tag, mode, label)
    else:
        filename = '%s-%s-m%s-%s-%s.py' % (
            dt_type, tag, mode[0], mode[1], label)
    
    file_ = os.path.join(attr.datpath, dt_type, label, 'src', filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1
    f = UserFile()
    f.append(content) 
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)
    return filename
Example #17
0
def main(opts, args):

    dt_type = args[0]
    stage = args[1]
    label = args[2] + '/crossfeeds'

    single_modes = get_single_modes(opts.set)

    org = UserFile()
    org.append(attr.fig_web_header)

    if stage == 'diag':
        for mode, sign in single_modes:
            msg = create_fig_diag_mode(dt_type, stage, label, mode, sign)
            org.append(msg)

    elif stage == 'nondiag':
        for x, y in [(x, y) for x in single_modes for y in single_modes
                     if x != y]:
            sys.stdout.write('Creating mode %s, %s ... ' % (x, y))
            sys.stdout.flush()
            msg = create_fig_nondiag_mode(dt_type, stage, label, x, y)
            org.append(msg)
            sys.stdout.write('OK.\n')
    else:
        raise NameError(stage)

    figname = 'crossfeeds_' + '_'.join(args).replace('/', '_')

    org.append(attr.fig_web_footer)

    figlabel = label.split('/')[0]

    figname = figname.replace(figlabel, '')
    figname = figname.replace('__', '_')

    orgname = figname + '.org'
    orgname = orgname.replace('_.org', '.org')
    orgpath = os.path.join(attr.figpath, figlabel)
    orgfile = tools.check_and_join(orgpath, orgname)

    verbose = opts.verbose
    if opts.test:
        verbose = 1

    org.output(orgfile, verbose=verbose)
    orglink = '[[./fig/%s/%s][figure]]' % (figlabel, orgname)
    sys.stdout.write('\n%s\n\n' % orglink)

    if opts.test:
        return

    tools.org_export_as_html(orgfile)
Example #18
0
def main(opts, args):

    dt_type = args[0]
    stage = args[1] 
    label = args[2]+'/crossfeeds'

    single_modes = get_single_modes(opts.set)
        
    org = UserFile()
    org.append(attr.fig_web_header)

    if stage == 'diag':
        for mode, sign in single_modes:
            msg = create_fig_diag_mode(dt_type, stage, label, mode, sign)
            org.append(msg)

    elif stage == 'nondiag':
        for x, y  in [(x, y) for x in single_modes for y in single_modes if x!=y]:
            sys.stdout.write('Creating mode %s, %s ... ' % (x, y))
            sys.stdout.flush()
            msg = create_fig_nondiag_mode(dt_type, stage, label, x, y)
            org.append(msg)
            sys.stdout.write('OK.\n')
    else:
        raise NameError(stage)

    figname = 'crossfeeds_' + '_'.join(args).replace('/', '_')
    
    org.append(attr.fig_web_footer)

    figlabel = label.split('/')[0]

    figname = figname.replace(figlabel, '')
    figname = figname.replace('__', '_')

    orgname = figname+'.org'
    orgname = orgname.replace('_.org', '.org')
    orgpath = os.path.join(attr.figpath, figlabel)
    orgfile = tools.check_and_join(orgpath, orgname)

    verbose = opts.verbose
    if opts.test:
        verbose = 1

    org.output(orgfile, verbose=verbose)
    orglink = '[[./fig/%s/%s][figure]]' %(figlabel, orgname)
    sys.stdout.write('\n%s\n\n' % orglink)

    if opts.test:
        return
    
    tools.org_export_as_html(orgfile)
Example #19
0
File: cleog.py Project: xshi/dhad
def cleog_mode(opts, mode, label, tasks=[1]):
    sys.stdout.write('dhad.gen: Mode %s \n' %mode )
    sys.stdout.write('dhad.gen: Label %s \n' %label)
    sys.stdout.write('dhad.gen: Task %s \n' %tasks)

    check_decfile(opts, mode, label)
    check_and_copy_file(opts, label, 'genmc.tcl')
    check_and_copy_file(opts, label, 'runlist')
    check_and_copy_file(opts, label, 'cleog-generic-array.sh')

    jobtype = 'cleog'
    seeds = tools.parse_opts_set(opts.set, 'seeds')
    
    edit_fix_single_mode_list(opts, mode, label)

    create_tag_numbers_file(opts, mode, label)

    for task_id in tasks:
        if  opts.set and 'interact' in opts.set:
            bash_file, logfile = create_bash_interact(
                jobtype, mode, task_id, label=label, seeds=seeds)
            if opts.test:
                sys.stdout.write(bash_file + '\n')
            else:
                subprocess.Popen(bash_file)
            continue

        if opts.set and 'bg' in opts.set:
            bash_file, logfile = create_bash_interact(
                jobtype, mode, task_id, label=label, seeds=seeds)
            if opts.test:
                sys.stdout.write(bash_file + '\n')
                sys.stdout.write(logfile + '\n')                
            else:
                sys.stdout.write('Save log as %s.\n' %logfile)
                process = subprocess.Popen(bash_file, stdout=subprocess.PIPE,
                                                stderr=subprocess.STDOUT)
                f = UserFile()
                f.append(process.communicate()[0])
                f.output(logfile)

            continue

        bash_file = create_bash_fix_mc_job(jobtype, label, task_id, seeds=seeds)

        if opts.test:
            sys.stdout.write(bash_file + '\n')
            continue

        output = commands.getoutput(bash_file)
        sys.stdout.write(output+ '\n')
Example #20
0
def create_tag_numbers_file(opts, mode, label):
    tag_numbers = tools.parse_opts_set(opts.set, 'tag_numbers')
    if tag_numbers == None:
        tag_numbers = attr.get_tag_numbers(mode)

    tag_numbers_file = os.path.join(attr.datpath, 'signal', label, 'src',
                                    'tag_numbers', mode)
    f = UserFile()
    f.data.append(str(tag_numbers))

    verbose = opts.verbose
    if opts.test:
        verbose = 1

    f.output(tag_numbers_file, verbose=verbose)
Example #21
0
File: cleog.py Project: xshi/dhad
def create_tag_numbers_file(opts, mode, label):
    tag_numbers = tools.parse_opts_set(opts.set, 'tag_numbers')
    if tag_numbers == None:
        tag_numbers = attr.get_tag_numbers(mode)        

    tag_numbers_file = os.path.join(attr.datpath, 'signal', label,
                                    'src', 'tag_numbers', mode)
    f = UserFile()
    f.data.append(str(tag_numbers))

    verbose = opts.verbose
    if opts.test:
        verbose = 1

    f.output(tag_numbers_file, verbose=verbose)
Example #22
0
def pass2_mode(opts, mode, label, tasks=[1]):
    sys.stdout.write('dhad.gen.pass2: Mode %s \n' % mode)
    sys.stdout.write('dhad.gen.pass2: Label %s \n' % label)
    sys.stdout.write('dhad.gen.pass2: Task %s \n' % tasks)

    jobtype = 'pass2'
    cleog.edit_fix_single_mode_list(opts, mode, label)
    cleog.check_and_copy_file(opts, label, 'mcp2.tcl')
    cleog.check_and_copy_file(opts, label, 'pass2-generic-array.sh')

    for task_id in tasks:
        if opts.set == 'interact':
            bash_file, logfile = cleog.create_bash_interact(jobtype,
                                                            mode,
                                                            task_id,
                                                            label=label)
            if opts.test:
                sys.stdout.write(bash_file + '\n')
            else:
                subprocess.Popen(bash_file)
            return

        if opts.set == 'bg':
            bash_file, logfile = cleog.create_bash_interact(jobtype,
                                                            mode,
                                                            task_id,
                                                            label=label)
            if opts.test:
                sys.stdout.write(bash_file + '\n')
                sys.stdout.write(logfile + '\n')
            else:
                sys.stdout.write('Save log as %s.\n' % logfile)
                process = subprocess.Popen(bash_file,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.STDOUT)
                f = UserFile()
                f.append(process.communicate()[0])
                f.output(logfile)

            return

        bash_file = cleog.create_bash_fix_mc_job(jobtype, label, task_id)
        if opts.test:
            sys.stdout.write(bash_file + '\n')
            continue

        output = commands.getoutput(bash_file)
        sys.stdout.write(output + '\n')
Example #23
0
def create_python_script_allinone(dt_type, modes, label, test):
    content = '''#!/usr/bin/env python

from fit import backgrounds

backgrounds.fit_backgrounds_single("%s", %s, "%s", %s)

''' % (dt_type, modes, label, test)
    filename = 'backgrounds-%s-allinone-%s.py' % (dt_type, label)
    filename = filename.replace('/', '-')
    file_ = os.path.join(attr.srcfitpath, filename)
    f = UserFile()
    f.append(content)
    f.output(file_)
    os.chmod(file_, 0755)
    return filename
Example #24
0
def create_python_script_allinone(dt_type, modes, label, test):
    content =  '''#!/usr/bin/env python

from fit import backgrounds

backgrounds.fit_backgrounds_single("%s", %s, "%s", %s)

'''% (dt_type, modes, label, test)
    filename = 'backgrounds-%s-allinone-%s.py' % (dt_type, label)
    filename = filename.replace('/', '-')
    file_ = os.path.join(attr.srcfitpath, filename)
    f = UserFile()
    f.append(content) 
    f.output(file_)
    os.chmod(file_, 0755)
    return filename
Example #25
0
def create_sh(opts, filename, label, proc_version):
    code_dir = os.path.join(attr.base, 'src', proc_version, 'proc')
    outputdir = os.path.join(attr.datpath, 'signal', label,
                             'dtuple_' + attr.cleog + '_' + attr.pass2)

    if not os.access(outputdir, os.F_OK):
        sys.stdout.write('Creating dir %s ...\n' % outputdir)
        os.makedirs(outputdir)

    sh_content = '''#!/bin/sh
# request Bourne shell as shell for job
#$ -S /usr/local/bin/bash
#$ -j y
#$ -m a
#$ -M [email protected]
date
hostname

. /nfs/cleo3/Offline/scripts/cleo3logins
. /nfs/cleo3/Offline/scripts/cleo3defs

cd %s
. local_setup

export INDIR=$TOPDIR/dskim$SUFFIX

export INPUTDATA=USERLOCALMC_SKIMMED
export USE_SETUP_ANALYSIS=1

export OUTPUTDIR=$TOPDIR/dtuple$SUFFIX

export FILELIST=$SCRIPTDIR/pds_files/dt-$1
export FNAME=$1
suez -f HadronicDNtupleProc/Test/loadHadronicDNtupleProc.tcl

date
''' % code_dir

    sh_file = os.path.join(attr.datpath, 'signal', label, 'src', filename)
    f = UserFile()
    f.append(sh_content)
    verbose = opts.verbose
    if opts.test:
        verbose = 1
    f.output(sh_file, verbose=verbose)
Example #26
0
def get_data_crosssectionsdef(prefix):
    filename = 'data_crosssectionsdef'
    file_ = tools.set_file(extbase=attr.brfpath, prefix=prefix, 
                           comname=filename)
    if '281ipb' in prefix:
        lumi = '281.50'
        lumi_err = '2.8150'
    elif '537ipb' in prefix:
        lumi = '536.57'
        lumi_err = '5.3657'
    elif '818ipb' in prefix or 'v13' in prefix:
        lumi = '818.10'
        lumi_err = '8.1810'
    else:
        raise NameError(prefix)

    bffilename = 'bf_stat'
    bffile = tools.set_file(extbase=attr.brfpath, prefix=prefix,
                            comname=bffilename)
    brf = BrfFile(bffile)

    ne_xsec_err = brf.parsed['sigma(D0D0bar)'].split('+-')[-1].strip()
    ch_xsec_err = brf.parsed['sigma(D+D-)'].split('+-')[-1].strip()
    xsec_err =  brf.parsed['sigma(DDbar)'].split('+-')[-1].strip()
    xsec_ratio_err = brf.parsed['chg/neu'].split('+-')[-1].strip()

    content = '''0
4
%s
%s
0
y
%s
0
y
%s
y
%s
y
%s
''' % (lumi, lumi_err, ne_xsec_err, ch_xsec_err, xsec_err, xsec_ratio_err)

    f = UserFile()
    f.append(content)
    f.output(file_, verbose=1)
Example #27
0
def create_script_logfile_jobname(datatype, tag, mode, label, opts):
    logname = '%s_%s.log' %(datatype, mode)
    logpath = os.path.join(attr.sellogpath, label, 'kssideband')
    logfile = tools.set_file(extbase=logpath, comname=logname)

    content =  '''#!/usr/bin/env python

from sel import kssideband

kssideband.single_tag_mode("%s", "%s", "%s", test=%s)

'''% (datatype, mode, label, opts.test)

    mode, sign = tools.get_modekey_sign(mode)

    if tag == 'single':
        if sign == [-1, 1]:
            filename = 'sel-%s-%s-m%s-%s.py' % (datatype, tag, mode, label)
            qjobname = 'sel%s' % mode 
        else:
            if sign == 1:
                sign = 'p'
            else: 
                sign = 'm'
            filename = 'sel-%s-%s-m%s-%s-%s.py' % (
                datatype, tag, mode, sign, label)
            qjobname = 'sel%s,%s' % (mode, sign)
            
    else:
        filename = 'sel-%s-%s-m%s-%s-%s.py' % (
            datatype, tag, mode[0], mode[1], label)
        qjobname = 'sel%s,%s' % (mode[0], mode[1])

    file_ = os.path.join(attr.datpath, datatype, label, 'src', 'sel', filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1
    f = UserFile()
    f.data.append(content) 
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)

    return filename, logfile, qjobname
Example #28
0
File: pass2.py Project: xshi/dhad
def pass2_mode(opts, mode, label, tasks=[1]):
    sys.stdout.write('dhad.gen.pass2: Mode %s \n' %mode )
    sys.stdout.write('dhad.gen.pass2: Label %s \n' %label)
    sys.stdout.write('dhad.gen.pass2: Task %s \n' %tasks)

    jobtype = 'pass2'
    cleog.edit_fix_single_mode_list(opts, mode, label)
    cleog.check_and_copy_file(opts, label, 'mcp2.tcl')
    cleog.check_and_copy_file(opts, label, 'pass2-generic-array.sh')

    for task_id in tasks:
        if opts.set == 'interact':
            bash_file, logfile = cleog.create_bash_interact(
                jobtype, mode, task_id, label=label)
            if opts.test:
                sys.stdout.write(bash_file + '\n')
            else:
                subprocess.Popen(bash_file)
            return

        if opts.set == 'bg':
            bash_file, logfile = cleog.create_bash_interact(
                jobtype, mode, task_id, label=label)
            if opts.test:
                sys.stdout.write(bash_file + '\n')
                sys.stdout.write(logfile + '\n')
            else:
                sys.stdout.write('Save log as %s.\n' %logfile)
                process = subprocess.Popen(bash_file, stdout=subprocess.PIPE,
                                           stderr=subprocess.STDOUT)
                f = UserFile()
                f.append(process.communicate()[0])
                f.output(logfile)

            return

        bash_file = cleog.create_bash_fix_mc_job(jobtype, label, task_id)
        if opts.test:
            sys.stdout.write(bash_file + '\n')
            continue

        output = commands.getoutput(bash_file)
        sys.stdout.write(output+ '\n')
Example #29
0
def output_headerfiles(label):
    headernames = [
        'Double_D0D0B_header', 'Double_DpDm_header', 'Single_D0_header',
        'Single_D0B_header', 'Single_Dp_header', 'Single_Dm_header'
    ]
    outpath = os.path.join(attr.datpath, 'signal', label, 'src',
                           'tag_fragments')
    for hname in headernames:
        headerfile = tools.check_and_join(outpath, hname)
        f = UserFile()
        if 'D0D0B' in hname:
            alias_line = '#\nAlias myD0 D0\n#\n#\nAlias myanti-D0 anti-D0\n#\n'
            psi_decay_line = '1.000    myD0  myanti-D0         VSS;\n'

        if 'DpDm' in hname:
            alias_line = '#\nAlias myD+ D+\n#\n#\nAlias myD- D-\n#\n'
            psi_decay_line = '1.000    myD+  myD-         VSS;\n'

        elif 'Single_D0_' in hname:
            alias_line = '#\nAlias myD0 D0\n#\n'
            psi_decay_line = '1.000    myD0  anti-D0         VSS;\n'

        elif 'Single_D0B_' in hname:
            alias_line = '#\nAlias myanti-D0 anti-D0\n#\n'
            psi_decay_line = '1.000    D0  myanti-D0         VSS;\n'

        elif 'Single_Dp_' in hname:
            alias_line = '#\nAlias myD+ D+\n#\n'
            psi_decay_line = '1.000    myD+  D-         VSS;\n'

        elif 'Single_Dm_' in hname:
            alias_line = '#\nAlias myD- D-\n#\n'
            psi_decay_line = '1.000    D+  myD-         VSS;\n'

        f.append(alias_line)
        f.append(
            'Decay vpho\n1.000   psi(3770)  gamma    VPHOTOVISR ;\nEnddecay\n#\nDecay psi(3770)\n'
        )
        f.append(psi_decay_line)
        f.append('Enddecay\n#')
        f.output(headerfile, verbose=1)
Example #30
0
File: kkmass.py Project: xshi/dhad
def create_python_script(opts, filename, datatype, mode, label):
    content =  '''#!/usr/bin/env python

from sel import kkmass

kkmass.single_tag_mode("%s", "%s", "%s", test=%s)

'''% (datatype, mode, label, opts.test)

    file_ = os.path.join(attr.datpath, datatype, label, 'src', 'sel', filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1
        
    f = UserFile()
    f.data.append(content) 
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)

    return filename 
Example #31
0
def create_python_script(opts, filename, datatype, mode, label):
    content = '''#!/usr/bin/env python

from sel import kkmass

kkmass.single_tag_mode("%s", "%s", "%s", test=%s)

''' % (datatype, mode, label, opts.test)

    file_ = os.path.join(attr.datpath, datatype, label, 'src', 'sel', filename)

    verbose = opts.verbose
    if opts.test:
        verbose = 1

    f = UserFile()
    f.data.append(content)
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)

    return filename
Example #32
0
def create_peak_script_logfile_jobname(datatype, tag, mode, label, test):
    prefix = 'dir_' + label
    logname = 'peak_bkg_%s_%s.log' % (datatype, mode)
    logname = logname.replace('/', '_')

    logfile = tools.set_file(extbase=attr.yldlogpath,
                             prefix=prefix,
                             comname=logname)

    content = '''#!/usr/bin/env python

from yld import backgrounds

backgrounds.process_peak_generic_single_mode("%s", "%s", "%s", test=%s)

''' % (datatype, mode, label, test)

    mode, sign = tools.get_modekey_sign(mode)

    if tag == 'single':
        if sign == 1:
            sign = 'p'
        else:
            sign = 'm'
        filename = 'peak-bkg-%s-%s-m%s-%s-%s.py' % (datatype, tag, mode, sign,
                                                    label)
        qjobname = 'bkg%s%s' % (mode, sign)
    else:
        filename = 'peak-bkg-%s-%s-m%s-%s-%s.py' % (datatype, tag, mode[0],
                                                    mode[1], label)
        qjobname = 'bkg%s,%s' % (mode[0], mode[1])

    file_ = os.path.join(attr.base, 'src', attr.src, 'yld', filename)

    f = UserFile()
    f.data.append(content)
    f.output(file_)
    os.chmod(file_, 0755)

    return filename, logfile, qjobname
Example #33
0
def create_bash_file(opts,
                     label,
                     dt_type,
                     script,
                     bashname='fit-mbc.sh',
                     optcommand='',
                     subdir=''):
    script_dir = os.path.join(attr.datpath, dt_type, label, 'src', subdir)

    bash_content = '''#!/bin/sh
#$ -S /usr/local/bin/bash
#$ -j y
#$ -m a
#$ -M [email protected]

date
hostname

.  ~/.bashrc
setdhad %s 

%s

cd %s
./%s

date

''' % (attr.version, optcommand, script_dir, script)

    bash_file = os.path.join(script_dir, bashname)

    verbose = opts.verbose
    if opts.test:
        verbose = 1
    f = UserFile()
    f.append(bash_content)
    f.output(bash_file, verbose=verbose)
    os.chmod(bash_file, 0755)
    return bash_file
Example #34
0
def create_peak_script_logfile_jobname(datatype, tag, mode, label, test):
    prefix = 'dir_'+label
    logname = 'peak_bkg_%s_%s.log' %(datatype, mode)
    logname = logname.replace('/', '_')
    
    logfile = tools.set_file(
        extbase=attr.yldlogpath, prefix=prefix,
        comname=logname)

    content =  '''#!/usr/bin/env python

from yld import backgrounds

backgrounds.process_peak_generic_single_mode("%s", "%s", "%s", test=%s)

'''% (datatype, mode, label, test)

    mode, sign = tools.get_modekey_sign(mode)

    if tag == 'single':
        if sign == 1:
            sign = 'p'
        else:
            sign = 'm'
        filename = 'peak-bkg-%s-%s-m%s-%s-%s.py' % (
            datatype, tag, mode, sign, label)
        qjobname = 'bkg%s%s' % (mode, sign)
    else:
        filename = 'peak-bkg-%s-%s-m%s-%s-%s.py' % (
            datatype, tag, mode[0], mode[1], label)
        qjobname = 'bkg%s,%s' % (mode[0], mode[1])

    file_ = os.path.join(attr.base, 'src', attr.src, 'yld', filename)
    
    f = UserFile()
    f.data.append(content) 
    f.output(file_)
    os.chmod(file_, 0755)

    return filename, logfile, qjobname
Example #35
0
def ntuple_mode(opts, mode, tasks, label, proc_version):
    sys.stdout.write('dhad.gen: Mode %s, %s \n' % (mode, label))
    cleog.edit_fix_single_mode_list(opts, mode, label)

    create_filelist(opts, mode, tasks, label)
    jobtype = 'ntuple'

    if opts.set == 'interact':
        bash_file, logfile = create_bash_interact(opts, mode, label,
                                                  proc_version)
        if opts.test:
            sys.stdout.write(bash_file + '\n')
        else:
            subprocess.Popen(bash_file)
        return

    if opts.set == 'bg':
        bash_file, logfile = create_bash_interact(opts, mode, label,
                                                  proc_version)
        if opts.test:
            sys.stdout.write(bash_file + '\n')
            sys.stdout.write(logfile + '\n')
        else:
            sys.stdout.write('Save log as %s.\n' % logfile)
            process = subprocess.Popen(bash_file,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT)
            f = UserFile()
            f.append(process.communicate()[0])
            f.output(logfile)
        return

    bash_file = cleog.create_bash_fix_mc_job(jobtype, label=label)
    if opts.test:
        sys.stdout.write(bash_file + '\n')
        return

    output = commands.getoutput(bash_file)
    sys.stdout.write(output + '\n')
Example #36
0
def create_script_logfile_jobname(opts, datatype, tag, mode, label):
    prefix = 'dir_'+label
    logname = 'bkg_%s_%s.log' %(datatype, mode)
    logfile = tools.set_file(
        extbase=attr.yldlogpath, prefix=prefix,
        comname=logname)

    content =  '''#!/usr/bin/env python

from yld import crossfeeds

crossfeeds.process_signal_single_mode("%s", "%s", test=%s)

'''% (mode, label, opts.test)

    mode, sign = tools.get_modekey_sign(mode)

    if tag == 'single':
        if sign == 1:
            sign = 'p'
        else:
            sign = 'm'
        filename = 'csf-%s-%s-m%s-%s.py' % (datatype, tag, mode, sign)
        qjobname = 'csf%s,%s' % (mode, sign)
    else:
        filename = 'csf-%s-%s-m%s-%s.py' % (datatype, tag, mode[0], mode[1])
        qjobname = 'csf%s,%s' % (mode[0], mode[1])

    file_ = os.path.join(attr.datpath, datatype, label, 'src', 'yld', filename)
    verbose = opts.verbose
    if opts.test:
        verbose = 1
    f = UserFile()
    f.data.append(content) 
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)

    return filename, logfile, qjobname
Example #37
0
File: parse.py Project: xshi/dhad
def output_headerfiles(label):
    headernames = ['Double_D0D0B_header', 'Double_DpDm_header',
                   'Single_D0_header', 'Single_D0B_header',
                   'Single_Dp_header', 'Single_Dm_header']
    outpath = os.path.join(attr.datpath, 'signal', label,
                           'src', 'tag_fragments')
    for hname in headernames:
        headerfile = tools.check_and_join(outpath, hname)
        f = UserFile()
        if 'D0D0B' in hname:
            alias_line = '#\nAlias myD0 D0\n#\n#\nAlias myanti-D0 anti-D0\n#\n'
            psi_decay_line = '1.000    myD0  myanti-D0         VSS;\n'

        if 'DpDm' in hname:
            alias_line = '#\nAlias myD+ D+\n#\n#\nAlias myD- D-\n#\n'
            psi_decay_line = '1.000    myD+  myD-         VSS;\n'

        elif 'Single_D0_' in hname:
            alias_line = '#\nAlias myD0 D0\n#\n'
            psi_decay_line = '1.000    myD0  anti-D0         VSS;\n'

        elif 'Single_D0B_' in hname:
            alias_line = '#\nAlias myanti-D0 anti-D0\n#\n'
            psi_decay_line = '1.000    D0  myanti-D0         VSS;\n'

        elif 'Single_Dp_' in hname:
            alias_line = '#\nAlias myD+ D+\n#\n'
            psi_decay_line = '1.000    myD+  D-         VSS;\n'

        elif 'Single_Dm_' in hname:
            alias_line = '#\nAlias myD- D-\n#\n'
            psi_decay_line = '1.000    D+  myD-         VSS;\n'

        f.append(alias_line)
        f.append('Decay vpho\n1.000   psi(3770)  gamma    VPHOTOVISR ;\nEnddecay\n#\nDecay psi(3770)\n')
        f.append(psi_decay_line)
        f.append('Enddecay\n#')
        f.output(headerfile, verbose=1)
Example #38
0
def create_filelist(opts, mode, tasks, label):
    filelistpath = os.path.join(attr.datpath, 'signal', label, 'src',
                                'pds_files')
    filelistname = 'dt-%s' % mode
    filelist_ = os.path.join(filelistpath, filelistname)

    filelist = UserFile()
    filelist.append('source_format sel PDSSourceFormat\n')
    filelist.append('source create myChain\n')

    for task in tasks:
        inputname = 'dskim_%s_%s.pds' % (mode, task)
        inputpath = os.path.join(attr.datpath, 'signal', label,
                                 'dskim_' + attr.cleog + '_' + attr.pass2)
        inputfile = os.path.join(inputpath, inputname)
        filelist.append('file add myChain %s\n' % inputfile)

    filelist.append('source act myChain beginrun startrun event endrun\n')

    verbose = opts.verbose
    if opts.test:
        verbose = 1
    filelist.output(filelist_, verbose=verbose)
Example #39
0
File: cleog.py Project: xshi/dhad
def create_sh(filename, randomseeds=''):
    code_dir = os.path.join(attr.base, 'src', attr.src, 'gen')
    sh_file = tools.set_file(extbase=code_dir, comname=filename)

    sh_content =  '''#!/bin/sh
# request Bourne shell as shell for job
#$ -S /usr/local/bin/bash
#$ -j y
#$ -m a
#$ -M [email protected]
date
hostname

. /nfs/cleo3/Offline/scripts/cleo3logins
. /nfs/cleo3/Offline/scripts/cleo3defs

c3rel $CGRELEASE
echo $SHELL
cd $SCRIPTDIR

%s

export BATCH=$SGE_TASK_ID
export NUMEVT=`cat $SCRIPTDIR/tag_numbers/$1`
export RUNNUMBER=`nl -s " " $SCRIPTDIR/runlist | grep " $SGE_TASK_ID " | awk '{ print $2 }'`
export DECAYTITLE=$1
export UDECAY=$SCRIPTDIR/tag_decfiles/$1.dec
export OUTDIR=$TOPDIR/cleog$CGSUFFIX

suez -f genmc.tcl
date

''' % (randomseeds)
    
    f = UserFile()
    f.append(sh_content) 
    f.output(sh_file)
Example #40
0
def create_sh(filename, randomseeds=''):
    code_dir = os.path.join(attr.base, 'src', attr.src, 'gen')
    sh_file = tools.set_file(extbase=code_dir, comname=filename)

    sh_content = '''#!/bin/sh
# request Bourne shell as shell for job
#$ -S /usr/local/bin/bash
#$ -j y
#$ -m a
#$ -M [email protected]
date
hostname

. /nfs/cleo3/Offline/scripts/cleo3logins
. /nfs/cleo3/Offline/scripts/cleo3defs

c3rel $CGRELEASE
echo $SHELL
cd $SCRIPTDIR

%s

export BATCH=$SGE_TASK_ID
export NUMEVT=`cat $SCRIPTDIR/tag_numbers/$1`
export RUNNUMBER=`nl -s " " $SCRIPTDIR/runlist | grep " $SGE_TASK_ID " | awk '{ print $2 }'`
export DECAYTITLE=$1
export UDECAY=$SCRIPTDIR/tag_decfiles/$1.dec
export OUTDIR=$TOPDIR/cleog$CGSUFFIX

suez -f genmc.tcl
date

''' % (randomseeds)

    f = UserFile()
    f.append(sh_content)
    f.output(sh_file)
Example #41
0
def create_bash_file(opts, datatype, label, script,
                     bashname='get-yields.sh',
                     subdir='yld',  optcommand=''):
    script_dir = os.path.join(
        attr.datpath, datatype, label, 'src', subdir)

    bash_content =  '''#!/bin/sh
#$ -S /usr/local/bin/bash
#$ -j y
#$ -m a
#$ -M [email protected]

date
hostname

.  ~/.bashrc
setdhad %s 

%s

cd %s
./%s

date

''' % (attr.version, optcommand, script_dir, script)
    
    bash_file = os.path.join(script_dir, bashname)

    verbose = opts.verbose
    if opts.test:
        verbose = 1
    f = UserFile()
    f.append(bash_content) 
    f.output(bash_file, verbose=verbose)
    os.chmod(bash_file, 0755)
    return bash_file
Example #42
0
def create_python_script(dt_type, mode, label, test):
    content = '''#!/usr/bin/env python

from fit import backgrounds

backgrounds.fit_backgrounds_single_mode("%s", "%s", "%s", %s)

''' % (dt_type, mode, label, test)

    mode_sign = tools.get_modekey_sign(mode)

    ms = tools.pair_to_str(mode_sign)

    filename = 'backgrounds-%s-%s-%s.py' % (dt_type, ms, label)

    filename = filename.replace('/', '-')

    file_ = os.path.join(attr.srcfitpath, filename)

    f = UserFile()
    f.append(content)
    f.output(file_)
    os.chmod(file_, 0755)
    return filename
Example #43
0
def create_script_logfile_jobname(opts, datatype, tag, mode, label, test):
    logfile = tools.set_file('log', datatype, mode, tag,
                             prefix='dir_'+label, extbase=attr.yldlogpath)

    content =  '''#!/usr/bin/env python

import yld

yld.%s_tag_mode("%s", "%s", "%s", test=%s)

'''% (tag, datatype, mode, label, test)

    mode, sign = tools.get_modekey_sign(mode)

    if tag == 'single':
        if sign == 1:
            sign = 'p'
        else:
            sign = 'm'
        filename = '%s-%s-m%s-%s.py' % (datatype, tag, mode, sign)
        qjobname = 'yld%s,%s' % (mode, sign)
    else:
        filename = '%s-%s-m%s-%s.py' % (datatype, tag, mode[0], mode[1])
        qjobname = 'yld%s,%s' % (mode[0], mode[1])

    file_ = os.path.join(attr.datpath, datatype, label, 'src', 'yld', filename)
    verbose = opts.verbose
    if opts.test:
        verbose = 1
        sys.stdout.write('logfile: %s\n' %logfile)
    f = UserFile()
    f.data.append(content) 
    f.output(file_, verbose=verbose)
    os.chmod(file_, 0755)

    return filename, logfile, qjobname
Example #44
0
def create_python_script(dt_type, mode, label, test):
    content =  '''#!/usr/bin/env python

from fit import backgrounds

backgrounds.fit_backgrounds_single_mode("%s", "%s", "%s", %s)

'''% (dt_type, mode, label, test)

    mode_sign = tools.get_modekey_sign(mode)

    ms = tools.pair_to_str(mode_sign)

    filename = 'backgrounds-%s-%s-%s.py' % (dt_type, ms, label)

    filename = filename.replace('/', '-')
    
    file_ = os.path.join(attr.srcfitpath, filename)
    
    f = UserFile()
    f.append(content) 
    f.output(file_)
    os.chmod(file_, 0755)
    return filename
Example #45
0
File: cleog.py Project: xshi/dhad
def create_bash_interact(jobtype, mode, task_id=1,
                         label='', seeds=None, verbose=0):
    bashname = '%s_task_%s.sh' %(jobtype, task_id)

    CGRELEASE= attr.cleog
    P2RELEASE= attr.pass2
    DSKIMRELEASE = attr.dskim
    CGSUFFIX = '_'+ CGRELEASE
    SUFFIX   = CGSUFFIX + '_' + P2RELEASE
    TOPDIR   = os.path.join(attr.base, 'dat/signal', label)
    SCRIPTDIR = os.path.join(TOPDIR, 'src')

    logname = '%s-%s-%s.txt' %(jobtype, mode, task_id)
    logpath = os.path.join(TOPDIR, 'log%s' %SUFFIX)
    logfile = tools.set_file(extbase=logpath, comname=logname)

    core_content = attr.gen_core_content[jobtype]

    if jobtype == 'cleog' and seeds != None:
        randomseeds = 'export RANDOMSEEDS=%s' % seeds
        core_content = randomseeds + core_content

    bash_content =  '''#!/usr/local/bin/bash
date
hostname

. /nfs/cleo3/Offline/scripts/cleo3logins
. /nfs/cleo3/Offline/scripts/cleo3defs

export CGRELEASE=%s
export P2RELEASE=%s
export DSKIMRELEASE=%s
export CGSUFFIX=%s
export SUFFIX=%s
export TOPDIR=%s
export SCRIPTDIR=%s
LOGDIR=$TOPDIR/log$SUFFIX

STRING="%s"
SGE_TASK_ID=%s

if [ ! -e $TOPDIR ] ; then mkdir -p $TOPDIR ; fi
if [ ! -e $LOGDIR ] ; then mkdir -p $LOGDIR ; fi

cd $SCRIPTDIR

export BATCH=$SGE_TASK_ID
export DECAYTITLE=$STRING
export UDECAY=$SCRIPTDIR/tag_decfiles/$STRING.dec

%s

# print date and time again
date



''' % (CGRELEASE, P2RELEASE, DSKIMRELEASE, CGSUFFIX, SUFFIX, TOPDIR, 
       SCRIPTDIR, mode, task_id, core_content)
    
    bash_file = os.path.join(SCRIPTDIR, bashname)

    f = UserFile()
    f.data.append(bash_content) 
    f.output(bash_file, verbose)
    os.chmod(bash_file, 0755)
    return bash_file, logfile
Example #46
0
File: cleog.py Project: xshi/dhad
def create_bash_fix_mc_job(jobtype, label, task_id='1', seeds=None, verbose=0):
    
    CGRELEASE= attr.cleog
    P2RELEASE= attr.pass2
    DSKIMRELEASE = attr.dskim
    CGSUFFIX = '_'+ CGRELEASE
    SUFFIX   = CGSUFFIX + '_' + P2RELEASE
    TOPDIR   = os.path.join(attr.base, 'dat/signal', label)
    SCRIPTDIR = os.path.join(TOPDIR, 'src')

    DODECAYTREE='0'
    DOCLEOG='0'
    DOPASS2='0'
    DODSKIM='0'
    DONTUPLE='0'

    if jobtype == 'decaytree':
        DODECAYTREE='1'
    elif jobtype == 'cleog':
        DOCLEOG='1'
        if seeds != None:
            randomseeds = 'export RANDOMSEEDS=%s' % seeds
            create_sh('cleog-generic-array.sh', randomseeds)

    elif jobtype == 'pass2':
        DOPASS2='1'
    elif jobtype == 'dskim':
        DODSKIM='1'
    elif jobtype == 'ntuple':
        DONTUPLE='1'
    else:
        sys.stdout.write('\nUnknow jobtype: %s\n' % jobtype)
        sys.exit()
        

    bash_content =  '''#!/usr/local/bin/bash
export CGRELEASE=%s
export P2RELEASE=%s
export DSKIMRELEASE=%s
export CGSUFFIX=%s
export SUFFIX=%s
export TOPDIR=%s
export SCRIPTDIR=%s
LOGDIR=$TOPDIR/log$SUFFIX

DODECAYTREE=%s
DOCLEOG=%s
DOPASS2=%s
DODSKIM=%s
DONTUPLE=%s

FIXTASKID=%s

FILELISTINGS="fix_single_mode_list"

if [ ! -e $TOPDIR ] ; then mkdir -p $TOPDIR ; fi
if [ ! -e $LOGDIR ] ; then mkdir -p $LOGDIR ; fi

cd $SCRIPTDIR

for STRING in `cat $FILELISTINGS` ; do

if [[ $DODECAYTREE == 1 ]] ; then 
if [ ! -e $TOPDIR/decaytree$CGSUFFIX ] ; then mkdir $TOPDIR/decaytree$CGSUFFIX ; fi
qsub -l arch=lx24-x86 -o $LOGDIR/decaytree-$STRING-\$TASK_ID.txt \
-N decaytree-$STRING -t $FIXTASKID \
-v CGSUFFIX,TOPDIR,SCRIPTDIR,CGRELEASE \
decaytree-generic-array.sh $STRING
fi


if [[ $DOCLEOG == 1 ]] ; then 
if [ ! -e $TOPDIR/cleog$CGSUFFIX ] ; then mkdir $TOPDIR/cleog$CGSUFFIX ; fi
qsub -l arch=lx24-x86 -o $LOGDIR/cleog-$STRING-\$TASK_ID.txt \
-N cleog-$STRING -t $FIXTASKID \
-v CGSUFFIX,TOPDIR,SCRIPTDIR,CGRELEASE \
cleog-generic-array.sh $STRING
fi


if [[ $DOPASS2  == 1 ]] ; then
if [ ! -e $TOPDIR/pass2$SUFFIX ] ; then mkdir $TOPDIR/pass2$SUFFIX ; fi
qsub -l arch=lx24-x86 -o $LOGDIR/pass2-$STRING-\$TASK_ID.txt \
-N pass2-$STRING -hold_jid cleog-$STRING \
-t $FIXTASKID \
-v SUFFIX,CGSUFFIX,TOPDIR,SCRIPTDIR,P2RELEASE \
pass2-generic-array.sh $STRING
fi


if [[ $DODSKIM == 1 ]] ; then
if [ ! -e $TOPDIR/dskim$SUFFIX ] ; then mkdir $TOPDIR/dskim$SUFFIX ; fi
qsub -l arch=lx24-x86 -o $LOGDIR/dskim-$STRING-\$TASK_ID.txt \
-N dskim-$STRING -hold_jid pass2-$STRING \
-t $FIXTASKID \
-v SUFFIX,CGSUFFIX,TOPDIR,SCRIPTDIR,DSKIMRELEASE \
dskim-generic-array.sh $STRING
fi



if [[ $DONTUPLE == 1 ]] ; then
if [ ! -e $SCRIPTDIR/tmp ] ; then mkdir -p $SCRIPTDIR/tmp; fi
if [ ! -e $TOPDIR/dtuple$SUFFIX ] ; then mkdir $TOPDIR/dtuple$SUFFIX ; fi
qsub -l arch=lx24-x86 -o $LOGDIR/dtuple-$STRING.txt \
-N dtuple-$STRING -hold_jid dskim-$STRING -v SUFFIX,TOPDIR,SCRIPTDIR \
dtuple-generic-array.sh $STRING
fi
done


''' % (CGRELEASE, P2RELEASE, DSKIMRELEASE, CGSUFFIX, SUFFIX, TOPDIR , 
SCRIPTDIR, DODECAYTREE, DOCLEOG, DOPASS2 , DODSKIM, DONTUPLE, task_id)
    
    bash_file = os.path.join(SCRIPTDIR, 'fix_mc_job.sh')

    f = UserFile()
    f.data.append(bash_content) 
    f.output(bash_file, verbose)
    os.chmod(bash_file, 0755)
    return bash_file
Example #47
0
def output_fakemodes(fakemodes, modefile):
    f = UserFile()
    f.data.append('Mode || Number \n')
    for k, v in fakemodes.items():
        f.data.append('%s | %s \n' %(k, v))
    f.output(modefile)
Example #48
0
File: brf.py Project: xshi/dhad
def yields_and_efficiencies(opts, args):
    label = args[0]
    prefix = 'dir_'+label
    
    yldfile = tools.set_file(extbase=attr.brfpath, prefix=prefix, 
                             comname='yields_and_efficiencies')
    
    f = UserFile()

    single_modes = [(pair, sign) for pair in modes for sign in [-1, 1]]

    input_label = label
    if '.' in label:
        input_label = label.split('.')[0]
        
    prefix='dir_'+input_label+'/crossfeeds'

    dt_type = 'signal'
    for x in single_modes:
        if x[1] == 1:
            uname = modes[x[0]]['uname']
            fname = modes[x[0]]['fname']
        else:
            uname = modes[x[0]]['unamebar']
            fname = modes[x[0]]['fnamebar']

        txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fname)
        txtfile  = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=txtname)

        tab = DHadTable(txtfile)

        entries = tab.cell_get('entries', 'Value')
        entries = tab.cell_trim(entries, rnd='1')

        yld = tab.cell_get('yield', 'Value')
        yld = tab.cell_trim(yld, rnd='.000001')
        
        ratio = tab.cell_get('ratio', 'Value')
        ratio = tab.cell_trim(ratio, rnd='.000001')

        f.data.append('%s: %s %s %s\n' % (fname, entries, yld, ratio))
        
    for x, y  in [(x, y) for x in single_modes for y in single_modes if x!=y]:
        if x[1] == 1:
            uname = modes[x[0]]['uname']
            fname = modes[x[0]]['fname']
        else:
            uname = modes[x[0]]['unamebar']
            fname = modes[x[0]]['fnamebar']
        if y[1] == 1:
            unameb = modes[y[0]]['uname']
            fnameb = modes[y[0]]['fname']
        else:
            unameb = modes[y[0]]['unamebar']
            fnameb = modes[y[0]]['fnamebar']

        txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fnameb)
        txtfile  = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=txtname)

        tab = DHadTable(txtfile)

        entries = tab.cell_get('entries', 'Value')
        entries = tab.cell_trim(entries, rnd='1')

        yld = tab.cell_get('yld', 'Value')
        ylderr = tab.cell_get('yld', 'Error')
        
        try:
            float(yld)/float(ylderr)
        except:
            sys.stdout.write('The original ylderr is %s, set to 1.0e10.\n' % ylderr)
            ylderr = 1.0e10
            
        yldsigma = str(float(yld)/float(ylderr))
        yldsigma = tab.cell_trim(yldsigma, rnd='.000001')
        
        yld = tab.cell_trim(yld, rnd='.000001')

        ratio = str(float(yld)/float(entries))
        ratio = tab.cell_trim(ratio, rnd='.000001')

        ratioerr = str(float(ylderr)/float(entries))
        ratioerr = tab.cell_trim(ratioerr, rnd='.000001')

        f.data.append('%s fakes %s: %s %s %s %s %s\n' % (
            fname, fnameb, yldsigma, entries, yld, ratio, ratioerr))
       
    f.output(yldfile, verbose=1)
    return yldfile
Example #49
0
File: brs.py Project: xshi/dhad
def create_brsfile_three(args):
    comname = '_'.join(args)
    comname = comname.replace('.', '_')

    brsfile = set_file(extbase=attr.srcmnfpath, comname=comname, ext='mnf')
    brs = UserFile()
    header = r'''
set def
del 0
dep nmodes = 9

'''

    brs.append(header)

    label_0, content_0 = get_brs(args[0])

    label_1, content_1 = get_brs(args[2])
    label_2, content_2 = get_brs(args[1])
        
    brs.extend(content_0)
    brs.extend(content_1)

    hmin = 0.4
    hmax = 1.6
    xleft = 0.45
    textsize = 0.45

    if args[0] == 'pdg2010':
        hmin = 0.85
        hmax = 1.10
        xleft = 0.86
        
    trunk = r'''
exec colors
dep yoffset = -0.15
exec pdgCompareMany %s %s white mustard burgundy "%s" 4 "%s" 8

! Add another set of data points
rename 1 11
rename 2 12

''' % (hmin, hmax, label_0, label_1)
 
    brs.append(trunk)
    brs.extend(content_0)
    brs.extend(content_2)
        
    footer = r'''
dep yoffset = 0.15
exec pdgCompareMany %s %s white mustard burgundy "%s" 3 "%s" 6.5

over 11 -60/lavender
over 12 -60/lavender

key
1
new
1000
%s
13 17.5 0.4 0 left cm -2000 lavender 3 0.01 black

draw line 1 black 1 plot
%s, -3.5
%s, -3.5


! xleft is the x position of the mode label in plot units
dep xleft = %s
dep textsize = %s

exec pdgCompareComment 1 xleft textsize "'K^-![p]^+'"
exec pdgCompareComment 2 xleft textsize "'K^-![p]^+![p]^0!'"
exec pdgCompareComment 3 xleft textsize "'K^-![p]^+![p]^-![p]^+!'"
exec pdgCompareComment 4 xleft textsize "'K^-![p]^+![p]^+!'"
exec pdgCompareComment 5 xleft textsize "'K^-![p]^+![p]^+![p]^0!'"
exec pdgCompareComment 6 xleft textsize "'K^0?S![p]^+!'"
exec pdgCompareComment 7 xleft textsize "'K^0?S![p]^+![p]^0!'"
exec pdgCompareComment 8 xleft textsize "'K^0?S![p]^+![p]^-![p]^+!'"
exec pdgCompareComment 9 xleft textsize "'K^-!K^+![p]^+!'"

hard epost
'''  % (hmin, hmax, label_0, label_2, label_1, hmin, hmax, xleft, textsize)
    brs.append(footer)
    brs.output(brsfile)
    return brsfile
Example #50
0
File: diff.py Project: xshi/dhad
def output_set_to_file(set_, file_):
    f = UserFile()
    f.data = sorted(list(set_))
    f.output(file_)
Example #51
0
def create_bash_dtuple_generic(dataset, grade, skim, label):
    generic_dir = os.path.join(attr.base, 'dat/generic', attr.src)
    log_dir = generic_dir
    outputdir = generic_dir

    comname = 'generic_%s_%s_%s' % (grade, skim, dataset)

    logfile_name = comname + '.txt'
    code_dir = os.path.join(attr.base, 'src', attr.src, 'proc')
    logfile = os.path.join(log_dir, logfile_name)

    qjobname = 'g%s%s' % (skim.replace('lumi', ''), dataset.replace(
        'data', 'd'))

    if len(qjobname) > 7:
        qjobname = dataset.replace('data', 'g')
        items = qjobname.split('_')
        if len(items) > 2:
            qjobname = '_'.join([items[0], items[-1]])

    inputdata = comname

    backup_and_remove(logfile)

    if _debug:
        sys.stdout.write('\ndebug: outputdir %s\n' % generic_dir)
        sys.stdout.write('\ndebug: logfile %s\n' % logfile)
        sys.stdout.write('\ndebug: inputdata %s\n' % inputdata)
        sys.stdout.write('\ndebug: qjobname %s\n' % qjobname)

    if not os.access(outputdir, os.F_OK):
        sys.stdout.write('Creating dir %s...' % outputdir)
        os.makedirs(outputdir)
        sys.stdout.write(' done.\n')

    fname = comname

    bash_file_name = comname + '.sh'

    bash_file = os.path.join(attr.genpath, bash_file_name)

    bash_content = '''#!/bin/sh
# request Bourne shell as shell for job
#$ -S /usr/local/bin/bash
#$ -j y
#$ -m ea
#$ -M [email protected]

# print date and time
date
hostname

. /nfs/cleo3/Offline/scripts/cleo3logins
. /nfs/cleo3/Offline/scripts/cleo3defs

cd %s
. local_setup

export INPUTDATA=%s
export OUTPUTDIR=%s
export FNAME=%s
export USE_SETUP_ANALYSIS=1

suez -f HadronicDNtupleProc/Test/loadHadronicDNtupleProc.tcl
# print date and time again
date

''' % (code_dir, inputdata, outputdir, fname)

    f = UserFile()
    f.append(bash_content)
    f.output(bash_file)

    return logfile, qjobname, bash_file
Example #52
0
def main(opts, args):
    if args[0] == 'backgrounds':
        import backgrounds
        backgrounds.main(opts, args[1:])
        return

    if args[0] == 'brs':
        import brs
        brs.main(opts, args[1:])
        return

    if args[0] == 'compare':
        import compare
        compare.main(opts, args[1:])
        return

    if args[0] == 'cbx':
        import cbx
        cbx.main(opts, args[1:])
        return

    if args[0] == 'crossfeeds':
        import crossfeeds
        crossfeeds.main(opts, args[1:])
        return

    if args[0] == 'evt':
        import evt
        evt.main(opts, args[1:])
        return

    if args[0] == 'fun':
        import fun
        fun.main(opts, args[1:])
        return

    if args[0] == 'kkmass':
        import kkmass
        kkmass.main(opts, args[1:])
        return

    if args[0] == 'kpimass':
        import kpimass
        kpimass.main(opts, args[1:])
        return

    if args[0] == 'trim':
        import trim
        trim.main(opts, args[1:])
        return

    if args[0] == 'trkmtm':
        import trkmtm
        trkmtm.main(opts, args[1:])
        return

    if args[0] == 'trkmtm1':
        import trkmtm1
        trkmtm1.main(opts, args[1:])
        return

    if args[0] == 'trkmtm2':
        import trkmtm2
        trkmtm2.main(opts, args[1:])
        return

    if args[0] == 'var':
        import var
        var.main(opts, args[1:])
        return


    figname = '_'.join(args).replace('/', '_')

    parsed = parse_args(args)
    dt_type  = parsed[0]
    tag = parsed[1]
    modes = parsed[2]
    label = parsed[3]

    sqrt = False
    if opts.set and opts.set == 'sqrt':
        sqrt = True

    linr = False
    if opts.set and opts.set == 'linr':
        linr = True


    org = UserFile()
    org.append(attr.fig_web_header)

    for mode in modes:
        if mode == 'double_all_d0s' or mode == 'double_all_dps' :
            modekey = mode
        else:
            modekey = get_modekey(mode)
        if sqrt:
            sqrt_fig_mode(tag, dt_type, modekey, label)
        sys.stdout.write('Creating %s ...' % mode)
        sys.stdout.flush()
        msg = create_fig_mode(tag, dt_type, modekey, label)
        sys.stdout.write(' OK.\n')
        org.append(msg)

    org.append(attr.fig_web_footer)
    figlabel = label.split('/')[0]

    figname = figname.replace(figlabel, '')
    figname = figname.replace('__', '_')

    orgname = figname+'.org'
    orgname = orgname.replace('_.org', '.org')
    orgpath = os.path.join(attr.figpath, figlabel)
    orgfile = tools.check_and_join(orgpath, orgname)
    
    verbose = opts.verbose
    if opts.test:
        verbose = 1

    org.output(orgfile, verbose=verbose)
    orglink = '[[./fig/%s/%s][figure]]' %(figlabel, orgname)
    sys.stdout.write('\n%s\n\n' % orglink)

    if opts.test:
        return

    tools.org_export_as_html(orgfile)
Example #53
0
def create_bash_interact(opts, mode, label, proc_version):
    bashname = 'dtuple-interact.sh'

    CGRELEASE = attr.cleog
    P2RELEASE = attr.pass2
    DSKIMRELEASE = attr.dskim
    CGSUFFIX = '_' + CGRELEASE
    SUFFIX = CGSUFFIX + '_' + P2RELEASE
    TOPDIR = os.path.join(attr.base, 'dat/signal', label)
    SCRIPTDIR = os.path.join(TOPDIR, 'src')

    logname = 'dtuple-%s.txt' % mode
    logpath = os.path.join(TOPDIR, 'log%s' % SUFFIX)
    logfile = set_file(extbase=logpath, comname=logname)

    code_dir = os.path.join(attr.base, 'src', proc_version, 'proc')
    outputdir = os.path.join(attr.base, 'dat/signal', label,
                             'dtuple_' + attr.cleog + '_' + attr.pass2)

    if not os.access(outputdir, os.F_OK):
        sys.stdout.write('Creating dir %s ...\n' % outputdir)
        os.makedirs(outputdir)

    bash_content = '''#!/usr/local/bin/bash
date
hostname

. /nfs/cleo3/Offline/scripts/cleo3logins
. /nfs/cleo3/Offline/scripts/cleo3defs

export CGRELEASE=%s
export P2RELEASE=%s
export DSKIMRELEASE=%s
export CGSUFFIX=%s
export SUFFIX=%s
export TOPDIR=%s
export SCRIPTDIR=%s

LOGDIR=$TOPDIR/log$SUFFIX

cd %s
. local_setup

STRING="%s"

if [ ! -e $SCRIPTDIR/tmp ] ; then mkdir -p $SCRIPTDIR/tmp; fi
if [ ! -e $TOPDIR/dtuple$SUFFIX ] ; then mkdir $TOPDIR/dtuple$SUFFIX ; fi

export INDIR=$TOPDIR/dskim$SUFFIX

export INPUTDATA=USERLOCALMC_SKIMMED
export USE_SETUP_ANALYSIS=1

export OUTPUTDIR=$TOPDIR/dtuple$SUFFIX/$LABEL
export FILELIST=$SCRIPTDIR/pds_files/dt-$STRING
export FNAME=$STRING
suez -f HadronicDNtupleProc/Test/loadHadronicDNtupleProc.tcl

date
''' % (CGRELEASE, P2RELEASE, DSKIMRELEASE, CGSUFFIX, SUFFIX, TOPDIR, SCRIPTDIR,
       code_dir, mode)

    bash_file = os.path.join(attr.datpath, 'signal', label, 'src', bashname)
    f = UserFile()
    f.append(bash_content)

    verbose = opts.verbose
    if opts.test:
        verbose = 1
    f.output(bash_file, verbose=verbose)
    os.chmod(bash_file, 0755)

    return bash_file, logfile
Example #54
0
def yields_and_efficiencies(opts, args):
    label = args[0]
    prefix = 'dir_' + label

    yldfile = tools.set_file(extbase=attr.brfpath,
                             prefix=prefix,
                             comname='yields_and_efficiencies')

    f = UserFile()

    single_modes = [(pair, sign) for pair in modes for sign in [-1, 1]]

    input_label = label
    if '.' in label:
        input_label = label.split('.')[0]

    prefix = 'dir_' + input_label + '/crossfeeds'

    dt_type = 'signal'
    for x in single_modes:
        if x[1] == 1:
            uname = modes[x[0]]['uname']
            fname = modes[x[0]]['fname']
        else:
            uname = modes[x[0]]['unamebar']
            fname = modes[x[0]]['fnamebar']

        txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fname)
        txtfile = tools.set_file(extbase=attr.fitpath,
                                 prefix=prefix,
                                 comname=txtname)

        tab = DHadTable(txtfile)

        entries = tab.cell_get('entries', 'Value')
        entries = tab.cell_trim(entries, rnd='1')

        yld = tab.cell_get('yield', 'Value')
        yld = tab.cell_trim(yld, rnd='.000001')

        ratio = tab.cell_get('ratio', 'Value')
        ratio = tab.cell_trim(ratio, rnd='.000001')

        f.data.append('%s: %s %s %s\n' % (fname, entries, yld, ratio))

    for x, y in [(x, y) for x in single_modes for y in single_modes if x != y]:
        if x[1] == 1:
            uname = modes[x[0]]['uname']
            fname = modes[x[0]]['fname']
        else:
            uname = modes[x[0]]['unamebar']
            fname = modes[x[0]]['fnamebar']
        if y[1] == 1:
            unameb = modes[y[0]]['uname']
            fnameb = modes[y[0]]['fname']
        else:
            unameb = modes[y[0]]['unamebar']
            fnameb = modes[y[0]]['fnamebar']

        txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fnameb)
        txtfile = tools.set_file(extbase=attr.fitpath,
                                 prefix=prefix,
                                 comname=txtname)

        tab = DHadTable(txtfile)

        entries = tab.cell_get('entries', 'Value')
        entries = tab.cell_trim(entries, rnd='1')

        yld = tab.cell_get('yld', 'Value')
        ylderr = tab.cell_get('yld', 'Error')

        try:
            float(yld) / float(ylderr)
        except:
            sys.stdout.write('The original ylderr is %s, set to 1.0e10.\n' %
                             ylderr)
            ylderr = 1.0e10

        yldsigma = str(float(yld) / float(ylderr))
        yldsigma = tab.cell_trim(yldsigma, rnd='.000001')

        yld = tab.cell_trim(yld, rnd='.000001')

        ratio = str(float(yld) / float(entries))
        ratio = tab.cell_trim(ratio, rnd='.000001')

        ratioerr = str(float(ylderr) / float(entries))
        ratioerr = tab.cell_trim(ratioerr, rnd='.000001')

        f.data.append('%s fakes %s: %s %s %s %s %s\n' %
                      (fname, fnameb, yldsigma, entries, yld, ratio, ratioerr))

    f.output(yldfile, verbose=1)
    return yldfile
Example #55
0
def output_set_to_file(set_, file_):
    f = UserFile()
    f.data = sorted(list(set_))
    f.output(file_)