ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/submitThem.py
Revision: 1.10
Committed: Sun Sep 30 17:36:39 2012 UTC (12 years, 7 months ago) by bortigno
Content type: text/x-python
Branch: MAIN
Changes since 1.9: +15 -3 lines
Log Message:
re-insert sample customization. Option -S.

File Contents

# Content
1 #! /usr/bin/env python
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 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. ")
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 dictionary with the samples to run over
29 samplesDict=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 repDict = {'en':en,'logpath':logPath,'job':''}
47 def submit(job,repDict):
48 repDict['job'] = job
49 command = 'qsub -V -cwd -q all.q -N %(job)s_%(en)s -o %(logpath)s/%(job)s_%(en)s.out -e %(logpath)s/%(job)s_%(en)s.err runAll.sh %(job)s %(en)s ' %(repDict) + opts.task
50 print command
51 subprocess.call([command], shell=True)
52
53 if opts.task == 'dc':
54 DC_vars = config.items('Limit')
55 if opts.task == 'plot':
56 Plot_vars= config.items('Plot')
57
58 path = config.get("Directories","samplepath")
59 infofile = open(path+'/env/samples.info','r')
60 info = pickle.load(infofile)
61 infofile.close()
62
63
64 if opts.task == 'plot':
65 for item in Plot_vars:
66 if 'ZH%s'%opts.mass in item[0]:
67 submit(item[0],repDict)
68 elif opts.mass == '' and 'ZH' in item[0]:
69 submit(item[0],repDict)
70
71 elif opts.task == 'dc':
72 for item in DC_vars:
73 if 'ZH%s'%opts.mass in item[0] and opts.tag in item[0]:
74 submit(item[0],repDict)
75 elif 'ZH' in item[0] and opts.tag in item[0] and opts.mass == '*':
76 submit(item[0],repDict)
77 elif opts.task == 'prep':
78 submit('prepare',repDict)
79
80 elif opts.task == 'eval' or opts.task == 'sys':
81 if ( opts.samples == ""):
82 for job in info:
83 submit(job.name,repDict)
84 else:
85 for sample in samplesDict:
86 submit(sample,repDict)
87