1 |
|
#! /usr/bin/env python |
2 |
< |
import os,time,subprocess |
3 |
< |
energy='8TeV' |
4 |
< |
#energy='7TeV' |
2 |
> |
import os,shutil,sys,pickle,subprocess,ROOT |
3 |
> |
from optparse import OptionParser |
4 |
> |
from BetterConfigParser import BetterConfigParser |
5 |
> |
from samplesclass import sample |
6 |
> |
import getpass |
7 |
|
|
8 |
< |
def submit(job,en): |
9 |
< |
command = 'qsub -q all.q -N %s_%s -o /shome/nmohr/VHbbAnalysis/LOG/%s.out -e /shome/nmohr/VHbbAnalysis/LOG/%s.err runAll.sh %s %s' %(job,en,job,job,job,en) |
8 |
> |
parser = OptionParser() |
9 |
> |
parser.add_option("-T", "--tag", dest="tag", default="", |
10 |
> |
help="Tag to run the analysis with, example '8TeV' uses config8TeV and pathConfig8TeV to run the analysis") |
11 |
> |
parser.add_option("-J", "--task", dest="task", default="", |
12 |
> |
help="Task to be done, i.e. 'dc' for Datacards, 'prep' for preparation of Trees, 'plot' to produce plots or 'eval' to write the MVA output or 'sys' to write regression and systematics (or 'syseval' for both). ") |
13 |
> |
parser.add_option("-M", "--mass", dest="mass", default="125", |
14 |
> |
help="Mass for DC or Plots, 110...135") |
15 |
> |
parser.add_option("-S","--samples",dest="samples",default="", |
16 |
> |
help="samples you want to run on") |
17 |
> |
|
18 |
> |
|
19 |
> |
(opts, args) = parser.parse_args(sys.argv) |
20 |
> |
if opts.tag == "": |
21 |
> |
print "Please provide tag to run the analysis with, example '-T 8TeV' uses config8TeV and pathConfig8TeV to run the analysis." |
22 |
> |
sys.exit(123) |
23 |
> |
|
24 |
> |
if opts.task == "": |
25 |
> |
print "Please provide a task.\n-J prep:\tpreparation of Trees\n-J sys:\t\twrite regression and systematics\n-J eval:\tcreate MVA output\n-J plot:\tproduce Plots\n-J dc:\t\twrite workspaces and datacards" |
26 |
> |
sys.exit(123) |
27 |
> |
|
28 |
> |
#create the list with the samples to run over |
29 |
> |
samplesList=opts.samples.split(",") |
30 |
> |
|
31 |
> |
en = opts.tag |
32 |
> |
configs = ['config%s'%(en),'pathConfig%s'%(en)] |
33 |
> |
|
34 |
> |
print configs |
35 |
> |
config = BetterConfigParser() |
36 |
> |
config.read(configs) |
37 |
> |
btagLibrary = config.get('BTagReshaping','library') |
38 |
> |
submitDir = os.getcwd() |
39 |
> |
os.chdir(os.path.dirname(btagLibrary)) |
40 |
> |
if not os.path.exists(btagLibrary): |
41 |
> |
ROOT.gROOT.LoadMacro('%s+'%btagLibrary.replace('_h.so','.h')) |
42 |
> |
shutil.copyfile(os.path.basename(btagLibrary),'/scratch/%s/%s'%(getpass.getuser(),os.path.basename(btagLibrary))) |
43 |
> |
shutil.copyfile('/scratch/%s/%s'%(getpass.getuser(),os.path.basename(btagLibrary)),btagLibrary) |
44 |
> |
os.chdir(submitDir) |
45 |
> |
logPath = config.get("Directories","logpath") |
46 |
> |
#check if the logPath exist. If not exit |
47 |
> |
if( not os.path.isdir(logPath) ): |
48 |
> |
print 'ERROR: ' + logPath + ': dir not found.' |
49 |
> |
print 'ERROR: Create it before submitting ' |
50 |
> |
print 'Exit' |
51 |
> |
sys.exit(-1) |
52 |
> |
|
53 |
> |
repDict = {'en':en,'logpath':logPath,'job':'','task':opts.task,'queue': 'all.q'} |
54 |
> |
def submit(job,repDict): |
55 |
> |
repDict['job'] = job |
56 |
> |
command = 'qsub -V -cwd -q %(queue)s -N %(job)s_%(en)s%(task)s -o %(logpath)s/%(job)s_%(en)s_%(task)s.out -e %(logpath)s/%(job)s_%(en)s_%(task)s.err runAll.sh %(job)s %(en)s ' %(repDict) + opts.task |
57 |
|
print command |
58 |
|
subprocess.call([command], shell=True) |
59 |
|
|
60 |
< |
theJobs = ['ZH110','ZH125','ZH120','DY','ZH115','ZH130','ZH135','ZZ','DY120','Zmm','ST_s','TT','Zee','STbar_s','STbar_t','WZ','WW','STbar_tW','ST_tW'] |
61 |
< |
if energy=='8TeV': |
62 |
< |
theJobs = ['ZH110','ZH125','ZH120','DY','DY5070','DY70100','DY100','ZH115','ZH130','ZH135','ZZ','DY120','Zmm','ST_s','TT','Zee','STbar_s','STbar_t','WZ','WW','STbar_tW','ST_tW'] |
60 |
> |
if opts.task == 'dc': |
61 |
> |
#DC_vars = config.items('Limit') |
62 |
> |
DC_vars= (config.get('LimitGeneral','List')).split(',') |
63 |
> |
print DC_vars |
64 |
> |
|
65 |
> |
if opts.task == 'plot': |
66 |
> |
Plot_vars= (config.get('Plot_general','List')).split(',') |
67 |
> |
|
68 |
> |
if not opts.task == 'prep': |
69 |
> |
path = config.get("Directories","samplepath") |
70 |
> |
infofile = open(path+'/env/samples.info','r') |
71 |
> |
info = pickle.load(infofile) |
72 |
> |
infofile.close() |
73 |
> |
|
74 |
> |
|
75 |
> |
if opts.task == 'plot': |
76 |
> |
repDict['queue'] = 'short.q' |
77 |
> |
for item in Plot_vars: |
78 |
> |
submit(item,repDict) |
79 |
|
|
80 |
+ |
elif opts.task == 'dc': |
81 |
+ |
repDict['queue'] = 'short.q' |
82 |
+ |
for item in DC_vars: |
83 |
+ |
if 'ZH%s'%opts.mass in item and opts.tag in item: |
84 |
+ |
submit(item,repDict) |
85 |
+ |
elif 'ZH' in item and opts.tag in item and opts.mass == '*': |
86 |
+ |
submit(item,repDict) |
87 |
+ |
|
88 |
+ |
elif opts.task == 'prep': |
89 |
+ |
submit('prepare',repDict) |
90 |
|
|
91 |
< |
for job in theJobs: |
92 |
< |
submit(job,energy) |
93 |
< |
#time.sleep(10) |
91 |
> |
elif opts.task == 'eval' or opts.task == 'sys' or opts.task == 'syseval': |
92 |
> |
if ( opts.samples == ""): |
93 |
> |
for job in info: |
94 |
> |
submit(job.name,repDict) |
95 |
> |
else: |
96 |
> |
for sample in samplesList: |
97 |
> |
submit(sample,repDict) |
98 |
> |
|