3 from __future__
import print_function
4 from builtins
import range
5 import os, sys, optparse, math, copy
6 from Alignment.MuonAlignment.geometryXMLparser
import MuonGeometry, dtorder, cscorder
9 for i
in range(len(copyargs)):
12 commandline =
" ".
join(copyargs)
17 usage =
"""%(prog)s INPUT_XML_0 INPUT_XML_N INPUT_REPORT_N OUTPUT_XML [--nsigma NSIGMA] [--dt] [--csc]
21 INPUT_XML_0 is xml file name with chamber positions from the initial (iteration 0) geometry
22 INPUT_XML_N is xml file name with chamber positions from the last iteration's geometry
23 INPUT_REPORT_N is a _report.py file from the last iteration
24 OUTPUT_XML is the resulting .xml file
28 --nsigma NSIGMA optional minimum position displacement (measured in nsigma of deltax) in order to move a chamber
30 --dt if present, DT chambers will be included
31 --csc if present, CSC chambers will be included
32 NOTE: By default, having no --dt or --csc specified is equivalent to "--dt --csc"
36 print(
"Too few arguments.\n\n"+usage)
39 parser=optparse.OptionParser(usage)
41 parser.add_option(
"-s",
"--nsigma",
42 help=
"optional minimum nsigma(deltax) position displacement in order to move a chamber; default NSIGMA=3",
47 parser.add_option(
"--dt",
48 help=
"If it is present, but not --csc, DT chambers only will be considered",
53 parser.add_option(
"--csc",
54 help=
"If this is present, but not --dt, CSC chambers only will be considered",
59 options, args = parser.parse_args(sys.argv[5:])
61 theInXML0 = sys.argv[1]
62 theInXMLN = sys.argv[2]
63 theInREPN = sys.argv[3]
64 theOutXML = sys.argv[4]
66 theNSigma = options.nsigma
70 if options.dt
or not ( options.dt
or options.csc):
72 if options.csc
or not ( options.dt
or options.csc):
76 if not os.access(theInXML0,os.F_OK):
print(theInXML0,
"not found!\n")
77 if not os.access(theInXMLN,os.F_OK):
print(theInXMLN,
"not found!\n")
78 if not os.access(theInREPN,os.F_OK):
print(theInREPN,
"not found!\n")
79 if not (os.access(theInXML0,os.F_OK)
and os.access(theInXMLN,os.F_OK)
and os.access(theInREPN,os.F_OK)):
83 geom0 = MuonGeometry(
file(theInXML0))
84 geomN = MuonGeometry(
file(theInXMLN))
93 keys = geom0.dt.keys()
95 elif muSystem ==
"CSC":
96 keys = geom0.csc.keys()
100 nkeys, nkeysr, nkeyspass, nmoved, nnotmoved = 0,0,0,0,0
101 nfail_toideal, nfail_deltafinal, nfail_lowstat, nfail_nsigma = 0,0,0,0
102 nok_toideal, nok_deltafinal, nok_lowstat, nok_nsigma = 0,0,0,0
107 if len(key) != 3: is_ch =
False
111 ch_g1 = geom0.dt[ch_key]
112 ch_g2 = geomN.dt[ch_key]
114 if len(key) != 4: is_ch =
False
118 ch_g1 = geom0.csc[ch_key]
119 ch_g2 = geomN.csc[ch_key]
123 if ch_key
in movedChamberKeys:
126 if g1.relativeto != g2.relativeto:
127 print(
"%s %s relativeto=\"%s\" versus relativeto=\"%s\"" % (muSystem,
str(key), g1.relativeto, g2.relativeto))
132 if r.postal_address[1:] == ch_key:
137 if is_ch:
print(muSystem,
str(key),
"not found in the report. Continue...")
141 if rep.status !=
"PASS":
142 if is_ch:
print(muSystem,
str(key),
"status is not PASS: %s Continue..." % rep.status)
145 if is_ch: nkeyspass+=1
152 if muSystem ==
"DT" and chWasntMoved:
155 if abs(ch_g2.x) > 2.
or abs(ch_g2.y) > 2.
or abs(ch_g2.phiy) > 0.02
or abs(ch_g2.phiz) > 0.02:
159 print(
"Warning!!!", muSystem,
str(key), \
160 "moved too much with respect to ideal: dx=%.2f mm dy=%.2f mm dphiy=%.2f mrad dphiz=%.2f mrad skipping..." % (ch_g2.x*10, ch_g2.y*10, ch_g2.phiy*1000, ch_g2.phiz*1000))
161 if is_ch
and ok: nok_toideal +=1
166 if abs(rep.deltax.value) > 0.03
or abs(rep.deltay.value) > 0.03
or abs(rep.deltaphiy.value) > 0.0003
or abs(rep.deltaphiz.value) > 0.0006:
169 nfail_deltafinal += 1
170 print(
"Warning!!!", muSystem,
str(key), \
171 "moved too much at final iteration: dx=%.2f mm dy=%.2f mm dphiy=%.2f mrad dphiz=%.2f mrad skipping..." % \
172 (rep.deltax.value*10, rep.deltay.value*10, rep.deltaphiy.value*1000, rep.deltaphiz.value*1000))
174 if abs(rep.deltax.value) > 0.03
or abs(rep.deltaphiy.value) > 0.0003
or abs(rep.deltaphiz.value) > 0.0006:
177 nfail_deltafinal += 1
178 print(
"Warning!!!", muSystem,
str(key), \
179 "moved too much at final iteration: dx=%.2f mm dphiy=%.2f mrad dphiz=%.2f mrad skipping..." % \
180 (rep.deltax.value*10, rep.deltaphiy.value*1000, rep.deltaphiz.value*1000))
181 if is_ch
and ok: nok_deltafinal +=1
184 if rep.deltax.error > 0.5:
188 print(
"Warning!!!", muSystem,
str(key),
"low statistics chamber with too big dx.error = %.2f mm skipping..." % (rep.deltax.error*10.))
189 if is_ch
and ok: nok_lowstat +=1
194 if abs(ch_g1.x - ch_g2.x) < theNSigma * math.sqrt ( rep.deltax.error*rep.deltax.error + 0.02*0.02 ) :
198 print(muSystem,
str(key),
"not moved: xN-x0 = %.3f - %.3f = %.3f < %.3f mm" % \
199 ( ch_g2.x*10., ch_g1.x*10., (ch_g2.x-ch_g1.x)*10., theNSigma * math.sqrt ( rep.deltax.error*rep.deltax.error + 0.02*0.02 )*10.))
201 if ok: chWasntMoved =
False
203 if not ok
or chWasntMoved:
continue
208 movedChamberKeys.append(ch_key)
213 geom0.dt[key] = copy.copy(geomN.dt[key])
215 geom0.csc[key] = copy.copy(geomN.csc[key])
217 nnotmoved = nkeys - nmoved
218 nsig =
int(theNSigma)
220 %(muSystem)s REPORT for %(nsig)d sigma policy:
222 %(nkeys)d\t chambers in geometry
223 %(nkeysr)d\t chambers in report
224 %(nkeyspass)d\t have PASS status
225 %(nok_toideal)d\t pass big shift with respect to ideal check
226 %(nok_deltafinal)d\t pass big deltas during final iteration
227 %(nok_lowstat)d\t pass low statistics (or big deltax.error) check
230 %(nnotmoved)d\t chambers not moved
231 Numbers of chambers were not moved due to:
232 %(nfail_toideal)d\t big shift with respect to ideal
233 %(nfail_deltafinal)d\t big deltas during final iteration
234 %(nfail_lowstat)d\t low statistics (or big deltax.error)
235 %(nfail_nsigma)d\t |x_final - x_initial| < nsigma
241 geom0.xml(
file(theOutXML,
"w"))