def drawTopoGeometry(geometry, is2016): outfn = "TopoLayout%s.pdf" % ("2016" if is2016 else "2015") global box, c, h, leg gROOT.Reset() gStyle.SetOptStat(0) c = TCanvas('c', "MuCTPi to Topo Geometry", 1400, 950) c.Draw() h = TH2F("h", "Muon Topo Geometry %s" % "2016" if is2016 else "2015", 10, -2.6, 2.6, 10, -0.15, 6.4) h.SetXTitle("#eta") h.SetYTitle("#phi") h.Draw() box = TBox() box.SetFillStyle(0) box.SetLineColor(3) circle = TArc() for colorIndex, MioctID in enumerate(drawOrder): MIOCT = geometry.getMIOCT(MioctID) color = colorMap[colorIndex % len(colorMap)] box.SetLineColor(color) box.SetFillColor(color) circle.SetLineColor(color) circle.SetFillColor(color) fillStyle = 3004 for cellIdx, TopoCell in enumerate(MIOCT.Decode.TopoCells): # corner 1 c1_x = float(TopoCell["etamin"]) c1_y = float(TopoCell["phimin"]) # corner 2 c2_x = float(TopoCell["etamax"]) c2_y = float(TopoCell["phimax"]) # center rounded c_x = float(TopoCell["ieta"]) c_y = float(TopoCell["iphi"]) #print "cell %i : eta [%f - %f], phi [%f - %f]" % (cellIdx, c1_x, c2_x, c1_y, c2_y) if fillStyle == 3004: fillStyle = 3012 else: fillStyle = 3004 box.SetFillStyle(fillStyle) box.DrawBox(c1_x, c1_y, c2_x, c2_y) box.SetFillStyle(0) box.DrawBox(c1_x, c1_y, c2_x, c2_y) circle.DrawArc(c_x / 10., c_y / 10., 0.02) c.Update() c.SaveAs(outfn)
mesg='nll: {0}, minNLL= {1}'.format(nll.getVal(),fitres.minNll()) recTime(mesg) var.setConstant(False) nll_scan.SetStats(False) nll_scan.SetLineWidth(2) nll_scan.GetXaxis().SetTitle(varInfo['var']) nll_profscan.Draw('axis') canv.Update() box=TBox() box.SetFillColor(7) bestVal=fitres.floatParsFinal().find(varInfo['var']) box.DrawBox( bestVal.getVal()+bestVal.getErrorLo(),canv.GetUymin(), bestVal.getVal()+bestVal.getErrorHi(),canv.GetUymax() ) nll_scan.Draw('csame') nll_profscan.SetLineWidth(2) nll_profscan.SetLineColor(2) nll_profscan.Draw('csame') outFile.cd() nll_scan.Write() nll_profscan.Write() canv.SaveAs(tMPfIG) SimpleSaveToFile( dir=figDir, object=nll_profscan,
def drawColorTable(clist=range(0, 50), nrow=None, ncol=None, cmax=10, tag="", label=False, RBG=False, newRBG=True, div=2): # https://root.cern.ch/doc/master/src_2TPad_8cxx_source.html#l01611 if not ncol: ncol = min(cmax, len(clist)) if not nrow: nrow = 1 if len(clist) <= cmax else int(ceil(len(clist) / float(cmax))) x1 = y1 = 0. x2 = y2 = 20. hs = (y2 - y1) / nrow ws = (x2 - x1) / ncol if label or RBG: width = 170 * ncol height = 80 * nrow else: width = 110 * ncol height = 80 * nrow scale = 400. / height if 400. < height: scale = sqrt(scale) canvas = TCanvas("c", "Fill Area colors", 0, 0, width, height) canvas.SetFillColor(0) canvas.Clear() canvas.Range(x1, y1, x2, y2) text = TText(0, 0, "") text.SetTextFont(61) text.SetTextSize(0.07 * scale) text.SetTextAlign(22) box = TBox() for r in range(0, nrow): ylow = y2 - hs * (r + 0.1) yup = y2 - hs * (r + 0.9) for c in range(0, ncol): i = ncol * r + c if i >= len(clist): break xlow = x1 + ws * (c + 0.1) xup = x1 + ws * (c + 0.9) color = clist[ncol * r + c] box.SetFillStyle(1001) box.SetFillColor(color) box.DrawBox(xlow, ylow, xup, yup) box.SetFillStyle(0) box.SetLineColor(1) box.DrawBox(xlow, ylow, xup, yup) if color == 1: text.SetTextColor(0) else: text.SetTextColor(1) name = "%d" % color if (isinstance(label, int) and i % div == label) or label: name = getColorString(color) if (not isinstance(RBG, bool) and isinstance(RBG, int) and i % div == RBG) or (RBG and not isinstance(label, int)): name = getRGBString(color) elif newRBG and color >= 924: name = getRGBString(color) text.DrawText(0.5 * (xlow + xup), 0.5 * (ylow + yup), name) if i >= len(clist): break canvas.SaveAs("TColorTable%s.png" % tag) canvas.SaveAs("TColorTable%s.pdf" % tag)
def main(): if True: mf=TGMainFrame(gClient.GetRoot(),1500,475) gvf=TGVerticalFrame(mf,1500,475) rec=TRootEmbeddedCanvas("ccc",gvf,1500,450) rec2=TRootEmbeddedCanvas("ccc2",gvf,1500,25) gvf.AddFrame(rec,TGLayoutHints(ROOT.kLHintsExpandX|ROOT.kLHintsTop)) gvf.AddFrame(rec2,TGLayoutHints(ROOT.kLHintsExpandX|ROOT.kLHintsBottom)) mf.AddFrame(gvf,TGLayoutHints(ROOT.kLHintsExpandX)) cc=rec.GetCanvas() cc2=rec2.GetCanvas() mf.SetEditable(0) mf.SetWindowName('HPS ECAL FADC SCALERS') mf.MapSubwindows() mf.Resize(1501,476)# resize to get proper frame placement mf.MapWindow() else: cc=TCanvas('cc','',1500,450) cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(11) hh=TH2D('hh',';X;Y',46,-22,24,11,-5,6) hi=TH2I('hi',';X;Y',46,-22,24,11,-5,6) setupHists([hh,hi]) xax,yax=hh.GetXaxis(),hh.GetYaxis() hh.Draw('COLZ') hi.Draw('TEXTSAME') gPad.SetLogz() gPad.SetGrid(1,1) gPad.SetLeftMargin(0.05) tt1=TPaveText(0.1,0.9,0.3,1.0,'NDC') tt2=TPaveText(0.7,0.91,0.9,0.99,'NDC') ttT=TPaveText(-22+13+0.05,6-5,-22+22,7-5-0.05) ttB=TPaveText(-22+13+0.05,4-5+0.05,-22+22,5-5) ttM=TPaveText(-22+0+0.05,5-5+0.05,-22+13,6-5.01) ttime=TPaveText(-10,-6.5,10,-5.8) tchan=TPaveText(0,0,0.9,1) setupPaveTexts([tt1,tt2,ttT,ttB,ttM,ttime,tchan]) ttM.SetTextColor(2) bb=TBox() bb.SetFillStyle(1001) bb.SetFillColor(0) bb.SetLineWidth(1) bb.SetLineColor(1) bb.DrawBox(-9+0.05,-1,0,1.97) bb.DrawBox(-24,0,24.05,0.97) tarrow=TText(14.5,0.3,'Beam Left') arrow=TArrow(19,0.5,23,0.5,0.02,'|>') arrow.SetAngle(40) arrow.SetFillColor(1) arrow.SetLineWidth(2) tt=TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.08) tt.DrawText(25.4,0,'kHz') tt.SetTextAngle(0) tt.SetTextColor(2) tt.DrawTextNDC(0.3,0.92,'ECAL FADC SCALERS') cc.cd() for xx in [tt2,ttT,ttB,ttM,arrow,tarrow,ttime]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() ll=TLine() ll.DrawLine(xax.GetXmin(),yax.GetXmin(),xax.GetXmax(),yax.GetXmin()) ll.DrawLine(xax.GetXmin(),yax.GetXmax(),xax.GetXmax(),yax.GetXmax()) ll.DrawLine(xax.GetXmin(),yax.GetXmin(),xax.GetXmin(),0) ll.DrawLine(xax.GetXmax(),yax.GetXmin(),xax.GetXmax(),0) ll.DrawLine(xax.GetXmin(),yax.GetXmax(),xax.GetXmin(),1) ll.DrawLine(xax.GetXmax(),yax.GetXmax(),xax.GetXmax(),1) ll.DrawLine(xax.GetXmax(),0,0,0) ll.DrawLine(xax.GetXmax(),1,0,1) ll.DrawLine(xax.GetXmin(),0,-9,0) ll.DrawLine(xax.GetXmin(),1,-9,1) ll.DrawLine(-9,-1,0,-1) ll.DrawLine(-9,2,0,2) ll.DrawLine(-9,1,-9,2) ll.DrawLine(-9,-1,-9,0) ll.DrawLine(0,-1,0,0) ll.DrawLine(0,1,0,2) gPad.SetEditable(0) while True: # try: zvals=getPVS() for ii in range(len(zvals)): hh.SetBinContent(xax.FindBin(XVALS[ii]),yax.FindBin(YVALS[ii]),zvals[ii]) hi.SetBinContent(xax.FindBin(XVALS[ii]),yax.FindBin(YVALS[ii]),zvals[ii]) for xx in [ttime,tt2,ttT,ttB,ttM]: xx.Clear() [top,bottom,maximum]=calcRates(zvals) tt2.AddText('Total: %.1f MHz'%((top+bottom)/1000)) ttT.AddText('%.1f MHz'%(top/1000)) ttB.AddText('%.1f MHz'%(bottom/1000)) ttM.AddText('MAX SINGLE CRYSTAL = %.0f kHz'%(maximum)) ttime.AddText(makeTime()) if gPad.GetEvent()==11: xy=pix2xy(gPad) ee=ECAL.findChannelXY(xy[0],xy[1]) if ee: tchan.Clear() tchan.AddText(printChannel(ee)) cc2.Modified() cc2.Update() elif gPad.GetEvent()==12: tchan.Clear() cc2.Modified() cc2.Update() cc.Modified() cc.Update() time.sleep(1)
def main(): cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(11) hh=TH2D('hh',';X;Y',22,-10.5,11.5,22,-10.5,11.5) hi=TH2I('hi',';X;Y',22,-10.5,11.5,22,-10.5,11.5) setupHists([hh,hi]) xax,yax=hh.GetXaxis(),hh.GetYaxis() hh.Draw('COLZ') hi.Draw('TEXTSAME') gPad.SetLogz() gPad.SetGrid(1,1) gPad.SetLeftMargin(0.09) gPad.SetRightMargin(0.11) #tt2=TPaveText(0.7,0.96,0.9,0.99,'NDC') ttM=TPaveText(-3+0.05, 7-4.45, 4.0, 8-4.51) tt2=TPaveText(-3+0.05, 7-5.45, 4.0, 8-5.51) ttX=TPaveText(-2, 7-8.00, 3, 8-8.00) ttY=TPaveText(-2, 7-9.00, 3, 8-9.00) ttZ=TPaveText(-2, 6-8.80, 3, 8-9.30) ttZ.AddText("positive = beam top/right") ttime=TPaveText(-10,-12.5,10,-11.8) tchan=TPaveText(0,0,0.9,1) setupPaveTexts([tt2,ttM,ttime,tchan,ttX,ttY,ttZ]) ttM.SetTextColor(2) ttM.SetFillStyle(0) ttZ.SetFillStyle(0) tt2.SetFillStyle(0) tarrow=TText(-0.9,0.7,'Beam Right') tarrow.SetTextSizePixels(15) arrow=TArrow(-1.4,0.5,2.4,0.5,0.02,'|>') arrow.SetAngle(40) arrow.SetFillColor(1) arrow.SetLineWidth(2) tt=TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.04) tt.DrawText(12.4,0,'kHz') tt.SetTextAngle(0) tt.SetTextColor(1) tt.DrawTextNDC(0.3,0.92,'FTC FADC SCALERS') bb=TBox() bb.SetFillStyle(1001) bb.SetFillColor(0) bb.SetLineWidth(1) bb.SetLineColor(1) bb.DrawBox(-3.47,-1.47,4.47,2.46) bb.DrawBox(-1.47,-3.47,2.49,4.47) bb.DrawBox(-2.47,-2.47,3.49,3.47) cc.cd() for xx in [ttM,tt2,ttime,arrow,tarrow,ttX,ttY,ttZ]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() gPad.SetEditable(0) while True: for ch in ECAL.chans: loadPV(ch) ch=ch.vals xx,yy=ch['X'],ch['Y'] #if (ch['PVVAL']>10): # print xx,yy,ch['PVVAL'] # swap x to make it downstream view: xx=-xx #after, fix the fact x=0 / y=0 don't exists if xx<0: xx+=1 if yy<0: yy+=1 hh.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL']) hi.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL']) for xx in [ttime,tt2,ttM,ttX,ttY]: xx.Clear() [total,maximum,top,bottom,left,right]=calcRates(ECAL.chans) tt2.AddText('Total: %.1f MHz'%(total/1000)) ttM.AddText('Max: %.0f kHz'%(maximum)) if total>1e2: xasy = (right-left)/total yasy = (top-bottom)/total ttX.AddText('X-Asy: %+.1f%%'%(100*xasy)) ttY.AddText('Y-Asy: %+.1f%%'%(100*yasy)) else: ttX.AddText('X-Asy: N/A') ttY.AddText('Y-Asy: N/A') ttime.AddText(makeTime()) if not gPad: sys.exit() if gPad.GetEvent()==11: xy=pix2xy(gPad) ee=ECAL.findChannelXY(xy[0],xy[1]) if ee: tchan.Clear() tchan.AddText(printChannel(ee)) cc2.Modified() cc2.Update() elif gPad.GetEvent()==12: tchan.Clear() cc2.Modified() cc2.Update() cc.Modified() cc.Update() time.sleep(2)
def drawROIGeometry(geometry, is2016): outfn = "ROILayout%s.pdf" % ("2016" if is2016 else "2015") global box, c, h, leg gROOT.Reset() gStyle.SetOptStat(0) c = TCanvas('c', "MuCTPi Geometry %s" % "2016" if is2016 else "2015", 1400, 950) c.Draw() #h = TH2F("h","Muon Geometry",10,-2.6,2.6,10,-6.4,6.4) h = TH2F("h", "Muon Geometry %s" % "2016" if is2016 else "2015", 10, -2.6, 2.6, 10, -0.15, 6.4) h.SetXTitle("#eta") h.SetYTitle("#phi") h.Draw() box = TBox() box.SetFillStyle(0) box.SetLineColor(3) box.SetLineColor(3) text = TLatex() text.SetTextSize(0.005) text.SetTextFont(42) text.SetTextAlign(22) secLabel = TLatex() secLabel.SetTextSize(0.008) secLabel.SetTextFont(42) secLabel.SetTextAlign(22) leg = TLegend(0.7, 0.1, 0.9, 0.4) leg.SetEntrySeparation(0.05) leg.SetNColumns(2) #for MIOCT in geometry.getMIOCTs(): for colorIndex, MioctID in enumerate(drawOrder): MIOCT = geometry.getMIOCT(MioctID) firstBox = True color = colorMap[colorIndex % len(colorMap)] #print "Using color ",color box.SetLineColor(color) box.SetLineWidth(1) for Sector in MIOCT.Sectors: ymin = 10 ymax = -10 for ROI in Sector.ROIs: c1_x = float(ROI["etamin"]) c1_y = float(ROI["phimin"]) c2_x = float(ROI["etamax"]) c2_y = float(ROI["phimax"]) ymin = min(ymin, c1_y) ymax = max(ymax, c2_y) #print "eta [%f - %f], phi [%f - %f]" % (c1_x,c2_x,c1_y,c2_y) b = box.DrawBox(c1_x, c1_y, c2_x, c2_y) text.DrawText((c1_x + c2_x) / 2, (c1_y + c2_y) / 2, ROI["roiid"]) if firstBox: firstBox = False leg.AddEntry(b, "Slot %s" % MIOCT["slot"], "l") if Sector["name"].startswith("B"): if int(Sector["name"][1:]) < 32: xpos = -0.02 ypos = (ymin + ymax) / 2 - 0.05 else: xpos = 0.02 ypos = (ymin + ymax) / 2 + 0.03 secLabel.DrawText(xpos, ypos, Sector["name"]) leg.Draw() c.Update() c.SaveAs(outfn)
def drawTopoGeometryEtaPhi(geometry, colorBy, is2016): if colorBy < ETACODE or colorBy > IPHI: return global box, c, h, leg gROOT.Reset() gStyle.SetOptStat(0) c = TCanvas('c', "MuCTPi to Topo Geometry", 1400, 950) c.Draw() h = TH2F("h", "Muon Topo Geometry %i" % (2016 if is2016 else 2015), 10, -2.6, 2.6, 10, -0.15, 6.4) h.SetXTitle("#eta") h.SetYTitle("#phi") h.Draw() box = TBox() box.SetFillStyle(0) box.SetLineColor(3) circle = TArc() if colorBy == IPHI: leg = TLegend(0.9, 0.1, 0.98, 0.9) else: leg = TLegend(0.8, 0.1, 0.9, 0.35) #leg.SetEntrySeparation(0.05) #leg.SetNColumns(2) codeInLegend = [] for MioctID in drawOrder: #for MioctID in [3,4,5,6,7]: MIOCT = geometry.getMIOCT(MioctID) fillStyle = 3004 for cellIdx, TopoCell in enumerate(MIOCT.Decode.TopoCells): if colorBy == ETACODE: code = int(TopoCell["etacode"], 16) elif colorBy == PHICODE: code = int(TopoCell["phicode"], 16) elif colorBy == IETA: code = abs(int(TopoCell["ieta"])) elif colorBy == IPHI: code = int(TopoCell["iphi"]) else: raise RuntimeError( "Don't know how to color the eta-phi map (%r)" % colorBy) color = colorMap2[code % len(colorMap2)] fillStyle = fillStyleMap2[code % 4] box.SetLineColor(color) box.SetFillColor(color) circle.SetLineColor(color) circle.SetFillColor(color) # corner 1 c1_x = float(TopoCell["etamin"]) c1_y = float(TopoCell["phimin"]) # corner 2 c2_x = float(TopoCell["etamax"]) c2_y = float(TopoCell["phimax"]) # center c_x = float(TopoCell["ieta"]) c_y = float(TopoCell["iphi"]) #if code>63: # continue #print "cell %i : eta [%f - %f], phi [%f - %f]" % (cellIdx, c1_x, c2_x, c1_y, c2_y) box.SetFillStyle(fillStyle) b = box.DrawBox(c1_x, c1_y, c2_x, c2_y) box.SetFillStyle(0) box.DrawBox(c1_x, c1_y, c2_x, c2_y) circle.DrawArc(c_x / 10., c_y / 10., 0.02) if not code in codeInLegend: codeInLegend += [code] if colorBy == ETACODE: leg.AddEntry(b, "etacode %i" % code, "lf") elif colorBy == PHICODE: leg.AddEntry(b, "phicode %i" % code, "f") elif colorBy == IETA: leg.AddEntry(b, "|ieta| %i" % code, "f") elif colorBy == IPHI: leg.AddEntry(b, "iphi %i" % code, "f") leg.Draw() c.Update() if colorBy == ETACODE: ext = "EtaCode" elif colorBy == PHICODE: ext = "PhiCode" elif colorBy == IETA: ext = "Eta" elif colorBy == IPHI: ext = "Phi" c.SaveAs("TopoLayout%s%s.pdf" % ("2016" if is2016 else "2015", ext))