def GetYaxisRanges(can, check_all=False, ignorezeros=False, ignoreErrors=False): # # check_all is if you want to check the maximum extent of all the histograms you plotted. # from ROOT import TGraph, TH1, THStack, TMath, TEfficiency ymin = 999999999 ymax = -999999999 for i in can.GetListOfPrimitives(): if issubclass(type(i), TGraph): ymin = min(ymin, TMath.MinElement(i.GetN(), i.GetY())) ymax = max(ymax, TMath.MaxElement(i.GetN(), i.GetY())) if not check_all: return ymin, ymax elif issubclass(type(i), TH1): ysum = 0 for bin in range(i.GetNbinsX()): ysum = ysum + i.GetBinContent(bin + 1) if ysum == 0: ignorezeros = 0 for bin in range(i.GetNbinsX()): y = i.GetBinContent(bin + 1) if ignoreErrors: ye = 0 else: ye = i.GetBinError(bin + 1) if ignorezeros and y == 0: continue ymin = min(ymin, y - ye) ymax = max(ymax, y + ye) if not check_all: return ymin, ymax elif issubclass(type(i), TEfficiency): ysum = 0 for bin in range(i.GetTotalHistogram().GetNbinsX()): ysum = ysum + i.GetTotalHistogram().GetBinContent(bin + 1) if ysum == 0: ignorezeros = 0 for bin in range(i.GetTotalHistogram().GetNbinsX()): y = i.GetTotalHistogram().GetBinContent(bin + 1) if ignoreErrors: ye = 0 else: ye = i.GetTotalHistogram().GetBinError(bin + 1) if ignorezeros and y == 0: continue ymin = min(ymin, y - ye) ymax = max(ymax, y + ye) if not check_all: return ymin, ymax elif issubclass(type(i), THStack): ymin = i.GetMinimum() ymax = i.GetMaximum() return ymin, ymax
def GetYaxisRanges(can, check_all=False): # # check_all is if you want to check the maximum extent of all the histograms you plotted. # from ROOT import TGraph, TH1, TMath, THStack ymin = 999999999 ymax = -999999999 primitives = list(can.GetListOfPrimitives()) if can.GetPrimitive('stack'): the_stack = list(can.GetPrimitive('stack').GetHists()) primitives += the_stack for i in primitives: if issubclass(type(i), TGraph): ymin = min(ymin, TMath.MinElement(i.GetN(), i.GetY())) ymax = max(ymax, TMath.MaxElement(i.GetN(), i.GetY())) if not check_all: return ymin, ymax if issubclass(type(i), TH1): for bin in range(i.GetNbinsX()): if bin < i.GetXaxis().GetFirst(): continue # X-axis SetRange should be done first if bin > i.GetXaxis().GetLast(): continue # X-axis SetRange should be done first y = i.GetBinContent(bin + 1) ye = i.GetBinError(bin + 1) ymin = min(ymin, y - ye) ymax = max(ymax, y + ye) if not check_all: return ymin, ymax if issubclass(type(i), THStack): ymin = min(ymin, i.GetMinimum()) ymax = max(ymax, i.GetMaximum()) if not check_all: return ymin, ymax # print 'GetYaxisRanges',ymin,ymax return ymin, ymax
def GetYMax(graphs): ymax = -99999. for graph in graphs: if TMath.MaxElement(graph.GetN(), graph.GetY()) > ymax: ymax = TMath.MaxElement(graph.GetN(), graph.GetY()) return ymax
def GetXMax(graphs): xmax = -99999. for graph in graphs: if TMath.MaxElement(graph.GetN(), graph.GetX()) > xmax: xmax = TMath.MaxElement(graph.GetN(), graph.GetX()) return xmax
def overlay(graphs, header, addon, runtype, tlabel, comparePerReleaseSuffix=""): dir_translator = { "1p": "1prong", "1ppi0": "1prongpizero", "2p": "2prong", "3p": "3prong", "3ppi0": "3prongpizero", "oldDM": "oldDM", "newDM": "newDM", "newDMwo2p": "newDMwithout2prong", } ymin = min(TMath.MinElement(g.GetN(), g.GetY()) for g in graphs) ymax = max(TMath.MaxElement(g.GetN(), g.GetY()) for g in graphs) canvas = TCanvas() leg = TLegend(0.2, 0.7, 0.5, 0.9) configureLegend(leg, 1) for i_graph, graph in enumerate(graphs): graph.GetYaxis().SetTitle('efficiency') graph.SetLineWidth(2) graph.SetMarkerSize(1) graph.SetMaximum(ymax * 1.4) graph.SetMinimum(ymin * 0.80) # hist.GetXaxis().SetLimits(hist.GetXaxis().GetXmin()+(3*(ii-3)), # hist.GetXaxis().GetXmax()+(3*(ii-3))) graph.Draw('ap' if i_graph == 0 else 'psame') legname = graph.GetName() # graph.GetPoint(0, x, y) leg.AddEntry(graph, legname, 'lep') leg.Draw() tex = TLatex( (graphs[-1].GetXaxis().GetXmin() + 0.01 * (graphs[-1].GetXaxis().GetXmax() - graphs[-1].GetXaxis().GetXmin())), ymax * 1.4, addon.replace('tau_', '')) tex.SetTextAlign(10) tex.SetTextFont(42) tex.SetTextSize(0.03) tex.Draw() xshift = 0.87 if tlabel.find('QCD') != -1: xshift = 0.6 if runtype.find('TTbarTau') != -1: xshift = 0.78 tex2 = TLatex( (graphs[-1].GetXaxis().GetXmin() + xshift * (graphs[-1].GetXaxis().GetXmax() - graphs[-1].GetXaxis().GetXmin())), ymax * 1.4, tlabel) tex2.SetTextAlign(10) tex2.SetTextFont(42) tex2.SetTextSize(0.03) tex2.Draw() eta = '_eta' if '_eta' in header else '' dir_name = header.split('_')[0] save( canvas, 'compare_' + runtype + comparePerReleaseSuffix + '/' + dir_name + eta + '/' + header) try: directory2 = dir_translator[header.split('_')[1]] save( canvas, 'compare_' + runtype + comparePerReleaseSuffix + '/' + directory2 + eta + '/' + header) except (IndexError, KeyError): pass save( canvas, 'compare_' + runtype + comparePerReleaseSuffix + '/all' + eta + '/' + header)
#HOTower = '(HODigi[2]+HODigi[3]+HODigi[4]+HODigi[5]+HODigi[6]+HODigi[7])' HOTower = '(HODigi[3]+HODigi[4]+HODigi[5]+HODigi[6])' if opts.hb: HOTower = '(HBDigi[3][{0}]+HBDigi[4][{0}]+HBDigi[5][{0}]+HBDigi[6][{0}])'.format( opts.depth) ## print '{0}'.format(HOTower),\ ## '(eta,phi): ({0:0.2f},{1:0.2f})'.format(event.HBTableEta, ## event.HBTablePhi) dataTree.Draw('{0}'.format(HOTower), pedCut, 'goff') havePeds = False if (dataTree.GetSelectedRows() > 1): minPed = TMath.MinElement(dataTree.GetSelectedRows(), dataTree.GetV1()) maxPed = TMath.MaxElement(dataTree.GetSelectedRows(), dataTree.GetV1()) pedRms = TMath.RMS(dataTree.GetSelectedRows(), dataTree.GetV1()) havePeds = True else: minPed = -6. maxPed = 10. pedRms = 1.2 minPed = int(minPed) - 1.5 maxPed = int(maxPed) + 1.5 while int((maxPed - minPed) / 2.) * 2. < (maxPed - minPed): maxPed += 1. minMip = int(minPed) - 0.5 binWidth = 1. if opts.sipm:
h_err = h_bkg.Clone() h_err.SetFillColorAlpha(12, 0.3) # Set grey colour (12) and alpha (0.3) h_err.SetMarkerSize(0) h_err.Draw('E2SAME') h_sig.SetLineColor(ROOT.kRed) h_sig.Draw('HISTSAME') h_err_sig = h_sig.Clone() h_err_sig.SetFillColorAlpha(2, 0.3) # Set grey colour (12) and alpha (0.3) h_err_sig.SetMarkerSize(0) h_err_sig.Draw('E2SAME') h_dat.Draw('PSAME') h_bkg.SetMaximum(TMath.MaxElement(h_dat.GetN(), h_dat.GetY()) * 1.2) #signal strenght tree = fin.Get('tree_fit_sb') signal_strenght = tree.GetLeaf('r') signal_strenght_HiErr = tree.GetLeaf('rHiErr') signal_strenght_LoErr = tree.GetLeaf('rLoErr') tree.GetEntry(0) signal_strenght = signal_strenght.GetValue() signal_strenght_HiErr = signal_strenght_HiErr.GetValue() signal_strenght_LoErr = signal_strenght_LoErr.GetValue() #pavetext pt = ROOT.TPaveText(0.6, 0.7, 0.8, 0.5, "NBNDC") pt.AddText('#mu = ' + str(signal_strenght)) pt.AddText('#sigma_{#mu}^{up} = ' + str(signal_strenght_HiErr))
def Measure_Integral(AllRuns, Title, RootName, WID): FNumber = len(AllRuns) xIntegral = array("d", xrange(0, FNumber)) yIntegral = array("d", xrange(0, FNumber)) yIntegralErrUp = array("d", xrange(0, FNumber)) yIntegralErrDown = array("d", xrange(0, FNumber)) xIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMSErrUp = array("d", xrange(0, FNumber)) yIntegral_RMSErrDown = array("d", xrange(0, FNumber)) xRatio = array("d", xrange(0, FNumber)) yRatio = array("d", xrange(0, FNumber)) xSingleEv = array("d", xrange(0, 40)) ySingleEv = array("d", xrange(0, 40)) OutFile = TFile(RootName, "RECREATE") num = -1 iAmp = 0 for Fname in AllRuns: num += 1 iAmp += 1 f = open(Fname) # data = getData(f) tdc = getTDCValues(f) M = TH1F(Fname, Fname, 200, 0, 100) x = array("d", xrange(0, 1001)) y = array("d", xrange(0, 1001)) for event in xrange(0, 995): pedSum = 0 sigSum = 0 Signal = 0 Pedestal = 0 for BX in xrange(0, 40): # print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", tdc[event][link][BX][linkChannel] # print BX # print event # print "data=", data[event][link][BX][linkChannel] # print "TDC=", tdc[event][link][BX][linkChannel] # print "\n" # print "@@@@@@@@-------> [event] ", event tdcValue = tdc[event][link][BX][linkChannel] # print "@@@@@@@@-------> [event] ", event if (WID[num] < 10 and BX == 20 and tdc[event][link][BX][linkChannel] != 31.5): sigSum += tdcValue if (WID[num] > 10 and BX == 21 and tdc[event][link][BX][linkChannel] != 31.5): sigSum += tdcValue # print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", tdc[event][link][BX][linkChannel] # if BX > 19 and BX < 25: sigSum += adcValue # if BX > 18 and BX < 26: print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", data[event][link][BX][linkChannel] # print "---------------------> sigSum= ",sigSum y[event] = sigSum M.Fill(y[event]) histMean = M.GetMean() histRMS = M.GetStdDev() highVal = histMean + 4 * histRMS lowVal = histMean - 4 * histRMS highValAx = histMean + 6 * histRMS lowValAx = histMean - 6 * histRMS canvas = MakeCanvas("asdf", "asdf", 800, 800) canvas.Update() MyGr = TGraph(len(x), x, y) mfit = TF1("fit", "gaus", lowVal, highVal) M.Fit(mfit, "R0", "") FitParam = mfit.GetParameters() # FitParErr=mfit.GetParError() integral = histMean if FitParam[1] < 1.5 * histMean: integral = round(FitParam[1], 4) integral_RMS = histRMS if round(FitParam[2], 4) < 2 * histRMS: integral_RMS = round(FitParam[2], 4) integralErr = round(mfit.GetParError(1), 4) integral_RMSErr = round(mfit.GetParError(2), 4) print "iAmp=", iAmp, " integral= ", integral, " integral_RMS=", integral_RMS M.SetMarkerStyle(22) M.GetXaxis().SetRangeUser(lowValAx, highValAx) # M.GetXaxis().SetRangeUser(lowValAx,highValAx) M.SetTitle(Title + " = " + str(iAmp)) M.Draw("pe") mfit.Draw("same") fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC") fitInfo.SetBorderSize(0) fitInfo.SetFillStyle(0) fitInfo.SetTextAlign(12) fitInfo.SetTextSize(0.03) fitInfo.SetTextColor(1) fitInfo.SetTextFont(62) fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1))) fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1))) fitInfo.Draw() canvas.SaveAs("HistoSingleRun_" + str(iAmp) + "_" + Title + "_TDC.pdf") XVAL = iAmp xIntegral[num] = XVAL yIntegral[num] = integral yIntegralErrUp[num] = integral + integralErr yIntegralErrDown[num] = integral - integralErr xIntegral_RMS[num] = XVAL yIntegral_RMS[num] = integral_RMS yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr print "iAmp, integral= ", iAmp, " ", integral, " XVAL= ", XVAL xRatio[num] = XVAL yRatio[num] = integral_RMS / integral # xIntegral.append(iAmp) # yIntegral.append(integral) # xIntegral_RMS.append(iAmp) # yIntegral_RMS.append(integral_RMS) Graph_Integral = TGraph(len(xIntegral), xIntegral, yIntegral) Graph_IntegralErUp = TGraph(len(xIntegral), xIntegral, yIntegralErrUp) Graph_IntegralErDown = TGraph(len(xIntegral), xIntegral, yIntegralErrDown) canvas_Integral = MakeCanvas("can1", "can1", 800, 800) # canvas_Integral.SetLogy() Graph_Integral.SetTitle("TDC Stability") Graph_Integral.SetMarkerStyle(22) Graph_Integral.SetMarkerColor(3) Graph_Integral.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Integral.GetYaxis().SetRangeUser(0, 40) print "%%%%%%%% Graph_Integral.GetMaximum()= ", TMath.MaxElement( len(xIntegral_RMS), Graph_Integral.GetY()) # Graph_Integral.SetMaximum(1.5) Graph_Integral.Draw() # Graph_IntegralErUp.Draw("same") # Graph_IntegralErDown.Draw("same") canvas_Integral.SaveAs("Integral_" + Title + "_TDC.pdf") Graph_Integral_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMS) Graph_Integral_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrUp) Graph_Integral_RMSErDown = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrDown) canvas_Integral_RMS = MakeCanvas("can2", "can2", 800, 800) Graph_Integral_RMS.SetTitle("TDC RMS vs. Pulse " + Title) Graph_Integral_RMS.SetMarkerStyle(23) Graph_Integral_RMS.SetMarkerColor(2) Graph_Integral_RMS.SetMarkerSize(2) Graph_Integral_RMS.GetXaxis().SetTitle("Day") Graph_Integral_RMS.GetYaxis().SetRangeUser( TMath.MinElement(len(xIntegral_RMS), Graph_Integral_RMS.GetY()) / 2, TMath.MaxElement(len(xIntegral_RMS), Graph_Integral_RMS.GetY()) * 1.5) Graph_Integral_RMS.Draw() # Graph_Integral_RMSErUp.Draw("same") # Graph_Integral_RMSErDown.Draw("same") canvas_Integral_RMS.SaveAs("Integral_RMS_" + Title + "_TDC.pdf") Graph_Ratio = TGraph(len(xRatio), xRatio, yRatio) canvas_Ratio = MakeCanvas("can2", "can2", 800, 800) Graph_Ratio.SetTitle("Ratio of TDC RMS and TDC " + Title) Graph_Ratio.SetMarkerStyle(21) Graph_Ratio.SetMarkerColor(4) Graph_Ratio.SetMarkerSize(2) Graph_Ratio.GetXaxis().SetTitle("Day") Graph_Ratio.GetYaxis().SetRangeUser( TMath.MinElement(len(xIntegral_RMS), Graph_Ratio.GetY()) / 2, TMath.MaxElement(len(xIntegral_RMS), Graph_Ratio.GetY()) * 1.5) Graph_Ratio.Draw() canvas_Ratio.SaveAs("Ratio_" + Title + "_TDC.pdf") OutFile = TFile(RootName, "RECREATE") OutFile.WriteObject(Graph_Integral, "Graph_Integral") OutFile.WriteObject(Graph_Integral_RMS, "Graph_Integral_RMS") OutFile.WriteObject(Graph_Ratio, "Graph_Ratio") OutFile.Close()
def Make_TDC_Energy(Fname1,Fname2,Title, XaxisT,low,high,freq,RootName): f_fc=TFile(Fname1) f_tdc=TFile(Fname2) gr_Inregral_fc=f_fc.Get("Graph_Integral") gr_Inregral_tdc=f_tdc.Get("Graph_Integral") FNumber=int((high-low)/freq) xpoint=array("d",xrange(0,FNumber)) ypoint=array("d",xrange(0,FNumber)) num=-1 for iAmp in range(low,high,freq): num+=1 xpoint[num]=gr_Inregral_fc.Eval(iAmp)/3800;print xpoint[num] ypoint[num]= gr_Inregral_tdc.Eval(iAmp); print ypoint[num] TwoDGraph=TGraph(len(xpoint), xpoint,ypoint) canvas_Integral = MakeCanvas("can1","can1",800,800) TwoDGraph.SetTitle("Time [ns] vs. Energy [GeV] ") TwoDGraph.SetMarkerStyle(22) TwoDGraph.SetMarkerColor(3) TwoDGraph.SetMarkerSize(2) TwoDGraph.GetXaxis().SetTitle("Energy [GeV]") TwoDGraph.GetYaxis().SetTitle("Time [ns]") TwoDGraph.GetYaxis().SetRangeUser(TMath.MinElement(len(xpoint),TwoDGraph.GetY())/1.3, TMath.MaxElement(len(xpoint),TwoDGraph.GetY()) * 1.2) TwoDGraph.Draw() canvas_Integral.SaveAs("Final_Time_Energy.pdf")
def maximum_value(drawables): """Returns the maximum value of all bins of all histograms or graphs provided, including any errors. Args: drawables: An iterable of drawable objects, each of one of the following types: - A TH1 object - A THStack object - A tuple of the form (THStack, TGraph) where the latter represents error bars - A TGraph object Returns: The maximum value than any bin takes on in any of the provided drawables. """ # Create our initial maximum result = 0.0 # Loop over histograms for drawable in drawables: # Unpack things if there is an error band if isinstance(drawable, tuple): drawable, error_band = drawable else: error_band = None # Compute the maximum for this drawable if is_histo(drawable) or is_stack(drawable): maximum = drawable.GetMaximum() elif is_graph(drawable): # http://root.cern.ch/phpBB3/viewtopic.php?t=9070 maximum = TMath.MaxElement(drawable.GetN(), drawable.GetY()) elif is_line(drawable): maximum = max(drawable.GetY1(), drawable.GetY2()) else: raise ValueError('unsupported drawable type') # NOTE: Clever math hack. Since drawable may be a THStack, we can't # (easily) do a bin-wise pairing and compute (value + error-high) for # each bin when looking for a maximum. However, the bin which has the # maximum value will also have the maximum statistical and systematic # normalization uncertainty, so we can assume that the value returned # by GetMaximum() corresponds to the bin with the greatest error, and # thus we can just scan for the largest error and adding that to the # GetMaximum() result gives the answer we would get from bin-wise # pairing. Of course, even if we didn't get the exact answer here, # we'd still be at-or-above the true maximum value, which is all we # really care about for plotting purposes. # If there is no error band, we just add enough room for statistical # error. if error_band is not None: maximum_error = 0.0 for i in xrange(error_band.GetN()): maximum_error = max(maximum_error, error_band.GetErrorYhigh(i)) maximum += maximum_error else: maximum += sqrt(maximum) # Update the result result = max(result, maximum) return result
def overlay(graphs, header, addon, runtype, tlabel, comparePerReleaseSuffix=""): dir_translator = { "1p": "1prong", "1ppi0": "1prongpizero", "2p": "2prong", "3p": "3prong", "3ppi0": "3prongpizero", "oldDM": "oldDM", "newDM": "newDM", "newDMwo2p": "newDMwithout2prong", } ymin = min(TMath.MinElement(g.GetN(), g.GetY()) for g in graphs) ymax = max(TMath.MaxElement(g.GetN(), g.GetY()) for g in graphs) c = TCanvas(tlabel) # Upper plot will be in pad1 pad1 = TPad("pad1", "pad1", 0, 0.3, 1, 1.0) pad1.SetBottomMargin(0.03) # Upper and lower plot are joined pad1.Draw() # Draw the upper pad: pad1 pad1.cd() # pad1 becomes the current pad pad1.SetLogy(0) leg = TLegend(0.2, 0.7, 0.5, 0.9) configureLegend(leg, 1) ratio_graphs = [] for i_graph, graph in enumerate(graphs): graph.GetYaxis().SetTitle('efficiency') graph.SetLineWidth(2) graph.SetMarkerSize(1) graph.SetMaximum(ymax * 1.4) graph.SetMinimum(ymin * 0.80) graph.GetXaxis().SetLabelSize(0.0) graph.GetYaxis().SetTitleSize(0.06) graph.GetYaxis().SetLabelSize(0.06) # hist.GetXaxis().SetLimits(hist.GetXaxis().GetXmin()+(3*(ii-3)), # hist.GetXaxis().GetXmax()+(3*(ii-3))) graph.Draw('ap' if i_graph == 0 else 'psame') legname = graph.GetName() # graph.GetPoint(0, x, y) if i_graph == 0: refg = graph.Clone() else: rp = graph.Clone() for i_points in range(rp.GetN()): if refg.GetPointY(i_points) != 0.0: rp.SetPoint( i_points, graph.GetPointX(i_points), graph.GetPointY(i_points) / refg.GetPointY(i_points)) else: rp.SetPoint(i_points, graph.GetPointX(i_points), 0.0) ratio_graphs.append(rp) leg.AddEntry(graph, legname, 'lep') leg.Draw() tex = TLatex( (graphs[-1].GetXaxis().GetXmin() + 0.01 * (graphs[-1].GetXaxis().GetXmax() - graphs[-1].GetXaxis().GetXmin())), ymax * 1.4, addon.replace('tau_', '')) tex.SetTextAlign(10) tex.SetTextFont(42) tex.SetTextSize(0.04) tex.Draw() # xshift = 0.0 xshift = 0.95 # yshift = ymax*1.4 yshift = 0.95 if tlabel.find('QCD') != -1: pad1.SetTopMargin(0.1) # xshift = 0.0 # yshift = ymax*1.45 yshift = 0.95 if runtype.find('TTbarTau') != -1: xshift = 0.78 tex2 = TLatex( # (graphs[-1].GetXaxis().GetXmax() + # xshift * (graphs[-1].GetXaxis().GetXmax() - # graphs[-1].GetXaxis().GetXmin())), xshift, yshift, tlabel) tex2.SetNDC() tex2.SetTextAlign(32) # tex2.SetTextAlign(30) tex2.SetTextFont(42) tex2.SetTextSize(0.04) tex2.Draw() # lower plot will be in pad c.cd() # Go back to the main canvas before defining pad2 pad2 = TPad("pad2", "pad2", 0, 0.0, 1, 0.27) pad2.SetTopMargin(0.03) pad2.SetBottomMargin(0.35) pad2.Draw() pad2.cd() for ii, ratio in enumerate(ratio_graphs): ratio.SetTitle("") ratio.GetXaxis().SetRangeUser(graphs[-1].GetXaxis().GetXmin(), graphs[-1].GetXaxis().GetXmax()) # ratio.GetXaxis().SetTitle('#epsilon_{s}') ratio.GetXaxis().SetTitleOffset(0.83) ratio.GetXaxis().SetNdivisions(507) ratio.GetYaxis().SetTitle('ratio') ratio.GetYaxis().SetNdivisions(305) ratio.SetMinimum(0.82) ratio.SetMaximum(1.18) ratio.GetYaxis().SetTitleOffset(0.5) ratio.GetYaxis().SetTitleSize(0.16) ratio.GetYaxis().SetLabelSize(0.16) ratio.GetXaxis().SetTitleSize(0.16) ratio.GetXaxis().SetLabelSize(0.16) ratio.Draw('APsame') c.cd() # Go back to the main canvas eta = '_eta' if '_eta' in header else '' dir_name = header.split('_')[0] save( c, 'compare_' + runtype + comparePerReleaseSuffix + '/' + dir_name + eta + '/' + header) try: directory2 = dir_translator[header.split('_')[1]] save( c, 'compare_' + runtype + comparePerReleaseSuffix + '/' + directory2 + eta + '/' + header) except (IndexError, KeyError): pass save( c, 'compare_' + runtype + comparePerReleaseSuffix + '/all' + eta + '/' + header) pad1 = None pad2 = None c = None
# lo style si vede for my_index in range(0, len(h_bkg_prefit)): h_bkg_prefit[my_index].SetLineColor(2 + my_index) h_bkg_prefit[my_index].SetMarkerColor(2 + my_index) h_bkg_prefit[my_index].SetMarkerStyle(20) h_bkg_prefit[my_index].SetMarkerSize(1) h_bkg_prefit[my_index].GetXaxis().SetTitle("Diphoton p_{T}") # hstack_prefit hstack_mc_prefit = ROOT.THStack("hstack_mc_prefit", "hstack_mc_prefit") for my_index in range(0, len(h_bkg_prefit)): hstack_mc_prefit.Add(h_bkg_prefit[my_index]) hstack_mc_prefit.Add(h_sig_prefit) hstack_mc_prefit.SetMaximum( TMath.MaxElement(h_data_prefit.GetN(), h_data_prefit.GetY()) * 1.2) ### POSTFIT DISTRIBUTIONS ### # data postfit h_data_postfit = fin.Get('shapes_fit_s' + '/' + args.channel + '/data') # sig postfit h_sig_postfit = fin.Get('shapes_fit_s' + '/' + args.channel + '/diboson') h_sig_postfit.SetLineColor(6) h_sig_postfit.SetLineStyle(2) h_sig_postfit.SetMarkerColor(6) h_sig_postfit.SetMarkerStyle(24) h_sig_postfit.SetMarkerSize(1) h_sig_postfit.GetXaxis().SetTitle("Diphoton p_{T}") # bkg postfit
can_allCuts.cd() if logy: gPad.SetLogy() #hist_allCutsQCD.Reset() hist_allCutsQCD.GetXaxis().SetRangeUser(xmin, xmax) hist_allCutsQCD.GetXaxis().SetTitle(xtitle) maximumBin = array('f', [ hist_allCutsQCD.GetBinContent(hist_allCutsQCD.GetMaximumBin()), hist_allCutsSig_1000.GetBinContent(hist_allCutsSig_1000.GetMaximumBin()), hist_allCutsSig_5000.GetBinContent(hist_allCutsSig_5000.GetMaximumBin()), hist_allCutsSig_8000.GetBinContent(hist_allCutsSig_8000.GetMaximumBin()) ]) max = TMath.MaxElement(4, maximumBin) hist_allCutsQCD.SetMaximum(1.2 * max) hist_allCutsQCD.SetMinimum(0.00001) hist_allCutsQCD.Draw("hist") hist_allCutsSig_1000.Draw("hist same") hist_allCutsSig_5000.Draw("hist same") hist_allCutsSig_8000.Draw("hist same") leg.Draw() gPad.RedrawAxis() can_allCuts.Write() can_allCuts.SaveAs(outputDir + var + '_allCuts.png') can_allCuts.SaveAs(outputDir + var + '_allCuts.svg') can_allCuts.Close() can_allOtherCuts.cd()