def double_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.yield: Processing Mode %s...' % mode) sys.stdout.flush() set_modes_attr(label) rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) evtname = datatype + '_' + mode + '.evt' evtpath = os.path.join(attr.datpath, 'evt', label) evtfile = tools.check_and_join(evtpath, evtname) logname = datatype + '_' + mode + '.log' logpath = os.path.join(attr.logpath, 'evt', label) logfile = tools.check_and_join(logpath, logname) if test: sys.stdout.write('\ntest: rootfile %s \n' % rootfile) evtfile = evtfile + '.test' sys.stdout.write('\ntest: evtfile %s\n' %evtfile) logfile = logfile + '.test' sys.stdout.write('\ntest: logfile %s\n' %logfile) opt = label nselected, ntotal = output_mbc_ebeam(pt, mode, evtfile, logfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def check_decfile(opts, mode, label): toppath = os.path.join(attr.datpath, 'signal', label, 'src') decpath = os.path.join(toppath, 'tag_decfiles') decname = '%s.dec' % mode decfile = tools.check_and_join(decpath, decname) if 'Single' in mode: headername = mode.split('to')[0] + 'header' modename = mode.replace('Single_', '') check_decfile_single(opts, label, toppath, decfile, headername, modename) elif 'Double' in mode: headername = mode.split('to')[0] + 'header' if '_Dp_' in headername: headername = headername.replace('_Dp_', '_DpDm_') elif '_D0_' in headername: headername = headername.replace('_D0_', '_D0D0B_') else: raise NameError(headername) modename = mode.replace('Double_', '') check_decfile_double(opts, label, toppath, decfile, headername, modename) else: raise NameError(mode)
def merge_root_files(srcdir, dstdir, size_max='5G', nfile_max=500): file_list = [] size_list = [] for root, dirs, files in os.walk(srcdir): for f in files: s = os.path.getsize(os.path.join(root, f)) file_list.append(os.path.join(root, f)) size_list.append(s) totalsize = sum(size_list) sys.stdout.write('total of %s files, size %s.\n' % (len(file_list), size(totalsize))) com_name = file_list[0].split('-')[0].split('/')[-1] groups = group_files_by_size(file_list, size_max) ngroups = len(groups) for i in range(ngroups): print i sourcefiles = ' '.join(groups[i-1]) targetname = '%s_merged_%s.root' % (com_name, i+ngroups) targetfile = check_and_join(dstdir, targetname) cmd = 'hadd %s %s' %(targetfile, sourcefiles) sys.stdout.write('merging %s of %s ...\n' %(i+1, ngroups)) sys.stdout.flush() output = proc_cmd(cmd) print output
def merge_root_files(srcdir, dstdir, size_max='2G', nfile_max=500): file_list = [] size_list = [] for root, dirs, files in os.walk(srcdir): for f in files: s = os.path.getsize(os.path.join(root, f)) file_list.append(os.path.join(root, f)) size_list.append(s) totalsize = sum(size_list) sys.stdout.write('total of %s files, size %s.\n' % (len(file_list), size(totalsize))) com_name = file_list[0].split('-')[0].split('/')[-1] groups = group_files_by_size(file_list, size_max) ngroups = len(groups) for i in range(ngroups): print i sourcefiles = ' '.join(groups[i-1]) targetname = '%s_merged_%s.root' % (com_name, i+ngroups) targetfile = check_and_join(dstdir, targetname) cmd = 'hadd %s %s' %(targetfile, sourcefiles) sys.stdout.write('merging %s of %s ...\n' %(i+1, ngroups)) sys.stdout.flush() output = proc_cmd(cmd) print output
def tag_fragments(opts, args): label = args[0] if label in ['281ipbv12', '537ipbv12', '818ipbv12']: release = '20080624_MCGEN' else: raise NameError(label) sys.stdout.write('Using release %s...\n' % release) output_headerfiles(label) decfile = '/nfs/cleo3/Offline/rel/%s/data/DECAY.DEC' % release i = interactive() i.do_readfile(decfile) modes = attr.modes for mode in modes: for fname, decname in [('fname', 'decname'), ('fnamebar', 'decnamebar')]: decay = modes[mode][decname] parent = decay.split()[0] children = decay.split()[2:] outname = modes[mode][fname] outpath = os.path.join(attr.datpath, 'signal', label, 'src', 'tag_fragments') outfile = tools.check_and_join(outpath, outname) i.details(parent, children, outfile)
def check_decfile(opts, mode, label): toppath = os.path.join(attr.datpath, 'signal', label, 'src') decpath = os.path.join(toppath, 'tag_decfiles') decname = '%s.dec' % mode decfile = tools.check_and_join(decpath, decname) if 'Single' in mode: headername = mode.split('to')[0] + 'header' modename = mode.replace('Single_', '') check_decfile_single(opts, label, toppath, decfile, headername, modename) elif 'Double' in mode: headername = mode.split('to')[0] + 'header' if '_Dp_' in headername: headername = headername.replace('_Dp_', '_DpDm_') elif '_D0_' in headername: headername = headername.replace('_D0_', '_D0D0B_') else: raise NameError(headername) modename = mode.replace('Double_', '') check_decfile_double(opts, label, toppath, decfile, headername, modename) else: raise NameError(mode)
def tag_fragments(opts, args): label = args[0] if label in ['281ipbv12', '537ipbv12', '818ipbv12']: release = '20080624_MCGEN' else: raise NameError(label) sys.stdout.write('Using release %s...\n' %release) output_headerfiles(label) decfile = '/nfs/cleo3/Offline/rel/%s/data/DECAY.DEC' % release i = interactive() i.do_readfile(decfile) modes = attr.modes for mode in modes: for fname, decname in [('fname','decname'), ('fnamebar','decnamebar')]: decay = modes[mode][decname] parent = decay.split()[0] children = decay.split()[2:] outname = modes[mode][fname] outpath = os.path.join(attr.datpath, 'signal', label, 'src', 'tag_fragments') outfile = tools.check_and_join(outpath, outname) i.details(parent, children, outfile)
def get_evtfile(datatype, mode, label, var, test=False): evtname = '%s_%s.evt' %(datatype, mode) if test: evtname += '.test' evtpath = os.path.join(attr.datpath, 'sel', label, var) evtfile = tools.check_and_join(evtpath, evtname) return evtfile
def get_evtfile(datatype, mode, label, var, test=False): evtname = '%s_%s.evt' % (datatype, mode) if test: evtname += '.test' evtpath = os.path.join(attr.datpath, 'sel', label, var) evtfile = tools.check_and_join(evtpath, evtname) return evtfile
def get_selfile(datatype, mode, label, test=False): selname = '%s_%s.root' %(datatype, mode) if test: selname += '.test' selpath = os.path.join(attr.datpath, 'sel', label, 'trkmtm') selfile = tools.check_and_join(selpath, selname) return selfile
def get_bkgfile(bkgname, label): bkgpath = os.path.join(attr.bkgpath, label) bkgfile = tools.check_and_join(bkgpath, bkgname) if not os.access(bkgfile, os.F_OK): if '818ipb' in label: bkgfile_281ipb = bkgfile.replace('818ipb', '281ipb') bkgfile_537ipb = bkgfile.replace('818ipb', '537ipb') tools.combine_files(bkgfile_281ipb, bkgfile_537ipb, bkgfile) else: raise ValueError(bkgfile) return bkgfile
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)
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)
def get_input_output_file(datatype, mode, label, outputdir): datpath = attr.datpath if datatype == 'signal': inputname = mode + '.root' elif datatype == 'data': inputname = '*.root' else: raise NameError(datatype) outputname = mode + '.root' inputpath = os.path.join(datpath, datatype, label) outputpath = os.path.join(inputpath, outputdir) inputfile = os.path.join(inputpath, inputname) outputfile = tools.check_and_join(outputpath, outputname) return inputfile, outputfile
def get_input_output_file(datatype, mode, label, outputdir): datpath = attr.datpath if datatype == 'signal': inputname = mode+'.root' elif datatype == 'data': inputname = '*.root' else: raise NameError(datatype) outputname = mode+'.root' inputpath = os.path.join(datpath, datatype, label) outputpath = os.path.join(inputpath, outputdir) inputfile = os.path.join(inputpath, inputname) outputfile = tools.check_and_join(outputpath, outputname) return inputfile, outputfile
def single_tag_mode(var, datatype, mode, label, test=False): sys.stdout.write('dhad.yld.var(%s): Processing Mode %s...' %(var,mode)) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) evtname = '%s_%s.evt' %(datatype, mode) evtpath = os.path.join(datpath, 'evt', label, 'var', var) evtfile = tools.check_and_join(evtpath, evtname) if var == 'deltae': nselected, ntotal = output_var_deltae(pt, mode, evtfile, label, test) else: raise NameError(var) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def single_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.sel.kssideband: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) if test: sys.stdout.write('rootfile: %s \n' % rootfile) pt = tools.add_rootfile(rootfile) selname = '%s_%s.evt' %(datatype, mode) if test: selname += '.test' selpath = os.path.join(attr.datpath, 'evt', label, 'kssideband') selfile = tools.check_and_join(selpath, selname) nselected, ntotal = output_kssideband(pt, mode, selfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
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)
def single_tag_mode(reweight, datatype, mode, label, test=False): sys.stdout.write('dhad.sel.multspec: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) selname = '%s_%s.root' % (datatype, mode) if test: selname += '.test' selpath = os.path.join(attr.datpath, 'sel', label, 'multspec', reweight) selfile = tools.check_and_join(selpath, selname) nselected, ntotal = output_multspec(reweight, pt, mode, selfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.write('Saved as %s \n' % selfile) sys.stdout.flush()
def single_tag_mode(reweight, datatype, mode, label, test=False): sys.stdout.write('dhad.sel.multspec: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) selname = '%s_%s.root' %(datatype, mode) if test: selname += '.test' selpath = os.path.join(attr.datpath, 'sel', label, 'multspec', reweight) selfile = tools.check_and_join(selpath, selname) nselected, ntotal = output_multspec(reweight, pt, mode, selfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.write('Saved as %s \n' %selfile) sys.stdout.flush()
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)
def single_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.yld.events: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath if datatype == 'signal': rootname = mode + '.root' elif datatype == 'data': rootname = '*.root' else: raise NameError(datatype) rootfile = os.path.join(datpath, datatype, label, rootname) pt = tools.add_rootfile(rootfile) evtname = datatype + '_' + mode + '.evt' evtpath = os.path.join(datpath, 'evt', label, 'events') evtfile = tools.check_and_join(evtpath, evtname) nselected, ntotal = output_run_event(pt, mode, evtfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def single_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.yld.events: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath if datatype == 'signal': rootname = mode + '.root' elif datatype == 'data': rootname = '*.root' else: raise NameError(datatype) rootfile = os.path.join(datpath, datatype, label, rootname) pt = tools.add_rootfile(rootfile) evtname = datatype + '_' + mode + '.evt' evtpath = os.path.join(datpath, 'evt', label, 'events') evtfile = tools.check_and_join(evtpath, evtname) nselected, ntotal = output_run_event(pt, mode, evtfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
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)
def output_multcand(pt, mode, selname, label, test=False): selpath_single = os.path.join(attr.datpath, 'evt', label, 'single_candidate') selfile_single = tools.check_and_join(selpath_single, selname) selpath_multiple = os.path.join(attr.datpath, 'evt', label, 'multiple_candidate') selfile_multiple = tools.check_and_join(selpath_multiple, selname) modekey, sign = tools.get_modekey_sign(mode) if sign == None: if not isinstance(modekey, tuple): raise ValueError(modekey) if modekey[0] in [0, 200]: signs = [-1] if modekey[1] in [0, 200]: signs = [1, -1] modekey = modekey[1] elif modekey[1] in [0, 200]: signs = [1] modekey = modekey[0] else: raise ValueError(modekey) else: signs = [sign] outf_s = open(selfile_single, 'w') outf_m = open(selfile_multiple, 'w') ntotal = 0 nselected = 0 for pte in pt: ntotal += 1 if test and nselected >= 30: break if pte.ecm < 3.7: continue for sign in signs: choice = chooseD(modekey, pte, sign) if choice != None and passDE(choice, pte): if pte.dmbc[choice] < 1.83: continue dictchoice = outf_s if countDcand(modekey, pte, sign) >= 2: dictchoice = outf_m dictchoice.write('%s %s %s\n' % (pte.dmbc[choice], pte.ecm / 2, sign)) nselected += 1 outf_s.close() outf_m.close() sys.stdout.write('Saved as %s \n' % selfile_single) sys.stdout.write('Saved as %s \n' % selfile_multiple) return nselected, ntotal
def output_multcand(pt, mode, selname, label, test=False): selpath_single = os.path.join(attr.datpath, 'evt', label, 'single_candidate') selfile_single = tools.check_and_join(selpath_single, selname) selpath_multiple = os.path.join(attr.datpath, 'evt', label, 'multiple_candidate') selfile_multiple = tools.check_and_join(selpath_multiple, selname) modekey, sign = tools.get_modekey_sign(mode) if sign == None: if not isinstance(modekey, tuple): raise ValueError(modekey) if modekey[0] in [0, 200]: signs = [-1] if modekey[1] in [0, 200]: signs = [1, -1] modekey = modekey[1] elif modekey[1] in [0, 200]: signs = [1] modekey = modekey[0] else: raise ValueError(modekey) else: signs = [sign] outf_s = open(selfile_single, 'w') outf_m = open(selfile_multiple, 'w') ntotal = 0 nselected = 0 for pte in pt: ntotal += 1 if test and nselected >= 30: break if pte.ecm < 3.7: continue for sign in signs: choice = chooseD(modekey, pte, sign) if choice != None and passDE(choice, pte): if pte.dmbc[choice] < 1.83: continue dictchoice = outf_s if countDcand(modekey, pte, sign) >= 2: dictchoice = outf_m dictchoice.write('%s %s %s\n' % (pte.dmbc[choice], pte.ecm/2, sign)) nselected += 1 outf_s.close() outf_m.close() sys.stdout.write('Saved as %s \n' %selfile_single) sys.stdout.write('Saved as %s \n' %selfile_multiple) return nselected, ntotal
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)
def main(opts, args): label = args[0] test = opts.test sys.stdout.write('dhad.sel.extlbkgs ...') sys.stdout.flush() datpath = attr.datpath datatype = 'generic' rootfile = tools.get_rootfile(datatype, label=label, test=test) pt = tools.add_rootfile(rootfile) bkg_mcdmodes = { 'kpi' : mcstringtodmode('K+ pi-'), 'kpipi0' : mcstringtodmode('K+ pi- pi0'), 'k3pi' : mcstringtodmode('K+ pi- pi+ pi-'), 'kkspi' : mcstringtodmode('K- K0 pi+'), 'kkspibar' : mcstringtodmode('K+ K0 pi-'), '3pi' : mcstringtodmode('pi+ pi- pi+'), '3pipi0' : mcstringtodmode('pi+ pi- pi+ pi0'), '5pi' : mcstringtodmode('pi+ pi- pi+ pi- pi+'), 'kskspi' : mcstringtodmode('K0 K0 pi+') } bkg_mcdmodes_rev = {} counts = {} files = {} selpath = os.path.join(attr.datpath, 'sel', label, 'extlbkgs') for i in bkg_mcdmodes: bkg_mcdmodes_rev[bkg_mcdmodes[i]] = i counts[i] = 0 selname = 'singtag_bkg_%s.evt' % i if test: selname += '.test' selfile = tools.check_and_join(selpath, selname) files[i] = open(selfile, 'w') # First number is the sign of the D we should look at for the fake signal; # second number is the mode. bkg_dmodes = { 'kpi' : (-1, 0), 'kpipi0' : (-1, 1), 'k3pi' : (-1, 3), 'kkspi' : (1, 3), 'kkspibar' : (-1, 3), '3pi' : (1, 202), '3pipi0' : (1, 203), '5pi' : (1, 204), 'kskspi' : (1, 204) } ensure_other_side_is_not = { 'kpi' : (mcstringtodmode('K+ pi-'),), 'kpipi0' : (mcstringtodmode('K+ pi- pi0'),), 'k3pi' : (mcstringtodmode('K+ pi- pi+ pi-'), mcstringtodmode('K+ K0 pi-')), 'kkspi' : (mcstringtodmode('K- K0 pi+'), mcstringtodmode('K- pi+ pi- pi+')), 'kkspibar' : (mcstringtodmode('K+ K0 pi-'), mcstringtodmode('K+ pi- pi- pi+')), '3pi' : (), '3pipi0' : (), '5pi' : (), 'kskspi' : () } ntotal = 0 nselected = 0 for pte in pt: ntotal += 1 if test and ntotal > 1000: break mcd = makeDDecaySubTree(pte, 1) mcdb = makeDDecaySubTree(pte, -1) mcdmode = mcDmodeFixRad(mcd[0].mcDmode()) mcdbmode = mcDmodeFixRad(mcdb[0].mcDmode()) if (mcdmode in bkg_mcdmodes_rev): mcdmode_string = bkg_mcdmodes_rev[mcdmode] if mcdbmode not in ensure_other_side_is_not[mcdmode_string]: counts[mcdmode_string] += 1 choice = chooseD(bkg_dmodes[mcdmode_string][1], pte, bkg_dmodes[mcdmode_string][0]) if choice != None and passDE(choice, pte): nselected += 1 files[mcdmode_string].write('%g\n' % pte.dmbc[choice]) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.write('Number of mcdmode: %s. \n' % counts) sys.stdout.flush()