-
Notifications
You must be signed in to change notification settings - Fork 4
/
hInvert.py
executable file
·106 lines (80 loc) · 3.78 KB
/
hInvert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python
import commands
import fileinput
import sys
import os
TESTING = 0
QUEUE = '8nm'
# copio nella cartella di arrivo meta' delle gen folder
# per la restante meta', chiamo la conversione
def runCommand (command, printIt = 0, doIt = 1) :
if printIt : print ('> ' + command)
if doIt :
commandOutput = commands.getstatusoutput (command)
if printIt : print commandOutput[1]
return commandOutput
else : print (' command not run')
return (1, 'command not run')
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
def prepareJob (tag, command) :
filename = 'run_' + tag + '.job'
f = open (filename, 'w')
f.write ('cd /cvmfs/cms.cern.ch/slc6_amd64_gcc481/cms/cmssw/CMSSW_7_2_0\n')
f.write ('eval `scram run -sh`\n')
f.write ('cd -\n')
f.write (command + '\n')
f.close ()
return filename
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
def submitToLSF (tag, command) :
print 'run : submitting jobs'
jobFileName = prepareJob (tag, command)
runCommand ('bsub -J ' + tag + ' -u pippopluto -q ' + QUEUE + ' < ' + jobFileName,
TESTING == 1, TESTING == 0)
runCommand ('rm ' + jobFileName, TESTING == 1, TESTING == 0)
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
if __name__ == "__main__":
eoscmd = '/afs/cern.ch/project/eos/installation/cms/bin/eos.select' ;
converter ='/afs/cern.ch/user/g/govoni/work/PHANTOM/phantom_at_cern/LHEActions/invertMuAndEleInLHE'
inputFolder = sys.argv[1]
outputBaseFolder = os.path.abspath (sys.argv[2])
outputUUFolder = outputBaseFolder + '/' + inputFolder + '_UE'
outputEEFolder = outputBaseFolder + '/' + inputFolder + '_EU'
inputFolder = os.path.abspath (inputFolder)
# find the gen folders
res = runCommand ('ls ' + inputFolder)
folders = [fol for fol in res[1].split () if 'gen' in fol and fol != 'gendir.scr']
if (len (folders) != 100) :
print 'PROBLEM: missing gen folders in ', inputFolder
sys.exit (1)
res = runCommand ('ls ' + outputBaseFolder)
if (res[0] != 0) :
print 'PROBLEM: missing output base folder ', outputBaseFolder
sys.exit (1)
res = runCommand ('ls ' + outputUUFolder, TESTING == 1, TESTING == 0)
if (res[0] == 0) :
print 'PROBLEM: output folder ', outputUUFolder, ' already existing'
sys.exit (1)
runCommand ('mkdir ' + outputUUFolder, TESTING == 1, TESTING == 0)
res = runCommand ('ls ' + outputEEFolder, TESTING == 1, TESTING == 0)
if (res[0] == 0) :
print 'PROBLEM: output folder ', outputEEFolder, ' already existing'
sys.exit (1)
runCommand ('mkdir ' + outputEEFolder, TESTING == 1, TESTING == 0)
# copy half of the events in the muons folder
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
runCommand ('cp ' + inputFolder + '/result ' + outputUUFolder, TESTING == 1, TESTING == 0)
for i in range (len (folders) / 2) :
runCommand ('cp -r ' + inputFolder + '/gen' + str (i + 1)
+ ' ' + outputUUFolder, TESTING == 1, TESTING == 0)
# the electrons part
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
runCommand ('cp ' + inputFolder + '/result ' + outputEEFolder, TESTING == 1, TESTING == 0)
for i in range (len (folders) / 2) :
localInputFolder = inputFolder + '/gen' + str (i + 1 + len (folders) / 2)
localOutputFolder = outputEEFolder + '/gen' + str (i + 1)
runCommand ('mkdir ' + localOutputFolder,
TESTING == 1, TESTING == 0)
submitToLSF (str (i+1),
converter + ' ' + localInputFolder + '/phamom.dat'
+ ' ' + localOutputFolder + '/phamom.dat')