Skip to content

Commit f24e803

Browse files
author
Luca
committed
scripts to shift CSC and create Input List
1 parent 8a832a6 commit f24e803

File tree

3 files changed

+596
-0
lines changed

3 files changed

+596
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import subprocess, time, sys, os, string
2+
3+
# Inputs
4+
ListDas = "InputList_DAS_2015D_PromotRecov3" # no .list (list of paths fo the files)
5+
removeUseless = True # remove files not included in the json files from the list
6+
randomList = True # randomize the list, it mixes files if they are sorted by size
7+
OutName = "SingleMuon_Run2015D-PromptReco-v3_RECO.py"
8+
fileJson = "Cert_246908-257599_13TeV_PromptReco_Collisions15_25ns_JSON_MuonPhys.txt"
9+
FilePerJob = 20
10+
11+
#Remove useles files
12+
fileIs=0
13+
fileIsNot=0
14+
if(removeUseless):
15+
ListDas_red = ListDas + '_red'
16+
Filelist_f = open( ListDas + '.list' )
17+
Jsonlist_f = open( fileJson )
18+
NEW_f = open( ListDas_red + ".list", 'w' )
19+
Filelistbase_v = Filelist_f.readlines()
20+
Jsonlistbase_v = Jsonlist_f.readlines()
21+
for Nline in range(len(Filelistbase_v)):
22+
IsThere=False
23+
line = Filelistbase_v[Nline]
24+
num = line.index('000') #assume .../v1/000/251/028/...
25+
newLine = line[int(num+4):int(num+7)]
26+
newLine += line[int(num+8):int(num)+11]
27+
for NlineJson in range(len(Jsonlistbase_v)):
28+
JsonLine = str(Jsonlistbase_v[NlineJson]).strip('\n')
29+
if( string.find(str(JsonLine),str(newLine))>0 ): IsThere=True
30+
if(IsThere):
31+
fileIs += 1
32+
NEW_f.write(Filelistbase_v[Nline])
33+
else:
34+
fileIsNot += 1
35+
print "File in the JSON files are " + str(fileIs) + "/" + str(float(fileIsNot+fileIs)) + " (" + str(float(fileIs/float(fileIs+fileIsNot))*100) + "%)"
36+
ListDas = ListDas_red
37+
Filelist_f.close()
38+
Jsonlist_f.close()
39+
NEW_f.close()
40+
41+
#Randomize
42+
if(randomList):
43+
ListDas_ran = ListDas + "_random"
44+
command = "cat " + ListDas + ".list | shuf > " + ListDas_ran + ".list"
45+
print "Executing:"
46+
print command
47+
comm = subprocess.Popen([command], stdout=subprocess.PIPE, shell=True);
48+
comm.communicate()
49+
ListDas = ListDas_ran
50+
51+
#Initial lines
52+
fout = open(OutName, 'w')
53+
num_lines = sum(1 for line in open(ListDas+ ".list"))
54+
fout.write('fileNamesBlocks = [\n')
55+
#Main body
56+
nLine = 1
57+
oldpost = ""
58+
with open(ListDas+ ".list", 'r') as f:
59+
for line in f:
60+
Myfile = line.strip()
61+
pre = ""
62+
if(nLine==1):
63+
pre = "["
64+
post = ""
65+
if(nLine%(FilePerJob)==0 and nLine!=1):
66+
post = "],"
67+
else:
68+
if(nLine != num_lines):
69+
post = ","
70+
else:
71+
post = "]"
72+
if(nLine!=1 and oldpost=="],"):
73+
pre = "["
74+
body = pre + "'" + str(Myfile) + "'" + post
75+
fout.write( body + '\n' )
76+
nLine += 1
77+
oldpost = post
78+
#Final line
79+
fout.write(']')
80+
fout.close()
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import subprocess, time, sys, os
2+
from ShiftCSCGeometry_Fn import *
3+
4+
# Inputs
5+
Curr_geo = "74X_dataRun2_Prompt_v0_AlignmentRcd" #no .xml here
6+
Tag_newGeo = "_moveglobal2"
7+
f = "data_CSC-1100-110001_SingleMuon_Run2015B-PromptReco-v1_RECO_7_4_6_patch3_pt20_v1_GlobalPosNoShift_01/data_CSC-1100-110001_SingleMuon_Run2015B-PromptReco-v1_RECO_7_4_6_patch3_pt20_v1_GlobalPosNoShift_01_plotting.root"
8+
9+
# First get your current geometry and make a copy
10+
print 'Copying ' + Curr_geo + '.xml -> ' + Curr_geo + Tag_newGeo + '.xml'
11+
copyGeo = subprocess.Popen(['cp ' + Curr_geo + '.xml ' + Curr_geo + Tag_newGeo + '.xml'], stdout=subprocess.PIPE, shell=True);
12+
copyGeo.communicate()
13+
14+
# Then Get the values for the shift
15+
16+
# Then edit your corrected geometry at the right line (last line -1)
17+
num_lines = sum(1 for line in open(Curr_geo + Tag_newGeo + '.xml'))
18+
print Curr_geo + '.xml has ' + str(num_lines) + ' lines'
19+
temp = open('temp', 'wb')
20+
nLine =0
21+
corr_1_1_1 = get_Corr(f,"p","+","1","1")
22+
corr_1_1_2 = get_Corr(f,"p","+","1","2")
23+
corr_1_1_3 = get_Corr(f,"p","+","1","3")
24+
corr_1_1_4 = corr_1_1_1
25+
corr_1_2_1 = get_Corr(f,"p","+","2","1")
26+
corr_1_2_2 = get_Corr(f,"p","+","2","2")
27+
corr_1_3_1 = get_Corr(f,"p","+","3","1")
28+
corr_1_3_2 = get_Corr(f,"p","+","3","2")
29+
corr_1_4_1 = get_Corr(f,"p","+","4","1")
30+
corr_1_4_2 = get_Corr(f,"p","+","4","2")
31+
corr_2_1_1 = get_Corr(f,"m","-","1","1")
32+
corr_2_1_2 = get_Corr(f,"m","-","1","2")
33+
corr_2_1_3 = get_Corr(f,"m","-","1","3")
34+
corr_2_1_4 = corr_2_1_1
35+
corr_2_2_1 = get_Corr(f,"m","-","2","1")
36+
corr_2_2_2 = get_Corr(f,"m","-","2","2")
37+
corr_2_3_1 = get_Corr(f,"m","-","3","1")
38+
corr_2_3_2 = get_Corr(f,"m","-","3","2")
39+
corr_2_4_1 = get_Corr(f,"m","-","4","1")
40+
corr_2_4_2 = get_Corr(f,"m","-","4","2")
41+
42+
with open(Curr_geo + Tag_newGeo + '.xml', 'r') as f:
43+
for line in f:
44+
nLine+=1
45+
if ( nLine==num_lines-1 ):
46+
temp.write('\n')
47+
temp.write('<operation>\n')
48+
temp.write(' <CSCRing endcap="1" station="1" ring="1" />\n')
49+
temp.write(' <moveglobal x="' + str(corr_1_1_1[0]) + '" y="' + str(corr_1_1_1[1]) + '" z="0" />\n')
50+
temp.write('</operation>\n')
51+
temp.write('\n')
52+
temp.write('<operation>\n')
53+
temp.write(' <CSCRing endcap="1" station="1" ring="2" />\n')
54+
temp.write(' <moveglobal x="' + str(corr_1_1_2[0]) + '" y="' + str(corr_1_1_2[1]) + '" z="0" />\n')
55+
temp.write('</operation>\n')
56+
temp.write('\n')
57+
temp.write('<operation>\n')
58+
temp.write(' <CSCRing endcap="1" station="1" ring="3" />\n')
59+
temp.write(' <moveglobal x="' + str(corr_1_1_3[0]) + '" y="' + str(corr_1_1_3[1]) + '" z="0" />\n')
60+
temp.write('</operation>\n')
61+
temp.write('\n')
62+
temp.write('<operation>\n')
63+
temp.write(' <CSCRing endcap="1" station="1" ring="4" />\n')
64+
temp.write(' <moveglobal x="' + str(corr_1_1_4[0]) + '" y="' + str(corr_1_1_4[1]) + '" z="0" />\n')
65+
temp.write('</operation>\n')
66+
temp.write('\n')
67+
temp.write('<operation>\n')
68+
temp.write(' <CSCRing endcap="1" station="2" ring="1" />\n')
69+
temp.write(' <moveglobal x="' + str(corr_1_2_1[0]) + '" y="' + str(corr_1_2_1[1]) + '" z="0" />\n')
70+
temp.write('</operation>\n')
71+
temp.write('\n')
72+
temp.write('<operation>\n')
73+
temp.write(' <CSCRing endcap="1" station="2" ring="2" />\n')
74+
temp.write(' <moveglobal x="' + str(corr_1_2_2[0]) + '" y="' + str(corr_1_2_2[1]) + '" z="0" />\n')
75+
temp.write('</operation>\n')
76+
temp.write('\n')
77+
temp.write('<operation>\n')
78+
temp.write(' <CSCRing endcap="1" station="3" ring="1" />\n')
79+
temp.write(' <moveglobal x="' + str(corr_1_3_1[0]) + '" y="' + str(corr_1_3_1[1]) + '" z="0" />\n')
80+
temp.write('</operation>\n')
81+
temp.write('\n')
82+
temp.write('<operation>\n')
83+
temp.write(' <CSCRing endcap="1" station="3" ring="2" />\n')
84+
temp.write(' <moveglobal x="' + str(corr_1_3_2[0]) + '" y="' + str(corr_1_3_2[1]) + '" z="0" />\n')
85+
temp.write('</operation>\n')
86+
temp.write('\n')
87+
temp.write('<operation>\n')
88+
temp.write(' <CSCRing endcap="1" station="4" ring="1" />\n')
89+
temp.write(' <moveglobal x="' + str(corr_1_4_1[0]) + '" y="' + str(corr_1_4_1[1]) + '" z="0" />\n')
90+
temp.write('</operation>\n')
91+
temp.write('\n')
92+
temp.write('<operation>\n')
93+
temp.write(' <CSCRing endcap="1" station="4" ring="2" />\n')
94+
temp.write(' <moveglobal x="' + str(corr_1_4_2[0]) + '" y="' + str(corr_1_4_2[1]) + '" z="0" />\n')
95+
temp.write('</operation>\n')
96+
temp.write('\n')
97+
temp.write('<operation>\n')
98+
temp.write(' <CSCRing endcap="2" station="1" ring="1" />\n')
99+
temp.write(' <moveglobal x="' + str(corr_2_1_1[0]) + '" y="' + str(corr_2_1_1[1]) + '" z="0" />\n')
100+
temp.write('</operation>\n')
101+
temp.write('\n')
102+
temp.write('<operation>\n')
103+
temp.write(' <CSCRing endcap="2" station="1" ring="2" />\n')
104+
temp.write(' <moveglobal x="' + str(corr_2_1_2[0]) + '" y="' + str(corr_2_1_2[1]) + '" z="0" />\n')
105+
temp.write('</operation>\n')
106+
temp.write('\n')
107+
temp.write('<operation>\n')
108+
temp.write(' <CSCRing endcap="2" station="1" ring="3" />\n')
109+
temp.write(' <moveglobal x="' + str(corr_2_1_3[0]) + '" y="' + str(corr_2_1_3[1]) + '" z="0" />\n')
110+
temp.write('</operation>\n')
111+
temp.write('\n')
112+
temp.write('<operation>\n')
113+
temp.write(' <CSCRing endcap="2" station="1" ring="4" />\n')
114+
temp.write(' <moveglobal x="' + str(corr_2_1_4[0]) + '" y="' + str(corr_2_1_4[1]) + '" z="0" />\n')
115+
temp.write('</operation>\n')
116+
temp.write('\n')
117+
temp.write('<operation>\n')
118+
temp.write(' <CSCRing endcap="2" station="2" ring="1" />\n')
119+
temp.write(' <moveglobal x="' + str(corr_2_2_1[0]) + '" y="' + str(corr_2_2_1[1]) + '" z="0" />\n')
120+
temp.write('</operation>\n')
121+
temp.write('\n')
122+
temp.write('<operation>\n')
123+
temp.write(' <CSCRing endcap="2" station="2" ring="2" />\n')
124+
temp.write(' <moveglobal x="' + str(corr_2_2_2[0]) + '" y="' + str(corr_2_2_2[1]) + '" z="0" />\n')
125+
temp.write('</operation>\n')
126+
temp.write('\n')
127+
temp.write('<operation>\n')
128+
temp.write(' <CSCRing endcap="2" station="3" ring="1" />\n')
129+
temp.write(' <moveglobal x="' + str(corr_2_3_1[0]) + '" y="' + str(corr_2_3_1[1]) + '" z="0" />\n')
130+
temp.write('</operation>\n')
131+
temp.write('\n')
132+
temp.write('<operation>\n')
133+
temp.write(' <CSCRing endcap="2" station="3" ring="2" />\n')
134+
temp.write(' <moveglobal x="' + str(corr_2_3_2[0]) + '" y="' + str(corr_2_3_2[1]) + '" z="0" />\n')
135+
temp.write('</operation>\n')
136+
temp.write('\n')
137+
temp.write('<operation>\n')
138+
temp.write(' <CSCRing endcap="2" station="4" ring="1" />\n')
139+
temp.write(' <moveglobal x="' + str(corr_2_4_1[0]) + '" y="' + str(corr_2_4_1[1]) + '" z="0" />\n')
140+
temp.write('</operation>\n')
141+
temp.write('\n')
142+
temp.write('<operation>\n')
143+
temp.write(' <CSCRing endcap="2" station="4" ring="2" />\n')
144+
temp.write(' <moveglobal x="' + str(corr_2_4_2[0]) + '" y="' + str(corr_2_4_2[1]) + '" z="0" />\n')
145+
temp.write('</operation>\n')
146+
temp.write(line)
147+
temp.close()
148+
MvTmp = subprocess.Popen(['mv temp ' + Curr_geo + Tag_newGeo + '.xml'], stdout=subprocess.PIPE, shell=True);
149+
MvTmp.communicate()
150+
print 'New geometry file ' + Curr_geo + Tag_newGeo + '.xml has been written'
151+
152+
print 'To convert the XML to DB, please do "CmsRun CSCshift_convertXMLtoSQLite_cfg.py"'
153+
convertXMLtoSQLite = open( "CSCshift_convertXMLtoSQLite_cfg.py", 'w' )
154+
writeXML_DB_Converter(convertXMLtoSQLite,"74X_dataRun2_Prompt_v0_AlignmentRcd_moveglobal.xml","74X_dataRun2_Prompt_v0_AlignmentRcd_CSCRingAlignment.db","GPR_July24_2015_Run2015B_74X_dataRun2_Prompt_v0_Tk150715_dL4_iter1.db","IdealGeometry" )

0 commit comments

Comments
 (0)