ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
make_rpv_snippets.py
Go to the documentation of this file.
1 #!/bin/env python
2 """Script for generating condor submission files"""
3 import shutil
4 import os
5 
6 def copytemplate(template, jobindex):
7  """Copy template to rundir"""
8  filename = template.replace('TEMPLATE',
9  'submit_' + jobindex).replace(' ', '_')
10  shutil.copy(template, filename)
11  return filename
12 
13 def replacestringinfile(filename, stringbefore, stringafter):
14  """Replace placeholders in template"""
15  tempstring = open(filename).read()
16  tempstring = tempstring.replace(stringbefore, stringafter)
17  outfile = open(filename, 'w')
18  outfile.write(tempstring)
19  outfile.close()
20 
22  """Output template"""
23  outfile = open('TEMPLATE.cmd', 'w')
24 
25  outfile.write('Executable = PATH/run_variations.sh\n')
26  outfile.write('Universe = vanilla\n')
27  outfile.write('Error = PATH/logs/VARTYPE.err\n')
28  outfile.write('Output = PATH/logs/VARTYPE.out\n')
29  outfile.write('Log = PATH/logs/VARTYPE.log\n')
30  outfile.write('arguments = "VARTYPE"\n')
31  outfile.write('request_memory = 3 GB\n')
32  outfile.write('Queue\n')
33  outfile.close()
34 
36  """Write script for condor jobs"""
37  outfile = open('run_variations.sh', 'w')
38  outfile.write('#!/bin/bash\n')
39  # set up CMSSW environment
40  outfile.write('. /cvmfs/cms.cern.ch/cmsset_default.sh\n')
41  outfile.write('cd /homes/cawest/CMSSW_7_4_14\n')
42  outfile.write('eval `scramv1 runtime -sh`\n')
43  outfile.write('cd ' + PATH + '\n')
44  # and then run script
45  outfile.write('./run/make_variations.exe $1 $2\n')
46  outfile.close()
47 
48 #default path should be changed
49 PATH = '/homes/jaehyeokyoo/RPV/ra4_macros_heller'
50 VARLIST = ['nominal','btag_bc', 'btag_udsg',
51  'gs45', 'gs67', 'gs89', 'gs10Inf',
52  'jes', 'jer',
53  'lep_eff', 'ttbar_pt', 'pileup',
54  'isr',
55  'qcd_flavor',
56  # the following are njet-dependent
57  # versions of the previous variation
58  'qcd_flavor45', 'qcd_flavor67',
59  'qcd_flavor89', 'qcd_flavor10Inf',
60  'qcd_mur', 'qcd_muf', 'qcd_murf',
61  'ttbar_mur', 'ttbar_muf', 'ttbar_murf',
62  'wjets_mur', 'wjets_muf', 'wjets_murf',
63  'other_mur', 'other_muf', 'other_murf',
64  'signal_mur', 'signal_muf', 'signal_murf']
65 
66 # make directory 'varscripts' to contain condor submit files
67 # and directory 'variations' to contain variations
68 PATH = os.getcwd()
69 if not os.path.isdir('variations'):
70  os.mkdir('variations')
71 if not os.path.isdir('varscripts'):
72  os.mkdir('varscripts')
73 os.chdir('varscripts')
74 
75 # write condor submission template file
76 # and script for running condor jobs
79 
80 
81 # add PDF variations
82 for i in range(0, 100):
83  VARLIST.append('w_pdf ' + str(i))
84 
85 for vartype in VARLIST:
86  newfilename = copytemplate('TEMPLATE.cmd', vartype)
87  replacestringinfile(newfilename, 'PATH', PATH + '/varscripts')
88  replacestringinfile(newfilename, 'VARTYPE', vartype)
89  replacestringinfile(newfilename, '/w_pdf ', '/w_pdf_')
90 
91 # remove the TEMPLATE.cmd temporary file
92 os.remove('TEMPLATE.cmd')
def replacestringinfile(filename, stringbefore, stringafter)
def copytemplate(template, jobindex)