6 from TrigConfMuctpi.XMLReader
import MioctGeometryXMLReader
9 from ROOT
import gROOT, gStyle, TH2F, TCanvas, TBox, TLegend, TArc, TLatex
24 2, 11, 7, 30, 51, 6, 38 ]
25 fillStyleMap2 = [ 3004, 3012, 3005, 3010 ]
39 geom = MioctGeometryXMLReader(filename)
46 outfn =
"ROILayout%s.pdf" % (
"2016" if is2016
else "2015")
53 c = TCanvas(
'c',
"MuCTPi Geometry %s" %
"2016" if is2016
else "2015",1400,950)
57 h =
TH2F(
"h",
"Muon Geometry %s" %
"2016" if is2016
else "2015",10,-2.6,2.6,10,-0.15,6.4)
68 text.SetTextSize(0.005)
73 secLabel.SetTextSize(0.008)
74 secLabel.SetTextFont(42)
75 secLabel.SetTextAlign(22)
77 leg = TLegend(0.7,0.1,0.9,0.4)
78 leg.SetEntrySeparation(0.05)
82 for colorIndex,MioctID
in enumerate(drawOrder):
83 MIOCT = geometry.getMIOCT(MioctID)
85 color = colorMap[colorIndex % len(colorMap)]
87 box.SetLineColor(color)
90 for Sector
in MIOCT.Sectors:
93 for ROI
in Sector.ROIs:
94 c1_x =
float(ROI[
"etamin"])
95 c1_y =
float(ROI[
"phimin"])
96 c2_x =
float(ROI[
"etamax"])
97 c2_y =
float(ROI[
"phimax"])
101 b = box.DrawBox(c1_x,c1_y,c2_x,c2_y)
102 text.DrawText( (c1_x + c2_x)/2, (c1_y + c2_y)/2 ,ROI[
"roiid"])
105 leg.AddEntry(b,
"Slot %s" % MIOCT[
"slot"],
"l")
106 if Sector[
"name"].startswith(
"B"):
107 if int(Sector[
"name"][1:])<32:
109 ypos = (ymin+ymax)/2 - 0.05
112 ypos = (ymin+ymax)/2 + 0.03
113 secLabel.DrawText(xpos,ypos,Sector[
"name"])
124 outfn =
"TopoLayout%s.pdf" % (
"2016" if is2016
else "2015")
131 c = TCanvas(
'c',
"MuCTPi to Topo Geometry",1400,950)
134 h =
TH2F(
"h",
"Muon Topo Geometry %s" %
"2016" if is2016
else "2015",10,-2.6,2.6,10,-0.15,6.4)
145 for colorIndex,MioctID
in enumerate(drawOrder):
146 MIOCT = geometry.getMIOCT(MioctID)
147 color = colorMap[colorIndex % len(colorMap)]
148 box.SetLineColor(color)
149 box.SetFillColor(color)
151 circle.SetLineColor(color)
152 circle.SetFillColor(color)
155 for cellIdx,TopoCell
in enumerate(MIOCT.Decode.TopoCells):
157 c1_x =
float(TopoCell[
"etamin"])
158 c1_y =
float(TopoCell[
"phimin"])
160 c2_x =
float(TopoCell[
"etamax"])
161 c2_y =
float(TopoCell[
"phimax"])
163 c_x =
float(TopoCell[
"ieta"])
164 c_y =
float(TopoCell[
"iphi"])
172 box.SetFillStyle(fillStyle)
173 box.DrawBox(c1_x,c1_y,c2_x,c2_y)
175 box.DrawBox(c1_x,c1_y,c2_x,c2_y)
177 circle.DrawArc(c_x/10.,c_y/10.,0.02)
191 if colorBy<ETACODE
or colorBy>IPHI:
194 global box, c, h, leg
199 c = TCanvas(
'c',
"MuCTPi to Topo Geometry",1400,950)
202 h =
TH2F(
"h",
"Muon Topo Geometry %i" % (2016
if is2016
else 2015),10,-2.6,2.6,10,-0.15,6.4)
214 leg = TLegend(0.9,0.1,0.98,0.9)
216 leg = TLegend(0.8,0.1,0.9,0.35)
222 for MioctID
in drawOrder:
224 MIOCT = geometry.getMIOCT(MioctID)
227 for cellIdx,TopoCell
in enumerate(MIOCT.Decode.TopoCells):
230 code =
int(TopoCell[
"etacode"],16)
231 elif colorBy==PHICODE:
232 code =
int(TopoCell[
"phicode"],16)
234 code = abs(
int(TopoCell[
"ieta"]))
236 code =
int(TopoCell[
"iphi"])
238 raise RuntimeError(
"Don't know how to color the eta-phi map (%r)" % colorBy)
239 color = colorMap2[code % len(colorMap2)]
240 fillStyle = fillStyleMap2[code % 4]
241 box.SetLineColor(color)
242 box.SetFillColor(color)
244 circle.SetLineColor(color)
245 circle.SetFillColor(color)
248 c1_x =
float(TopoCell[
"etamin"])
249 c1_y =
float(TopoCell[
"phimin"])
251 c2_x =
float(TopoCell[
"etamax"])
252 c2_y =
float(TopoCell[
"phimax"])
254 c_x =
float(TopoCell[
"ieta"])
255 c_y =
float(TopoCell[
"iphi"])
261 box.SetFillStyle(fillStyle)
262 b = box.DrawBox(c1_x,c1_y,c2_x,c2_y)
264 box.DrawBox(c1_x,c1_y,c2_x,c2_y)
266 circle.DrawArc(c_x/10.,c_y/10.,0.02)
269 if code
not in codeInLegend:
270 codeInLegend += [code]
272 leg.AddEntry(b,
"etacode %i" % code,
"lf")
273 elif colorBy==PHICODE:
274 leg.AddEntry(b,
"phicode %i" % code,
"f")
276 leg.AddEntry(b,
"|ieta| %i" % code,
"f")
278 leg.AddEntry(b,
"iphi %i" % code,
"f")
285 elif colorBy==PHICODE:
293 c.SaveAs(
"TopoLayout%s%s.pdf" % (
"2016" if is2016
else "2015", ext))
304 c = TCanvas(
'c',
"Topo encoding",1400,950)
307 h =
TH2F(
"h",
"Muon Topo encoding %i" % (2016
if is2016
else 2015),8,0,8,8,0,8)
312 for MioctID
in drawOrder:
314 MIOCT = geometry.getMIOCT(MioctID)
315 for tc
in MIOCT.Decode.TopoCells:
316 h.Fill(
int(tc[
'etacode'],16),
int(tc[
'phicode'],16))
320 c.SaveAs(
"TopoCodes%s.pdf" %
"2016" if is2016
else "2015")
330 c = TCanvas(
'c',
"Topo encoding",1400,950)
333 h =
TH2F(
"h",
"Muon Topo encoding %i" % (2016
if is2016
else 2015),48,-24,24,64,0,64)
334 h.SetXTitle(
"#eta_{index}")
335 h.SetYTitle(
"#phi_{index}")
338 for MioctID
in drawOrder:
339 MIOCT = geometry.getMIOCT(MioctID)
340 for tc
in MIOCT.Decode.TopoCells:
341 h.Fill(
int(tc[
'ieta'])+0.5,
int(tc[
'iphi'])+0.5)
345 c.SaveAs(
"TopoCellCenters%s.pdf" %
"2016" if is2016
else "2015")
351 def getTopoCell(mioct, etacode, phicode):
354 mioctid = mioct[
'id']
355 if mioctid
not in mioctTCmap:
357 for tc
in mioct.Decode.TopoCells:
358 key = (
int(tc[
'etacode'],16),
int(tc[
'phicode'],16))
360 mioctTCmap[mioctid] = d
361 return mioctTCmap[mioctid][(etacode,phicode)]
368 c = TCanvas(
'c',
"Topo encoding",1400,950)
372 hB =
TH2F(
"hb",
"Delta R between ROI and TopoCell %i in Barrel" % (2016
if is2016
else 2015),64,0,64,32,0,32)
374 hB.SetYTitle(
"ROI ID")
376 hEC =
TH2F(
"hec",
"Delta R between ROI and TopoCell %i in Endcap" % (2016
if is2016
else 2015),96,0,96,148,0,148)
378 hEC.SetYTitle(
"ROI ID")
380 hFW =
TH2F(
"hfw",
"Delta R between ROI and TopoCell %i in Forward" % (2016
if is2016
else 2015),48,0,48,64,0,64)
382 hFW.SetYTitle(
"ROI ID")
384 for MioctID
in drawOrder:
385 mioct = geometry.getMIOCT(MioctID)
387 for sector
in mioct.Sectors:
388 for roi
in sector.ROIs:
389 tc = getTopoCell(mioct,
int(roi[
'etacode'],16),
int(roi[
'phicode'],16))
390 deltaEta =
float(roi[
'eta'])-
float(tc[
'ieta'])/10.
391 deltaPhi =
float(roi[
'phi'])-
float(tc[
'iphi'])/10.
393 deltaPhi -= 2*math.pi
394 deltaR = math.sqrt(deltaEta*deltaEta+deltaPhi*deltaPhi)
395 sectorid =
int(sector[
'name'].lstrip(
'ABCDEF'))
396 roiid =
int(roi[
'roiid'])
397 if sector[
'name'].startswith(
'B'):
398 hB.Fill(sectorid,roiid,deltaR)
399 elif sector[
'name'].startswith(
'E'):
400 if sector[
'name'].startswith(
'EA'):
402 hEC.Fill(sectorid,roiid,deltaR)
403 elif sector[
'name'].startswith(
'F'):
404 if sector[
'name'].startswith(
'FA'):
406 hFW.Fill(sectorid,roiid,deltaR)
416 c.SaveAs(
"ROIDeltaR%s.pdf" %
"2016" if is2016
else "2015")
422 parser = argparse.ArgumentParser( description=__doc__,
423 formatter_class = argparse.RawTextHelpFormatter)
425 parser.add_argument(
'-i', dest=
'filename', default=
"TrigConfMuctpi/TestMioctGeometry2016.xml", type=str,
426 help=
'name of muon geometry xml file')
428 args = parser.parse_args()
430 is2016 =
'2016' in args.filename
432 print(
"Using input %s" % args.filename)
434 geometry =
readXML(args.filename)
455 input(
"Press Enter to continue...")
458 if __name__==
"__main__":