Beispiel #1
0
def SetStyle(styleName="MyStyle"):

    ## MyStyle or tdrStyle
    from ROOT import gROOT, gStyle

    gROOT.Reset()
    gROOT.ProcessLine(".x ~/rootmacros/myStyle.cc")
    gROOT.ProcessLine(".x ~/rootmacros/setTDRStyle.C")
    # gROOT.SetStyle("tdrStyle");
    # gROOT.SetStyle("MyStyle");
    gROOT.SetStyle(styleName)
    gStyle.SetOptLogy(0)
    gStyle.SetPalette(1)
    gStyle.SetOptTitle(0)
    gStyle.SetOptStat(0)
    gStyle.SetPadTopMargin(0.02)
    gStyle.SetPadTickX(1)

    gStyle.SetLabelSize(0.045, "XYZ")
    gStyle.SetLabelSize(0.04, "Y")
    gStyle.SetTitleSize(0.045, "XYZ")

    gROOT.ForceStyle()

    return
Beispiel #2
0
def SetStyle():
    gROOT.SetStyle('Plain')
    gROOT.ForceStyle()
    gStyle.SetTextFont(42)

    gStyle.SetOptTitle(0)
    gStyle.SetOptFit(1112)
    gStyle.SetOptStat(1110)

    gStyle.SetPadRightMargin(0.08)
    gStyle.SetPadTopMargin(0.11)
    gStyle.SetPadBottomMargin(0.12)

    gStyle.SetTitleFont(42, 'x')
    gStyle.SetTitleFont(42, 'y')
    gStyle.SetTitleFont(42, 'z')

    gStyle.SetTitleOffset(1.05, 'x')
    gStyle.SetTitleOffset(1.00, 'y')

    gStyle.SetTitleSize(0.05, 'x')
    gStyle.SetTitleSize(0.05, 'y')
    gStyle.SetTitleSize(0.05, 'z')

    gStyle.SetLabelFont(42, 'x')
    gStyle.SetLabelFont(42, 'y')
    gStyle.SetLabelFont(42, 'z')

    gStyle.SetLabelSize(0.05, 'x')
    gStyle.SetLabelSize(0.05, 'y')
    gStyle.SetLabelSize(0.05, 'z')

    TGaxis.SetMaxDigits(3)
    gStyle.SetStatY(0.9)
Beispiel #3
0
def SetTuningStyle():
    print "\nApplying TuningTool style settings..."
    tuningStyle = TuningStyle()
    from ROOT import gROOT, kTRUE
    gROOT.SetStyle("Tuning")
    gROOT.ForceStyle()
    gROOT.SetBatch(kTRUE)
Beispiel #4
0
def load_joeys_style():
    from ROOT import gStyle, gROOT
    font_id = 12
    gStyle.SetOptStat(0)
    gStyle.SetTitleFont(font_id, "X") # LaTeX typeface
    gStyle.SetTitleFont(font_id, "Y")
    gStyle.SetTitleFont(font_id, "Z")
    gStyle.SetTitleFont(font_id, "T")
    gStyle.SetLabelFont(font_id, "X") # LaTeX typeface
    gStyle.SetLabelFont(font_id, "Y")
    gStyle.SetLabelFont(font_id, "Z")
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
    gStyle.SetPadTopMargin(0.13)
    gStyle.SetPadBottomMargin(0.25)
    gStyle.SetPadLeftMargin(0.17)
    gStyle.SetPadRightMargin(0.25)
    gStyle.SetCanvasDefW(1500)
    gStyle.SetCanvasDefH(900)
    gStyle.SetTitleSize(0.06,"X")
    gStyle.SetTitleSize(0.06,"Y")
    gStyle.SetTitleSize(0.06,"Z")
    gStyle.SetTitleSize(0.06,"T") # for title
    gStyle.SetLabelSize(0.04,"X")
    gStyle.SetLabelSize(0.04,"Y")
    gStyle.SetLabelSize(0.04,"Z")
    gStyle.SetTitleOffset(1.5,"X")
    gStyle.SetTitleOffset(1.1,"Y")
    gStyle.SetTitleOffset(1.3,"Z")
    gROOT.ForceStyle()
Beispiel #5
0
 def __init__(self):
     super(StyleClass, self).__init__("CRRootStyle", "CRRootStyle")
     self.root_style_settings()
     self.cd()
     gROOT.SetStyle("CRRootStyle")
     gROOT.ForceStyle()
     TGaxis.SetMaxDigits(3)
Beispiel #6
0
def write_spikeroothistogram(vectorspikes, histogramtitle, ytitle,
                             rootdirectory, deltatime):
    """Function to perform ROOT histograms"""

    #Set ROOT histograms
    TH1Hist = TH1F(histogramtitle, "", 3, 0, 3)

    vectorspikes = [x[5:len(x)] for x in vectorspikes]

    #Fill histograms in for loop
    for entry in range(len(vectorspikes)):
        TH1Hist.Fill(vectorspikes[entry], 1. / (deltatime / 60))

    #Draw + DrawOptions histograms
    c = TCanvas()
    c.SetName(histogramtitle + "_canvas")
    Style = gStyle
    Style.SetLineWidth(1)  #TH1Hist
    Style.SetOptStat(0)  #Show statistics
    gROOT.ForceStyle()
    TH1Hist.SetCanExtend(TH1.kAllAxes)
    TH1Hist.SetFillColor(38)
    TH1Hist.LabelsDeflate()
    TH1Hist.SetMinimum(0)
    TH1Hist.SetMaximum(2)
    YAxis = TH1Hist.GetYaxis()
    YAxis.SetTitle(ytitle)
    rootdirectory.WriteTObject(TH1Hist)
    line = TLine(0., 1.0, len(set(vectorspikes)), 1.0)
    line.SetLineStyle(2)
    line.SetLineColor(2)
    TH1Hist.Draw("histo")
    line.Draw()
    rootdirectory.WriteTObject(c)
Beispiel #7
0
def looks_atlas2():

    atlasStyle = TStyle("ATLAS", "Atlas style")
    icol = 0
    atlasStyle.SetFrameBorderMode(icol)
    atlasStyle.SetFrameFillColor(icol)
    atlasStyle.SetCanvasBorderMode(icol)
    atlasStyle.SetCanvasColor(icol)
    atlasStyle.SetPadBorderMode(icol)
    atlasStyle.SetPadColor(icol)
    atlasStyle.SetStatColor(icol)
    atlasStyle.SetPaperSize(20, 26)

    atlasStyle.SetPadTopMargin(0.05)
    atlasStyle.SetPadRightMargin(0.05)
    atlasStyle.SetPadBottomMargin(0.16)
    atlasStyle.SetPadLeftMargin(0.16)

    atlasStyle.SetTitleXOffset(1.4)
    atlasStyle.SetTitleYOffset(1.4)

    font = 42
    tsize = 0.05
    atlasStyle.SetTextFont(font)

    atlasStyle.SetTextSize(tsize)
    atlasStyle.SetLabelFont(font, 'x')
    atlasStyle.SetTitleFont(font, 'x')
    atlasStyle.SetLabelFont(font, 'y')
    atlasStyle.SetTitleFont(font, 'y')
    atlasStyle.SetLabelFont(font, 'z')
    atlasStyle.SetTitleFont(font, 'z')

    atlasStyle.SetLabelSize(tsize, 'x')
    atlasStyle.SetTitleSize(tsize, 'x')
    atlasStyle.SetLabelSize(tsize, 'y')
    atlasStyle.SetTitleSize(tsize, 'y')
    atlasStyle.SetLabelSize(tsize, 'z')
    atlasStyle.SetTitleSize(tsize, 'z')

    atlasStyle.SetMarkerStyle(20)
    atlasStyle.SetMarkerSize(1.2)
    atlasStyle.SetHistLineWidth(2)
    atlasStyle.SetLineStyleString(2, '[12 12]')

    atlasStyle.SetEndErrorSize(0.)

    atlasStyle.SetOptTitle(0)
    atlasStyle.SetOptStat(0)
    atlasStyle.SetOptFit(0)

    atlasStyle.SetPadTickX(1)
    atlasStyle.SetPadTickY(1)

    atlasStyle.cd()
    gROOT.ForceStyle()
    atlasStyle.ls()
def SetAtlasStyle():
    """Applying ATLAS style settings globally.
    """
    print("\n{}\n".format(bcolor.green + "Applying ATLAS style settings..." +
                          bcolor.end))

    AtlasStyle()
    gROOT.SetStyle("ATLAS")
    gROOT.ForceStyle()
def setStyle():
    tdrStyle = Styles.tdrStyle.getStyle()

    #slight adaptation
    tdrStyle.SetPadRightMargin(0.05); #originally was 0.02, too narrow!
    tdrStyle.SetStatH(0.2);
    #tdrStyle.SetOptStat(1110);//off title
    tdrStyle.SetOptStat(0);#off title
    tdrStyle.SetOptFit(0);#off title
#    tdrStyle.SetTitleYOffset(1.6);
    tdrStyle.cd();
    gROOT.ForceStyle();     
Beispiel #10
0
def setAtlasStyle():
	from ROOT import TStyle
		
	atlasStyle = TStyle("ATLAS","Atlas style")

	atlasStyle.SetFrameBorderMode(0)
	atlasStyle.SetFrameFillColor(0)
	atlasStyle.SetCanvasBorderMode(0)
	atlasStyle.SetCanvasColor(0)
	atlasStyle.SetPadBorderMode(0)
	atlasStyle.SetPadColor(0)
	atlasStyle.SetStatColor(0)	
	atlasStyle.SetPaperSize(20,26)
	atlasStyle.SetPadTopMargin(0.07)
	atlasStyle.SetPadRightMargin(0.05)
	atlasStyle.SetPadBottomMargin(0.16)
	atlasStyle.SetPadLeftMargin(0.16)
	atlasStyle.SetTitleXOffset(1.4)
	atlasStyle.SetTitleYOffset(1.2)
	font=43
	tsize=0.05
	atlasStyle.SetTextFont(font)
	atlasStyle.SetTextSize(tsize)
	atlasStyle.SetLabelFont(font,"x")
	atlasStyle.SetTitleFont(font,"x")
	atlasStyle.SetLabelFont(font,"y")
	atlasStyle.SetTitleFont(font,"y")
	atlasStyle.SetLabelFont(font,"z")
	atlasStyle.SetTitleFont(font,"z")
	atlasStyle.SetLabelSize(tsize,"x")
	atlasStyle.SetTitleSize(tsize,"x")
	atlasStyle.SetLabelSize(tsize,"y")
	atlasStyle.SetTitleSize(tsize,"y")
	atlasStyle.SetLabelSize(tsize,"z")
	atlasStyle.SetTitleSize(tsize,"z")
	atlasStyle.SetMarkerStyle(20)
	atlasStyle.SetMarkerSize(1.2)
	atlasStyle.SetHistLineWidth(2)
	atlasStyle.SetLineStyleString(2,"[12 12]")
	atlasStyle.SetEndErrorSize(0.)
	atlasStyle.SetOptTitle(0)
	atlasStyle.SetOptStat(0)
	atlasStyle.SetOptFit(0)
	atlasStyle.SetPadTickX(1)
	atlasStyle.SetPadTickY(1)

	gROOT.SetStyle("ATLAS")
	gROOT.ForceStyle()
def plot_response(histos,profiles,profiles_noReg,profiles_Cat,style=False,outString=None):
    if style==True:
        gROOT.SetBatch(True)
        gROOT.ProcessLineSync(".x /mnt/t3nfs01/data01/shome/nchernya/HHbbgg_ETH_devel/scripts/setTDRStyle.C")
        gROOT.ForceStyle()
        gStyle.SetPadTopMargin(0.06)
        gStyle.SetPadRightMargin(0.04)
        gStyle.SetPadLeftMargin(0.15)
        
    c = ROOT.TCanvas("c","c",900,900)
    c.cd()
    histos.Draw("HISTBOX")
    colors=[ROOT.kRed,ROOT.kOrange-3,ROOT.kAzure+10]
    profiles.SetLineColor(colors[0])
    profiles.SetLineWidth(3)
    profiles.SetMarkerColor(colors[0])
    profiles.SetStats(0)
    profiles.Draw("PLsame")
    profiles_noReg.SetLineColor(colors[1])
    profiles_noReg.SetLineWidth(3)
    profiles_noReg.SetMarkerColor(colors[1])
    profiles_noReg.SetStats(0)
    profiles_noReg.Draw("PLsame")
    profiles_Cat.SetLineColor(colors[2])
    profiles_Cat.SetLineWidth(3)
    profiles_Cat.SetMarkerColor(colors[2])
    profiles_Cat.SetStats(0)
    profiles_Cat.Draw("PLsame")
    line = ROOT.TLine(histos.GetXaxis().GetBinCenter(0),1,histos.GetXaxis().GetBinCenter(histos.GetXaxis().GetNbins()),1)
    line.SetLineStyle(9)
    line.SetLineWidth(3)
    line.SetLineColor(ROOT.kGreen+1)
    line.Draw("Lsame")
    leg = ROOT.TLegend(0.72,0.75,0.95,0.9)
    leg.SetFillStyle(-1)
    leg.SetBorderSize(0)
    leg.SetTextFont(42)
    leg.SetTextSize(0.03)
    leg.AddEntry(profiles,"XGboost","PL")
    leg.AddEntry(profiles_noReg,"no regression","PL")
    leg.AddEntry(profiles_Cat,"HIG-16-044","PL")
    leg.Draw("same")
    
    c.SaveAs(utils.IO.plotFolder+"Response_"+histos.GetTitle()+'_'+str(outString)+'.png')
    c.SaveAs(utils.IO.plotFolder+"Response_"+histos.GetTitle()+'_'+str(outString)+'.pdf')
Beispiel #12
0
def main(extension, network_name, luminosity, output_flag, output_mod,
         veto_all_jets, generator, extra_text, fudge, text,
         Independant_Variable_List, Variable_list, WP_list, MC_list,
         Real_Data):
    gROOT.SetStyle("ATLAS")
    gROOT.ForceStyle()
    gStyle.SetErrorX(0.5)
    TH1.SetDefaultSumw2()

    OUTPUT_dir = os.path.join(os.environ["HOME_DIRECTORY"], "Output")

    ## Changing the name of the input file to match the generator
    if generator == "PowhegPythia":
        pass
    elif generator == "Sherpa":
        MC_list[0].file = "S" + MC_list[0].file
    elif generator == "MadGraph":
        MC_list[0].file = "MG" + MC_list[0].file
    else:
        print("\n\n\nUnknown Generator option\n\n\n")
        return 0

    ## Changing the name of the input files to match the jet selection
    if veto_all_jets:
        for mc in MC_list:
            mc.file = mc.file + "_NOJETS"
        Real_Data.file = Real_Data.file + "_NOJETS"
        extra_text += "0 Jets"

    ########## Plotting the independant variables ##########
    for ivar in Independant_Variable_List:
        STACK(extension, OUTPUT_dir, network_name, luminosity, output_flag,
              output_mod, generator, extra_text, fudge, text, MC_list,
              Real_Data, ivar, None)

    ########## Loading and Plotting the TH1Ds ##########
    for var in Variable_list:
        for wp in WP_list:

            STACK(extension, OUTPUT_dir, network_name, luminosity, output_flag,
                  output_mod, generator, extra_text, fudge, text, MC_list,
                  Real_Data, var, wp)

    return 0
Beispiel #13
0
    def __init__(self):
        '''
        Set up PlotStyle, set gStyle for things we always want no matter what.
        '''
        # CMS-approved everything
        tdrstyle.setTDRStyle()

        ### Differences from TDR standard:

        # Big canvas (can always shrink later)
        gStyle.SetCanvasDefH(1200)
        gStyle.SetCanvasDefW(1200)

        # Tick marks on all sides
        gStyle.SetPadTickX(1)
        gStyle.SetPadTickY(1)

        # Everything has white backgrounds
        gStyle.SetLegendFillColor(0)

        # Colors that don't suck
        gStyle.SetPalette(1)

        # Make axis title and labels just a little smaller and (for Y) closer to the axis
        gStyle.SetTitleSize(0.044, "XYZ")
        gStyle.SetLabelSize(0.033, "XYZ")
        gStyle.SetTitleYOffset(1.15)
        gStyle.SetTitleXOffset(0.95)
        gStyle.SetPadLeftMargin(0.1)
        gStyle.SetPadRightMargin(0.025)
        gStyle.SetPadBottomMargin(0.095)
        gStyle.SetTitleAlign(12)

        # Apply changes
        gROOT.ForceStyle()

        # Force exponentials when axes are over 3 digits
        TGaxis.SetMaxDigits(3)
        TGaxis.SetExponentOffset(-0.060, 0.008, "y")
        TGaxis.SetExponentOffset(
            -0.055, -0.062,
            "x")  # will overlap with title unless title is centered
Beispiel #14
0
def plot(config):
    gROOT.ForceStyle()
    sel_opts = np.array(config.opt_predout)
    sel_opts_names = np.array(config.nameopt_predout)
    sel_opts_names = sel_opts_names[sel_opts == 1]
    for opt_name in sel_opts_names:
        myfile = TFile.Open("%s/output_%s_nEv%d.root" % \
                            (config.dirapply, config.suffix,
                             config.train_events), "open")
        h_dist_all_events = myfile.Get("%s_all_events_%s" %
                                       (config.h_dist_name, config.suffix))
        h_deltas_all_events = myfile.Get("%s_all_events_%s" % \
                                         (config.h_deltas_name, config.suffix))
        h_deltas_vs_dist_all_events = myfile.Get("%s_all_events_%s" % \
                                                 (config.h_deltas_vs_dist_name,
                                                  config.suffix))
        profile_deltas_vs_dist_all_events = \
            myfile.Get("%s_all_events_%s" % (config.profile_name, config.suffix))

        plot_distortion(config, h_dist_all_events, h_deltas_all_events,
                        h_deltas_vs_dist_all_events,
                        profile_deltas_vs_dist_all_events, config.suffix,
                        opt_name)

        if config.per_event_hists:
            counter = 0
            for iexperiment in config.partition['apply']:
                h_suffix = "Ev%d_Mean%d_%s" % (iexperiment[0], iexperiment[1],
                                               config.suffix)
                h_dist = myfile.Get("%s_%s" % (config.h_dist_name, h_suffix))
                h_deltas = myfile.Get("%s_%s" %
                                      (config.h_deltas_name, h_suffix))
                h_deltas_vs_dist = myfile.Get(
                    "%s_%s" % (config.h_deltas_vs_dist_name, h_suffix))
                profile = myfile.Get("%s_%s" % (config.profile_name, h_suffix))
                plot_distortion(config, h_dist, h_deltas, h_deltas_vs_dist,
                                profile, h_suffix, opt_name)
                counter = counter + 1
                if counter > 100:
                    return
Beispiel #15
0
def main():

    extension = "pdf"

    luminosity = 44307.4
    ymin = 0
    ymax = 0.024

    data_set_names = [
        (["SZee_all_susy_2l_0jets.root",
          "SZmumu_all_susy_2l_0jets.root"], "Z#rightarrowll", 860 + 0, 23),
        (["ZZ_1in3_susy_2l_0jets.root"], "ZZ#rightarrowll#nu#nu", 416 + 3, 43),
        (["WZ_1in3_susy_2l_0jets.root"], "WZ#rightarrowl#null", 416 - 8, 33),
        (["WW_1in3_susy_2l_0jets.root"], "WW#rightarrowl#nul#nu", 416 + 0, 20),
        ([
            "ttbar_1in3_susy_2l_0jets.root", "top_1in3_susy_2l_0jets.root",
            "antitop_1in3_susy_2l_0jets.root"
        ], "Top", 800 + 4, 21),
    ]

    DATA_dir = os.path.join(os.environ["HOME_DIRECTORY"], "Data", "SR_SUSY")

    ## Creating the plots
    gROOT.SetStyle("ATLAS")
    gROOT.ForceStyle()
    gStyle.SetErrorX(0.5)
    canvas = TCanvas("canvas", 'A basic canvas', 800, 600)
    # canvas.SetLogy()

    ## Adding in the legend
    leg = Plotting.Create_Legend(0.60, 0.60, 0.95, 0.95, ncols=1)

    ## Creating the stack
    stack = THStack("stack", "stack")
    stack.SetMinimum(ymin)
    stack.SetMaximum(ymax)

    ## Cycling through the different datasets
    for datasets, label, colour, style in data_set_names:

        ## Creating the total histogram which will be filled
        myhist = TH1D(label, label, 50, 0, 150)
        myhist.SetStats(True)
        myhist.StatOverflows(True)

        for dataset in datasets:

            ## The root file is opened
            rootfile_name = os.path.join(DATA_dir, dataset)
            print(rootfile_name)
            root_file = TFile.Open(rootfile_name, 'read')
            tree = root_file.Get("mt2_Truth")

            ## Creating the current histogram which will be filled
            thishist = TH1D(label, label, 50, 0, 150)
            thishist.SetStats(True)
            thishist.StatOverflows(True)

            ## Drawing the tree and saving the hist to the matrix
            execution = "mt2>>{}".format(label)
            tree.Draw(execution, "", "goff")

            thishist.SetDirectory(0)
            myhist.Add(thishist)

            ## We are dont with the file
            root_file.Close()
            del root_file

        ## Changing the properties of the histogram
        myhist.Scale(1 / myhist.Integral("width"))

        myhist.SetLineColor(colour)
        myhist.SetMarkerColor(colour)
        myhist.SetMarkerStyle(style)
        myhist.SetMarkerSize(1.5)

        ## Adding the legend entry
        leg.AddEntry(myhist, label, "p")

        ## Adding the object to the stack
        stack.Add(myhist)
        del myhist

    ## Drawing the stack on the currrent canvas
    stack.Draw("NOSTACK HIST P")
    leg.Draw()

    ## Setting axis labels
    stack.GetXaxis().SetTitle("m_{T2} (True #it{E}_{T}^{miss}) [GeV]")
    stack.GetYaxis().SetTitle("Normalised Distributions")

    ## Moving axis tick marks
    stack.GetYaxis().SetMaxDigits(3)
    stack.GetXaxis().SetLabelOffset(0.017)

    ## Drawing all text
    left = 0.2
    size = 1.0
    shift = 0.06
    pos = 0.88
    Plotting.Draw_ATLASLabel(left, pos, "Simulation", scale=1.0)
    pos -= shift
    Plotting.Draw_Text(left, pos, "work in progress", scale=size)
    pos -= shift
    Plotting.Draw_Lumi(left, pos, 0, scale=size)
    pos -= shift

    ## Updating the canvas
    canvas.Update()

    out_file = "true_strans.{}".format(extension)
    canvas.Print(out_file)

    del canvas

    return 0
Beispiel #16
0
def SetAtlasStyle():
    print "\nApplying ATLAS style settings..."
    atlasStyle = AtlasStyle()
    gROOT.SetStyle("ATLAS")
    gROOT.ForceStyle()
Beispiel #17
0
def setStyle():

    style = TStyle('style', 'style')

    style.SetCanvasBorderMode(0)
    style.SetCanvasColor(ROOT.kWhite)
    style.SetCanvasDefH(600)
    style.SetCanvasDefW(600)
    style.SetCanvasDefX(0)
    style.SetCanvasDefY(0)

    style.SetPadBorderMode(0)
    style.SetPadColor(ROOT.kWhite)
    style.SetPadGridX(False)
    style.SetPadGridY(False)
    style.SetGridColor(0)
    style.SetGridStyle(3)
    style.SetGridWidth(1)

    style.SetFrameBorderMode(0)
    style.SetFrameBorderSize(1)
    style.SetFrameFillColor(0)
    style.SetFrameFillStyle(0)
    style.SetFrameLineColor(1)
    style.SetFrameLineStyle(1)
    style.SetFrameLineWidth(1)

    style.SetHistLineColor(1)
    style.SetHistLineStyle(0)
    style.SetHistLineWidth(1)

    style.SetEndErrorSize(2)
    style.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:
    style.SetOptFile(0)
    style.SetOptStat(0)
    style.SetStatColor(ROOT.kWhite)
    style.SetStatFont(42)
    style.SetLegendFont(42)
    style.SetStatFontSize(0.08)
    style.SetStatTextColor(1)
    style.SetStatFormat("6.4g")
    style.SetStatBorderSize(1)
    style.SetStatH(0.7)
    style.SetStatW(0.15)
    #//gStyle->SetStatTextSize(2.5);

    #gStyle->SetStatX(0.96);
    #//gStyle->SetStatY(0.35);
    #// gStyle->SetStatStyle(Style_t style = 1001);
    #// gStyle->SetStatX(Float_t x = 0);
    #// gStyle->SetStatY(Float_t y = 0);

    #Margins:
    style.SetPadTopMargin(0.05)
    style.SetPadBottomMargin(0.13)
    style.SetPadLeftMargin(0.16)
    style.SetPadRightMargin(0.04)

    # For the Global title:
    style.SetOptTitle(0)
    style.SetTitleFont(42)
    style.SetTitleColor(1)
    style.SetTitleTextColor(1)
    style.SetTitleFillColor(10)
    style.SetTitleFontSize(0.05)

    #For the axis titles:
    style.SetTitleColor(1, "XYZ")
    style.SetTitleFont(42, "XYZ")
    style.SetTitleSize(0.06, "XYZ")
    style.SetTitleXOffset(0.9)
    style.SetTitleYOffset(1.25)

    #For the axis labels:
    style.SetLabelColor(1, "XYZ")
    style.SetLabelFont(42, "XYZ")
    style.SetLabelOffset(0.007, "XYZ")
    style.SetLabelSize(0.05, "XYZ")

    #For the axis:
    style.SetAxisColor(1, "XYZ")
    style.SetStripDecimals(ROOT.kTRUE)
    style.SetTickLength(0.03, "XYZ")
    style.SetNdivisions(505, "XYZ")
    style.SetPadTickX(1)
    style.SetPadTickY(1)

    style.SetEndErrorSize(0.)

    ##Change for log plots:
    #gStyle->SetOptLogx(0);
    #gStyle->SetOptLogy(0);
    #gStyle->SetOptLogz(0);

    #// Postscript options:
    #gStyle->SetPaperSize(20.,20.);
    #// gStyle->SetLineScalePS(Float_t scale = 3);
    #// gStyle->SetLineStyleString(Int_t i, const char* text);
    #// gStyle->SetHeaderPS(const char* header);
    #// gStyle->SetTitlePS(const char* pstitle);

    #// gStyle->SetBarOffset(Float_t baroff = 0.5);
    #// gStyle->SetBarWidth(Float_t barwidth = 0.5);
    #// gStyle->SetPaintTextFormat(const char* format = "g");
    #// gStyle->SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
    #// gStyle->SetTimeOffset(Double_t toffset);
    #// gStyle->SetHistMinimumZero(kTRUE);

    #//For error in SF maps
    #gStyle->SetMarkerSize(0.9); //TEMPORARY SIZE FOR DILEPTON PLOTS. SET BACK TO DEFAULT FOR TRILEPTON
    #gStyle->SetPaintTextFormat("4.2f");  //4.2
    #//gStyle->SetHatchesLineWidth(5);
    #//gStyle->SetHatchesSpacing(0.05);

    style.SetLegendBorderSize(0)
    gROOT.SetStyle('style')
    gROOT.ForceStyle()

    return style
def setLHCbStyle():
    global lhcbStyle
    global lhcbText
    global lhcbLatex

    lhcbStyle = TStyle("lhcbStyle", "Standard LHCb plots style")

    # use times new roman
    lhcbFont = 132
    # line thickness
    lhcbWidth = 2
    lhcbTSize = 0.06

    #// use plain black on white colors
    lhcbStyle.SetFrameBorderMode(0)
    lhcbStyle.SetCanvasBorderMode(0)
    lhcbStyle.SetPadBorderMode(0)
    lhcbStyle.SetPadColor(0)
    lhcbStyle.SetCanvasColor(0)
    lhcbStyle.SetStatColor(0)
    lhcbStyle.SetPalette(1)

    lhcbStyle.SetLegendBorderSize(0)
    lhcbStyle.SetLegendFont(132)
    lhcbStyle.SetFillColor(1)
    lhcbStyle.SetFillStyle(1001)

    # set the paper & margin sizes
    lhcbStyle.SetPaperSize(20, 26)

    lhcbStyle.SetPadTopMargin(0.1)

    lhcbStyle.SetPadRightMargin(0.05)
    lhcbStyle.SetPadBottomMargin(0.16)
    lhcbStyle.SetPadLeftMargin(0.14)

    # use large fonts
    lhcbStyle.SetTextFont(lhcbFont)
    lhcbStyle.SetTextSize(lhcbTSize)
    #  lhcbStyle.SetTextSize(0.08)
    lhcbStyle.SetLabelFont(lhcbFont, "x")
    lhcbStyle.SetLabelFont(lhcbFont, "y")
    lhcbStyle.SetLabelFont(lhcbFont, "z")
    lhcbStyle.SetLabelSize(lhcbTSize, "x")
    lhcbStyle.SetLabelSize(lhcbTSize, "y")
    lhcbStyle.SetLabelSize(lhcbTSize, "z")
    lhcbStyle.SetTitleFont(lhcbFont)
    lhcbStyle.SetTitleFont(lhcbFont, "x")
    lhcbStyle.SetTitleFont(lhcbFont, "y")
    lhcbStyle.SetTitleFont(lhcbFont, "z")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "x")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "y")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "z")

    # use bold lines and markers
    lhcbStyle.SetLineWidth(lhcbWidth)
    lhcbStyle.SetFrameLineWidth(lhcbWidth)
    lhcbStyle.SetHistLineWidth(lhcbWidth)
    lhcbStyle.SetFuncWidth(lhcbWidth)
    lhcbStyle.SetGridWidth(lhcbWidth)
    lhcbStyle.SetLineStyleString(2, "[12 12]")
    lhcbStyle.SetMarkerStyle(20)
    lhcbStyle.SetMarkerSize(1.0)

    # label offsets
    lhcbStyle.SetLabelOffset(0.010)

    #titles
    lhcbStyle.SetTitleOffset(0.95, "X")
    lhcbStyle.SetTitleOffset(0.95, "Y")
    lhcbStyle.SetTitleOffset(1.2, "Z")
    lhcbStyle.SetTitleFillColor(0)
    lhcbStyle.SetTitleStyle(0)
    lhcbStyle.SetTitleBorderSize(0)
    lhcbStyle.SetTitleFont(lhcbFont, "title")
    lhcbStyle.SetTitleX(0.0)
    lhcbStyle.SetTitleY(1.0)
    lhcbStyle.SetTitleW(1.0)
    lhcbStyle.SetTitleH(0.05)

    # by default, do not display histogram decorations:
    lhcbStyle.SetOptStat(0)
    #lhcbStyle.SetOptStat("emr")     # show only nent -e , mean - m , rms -r
    #lhcbStyle.SetStatFormat("6.3g") # specified as c printf options
    lhcbStyle.SetOptTitle(0)
    lhcbStyle.SetOptFit(0)
    #lhcbStyle.SetOptFit(1011) # order is probability, Chi2, errors, parameters

    # look of the statistics box:
    lhcbStyle.SetStatBorderSize(0)
    lhcbStyle.SetStatFont(lhcbFont)
    lhcbStyle.SetStatFontSize(0.05)
    lhcbStyle.SetStatX(0.93)
    lhcbStyle.SetStatY(0.88)
    lhcbStyle.SetStatW(0.20)
    lhcbStyle.SetStatH(0.15)

    # put tick marks on top and RHS of plots
    lhcbStyle.SetPadTickX(1)
    lhcbStyle.SetPadTickY(1)

    # histogram divisions: only 5 in x to avoid label overlaps
    lhcbStyle.SetNdivisions(505, "x")
    lhcbStyle.SetNdivisions(505, "y")
    lhcbStyle.SetNdivisions(505, "z")

    # define style for text
    lhcbLabel = TText()
    lhcbLabel.SetTextFont(lhcbFont)
    lhcbLabel.SetTextColor(1)
    lhcbLabel.SetTextSize(0.04)
    lhcbLabel.SetTextAlign(12)

    # define style of latex text
    lhcbLatex = TLatex()
    lhcbLatex.SetTextFont(lhcbFont)
    lhcbLatex.SetTextColor(1)
    lhcbLatex.SetTextSize(0.04)
    lhcbLatex.SetTextAlign(12)

    # set this style
    gROOT.SetStyle("lhcbStyle")
    gROOT.ForceStyle()
    return
Beispiel #19
0
def looks_atlas():
    atlasStyle = TStyle("ATLAS", "Atlas style")

    # use plain black on white colors
    icol = int(0)
    # WHITE
    atlasStyle.SetFrameBorderMode(icol)
    atlasStyle.SetFrameFillColor(icol)
    atlasStyle.SetCanvasBorderMode(icol)
    atlasStyle.SetCanvasColor(icol)
    atlasStyle.SetPadBorderMode(icol)
    atlasStyle.SetPadColor(icol)
    atlasStyle.SetStatColor(icol)
    #atlasStyle.SetFillColor(icol); # don't use: white fill color for *all* objects

    # set the paper & margin sizes
    atlasStyle.SetPaperSize(20, 26)

    # set margin sizes
    atlasStyle.SetPadTopMargin(0.05)
    atlasStyle.SetPadRightMargin(0.05)
    atlasStyle.SetPadBottomMargin(0.16)
    atlasStyle.SetPadLeftMargin(0.16)

    # set title offsets (for axis label)
    atlasStyle.SetTitleXOffset(1)
    atlasStyle.SetTitleYOffset(1)

    # use large fonts
    #Int_t font=72; # Helvetica italics
    font = int(42)
    # Helvetica
    tsize = int(0.05)
    atlasStyle.SetTextFont(font)

    atlasStyle.SetTextSize(tsize)
    atlasStyle.SetLabelFont(font, "x")
    atlasStyle.SetTitleFont(font, "x")
    atlasStyle.SetLabelFont(font, "y")
    atlasStyle.SetTitleFont(font, "y")
    atlasStyle.SetLabelFont(font, "z")
    atlasStyle.SetTitleFont(font, "z")

    atlasStyle.SetLabelSize(tsize, "x")
    atlasStyle.SetTitleSize(tsize, "x")
    atlasStyle.SetLabelSize(tsize, "y")
    atlasStyle.SetTitleSize(tsize, "y")
    atlasStyle.SetLabelSize(tsize, "z")
    atlasStyle.SetTitleSize(tsize, "z")

    # use bold lines and markers
    atlasStyle.SetMarkerStyle(20)
    atlasStyle.SetMarkerSize(1.2)
    atlasStyle.SetHistLineWidth(2)
    atlasStyle.SetLineStyleString(2, "[12 12]")
    # postscript dashes

    # get rid of X error bars
    #atlasStyle.SetErrorX(0.001);
    # get rid of error bar caps
    atlasStyle.SetEndErrorSize(0.)

    # do not display any of the standard histogram decorations
    atlasStyle.SetOptTitle(0)
    #atlasStyle.SetOptStat(1111);
    atlasStyle.SetOptStat(0)
    #atlasStyle.SetOptFit(1111)
    atlasStyle.SetOptFit(0)

    # put tick marks on top and RHS of plots
    atlasStyle.SetPadTickX(1)
    atlasStyle.SetPadTickY(1)
    atlasStyle.cd()
    gROOT.ForceStyle()
    gStyle.ls()
Beispiel #20
0
def looks_CmsTDR():
    tdrStyle = TStyle("tdrStyle", "Style for P-TDR")

    # For the canvas:
    tdrStyle.SetCanvasBorderMode(0)
    tdrStyle.SetCanvasColor(ROOT.kWhite)
    tdrStyle.SetCanvasDefH(600)
    #Height of canvas
    tdrStyle.SetCanvasDefW(600)
    #Width of canvas
    tdrStyle.SetCanvasDefX(0)
    #POsition on screen
    tdrStyle.SetCanvasDefY(0)

    # For the Pad:
    tdrStyle.SetPadBorderMode(0)
    # tdrStyle.SetPadBorderSize(Width_t size = 1);
    tdrStyle.SetPadColor(ROOT.kWhite)
    #tdrStyle.SetPadGridX(false);
    #tdrStyle.SetPadGridY(false);
    tdrStyle.SetGridColor(0)
    tdrStyle.SetGridStyle(3)
    tdrStyle.SetGridWidth(1)

    # For the frame:
    tdrStyle.SetFrameBorderMode(0)
    tdrStyle.SetFrameBorderSize(1)
    tdrStyle.SetFrameFillColor(0)
    tdrStyle.SetFrameFillStyle(0)
    tdrStyle.SetFrameLineColor(1)
    tdrStyle.SetFrameLineStyle(1)
    tdrStyle.SetFrameLineWidth(1)

    # For the histo:
    # tdrStyle.SetHistFillColor(1);
    # tdrStyle.SetHistFillStyle(0);
    tdrStyle.SetHistLineColor(1)
    tdrStyle.SetHistLineStyle(0)
    tdrStyle.SetHistLineWidth(1)
    # tdrStyle.SetLegoInnerR(Float_t rad = 0.5);
    # tdrStyle.SetNumberContours(Int_t number = 20);

    tdrStyle.SetEndErrorSize(2)
    #tdrStyle.SetErrorMarker(20);  # Seems to give an error
    tdrStyle.SetErrorX(0.)

    tdrStyle.SetMarkerStyle(20)

    #For the fit/function:
    tdrStyle.SetOptFit(1)
    tdrStyle.SetFitFormat("5.4g")
    tdrStyle.SetFuncColor(2)
    tdrStyle.SetFuncStyle(1)
    tdrStyle.SetFuncWidth(1)

    #For the date:
    tdrStyle.SetOptDate(0)
    # tdrStyle.SetDateX(Float_t x = 0.01);
    # tdrStyle.SetDateY(Float_t y = 0.01);

    # For the statistics box:
    tdrStyle.SetOptFile(0)
    tdrStyle.SetOptStat(0)
    # To display the mean and RMS:   SetOptStat("mr");
    tdrStyle.SetStatColor(ROOT.kWhite)
    tdrStyle.SetStatFont(42)
    tdrStyle.SetStatFontSize(0.025)
    tdrStyle.SetStatTextColor(1)
    tdrStyle.SetStatFormat("6.4g")
    tdrStyle.SetStatBorderSize(1)
    tdrStyle.SetStatH(0.1)
    tdrStyle.SetStatW(0.15)
    # tdrStyle.SetStatStyle(Style_t style = 1001);
    # tdrStyle.SetStatX(Float_t x = 0);
    # tdrStyle.SetStatY(Float_t y = 0);

    # Margins:
    tdrStyle.SetPadTopMargin(0.05)
    tdrStyle.SetPadBottomMargin(0.13)
    tdrStyle.SetPadLeftMargin(0.16)
    tdrStyle.SetPadRightMargin(0.02)

    # For the Global title:
    tdrStyle.SetOptTitle(1)
    # 0=No Title
    tdrStyle.SetTitleFont(42)
    tdrStyle.SetTitleColor(1)
    tdrStyle.SetTitleTextColor(1)
    tdrStyle.SetTitleFillColor(10)
    tdrStyle.SetTitleFontSize(0.05)
    # tdrStyle.SetTitleH(0); # Set the height of the title box
    # tdrStyle.SetTitleW(0); # Set the width of the title box
    # tdrStyle.SetTitleX(0); # Set the position of the title box
    # tdrStyle.SetTitleY(0.985); # Set the position of the title box
    # tdrStyle.SetTitleStyle(Style_t style = 1001);
    # tdrStyle.SetTitleBorderSize(2);

    # For the axis titles:
    tdrStyle.SetTitleColor(1, "XYZ")
    tdrStyle.SetTitleFont(42, "XYZ")
    tdrStyle.SetTitleSize(0.06, "XYZ")
    # tdrStyle.SetTitleXSize(Float_t size = 0.02); # Another way to set the size?
    # tdrStyle.SetTitleYSize(Float_t size = 0.02);
    tdrStyle.SetTitleXOffset(0.9)
    tdrStyle.SetTitleYOffset(1.25)
    # tdrStyle.SetTitleOffset(1.1, "Y"); # Another way to set the Offset

    # For the axis labels:
    tdrStyle.SetLabelColor(1, "XYZ")
    tdrStyle.SetLabelFont(42, "XYZ")
    tdrStyle.SetLabelOffset(0.007, "XYZ")
    tdrStyle.SetLabelSize(0.05, "XYZ")

    # For the axis:
    tdrStyle.SetAxisColor(1, "XYZ")
    tdrStyle.SetStripDecimals(ROOT.kTRUE)
    tdrStyle.SetTickLength(0.03, "XYZ")
    tdrStyle.SetNdivisions(510, "XYZ")
    tdrStyle.SetPadTickX(0)
    # 0=Text labels (and tics) only on bottom, 1=Text labels on top and bottom
    tdrStyle.SetPadTickY(1)

    # Change for log plots:
    tdrStyle.SetOptLogx(0)
    tdrStyle.SetOptLogy(0)
    tdrStyle.SetOptLogz(0)

    # Postscript options:
    tdrStyle.SetPaperSize(20., 20.)
    # tdrStyle.SetLineScalePS(Float_t scale = 3);
    # tdrStyle.SetLineStyleString(Int_t i, const char* text);
    # tdrStyle.SetHeaderPS(const char* header);
    # tdrStyle.SetTitlePS(const char* pstitle);

    # tdrStyle.SetBarOffset(Float_t baroff = 0.5);
    # tdrStyle.SetBarWidth(Float_t barwidth = 0.5);
    # tdrStyle.SetPaintTextFormat(const char* format = "g");
    # tdrStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
    # tdrStyle.SetTimeOffset(Double_t toffset);
    # tdrStyle.SetHistMinimumZero(kTRUE);

    tdrStyle.cd()
    gROOT.ForceStyle()
    # Try this if stuff doesn't work right
    gStyle.ls()
Beispiel #21
0
def looks_minos():
    minosStyle = TStyle("minosStyle", "MINOS Style")

    # Colors
    #set the background color to white
    minosStyle.SetFillColor(10)
    minosStyle.SetFrameFillColor(10)
    minosStyle.SetCanvasColor(10)
    minosStyle.SetPadColor(10)
    minosStyle.SetTitleFillColor(0)
    minosStyle.SetStatColor(10)

    #dont put a colored frame around the plots
    minosStyle.SetFrameBorderMode(0)
    minosStyle.SetCanvasBorderMode(0)
    minosStyle.SetPadBorderMode(0)

    #use the primary color palette
    #minosStyle.SetPalette(1,0);

    #set the default line color for a histogram to be black
    minosStyle.SetHistLineColor(ROOT.kBlack)

    #set the default line color for a fit function to be red
    minosStyle.SetFuncColor(ROOT.kRed)

    #make the axis labels black
    minosStyle.SetLabelColor(ROOT.kBlack, "xyz")

    #set the default title color to be black
    minosStyle.SetTitleColor(ROOT.kBlack)

    # Sizes

    #set the margins
    minosStyle.SetPadBottomMargin(0.2)
    minosStyle.SetPadTopMargin(0.075)
    minosStyle.SetPadLeftMargin(0.15)

    #set axis label and title text sizes
    minosStyle.SetLabelSize(0.05, "xyz")
    minosStyle.SetTitleSize(0.06, "xyz")
    minosStyle.SetTitleOffset(0.9, "x")
    minosStyle.SetTitleOffset(0.8, "yz")
    minosStyle.SetStatFontSize(0.05)
    minosStyle.SetTextSize(0.06)
    minosStyle.SetTitleBorderSize(0)
    minosStyle.SetStatBorderSize(0)

    #set line widths
    minosStyle.SetHistLineWidth(2)
    minosStyle.SetFrameLineWidth(2)
    minosStyle.SetFuncWidth(2)

    # Misc

    #align the titles to be centered
    minosStyle.SetTitleAlign(22)

    #set the number of divisions to show
    minosStyle.SetNdivisions(506, "xy")

    #turn off xy grids
    minosStyle.SetPadGridX(0)
    minosStyle.SetPadGridY(0)

    #set the tick mark style
    #minosStyle.SetPadTickX(1);
    #minosStyle.SetPadTickY(1);

    #show the fit parameters in a box
    minosStyle.SetOptFit(1111)

    #turn off all other stats
    minosStyle.SetOptStat(0000000)

    #marker settings
    minosStyle.SetMarkerStyle(8)
    minosStyle.SetMarkerSize(0.9)

    # Fonts

    kMinosFont = int(42)

    minosStyle.SetStatFont(kMinosFont)
    minosStyle.SetLabelFont(kMinosFont, "xyz")
    minosStyle.SetTitleFont(kMinosFont, "xyz")
    minosStyle.SetTextFont(kMinosFont)

    #done
    minosStyle.cd()

    gROOT.ForceStyle()
    gStyle.ls()
Beispiel #22
0
atlasStyle.SetOptTitle(0)
#atlasStyle.SetOptStat(1111)
atlasStyle.SetOptStat(0)
#atlasStyle.SetOptFit(1111)
atlasStyle.SetOptFit(0)

# put tick marks on top and RHS of plots
atlasStyle.SetPadTickX(1)
atlasStyle.SetPadTickY(1)

gROOT.SetStyle("Plain")

#gStyle.SetPadTickX(1)
#gStyle.SetPadTickY(1)
gROOT.SetStyle("ATLAS")
gROOT.ForceStyle() 
gStyle.SetOptTitle(0)
gStyle.SetOptStat(0) 
gStyle.SetOptFit(0) 
# overwrite atlas styles

atlasStyle.SetMarkerSize(1.0)
atlasStyle.SetPadLeftMargin(0.14)  
atlasStyle.SetPadRightMargin(0.03)    
atlasStyle.SetPadBottomMargin(0.12)     
atlasStyle.SetPadTopMargin(0.05)  
atlasStyle.SetFrameFillColor(0)

def ATLASLabel(x,y,shift,studytype,color=1): 
  l=TLatex(x, y, "ATLAS") 
  l.SetNDC()
def SetGlobalStyle(**kwargs):
    '''
    Method to set global style.

    Parameters
    ----------

    - padrightmargin (float), default = 0.035
    - padleftmargin (float), default = 0.12
    - padtopmargin (float), default = 0.035
    - padbottommargin (float), default = 0.12

    - titlesize (float), default = 0.050
    - titlesizex (float), default = 0.050
    - titlesizey (float), default = 0.050
    - titlesizez (float), default = 0.050

    - labelsize (float), default = 0.045
    - labelsizex (float), default = 0.045
    - labelsizey (float), default = 0.045
    - labelsizez (float), default = 0.045

    - titleoffset (float), default = 1.2
    - titleoffsetx (float), default = 1.2
    - titleoffsey (float), default = 1.2
    - titleoffsetz (float), default = 1.2

    - opttitle (int), default = 0
    - optstat (int), default = 0

    - padtickx (int), default = 1
    - padticky (int), default = 1

    - maxdigits (int), default no max value

    - palette (int), default kBird
    '''

    # pad margins
    if 'padrightmargin' in kwargs:
        gStyle.SetPadRightMargin(kwargs['padrightmargin'])
    else:
        gStyle.SetPadRightMargin(0.035)

    if 'padleftmargin' in kwargs:
        gStyle.SetPadLeftMargin(kwargs['padleftmargin'])
    else:
        gStyle.SetPadLeftMargin(0.12)

    if 'padtopmargin' in kwargs:
        gStyle.SetPadTopMargin(kwargs['padtopmargin'])
    else:
        gStyle.SetPadTopMargin(0.035)

    if 'padbottommargin' in kwargs:
        gStyle.SetPadBottomMargin(kwargs['padbottommargin'])
    else:
        gStyle.SetPadBottomMargin(0.1)

    # title sizes
    if 'titlesize' in kwargs:
        gStyle.SetTitleSize(kwargs['titlesize'], 'xyz')
    else:
        gStyle.SetTitleSize(0.050, 'xyz')

    if 'titlesizex' in kwargs:
        gStyle.SetTitleSize(kwargs['titlesizex'], 'x')
    if 'titlesizey' in kwargs:
        gStyle.SetTitleSize(kwargs['titlesizex'], 'y')
    if 'titlesizez' in kwargs:
        gStyle.SetTitleSize(kwargs['titlesizex'], 'z')

    # label sizes
    if 'labelsize' in kwargs:
        gStyle.SetLabelSize(kwargs['labelsize'], 'xyz')
    else:
        gStyle.SetLabelSize(0.045, 'xyz')

    if 'labelsizex' in kwargs:
        gStyle.SetLabelSize(kwargs['labelsizex'], 'x')
    if 'labelsizey' in kwargs:
        gStyle.SetLabelSize(kwargs['labelsizex'], 'y')
    if 'labelsizez' in kwargs:
        gStyle.SetLabelSize(kwargs['labelsizex'], 'z')

    # title offsets
    if 'titleoffset' in kwargs:
        gStyle.SetTitleOffset(kwargs['titleoffset'], 'xyz')
    else:
        gStyle.SetTitleOffset(1.2, 'xyz')

    if 'titleoffsetx' in kwargs:
        gStyle.SetTitleOffset(kwargs['titleoffsetx'], 'x')
    if 'titleoffsety' in kwargs:
        gStyle.SetTitleOffset(kwargs['titleoffsety'], 'y')
    if 'titleoffsetz' in kwargs:
        gStyle.SetTitleOffset(kwargs['titleoffsetz'], 'z')

    # other options
    if 'opttitle' in kwargs:
        gStyle.SetOptTitle(kwargs['opttitle'])
    else:
        gStyle.SetOptTitle(0)

    if 'optstat' in kwargs:
        gStyle.SetOptStat(kwargs['optstat'])
    else:
        gStyle.SetOptStat(0)

    if 'padtickx' in kwargs:
        gStyle.SetPadTickX(kwargs['padtickx'])
    else:
        gStyle.SetPadTickX(1)

    if 'padticky' in kwargs:
        gStyle.SetPadTickY(kwargs['padticky'])
    else:
        gStyle.SetPadTickY(1)

    gStyle.SetLegendBorderSize(0)

    if 'maxdigits' in kwargs:
        TGaxis.SetMaxDigits(kwargs['maxdigits'])

    if 'palette' in kwargs:
        gStyle.SetPalette(kwargs['palette'])

    gROOT.ForceStyle()
Beispiel #24
0
def draw_multievent_hist(config, events_counts, func_label, hist_name, source_hist):
    gROOT.ForceStyle()
    gran_str = "%d#times %d #times %d" % (config.grid_phi, config.grid_r,
                                          config.grid_z)
    date = datetime.date.today().strftime("%Y%m%d")

    file_formats = ["pdf", "png"]
    # file_formats = ["png", "eps", "pdf"]
    var_labels = np.array(["r", "r#varphi", "z"])
    colors = [kBlue+1, kGreen+2, kRed+1, kCyan+2, kOrange+7, kMagenta+2]
    #colors = [kRed+1, kMagenta+2, kOrange+7, kCyan+1, kMagenta+2]
    sel_opts = np.array(config.opt_predout)
    sel_opts_names = np.array(config.nameopt_predout)
    sel_opts_names = sel_opts_names[sel_opts == 1]
    sel_var_labels = var_labels[sel_opts == 1]
    for opt_name, var_label in zip(sel_opts_names, sel_var_labels):
        x_label = "d#it{%s}_{true} (cm)" % var_label
        y_label = "%s of d#it{%s}_{pred} - d#it{%s}_{true} (cm)" %\
                  (func_label, var_label, var_label)
        canvas, frame, leg = setup_canvas(config.suffix, hist_name, opt_name, x_label, y_label)

        # TODO: Clean these codes
        for i, (train_events, _, _, _) in enumerate(events_counts):
            filename = "%s/output_%s_nEv%d.root" % (config.dirval, config.suffix, train_events)
            config.logger.info("Reading %s...", filename)

            root_file = TFile.Open(filename, "read")
            hist = root_file.Get("%s_all_events_%s" % (source_hist, config.suffix))
            hist.SetDirectory(0)
            hist.Draw("same")
            hist.SetMarkerStyle(20)
            hist.SetMarkerColor(colors[i])
            hist.SetLineColor(colors[i])
            # train_events_k = train_events / 1000
            leg.AddEntry(hist, "%d, %s" % (train_events, gran_str), "LP")

            if "mean" in hist_name and "std" in hist_name:
                hist.Delete("C")
                leg.DeleteEntry()
                hist_mean = root_file.Get("%s_all_events_%s" % \
                        (config.profile_name, config.suffix))
                hist_stddev = root_file.Get("%s_all_events_%s" % \
                        (config.h_std_dev_name, config.suffix))
                hist_mean.SetDirectory(0)
                hist_stddev.SetDirectory(0)
                hist = hist_mean.ProjectionX("hist_meanSD")
                hist.Reset()
                hist.Sumw2()
                hist.SetDirectory(0)
                nbin = hist_mean.GetNbinsX()
                for ibin in range(0,nbin):
                    hist.SetBinContent(ibin+1, hist_mean.GetBinContent(ibin+1))
                    hist.SetBinError(ibin+1, hist_stddev.GetBinContent(ibin+1))

                hist.SetMarkerStyle(20)
                hist.SetMarkerColor(colors[i])
                hist.SetLineColor(colors[i])
                hist.SetFillColor(colors[i])
                hist.SetFillStyle(3001)
                hist.Draw("sameE2")
                leg.AddEntry(hist, "%d, %s" % (train_events, gran_str), "FP")

            root_file.Close()

        leg.Draw()
        txt = add_desc_to_canvas(config, 0.15, 0.81, 0.4, 0.89, 0.03,
                                 {"add_alice": False, "add_gran": False, "add_inputs": True,
                                  "add_events": False})
        txt.Draw()
        save_canvas(config, canvas, frame, "{}/{}".format(config.dirplots, date),
                    hist_name, file_formats)
Beispiel #25
0
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()
Beispiel #26
0
def main():
    # usage description
    usage = "Example: ./scripts/plotLimits.py -M Asymptotic -l logs -f qq --massrange 1200 7000 100"

    # input parameters
    parser = ArgumentParser(
        description='Script that plots limits for specified mass points',
        epilog=usage)

    parser.add_argument("-M",
                        "--method",
                        dest="method",
                        required=True,
                        choices=[
                            'ProfileLikelihood', 'HybridNew', 'Asymptotic',
                            'MarkovChainMC', 'theta'
                        ],
                        help="Method to calculate upper limits",
                        metavar="METHOD")

    results_group = parser.add_mutually_exclusive_group(required=True)
    results_group.add_argument("-l",
                               "--logs_path",
                               dest="logs_path",
                               help="Path to log files",
                               metavar="LOGS_PATH")
    results_group.add_argument("-r",
                               "--results_file",
                               dest="results_file",
                               help="Path to a file containing results",
                               metavar="RESULTS_FILE")

    parser.add_argument("-f",
                        "--final_state",
                        dest="final_state",
                        required=True,
                        help="Final state (e.g. qq, qg, gg)",
                        metavar="FINAL_STATE")

    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='Simulation Preliminary',
                        help="Extra text on the plot (default: %(default)s)")

    parser.add_argument(
        "--lumi_sqrtS",
        dest="lumi_sqrtS",
        default='1 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")

    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')
    xs_obs_limits = array('d')
    xs_exp_limits = array('d')
    masses_exp = array('d')
    xs_exp_limits_1sigma = array('d')
    xs_exp_limits_1sigma_up = array('d')
    xs_exp_limits_2sigma = array('d')
    xs_exp_limits_2sigma_up = array('d')

    if args.logs_path != None:

        logs_path = os.path.join(os.getcwd(), args.logs_path)

        for mass in input_masses:

            print ">> Reading results for %s resonance with m = %i GeV..." % (
                args.final_state, int(mass))

            masses.append(mass)
            if args.method == 'Asymptotic': masses_exp.append(mass)

            logName = 'limits_%s_%s_m%i.log' % (args.method, args.final_state,
                                                int(mass))

            if args.method == 'theta': logName = logName.replace('limits_', '')

            log_file = open(os.path.join(logs_path, logName), 'r')

            foundMethod = False

            # read the log file
            for line in log_file:
                if args.method == 'Asymptotic':
                    if re.search("^Observed Limit: r", line):
                        xs_obs_limits.append(float(line.split()[-1]))
                    if re.search("^Expected 50.0%: r", line):
                        xs_exp_limits.append(float(line.split()[-1]))
                    if re.search("^Expected 16.0%: r", line):
                        xs_exp_limits_1sigma.append(float(line.split()[-1]))
                    if re.search("^Expected 84.0%: r", line):
                        xs_exp_limits_1sigma_up.append(float(line.split()[-1]))
                    if re.search("^Expected  2.5%: r", line):
                        xs_exp_limits_2sigma.append(float(line.split()[-1]))
                    if re.search("^Expected 97.5%: r", line):
                        xs_exp_limits_2sigma_up.append(float(line.split()[-1]))
                elif args.method == 'theta':
                    if re.search('^# x; y; yerror', line):
                        foundMethod = True
                    if line.split()[0] == '0' and foundMethod:
                        xs_obs_limits.append(float(line.split()[1]))
                else:
                    if re.search(' -- ' + args.method, line):
                        foundMethod = True
                    if re.search("^Limit: r", line) and foundMethod:
                        xs_obs_limits.append(float(line.split()[3]))

            if len(masses) != len(xs_obs_limits):
                print "** ERROR: ** Could not find observed limit for m =", int(
                    mass), "GeV. Aborting."
                sys.exit(1)

            if args.method == 'Asymptotic':
                if len(masses) != len(xs_exp_limits):
                    print "** ERROR: ** Could not find expected limit for m =", int(
                        mass), "GeV. Aborting."
                    sys.exit(1)

                if len(masses) != len(xs_exp_limits_1sigma):
                    print "** ERROR: ** Could not find expected 1 sigma down limit for m =", int(
                        mass), "GeV. Aborting."
                    sys.exit(1)

                if len(masses) != len(xs_exp_limits_1sigma_up):
                    print "** ERROR: ** Could not find expected 1 sigma up limit for m =", int(
                        mass), "GeV. Aborting."
                    sys.exit(1)

                if len(masses) != len(xs_exp_limits_2sigma):
                    print "** ERROR: ** Could not find expected 2 sigma down limit for m =", int(
                        mass), "GeV. Aborting."
                    sys.exit(1)

                if len(masses) != len(xs_exp_limits_2sigma_up):
                    print "** ERROR: ** Could not find expected 2 sigma up limit for m =", int(
                        mass), "GeV. Aborting."
                    sys.exit(1)
        if args.method == 'Asymptotic':
            # complete the expected limit arrays
            for i in range(0, len(masses)):
                masses_exp.append(masses[len(masses) - i - 1])
                xs_exp_limits_1sigma.append(
                    xs_exp_limits_1sigma_up[len(masses) - i - 1])
                xs_exp_limits_2sigma.append(
                    xs_exp_limits_2sigma_up[len(masses) - i - 1])
    else:
        print ">> Importing results..."

        sys.path.insert(0, os.path.dirname(args.results_file))

        results = __import__(
            os.path.basename(args.results_file).replace(".py", ""))

        all_masses = np.array(results.masses)
        all_masses_exp = np.array(results.masses_exp)
        indices = []
        indices_exp = []

        # search for indices of input_masses
        for mass in input_masses:
            where = np.where(all_masses == mass)[0]
            if len(where) == 0:
                print "** WARNING: ** Cannot find results for m =", int(
                    mass
                ), "GeV in the provided results file. Skipping this mass point."
            indices.extend(where)
            if len(all_masses_exp) > 0:
                where = np.where(all_masses_exp == mass)[0]
                if len(where) == 0:
                    print "** WARNING: ** Cannot find results for m =", int(
                        mass
                    ), "GeV in the provided results file. Skipping this mass point."
                indices_exp.extend(where)

        # sort indices
        indices.sort()
        indices_exp.sort()

        for i in indices:
            masses.append(results.masses[i])
            xs_obs_limits.append(results.xs_obs_limits[i])
            if len(all_masses_exp) > 0:
                xs_exp_limits.append(results.xs_exp_limits[i])
        for i in indices_exp:
            masses_exp.append(results.masses_exp[i])
            xs_exp_limits_1sigma.append(results.xs_exp_limits_1sigma[i])
            xs_exp_limits_2sigma.append(results.xs_exp_limits_2sigma[i])

    if args.printResults:
        print "masses =", masses.tolist()
        print "xs_obs_limits =", xs_obs_limits.tolist()
        print "xs_exp_limits =", xs_exp_limits.tolist()
        print ""
        print "masses_exp =", masses_exp.tolist()
        print "xs_exp_limits_1sigma =", xs_exp_limits_1sigma.tolist()
        print "xs_exp_limits_2sigma =", xs_exp_limits_2sigma.tolist()

    # import ROOT stuff
    from ROOT import kTRUE, kFALSE, gROOT, gStyle, gPad, TGraph, TCanvas, TLegend
    from ROOT import kGreen, kYellow, kWhite

    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()

    # theory curves: gg
    massesS8 = array('d', [
        1000.0, 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0,
        1900.0, 2000.0, 2100.0, 2200.0, 2300.0, 2400.0, 2500.0, 2600.0, 2700.0,
        2800.0, 2900.0, 3000.0, 3100.0, 3200.0, 3300.0, 3400.0, 3500.0, 3600.0,
        3700.0, 3800.0, 3900.0, 4000.0, 4100.0, 4200.0, 4300.0, 4400.0, 4500.0,
        4600.0, 4700.0, 4800.0, 4900.0, 5000.0, 5100.0, 5200.0, 5300.0, 5400.0,
        5500.0, 5600.0, 5700.0, 5800.0, 5900.0, 6000.0
    ])
    xsS8 = array('d', [
        5.46E+02, 3.12E+02, 1.85E+02, 1.12E+02, 7.19E+01, 4.59E+01, 3.02E+01,
        2.01E+01, 1.37E+01, 9.46E+00, 6.55E+00, 4.64E+00, 3.27E+00, 2.36E+00,
        1.70E+00, 1.24E+00, 9.11E-01, 6.69E-01, 4.97E-01, 3.71E-01, 2.78E-01,
        2.07E-01, 1.55E-01, 1.19E-01, 9.26E-02, 7.08E-02, 5.43E-02, 4.15E-02,
        3.22E-02, 2.50E-02, 1.92E-02, 1.51E-02, 1.19E-02, 9.25E-03, 7.35E-03,
        5.86E-03, 4.53E-03, 3.66E-03, 2.91E-03, 2.33E-03, 1.86E-03, 1.45E-03,
        1.12E-03, 8.75E-04, 6.90E-04, 5.55E-04, 4.47E-04, 3.63E-04, 2.92E-04,
        2.37E-04, 1.97E-04
    ])

    graph_xsS8 = TGraph(len(massesS8), massesS8, xsS8)
    graph_xsS8.SetLineWidth(3)
    graph_xsS8.SetLineStyle(8)
    graph_xsS8.SetLineColor(6)

    # theory curves: qg
    massesString = array('d', [
        1000.0, 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0,
        1900.0, 2000.0, 2100.0, 2200.0, 2300.0, 2400.0, 2500.0, 2600.0, 2700.0,
        2800.0, 2900.0, 3000.0, 3100.0, 3200.0, 3300.0, 3400.0, 3500.0, 3600.0,
        3700.0, 3800.0, 3900.0, 4000.0, 4100.0, 4200.0, 4300.0, 4400.0, 4500.0,
        4600.0, 4700.0, 4800.0, 4900.0, 5000.0, 5100.0, 5200.0, 5300.0, 5400.0,
        5500.0, 5600.0, 5700.0, 5800.0, 5900.0, 6000.0, 6100.0, 6200.0, 6300.0,
        6400.0, 6500.0, 6600.0, 6700.0, 6800.0, 6900.0, 7000.0, 7100.0, 7200.0,
        7300.0, 7400.0, 7500.0, 7600.0, 7700.0, 7800.0, 7900.0, 8000.0, 8100.0,
        8200.0, 8300.0, 8400.0, 8500.0, 8600.0, 8700.0, 8800.0, 8900.0, 9000.0,
        9100., 9200., 9300., 9400., 9500., 9600., 9700., 9800., 9900., 10000.
    ])
    xsString = array('d', [
        8316.184311558545, 5312.93137758767, 3435.0309937336524,
        2304.4139502741305, 1569.8115447896687, 1090.9516635659693,
        770.901859690924, 551.9206062572061, 399.69535383507633,
        293.77957451762086, 218.15126842827823, 162.87634729465125,
        123.17685479653694, 93.63530805932386, 71.53697229809124,
        55.37491301647483, 42.75271508357369, 33.36378355470234,
        26.06619302090876, 20.311817606835643, 16.1180931789545,
        12.768644973921226, 10.142660425967444, 8.057990848043234,
        6.400465846290908, 5.115134438331436, 4.132099789492928,
        3.3193854239538734, 2.6581204529344302, 2.157554604919995,
        1.7505176068913348, 1.4049155245498584, 1.140055677916783,
        0.9253251132104159, 0.7522038169131606, 0.6119747371392215,
        0.49612321727328523, 0.40492020959456737, 0.33091999402250655,
        0.27017917021492555, 0.2201693919322846, 0.17830700070267996,
        0.14564253802358157, 0.11940534430331146, 0.09694948234356839,
        0.0793065371847468, 0.06446186373361917, 0.05282660618352478,
        0.0428516302310620888, 0.0348997638039910363, 0.0283334766442618227,
        0.0231416918363592127, 0.0187417921340763783, 0.0153501307395115115,
        0.0124396534127133717, 0.0100542205744949455, 0.0081744954858627415,
        0.0066338099362915941, 0.0053365711503318145, 0.00430912459914657443,
        0.00346381039244064343, 0.00278602671711227174, 0.00225154342228859257,
        0.0018082930150063248, 0.00143929440338502119, 0.0011581373956044489,
        0.00091869589873893118, 0.00073410823691329855, 0.00058669382997948734,
        0.0004661568745858897, 0.000368716655469570365,
        0.000293168485206959169, 0.000230224535021638668,
        0.000182317101888465142, 0.000143263359883433282,
        0.000112630538527214965, 0.000088189175598406759,
        0.000068708474367442343, 0.000053931726669273556,
        0.0000416417855733682702, 0.0000326529676755488658,
        0.0000254365480426201587, 0.0000198410151166864761,
        0.0000154034425617473576, 0.0000119095554601641413,
        9.2537574320108232e-6, 7.2155417437856749e-6, 5.6130924422251982e-6,
        4.36634755605624901e-6, 3.39717456406994868e-6, 2.6766018046173896e-6
    ])

    massesQstar = array('d', [
        1000.0, 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0,
        1900.0, 2000.0, 2100.0, 2200.0, 2300.0, 2400.0, 2500.0, 2600.0, 2700.0,
        2800.0, 2900.0, 3000.0, 3100.0, 3200.0, 3300.0, 3400.0, 3500.0, 3600.0,
        3700.0, 3800.0, 3900.0, 4000.0, 4100.0, 4200.0, 4300.0, 4400.0, 4500.0,
        4600.0, 4700.0, 4800.0, 4900.0, 5000.0, 5100.0, 5200.0, 5300.0, 5400.0,
        5500.0, 5600.0, 5700.0, 5800.0, 5900.0, 6000.0, 6100.0, 6200.0, 6300.0,
        6400.0, 6500.0, 6600.0, 6700.0, 6800.0, 6900.0, 7000.0, 7100.0, 7200.0,
        7300.0, 7400.0, 7500.0, 7600.0, 7700.0, 7800.0, 7900.0, 8000.0, 8100.0,
        8200.0, 8300.0, 8400.0, 8500.0, 8600.0, 8700.0, 8800.0, 8900.0, 9000.0
    ])
    xsQstar = array('d', [
        0.4101E+03, 0.2620E+03, 0.1721E+03, 0.1157E+03, 0.7934E+02, 0.5540E+02,
        0.3928E+02, 0.2823E+02, 0.2054E+02, 0.1510E+02, 0.1121E+02, 0.8390E+01,
        0.6328E+01, 0.4807E+01, 0.3674E+01, 0.2824E+01, 0.2182E+01, 0.1694E+01,
        0.1320E+01, 0.1033E+01, 0.8116E+00, 0.6395E+00, 0.5054E+00, 0.4006E+00,
        0.3182E+00, 0.2534E+00, 0.2022E+00, 0.1616E+00, 0.1294E+00, 0.1038E+00,
        0.8333E-01, 0.6700E-01, 0.5392E-01, 0.4344E-01, 0.3503E-01, 0.2827E-01,
        0.2283E-01, 0.1844E-01, 0.1490E-01, 0.1205E-01, 0.9743E-02, 0.7880E-02,
        0.6373E-02, 0.5155E-02, 0.4169E-02, 0.3371E-02, 0.2725E-02, 0.2202E-02,
        0.1779E-02, 0.1437E-02, 0.1159E-02, 0.9353E-03, 0.7541E-03, 0.6076E-03,
        0.4891E-03, 0.3935E-03, 0.3164E-03, 0.2541E-03, 0.2039E-03, 0.1635E-03,
        0.1310E-03, 0.1049E-03, 0.8385E-04, 0.6699E-04, 0.5347E-04, 0.4264E-04,
        0.3397E-04, 0.2704E-04, 0.2151E-04, 0.1709E-04, 0.1357E-04, 0.1077E-04,
        0.8544E-05, 0.6773E-05, 0.5367E-05, 0.4251E-05, 0.3367E-05, 0.2666E-05,
        0.2112E-05, 0.1673E-05, 0.1326E-05
    ])

    graph_xsString = TGraph(len(massesString), massesString, xsString)
    graph_xsString.SetLineWidth(3)
    graph_xsString.SetLineStyle(8)
    graph_xsString.SetLineColor(9)

    graph_xsQstar = TGraph(len(massesQstar), massesQstar, xsQstar)
    graph_xsQstar.SetLineWidth(3)
    graph_xsQstar.SetLineStyle(2)
    graph_xsQstar.SetLineColor(1)

    # theory curves: qq
    massesTh = array('d', [
        1000.0, 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0,
        1900.0, 2000.0, 2100.0, 2200.0, 2300.0, 2400.0, 2500.0, 2600.0, 2700.0,
        2800.0, 2900.0, 3000.0, 3100.0, 3200.0, 3300.0, 3400.0, 3500.0, 3600.0,
        3700.0, 3800.0, 3900.0, 4000.0, 4100.0, 4200.0, 4300.0, 4400.0, 4500.0,
        4600.0, 4700.0, 4800.0, 4900.0, 5000.0, 5100.0, 5200.0, 5300.0, 5400.0,
        5500.0, 5600.0, 5700.0, 5800.0, 5900.0, 6000.0, 6100.0, 6200.0, 6300.0,
        6400.0, 6500.0, 6600.0, 6700.0, 6800.0, 6900.0, 7000.0, 7100.0, 7200.0,
        7300.0, 7400.0, 7500.0, 7600.0, 7700.0, 7800.0, 7900.0, 8000.0, 8100.0,
        8200.0, 8300.0, 8400.0, 8500.0, 8600.0, 8700.0, 8800.0, 8900.0, 9000.0
    ])

    xsAxi = array('d', [
        0.1849E+03, 0.1236E+03, 0.8473E+02, 0.5937E+02, 0.4235E+02, 0.3069E+02,
        0.2257E+02, 0.1680E+02, 0.1263E+02, 0.9577E+01, 0.7317E+01, 0.5641E+01,
        0.4374E+01, 0.3411E+01, 0.2672E+01, 0.2103E+01, 0.1658E+01, 0.1312E+01,
        0.1041E+01, 0.8284E+00, 0.6610E+00, 0.5294E+00, 0.4250E+00, 0.3417E+00,
        0.2752E+00, 0.2220E+00, 0.1792E+00, 0.1449E+00, 0.1172E+00, 0.9487E-01,
        0.7686E-01, 0.6219E-01, 0.5033E-01, 0.4074E-01, 0.3298E-01, 0.2671E-01,
        0.2165E-01, 0.1755E-01, 0.1422E-01, 0.1152E-01, 0.9322E-02, 0.7539E-02,
        0.6092E-02, 0.4917E-02, 0.3965E-02, 0.3193E-02, 0.2568E-02, 0.2062E-02,
        0.1653E-02, 0.1323E-02, 0.1057E-02, 0.8442E-03, 0.6728E-03, 0.5349E-03,
        0.4242E-03, 0.3357E-03, 0.2644E-03, 0.2077E-03, 0.1627E-03, 0.1271E-03,
        0.9891E-04, 0.7686E-04, 0.5951E-04, 0.4592E-04, 0.3530E-04, 0.2704E-04,
        0.2059E-04, 0.1562E-04, 0.1180E-04, 0.8882E-05, 0.6657E-05, 0.4968E-05,
        0.3693E-05, 0.2734E-05, 0.2016E-05, 0.1481E-05, 0.1084E-05, 0.7903E-06,
        0.5744E-06, 0.4160E-06, 0.3007E-06
    ])
    xsDiquark = array('d', [
        0.5824E+02, 0.4250E+02, 0.3172E+02, 0.2411E+02, 0.1862E+02, 0.1457E+02,
        0.1153E+02, 0.9211E+01, 0.7419E+01, 0.6019E+01, 0.4912E+01, 0.4031E+01,
        0.3323E+01, 0.2750E+01, 0.2284E+01, 0.1903E+01, 0.1590E+01, 0.1331E+01,
        0.1117E+01, 0.9386E+00, 0.7900E+00, 0.6658E+00, 0.5618E+00, 0.4745E+00,
        0.4010E+00, 0.3391E+00, 0.2869E+00, 0.2428E+00, 0.2055E+00, 0.1740E+00,
        0.1473E+00, 0.1246E+00, 0.1055E+00, 0.8922E-01, 0.7544E-01, 0.6376E-01,
        0.5385E-01, 0.4546E-01, 0.3834E-01, 0.3231E-01, 0.2720E-01, 0.2288E-01,
        0.1922E-01, 0.1613E-01, 0.1352E-01, 0.1132E-01, 0.9463E-02, 0.7900E-02,
        0.6584E-02, 0.5479E-02, 0.4551E-02, 0.3774E-02, 0.3124E-02, 0.2581E-02,
        0.2128E-02, 0.1750E-02, 0.1437E-02, 0.1177E-02, 0.9612E-03, 0.7833E-03,
        0.6366E-03, 0.5160E-03, 0.4170E-03, 0.3360E-03, 0.2700E-03, 0.2162E-03,
        0.1725E-03, 0.1372E-03, 0.1087E-03, 0.8577E-04, 0.6742E-04, 0.5278E-04,
        0.4114E-04, 0.3192E-04, 0.2465E-04, 0.1894E-04, 0.1448E-04, 0.1101E-04,
        0.8322E-05, 0.6253E-05, 0.4670E-05
    ])
    xsWprime = array('d', [
        0.8811E+01, 0.6024E+01, 0.4216E+01, 0.3010E+01, 0.2185E+01, 0.1610E+01,
        0.1200E+01, 0.9043E+00, 0.6875E+00, 0.5271E+00, 0.4067E+00, 0.3158E+00,
        0.2464E+00, 0.1932E+00, 0.1521E+00, 0.1201E+00, 0.9512E-01, 0.7554E-01,
        0.6012E-01, 0.4792E-01, 0.3827E-01, 0.3059E-01, 0.2448E-01, 0.1960E-01,
        0.1571E-01, 0.1259E-01, 0.1009E-01, 0.8090E-02, 0.6483E-02, 0.5193E-02,
        0.4158E-02, 0.3327E-02, 0.2660E-02, 0.2125E-02, 0.1695E-02, 0.1351E-02,
        0.1075E-02, 0.8546E-03, 0.6781E-03, 0.5372E-03, 0.4248E-03, 0.3353E-03,
        0.2642E-03, 0.2077E-03, 0.1629E-03, 0.1275E-03, 0.9957E-04, 0.7757E-04,
        0.6027E-04, 0.4670E-04, 0.3610E-04, 0.2783E-04, 0.2140E-04, 0.1641E-04,
        0.1254E-04, 0.9561E-05, 0.7269E-05, 0.5510E-05, 0.4167E-05, 0.3143E-05,
        0.2364E-05, 0.1774E-05, 0.1329E-05, 0.9931E-06, 0.7411E-06, 0.5523E-06,
        0.4108E-06, 0.3055E-06, 0.2271E-06, 0.1687E-06, 0.1254E-06, 0.9327E-07,
        0.6945E-07, 0.5177E-07, 0.3863E-07, 0.2888E-07, 0.2162E-07, 0.1622E-07,
        0.1218E-07, 0.9156E-08, 0.6893E-08
    ])
    xsZprime = array('d', [
        0.5027E+01, 0.3398E+01, 0.2353E+01, 0.1663E+01, 0.1196E+01, 0.8729E+00,
        0.6450E+00, 0.4822E+00, 0.3638E+00, 0.2769E+00, 0.2123E+00, 0.1639E+00,
        0.1272E+00, 0.9933E-01, 0.7789E-01, 0.6134E-01, 0.4848E-01, 0.3845E-01,
        0.3059E-01, 0.2440E-01, 0.1952E-01, 0.1564E-01, 0.1256E-01, 0.1010E-01,
        0.8142E-02, 0.6570E-02, 0.5307E-02, 0.4292E-02, 0.3473E-02, 0.2813E-02,
        0.2280E-02, 0.1848E-02, 0.1499E-02, 0.1216E-02, 0.9864E-03, 0.8002E-03,
        0.6490E-03, 0.5262E-03, 0.4264E-03, 0.3453E-03, 0.2795E-03, 0.2260E-03,
        0.1826E-03, 0.1474E-03, 0.1188E-03, 0.9566E-04, 0.7690E-04, 0.6173E-04,
        0.4947E-04, 0.3957E-04, 0.3159E-04, 0.2516E-04, 0.2001E-04, 0.1587E-04,
        0.1255E-04, 0.9906E-05, 0.7795E-05, 0.6116E-05, 0.4785E-05, 0.3731E-05,
        0.2900E-05, 0.2247E-05, 0.1734E-05, 0.1334E-05, 0.1022E-05, 0.7804E-06,
        0.5932E-06, 0.4492E-06, 0.3388E-06, 0.2544E-06, 0.1903E-06, 0.1417E-06,
        0.1051E-06, 0.7764E-07, 0.5711E-07, 0.4186E-07, 0.3055E-07, 0.2223E-07,
        0.1612E-07, 0.1164E-07, 0.8394E-08
    ])

    graph_xsAxi = TGraph(len(massesTh), massesTh, xsAxi)
    graph_xsAxi.SetLineWidth(3)
    graph_xsAxi.SetLineStyle(3)
    graph_xsAxi.SetLineColor(63)

    graph_xsDiquark = TGraph(len(massesTh), massesTh, xsDiquark)
    graph_xsDiquark.SetLineWidth(3)
    graph_xsDiquark.SetLineStyle(9)
    graph_xsDiquark.SetLineColor(8)

    graph_xsWprime = TGraph(len(massesTh), massesTh, xsWprime)
    graph_xsWprime.SetLineWidth(3)
    graph_xsWprime.SetLineStyle(7)
    graph_xsWprime.SetLineColor(46)

    graph_xsZprime = TGraph(len(massesTh), massesTh, xsZprime)
    graph_xsZprime.SetLineWidth(3)
    graph_xsZprime.SetLineStyle(5)
    graph_xsZprime.SetLineColor(38)

    # limits
    graph_exp_2sigma = (TGraph(len(masses_exp), masses_exp,
                               xs_exp_limits_2sigma)
                        if len(xs_exp_limits_2sigma) > 0 else TGraph(0))
    graph_exp_2sigma.SetFillColor(kYellow)

    graph_exp_1sigma = (TGraph(len(masses_exp), masses_exp,
                               xs_exp_limits_1sigma)
                        if len(xs_exp_limits_2sigma) > 0 else TGraph(0))
    graph_exp_1sigma.SetFillColor(kGreen + 1)

    graph_exp = (TGraph(len(masses), masses, xs_exp_limits)
                 if len(xs_exp_limits_2sigma) > 0 else TGraph(0))
    #graph_exp.SetMarkerStyle(24)
    graph_exp.SetLineWidth(3)
    graph_exp.SetLineStyle(2)
    graph_exp.SetLineColor(4)

    graph_obs = TGraph(len(masses), masses, xs_obs_limits)
    graph_obs.SetMarkerStyle(20)
    graph_obs.SetLineWidth(3)
    #graph_obs.SetLineStyle(1)
    graph_obs.SetLineColor(1)

    c = TCanvas("c", "", 800, 800)
    c.cd()

    legend = TLegend(.60, .55, .90, .70)
    legend.SetBorderSize(0)
    legend.SetFillColor(0)
    legend.SetFillStyle(0)
    legend.SetTextFont(42)
    legend.SetTextSize(0.03)
    legend.SetHeader('95% CL upper limits')

    if len(xs_exp_limits_2sigma) > 0:
        graph_exp_2sigma.GetXaxis().SetTitle("%s resonance mass [GeV]" %
                                             (args.final_state))
        graph_exp_2sigma.GetYaxis().SetTitle(
            "#sigma #times #it{B} #times #it{A} [pb]")
        graph_exp_2sigma.GetYaxis().SetTitleOffset(1.1)
        graph_exp_2sigma.GetYaxis().SetRangeUser(1e-02, 1e+03)
        #graph_exp_2sigma.GetXaxis().SetNdivisions(1005)

        graph_exp_2sigma.Draw("AF")
        graph_exp_1sigma.Draw("F")
        graph_exp.Draw("L")
        graph_obs.Draw("LP")

        legend.AddEntry(graph_obs, "Observed", "lp")
        legend.AddEntry(graph_exp, "Expected", "lp")
        legend.AddEntry(graph_exp_1sigma, "#pm 1#sigma", "F")
        legend.AddEntry(graph_exp_2sigma, "#pm 2#sigma", "F")
    else:
        graph_obs.GetXaxis().SetTitle("%s resonance mass [GeV]" %
                                      (args.final_state))
        graph_obs.GetYaxis().SetTitle(
            "#sigma #times #it{B} #times #it{A} [pb]")
        graph_obs.GetYaxis().SetTitleOffset(1.1)
        graph_obs.GetYaxis().SetRangeUser(1e-02, 1e+03)
        #graph_obs.GetXaxis().SetNdivisions(1005)

        graph_obs.Draw("ALP")

        legend.AddEntry(graph_obs, "Observed", "lp")

    if args.final_state == 'gg':
        graph_xsS8.Draw("L")
    elif args.final_state == 'qg':
        graph_xsQstar.Draw("L")
        graph_xsString.Draw("L")
    elif args.final_state == 'qq':
        graph_xsAxi.Draw("L")
        graph_xsDiquark.Draw("L")
        graph_xsWprime.Draw("L")
        graph_xsZprime.Draw("L")

    legend.Draw()

    if args.final_state == 'gg':
        legendTh = TLegend(.60, .80, .90, .84)
        legendTh.SetBorderSize(0)
        legendTh.SetFillColor(0)
        legendTh.SetFillStyle(0)
        legendTh.SetTextFont(42)
        legendTh.SetTextSize(0.03)
        legendTh.AddEntry(graph_xsS8, "S8", "l")
        legendTh.Draw()
    elif args.final_state == 'qg':
        legendTh = TLegend(.60, .80, .90, .88)
        legendTh.SetBorderSize(0)
        legendTh.SetFillColor(0)
        legendTh.SetFillStyle(0)
        legendTh.SetTextFont(42)
        legendTh.SetTextSize(0.03)
        legendTh.AddEntry(graph_xsString, "String", "l")
        legendTh.AddEntry(graph_xsQstar, "Excited quark", "l")
        legendTh.Draw()
    elif args.final_state == 'qq':
        legendTh = TLegend(.60, .72, .90, .88)
        legendTh.SetBorderSize(0)
        legendTh.SetFillColor(0)
        legendTh.SetFillStyle(0)
        legendTh.SetTextFont(42)
        legendTh.SetTextSize(0.03)
        legendTh.AddEntry(graph_xsAxi, "Axigluon/coloron", "l")
        legendTh.AddEntry(graph_xsDiquark, "Scalar diquark", "l")
        legendTh.AddEntry(graph_xsWprime, "W' SSM", "l")
        legendTh.AddEntry(graph_xsZprime, "Z' SSM", "l")
        legendTh.Draw()

    # 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.SetLogy()
    fileName = 'xs_limit_%s_%s.%s' % (args.method, args.final_state + (
        ('_' + args.postfix) if args.postfix != '' else ''),
                                      args.fileFormat.lower())
    c.SaveAs(fileName)
    print "Plot saved to '%s'" % (fileName)
Beispiel #27
0
def setLHCbStyle():
    # configuring the plot-style
    gROOT.SetStyle("Plain")
    lhcbStyle = TStyle("lhcbstyle", "LHCb plots style")
    GlobalLHCbTSize = 0.06
    lhcbTSize = 0.06
    kLHCbFont = 132
    lhcbWidth = 2

    lhcbStyle.SetFillColor(1)
    lhcbStyle.SetFillStyle(1001)
    lhcbStyle.SetFrameFillColor(0)
    lhcbStyle.SetFrameBorderMode(0)
    lhcbStyle.SetPadBorderMode(0)
    lhcbStyle.SetPadColor(0)
    lhcbStyle.SetCanvasBorderMode(0)
    lhcbStyle.SetCanvasColor(0)
    lhcbStyle.SetStatColor(0)
    lhcbStyle.SetLegendBorderSize(0)
    lhcbStyle.SetPalette(1)
    # colors = [0,5,7,3,6,2,4,1]
    # lhcbStyle.SetPalette(8,colors)
    lhcbStyle.SetPaperSize(20, 26)
    lhcbStyle.SetPadTopMargin(0.05)
    lhcbStyle.SetPadRightMargin(0.05)
    lhcbStyle.SetPadBottomMargin(0.16)
    lhcbStyle.SetPadLeftMargin(0.14)
    lhcbStyle.SetTextFont(kLHCbFont)
    lhcbStyle.SetTextSize(lhcbTSize)
    lhcbStyle.SetLabelFont(kLHCbFont, "x")
    lhcbStyle.SetLabelFont(kLHCbFont, "y")
    lhcbStyle.SetLabelFont(kLHCbFont, "z")
    lhcbStyle.SetLabelSize(lhcbTSize, "x")
    lhcbStyle.SetLabelSize(lhcbTSize, "y")
    lhcbStyle.SetLabelSize(lhcbTSize, "z")
    lhcbStyle.SetTitleFont(kLHCbFont)
    lhcbStyle.SetTitleFont(kLHCbFont, "x")
    lhcbStyle.SetTitleFont(kLHCbFont, "y")
    lhcbStyle.SetTitleFont(kLHCbFont, "z")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "x")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "y")
    lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "z")
    lhcbStyle.SetLineWidth(lhcbWidth)
    lhcbStyle.SetHistLineWidth(lhcbWidth)
    lhcbStyle.SetFuncWidth(lhcbWidth)
    lhcbStyle.SetGridWidth(lhcbWidth)
    lhcbStyle.SetLineStyleString(2, "[12 12]")
    lhcbStyle.SetMarkerStyle(20)
    lhcbStyle.SetMarkerSize(1.0)
    lhcbStyle.SetLabelOffset(0.010, "X")
    lhcbStyle.SetLabelOffset(0.010, "Y")
    lhcbStyle.SetOptStat(0)
    lhcbStyle.SetStatFormat("6.3g")
    lhcbStyle.SetOptTitle(0)
    lhcbStyle.SetOptFit(0)
    lhcbStyle.SetTitleOffset(0.95, "X")
    lhcbStyle.SetTitleOffset(0.95, "Y")
    lhcbStyle.SetTitleOffset(1.2, "Z")
    lhcbStyle.SetTitleFillColor(0)
    lhcbStyle.SetTitleStyle(0)
    lhcbStyle.SetTitleBorderSize(0)
    lhcbStyle.SetTitleFont(kLHCbFont, "title")
    lhcbStyle.SetTitleX(0.0)
    lhcbStyle.SetTitleY(1.0)
    lhcbStyle.SetTitleW(1.0)
    lhcbStyle.SetTitleH(0.05)
    lhcbStyle.SetStatBorderSize(0)
    lhcbStyle.SetStatFont(kLHCbFont)
    lhcbStyle.SetStatFontSize(0.05)
    lhcbStyle.SetStatX(0.9)
    lhcbStyle.SetStatY(0.9)
    lhcbStyle.SetStatW(0.25)
    lhcbStyle.SetStatH(0.15)
    lhcbStyle.SetPadTickX(1)
    lhcbStyle.SetPadTickY(1)
    lhcbStyle.SetNdivisions(505, "x")
    lhcbStyle.SetNdivisions(510, "y")

    gROOT.SetStyle("lhcbstyle")
    gROOT.ForceStyle()
Beispiel #28
0
    def __init__(self):
        super(StyleClass, self).__init__('CmsRootStyle', 'CmsRootStyle')

        ################################ custom root style commands ###
        self.SetFrameBorderMode(0)
        self.SetCanvasBorderMode(0)
        self.SetPadBorderMode(0)
        self.SetPadBorderMode(0)

        #self.SetFrameColor(0)
        self.SetPadColor(0)
        self.SetCanvasColor(0)
        self.SetStatColor(0)
        self.SetFillColor(0)
        self.SetNdivisions(505, 'XY')

        self.SetTextFont(42) #132
        self.SetTextSize(0.09)
        self.SetLabelFont(42, 'xyz')
        self.SetTitleFont(42, 'xyz')
        self.SetLabelSize(0.045, 'xyz') #0.035
        self.SetTitleSize(0.045, 'xyz')
        self.SetTitleOffset(1.3, 'xy')

        self.SetTitleX(0.16)
        self.SetTitleY(0.93)
        self.SetTitleColor(1)
        self.SetTitleTextColor(1)
        self.SetTitleFillColor(0)
        self.SetTitleBorderSize(1)
        self.SetTitleFontSize(0.04)
        self.SetPadTopMargin(0.05)
        self.SetPadBottomMargin(0.13)
        #self.SetPadLeftMargin(0.14)
        #self.SetPadRightMargin(0.02)

        self.SetPaperSize(20, 26)
        self.SetPadRightMargin(0.3)
        self.SetPadLeftMargin(0.16)
        #self.SetCanvasDefH(800)
        #self.SetCanvasDefW(800)
        #self.SetPadGridX(1)
        #self.SetPadGridY(1)
        self.SetPadTickX(1)
        self.SetPadTickY(1)

        # use bold lines and markers
        self.SetMarkerStyle(8)
        self.SetMarkerSize(1.2)
        self.SetHistLineWidth(1)
        self.SetLineWidth(1)
        self.SetEndErrorSize(0)

        self.SetOptTitle(1)
        self.SetOptStat(0)

        # don't know what these are for. Need to ask the kuess'l-o-mat.
        self.colors = [1, 2, 3, 4, 6, 7, 8, 9, 11]
        self.markers = [20, 21, 22, 23, 24, 25, 26, 27, 28]
        self.styles = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        ############################ end custom root style commands ###

        self.cd()
        self.set_palette()
        gROOT.SetStyle('CmsRootStyle')
        gROOT.ForceStyle()
        TGaxis.SetMaxDigits(3)
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)
Beispiel #30
0
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()