|
| 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