def set2DStyle(self, opt="BasicRainBow"): gStyle.SetPadRightMargin( 0.2 ) # Leave more space to the right side of the current Pad to show the histogram scale if opt == "FancyRainBow": icol = 0 gStyle.SetFrameBorderMode(icol) gStyle.SetFrameFillColor(icol) gStyle.SetCanvasBorderMode(icol) gStyle.SetCanvasColor(icol) gStyle.SetPadBorderMode(icol) gStyle.SetPadColor(icol) gStyle.SetStatColor(icol) gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetOptFit(0) ncontours = 999 s = array.array('d', [0.00, 0.34, 0.61, 0.84, 1.00]) r = array.array('d', [0.00, 0.00, 0.87, 1.00, 0.51]) g = array.array('d', [0.00, 0.81, 1.00, 0.20, 0.00]) b = array.array('d', [0.51, 1.00, 0.12, 0.00, 0.00]) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours) if opt == "BasicRainBow": gStyle.SetPalette( 1 ) # This resets the color palette to a simple Rainbow Color Map w/ 50 colors. See https://root.cern.ch/doc/master/classTColor.html
def set_pub_style(): from ROOT import gStyle # No Canvas Border gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasBorderSize(0) # White BG gStyle.SetCanvasColor(10) # Format for axes gStyle.SetLabelFont(42, 'xyz') gStyle.SetLabelSize(0.05, 'xyz') gStyle.SetLabelOffset(0.01, 'xyz') # gStyle->SetNdivisions(510, 'xyz') gStyle.SetTitleFont(42, 'xyz') gStyle.SetTitleColor(1, 'xyz') gStyle.SetTitleSize(0.06, 'xyz') gStyle.SetTitleOffset(1.25, 'xyz') # No pad borders gStyle.SetPadBorderMode(0) gStyle.SetPadBorderSize(0) # White BG gStyle.SetPadColor(10) # Margins for labels etc. gStyle.SetPadLeftMargin(0.155) gStyle.SetPadBottomMargin(0.155) gStyle.SetPadRightMargin(0.15) gStyle.SetPadTopMargin(0.1) # No error bars in x direction gStyle.SetErrorX(0) # Format legend gStyle.SetLegendBorderSize(0)
def rootSetup(): from ROOT import gStyle gStyle.SetStatColor(0) gStyle.SetFillColor(38) gStyle.SetCanvasColor(0) gStyle.SetPadColor(0) gStyle.SetPadBorderMode(0) gStyle.SetCanvasBorderMode(0) gStyle.SetFrameBorderMode(0) gStyle.SetOptStat(1110) gStyle.SetStatH(0.3) gStyle.SetStatW(0.3) gStyle.SetTitleFillColor(0) #gStyle.SetTitleY(1.) #gStyle.SetTitleX(.1) gStyle.SetTitleBorderSize(0) gStyle.SetHistLineWidth(2) gStyle.SetFrameFillColor(0) #gStyle.SetLineWidth(2) #gStyle.SetTitleColor(0) #gStyle.SetTitleColor(1) gStyle.SetLabelSize(0.05, "x") gStyle.SetLabelSize(0.05, "y") gStyle.SetLabelOffset(0.02, "y") gStyle.SetTitleOffset(1.8, "y") gStyle.SetTitleSize(0.04, "y") gStyle.SetPadRightMargin(0.02) gStyle.SetPadLeftMargin(0.14) # Used to be 0.20 --> Salva gStyle.SetPadBottomMargin(0.14)
def loadstyle(): gStyle.SetOptStat(0) gStyle.SetOptStat(0000) gStyle.SetPalette(1) gStyle.SetNumberContours(100) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0)
def load_root_style_simple(): """ Set basic ROOT style for histograms """ gStyle.SetOptStat(0) gStyle.SetPalette(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0)
def loadstyle(): gROOT.SetStyle("Plain") gStyle.SetOptStat(0) gStyle.SetOptStat(0000) gStyle.SetPalette(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) gStyle.SetOptTitle(0)
def setstyle(self): # Delete previous PostScript plots and set Canvas options gSystem.Exec('rm -f ' + 'D0.pdf') gSystem.Exec('rm -f ' + 'Fit.pdf') gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(0) gStyle.SetStatBorderSize(1) gStyle.SetStatColor(0)
def ratiocase(case_num, case_den, typean): gROOT.SetStyle("Plain") gStyle.SetOptStat(0) gStyle.SetOptStat(0000) gStyle.SetPalette(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) gStyle.SetOptTitle(0) with open("data/database_ml_parameters_%s.yml" % case_num, 'r') as param_config_num: data_param_num = yaml.load(param_config_num, Loader=yaml.FullLoader) with open("data/database_ml_parameters_%s.yml" % case_den, 'r') as param_config_den: data_param_den = yaml.load(param_config_den, Loader=yaml.FullLoader) folder_num = data_param_num[case_num]["analysis"][typean]["data"]["resultsallp"] folder_den = data_param_den[case_den]["analysis"][typean]["data"]["resultsallp"] binsmin_num = data_param_num[case_num]["analysis"][typean]["sel_binmin2"] binsmax_num = data_param_num[case_num]["analysis"][typean]["sel_binmax2"] latexbin2var = data_param_num[case_num]["analysis"][typean]["latexbin2var"] plotbin = data_param_num[case_num]["analysis"][typean]["plotbin"] ccross = TCanvas('cCross', 'The Fit Canvas', 100, 600) ccross = TCanvas('cCross', 'The Fit Canvas') ccross.SetCanvasSize(1500, 1500) ccross.SetWindowSize(500, 500) # ccross.SetLogx() legyield = TLegend(.3, .65, .7, .85) legyield.SetBorderSize(0) legyield.SetFillColor(0) legyield.SetFillStyle(0) legyield.SetTextFont(42) legyield.SetTextSize(0.035) file_num = TFile.Open("%s/finalcross%s%s.root" % (folder_num, case_num, typean)) file_den = TFile.Open("%s/finalcross%s%s.root" % (folder_den, case_den, typean)) for imult, _ in enumerate(binsmax_num): print(imult) hratio = file_num.Get("hcross%d" % (imult)) hcross_den = file_den.Get("hcross%d" % (imult)) hratio.Divide(hcross_den) hratio.GetXaxis().SetTitle("p_{T} (GeV)") hratio.GetYaxis().SetTitle("Particle ratio") hratio.GetYaxis().SetRangeUser(0., 1.) if plotbin[imult] == 1: hratio.Draw("same") legyieldstring = "%.1f < %s < %.1f" % \ (binsmin_num[imult], latexbin2var, binsmax_num[imult]) legyield.AddEntry(hratio, legyieldstring, "LEP") legyield.Draw() ccross.SaveAs("ComparisonRatios_%s%s_%s.eps" % \ (case_num, case_den, typean))
def showRMSPOH_DAC(sector, poh, gain, wait=True, filename=None): gStyle.SetOptStat(0) gStyle.SetCanvasColor(0) gStyle.SetTitleFillColor(0) sector.poh[poh].biasGraphs = [] sector.poh[poh].rmsGraphs = [] sector.poh[poh].slopeGraphs = [] sector.ResetAllandInitAll() data = sector.poh[poh].ScanDACoffset() if filename is None: filename = getFilename("poh%s_%d.ps" % (sector.name, poh)) c1 = TCanvas('c1', time.strftime("%Y-%m-%d-%m %H:%M"), 200, 10, 800, 800) sector.poh[poh].pl = TPaveLabel(0.8, 0.9, 0.95, 0.95, time.strftime("%Y-%m-%d-%m %H:%M")) sector.poh[poh].pl.Draw() c1.Divide(2, 3) for ch in range(1, 5): c1.cd(ch) title = "POHBias_POH" + str(poh) + ":" + str( ch) + " " + sector.name + " fed channel " + str( sector.poh[poh].fedchannels[ch]) + "gain =" + str(gain) f = TH2D('h' + title, title, 2, 0, 255, 2, 0, 1024) hList.append(f) f.GetXaxis().SetTitle("DAC") #f.GetYaxis().SetTitle("FED ADC") f.Draw() color = 1 biasGraph = graph([(t[0], t[1]) for t in data[ch]], color=1, name="bias_" + str(poh) + ":" + str(ch)) rmsGraph = graph([(t[0], t[2] * 10.) for t in data[ch]], color=2, name="rms_" + str(poh) + ":" + str(ch)) slopeGraph = graph([(t[0], t[3] * 10.) for t in data[ch]], color=3, name="slope_" + str(poh) + ":" + str(ch)) sector.poh[poh].biasGraphs.append(biasGraph) sector.poh[poh].rmsGraphs.append(rmsGraph) sector.poh[poh].slopeGraphs.append(slopeGraph) biasGraph.Write() rmsGraph.Write() slopeGraph.Write() c1.Update() c1.Print(filename) gCanvases.append(c1) if wait: raw_input("hit return to continue")
def Init(): from ROOT import gStyle from ROOT import gROOT gROOT.ProcessLine("gErrorIgnoreLevel = 2000;") gStyle.SetCanvasColor(0); gStyle.SetCanvasBorderMode(0); gStyle.SetCanvasBorderSize(3); gStyle.SetPadLeftMargin(0.125); gStyle.SetPadBottomMargin(0.12); gStyle.SetPadColor(0); gStyle.SetPadBorderMode(0); gStyle.SetFrameBorderMode(0); gStyle.SetFrameBorderSize(0); gStyle.SetFrameFillColor(0); gStyle.SetOptStat(0); gStyle.SetLabelOffset(0.005,"X"); gStyle.SetLabelSize(0.03,"X"); gStyle.SetLabelFont(42,"X"); gStyle.SetTitleOffset(.85,"X"); gStyle.SetTitleSize(0.04,"X"); gStyle.SetTitleFont(42,"X"); gStyle.SetLabelOffset(0.005,"Y"); gStyle.SetLabelSize(0.03,"Y"); gStyle.SetLabelFont(42,"Y"); gStyle.SetTitleOffset(.98,"Y"); gStyle.SetTitleSize(0.04,"Y"); gStyle.SetTitleFont(42,"Y"); gStyle.SetStatColor(0); gStyle.SetStatBorderSize(0); gStyle.SetTextFont(2); gStyle.SetTextSize(.05); gStyle.SetLegendBorderSize(1); gStyle.SetHistLineWidth(2); gStyle.SetTitleFillColor(0); gStyle.SetTitleFontSize(0.06); gStyle.SetTitleBorderSize(0); gStyle.SetTitleAlign(13); gStyle.SetTextAlign(22); #RJ gStyle.SetPadTickX(1); gStyle.SetPadTickY(1); gStyle.SetPadTopMargin(0.05); gStyle.SetPadBottomMargin(0.13); gStyle.SetPadLeftMargin(0.16); gStyle.SetPadRightMargin(0.03);
def Styling(): # Center title gStyle.SetTitleAlign(22) gStyle.SetTitleX(.5) gStyle.SetTitleY(.95) gStyle.SetTitleBorderSize(0) # Remove stats box gStyle.SetOptStat(0) # Set background color to white gStyle.SetFillColor(10) gStyle.SetFrameFillColor(10) gStyle.SetCanvasColor(10) gStyle.SetPadColor(10) gStyle.SetTitleFillColor(0) gStyle.SetStatColor(10) # No colored frames around plots gStyle.SetFrameBorderMode(0) gStyle.SetCanvasBorderMode(0) gStyle.SetPadBorderMode(0) # Set the default line color for a fit function to be red gStyle.SetFuncColor(2) # Marker settings gStyle.SetMarkerStyle(20) # No border on legends gStyle.SetLegendBorderSize(0) # Disabled for violating NOvA style guidelines # Scientific notation on axes TGaxis.SetMaxDigits(3) # Axis titles gStyle.SetTitleSize(.055, "xyz") gStyle.SetTitleOffset(2.2, "xyz") gStyle.SetTitleOffset(2.2, "y") gStyle.SetTitleSize(.05, "") gStyle.SetTitleOffset(2.2, "") # Axis labels (numbering) gStyle.SetLabelSize(.05, "xyz") gStyle.SetLabelOffset(.005, "xyz") # Thicker lines gStyle.SetHistLineWidth(2) gStyle.SetFrameLineWidth(2) gStyle.SetFuncWidth(2) # Set the number of tick marks gStyle.SetNdivisions(506, "xyz") # Set tick marks on all sides gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) # Fonts kNovaFont = 42 gStyle.SetStatFont(kNovaFont) gStyle.SetLabelFont(kNovaFont, "xyz") gStyle.SetTitleFont(kNovaFont, "xyz") gStyle.SetTitleFont(kNovaFont, "") # Apply same settings to titles gStyle.SetTextFont(kNovaFont) gStyle.SetLegendFont(kNovaFont)
def draw_syst(self, save_dir, results_dir, root_dir=None): """Draw all fits one-by-one Args: save_dir: directory where to save plots results_dir: where to find intermediate results of the multi trial root_dir: TDirectory where to save summary plots """ gStyle.SetOptStat(0) gStyle.SetOptStat(0000) gStyle.SetPalette(1) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) bins1_ranges = self.pars_factory.bins1_edges_low.copy() bins1_ranges.append(self.pars_factory.bins1_edges_up[-1]) for (ibin1, ibin2), fit in self.syst_fits.items(): if not fit: self.logger.warning( "No systematic fit for bins (%i, %i). Skip...", ibin1, ibin2) continue bin_id_match = self.pars_factory.bin_matching[ibin1] # Some variables set for drawing title = f"{self.pars_factory.bins1_edges_low[ibin1]:.1f} < #it{{p}}_{{T}} < " \ f"{self.pars_factory.bins1_edges_up[ibin1]:.1f}" \ f"(prob > {self.pars_factory.prob_cut_fin[bin_id_match]:.2f})" suffix_write = self.pars_factory.make_suffix(ibin1, ibin2) fit.results_path = os.path.join( results_dir, f"multi_trial_bin1_{ibin1}_bin2_{ibin2}.root") # Central fits canvas = TCanvas("fit_canvas", suffix_write, 1400, 800) fit.draw(canvas, title=title) if self.pars_factory.apply_weights is False: canvas.SaveAs( make_file_path(save_dir, "multi_trial", "eps", None, suffix_write)) else: canvas.SaveAs( make_file_path(save_dir, "multi_trial_weights", "eps", None, suffix_write)) if root_dir: root_dir.cd() canvas.Write(f"multi_trial_{suffix_write}") canvas.Close()
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 showRMSAOHTestCCU(sector, aoh, wait=True, filename=None): gStyle.SetOptStat(0) gStyle.SetCanvasColor(0) gStyle.SetTitleFillColor(0) sector.aoh[aoh].biasGraphs = [] sector.aoh[aoh].rmsGraphs = [] sector.aoh[aoh].slopeGraphs = [] data = sector.aoh[aoh].getBiasRMSCurvesTestCCU() if filename is None: filename = getFilename("aoh%s_%d.ps" % (sector.name, aoh)) c1 = TCanvas('c1', time.strftime("%Y-%m-%d-%m %H:%M"), 200, 10, 800, 800) sector.aoh[aoh].pl = TPaveLabel(0.8, 0.9, 0.95, 0.95, time.strftime("%Y-%m-%d-%m %H:%M")) sector.aoh[aoh].pl.Draw() c1.Divide(2, 3) for ch in range(1, 7): c1.cd(ch) title = "AOHBias_AOH" + str(aoh) + ":" + str( ch) + " " + sector.name + " fed channel " + str( sector.aoh[aoh].fedchannels[ch]) f = TH2D('h' + title, title, 2, 10, 40, 2, 0, 1024) hList.append(f) f.GetXaxis().SetTitle("aoh bias") #f.GetYaxis().SetTitle("FED ADC") f.Draw() color = 1 biasGraph = graph([(t[0], t[1]) for t in data[ch]], color=1, name="bias_" + str(aoh) + ":" + str(ch)) rmsGraph = graph([(t[0], t[2] * 100.) for t in data[ch]], color=2, name="rms_" + str(aoh) + ":" + str(ch)) slopeGraph = graph([(t[0], t[3] * 10.) for t in data[ch]], color=3, name="slope_" + str(aoh) + ":" + str(ch)) sector.aoh[aoh].biasGraphs.append(biasGraph) sector.aoh[aoh].rmsGraphs.append(rmsGraph) sector.aoh[aoh].slopeGraphs.append(slopeGraph) biasGraph.Write() rmsGraph.Write() slopeGraph.Write() c1.Update() c1.Print(filename) gCanvases.append(c1) if wait: raw_input("hit return to continue")
def plotcomparison(case): gROOT.SetStyle("Plain") gStyle.SetOptStat(0) gStyle.SetOptStat(0000) gStyle.SetPalette(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) gStyle.SetOptTitle(0) with open("data/database_ml_parameters_%s.yml" % case, 'r') as param_config: data_param = yaml.load(param_config, Loader=yaml.FullLoader)
def loadstyle2(): gROOT.SetStyle("Plain") gStyle.SetOptStat(0) gStyle.SetOptStat(0000) gStyle.SetPalette(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) gStyle.SetTitleOffset(1.15, "y") gStyle.SetTitleFont(42, "xy") gStyle.SetLabelFont(42, "xy") gStyle.SetTitleSize(0.042, "xy") gStyle.SetLabelSize(0.035, "xy") gStyle.SetPadTickX(1) gStyle.SetPadTickY(1)
def set_root_style(stat=1110, grid=0, PadTopMargin=0.08, PadLeftMargin=0.10, TitleOffsetY=1.2): # must be used in the beginning from ROOT import gROOT, gStyle gROOT.SetBatch(1) gROOT.Reset() gStyle.SetOptTitle(1) gStyle.SetTitleFillColor(0) gStyle.SetTitleBorderSize(0) # gStyle.SetTitleFont(22) # gStyle.SetStatFont(22) # gStyle.SetStatColor(1) # gStyle.SetLabelFont(22,"X") # gStyle.SetLabelFont(22,"Y") gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(0) gStyle.SetCanvasDefX(0) gStyle.SetCanvasDefY(0) gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) gStyle.SetPadTopMargin(PadTopMargin) gStyle.SetPadLeftMargin(PadLeftMargin) gStyle.SetPadRightMargin(0.05) gStyle.SetLabelSize(0.03, "XYZ") gStyle.SetTitleSize(0.04, "XYZ") gStyle.SetTitleOffset(TitleOffsetY, "Y") gStyle.SetPadBorderMode(0) gStyle.SetPadColor(0) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetPadGridX(grid) gStyle.SetPadGridY(grid) gStyle.SetOptStat(stat) gStyle.SetStatColor(0) gStyle.SetStatBorderSize(1)
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 load_root_style(): """ Set more advanced ROOT style for histograms """ gROOT.SetStyle("Plain") gStyle.SetOptStat(0) gStyle.SetPalette(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) gStyle.SetTitleOffset(1.15, "y") gStyle.SetTitleFont(42, "xy") gStyle.SetLabelFont(42, "xy") gStyle.SetTitleSize(0.042, "xy") gStyle.SetLabelSize(0.035, "xy") gStyle.SetPadTickX(1) gStyle.SetPadTickY(1)
def setStyle(): gROOT.Reset() icol = 0 # WHITE font = 42 # Helvetica tsize = 0.05 gStyle.SetFrameBorderMode(icol) gStyle.SetFrameFillColor(icol) gStyle.SetCanvasBorderMode(icol) gStyle.SetCanvasColor(icol) gStyle.SetPadBorderMode(icol) gStyle.SetPadColor(icol) gStyle.SetStatColor(icol) gStyle.SetPaperSize(20, 26) gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.08) gStyle.SetPadBottomMargin(0.15) gStyle.SetPadLeftMargin(0.12) gStyle.SetTitleXOffset(1.05) gStyle.SetTitleYOffset(0.95) gStyle.SetTextFont(font) gStyle.SetTextSize(tsize) 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.SetLabelSize(tsize * 0.85, "x") gStyle.SetTitleSize(tsize * 1.10, "x") gStyle.SetLabelSize(tsize * 0.85, "y") gStyle.SetTitleSize(tsize * 1.10, "y") gStyle.SetLabelSize(tsize * 0.85, "z") gStyle.SetTitleSize(tsize * 1.10, "z") gStyle.SetMarkerStyle(20) gStyle.SetMarkerSize(1.) gStyle.SetHistLineWidth(2) gStyle.SetLineStyleString(2, "[12 12]") # postscript dashes gStyle.SetEndErrorSize(0.) # gStyle.SetOptTitle(0); gStyle.SetOptStat(0) gStyle.SetOptFit(0) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetPaintTextFormat("4.1f")
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 set_fancy_2D_style(): icol = 0 gStyle.SetFrameBorderMode(icol) gStyle.SetFrameFillColor(icol) gStyle.SetCanvasBorderMode(icol) gStyle.SetCanvasColor(icol) gStyle.SetPadBorderMode(icol) gStyle.SetPadColor(icol) gStyle.SetStatColor(icol) gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetOptFit(0) ncontours = 999 s = array('d', [0.00, 0.34, 0.61, 0.84, 1.00]) r = array('d', [0.00, 0.00, 0.87, 1.00, 0.51]) g = array('d', [0.00, 0.81, 1.00, 0.20, 0.00]) b = array('d', [0.51, 1.00, 0.12, 0.00, 0.00]) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours)
def main(): # usage description usage = "Example: ./scripts/plotSignificance.py -l logs -f qq --massrange 1200 6000 100" # input parameters parser = ArgumentParser( description='Script that plots significance for specified mass points', epilog=usage) parser.add_argument('analysis', type=str, help='Analysis name') parser.add_argument('model', type=str, help='Model name') parser.add_argument("-M", "--method", dest="method", choices=['ProfileLikelihood', 'HybridNew', 'theta'], default='ProfileLikelihood', help="Method to calculate upper limits", metavar="METHOD") parser.add_argument( '--fit_function', type=str, default="dijet4", help="Name of fit function used for background estimate") parser.add_argument( "--sigRange", dest="sigRange", type=float, default=2.5, help="Significance range to plot (default: %(default)f)") parser.add_argument( "--postfix", dest="postfix", default='', help="Postfix for the output plot name (default: %(default)s)") parser.add_argument( "--fileFormat", dest="fileFormat", default='pdf', help="Format of the output plot (default: %(default)s)") parser.add_argument("--extraText", dest="extraText", default='Preliminary', help="Extra text on the plot (default: %(default)s)") parser.add_argument( "--lumi_sqrtS", dest="lumi_sqrtS", default='19.7 fb^{-1} (13 TeV)', help= "Integrated luminosity and center-of-mass energy (default: %(default)s)" ) parser.add_argument("--printResults", dest="printResults", default=False, action="store_true", help="Print results to the screen") parser.add_argument('--fitTrigger', action='store_true', help="Use trigger fit") parser.add_argument('--correctTrigger', action='store_true', help="Use trigger correction") parser.add_argument('--useMCTrigger', action='store_true', help="Use MC trigger emulation") parser.add_argument("--noSyst", action="store_true", help="Make plots for limits without systematics") parser.add_argument( "--freezeNuisances", type=str, help="Make plots for limits with frozen nuisance parameters") mass_group = parser.add_mutually_exclusive_group(required=True) mass_group.add_argument( "--mass", type=int, nargs='*', default=1000, help= "Mass can be specified as a single value or a whitespace separated list (default: %(default)i)" ) mass_group.add_argument( "--massrange", type=int, nargs=3, help="Define a range of masses to be produced. Format: min max step", metavar=('MIN', 'MAX', 'STEP')) mass_group.add_argument("--masslist", help="List containing mass information") args = parser.parse_args() # mass points for which resonance shapes will be produced input_masses = [] if args.massrange != None: MIN, MAX, STEP = args.massrange input_masses = range(MIN, MAX + STEP, STEP) elif args.masslist != None: # A mass list was provided print "Will create mass list according to", args.masslist masslist = __import__(args.masslist.replace(".py", "")) input_masses = masslist.masses else: input_masses = args.mass # sort masses input_masses.sort() # arrays holding results masses = array('d') significances = array('d') p0_values = array('d') for mass in input_masses: masses.append(mass) #print ">> Reading results for resonance with m = %i GeV..."%(int(mass)) log_file = open( limit_config.get_combine_log_path( args.analysis, args.model, mass, args.fit_function, args.method, what="significance", systematics=(not args.noSyst), frozen_nps=args.freezeNuisances, fitTrigger=args.fitTrigger, correctTrigger=args.correctTrigger, useMCTrigger=args.useMCTrigger), 'r') if args.method == 'theta': logName = logName.replace('significance_', '') # read the log file for line in log_file: if args.method == 'theta': if re.search("^{'signal': {'Z':", line): significances.append( float(line.split()[-1].lstrip('[').rstrip('}').rstrip( ']'))) else: if re.search("^Significance:", line): significances.append(float(line.split()[1])) elif re.search("^Null p-value:", line): p0_values.append(float(line.split()[2])) if len(masses) != len(significances): print "** ERROR: ** Could not find significance for m =", int( mass), "GeV. Aborting." sys.exit(1) if len(masses) != len(p0_values): print "** ERROR: ** Could not find p0 value for m =", int( mass), "GeV. Aborting." sys.exit(1) # Allow only positive fluctuations if significances[-1] < 0: significances[-1] = 0. if args.printResults: print "masses =", masses.tolist() print "significances =", significances.tolist() print "p0_values =", p0_values.tolist() # import ROOT stuff from ROOT import kTRUE, kFALSE, gROOT, gStyle, gPad, TGraph, TCanvas, TLegend from ROOT import kGreen, kYellow, kWhite, kRed, kBlue gROOT.SetBatch(kTRUE) gStyle.SetOptStat(0) gStyle.SetOptTitle(0) gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") gStyle.SetCanvasBorderMode(0) gStyle.SetFrameBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetPadLeftMargin(0.15) gStyle.SetPadRightMargin(0.05) gStyle.SetPadTopMargin(0.05) gStyle.SetPadBottomMargin(0.15) gROOT.ForceStyle() graph_sig = TGraph(len(masses), masses, significances) graph_sig.GetXaxis().SetTitle("Resonance mass [GeV]") graph_sig.GetYaxis().SetTitle("p_0") graph_sig.GetYaxis().SetTitleOffset(1.2) graph_sig.GetYaxis().SetRangeUser(0., args.sigRange) graph_sig.SetLineWidth(2) graph_sig.SetLineColor(kRed) graph_sig.SetMarkerStyle(21) graph_sig.SetMarkerSize(1) graph_sig.SetMarkerColor(kBlue) c = TCanvas("c", "", 800, 800) c.cd() graph_sig.Draw("ALP") # draw the lumi text on the canvas CMS_lumi.extraText = args.extraText CMS_lumi.lumi_sqrtS = args.lumi_sqrtS # used with iPeriod = 0 (free form) iPos = 11 iPeriod = 0 CMS_lumi.CMS_lumi(c, iPeriod, iPos) gPad.RedrawAxis() c.SetGridx() c.SetGridy() fileName = limit_config.paths[ "limit_plots"] + '/significance_%s_%s_%s_%s.%s' % ( args.method, args.analysis, args.model + args.postfix, args.fit_function, args.fileFormat.lower()) c.SaveAs(fileName) #print "Significance plot saved to '%s'"%(fileName) graph_p0 = TGraph(len(masses), masses, p0_values) graph_p0.GetXaxis().SetTitle("Resonance mass [GeV]") graph_p0.GetYaxis().SetTitle("p_{0} (local)") graph_p0.GetYaxis().SetTitleOffset(1.2) graph_p0.GetYaxis().SetRangeUser(1.e-3, 1.) graph_p0.SetLineWidth(2) graph_p0.SetLineColor(kRed) graph_p0.SetMarkerStyle(21) graph_p0.SetMarkerSize(1) graph_p0.SetMarkerColor(kBlue) c_p0 = TCanvas("c_p0", "", 800, 800) c_p0.SetLogy() c_p0.cd() graph_p0.Draw("ALP") # draw the lumi text on the canvas # draw the lumi text on the canvas CMS_lumi.extraText = args.extraText CMS_lumi.lumi_sqrtS = args.lumi_sqrtS # used with iPeriod = 0 (free form) iPos = 11 iPeriod = 0 CMS_lumi.CMS_lumi(c, iPeriod, iPos) #Root.CMSLabel(0.2, 0.2, "Internal", 1, 0.65) gPad.RedrawAxis() c_p0.SetGridx() c_p0.SetGridy() fileName = limit_config.paths["limit_plots"] + '/p0_%s_%s_%s_%s.%s' % ( args.method, args.analysis, args.model + args.postfix, args.fit_function, args.fileFormat.lower()) c_p0.SaveAs(fileName) print "p0 plot saved to '%s'" % (fileName)
def initialize2(self): # For the canvas: gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(600) #Height of canvas gStyle.SetCanvasDefW(600) #Width of canvas gStyle.SetCanvasDefX(0) #POsition on screen gStyle.SetCanvasDefY(0) # For the Pad: gStyle.SetPadBorderMode(0) # gStyle.SetPadBorderSize(Width_t size = 1) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(False) gStyle.SetPadGridY(False) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) # For the frame: gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillStyle(1000) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) # For the histo: # gStyle.SetHistFillColor(1) # gStyle.SetHistFillStyle(0) gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(1) # gStyle.SetLegoInnerR(Float_t rad = 0.5) # gStyle.SetNumberContours(Int_t number = 20) gStyle.SetEndErrorSize(2) # gStyle.SetErrorMarker(20) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(20) #For the fit/function: gStyle.SetOptFit(1) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) #For the date: gStyle.SetOptDate(0) # gStyle.SetDateX(Float_t x = 0.01) # gStyle.SetDateY(Float_t y = 0.01) # For the statistics box: gStyle.SetOptFile(0) gStyle.SetOptStat( 0) # To display the mean and RMS: SetOptStat("mr") gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) # gStyle.SetStatStyle(Style_t style = 1001) # gStyle.SetStatX(Float_t x = 0) # gStyle.SetStatY(Float_t y = 0) # Margins: gStyle.SetPadTopMargin(0.05) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.02) # For the Global title: gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) # gStyle.SetTitleH(0) # Set the height of the title box # gStyle.SetTitleW(0) # Set the width of the title box # gStyle.SetTitleX(0) # Set the position of the title box # gStyle.SetTitleY(0.985) # Set the position of the title box # gStyle.SetTitleStyle(Style_t style = 1001) # gStyle.SetTitleBorderSize(2) # For the axis titles: gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size? # gStyle.SetTitleYSize(Float_t size = 0.02) gStyle.SetTitleXOffset(0.9) gStyle.SetTitleYOffset(1.25) # gStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset # For the axis labels: gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") # For the axis: gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX( 1) # To get tick marks on the opposite side of the frame gStyle.SetPadTickY(1) # Change for log plots: gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) # Postscript options: gStyle.SetPaperSize(20., 20.)
from ROOT import TH1F, TH2F, TFile, TTree from ROOT import gROOT, gStyle from ROOT import TCanvas gROOT.SetBatch(1) gROOT.Reset() gStyle.SetCanvasColor(0) gStyle.SetFrameBorderMode(0) gStyle.SetOptStat(0) gStyle.SetTitleX(0.5) # title X location gStyle.SetTitleY(0.96) # title Y location gStyle.SetPaintTextFormat(".2f") def draw_underflow_overflow(h1): h1.GetXaxis().SetRange(0, h1.GetNbinsX() + 1) h1.Draw() return h1 def fill_underflow_overflow(h1): nbin = h1.GetNbinsX() h1.Fill(h1.GetBinCenter(1),h1.GetBinContent(0)) h1.Fill(h1.GetBinCenter(nbin),h1.GetBinContent(nbin+1)) h1.Draw() return h1 Canv = TCanvas("c1","c1",0,0,800,600) f_out = TFile(filename,"recreate") for sample in sampleName:
def setTDRStyle(force): gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(600) gStyle.SetCanvasDefW(600) gStyle.SetCanvasDefX(0) gStyle.SetCanvasDefY(0) gStyle.SetPadBorderMode(0) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(False) gStyle.SetPadGridY(False) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) if force: gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(1) gStyle.SetEndErrorSize(2) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(20) gStyle.SetOptFit(1) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) gStyle.SetOptDate(0) gStyle.SetOptFile(0) gStyle.SetOptStat(0) gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.04) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.2) gStyle.SetPadTopMargin(0.05) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.04) gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") gStyle.SetTitleXOffset(0.9) gStyle.SetTitleYOffset(1.25) gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) gStyle.SetPaperSize(20.,20.) gROOT.ForceStyle()
def setStyle(): gStyle.SetCanvasColor(0) gStyle.SetCanvasBorderSize(10) gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasDefH(700) gStyle.SetCanvasDefW(700) gStyle.SetPadColor(0) gStyle.SetPadBorderSize(10) gStyle.SetPadBorderMode(0) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadTopMargin(0.08) gStyle.SetPadLeftMargin(0.15) gStyle.SetPadRightMargin(0.05) gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetFrameFillStyle(0) gStyle.SetFrameFillColor(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(0) gStyle.SetFrameLineWidth(1) gStyle.SetFrameBorderSize(10) gStyle.SetFrameBorderMode(0) gStyle.SetNdivisions(505) gStyle.SetLineWidth(2) gStyle.SetHistLineWidth(2) gStyle.SetFrameLineWidth(2) gStyle.SetLegendFillColor(root.kWhite) gStyle.SetLegendFont(42) gStyle.SetMarkerSize(1.2) gStyle.SetMarkerStyle(20) gStyle.SetLabelSize(0.040, "X") gStyle.SetLabelSize(0.040, "Y") gStyle.SetLabelOffset(0.010, "X") gStyle.SetLabelOffset(0.010, "Y") gStyle.SetLabelFont(42, "X") gStyle.SetLabelFont(42, "Y") gStyle.SetTitleBorderSize(0) gStyle.SetTitleFont(42) gStyle.SetTitleFont(42, "X") gStyle.SetTitleFont(42, "Y") gStyle.SetTitleSize(0.045, "X") gStyle.SetTitleSize(0.045, "Y") gStyle.SetTitleOffset(1.4, "X") gStyle.SetTitleOffset(1.4, "Y") gStyle.SetTextSize(0.055) gStyle.SetTextFont(42) gStyle.SetOptStat(0)
from ROOT import gROOT, gStyle, gPad, TF1, TH1F, TCanvas, TArrow, TGraph, kWhite, kRed, kBlue from array import array import CMS_lumi gROOT.SetBatch(1) gStyle.SetOptStat(111111) gStyle.SetOptFit(1111) #gStyle.SetOptTitle(0) gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") gStyle.SetCanvasBorderMode(0) gStyle.SetFrameBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetPadLeftMargin(0.15) gStyle.SetPadRightMargin(0.05) gStyle.SetPadTopMargin(0.06) gStyle.SetPadBottomMargin(0.14) gROOT.ForceStyle() masses = array('d') significances = array('d') mass_min = 1500 mass_max = 7200 ##------------------------------------------------------
def plot_hfptspectrum_ratios_comb(case_num, case_den, arraytype): gROOT.SetStyle("Plain") gStyle.SetOptStat(0) gStyle.SetOptStat(0000) gStyle.SetPalette(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) gStyle.SetOptTitle(0) gStyle.SetTitleOffset(1.15, "y") gStyle.SetTitleFont(42, "xy") gStyle.SetLabelFont(42, "xy") gStyle.SetTitleSize(0.042, "xy") gStyle.SetLabelSize(0.035, "xy") gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) with open("data/database_ml_parameters_%s.yml" % case_num, 'r') as param_config_num: data_param_num = yaml.load(param_config_num, Loader=yaml.FullLoader) with open("data/database_ml_parameters_%s.yml" % case_den, 'r') as param_config_den: data_param_den = yaml.load(param_config_den, Loader=yaml.FullLoader) folder_plots_num = data_param_num[case_num]["analysis"][ "dir_general_plots"] folder_plots_den = data_param_den[case_den]["analysis"][ "dir_general_plots"] if not os.path.exists(folder_plots_num): print("creating folder ", folder_plots_num) os.makedirs(folder_plots_num) if not os.path.exists(folder_plots_den): print("creating folder ", folder_plots_den) os.makedirs(folder_plots_den) folder_num_allperiods = \ data_param_num[case_num]["analysis"][arraytype[0]]["data"]["resultsallp"] folder_den_allperiods = \ data_param_den[case_den]["analysis"][arraytype[0]]["data"]["resultsallp"] folder_num_triggered = \ data_param_num[case_num]["analysis"][arraytype[1]]["data"]["resultsallp"] folder_den_triggered = \ data_param_den[case_den]["analysis"][arraytype[1]]["data"]["resultsallp"] binsmin_num = data_param_num[case_num]["analysis"][ arraytype[0]]["sel_binmin2"] binsmax_num = data_param_num[case_num]["analysis"][ arraytype[0]]["sel_binmax2"] name_num = data_param_num[case_num]["analysis"][ arraytype[0]]["latexnamemeson"] name_den = data_param_den[case_den]["analysis"][ arraytype[0]]["latexnamemeson"] latexbin2var = data_param_num[case_num]["analysis"][ arraytype[0]]["latexbin2var"] plotbinMB = data_param_num[case_num]["analysis"][arraytype[0]]["plotbin"] plotbinHM = data_param_num[case_num]["analysis"][arraytype[1]]["plotbin"] br_num = data_param_num[case_num]["ml"]["opt"]["BR"] br_den = data_param_den[case_den]["ml"]["opt"]["BR"] sigmav0_num = data_param_num[case_num]["analysis"]["sigmav0"] sigmav0_den = data_param_den[case_den]["analysis"]["sigmav0"] file_num_allperiods = TFile.Open("%s/finalcross%s%smulttot.root" % \ (folder_num_allperiods, case_num, arraytype[0])) file_den_allperiods = TFile.Open("%s/finalcross%s%smulttot.root" % \ (folder_den_allperiods, case_den, arraytype[0])) file_num_triggered = TFile.Open("%s/finalcross%s%smulttot.root" % \ (folder_num_triggered, case_num, arraytype[1])) file_den_triggered = TFile.Open("%s/finalcross%s%smulttot.root" % \ (folder_den_triggered, case_den, arraytype[1])) if not file_num_allperiods or not file_num_triggered: print("---Warning: Issue with %s merged files. Meson ratio plot skipped (%s, %s)---" % \ (case_num, arraytype[0], arraytype[1])) return if not file_den_allperiods or not file_den_triggered: print("---Warning: Issue with %s merged files. Meson ratio plot skipped (%s, %s)---" % \ (case_den, arraytype[0], arraytype[1])) return rootfilename = "%s/ComparisonRatios_%s%s_%scombined%s.root" % \ (folder_plots_num, case_num, case_den, arraytype[0], arraytype[1]) fileoutput = TFile.Open(rootfilename, "recreate") ccross = TCanvas('cRatioCross', 'The Fit Canvas') ccross.SetCanvasSize(1500, 1500) ccross.SetWindowSize(500, 500) maxplot = 1.0 if case_num == "Dspp": maxplot = 0.5 ccross.cd(1).DrawFrame(0.9, 0, 30, maxplot, ";#it{p}_{T} (GeV/#it{c});%s / %s" % \ (name_num, name_den)) ccross.cd(1).SetLogx() legyield = TLegend(.4, .68, .8, .88) legyield.SetBorderSize(0) legyield.SetFillColor(0) legyield.SetFillStyle(0) legyield.SetTextFont(42) legyield.SetTextSize(0.025) colors = [kBlack, kRed, kGreen + 2, kBlue] for imult, iplot in enumerate(plotbinMB): if not iplot: continue hratio = file_num_allperiods.Get("histoSigmaCorr%d" % (imult)) hratio.Scale(1. / (br_num * sigmav0_num * 1e12)) hcross_den = file_den_allperiods.Get("histoSigmaCorr%d" % (imult)) hcross_den.Scale(1. / (br_den * sigmav0_den * 1e12)) hratio.Divide(hcross_den) hratio.SetLineColor(colors[imult % len(colors)]) hratio.SetMarkerColor(colors[imult % len(colors)]) hratio.SetMarkerStyle(21) hratio.SetTitle(";#it{p}_{T} (GeV/#it{c});%s / %s" % (name_num, name_den)) hratio.Draw("same") legyieldstring = "%.1f #leq %s < %.1f (MB)" % \ (binsmin_num[imult], latexbin2var, binsmax_num[imult]) legyield.AddEntry(hratio, legyieldstring, "LEP") fileoutput.cd() hratio.Write("hratio_fromMB_%.1f_%s_%.1f" % \ (binsmin_num[imult], latexbin2var, binsmax_num[imult])) for imult, iplot in enumerate(plotbinHM): if not iplot: continue hratioHM = file_num_triggered.Get("histoSigmaCorr%d" % (imult)) hratioHM.Scale(1. / (br_num * sigmav0_num * 1e12)) hcrossHM_den = file_den_triggered.Get("histoSigmaCorr%d" % (imult)) hcrossHM_den.Scale(1. / (br_den * sigmav0_den * 1e12)) hratioHM.Divide(hcrossHM_den) hratioHM.SetLineColor(colors[imult % len(colors)]) hratioHM.SetMarkerColor(colors[imult % len(colors)]) hratioHM.SetTitle(";#it{p}_{T} (GeV/#it{c});%s / %s" % (name_num, name_den)) hratioHM.Draw("same") legyieldstring = "%.1f #leq %s < %.1f (HM)" % \ (binsmin_num[imult], latexbin2var, binsmax_num[imult]) legyield.AddEntry(hratioHM, legyieldstring, "LEP") fileoutput.cd() hratioHM.Write("hratio_fromHM_%.1f_%s_%.1f" % \ (binsmin_num[imult], latexbin2var, binsmax_num[imult])) legyield.Draw() ccross.SaveAs("%s/PtSpec_ComparisonRatios_%s%s_%scombined%s_logx.eps" % \ (folder_plots_num, case_num, case_den, arraytype[0], arraytype[1])) ccross.SaveAs("%s/PtSpec_ComparisonRatios_%s%s_%scombined%s_logx.eps" % \ (folder_plots_den, case_num, case_den, arraytype[0], arraytype[1])) ccross.cd(1).SetLogx(0) ccross.SaveAs("%s/PtSpec_ComparisonRatios_%s%s_%scombined%s.eps" % \ (folder_plots_num, case_num, case_den, arraytype[0], arraytype[1])) ccross.SaveAs("%s/PtSpec_ComparisonRatios_%s%s_%scombined%s.eps" % \ (folder_plots_den, case_num, case_den, arraytype[0], arraytype[1])) fileoutput.cd() ccross.Write() fileoutput.Close() rootfilenameden = "%s/ComparisonRatios_%s%s_%scombined%s.root" % \ (folder_plots_den, case_num, case_den, arraytype[0], arraytype[1]) copyfile(rootfilename, rootfilenameden) print("---Output stored in:", rootfilename, "and", rootfilenameden, "---")
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)