6 from TrigConfMuctpi.XMLReader
import MioctGeometryXMLReader
22 2, 11, 7, 30, 51, 6, 38 ]
23 fillStyleMap2 = [ 3004, 3012, 3005, 3010 ]
37 geom = MioctGeometryXMLReader(filename)
44 outfn =
"ROILayout%s.pdf" % (
"2016" if is2016
else "2015")
51 c = TCanvas(
'c',
"MuCTPi Geometry %s" %
"2016" if is2016
else "2015",1400,950)
55 h =
TH2F(
"h",
"Muon Geometry %s" %
"2016" if is2016
else "2015",10,-2.6,2.6,10,-0.15,6.4)
66 text.SetTextSize(0.005)
71 secLabel.SetTextSize(0.008)
72 secLabel.SetTextFont(42)
73 secLabel.SetTextAlign(22)
75 leg = TLegend(0.7,0.1,0.9,0.4)
76 leg.SetEntrySeparation(0.05)
80 for colorIndex,MioctID
in enumerate(drawOrder):
81 MIOCT = geometry.getMIOCT(MioctID)
83 color = colorMap[colorIndex % len(colorMap)]
85 box.SetLineColor(color)
88 for Sector
in MIOCT.Sectors:
91 for ROI
in Sector.ROIs:
92 c1_x =
float(ROI[
"etamin"])
93 c1_y =
float(ROI[
"phimin"])
94 c2_x =
float(ROI[
"etamax"])
95 c2_y =
float(ROI[
"phimax"])
99 b = box.DrawBox(c1_x,c1_y,c2_x,c2_y)
100 text.DrawText( (c1_x + c2_x)/2, (c1_y + c2_y)/2 ,ROI[
"roiid"])
103 leg.AddEntry(b,
"Slot %s" % MIOCT[
"slot"],
"l")
104 if Sector[
"name"].startswith(
"B"):
105 if int(Sector[
"name"][1:])<32:
107 ypos = (ymin+ymax)/2 - 0.05
110 ypos = (ymin+ymax)/2 + 0.03
111 secLabel.DrawText(xpos,ypos,Sector[
"name"])
122 outfn =
"TopoLayout%s.pdf" % (
"2016" if is2016
else "2015")
124 global box, c, h, leg
129 c = TCanvas(
'c',
"MuCTPi to Topo Geometry",1400,950)
132 h =
TH2F(
"h",
"Muon Topo Geometry %s" %
"2016" if is2016
else "2015",10,-2.6,2.6,10,-0.15,6.4)
143 for colorIndex,MioctID
in enumerate(drawOrder):
144 MIOCT = geometry.getMIOCT(MioctID)
145 color = colorMap[colorIndex % len(colorMap)]
146 box.SetLineColor(color)
147 box.SetFillColor(color)
149 circle.SetLineColor(color)
150 circle.SetFillColor(color)
153 for cellIdx,TopoCell
in enumerate(MIOCT.Decode.TopoCells):
155 c1_x =
float(TopoCell[
"etamin"])
156 c1_y =
float(TopoCell[
"phimin"])
158 c2_x =
float(TopoCell[
"etamax"])
159 c2_y =
float(TopoCell[
"phimax"])
161 c_x =
float(TopoCell[
"ieta"])
162 c_y =
float(TopoCell[
"iphi"])
170 box.SetFillStyle(fillStyle)
171 box.DrawBox(c1_x,c1_y,c2_x,c2_y)
173 box.DrawBox(c1_x,c1_y,c2_x,c2_y)
175 circle.DrawArc(c_x/10.,c_y/10.,0.02)
189 if colorBy<ETACODE
or colorBy>IPHI:
192 global box, c, h, leg
197 c = TCanvas(
'c',
"MuCTPi to Topo Geometry",1400,950)
200 h =
TH2F(
"h",
"Muon Topo Geometry %i" % (2016
if is2016
else 2015),10,-2.6,2.6,10,-0.15,6.4)
212 leg = TLegend(0.9,0.1,0.98,0.9)
214 leg = TLegend(0.8,0.1,0.9,0.35)
220 for MioctID
in drawOrder:
222 MIOCT = geometry.getMIOCT(MioctID)
225 for cellIdx,TopoCell
in enumerate(MIOCT.Decode.TopoCells):
228 code =
int(TopoCell[
"etacode"],16)
229 elif colorBy==PHICODE:
230 code =
int(TopoCell[
"phicode"],16)
232 code = abs(
int(TopoCell[
"ieta"]))
234 code =
int(TopoCell[
"iphi"])
236 raise RuntimeError(
"Don't know how to color the eta-phi map (%r)" % colorBy)
237 color = colorMap2[code % len(colorMap2)]
238 fillStyle = fillStyleMap2[code % 4]
239 box.SetLineColor(color)
240 box.SetFillColor(color)
242 circle.SetLineColor(color)
243 circle.SetFillColor(color)
246 c1_x =
float(TopoCell[
"etamin"])
247 c1_y =
float(TopoCell[
"phimin"])
249 c2_x =
float(TopoCell[
"etamax"])
250 c2_y =
float(TopoCell[
"phimax"])
252 c_x =
float(TopoCell[
"ieta"])
253 c_y =
float(TopoCell[
"iphi"])
259 box.SetFillStyle(fillStyle)
260 b = box.DrawBox(c1_x,c1_y,c2_x,c2_y)
262 box.DrawBox(c1_x,c1_y,c2_x,c2_y)
264 circle.DrawArc(c_x/10.,c_y/10.,0.02)
267 if code
not in codeInLegend:
268 codeInLegend += [code]
270 leg.AddEntry(b,
"etacode %i" % code,
"lf")
271 elif colorBy==PHICODE:
272 leg.AddEntry(b,
"phicode %i" % code,
"f")
274 leg.AddEntry(b,
"|ieta| %i" % code,
"f")
276 leg.AddEntry(b,
"iphi %i" % code,
"f")
283 elif colorBy==PHICODE:
291 c.SaveAs(
"TopoLayout%s%s.pdf" % (
"2016" if is2016
else "2015", ext))
302 c = TCanvas(
'c',
"Topo encoding",1400,950)
305 h =
TH2F(
"h",
"Muon Topo encoding %i" % (2016
if is2016
else 2015),8,0,8,8,0,8)
310 for MioctID
in drawOrder:
312 MIOCT = geometry.getMIOCT(MioctID)
313 for tc
in MIOCT.Decode.TopoCells:
314 h.Fill(
int(tc[
'etacode'],16),
int(tc[
'phicode'],16))
318 c.SaveAs(
"TopoCodes%s.pdf" %
"2016" if is2016
else "2015")
328 c = TCanvas(
'c',
"Topo encoding",1400,950)
331 h =
TH2F(
"h",
"Muon Topo encoding %i" % (2016
if is2016
else 2015),48,-24,24,64,0,64)
332 h.SetXTitle(
"#eta_{index}")
333 h.SetYTitle(
"#phi_{index}")
336 for MioctID
in drawOrder:
337 MIOCT = geometry.getMIOCT(MioctID)
338 for tc
in MIOCT.Decode.TopoCells:
339 h.Fill(
int(tc[
'ieta'])+0.5,
int(tc[
'iphi'])+0.5)
343 c.SaveAs(
"TopoCellCenters%s.pdf" %
"2016" if is2016
else "2015")
349 def getTopoCell(mioct, etacode, phicode):
352 mioctid = mioct[
'id']
353 if mioctid
not in mioctTCmap:
355 for tc
in mioct.Decode.TopoCells:
356 key = (
int(tc[
'etacode'],16),
int(tc[
'phicode'],16))
358 mioctTCmap[mioctid] = d
359 return mioctTCmap[mioctid][(etacode,phicode)]
361 global h,c,hB,hEC,hFW
366 c = TCanvas(
'c',
"Topo encoding",1400,950)
370 hB =
TH2F(
"hb",
"Delta R between ROI and TopoCell %i in Barrel" % (2016
if is2016
else 2015),64,0,64,32,0,32)
372 hB.SetYTitle(
"ROI ID")
374 hEC =
TH2F(
"hec",
"Delta R between ROI and TopoCell %i in Endcap" % (2016
if is2016
else 2015),96,0,96,148,0,148)
376 hEC.SetYTitle(
"ROI ID")
378 hFW =
TH2F(
"hfw",
"Delta R between ROI and TopoCell %i in Forward" % (2016
if is2016
else 2015),48,0,48,64,0,64)
380 hFW.SetYTitle(
"ROI ID")
382 for MioctID
in drawOrder:
383 mioct = geometry.getMIOCT(MioctID)
385 for sector
in mioct.Sectors:
386 for roi
in sector.ROIs:
387 tc = getTopoCell(mioct,
int(roi[
'etacode'],16),
int(roi[
'phicode'],16))
388 deltaEta =
float(roi[
'eta'])-
float(tc[
'ieta'])/10.
389 deltaPhi =
float(roi[
'phi'])-
float(tc[
'iphi'])/10.
391 deltaPhi -= 2*math.pi
392 deltaR = math.sqrt(deltaEta*deltaEta+deltaPhi*deltaPhi)
393 sectorid =
int(sector[
'name'].lstrip(
'ABCDEF'))
394 roiid =
int(roi[
'roiid'])
395 if sector[
'name'].startswith(
'B'):
396 hB.Fill(sectorid,roiid,deltaR)
397 elif sector[
'name'].startswith(
'E'):
398 if sector[
'name'].startswith(
'EA'):
400 hEC.Fill(sectorid,roiid,deltaR)
401 elif sector[
'name'].startswith(
'F'):
402 if sector[
'name'].startswith(
'FA'):
404 hFW.Fill(sectorid,roiid,deltaR)
414 c.SaveAs(
"ROIDeltaR%s.pdf" %
"2016" if is2016
else "2015")
420 parser = argparse.ArgumentParser( description=__doc__,
421 formatter_class = argparse.RawTextHelpFormatter)
423 parser.add_argument(
'-i', dest=
'filename', default=
"TrigConfMuctpi/TestMioctGeometry2016.xml", type=str,
424 help=
'name of muon geometry xml file')
426 args = parser.parse_args()
428 is2016 =
'2016' in args.filename
430 print(
"Using input %s" % args.filename)
432 geometry =
readXML(args.filename)
434 from ROOT
import gROOT, gStyle, TH2F, TCanvas, TBox, TLegend, TArc, TLatex
435 global gROOT, gStyle, TH2F, TCanvas, TBox, TLegend, TArc, TLatex
456 input(
"Press Enter to continue...")
459 if __name__==
"__main__":