def looks(): gROOT.ProcessLine('TGaxis::SetMaxDigits(3)') gStyle.SetFrameBorderMode(0) gStyle.SetFrameFillColor(0) gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(0) gStyle.SetPadBorderMode(0) gStyle.SetPadColor(0) gStyle.SetStatColor(0) gStyle.SetTitleFont(42, '') gStyle.SetLabelFont(42, 'x') gStyle.SetTitleFont(42, 'x') gStyle.SetLabelFont(42, 'y') gStyle.SetTitleFont(42, 'y') gStyle.SetLabelFont(42, 'z') gStyle.SetTitleFont(42, 'z') gStyle.SetLabelSize(0.048, 'x') gStyle.SetTitleSize(0.048, 'x') gStyle.SetLabelSize(0.048, 'y') gStyle.SetTitleSize(0.048, 'y') gStyle.SetLabelSize(0.048, 'z') gStyle.SetTitleSize(0.048, 'z') gStyle.SetTitleSize(0.048, '') gStyle.SetTitleAlign(23) gStyle.SetTitleX(0.5) gStyle.SetTitleBorderSize(0) gStyle.SetTitleFillColor(0) gStyle.SetTitleStyle(0) gStyle.SetOptStat('emr') gStyle.SetOptStat(0) gStyle.SetStatBorderSize(0) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.048) gStyle.SetStatY(0.9) gStyle.SetStatX(0.86) gStyle.SetHistLineColor(ROOT.kBlue + 2) gStyle.SetLegendBorderSize(0) gStyle.SetLegendFillColor(0) gStyle.SetFuncWidth(2) gStyle.SetFuncColor(2) gStyle.SetPadTopMargin(0.08) gStyle.SetPadBottomMargin(0.12) gStyle.SetPadLeftMargin(0.12) gStyle.SetPadRightMargin(0.06) gStyle.SetCanvasDefX(400) gStyle.SetCanvasDefY(20) gStyle.SetCanvasDefH(420) gStyle.SetCanvasDefW(610) gStyle.SetFrameBorderMode(0) gStyle.SetFrameLineWidth(2) gStyle.SetHistLineWidth(2) gStyle.SetTitleOffset(1.16, 'y') gStyle.SetTitleOffset(1.20, 'x')
def makeMassRes(inputDATA,inputMC,output,weights,weights2,trackType,funct,mcIsData,dataIsMC): style = setTDRStyle() gStyle.SetTitleYOffset(1.45) gStyle.SetTitleXOffset(1.45) gStyle.SetOptFit(0) gStyle.SetStatX(.9) gStyle.SetStatY(.9) (data_B,mc_B,ptdaB,ptmcB) = loadHistos(inputDATA,inputMC,"BB",weights,weights2,trackType,mcIsData,dataIsMC) (data_E,mc_E,ptdaE,ptmcE) = loadHistos(inputDATA,inputMC,"BE",weights,weights2,trackType,mcIsData,dataIsMC) # ~ (data_E2,mc_E2,ptdaE2,ptmcE2) = loadHistos(inputDATA,inputMC,"BE_neweta",weights,weights2,trackType,mcIsData,dataIsMC) drawMassRes(data_B,mc_B,output,"BB",ptdaB,ptmcB,trackType,funct,mcIsData,dataIsMC,inputDATA) drawMassRes(data_E,mc_E,output,"BE",ptdaE,ptmcE,trackType,funct,mcIsData,dataIsMC,inputDATA)
def set_root_env(): from ROOT import gStyle, gROOT gROOT.Reset() gROOT.SetStyle('Plain') gStyle.SetCanvasColor(10) gStyle.SetStatBorderSize(1) gStyle.SetFillColor(10) gStyle.SetOptStat(1) gStyle.SetStatX(0.46) gStyle.SetStatY(0.9) gStyle.SetTitleYOffset(1.4) gStyle.SetPalette(45) gStyle.SetMarkerSize(0.8) gStyle.SetLineColor(1) gStyle.SetLineWidth(1)
def set_statbox(x=.95, y=.88, w=.16, entries=3, only_fit=False, opt=None, form=None): if only_fit: gStyle.SetOptStat(0011) gStyle.SetOptFit(1) gStyle.SetOptStat(opt) if opt is not None else do_nothing() gStyle.SetFitFormat(form) if form is not None else do_nothing() gStyle.SetStatX(x) gStyle.SetStatY(y) gStyle.SetStatW(w) gStyle.SetStatH(.04 * entries)
def my_style(): gStyle.SetLabelSize(fontsize, "x") gStyle.SetLabelSize(fontsize, "y") gStyle.SetLabelSize(fontsize, "z") gStyle.SetTitleFontSize(1.5 * fontsize) gStyle.SetTitleSize(fontsize, "x") gStyle.SetTitleSize(fontsize, "y") gStyle.SetTitleSize(fontsize, "z") gStyle.SetTickLength(0, "Y") gStyle.SetTitleOffset(1.5, "xy") gStyle.SetTitleFont(62, "bla") gStyle.SetPadBottomMargin(0.15) gStyle.SetPadTopMargin(0.10) gStyle.SetPadLeftMargin(0.32) gStyle.SetPadRightMargin(0.05) gStyle.SetStatX(0.88) gStyle.SetStatY(0.87) gStyle.SetNdivisions(505) gStyle.SetCanvasColor(-1) gStyle.SetPadColor(-1) gStyle.SetFrameFillColor(-1) gStyle.SetTitleFillColor(-1) gStyle.SetFillColor(-1) gStyle.SetFillStyle(4000) gStyle.SetStatStyle(0) gStyle.SetTitleStyle(0) gStyle.SetCanvasBorderSize(0) gStyle.SetFrameBorderSize(0) gStyle.SetLegendBorderSize(0) gStyle.SetStatBorderSize(0) gStyle.SetTitleBorderSize(0)
def __init__(self): # ROOT gROOT.LoadMacro("tdrstyle.C") gROOT.LoadMacro("../interface/HelperMath.h") gROOT.LoadMacro("../../AMSimulationIO/src/AMSimulationIOLinkDef.h") gROOT.ProcessLine("setTDRStyle()") gStyle.SetEndErrorSize(2) gStyle.SetPadRightMargin(0.05) gStyle.SetTitleOffset(1.1, "Y") gStyle.SetLabelSize(0.04, "Y") gStyle.SetLabelSize(0.04, "Z") gStyle.SetNdivisions(505, "XY") gStyle.SetPalette(55) # rainbow color map gStyle.SetNumberContours(100) gStyle.SetOptStat(111110) gStyle.SetStatX(0.94) gStyle.SetStatY(0.93) gStyle.SetStatH(0.30) gStyle.SetStatW(0.28) TH1.SetDefaultSumw2()
redArray = array('d',red) greenArray = array('d',green) blueArray = array('d',blue) ROOT.TColor.CreateGradientColorTable(NRGBs,stopsArray,redArray,greenArray,blueArray,NCont) gStyle.SetNumberContours(NCont) gPad.SetLogz(1) #gStyle.SetOptStat(0) gPad.SetRightMargin(0.15) Correlation_plot.Draw("colz") gr.Draw("same") gStyle.SetStatX(0.85) gStyle.SetStatY(0.95) gPad.Update() CanvCorrelation.cd(2) gStyle.SetOptStat("e") #gPad.SetLogz(0) Correlation_plot_2Dmap.Draw("colz") gStyle.SetStatX(0.9) gStyle.SetStatY(0.95) gPad.SetRightMargin(0.15)
# ------- Create canvas Canv4Plots = ROOT.TCanvas("Thresh_2D", "Thresh_2D", 800, 600) ROOT.SetOwnership(Canv4Plots, False) # TODO: DOESN'T WORK... Canv4Plots.Divide(2, 2) Canv4Plots.cd(1) gPad.SetGrid() gStyle.SetOptStat("rmen") thresh1D.Draw() gPad.Update() Canv4Plots.cd(2) gStyle.SetOptStat("e") gStyle.SetStatX(0.9) gStyle.SetStatY(0.95) thresh2D.GetZaxis().SetTitleOffset(1.3) gPad.SetRightMargin(0.15) thresh2D.Draw("colz") TDAC2D.Draw("sametext") TDAC2D.SetMarkerSize(0.9) list_TLine = [] for i in range(0, 25): line_vert = TLine(i, 12, i, 48) line_vert.Draw() list_TLine.append(line_vert) for i in range(12, 49):
def rootStyle(batchMode=True): from ROOT import gROOT, gStyle, kWhite, kBlack # No info messages gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;") # Batch mode (no TCanvas) gROOT.SetBatch(batchMode) # Start from a plain default gROOT.SetStyle("Plain") lhcbMarkerType = 8 lhcbMarkerSize = 0.8 lhcbFont = 62 lhcbStatFontSize = 0.02 lhcbStatBoxWidth = 0.12 lhcbStatBoxHeight = 0.12 lhcbWidth = 1 lhcbTextSize = 0.05 lhcbLabelSize = 0.035 lhcbAxisLabelSize = 0.035 lhcbForeColour = kBlack gStyle.SetFrameBorderMode(0) gStyle.SetPadBorderMode(0) # canvas options gStyle.SetCanvasBorderSize(0) gStyle.SetCanvasBorderMode(0) # fonts gStyle.SetTextFont(lhcbFont) gStyle.SetTextSize(lhcbTextSize) gStyle.SetLabelFont(lhcbFont, "x") gStyle.SetLabelFont(lhcbFont, "y") gStyle.SetLabelFont(lhcbFont, "z") gStyle.SetLabelSize(lhcbLabelSize, "x") gStyle.SetLabelSize(lhcbLabelSize, "y") gStyle.SetLabelSize(lhcbLabelSize, "z") gStyle.SetTitleFont(lhcbFont) gStyle.SetTitleSize(lhcbAxisLabelSize, "x") gStyle.SetTitleSize(lhcbAxisLabelSize, "y") gStyle.SetTitleSize(lhcbAxisLabelSize, "z") gStyle.SetTitleColor(kWhite) gStyle.SetTitleFillColor(kWhite) gStyle.SetTitleColor(kBlack) gStyle.SetTitleBorderSize(0) gStyle.SetTitleTextColor(kBlack) # set title position gStyle.SetTitleX(0.15) gStyle.SetTitleY(0.97) # turn off Title box gStyle.SetTitleBorderSize(0) gStyle.SetTitleTextColor(lhcbForeColour) gStyle.SetTitleColor(lhcbForeColour) # use bold lines and markers gStyle.SetLineWidth(lhcbWidth) gStyle.SetFrameLineWidth(lhcbWidth) gStyle.SetHistLineWidth(lhcbWidth) gStyle.SetFuncWidth(lhcbWidth) gStyle.SetGridWidth(lhcbWidth) gStyle.SetLineStyleString(2, "[12 12]") gStyle.SetMarkerStyle(lhcbMarkerType) gStyle.SetMarkerSize(lhcbMarkerSize) # label offsets gStyle.SetLabelOffset(0.015) # by default, do not display histogram decorations: gStyle.SetOptStat(1111) # show probability, parameters and errors gStyle.SetOptFit(1011) # look of the statistics box: gStyle.SetStatBorderSize(1) gStyle.SetStatFont(lhcbFont) gStyle.SetStatFontSize(lhcbStatFontSize) gStyle.SetStatX(0.9) gStyle.SetStatY(0.9) gStyle.SetStatW(lhcbStatBoxWidth) gStyle.SetStatH(lhcbStatBoxHeight) # put tick marks on top and RHS of plots gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) # histogram divisions gStyle.SetNdivisions(505, "x") gStyle.SetNdivisions(510, "y") # Force the style gROOT.ForceStyle()
def drawHist(hist, confL, name, colz=True, contour=False, dec=False): can = TCanvas() can.cd() if (dec): gStyle.SetPaintTextFormat("3.2f") else: gStyle.SetPaintTextFormat("3.0f") if "metOmeff" in hist.GetName(): gStyle.SetPaintTextFormat("3.2f") gStyle.SetStatX(50) #colors = array("i",[3,30, 40, 20, 46, 5, 6, 7, 8, 9,11,4]) #colors >= #levels - 1 #gStyle.SetPalette(len(colors), colors) #levels = array("d",[.01, .20, 0.50, 1, 2, 3, 4, 7,9,10]) #hist.SetContour(len(levels), levels) hist.SetMarkerSize(1.5) if colz: hist.Draw("colz,same") hist.Draw("text30, same") if SigSample == "GG_ttn1": xlabel = 850 ylabel = 1400 elif SigSample == "GG_2stepWZ": xlabel = 600 ylabel = 1400 elif SigSample == "GG_SLN1": xlabel = 400 ylabel = 1000 elif SigSample == "BB_onestepC1": xlabel = 350 ylabel = 300 xlabel = 650 ylabel = 1500 if contour: g = TGraph2D() TH2toTGraph2D(hist, g) Ghisto = g.GetHistogram() level = array('d', [1.64, 3]) Ghisto.SetLineWidth(4) Ghisto.SetContour(2, level) Ghisto.Draw("cont1,list ,same") # confL.SetLineColor(1) # confL.Draw("colz,same") tex1 = TLatex() if SigSample == "BB_onestepC1": tex1.DrawLatex(xlabel, ylabel + 50, "#color[3]{1.64#sigma}") else: tex1.DrawLatex(xlabel, ylabel + 100, "#color[3]{1.64#sigma}") tex1.DrawLatex(xlabel, ylabel, "#color[2]{3#sigma}") #sprintf(&title[0],"MET>%d GeV",met); #myText(.2,.84,kBlue,title); #sprintf(&title[0],"MEFF>%d GeV",meff); #myText(.2,.79,kBlue,title); #sprintf(&title[0],"Bkg: %3.1f evts",_bkg); #myText(.2,.74,kBlue,title); # myLineText(.26, .8 , 0.05, kGreen,"1.64#sigma") # myLineText(.26, .75, 0.05, kRed, "3#sigma") hist.GetYaxis().SetTitleOffset(1.3) hist.GetXaxis().SetTitle("Gluino Mass (GeV)") hist.GetYaxis().SetTitle("Neutralino Mass (GeV)") gStyle.SetTitleX(100.0) # move title off plot gStyle.SetTitleW(0.0) # title width =0 tex2 = TLatex() if SigSample == "BB_onestepC1": tex2.DrawLatex( xlabel, ylabel + 100, name + " " + str(luminosity) + " fb^{-1}: " + hist.GetName()) else: tex2.DrawLatex( xlabel, ylabel + 200, name + " " + str(luminosity) + " fb^{-1}: " + hist.GetName()) # Draw m_gl - m_N1 = 2 (m_W+m_b) line = TLine(600, 429.6, 1800, 1629.6) line.SetLineColor(16) line.SetLineStyle(7) line.Draw("same") th1 = TLatex( 1450, 1340, "m_{#tilde{g}} - m_{#tilde{#chi}_{1}^{0}} = 2 #left(m_{W}+m_{b}#right)" ) th1.SetTextAngle(30) th1.SetTextColor(16) th1.SetTextSize(0.03) th1.Draw("same") # Draw m_gl - m_N1 = 2 m_t line2 = TLine(600, 255, 2050, 1680) line2.SetLineColor(16) line2.SetLineStyle(7) line2.Draw("same") th2 = TLatex(1550, 1240, "m_{#tilde{g}} - m_{#tilde{#chi}_{1}^{0}} = 2 m_{t}") th2.SetTextAngle(30) th2.SetTextColor(16) th2.SetTextSize(0.03) # th2.Draw("same") if "Dm" in hist.GetName(): line3 = TLine(600, 25, 2100, 25) line3.SetLineColor(16) line3.SetLineStyle(7) line3.Draw("same") th3 = TLatex( 1600, 40, "#Delta m = m_{#tilde{#chi}_{1}^{0}} - #left(m_{#tilde{g}} -2 m_{t} #right)" ) # th3.SetTextAngle(32) th3.SetTextColor(16) th3.SetTextSize(0.03) th3.Draw("same") hist.GetYaxis().SetTitle( "#Delta m_{#tilde{#chi}_{1}^{0}} (above diagonal) (GeV)") can.Update() directory = "/afs/cern.ch/user/o/othrif/workarea/results/v48/Plots/" + Dirbase #+"/Lumi"+str(luminosity) if not os.path.exists(directory): os.makedirs(directory) can.SaveAs(directory + "/" + name + "_" + hist.GetName() + ".pdf")
def setStyle(): TColor.InitializeColors() stops = array('d', [ 0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000 ]) red = array('d', [ 0.9764, 0.9956, 0.8186, 0.5301, 0.1802, 0.0232, 0.0780, 0.0592, 0.2082 ]) green = array('d', [ 0.9832, 0.7862, 0.7328, 0.7492, 0.7178, 0.6419, 0.5041, 0.3599, 0.1664 ]) blue = array('d', [ 0.0539, 0.1968, 0.3499, 0.4662, 0.6425, 0.7914, 0.8385, 0.8684, 0.5293 ]) TColor.CreateGradientColorTable(9, stops, red, green, blue, 255, 1.0) gStyle.SetHatchesLineWidth(1) gStyle.SetNumberContours(255) gStyle.SetNdivisions(505, "xyz") gStyle.SetTitleBorderSize(0) gStyle.SetTitleColor(1) gStyle.SetTitleStyle(3013) gStyle.SetTitleFillColor(0) gStyle.SetTitleX(0.05) gStyle.SetTitleW(0.4) gStyle.SetTitleY(0.965) gStyle.SetTitleH(0.065) gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasBorderSize(3) gStyle.SetCanvasColor(0) gStyle.SetPadColor(0) gStyle.SetPadBorderMode(0) gStyle.SetFuncWidth(3) gStyle.SetPadGridY(False) gStyle.SetPadGridX(False) gStyle.SetFrameLineWidth(1) gStyle.SetMarkerSize(5) gStyle.SetPadTickX(True) gStyle.SetPadTickY(True) #gStyle.SetPalette(1) gStyle.SetHistLineWidth(3) gStyle.SetHistLineColor(1) gStyle.SetOptStat(0) gStyle.SetOptFit(0) gStyle.SetStatW(0.25) gStyle.SetStatH(0.25) gStyle.SetStatX(0.9) gStyle.SetStatY(0.9) gStyle.SetStatColor(0) gStyle.SetStatFormat("6.4g") gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.05) gStyle.SetPadBottomMargin(0.16) gStyle.SetPadLeftMargin(0.12) font = 42 gStyle.SetTextSize(.055) gStyle.SetTextFont(font) gStyle.SetLabelFont(font, "x") gStyle.SetTitleFont(font, "x") gStyle.SetLabelFont(font, "y") gStyle.SetTitleFont(font, "y") gStyle.SetLabelFont(font, "z") gStyle.SetTitleFont(font, "z") gStyle.SetTitleSize(.055, "x") gStyle.SetTitleSize(.055, "y") gStyle.SetTitleSize(.05, "z") gStyle.SetLabelSize(.05, "x") gStyle.SetLabelSize(.05, "y") gStyle.SetLabelSize(.05, "z") gStyle.SetLabelOffset(0.014, "x") gStyle.SetLabelOffset(0.006, "y") gStyle.SetLabelOffset(0.008, "z") gStyle.SetTitleOffset(1, "y") gStyle.SetTitleXOffset(1.2) # use bold lines and markers gStyle.SetMarkerStyle(20) gStyle.SetMarkerColor(1) gStyle.SetMarkerSize(1.2) gStyle.SetLineStyleString(2, "[12 12]") # postscript dashes gStyle.SetPadTickX(1) gStyle.SetPadTickY(1)
gROOT.Reset() #============= root file input rootfile = "test.root" treeName = "tree" f0 = TFile(rootfile, "read") tree = f0.Get(treeName) print("=====> /// %15s //// is loaded. Total #Entry: %10d " % (rootfile, tree.GetEntries())) #============= Canvas Div = [1, 1] #x,y size = [800, 600] #x,y cScript = TCanvas("cScript", "cScript", 0, 0, size[0] * Div[0], size[1] * Div[1]) cScript.Divide(Div[0], Div[1]) for i in range(1, Div[0] * Div[1] + 1): cScript.cd(i).SetGrid() cScript.cd(1) gStyle.SetOptStat(1111111) gStyle.SetStatY(0.99) gStyle.SetStatX(0.99) gStyle.SetStatW(0.2) gStyle.SetStatH(0.1) #=============== tree.Draw("det")
p0Fit = fitresult.Parameter(0) # - dsMeanVal.getValV(); p0FitError = fitresult.ParError(0) print 'P0FIT = ', p0Fit, '\nDSMEANVAL = ', etaAvg.getValV( ), '\nP0END = ', p0End, '\n' hp0.Fill((p0Fit - p0End) / p0FitError) #break; from ROOT import gStyle, TStyle gStyle.SetOptFit(111) gStyle.SetOptStat(11) gStyle.SetStatW(gStyle.GetStatW() / 1.1) gStyle.SetStatH(gStyle.GetStatH() / 1.1) gStyle.SetStatX(gStyle.GetStatX()) gStyle.SetStatY(gStyle.GetStatY() - 0.05) currentTime = time.time() theHistCanvas = TCanvas() theHistCanvas.SetBottomMargin(0.2) theHistCanvas.SetRightMargin(0.05) hp1.Fit("gaus", "ILL") hp1.Draw() hp1.GetYaxis().SetTitleSize(0.05) hp1.GetXaxis().SetTitleSize(0.05) hp1.GetXaxis().SetTitleOffset(1.5) theHistCanvas.Update()
def initialization(batch=True, font=default_font): '''-- ROOT initialization --''' print "Initializing ROOT ..." # general gROOT.Reset() gROOT.SetBatch(batch) gROOT.SetStyle("Plain") # gStyle gStyle.SetFillColor(0) gStyle.SetCanvasColor(10) gStyle.SetLineWidth(1) gStyle.SetPalette(8) gStyle.SetTextFont(font) #gStyle.SetTextSize(30) # Frame gStyle.SetFrameBorderMode(0) gStyle.SetFrameFillColor(0) # Pad gStyle.SetPadBorderMode(0) gStyle.SetPadColor(0) gStyle.SetPadBottomMargin(0.1) gStyle.SetPadTopMargin(0.01) gStyle.SetPadLeftMargin(0.1) gStyle.SetPadRightMargin(0.01) gStyle.SetPadTickX(1) # make ticks be on all 4 sides. gStyle.SetPadTickY(1) gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) # histogram gStyle.SetHistFillStyle(0) gStyle.SetOptTitle(0) gStyle.SetTitleSize(0.22) gStyle.SetTitleFontSize(10) gStyle.SetTitleFont(font) gStyle.SetTitleFont(font, "xyz") gStyle.SetTitleYOffset(1.0) gStyle.SetTitleXOffset(1.0) gStyle.SetTitleXSize(0.04) gStyle.SetTitleYSize(0.04) gStyle.SetTitleX(.15) gStyle.SetTitleY(.98) gStyle.SetTitleW(.70) gStyle.SetTitleH(.05) # statistics box gStyle.SetOptStat(0) gStyle.SetStatFont(font) gStyle.SetStatFontSize(10) gStyle.SetStatX(.91) gStyle.SetStatY(.90) gStyle.SetStatW(.15) gStyle.SetStatH(.15) # axis labels gStyle.SetLabelFont(font) gStyle.SetLabelFont(font, "xyz") gStyle.SetLabelSize(10, "xyz") # gStyle.SetGridColor(1) gStyle.SetLegendBorderSize(1)
def drawDCS(fdbi,webdcs,chamber,c=None): if (c==None): c=TCanvas() jdict={} jdict['settings']={} gStyle.SetOptFit(1) c.Clear() #c.Divide(2,4) conn = sqlite3.connect(fdbi) conn.text_factory = str curs = conn.cursor() sql_dcs="select ATT,DEAD,TRET,TCOAX,TRIGGER,ACTIVE,START from webdcs WHERE dcs=%d" % webdcs curs.execute(sql_dcs) v=curs.fetchall() att=-1 dthr=-1 dead=-1 trig="UNKNOwN" if (len(v)<1): return jdict['settings']['dcs']=webdcs jdict['settings']['att']=v[0][0] jdict['settings']['dead']=v[0][1] jdict['settings']['tret']=v[0][2] jdict['settings']['tcoax']=v[0][3] jdict['settings']['trigger']=v[0][4] jdict['settings']['active']=v[0][5] jdict['settings']['start']=v[0][6] dirout="./results/dcs/%d_ATT%3.1f_DT%d_THR%d_%s/chamber%d/" % (webdcs,v[0][0],v[0][1],v[0][2]-500,v[0][4].replace('"','').replace(' ','_'),chamber) os.system("mkdir -p %s" % dirout) fout=open(dirout+"summary%d_ATT%3.1f_DT%d_THR%d_%s.txt" % (webdcs,v[0][0],v[0][1],v[0][2]-500,v[0][4].replace('"','').replace(' ','_')),"w") for x in v: fout.write("Cuts: %5.2f %d %d %d %s %d %s\n" % x) att=x[0] dead=x[1] dthr=x[2]-500 trig=x[4] sql_query=" select EFFCOR,DEFFC,(SELECT HV FROM runs WHERE runs.RUN=corana.RUN),DAQFEBRATE,DAQEFFLOSS,RUN,NCEVT,EFFC,CSIZE,NCLUS,XYFEBRATE,EFFBACK from corana WHERE RUN IN (SELECT RUN FROM runs WHERE DCS=%d) AND CHAMBER=%d" % (webdcs,chamber) curs.execute(sql_query) vo=curs.fetchall() if (len(vo)<1): return; hv=[] eff=[] dhv=[] deff=[] febrate=[] dfebrate=[] effloss=[] csize=[] nclus=[] effback=[] jdict['runs']={} jdict['runs']['effcor']=[] jdict['runs']['hv']=[] jdict['runs']['febrate']=[] jdict['runs']['effloss']=[] jdict['runs']['runid']=[] jdict['runs']['nevt']=[] jdict['runs']['effclu']=[] jdict['runs']['csize']=[] jdict['runs']['nclus']=[] jdict['runs']['xyrate']=[] jdict['runs']['effback']=[] for x in vo: if (x[1]==0): continue fout.write("Results: %5.2f %5.2f %5.2f %5.2f %5.2f %d %d %5.2f %5.2f %5.2f %5.2f %5.2f \n" % x) hv.append(x[2]) dhv.append(10.) eff.append(x[0]) deff.append(x[1]) febrate.append(x[3]) effloss.append(x[4]) csize.append(x[8]) nclus.append(x[9]) effback.append(x[11]) jdict['runs']['effcor'].append(x[0]) jdict['runs']['hv'].append(x[2]) jdict['runs']['febrate'].append(x[3]) jdict['runs']['effloss'].append(x[4]) jdict['runs']['runid'].append(x[5]) jdict['runs']['nevt'].append(x[6]) jdict['runs']['effclu'].append(x[7]) jdict['runs']['csize'].append(x[8]) jdict['runs']['nclus'].append(x[9]) jdict['runs']['xyrate'].append(x[10]) jdict['runs']['effback'].append(x[11]) stitle="DCS%d_TRG%s_ATT%3.1f_THR%d_DT%d_CH%d" % (webdcs,trig,att,dthr,dead,chamber) gr=buildTGraph("effi",hv,dhv,eff,deff,"HV effective (V)","efficiency (%)") func = TF1("func", "([0]/(1+ TMath::Exp(-[1]*(x-[2]))))", 6500,8200) func.SetParameters(90, 9.E-3, 7000) print(100, 9.E-3, 7100) gr.Fit(func,"","",6700,8200) hv95=func.GetX(func.GetParameter(0)*0.95) hv99=func.GetX(func.GetParameter(0)*0.99) print("HV95",hv95,hv95+150,hv99,hv99-hv95) wp=hv99 jdict['fit']={} jdict['fit']['Efficiency']=func.GetParameter(0) jdict['fit']['Slope']=func.GetParameter(1) jdict['fit']['HV50']=func.GetParameter(2) jdict['fit']['HV95']=hv95 jdict['fit']['HV99']=wp fout.write("FIT results: %f %f %f %f %f \n" % (func.GetParameter(0),func.GetParameter(1),func.GetParameter(2),hv95,wp)) title=stitle+"_HV95_%4.0f_WP_%4.0f" % (hv95,wp) gr.SetTitle(title) gStyle.SetStatX(0.85) gStyle.SetStatY(0.7) c.cd(1) gr.Draw("AP") c.Update() #val=raw_input() c.SaveAs(dirout+"%s.png" % title) tgr=[] tgr.append(buildTGraph1('FEB Rate',hv,febrate,'HV eff (V)','Rate (Hz/cm^2)')) tgr.append(buildTGraph1('Dead Time Loss',hv,effloss,'HV eff (V)','Dead time loss (%)')) tgr.append(buildTGraph1('Cluster Size',hv,csize,'HV eff (V)','Cluster size')) tgr.append(buildTGraph1('Cluster Number',hv,nclus,'HV eff (V)','Clusters')) tgr.append(buildTGraph1('Background Efficiency',hv,effback,'HV eff (V)','Efficiency (%)')) #val=raw_input() # grb=buildTGraph("background",hv,dhv,febrate,dfebrate,"HV effective (V)","FEB rate (Hz/cm^2)") # title=stitle # grb.SetTitle(title) # gStyle.SetStatX(0.85) # gStyle.SetStatY(0.7) # c.cd(2) # grb.Draw("AP") # c.Update() # c.SaveAs(dirout+"%s.png" % title) #val=raw_input() sql_query="select * from RESULTS WHERE CTIME>=(SELECT CFIRST FROM webdcs WHERE DCS=%d) AND CTIME<=(SELECT CLAST FROM webdcs WHERE DCS=%d)-200 AND HARDWARE='BMP'" % (webdcs,webdcs) curs.execute(sql_query) v=curs.fetchall() bmp=[] for x in v: bmp.append([x[3],json.loads(x[4].decode('latin-1').encode("utf-8"))]) #print(bmp) PB=0 TB=0 NB=0 for x in bmp: PB=PB+x[1]['pressure'] TB=TB+x[1]['temperature'] NB=NB+1 if (NB>0): PB=PB/NB TB=TB/NB+273.15 fout.write("Pressure: %d %5.2f %5.2f \n" % (NB,PB,TB)) jdict['BMP']={"P":PB,"T":TB} #val=raw_input() sql_query="select * from RESULTS WHERE CTIME>=(SELECT CFIRST FROM webdcs WHERE DCS=%d) AND CTIME<=(SELECT CLAST FROM webdcs WHERE DCS=%d)-200 AND HARDWARE='SY1527'" % (webdcs,webdcs) curs.execute(sql_query) v=curs.fetchall() a=[] for x in v: a.append([x[3],json.loads(x[4].decode('latin-1').encode("utf-8"))]) #print(a) #val=raw_input() if (chamber==1): chan=[4,5] else: chan=[1,2] idx=0 #tgr=[] jdict['HV']={} for ch in chan: x_t=[] y_vs=[] z_vm=[] w_im=[] g_g=[] chname="" first=0 for x in a: if (x[1]['channels'][ch]['rampup']==0): continue if (float(x[1]['channels'][ch]['vset']) < 5500.0): continue #print(float(x[1]['channels'][ch]['vset'])) if (first==0): first=x[0] x_t.append(x[0]-first) y_vs.append(x[1]['channels'][ch]['vset']) z_vm.append(x[1]['channels'][ch]['vout']) w_im.append(x[1]['channels'][ch]['iout']) g_g.append( x[1]['channels'][ch]['iout']/ x[1]['channels'][ch]['vout']) #print(ch,x) chname=x[1]['channels'][ch]['name'] if (len(x_t)<1): continue dy_vs=[] if (len(y_vs)>1): for i in range(0,len(y_vs)): if (i==0 and i!=len(y_vs)-1): dy_vs.append(y_vs[i+1]-y_vs[i]) continue if (i==len(y_vs)-1 and i!=0): dy_vs.append(y_vs[i]-y_vs[i-1]) continue dy_vs.append((y_vs[i+1]-y_vs[i-1])/2.) else: dy_vs.append(0) vset=[] vmon=[] veff=[] imon=[] nval=0 vmon_sum=0 vset_sum=0 imon_sum=0 for i in range(0,len(y_vs)): if (abs(dy_vs[i])>10): if (nval>0): vmon.append(vmon_sum/nval) vset.append(vset_sum/nval) imon.append(imon_sum/nval) if (NB>0): veff.append(calV(vmon_sum/nval,PB,TB)) else: veff.append(vmon_sum/nval) nval=0 vmon_sum=0 vset_sum=0 imon_sum=0 continue nval=nval+1 vmon_sum=vmon_sum+z_vm[i] vset_sum=vset_sum+y_vs[i] imon_sum=imon_sum+w_im[i] if (nval>0): vmon.append(vmon_sum/nval) vset.append(vset_sum/nval) imon.append(imon_sum/nval) if (NB>0): veff.append(calV(vmon_sum/nval,PB,TB)) else: veff.append(vmon_sum/nval) #print(chname,"VSET",vset) #print(chname,"VMON",vmon) #print(chname,"VEFF",veff) #print(chname,"IMON",imon) fout.write(chname+"\n") jdict['HV'][chname]={} jdict['HV'][chname]['vset']=vset jdict['HV'][chname]['vmon']=vmon jdict['HV'][chname]['imon']=imon jdict['HV'][chname]['veff']=veff for ip in range(0,len(vmon)): fout.write("%5.2f %5.2f %5.2f %5.2f \n" % (vset[ip],vmon[ip],veff[ip],imon[ip])) #tgr.append(buildTGraph1('V set vs t %s' % chname,x_t,y_vs,'t(s)','V set (V)')) tgr.append(buildTGraph1('V Mon vs t %s' % chname,x_t,z_vm,'t(s)','V mon (V)')) tgr.append(buildTGraph1('I Mon vs t %s' % chname,x_t,w_im,'t(s)','I mon ([m]A)')) tgr.append(buildTGraph1('I Mon vs V eff %s' % chname,veff,imon,'V eff(V)','I mon ([m]A)')) icd=3 for x in tgr: c.cd(icd) icd=icd+1 x.Draw("AP") c.Update() c.SaveAs(dirout+"%s.png" % x.GetTitle().replace(" ","_")) #val=raw_input() # resume chans=[] if (chamber == 2): chans=["COAX-BOT","COAX-TOP"] else: chans=["RETURN-BOT","RETURN-TOP"] jdict['AWP']={} jdict['AWP']['hv']=wp ihv=-1 for i in range(0,len(jdict['runs']['hv'])-1): if (wp>jdict['runs']['hv'][i] and wp<=jdict['runs']['hv'][i+1]): ihv=i break if (ihv!=-1): jdict['AWP']['plateau']=jdict['fit']['Efficiency'] jdict['AWP']['febrate']=approx(wp,jdict['runs']['hv'][ihv],jdict['runs']['hv'][ihv+1],jdict['runs']['febrate'][ihv],jdict['runs']['febrate'][ihv+1]) jdict['AWP']['effloss']=approx(wp,jdict['runs']['hv'][ihv],jdict['runs']['hv'][ihv+1],jdict['runs']['effloss'][ihv],jdict['runs']['effloss'][ihv+1]) jdict['AWP']['effcor']=approx(wp,jdict['runs']['hv'][ihv],jdict['runs']['hv'][ihv+1],jdict['runs']['effcor'][ihv],jdict['runs']['effcor'][ihv+1]) jdict['AWP']['csize']=approx(wp,jdict['runs']['hv'][ihv],jdict['runs']['hv'][ihv+1],jdict['runs']['csize'][ihv],jdict['runs']['csize'][ihv+1]) jdict['AWP']['nclus']=approx(wp,jdict['runs']['hv'][ihv],jdict['runs']['hv'][ihv+1],jdict['runs']['nclus'][ihv],jdict['runs']['nclus'][ihv+1]) for x in chans: ihv=-1 if (x in jdict['HV']): for i in range(0,len(jdict['HV'][x]['veff'])-1): if (wp>jdict['HV'][x]['veff'][i] and wp<=jdict['HV'][x]['veff'][i+1]): ihv=i break if (ihv!=-1): jdict['AWP'][x]=approx(wp,jdict['HV'][x]['veff'][ihv],jdict['HV'][x]['veff'][ihv+1],jdict['HV'][x]['imon'][ihv],jdict['HV'][x]['imon'][ihv+1]) itot=0 surf=0 if (chamber==1): surf=13000 if ('RETURN-TOP' in jdict['AWP']): itot=itot+jdict['AWP']['RETURN-TOP'] if ('RETURN-BOT' in jdict['AWP']): itot=itot+jdict['AWP']['RETURN-BOT'] if (chamber==2): surf=15000 if ('COAX-TOP' in jdict['AWP']): itot=itot+jdict['AWP']['COAX-TOP'] if ('COAX-BOT' in jdict['AWP']): itot=itot+jdict['AWP']['COAX-BOT'] if ('febrate' in jdict['AWP']): if (jdict['AWP']['febrate']!=0): jdict['AWP']['ITOT']=itot jdict['AWP']['QSEEN']=itot/jdict['AWP']['febrate']/surf*1E6 fout.write("%d|%5.1f|%5.0f|%5.2f|%5.2f|%5.2f|%5.2f|%5.1f|%5.1f|%5.1f|%5.1f\n" % (webdcs, jdict['settings']['att'], jdict['AWP']['hv'], jdict['AWP']['plateau'], jdict['AWP']['effcor'], jdict['AWP']['effloss'], jdict['AWP']['plateau']-jdict['AWP']['effloss'], jdict['AWP']['febrate'], jdict['AWP']['ITOT'], jdict['AWP']['QSEEN'],jdict['AWP']['csize'])) with open(dirout+'summary.json', 'w') as outfile: dd= json.dumps(jdict,sort_keys=True, indent=2,separators=(',', ': ')) outfile.write(dd) outfile.close() fout.close() return jdict
def applyRootStyle(): from ROOT import gROOT, gStyle, kWhite, kBlack, TColor # Start from a plain default gROOT.SetStyle("Plain") lhcbMarkerType = 8 lhcbMarkerSize = 0.8 lhcbFont = 62 lhcbStatFontSize = 0.02 lhcbStatBoxWidth = 0.12 lhcbStatBoxHeight = 0.12 lhcbWidth = 1 lhcbTextSize = 0.05 lhcbLabelSize = 0.035 lhcbAxisLabelSize = 0.035 lhcbForeColour = kBlack gStyle.SetFrameBorderMode(0) gStyle.SetPadBorderMode(0) # canvas options gStyle.SetCanvasBorderSize(0) gStyle.SetCanvasBorderMode(0) # fonts gStyle.SetTextFont(lhcbFont) gStyle.SetTextSize(lhcbTextSize) gStyle.SetLabelFont(lhcbFont, "x") gStyle.SetLabelFont(lhcbFont, "y") gStyle.SetLabelFont(lhcbFont, "z") gStyle.SetLabelSize(lhcbLabelSize, "x") gStyle.SetLabelSize(lhcbLabelSize, "y") gStyle.SetLabelSize(lhcbLabelSize, "z") gStyle.SetTitleFont(lhcbFont) gStyle.SetTitleSize(lhcbAxisLabelSize, "x") gStyle.SetTitleSize(lhcbAxisLabelSize, "y") gStyle.SetTitleSize(lhcbAxisLabelSize, "z") gStyle.SetTitleColor(kWhite) gStyle.SetTitleFillColor(kWhite) gStyle.SetTitleColor(kBlack) gStyle.SetTitleBorderSize(0) gStyle.SetTitleTextColor(kBlack) # set title position gStyle.SetTitleX(0.15) gStyle.SetTitleY(0.97) # turn off Title box gStyle.SetTitleBorderSize(0) gStyle.SetTitleTextColor(lhcbForeColour) gStyle.SetTitleColor(lhcbForeColour) # use bold lines and markers gStyle.SetLineWidth(lhcbWidth) gStyle.SetFrameLineWidth(lhcbWidth) gStyle.SetHistLineWidth(lhcbWidth) gStyle.SetFuncWidth(lhcbWidth) gStyle.SetGridWidth(lhcbWidth) gStyle.SetLineStyleString(2, "[12 12]") gStyle.SetMarkerStyle(lhcbMarkerType) gStyle.SetMarkerSize(lhcbMarkerSize) # Grid # gStyle.SetGridStyle(3) # label offsets gStyle.SetLabelOffset(0.015) # by default, do not display histogram decorations: gStyle.SetOptStat(1111) # show probability, parameters and errors gStyle.SetOptFit(1011) # look of the statistics box: gStyle.SetStatBorderSize(1) gStyle.SetStatFont(lhcbFont) gStyle.SetStatFontSize(lhcbStatFontSize) gStyle.SetStatX(0.9) gStyle.SetStatY(0.9) gStyle.SetStatW(lhcbStatBoxWidth) gStyle.SetStatH(lhcbStatBoxHeight) # put tick marks on top and RHS of plots gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) # histogram divisions gStyle.SetNdivisions(505, "x") gStyle.SetNdivisions(510, "y") # Style for 2D zcol plots NRGBs = 5 NCont = 255 from array import array stops = array('d', [0.00, 0.34, 0.61, 0.84, 1.00]) red = array('d', [0.00, 0.00, 0.87, 1.00, 0.51]) green = array('d', [0.00, 0.81, 1.00, 0.20, 0.00]) blue = array('d', [0.51, 1.00, 0.12, 0.00, 0.00]) TColor().CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont) gStyle.SetNumberContours(NCont) # Force the style gROOT.ForceStyle()
def closureTest_plots(filename): f = BareRootFile(filename) tree = f.Get('closureTest') gStyle.SetStatX(0.9) gStyle.SetStatY(0.9) gStyle.SetStatW(0.2) gStyle.SetStatH(0.14) hist1 = TH1F('hist1', '', 55, 0.9, 2.0) hist2 = TH1F('hist2', '', 55, 0.9, 2.0) condition = ('fit_overlapDiff>=0 && temp_overlapDiff>=0 && ' 'fit_chisq/fit_dof<=2 && temp_chisq/temp_dof<=2') tree.Draw('temp_chisq/temp_dof>>hist1', condition) tree.Draw('fit_chisq/fit_dof>>hist2', condition) for i, hist in [(0, hist1), (1, hist2)]: hist.SetLineColor(colors[i]) hist.SetLineWidth(3) maxi = max(hist1.GetMaximum(), hist2.GetMaximum()) * 1.1 plot = SingleHistBase(hist1, 'hist_numberPerChisq', fill=None, workinprogress=wip) gStyle.SetOptStat(10) plot._xtitle = '#chi^{2}/d.o.f.' plot._ytitle = 'number of toys' plot.yrange(0.0, maxi) leg = TLegend(0.65, 0.75, 0.89, 0.85) leg.SetBorderSize(0) leg.AddEntry(hist1, 'DG fit', 'L') leg.AddEntry(hist2, 'SupDG fit', 'L') plot.draw() hist2.Draw('SAMEH') leg.Draw() plot.save_pdf() plot.Close() hist3 = TH2F('hist3', '', 31, -0.05, 3.05, 31, -0.05, 3.05) tree.Draw('100*temp_overlapDiff:100*fit_overlapDiff>>hist3', condition) one = TF1('one', 'x', -10.0, 10.0) one.SetLineColor(1) plot = SingleHistBase(hist3, 'correctionDGvsSupDG', fill=None, workinprogress=wip) plot.add(one) plot._drawoption = 'BOX' plot._xtitle = 'correction [%] from SupDG fit' plot._ytitle = 'correction [%] from DG fit' plot._above = True plot.draw() plot.save_pdf() plot.Close() hist4 = TH2F('hist4', '', 22, 0.95, 1.5, 22, 0.95, 1.5) tree.Draw('temp_chisq/temp_dof:fit_chisq/fit_dof>>hist4', condition) plot = SingleHistBase(hist4, 'chisqDGvsSupDG', fill=None, workinprogress=wip) plot.add(one) plot._drawoption = 'BOX' plot._xtitle = '#chi^{2}/d.o.f. of SupDG fit' plot._ytitle = '#chi^{2}/d.o.f. of DG fit' plot._above = True plot.draw() plot.save_pdf() plot.Close() gStyle.SetStatX(0.9) gStyle.SetStatY(0.83) gStyle.SetStatW(0.3) gStyle.SetStatH(0.08) #bins_csq = [(0.0, 1.1), (1.1, 1.3), (1.3, 1.6), (1.6, 2.0)] #bins_cor = [(0.0, 0.5), (0.5, 1.0), (1.0, 1.5), (1.5, 2.0), (2.0, 2.5)] #bins_csq = [(1.07, 1.13), (1.06, 1.11), (1.3, 1.5), (1.08, 1.17), (1.1, 1.2)] #bins_cor = [(0.3, 0.8), (0.9, 1.2), (0.1, 0.5), (0.4, 0.7), (0.3, 1.1)] bins_csq = [(0.99, 1.06), (0.98, 1.07), (0.99, 1.10), (1.02, 1.06), (1.00, 1.06), (1.00, 1.04)] bins_cor = [(0.9, 1.9), (0.4, 1.6), (0.6, 1.5), (0.6, 1.9), (1.0, 1.3), (0.3, 1.5)] means = { mod: [[0.0 for __ in bins_cor] for __ in bins_csq] for mod in ('DG', 'SupDG') } meane = { mod: [[0.0 for __ in bins_cor] for __ in bins_csq] for mod in ('DG', 'SupDG') } rmses = { mod: [[0.0 for __ in bins_cor] for __ in bins_csq] for mod in ('DG', 'SupDG') } rmser = { mod: [[0.0 for __ in bins_cor] for __ in bins_csq] for mod in ('DG', 'SupDG') } #for i, (csq_lo, csq_hi) in enumerate(bins_csq): # for j, (cor_lo, cor_hi) in enumerate(bins_cor): for i, ((csq_lo, csq_hi), (cor_lo, cor_hi)) in enumerate(zip(bins_csq, bins_cor)): j = i name = 'hist_{{0}}_{0}csq{1}_{2}cor{3}' \ .format(csq_lo, csq_hi, cor_lo, cor_hi) fields = '100*({0}_overlapDiff-toy_overlapDiff)>>hist' condition = ( '100*{{0}}_overlapDiff>={0} && 100*{{0}}_overlapDiff<{1} && ' '{{0}}_chisq/{{0}}_dof>={2} && {{0}}_chisq/{{0}}_dof<{3} && ' 'fit_overlapDiff>=0 && temp_overlapDiff>=0 && ' 'fit_chisq/fit_dof<=2 && temp_chisq/temp_dof<=2').format( cor_lo, cor_hi, csq_lo, csq_hi) xtitle = 'correction [%] from {0} fit #minus true correction [%]' line1 = '{0} < correction < {1}'.format(cor_lo, cor_hi) line2 = '{0} < #chi^{{2}}/d.o.f. < {1}'.format(csq_lo, csq_hi) gStyle.SetOptStat(2210) for prefix, modname in (('temp', 'DG'), ('fit', 'SupDG')): hist = TH1F('hist', '', 41, -2.05, 2.05) hist.StatOverflows() tree.Draw(fields.format(prefix), condition.format(prefix)) plot = SingleHistBase(hist, name.format(modname), fill=None, workinprogress=wip) gStyle.SetOptStat(2210) plot._xtitle = xtitle.format(modname) plot._ytitle = 'number of toys' plot.xrange(-2.05, 2.05) plot.yrange(0.0, plot._graph.GetMaximum() * 1.2) pave = plot.add_pave(0.6, 0.83, 0.9, 0.9, border=True) pave(line1) pave(line2) plot.draw() plot.save_pdf() means[modname][i][j] = plot._graph.GetMean() meane[modname][i][j] = plot._graph.GetMeanError() rmses[modname][i][j] = plot._graph.GetRMS() rmser[modname][i][j] = plot._graph.GetRMSError() plot.Close() multi = TMultiGraph('multi', '') for k, modname in enumerate(('DG', 'SupDG')): for i, (csq_lo, csq_hi) in enumerate(bins_csq): xval = array( 'd', [j - 0.35 + k * 0.4 + i * 0.1 for j in range(len(bins_cor))]) xerr = array('d', [0.0] * len(bins_cor)) yval = array('d', means[modname][i]) yerr = array('d', rmses[modname][i]) graph = TGraphErrors(len(bins_cor), xval, yval, xerr, yerr) graph.SetName('graph{0}{1}'.format(k, i)) graph.SetMarkerStyle(22 + k) graph.SetMarkerColor(colors[i]) graph.SetLineColor(colors[i]) multi.Add(graph) minvalues = [ means[mod][i][j] - rmses[mod][i][j] for j in range(len(bins_cor)) for i in range(len(bins_csq)) for mod in ('DG', 'SupDG') ] maxvalues = [ means[mod][i][j] + rmses[mod][i][j] for j in range(len(bins_cor)) for i in range(len(bins_csq)) for mod in ('DG', 'SupDG') ] mini, maxi = min(minvalues), max(maxvalues) mini, maxi = mini - 0.1 * (maxi - mini), maxi + 0.3 * (maxi - mini) hist = TH2F('axishist', '', len(bins_cor), -0.5, len(bins_cor) - 0.5, 100, mini, maxi) for j, (cor_lo, cor_hi) in enumerate(bins_cor): hist.GetXaxis().SetBinLabel(j + 1, '{0}% #minus {1}%'.format(cor_lo, cor_hi)) leg1 = TLegend(0.53, 0.78, 0.63, 0.86) leg1.SetBorderSize(0) dgmarker = TMarker(0.0, 0.0, 22) supdgmarker = TMarker(0.0, 0.0, 23) leg1.AddEntry(dgmarker, 'DG', 'P') leg1.AddEntry(supdgmarker, 'SupDG', 'P') leg2 = TLegend(0.65, 0.75, 0.89, 0.89) leg2.SetBorderSize(0) csqmarker = TMarker(0.0, 0.0, 1) for i, (csq_lo, csq_hi) in enumerate(bins_csq): title = '{0} < #chi^{{2}}/d.o.f. < {1}'.format(csq_lo, csq_hi) entry = leg2.AddEntry(csqmarker, title, 'L') entry.SetMarkerColor(colors[i]) entry.SetLineColor(colors[i]) zero = TF1('zero', '0.0', -1.0, 10.0) zero.SetLineColor(1) zero.SetLineStyle(2) plot = SingleHistBase(hist, name='differenceDoubleDifferential', fill=None, workinprogress=wip) plot._xtitle = 'correction from fit' plot._ytitle = 'correction [%] from fit #minus true correction [%]' plot.xrange(-0.5, len(bins_cor) - 0.5) plot.yrange(mini, maxi) plot._drawoption = 'AXIS' plot.draw() plot.xaxis().SetNdivisions(len(bins_cor), False) plot.xaxis().SetLabelSize(0.03) zero.Draw('SAME') multi.Draw('P') leg1.Draw() leg2.Draw() plot.save_pdf() plot.Close() bcid = (41, 281, 872, 1783, 2063) DGcor1 = array('d', [0.809, 0.392, 0.846, 0.731, 0.497]) DGerr1 = array('d', [0.548, 0.567, 0.984, 0.984, 1.018]) DGcor2 = array('d', [1.145, 0.799, 1.58, 1.465, 1.281]) DGerr2 = array('d', [0.432, 0.395, 0.656, 0.656, 0.649]) DGxval = array('d', [j - 0.1 for j in range(5)]) SupDGcor1 = array('d', [0.823, 0.761, 1.458, 0.986, 1.012]) SupDGerr1 = array('d', [0.513, 0.513, 0.499, 0.513, 0.499]) SupDGcor2 = array('d', [0.978, 0.916, 1.532, 1.141, 1.086]) SupDGerr2 = array('d', [0.489, 0.489, 0.493, 0.489, 0.493]) SupDGxval = array('d', [j + 0.1 for j in range(5)]) xerr = array('d', [0.0] * 5) for fill, values in [ (4266, { 'DGcor': [1.021, 1.057, 0.968, 1.084, 1.114], 'DGerr': [(e**2 + 0.74**2)**0.5 for e in (0.118, 0.124, 0.119, 0.117, 0.119)], 'SupDGcor': [1.402, 1.411, 1.164, 1.549, 1.589], 'SupDGerr': [(e**2 + 0.45**2)**0.5 for e in (0.106, 0.110, 0.108, 0.106, 0.115)], 'bcids': [51, 771, 1631, 2211, 2674] }), (4954, { 'DGcor': [0.799, 0.398, 0.845, 0.724, 0.502], 'DGerr': [(e**2 + 0.79**2)**0.5 for e in (0.137, 0.124, 0.122, 0.130, 0.116)], 'SupDGcor': [0.794, 0.694, 1.642, 0.983, 0.993], 'SupDGerr': [(e**2 + 0.50**2)**0.5 for e in (0.126, 0.112, 0.186, 0.102, 0.144)], 'bcids': [41, 281, 872, 1783, 2063] }), (4937, { 'DGcor': [0.649, 0.494, 0.575, 0.527, 0.602], 'DGerr': [(e**2 + 0.85**2)**0.5 for e in (0.127, 0.115, 0.120, 0.125)], 'SupDGcor': [0.377, 0.611, 1.137, 0.453, 1.840], 'SupDGerr': [(e**2 + 0.56**2)**0.5 for e in (0.100, 0.105, 0.288, 0.161, 0.207)], 'bcids': [81, 875, 1610, 1690, 1730] }), (6016, { 'DGcor': [0.146, 0.394, 0.377, 0.488, 0.184], 'DGerr': [(e**2 + 1.15**2)**0.5 for e in (0.110, 0.114, 0.118, 0.123, 0.109)], 'SupDGcor': [0.760, 0.953, 1.048, 0.847, 0.373], 'SupDGerr': [(e**2 + 0.79**2)**0.5 for e in (0.219, 0.094, 0.189, 0.098, 0.169)], 'bcids': [41, 281, 872, 1783, 2063] }) ]: bcid = values['bcids'] DGcor = array('d', values['DGcor']) DGerr = array('d', values['DGerr']) DGxvl = array('d', [j - 0.1 for j in range(len(bcid))]) SupDGcor = array('d', values['SupDGcor']) SupDGerr = array('d', values['SupDGerr']) SupDGxvl = array('d', [j + 0.1 for j in range(len(bcid))]) xerr = array('d', [0.0] * len(bcid)) maxi = max(max([v + e for v, e in zip(DGcor, DGerr)]), max([v + e for v, e in zip(SupDGcor, SupDGerr)])) mini = min(min([v - e for v, e in zip(DGcor, DGerr)]), min([v - e for v, e in zip(SupDGcor, SupDGerr)])) maxi, mini = maxi + 0.2 * (maxi - mini), mini - 0.1 * (maxi - mini) graphDG = TGraphErrors(len(bcid), DGxvl, DGcor, xerr, DGerr) graphDG.SetName('graphDG') graphSupDG = TGraphErrors(len(bcid), SupDGxvl, SupDGcor, xerr, SupDGerr) graphSupDG.SetName('graphSupDG') multi = TMultiGraph('multi', '') for i, graph in [(0, graphDG), (1, graphSupDG)]: graph.SetMarkerStyle(22 + i) graph.SetMarkerColor(colors[i]) graph.SetLineColor(colors[i]) multi.Add(graph) leg = TLegend(0.15, 0.80, 0.5, 0.83) leg.SetNColumns(2) leg.SetBorderSize(0) leg.AddEntry(graphDG, 'DG fit', 'PL') leg.AddEntry(graphSupDG, 'SupDG fit', 'PL') axishist = TH2F('axishist', '', len(bcid), -0.5, len(bcid) - 0.5, 100, mini, maxi) for i, bx in enumerate(bcid): axishist.GetXaxis().SetBinLabel(i + 1, '{0}'.format(bx)) plot = SingleHistBase(axishist, name='Fill{0}biased'.format(fill), fill=fill, workinprogress=wip) plot._xtitle = 'BCID' plot._ytitle = 'correction [%] from fit' plot.xrange(-0.5, len(bcid) - 0.5) plot.yrange(mini, maxi) plot._drawoption = 'AXIS' plot.draw() plot.xaxis().SetNdivisions(len(bcid), False) plot.xaxis().SetLabelSize(0.03) multi.Draw('P') leg.Draw() plot.save_pdf() plot.Close() print print 'Fill', fill for bx, cor, err in zip(bcid, SupDGcor, SupDGerr): print 'BCID {0}:\t{1:.2f} +- {2:.2f}'.format(bx, cor, err) print
#data.Draw("x>>hdata(200,359.5,379.5)","x>0 && y>0 && pix>250","colz") #c.Print(outfilename+".pdf"); c.cd(iHdu + 1 * len(ohdus) + 1) data.Draw("y>>h{0}y(700,-0.5,699.5)".format(ohdus[iHdu]), "x>=8 && x<=369", "colz") c.cd(iHdu + 2 * len(ohdus) + 1) data.Draw("y>>h{0}y2(26,0.5,624.5)".format(ohdus[iHdu]), "x>=8 && x<=369", "colz") h = gDirectory.Get("h{0}y2".format(ohdus[iHdu])) h.Sumw2() h.Fit("linfunc", "Q") gStyle.SetStatX(0.4) c.cd(iHdu + 2 * len(ohdus) + 1) latex.DrawLatex(0.4, 0.025, "OHDU{0}".format(ohdus[iHdu])) c.cd() c.Print(outfilename + ".pdf") #data.Draw("y>>hdata(200,600,650)","x>=8 && x<=369","colz") #c.Print(outfilename+".pdf"); #data.Draw("y>>hdata(70,-0.5,699.5)","x>=8 && x<=100","colz") #c.Print(outfilename+".pdf"); #data.Draw("y>>hdata(70,-0.5,699.5)","x>369","colz") #c.Print(outfilename+".pdf");
#parser.add_option('--ML', type='string', action='store', # default= 'DNN', # dest='ML', # help='Which ML method? DNN, BDT, MLP, or kNN') (options, args) = parser.parse_args() argv = [] folder = "varplots_" + str(options.n) + "_" + str(options.layers) #ML = str(options.ML) #eff = options.eff gStyle.SetStatY(0.93) gStyle.SetStatX(0.25) gStyle.SetStatW(0.15) gStyle.SetStatH(0.1) xlist = ["Hit_plane0", "Hit_plane1", "Hit_plane6", "Hit_plane7"] uvlist = ["Hit_plane2", "Hit_plane3", "Hit_plane4", "Hit_plane5"] planes = xlist + uvlist ########### START LOOP OVER EFFICIENCIES ########### #effs = [90,91,92,93,94,95,96,97,98,99,100] effs = [100] for eff in effs: TMVA.Tools.Instance()
#COLORS = [kRed, kCyan+1, kGreen+2, kViolet+1] #MARKERS = [21, 22, 29, 33] COLORS = [kRed, kBlue, kOrange, kCyan, kGreen, kBlack, kViolet, kMagenta] COLORSprime = list(c + 2 for c in COLORS) COLORS = COLORS + COLORSprime MARKERS = list(i for i in xrange(20, 36)) # Stat box contains # e: entries # m: mean # r: rms gStyle.SetOptStat("emr") gStyle.SetStatW(0.16) gStyle.SetStatX(1.0) gStyle.SetStatY(0.9) def plotMultiGraph(dataReadings, vals, title, xTitle, yTitle, outF): """ Plots several TGraphs using TMultiGraph """ mg = TMultiGraph() cv = TCanvas(outF, "cv", 1200, 1200) l = TLegend(0.9, 0.7, 1.0, 0.9) pad = TPad("p", "p", 0.05, 0.05, 1.0, 1.0) pad.cd() for a in xrange(len(vals)): print "vals[a] = {0}".format(vals[a]) l.AddEntry(vals[a], "Value %d" % (a + 1), "pl")