def EMTFEta(plotter): ## variables for the plot xTitle = "Generated muon |#eta|" title = "%s;%s;%s" % (topTitle, xTitle, yTitle) toPlot = "TMath::Abs(%s)" % (geneta) h_bins = "(20,1.2,2.4)" nBins = int(h_bins[1:-1].split(',')[0]) minBin = float(h_bins[1:-1].split(',')[1]) maxBin = float(h_bins[1:-1].split(',')[2]) c = newCanvas() gPad.SetGridx(xGrid) gPad.SetGridy(yGrid) base = TH1F("base", title, nBins, minBin, maxBin) base.SetMinimum(0) base.SetMaximum(plotter.yMax) base.GetXaxis().SetLabelSize(0.05) base.GetYaxis().SetLabelSize(0.05) base.GetXaxis().SetTitleSize(0.05) base.GetYaxis().SetTitleSize(0.05) base.Draw("") CMS_lumi.CMS_lumi(c, iPeriod, iPos) denom_cut = AND(ok_eta(1.2, 2.4), ok_2_csc_lcts()) h1 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>20")), ok_emtf(20), "same", kBlue) h2 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>15")), ok_emtf(15), "same", kRed) h3 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>10")), ok_emtf(10), "same", kGreen + 2) h4 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>5")), ok_emtf(5), "same", kOrange + 2) h5 = draw_geff(plotter.tree, title, h_bins, toPlot, AND(denom_cut, TCut("genParticle.pt>3")), ok_emtf(0), "same", kBlack) leg = TLegend(0.45, 0.2, .75, 0.5, "", "brNDC") leg.SetBorderSize(0) leg.SetFillStyle(0) leg.SetTextSize(0.05) leg.SetHeader("EMTF") leg.AddEntry(h1, "p_{T} > 20 GeV", "l") leg.AddEntry(h2, "p_{T} > 15 GeV", "l") leg.AddEntry(h3, "p_{T} > 10 GeV", "l") leg.AddEntry(h4, "p_{T} > 5 GeV", "l") leg.AddEntry(h5, "p_{T} > 0 GeV", "l") leg.Draw("same") c.Print("%sEff_EMTF_eta_Pt20_%s" % (plotter.targetDir + subdirectory, plotter.ext)) del c, base, h1, leg, h2, h3, h4, h5
def drawStavePlots(detector, det): from ROOT import TCanvas from ROOT import TH1F from ROOT import gPad StavePlots = {} if det == 1: Lay = [0, 1, 2] Phi = [22, 38, 52] detname = "PIX" if det == 2: Lay = [0, 1, 2, 3] Phi = [32, 40, 48, 56] detname = "SCT" ncanvas = 0 for lay in Lay: for phi in range(Phi[lay]): StavePlots[ncanvas] = TCanvas( "Stave%sPlots_L%d_Phi%d" % (detname, lay, phi), "Stave Plots %s L%d Phi%d" % (detname, lay, phi)) StavePlots[ncanvas].Divide(3, 2) stavemodules = detector.ReturnModules(det, 0, lay, phi) hStaveCorrections = {} for i in range(6): StavePlots[ncanvas].cd(i + 1) name, value = detector.GetModule(0).GetDoF(i) hname = 'Stave_%s_L%d_Phi%d_%s_corrections' % (detname, lay, phi, name) htitle = 'Stave %s L%d Phi%d %s Corrections' % (detname, lay, phi, name) hStaveCorrections[name] = TH1F(hname, htitle, len(stavemodules), 0, len(stavemodules)) if name is 'Tx' or name is 'Ty' or name is 'Tz' or name is 'Bx': hStaveCorrections[name].SetYTitle("mm") else: hStaveCorrections[name].SetYTitle("mrad") bin = 1 for mod in stavemodules: hStaveCorrections[name].SetBinContent( bin, detector.GetModule(mod).GetDoF(i)[1]) bin = bin + 1 #hStaveCorrections[name].Draw() XAxis = hStaveCorrections[name].GetXaxis() XAxis.CenterLabels() bin = 1 for mod in stavemodules: XAxis.SetBinLabel(bin, str(detector.GetModule(mod).Eta)) bin = bin + 1 hStaveCorrections[name].SetStats(False) hStaveCorrections[name].DrawCopy() gPad.SetGridx() gPad.SetGridy() ncanvas = ncanvas + 1 return StavePlots
def setpad(left, right, top, bottom): gPad.SetFillColor(10) gPad.SetBorderMode(0) gPad.SetBorderSize(0) gPad.SetFrameFillColor(10) gPad.SetFrameBorderMode(0) gPad.SetFrameBorderSize(0) gPad.SetLeftMargin(left) gPad.SetRightMargin(right) gPad.SetTopMargin(top) gPad.SetBottomMargin(bottom) gPad.SetGridx(0) gPad.SetGridy(0) gStyle.SetOptStat(0)
def drawSctBarrelCorrDistributions(detector): from ROOT import TCanvas from ROOT import TH1F from ROOT import gPad SctBarrelCorrDistributions = TCanvas( "SctBarrelCorrDistributions", "SCT Barrel Corrections Distributions") SctBarrelCorrDistributions.Divide(3, 2) hSctBarrelCorrDistributions = {} detname = "SCT Barrel" Color = AutoColors(len(detector)) for d in detector: hSctBarrelCorrDistributions[d] = {} for i in range(6): SctBarrelCorrDistributions.cd(i + 1) name, value = detector[d].GetModule(0).GetDoF(i) hname = '%s_%sCorrections_%d' % (detname, name, d) htitle = '%s %s Corrections' % (detname, name) if name is 'Tx': hSctBarrelCorrDistributions[d][name] = TH1F( hname, htitle, 50, -0.005, 0.005) elif name is 'Ty': hSctBarrelCorrDistributions[d][name] = TH1F( hname, htitle, 50, -0.1, 0.1) else: hSctBarrelCorrDistributions[d][name] = TH1F( hname, htitle, 50, -0.25, 0.25) if name is 'Tx' or name is 'Ty' or name is 'Tz' or name is 'Bx': hSctBarrelCorrDistributions[d][name].GetXaxis().SetTitle( name + " (mm)") else: hSctBarrelCorrDistributions[d][name].GetXaxis().SetTitle( name + " (mrad)") hSctBarrelCorrDistributions[d][name].GetYaxis().SetTitle("Modules") hSctBarrelCorrDistributions[d][name].SetLineColor(Color[d]) for module in detector[d].ReturnSctBarrelModules(): hSctBarrelCorrDistributions[d][name].Fill(module.GetDoF(i)[1]) if d == 0: hSctBarrelCorrDistributions[d][name].Draw() else: hSctBarrelCorrDistributions[d][name].Draw("Same") gPad.SetGridx() gPad.SetGridy() SctBarrelCorrDistributions.Update() return SctBarrelCorrDistributions, hSctBarrelCorrDistributions
def drawCorrVsHits(detector): from ROOT import TCanvas from ROOT import TGraph from array import array from ROOT import gPad CorrVsHits = TCanvas("CorrVsHits", "Alignment Corrections vs hits") CorrVsHits.Divide(3, 2) hCorrVsHits = {} Color = AutoColors(len(detector)) for det in detector: hCorrVsHits[det] = {} for i in range(6): CorrVsHits.cd(i + 1) name, value = detector[det].GetModule(0).GetDoF(i) hname = 'CorrVsHits_%s_corrections_%d' % (name, det) htitle = '%s Corrections vs hits_%d' % (name, det) xpoints = [] ypoints = [] for j in range(detector[det].nModules()): xpoints.append(detector[det].GetModule(j).Hits) ypoints.append(detector[det].GetModule(j).GetDoF(i)[1]) x = array("f", xpoints) y = array("f", ypoints) hCorrVsHits[det][name] = TGraph(detector[det].nModules(), x, y) hCorrVsHits[det][name].SetTitle(htitle) hCorrVsHits[det][name].GetXaxis().SetTitle("Hits per module") hCorrVsHits[det][name].GetYaxis().SetTitle(name) if name is 'Tx' or name is 'Ty' or name is 'Tz' or name is 'Bx': hCorrVsHits[det][name].GetYaxis().SetTitle(name + " (mm)") else: hCorrVsHits[det][name].GetYaxis().SetTitle(name + " (mrad)") hCorrVsHits[det][name].SetMarkerStyle(4) hCorrVsHits[det][name].SetMarkerSize(0.5) hCorrVsHits[det][name].SetMarkerColor(Color[det]) if det == 0: hCorrVsHits[det][name].Draw("Ap") else: hCorrVsHits[det][name].Draw("psame") gPad.SetGridx() gPad.SetGridy() gPad.SetLogx() CorrVsHits.Update() return CorrVsHits, hCorrVsHits
nc.cd() print colorlist[j] g.SetLineColor(colorlist[j]) g.SetMarkerColor(colorlist[j]) g.SetMarkerStyle(8) g.SetMarkerSize(0.8) g.SetTitle('') g.GetXaxis().SetTitle(ix[3]) g.GetYaxis().SetTitle(var[1]) g.GetYaxis().SetRangeUser(var[5][0], var[5][1]) graphs.append(g) nc.cd() for j, jgraph in enumerate(graphs): jgraph.Draw('AP' * (j == 0) + 'P same' * (j != 0)) if options.leg: l.AddEntry(jgraph, options.leg.split(',')[j], "pel") nc.Update() nc.Modified() if options.leg: l.Draw() gPad.SetGridx(True) gPad.SetGridy(True) nc.SaveAs('pull_resolution_plots/' + var[6] + 'vs' + ix[0] + '_Run278820_RelVal.pdf')
for line in file: histoBytes.SetBinContent(bin, int(line.split("\n")[0])) bin = bin + 1 l = int(line.split("\n")[0]) l = hex(l)[2:] f.write("%s\n" % l) k = k + 1 print(" mem[%2d] = 8'h%s ;" % (k, l)) histoBytes.Draw() ## set the correct range of the Sine Wave histoBytes.GetXaxis().SetRangeUser(-2, 70) ## cosmetics histoBytes.GetXaxis().SetTitle("number") histoBytes.GetYaxis().SetTitle("Sine Data") histoBytes.GetYaxis().CenterTitle() gPad.SetGridx() gPad.SetGridy() ##end print("end") print("// Verilog code ends here") print("\n\nROM depth must be at least %d-slots deep.\n\n" % (k)) f.close()
def drawAllCorr(detector): from ROOT import TCanvas from ROOT import TH1F from ROOT import gPad debug = False if (debug): print " -- drawAllCorr -- starting for detector = ", detector showErrors = True Alldetector = TCanvas("AlignmentCorrections(All)", "Alignment Corrections (All)") Alldetector.Divide(3, 2) AllCorrections = {} yrange = [0, 0, 0, 0, 0, 0] if (debug): print " -- drawAllCorr -- finding out histogram ranges... " for i in range(6): if (debug): print " -- drawAllCorr -- extracting range for dof:", i for det in detector: for bin in range(detector[det].nModules()): #print " ** drawutils ** drawAllCorr ** det:",det," nModules = ",detector[det].nModules() if abs(detector[det].GetModule(bin).GetDoF(i)[1]) > yrange[i]: yrange[i] = abs(detector[det].GetModule(bin).GetDoF(i)[1]) yrange[i] *= 1.1 if (debug): print " -- drawAllCorr -- finding out colors ..." Color = AutoColors(len(detector)) for det in detector: for i in range(6): Alldetector.cd(i + 1) AllCorrections[det] = {} name, value = detector[det].GetModule(0).GetDoF(i) hname = 'All_%s_corrections_%d' % (name, det) htitle = 'All %s Corrections_%d' % (name, det) AllCorrections[det][name] = TH1F(hname, htitle, detector[det].nModules(), 0, detector[det].nModules()) if name is 'Tx' or name is 'Ty' or name is 'Tz' or name is 'Bx': AllCorrections[det][name].SetYTitle("mm") else: AllCorrections[det][name].SetYTitle("mrad") for bin in range(detector[det].nModules()): AllCorrections[det][name].SetBinContent( bin + 1, detector[det].GetModule(bin).GetDoF(i)[1]) if showErrors: AllCorrections[det][name].SetBinError( bin + 1, detector[det].GetModule(bin).GetDoFError(i)[1]) if detector[det].nModules() < 35: AllCorrections[det][name].GetXaxis().SetBinLabel( bin + 1, detector[det].GetModule(bin).GetName()) #AllCorrections[det][name].SetMarkerStyle(20) AllCorrections[det][name].SetMarkerColor(Color[det]) AllCorrections[det][name].SetLineColor(Color[det]) AllCorrections[det][name].SetFillColor(Color[det]) AllCorrections[det][name].SetFillStyle(1001) AllCorrections[det][name].SetStats(False) if det == 0: AllCorrections[det][name].GetYaxis().SetRangeUser( -yrange[i], yrange[i]) AllCorrections[det][name].DrawCopy() else: AllCorrections[det][name].DrawCopy('same') gPad.SetGridx() gPad.SetGridy() gPad.Update() return Alldetector
def drawL3CorrVsHits(detector, det, bec): from ROOT import TCanvas from ROOT import TGraph from array import array from ROOT import gPad if det == 1: if bec == None: detname = "PIX" elif bec == 0: detname = "PIXBarrel" elif bec == -1: detname = "PIXECC" elif bec == 1: detname = "PIXECA" elif det == 2: if bec == None: detname = "SCT" elif bec == 0: detname = "SCTBarrel" elif bec == -1: detname = "SCTECC" elif bec == 1: detname = "SCTECA" L3CorrVsHits = TCanvas(detname + "CorrVsHits", detname + " Alignment Corrections vs hits") L3CorrVsHits.Divide(3, 2) hCorrVsHits = {} Color = AutoColors(len(detector)) for d in detector: hCorrVsHits[d] = {} for i in range(6): L3CorrVsHits.cd(i + 1) name, value = detector[d].GetModule(0).GetDoF(i) hname = '%s_CorrVsHits_%s_corrections' % (detname, name) htitle = '%s %s Corrections vs hits' % (detname, name) xpoints = [] ypoints = [] for j in detector[d].ReturnModules(det, bec): xpoints.append(detector[d].GetModule(j).Hits) ypoints.append(detector[d].GetModule(j).GetDoF(i)[1]) x = array("f", xpoints) y = array("f", ypoints) hCorrVsHits[d][name] = TGraph(len(x), x, y) hCorrVsHits[d][name].SetTitle(htitle) hCorrVsHits[d][name].GetXaxis().SetTitle("Hits per module") hCorrVsHits[d][name].GetYaxis().SetTitle(name) if name is 'Tx' or name is 'Ty' or name is 'Tz' or name is 'Bx': hCorrVsHits[d][name].GetYaxis().SetTitle(name + " (mm)") else: hCorrVsHits[d][name].GetYaxis().SetTitle(name + " (mrad)") hCorrVsHits[d][name].SetMarkerStyle(4) hCorrVsHits[d][name].SetMarkerSize(0.5) hCorrVsHits[d][name].SetMarkerColor(Color[d]) if d == 0: hCorrVsHits[d][name].Draw("Ap") else: hCorrVsHits[d][name].Draw("Ap") gPad.SetGridx() gPad.SetGridy() L3CorrVsHits.Update() return L3CorrVsHits, hCorrVsHits
def OLD_drawCorrEvolution(detector, labelList, drawErrors=False, drawLine=True, whichdof=-1): from ROOT import TCanvas from ROOT import TH1F from ROOT import gPad from ROOT import TLegend doDebug = True showErrors = True drawAllDofs = True nUsedDofs = 6 if (whichdof != -1): drawAllDofs = False if (whichdof > 5): nUsedDofs = 7 # 7/oct/2015 with the BowX we may have up to 7 dofs. Unless stated draw the ordinary 6. lowerDof = 0 upperDof = 5 if (not drawAllDofs): lowerDof = whichdof upperDof = whichdof # a canvas for all dofs ThisCanvas = TCanvas("AlignmentCorrectionsEvol", "Evolution of alignment corrections (All)") if (drawAllDofs): ThisCanvas.Divide(3, 2) hCorrectionsEvol = {} hCorrectionsEvolStruct = {} yrange = [0.002, 0.002, 0.002, 0.01, 0.01, 0.01, 0.002] # minimum is 0.001 (mm or mrad) # here detector = num of iterations numOfIterations = len(detector) if (doDebug): print " numOfIterations=", numOfIterations numOfAlignableStruct = detector[0].nModules() if (doDebug): print " numOfAlignableStructe=", numOfAlignableStruct EvolColor = AutoColors(numOfAlignableStruct) # find out range #for i in range(lowerDof, upperDof): for i in range(nUsedDofs): for iter in range(numOfIterations): for bin in range(detector[iter].nModules()): thisValue = abs(detector[iter].GetModule(bin).GetDoF( i)[1]) + detector[iter].GetModule(bin).GetDoFError(i)[1] if abs(thisValue) > yrange[i]: yrange[i] = thisValue yrange[i] *= 1.025 if (doDebug): print " dof=", i, " --> range: ", yrange[i] # maximum range maxTransRange = 0.100 if (yrange[0] > maxTransRange): yrange[0] = maxTransRange if (yrange[1] > maxTransRange): yrange[1] = maxTransRange if (yrange[2] > maxTransRange): yrange[2] = maxTransRange #yrange[0] = 0.04 #yrange[1] = 0.04 # Tx and Ty should have the same range if (yrange[0] > yrange[1]): yrange[1] = yrange[0] else: yrange[0] = yrange[1] # Tz range should be as minimum as Tx and Ty if (yrange[2] < yrange[0]): yrange[2] = yrange[0] # Rx and Ry should have the same range if (yrange[3] > yrange[4]): yrange[4] = yrange[3] else: yrange[3] = yrange[4] # Rz range should be as minimum as Rx and Ry #if (yrange[5] < yrange[3]): yrange[5] = yrange[3] # prepare the legend myLegend = TLegend(0.65, 0.65, 0.92, 0.92) # loop dof by dof (Tx, Ty...) and fill a polyline with teh corrections for each iteration if (doDebug): print " ** drawCorrEvolution ** lowerDof=", lowerDof, " upperDof = ", upperDof #for dof in range(nUsedDofs): for dof in range(lowerDof, upperDof + 1): if (doDebug): print " ** drawCorrEvolution ** going to draw dof=", dof ThisCanvas.cd() if (drawAllDofs): ThisCanvas.cd(dof + 1) name = detector[0].GetModule(0).GetDoF(dof)[0] hname = 'Dof_%s_corrections_Evol' % (name) htitle = 'Corrections evolution for %s' % (name) if (doDebug): print " ** drawCorrEvolution ** dof=", dof, " hname = ", hname print " htitle = ", htitle # this histogram is the main frame hCorrectionsEvol[dof] = TH1F(hname, htitle, numOfIterations - 1, -0.5, numOfIterations * 1. - 1.5) # set the x axis labels if (numOfIterations > 12): hCorrectionsEvol[dof].GetXaxis().SetLabelSize(0.03) hCorrectionsEvol[dof].GetXaxis().SetBit(18) for iter in range(numOfIterations - 1): # -1 do not include the total sum in the plot hCorrectionsEvol[dof].GetXaxis().SetBinLabel( iter + 1, 'Iter_%d' % (iter)) if (len(labelList) > iter): # use label given by user hCorrectionsEvol[dof].GetXaxis().SetBinLabel( iter + 1, labelList[iter]) # label Y axis if name is 'Tx' or name is 'Ty' or name is 'Tz' or name is 'Bx': hCorrectionsEvol[dof].SetYTitle("mm") else: hCorrectionsEvol[dof].SetYTitle("mrad") hCorrectionsEvol[dof].GetYaxis().SetRangeUser(-yrange[dof], yrange[dof]) hCorrectionsEvol[dof].SetStats(False) hCorrectionsEvol[dof].DrawCopy() gPad.SetGridx() gPad.SetGridy() #once the frame is plotted, loop on every structure and fill a histogram and draw it print " .. dealing with", name, "corrections .. with range for this dof: (", dof, ") range: +-", yrange[ dof] print " ** ==> numOfAlignableStruct = ", numOfAlignableStruct for struct in range(numOfAlignableStruct): #for struct in range(0,2): if (doDebug): print " >> looping on struct:", struct hCorrectionsEvolStruct[dof] = {} hname = 'Dof_%s_corrections_Evol_struct_%d' % (name, struct) htitle = 'Corrections evolution for structure %s (struct %d)' % ( name, struct) hCorrectionsEvolStruct[dof][struct] = TH1F( hname, htitle, numOfIterations, -0.5, numOfIterations * 1. - 0.5) hCorrectionsEvolStruct[dof][struct].SetLineColor(EvolColor[struct]) hCorrectionsEvolStruct[dof][struct].SetStats(False) # once the histogram is created, fill it with the corrections of each iteration accumvalue = 0 for iter in range(numOfIterations - 1): # -1 to account for the overall integration value = detector[iter].GetModule(struct).GetDoF(dof)[1] accumvalue = accumvalue + value # if (doDebug): print " dof:",dof, " struct:",struct," iter:",iter," delta=",value hCorrectionsEvolStruct[dof][struct].SetBinContent( iter + 1, value) # if (doDebug): print "hCorrectionsEvolStruct[",dof,"][",struct,"].SetBinContent(",iter+1,",", value,")" if (drawErrors): hCorrectionsEvolStruct[dof][struct].SetBinError( iter + 1, detector[iter].GetModule(struct).GetDoFError(dof)[1]) # now draw the corrections for this structure if (doDebug): print "Accumulated", hname, ":", accumvalue # store the accumulated if (dof == 0): detector[numOfIterations - 1].GetModule(struct).setTx(accumvalue) if (dof == 1): detector[numOfIterations - 1].GetModule(struct).setTy(accumvalue) if (dof == 2): detector[numOfIterations - 1].GetModule(struct).setTz(accumvalue) if (dof == 3): detector[numOfIterations - 1].GetModule(struct).setRx(accumvalue) if (dof == 4): detector[numOfIterations - 1].GetModule(struct).setRy(accumvalue) if (dof == 5): detector[numOfIterations - 1].GetModule(struct).setRz(accumvalue) if (dof == 6): detector[numOfIterations - 1].GetModule(struct).setBx(accumvalue) if (drawErrors): hCorrectionsEvolStruct[dof][struct].SetFillColor( EvolColor[struct]) hCorrectionsEvolStruct[dof][struct].SetFillStyle(3354) # hCorrectionsEvolStruct[dof][struct].DrawCopy('same e3') # --> original hCorrectionsEvolStruct[dof][struct].DrawCopy('same e3') hCorrectionsEvolStruct[dof][struct].SetMarkerStyle(20) hCorrectionsEvolStruct[dof][struct].SetMarkerSize(0.5) hCorrectionsEvolStruct[dof][struct].SetMarkerColor( EvolColor[struct]) hCorrectionsEvolStruct[dof][struct].DrawCopy('same p e3 x0') for iter in range(numOfIterations - 1): hCorrectionsEvolStruct[dof][struct].SetBinError( iter + 1, 0) hCorrectionsEvolStruct[dof][struct].SetFillStyle(0) hCorrectionsEvolStruct[dof][struct].DrawCopy('same l') else: myOption = "same" if (drawLine): myOption += " l" else: myOption += " p" hCorrectionsEvolStruct[dof][struct].SetMarkerStyle(20) hCorrectionsEvolStruct[dof][struct].SetMarkerColor( EvolColor[struct]) hCorrectionsEvolStruct[dof][struct].DrawCopy(myOption) gPad.Update() if (dof == nUsedDofs - 1 and False): myLegend.AddEntry(hCorrectionsEvolStruct[dof][struct], detector[0].GetModule(struct).GetName(), "l") myLegend.Draw() gPad.Update() return ThisCanvas