datime.GetYear(), datime.GetHour(), datime.GetMinute(), datime.GetSecond()) def setupPaveTexts(pts): for pt in pts: pt.SetTextColor(1) pt.SetTextAngle(0) pt.SetFillColor(0) pt.SetBorderSize(0) pt.SetLineWidth(0) #mf=ROOT.TGMainFrame(gClient.GetRoot(),1500,475) mf = ROOT.TGMainFrame(0, 900, 925) gvf = TGVerticalFrame(mf, 900, 925) rec = TRootEmbeddedCanvas("ccc", gvf, 800, 800) rec2 = TRootEmbeddedCanvas("ccc2", gvf, 800, 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('SHMS PCAL FADC SCALERS') mf.MapSubwindows() mf.Resize(901, 926) # resize to get proper frame placement mf.MapWindow() mf.SetCleanup(ROOT.kDeepCleanup)
def __init__(self, model, fitter): self._container = [] self.model = model self.fitter = fitter ColorBase.kBird() gStyle.SetOptStat(0) TGMainFrame.__init__(self, 0, 300, 300) self.SetLayoutManager(TGHorizontalLayout(self)) self._fitCol = TGVerticalFrame(self, 250, 500) self._fitPars = {} for par in self.model.parameters(): if par.is_formula() or match('^[xy]0[12][12]$', par.GetName()) or ( par.isConstant() and not par.GetName().endswith('VtxRes') ): continue row = TGHorizontalFrame(self._fitCol, 250, 50) label = TGLabel(row, par.GetName()) entry = TGNumberEntry(row, par.val(), 10, kNESRealThree) row.AddFrame(label, TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5)) row.AddFrame(entry) self._fitCol.AddFrame(row, TGLayoutHints(kLHintsExpandX)) self._container.append(row) self._container.append(label) self._fitPars[par.GetName()] = entry self.AddFrame(self._fitCol) self._physCol = TGVerticalFrame(self, 250, 500) self._physPars = {} for par in self.model.parameters(): if ( not par.is_formula() and not match('^[xy]0[12][12]$', par.GetName()) and (not par.isConstant() or par.GetName().endswith('VtxRes')) ): continue row = TGHorizontalFrame(self._physCol, 250, 50) label = TGLabel(row, par.GetName()) entry = TGNumberEntry(row, par.val(), 10, kNESRealThree) entry.SetState(False) row.AddFrame(label, TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5)) row.AddFrame(entry) self._physCol.AddFrame(row, TGLayoutHints(kLHintsExpandX)) self._container.append(row) self._container.append(label) self._physPars[par.GetName()] = entry self.AddFrame(self._physCol) self._metaCol = TGVerticalFrame(self, 250, 500) self._metaPars = {} for par in ['chi2/dof', 'nll']: row = TGHorizontalFrame(self._metaCol, 250, 50) label = TGLabel(row, par) entry = TGNumberEntry(row, 0.0, 10, kNESRealThree) entry.SetState(False) row.AddFrame(label, TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5)) row.AddFrame(entry) self._metaCol.AddFrame(row, TGLayoutHints(kLHintsExpandX)) self._container.append(row) self._container.append(label) self._metaPars[par] = entry self._computeBtn = TGTextButton(self._metaCol, 'Compute', 10) self._fitBtn = TGTextButton(self._metaCol, 'Fit data', 10) self._drawBtn = TGTextButton(self._metaCol, 'Draw model', 10) for btn in [self._computeBtn, self._fitBtn, self._drawBtn]: self._metaCol.AddFrame(btn, TGLayoutHints(kLHintsExpandX, 5,5,5,5)) self.AddFrame(self._metaCol) self._canvCol = [TGVerticalFrame(self, 250, 500) for i in range(2)] self._canvas = [TRootEmbeddedCanvas( 'ce{0}'.format(i), self._canvCol[i%2], 250, 250 ) for i in range(4)] for i in range(2): self.AddFrame(self._canvCol[i], TGLayoutHints( kLHintsExpandX | kLHintsExpandY )) self._canvCol[i].AddFrame(self._canvas[i], TGLayoutHints( kLHintsExpandX | kLHintsExpandY )) self._canvCol[i].AddFrame(self._canvas[i+2], TGLayoutHints( kLHintsExpandX | kLHintsExpandY )) self._computeBtnDisp = TPyDispatcher(self.computeBtnClicked) self._computeBtn.Connect( 'Clicked()', 'TPyDispatcher', self._computeBtnDisp, 'Dispatch()' ) self._fitBtnDisp = TPyDispatcher(self.fitBtnClicked) self._fitBtn.Connect( 'Clicked()', 'TPyDispatcher', self._fitBtnDisp, 'Dispatch()' ) self._drawBtnDisp = TPyDispatcher(self.drawBtnClicked) self._drawBtn.Connect( 'Clicked()', 'TPyDispatcher', self._drawBtnDisp, 'Dispatch()' ) self.SetWindowName('{0} Parameters'.format(self.model.name())) self.MapSubwindows() self.Resize(self.GetDefaultSize()) self.MapWindow() for par in self.model.parameters(): if match('^[xy]0[12][12]$', par.GetName()) or par.is_formula(): continue par.setConstant()
for pt in pts: pt.SetTextColor(1) pt.SetTextAngle(0) pt.SetFillColor(0) pt.SetBorderSize(0) pt.SetLineWidth(0) def loadPV(chan): ch = chan.vals ch['PVVAL'] = ch['PV'].get() ch['PVTIMEVAL'] = ch['PVTIME'].get() mf = TGMainFrame(gClient.GetRoot(), 800, 565) gvf = TGVerticalFrame(mf, 800, 565) rec = TRootEmbeddedCanvas("ccc", gvf, 800, 565) gvf.AddFrame(rec, TGLayoutHints(ROOT.kLHintsExpandX | ROOT.kLHintsTop)) mf.AddFrame(gvf, TGLayoutHints(ROOT.kLHintsExpandX)) cc = rec.GetCanvas() mf.SetEditable(0) mf.SetWindowName('SVT Scalers') mf.MapSubwindows() mf.Resize(801, 566) # resize to get proper frame placement mf.MapWindow() mf.SetCleanup(ROOT.kDeepCleanup) def __atexit__(): del cc del rec
class ParameterConstWindow(TGMainFrame): def __init__(self, model, fitter): self._container = [] self.model = model self.fitter = fitter ColorBase.kBird() gStyle.SetOptStat(0) TGMainFrame.__init__(self, 0, 300, 300) self.SetLayoutManager(TGHorizontalLayout(self)) self._fitCol = TGVerticalFrame(self, 250, 500) self._fitPars = {} for par in self.model.parameters(): if par.is_formula() or match('^[xy]0[12][12]$', par.GetName()) or ( par.isConstant() and not par.GetName().endswith('VtxRes') ): continue row = TGHorizontalFrame(self._fitCol, 250, 50) label = TGLabel(row, par.GetName()) entry = TGNumberEntry(row, par.val(), 10, kNESRealThree) row.AddFrame(label, TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5)) row.AddFrame(entry) self._fitCol.AddFrame(row, TGLayoutHints(kLHintsExpandX)) self._container.append(row) self._container.append(label) self._fitPars[par.GetName()] = entry self.AddFrame(self._fitCol) self._physCol = TGVerticalFrame(self, 250, 500) self._physPars = {} for par in self.model.parameters(): if ( not par.is_formula() and not match('^[xy]0[12][12]$', par.GetName()) and (not par.isConstant() or par.GetName().endswith('VtxRes')) ): continue row = TGHorizontalFrame(self._physCol, 250, 50) label = TGLabel(row, par.GetName()) entry = TGNumberEntry(row, par.val(), 10, kNESRealThree) entry.SetState(False) row.AddFrame(label, TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5)) row.AddFrame(entry) self._physCol.AddFrame(row, TGLayoutHints(kLHintsExpandX)) self._container.append(row) self._container.append(label) self._physPars[par.GetName()] = entry self.AddFrame(self._physCol) self._metaCol = TGVerticalFrame(self, 250, 500) self._metaPars = {} for par in ['chi2/dof', 'nll']: row = TGHorizontalFrame(self._metaCol, 250, 50) label = TGLabel(row, par) entry = TGNumberEntry(row, 0.0, 10, kNESRealThree) entry.SetState(False) row.AddFrame(label, TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5)) row.AddFrame(entry) self._metaCol.AddFrame(row, TGLayoutHints(kLHintsExpandX)) self._container.append(row) self._container.append(label) self._metaPars[par] = entry self._computeBtn = TGTextButton(self._metaCol, 'Compute', 10) self._fitBtn = TGTextButton(self._metaCol, 'Fit data', 10) self._drawBtn = TGTextButton(self._metaCol, 'Draw model', 10) for btn in [self._computeBtn, self._fitBtn, self._drawBtn]: self._metaCol.AddFrame(btn, TGLayoutHints(kLHintsExpandX, 5,5,5,5)) self.AddFrame(self._metaCol) self._canvCol = [TGVerticalFrame(self, 250, 500) for i in range(2)] self._canvas = [TRootEmbeddedCanvas( 'ce{0}'.format(i), self._canvCol[i%2], 250, 250 ) for i in range(4)] for i in range(2): self.AddFrame(self._canvCol[i], TGLayoutHints( kLHintsExpandX | kLHintsExpandY )) self._canvCol[i].AddFrame(self._canvas[i], TGLayoutHints( kLHintsExpandX | kLHintsExpandY )) self._canvCol[i].AddFrame(self._canvas[i+2], TGLayoutHints( kLHintsExpandX | kLHintsExpandY )) self._computeBtnDisp = TPyDispatcher(self.computeBtnClicked) self._computeBtn.Connect( 'Clicked()', 'TPyDispatcher', self._computeBtnDisp, 'Dispatch()' ) self._fitBtnDisp = TPyDispatcher(self.fitBtnClicked) self._fitBtn.Connect( 'Clicked()', 'TPyDispatcher', self._fitBtnDisp, 'Dispatch()' ) self._drawBtnDisp = TPyDispatcher(self.drawBtnClicked) self._drawBtn.Connect( 'Clicked()', 'TPyDispatcher', self._drawBtnDisp, 'Dispatch()' ) self.SetWindowName('{0} Parameters'.format(self.model.name())) self.MapSubwindows() self.Resize(self.GetDefaultSize()) self.MapWindow() for par in self.model.parameters(): if match('^[xy]0[12][12]$', par.GetName()) or par.is_formula(): continue par.setConstant() def __del__(self): self.Cleanup() def readParameters(self): def setVal(par, val): self.model.parameter(par).set_range(val-0.1, val+0.1) self.model.parameter(par).setVal(val) for par in self._fitPars: setVal(par, self._fitPars[par].GetNumber()) for par in [p for p in self._physPars if 'VtxRes' in p]: setVal(par, self._physPars[par].GetNumber()) def displayParameters(self, chi2=False, nll=False): for par in [p for p in self._physPars if 'VtxRes' not in p]: self._physPars[par].SetNumber(self.model.parameter(par).val()) if chi2: self._metaPars['chi2/dof'].SetNumber(chi2) if nll: self._metaPars['nll'].SetNumber(nll) def computeBtnClicked(self): self.readParameters() self.displayParameters() def fitBtnClicked(self): self.readParameters() result, residuals, allChi2, allDof = self.fitter(self.model) self._residuals = residuals self.displayParameters(sum(allChi2)/sum(allDof), result.minNll()) for i in range(4): self._canvas[i].GetCanvas().cd() for xbin in range(self._residuals[i].GetXaxis().GetNbins()+1): for ybin in range(self._residuals[i].GetYaxis().GetNbins()+1): if self._residuals[i].GetBinContent(xbin, ybin) < -4.9999: self._residuals[i].SetBinContent(xbin, ybin, -4.9999) if self._residuals[i].GetBinContent(xbin, ybin) == 0.0: self._residuals[i].SetBinContent(xbin, ybin, -10.0) self._residuals[i].Draw('COLZ') self._residuals[i].GetZaxis().SetRangeUser(-5.0, 5.0) self._canvas[i].GetCanvas().Update() def drawBtnClicked(self): self.readParameters() self.displayParameters() modelFunctions = self.model.model_functions() self._hists = [] for i in range(4): self._canvas[i].GetCanvas().cd() hist = modelFunctions[i].createHistogram( 'model{0}'.format(i), self.model.xvar(), RooFit.Binning(95), RooFit.YVar(self.model.yvar(), RooFit.Binning(95)) ) hist.SetTitle('') hist.GetXaxis().SetTitle('') hist.GetYaxis().SetTitle('') hist.GetZaxis().SetTitle('') hist.Draw('COLZ') self._hists.append(hist) self._canvas[i].GetCanvas().Update()
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)