3 import re,os,sys,shutil
8 execfile(
"plotscripts.py")
10 ROOT.gROOT.SetBatch(1);
15 usage=
'%prog [options]\n'+\
16 'a script to run CSC ring alignment procedure'+\
17 'It is designed to run right after alignmentValidation.py script that was run with --map option. '
19 parser=optparse.OptionParser(usage)
21 parser.add_option(
"-l",
"--runLabel",
22 help=
"[REQUIRED] label to use for a run",
27 parser.add_option(
"-d",
"--dir",
28 help=
"[REQUIRED] directory where tmp_test_results_map__{runLabel}.pkl fit results file is located",
33 parser.add_option(
"-x",
"--xml",
34 help=
"[REQUIRED] xml file with input geometry",
39 parser.add_option(
"--ring2only",
40 help=
"if invoked, use only ring 2 results to align all rings in corresponding disks",
44 options,args=parser.parse_args()
47 if options.runLabel==
'' or options.dir==
'' or options.xml==
'':
48 print "\nOne or more of REQUIRED options is missing!\n"
52 allOptions =
"-l "+options.runLabel+
" -i "+options.dir+
" -x "+options.xml
54 print sys.argv[0]+
" "+allOptions
56 pwd = str(os.getcwdu())
58 if not os.access(options.dir,os.F_OK):
59 print "Directory " + options.dir +
" does not exist. Exiting..."
64 print "Cant open pickle file with mapplots fit results. Exiting..."
70 print " \tdX(mm) \t dY(mm) \tdPhiZ(mrad)"
71 for endcap
in CSC_TYPES:
72 for station
in endcap[2]:
73 for ring
in station[2]:
74 if ring[1]==
"ALL":
continue
76 if station[1]==
"4" and ring[1]==
"2":
continue
78 ring_id =
"%s%s/%s" % (endcap[0], station[1],ring[1])
80 if ring_id
in MAP_RESULTS_FITSIN:
83 fits = MAP_RESULTS_FITSIN[ring_id]
84 d_x, de_x = fits[
'sin'][0]/10., fits[
'sin'][1]/10.
85 d_y, de_y = -fits[
'cos'][0]/10., fits[
'cos'][1]/10.
86 d_phiz, de_phiz = -fits[
'a'][0]/10./signConventions[postal_address][3], fits[
'a'][1]/10./signConventions[postal_address][3]
88 print "%s \t%+.2f+-%.2f \t%+.2f+-%.2f \t%+.2f+-%.2f" % (ring_id, d_x*10 , de_x*10, d_y*10 , de_y*10 , d_phiz*1000, de_phiz*1000)
93 xml_corr[ring_id] =
"<setposition relativeto=\"none\" x=\"%(d_x)s\" y=\"%(d_y)s\" phiz=\"%(d_phiz)s\" />" % vars()
97 for endcap
in CSC_TYPES:
98 for station
in endcap[2]:
99 for ring
in station[2]:
100 if ring[1]==
"ALL":
continue
104 r_with_corr = ring[1]
105 s_with_corr = station[1]
107 if station[1]==
"4" and ring[1]==
"2": r_with_corr =
"1"
109 if options.ring2only : r_with_corr =
"2"
110 if options.ring2only
and station[1]==
"3": s_with_corr =
"2"
112 if station[1]==
"1" and ring[1]==
"1": r_with_corr =
"1"
120 ring_id =
"%s%s/%s" % (endcap[0], s_with_corr, r_with_corr)
122 if ring_id
in xml_corr:
123 corr = xml_corr[ring_id]
127 xml_str +=
"""<operation>
128 <CSCRing endcap=\"%(e)s\" station=\"%(s)s\" ring=\"%(r)s\" />
134 if s==
"1" and r==
"1":
135 xml_str +=
"""<operation>
136 <CSCRing endcap=\"%(e)s\" station=\"%(s)s\" ring=\"4\" />
143 xml_str +=
"</MuonAlignment>"
147 ff = open(options.xml+
".ring",mode=
"w")
151 os.system(
'grep -v "</MuonAlignment>" %s > %s' % (options.xml, options.xml+
".tmp"))
152 os.system(
'cat %s %s > %s' % (options.xml+
".tmp", options.xml+
".ring", options.xml+
".ring.xml") )
153 os.system(
'rm %s %s' % (options.xml+
".tmp", options.xml+
".ring") )