3 from __future__
import print_function
4 import re,os,sys,shutil
9 execfile(
"plotscripts.py")
11 ROOT.gROOT.SetBatch(1);
16 usage=
'%prog [options]\n'+\
17 'a script to run CSC ring alignment procedure'+\
18 'It is designed to run right after alignmentValidation.py script that was run with --map option. '
20 parser=optparse.OptionParser(usage)
22 parser.add_option(
"-l",
"--runLabel",
23 help=
"[REQUIRED] label to use for a run",
28 parser.add_option(
"-d",
"--dir",
29 help=
"[REQUIRED] directory where tmp_test_results_map__{runLabel}.pkl fit results file is located",
34 parser.add_option(
"-x",
"--xml",
35 help=
"[REQUIRED] xml file with input geometry",
40 parser.add_option(
"--ring2only",
41 help=
"if invoked, use only ring 2 results to align all rings in corresponding disks",
45 options,args=parser.parse_args()
48 if options.runLabel==
'' or options.dir==
'' or options.xml==
'':
49 print(
"\nOne or more of REQUIRED options is missing!\n")
53 allOptions =
"-l "+options.runLabel+
" -i "+options.dir+
" -x "+options.xml
55 print(sys.argv[0]+
" "+allOptions)
57 pwd =
str(os.getcwd())
59 if not os.access(options.dir,os.F_OK):
60 print(
"Directory " + options.dir +
" does not exist. Exiting...")
65 print(
"Cant open pickle file with mapplots fit results. Exiting...")
71 print(
" \tdX(mm) \t dY(mm) \tdPhiZ(mrad)")
72 for endcap
in CSC_TYPES:
73 for station
in endcap[2]:
74 for ring
in station[2]:
75 if ring[1]==
"ALL":
continue
77 if station[1]==
"4" and ring[1]==
"2":
continue
79 ring_id =
"%s%s/%s" % (endcap[0], station[1],ring[1])
81 if ring_id
in MAP_RESULTS_FITSIN:
84 fits = MAP_RESULTS_FITSIN[ring_id]
85 d_x, de_x = fits[
'sin'][0]/10., fits[
'sin'][1]/10.
86 d_y, de_y = -fits[
'cos'][0]/10., fits[
'cos'][1]/10.
87 d_phiz, de_phiz = -fits[
'a'][0]/10./signConventions[postal_address][3], fits[
'a'][1]/10./signConventions[postal_address][3]
89 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))
94 xml_corr[ring_id] =
"<setposition relativeto=\"none\" x=\"%(d_x)s\" y=\"%(d_y)s\" phiz=\"%(d_phiz)s\" />" % vars()
98 for endcap
in CSC_TYPES:
99 for station
in endcap[2]:
100 for ring
in station[2]:
101 if ring[1]==
"ALL":
continue
105 r_with_corr = ring[1]
106 s_with_corr = station[1]
108 if station[1]==
"4" and ring[1]==
"2": r_with_corr =
"1"
110 if options.ring2only : r_with_corr =
"2"
111 if options.ring2only
and station[1]==
"3": s_with_corr =
"2"
113 if station[1]==
"1" and ring[1]==
"1": r_with_corr =
"1"
121 ring_id =
"%s%s/%s" % (endcap[0], s_with_corr, r_with_corr)
123 if ring_id
in xml_corr:
124 corr = xml_corr[ring_id]
128 xml_str +=
"""<operation>
129 <CSCRing endcap=\"%(e)s\" station=\"%(s)s\" ring=\"%(r)s\" />
135 if s==
"1" and r==
"1":
136 xml_str +=
"""<operation>
137 <CSCRing endcap=\"%(e)s\" station=\"%(s)s\" ring=\"4\" />
144 xml_str +=
"</MuonAlignment>"
148 ff = open(options.xml+
".ring",mode=
"w")
149 print(xml_str, file=ff)
152 os.system(
'grep -v "</MuonAlignment>" %s > %s' % (options.xml, options.xml+
".tmp"))
153 os.system(
'cat %s %s > %s' % (options.xml+
".tmp", options.xml+
".ring", options.xml+
".ring.xml") )
154 os.system(
'rm %s %s' % (options.xml+
".tmp", options.xml+
".ring") )
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)