コード例 #1
0
    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);
コード例 #2
0
ファイル: style.py プロジェクト: rmanzoni/MCProduction
 def _initDefaultStyle(self):
     gROOT.Reset()
     gROOT.SetStyle("Plain")
     #gStyle.SetOptStat(0)
     gStyle.SetOptFit(1111)
     gStyle.SetPadLeftMargin(0.1)
     gStyle.SetPadBottomMargin(0.1)
     gStyle.SetMarkerSize(1.5)
     gStyle.SetHistLineWidth(1)
     gStyle.SetStatFontSize(0.025)
     gStyle.SetTitleFontSize(0.05)
     gStyle.SetTitle(
         'CMS Preliminary tH, H#to#tau#tau, 19.7 fb^{-1} at 8 TeV')
     gStyle.SetTitleSize(0.06, "XYZ")
     gStyle.SetLabelSize(0.05, "XYZ")
     gStyle.SetNdivisions(510, "XYZ")
コード例 #3
0
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)
コード例 #4
0
def rocPlotMacro():
	
	# load TDR-style plotting macro
	gROOT.LoadMacro("$CMSSW_BASE/src/TauAnalysisTools/TauAnalysisTools/macros/tdrstyle.C")
	ROOT.setTDRStyle()
	gStyle.SetFrameLineWidth(3)
	gStyle.SetLineWidth(3)
	gStyle.SetPadGridX(True)
	gStyle.SetPadGridY(True)
	gStyle.SetPadTopMargin(0.08)
	gStyle.SetPadBottomMargin(0.15)
	gStyle.SetPadLeftMargin(0.18)
	gStyle.SetPadRightMargin(0.05)
	gStyle.SetTitleFontSize(0.055)
	gStyle.SetTitleSize(0.055, "XYZ")
	gStyle.SetTitleXOffset(1.25)
	gStyle.SetTitleYOffset(1.60)
	gStyle.SetLabelSize(0.04, "XYZ")
	gStyle.SetLabelOffset(0.013, "XYZ")

	# list of trainings
	reference53X = {
		'folder' : 'forFabio',
		'color'  : ROOT.kGreen,
		'text'   : '53X'
	}
	reference74X = {
		'folder' : 'antiElectronDiscr74X_onlyZWTTjetsHiggsWZprimeSUSY_FullSkim',
		'color'  : ROOT.kMagenta,
		'text'   : '74X (Complete skim)'
	}

	inputFilePath = '/nfs/dust/cms/user/fcolombo/HiggsToTauTau/TauPOG/antiElectronDiscrMVATraining'

	trainingList = []
	trainingList.append(reference53X)
	trainingList.append(reference74X)

	# list of plots to produce
	roc_linear = {
		'file' : 'showROCcurvesAntiElectronDiscrMVA_all_linear.root',
		'name' : 'roc_linear',
		'y_range' : [0.4, 1.],
		'y_log' : False,
		'leg_loc' : [0.2, 0.2, 0.8, 0.35]
	}
	roc_log = {
		'file' : 'showROCcurvesAntiElectronDiscrMVA_all_log.root',
		'name' : 'roc_log',
		'y_range' : [0.001, 1.],
		'y_log' : True,
		'leg_loc' : [0.2, 0.75, 0.8, 0.9]
	}

	plotList = []
	plotList.append(roc_linear)
	plotList.append(roc_log)

	pTbinsList = ['','tauPtLt50_','tauPt50to100_','tauPt100to200_','tauPt200to400_','tauPt400to600_','tauPt600to900_','tauPt900to1200_','tauPtGt1200_']

	for iPlot, plotDict in enumerate(plotList):
		for ptBin in pTbinsList:

			filename = 'showROCcurvesAntiElectronDiscrMVA_all_'+ptBin+('log' if plotDict['y_log'] else 'linear')

			c1 = TCanvas()
			c1.SetTitle(plotDict['name'])

			legend = TLegend(plotDict['leg_loc'][0], plotDict['leg_loc'][1], plotDict['leg_loc'][2], plotDict['leg_loc'][3])
			legend.SetShadowColor(0)
			legend.SetFillColor(0)

			for iTrain, trainDict in enumerate(trainingList):

				file = TFile.Open(os.path.join(inputFilePath, trainDict['folder'], filename+'.root'))
				canvas = file.Get("canvas")
				histo = canvas.GetPrimitive("dummyHistogram")
				graph = canvas.GetPrimitive("mvaAntiElectronDiscr5_TestTree_"+ptBin+"cloned")

				legend.AddEntry(graph, trainDict['text'], 'l')
				c1.cd()
				if (iTrain == 0):
					histo.GetYaxis().SetRangeUser(plotDict['y_range'][0], plotDict['y_range'][1])
					histo.GetYaxis().SetTitleOffset(1.6)
					histo.Draw()

				graph.SetMarkerColor(trainDict['color'])
				graph.SetLineColor(trainDict['color'])
				graph.SetLineWidth(2)
				graph.Draw("LP SAME")

			if (plotDict['y_log'] == True):
				c1.SetLogy()

			legend.Draw()

			if 'plots' not in os.listdir(inputFilePath):
				os.mkdir(os.path.join(inputFilePath, 'plots'))

			c1.SaveAs(os.path.join(inputFilePath, 'plots', plotDict['name']+'_'+(ptBin[:-1] if ptBin != '' else 'all')+'.png'))
コード例 #5
0
#target = 'TRACK'

data = dat['all_events'][target][0]
print(data.max)

data = data / 1000.
mat = TMatrix(224, 224)

for i in range(224):
    for j in range(224):
        mat[i][j] = data[i][j]

#mat.Print()

gStyle.SetOptStat(0)
gStyle.SetTitleFontSize(25)
h2 = TH2F(mat)

h2.GetXaxis().SetNdivisions(8)
h2.GetXaxis().SetTitle('#phi pixel')
h2.GetXaxis().ChangeLabel(1, -1, -1, -1, -1, -1, "-3.15")
h2.GetXaxis().ChangeLabel(2, -1, -1, -1, -1, -1, "-1.07")
h2.GetXaxis().ChangeLabel(3, -1, -1, -1, -1, -1, "0.169")
h2.GetXaxis().ChangeLabel(4, -1, -1, -1, -1, -1, "1.41")
h2.GetXaxis().ChangeLabel(5, -1, -1, -1, -1, -1, "2.82")

h2.GetXaxis().SetTitleOffset(1.5)
h2.GetXaxis().SetTitleSize(0.06)
h2.GetXaxis().SetLabelSize(0.05)

h2.GetYaxis().SetNdivisions(8)
コード例 #6
0
def setStyle():

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBottomMargin(0.12)
    gStyle.SetPadLeftMargin(0.12)
    gStyle.SetCanvasColor(ROOT.kWhite)
    gStyle.SetCanvasDefH(600)
    #Height of canvas
    gStyle.SetCanvasDefW(600)
    #Width of canvas
    gStyle.SetCanvasDefX(0)
    #POsition on screen
    gStyle.SetCanvasDefY(0)

    gStyle.SetPadTopMargin(0.05)
    gStyle.SetPadBottomMargin(0.15)
    #0.13);
    gStyle.SetPadLeftMargin(0.15)
    #0.16);
    gStyle.SetPadRightMargin(0.05)
    #0.02);

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

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

    gStyle.SetAxisColor(1, "XYZ")
    gStyle.SetStripDecimals(ROOT.kTRUE)
    gStyle.SetTickLength(0.03, "XYZ")
    gStyle.SetNdivisions(505, "XYZ")
    gStyle.SetPadTickX(1)
    # To get tick marks on the opposite side of the frame
    gStyle.SetPadTickY(1)
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)

    gStyle.SetTitleColor(1, "XYZ")
    gStyle.SetTitleFont(42, "XYZ")
    gStyle.SetTitleSize(0.05, "XYZ")
    # gStyle.SetTitleXSize(Float_t size = 0.02); # Another way to set the size?
    # gStyle.SetTitleYSize(Float_t size = 0.02);
    gStyle.SetTitleXOffset(1.15)
    #0.9);
    gStyle.SetTitleYOffset(1.3)
    # => 1.15 if exponents
    gStyle.SetLabelColor(1, "XYZ")
    gStyle.SetLabelFont(42, "XYZ")
    gStyle.SetLabelOffset(0.007, "XYZ")
    gStyle.SetLabelSize(0.045, "XYZ")

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetTitleTextColor(1)
    gStyle.SetTitleFillColor(10)
    gStyle.SetTitleFontSize(0.05)
コード例 #7
0
ファイル: style.py プロジェクト: hroskes/makeDjetplot
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()
コード例 #8
0
ファイル: plot_hist.py プロジェクト: ZhiyuanH3/PyrootLearn
def plot_2(var,cuts):
    for s in attr:
        c1 = TCanvas("c1", "Signals", 1200, 800)

        if log_y == 1: 
            c1.SetLogy()

        c1.SetTopMargin(0.08)#0.12
        c1.SetBottomMargin(0.11)#0.12
        c1.SetLeftMargin(0.14)
        c1.SetRightMargin(0.14)#0.24
        c1.cd()
        #c1.SetGrid()
        gStyle.SetTitleFontSize(0.04)
        if ct_dep == 0:
            if s in ('elf','muf','cm','nm','chm'): 
                c1.SetLogx()
            for cc in channel:
                #hist[cc][s].SetMaximum(0.44)
                if   'combind' in cc:     
                    fc = 30
                    #hist[cc][s].SetFillStyle()#3005)
                elif 'VBF'      in cc:   
                    fc = 38    
                    hist[cc][s].SetFillStyle(3444)
                elif 'HT50'     in cc:  
                    fc = 7
                    hist[cc][s].SetFillStyle(3001)                  
                elif 'HT100'    in cc: 
                    fc = 4
                    hist[cc][s].SetFillStyle(3002) 
                elif 'HT200'    in cc: 
                    fc = 6
                    hist[cc][s].SetFillStyle(3003) 
                elif 'HT300'    in cc: 
                    fc = 9
                    hist[cc][s].SetFillStyle(3004) 
                
                if histFillColOn == 1:
                    pass
                    #hist[cc][s].SetFillColor(fc) 
                
                hist[cc][s].Draw(histStyl) 
            #legend = TLegend(0.76, 0.56, 0.99, 0.88)
            legend = TLegend(0.60, 0.9-0.04*2, 0.85, 0.9) #x_left y_bottom x_right y_top
            legend.SetBorderSize(0)
            legend.SetFillStyle(0)#1001
            legend.SetFillColor(0)
            #legend.SetHeader( entry['entries'] )
            for cc in channel:
                legend.AddEntry(hist[cc][s],cc)
            legend.Draw()
            for ct in cut_text:
                cut_text[ct].Draw()
            
            #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Line for critical value
            if   s == 'chm':
                l = TLine(11.4,0.0,11.4,0.084) 
            elif s == 'cHadEFrac':
                l = TLine(0.38,0.0,0.38,0.027)
            elif s == 'FracCal':
                l = TLine(30,0.0,30,0.44)
            #l.SetLineColor(2)
            #l.SetLineWidth(3)
            if critical_line == 1: 
                l.SetLineColor(46)#4,2
                l.SetLineWidth(3)
                l.Draw('same')

            c1.Print(path1 + s + var + cuts.replace('(','_').replace(')','_').replace('&&','_').replace('>','LG').replace('<','LS').replace('=','EQ').replace('.','P').replace('-','N').replace('Jet','J').replace('GenBquark','GBQ') + ".pdf")
            
        elif ct_dep == 1:
            eac0 = str( entries_after_cut['ct0'][s] )
            c1.SetLogx()
            #gr = TGraph( len_of_lt , x , yy['sgn'][s] )
            gr = TGraphErrors( len_of_lt , x , yy['sgn'][s] , ex , ey['sgn'][s] )
            gr.SetMarkerSize(1.5)
            gr.SetMarkerStyle(1)
            gr.GetYaxis().SetTitleOffset(1.6)
            gr.SetLineColor(4)
            gr.SetLineWidth(4)
            gr.SetTitle('mean ' + s )
            gr.GetXaxis().SetTitle('decaying length (mm)')
            gr.GetYaxis().SetTitle('mean normalized number of events')
            gr.GetXaxis().SetTitleOffset(1.4)
            gr.SetMaximum( plotrange[s] * 1.12 )
            gr.SetName('sgn')
            gr.Draw('ACP')  # '' sets up the scattering style
            gr1 = TGraphErrors( len_of_lt , x , yy['QCD'][s] , ex , ey['QCD'][s] )
            gr1.SetMarkerSize(1.0)
            gr1.SetMarkerStyle(1)
            gr.GetYaxis().SetTitleOffset(1.6)
            gr1.SetLineColor(2)
            gr1.SetLineWidth(2)
            gr1.SetName('QCD')
            #gr1.SetTitle('averaged ' + s)
            #gr1.GetXaxis().SetTitle('decaying length (mm)')
            #gr1.GetYaxis().SetTitle('mean frequency')
            gr1.Draw('CP')  # '' sets up the scattering style
            legend = TLegend(0.76, 0.56, 0.99, 0.88)
            legend.SetHeader( 'Entries: ' + eac0 )
            legend.AddEntry('QCD', legendb, 'l')
            legend.AddEntry('sgn', legends, 'l')
            legend.Draw()
            for ct in cut_text:
                cut_text[ct].Draw()
            c1.Print(path1 + 'mean_' + s + var + cuts.replace('(','_').replace(')','_').replace('&&','_').replace('>','LG').replace('<','LS').replace('=','EQ').replace('.','P').replace('-','N').replace('Jet','J').replace('GenBquark','GBQ') + ".pdf")
        c1.Update()
        c1.Close() 
        print('|||||||||||||||||||||||||||||||||||||||||||||||||||')        
コード例 #9
0
ファイル: plotTools.py プロジェクト: jaimeleonh/HHbbtautau
def combinePlotsWithRatios(hlist,
                           ratioDictList,
                           legends,
                           plottingStuff,
                           path,
                           savescaffold,
                           logy=False,
                           normalize=False,
                           lumi=10000):
    print "Combining list of plots"
    if len(hlist) == 0: raise RuntimeError("Empty list of plots")
    c = r.TCanvas("c", "c", 10, 10, 1000, 1000)
    #c.Divide(1,2,0,0)
    pad1 = r.TPad("pad1", "The pad 70% of the height", 0.0, 0.3, 1.0, 1.0, 31)
    pad2 = r.TPad("pad2", "The pad 30% of the height", 0.0, 0.0, 1.0, 0.3, 32)

    pad1.SetFillColor(r.kWhite)
    pad2.SetFillColor(r.kWhite)
    pad1.Draw()
    pad2.Draw("same")
    pad1.cd()
    pad1.SetBottomMargin(0.1)
    #pad1.SetLeftMargin(0.2);

    binWidth = hlist[0].GetBinWidth(1)
    lowerEdge = hlist[0].GetBinCenter(1) - binWidth / 2
    upperEdge = hlist[0].GetBinCenter(hlist[0].GetNbinsX()) + binWidth / 2

    maximum = 0

    gStyle.SetOptStat(0)
    gStyle.SetTitleFontSize(.05)
    gStyle.SetLabelSize(.03, "XY")

    leg = r.TLegend(plottingStuff['legxlow'], plottingStuff['legylow'],
                    plottingStuff['legxhigh'], plottingStuff['legyhigh'])
    for iplot in range(len(hlist)):
        if hlist[iplot].Integral() > 0:
            hlist[iplot].Scale(1. / hlist[iplot].Integral())
        if hlist[iplot].GetMaximum() > maximum:
            maximum = hlist[iplot].GetMaximum()
        if legends[iplot] in markerColorsMerge:
            #hlist[iplot].SetFillColor(markerColorsMerge[legends[iplot]])
            hlist[iplot].SetMarkerColor(markerColorsMerge[legends[iplot]])
            hlist[iplot].SetLineColor(markerColorsMerge[legends[iplot]])
        else:
            #hlist[iplot].SetFillColor(markerColors[iplot % len(markerColors)])
            hlist[iplot].SetMarkerColor(markerColors[iplot %
                                                     len(markerColors)])
            hlist[iplot].SetLineColor(markerColors[iplot % len(markerColors)])

        #if legends[iplot]=="VBFHHSM" or legends[iplot]=="GGHHSM" : hlist[iplot].SetLineStyle(r.kDashed)

        hlist[iplot].SetMarkerStyle(20)
        leg.AddEntry(hlist[iplot], legends[iplot], "PL")

    dummy_hist = r.TH1F(
        "dummy", " ;" + hlist[0].GetXaxis().GetTitle() +
        "; Normalized entries / {:.2f}".format(binWidth), hlist[0].GetNbinsX(),
        lowerEdge, upperEdge)
    dummy_hist.GetYaxis().SetRangeUser(
        0, 1.35 * maximum) if not logy else dummy_hist.GetYaxis().SetRangeUser(
            1E-3, 100 * maximum)
    # if logy: dummy_hist.SetMinimum(1E-3)
    dummy_hist.GetYaxis().SetTitleOffset(1.4)
    dummy_hist.Draw()

    for iplot in range(len(hlist)):
        hlist[iplot].Draw("histosame")

    leg.SetFillColor(4001)
    leg.SetBorderSize(0)
    leg.SetNColumns(2)
    leg.Draw()
    if logy: pad1.SetLogy()

    r.gPad.Update()
    #hlist[0].GetYaxis().SetRangeUser(plottingStuff['lowlimityaxis'], plottingStuff['highlimityaxis'])

    firstLabel = "#scale[1.5]{CMS} private work"
    otherStuff = ["channel", "selection", "region"]
    for elem in otherStuff:
        if elem in plottingStuff.keys():
            firstLabel += "," + (elem != "#tau#tau") * " "
            firstLabel += plottingStuff[elem]

    firsttex = r.TLatex()
    firsttex.SetTextSize(0.03)
    firsttex.DrawLatexNDC(0.11, 0.91, firstLabel)
    firsttex.Draw("same")

    secondtext = r.TLatex()
    toDisplay = r.TString()
    toDisplay = r.TString("{:.1f}".format(lumi / 1000.) + "fb^{-1}, 13 TeV")
    secondtext.SetTextSize(0.035)
    secondtext.SetTextAlign(31)
    secondtext.DrawLatexNDC(0.90, 0.91, toDisplay.Data())
    secondtext.Draw("same")

    r.gPad.SetTicks(1, 1)
    r.gPad.RedrawAxis()

    pad2.cd()
    pad2.SetGrid()
    legD = r.TLegend(0.2575 + 2 * 0.1975, plottingStuff['legylow'],
                     plottingStuff['legxhigh'], plottingStuff['legyhigh'])
    dummy_hist_D = r.TH1F("dummy_D",
                          " ;" + hlist[0].GetXaxis().GetTitle() + "; Ratio",
                          hlist[0].GetNbinsX(), lowerEdge, upperEdge)
    dummy_hist_D.GetYaxis().SetRangeUser(0.5, 2)
    dummy_hist_D.GetYaxis().SetNdivisions(4)
    dummy_hist_D.GetYaxis().SetTitleOffset(0.45)
    dummy_hist_D.SetLabelSize(0.08, "xy")
    dummy_hist_D.SetTitleSize(0.08, "xy")
    dummy_hist_D.GetYaxis().SetNdivisions(4)
    dummy_hist_D.Draw()

    myRatios = []
    for i, ratio in enumerate(ratioDictList):
        aux = ratio['num'].Clone()
        aux1 = ratio['den'].Clone()
        aux.Divide(aux1)
        aux.SetLineColor(ratio['color'])
        aux.SetMarkerColor(ratio['color'])
        legD.AddEntry(aux, ratio['legend'], "PL")
        myRatios.append(aux)

    for histo in myRatios:
        histo.Draw("P, same")
    legD.Draw("same")

    if not logy:
        c.SaveAs(path + savescaffold + ".png")
        c.SaveAs(path + savescaffold + ".pdf")
    else:
        c.SaveAs(path + savescaffold + "_logy.png")
        c.SaveAs(path + savescaffold + "_logy.pdf")

    c.Close()
    del c
コード例 #10
0
def plot_2(var, cuts):
    for s in attr:
        c1 = TCanvas("c1", "Signals", 1200, 800)
        c1.SetTopMargin(0.12)
        c1.SetLeftMargin(0.14)
        c1.SetRightMargin(0.24)
        c1.cd()
        c1.SetGrid()
        gStyle.SetTitleFontSize(0.08)
        if ct_dep == 0:
            if s in ('elf', 'muf', 'chm', 'cm', 'nm'):
                c1.SetLogx()
            for cc in channel:
                #hist[cc][s].SetMaximum(0.44)
                hist[cc][s].Draw('colz same')
                if CHS == 1:
                    hist_CHS[cc][s].Draw('colz same')
            legend = TLegend(0.76, 0.56, 0.99, 0.88)
            legend.SetHeader(entry['entries'])
            for cc in channel:
                legend.AddEntry(hist[cc][s], cc)
                if CHS == 1:
                    legend.AddEntry(hist_CHS[cc][s], cc + 'CHS')
            legend.Draw()
            for ct in cut_text:
                cut_text[ct].Draw()
            c1.Print(path1 + s + var +
                     cuts.replace('(', '_').replace(')', '_').replace(
                         '&&', '_').replace('>', 'LG').replace('<', 'LS').
                     replace('=', 'EQ').replace('.', 'P').replace('-', 'N').
                     replace('Jet', 'J').replace('GenBquark', 'GBQ') + ".pdf")

        elif ct_dep == 1:
            eac0 = str(entries_after_cut['ct0'][s])
            c1.SetLogx()
            #gr = TGraph( len_of_lt , x , yy['sgn'][s] )
            gr = TGraphErrors(len_of_lt, x, yy['sgn'][s], ex, ey['sgn'][s])
            gr.SetMarkerSize(1.5)
            gr.SetMarkerStyle(1)
            gr.GetYaxis().SetTitleOffset(1.6)
            gr.SetLineColor(4)
            gr.SetLineWidth(4)
            gr.SetTitle('mean ' + s)
            gr.GetXaxis().SetTitle('decaying length (mm)')
            gr.GetYaxis().SetTitle('mean normalized number of events')
            gr.GetXaxis().SetTitleOffset(1.4)
            gr.SetMaximum(plotrange[s] * 1.12)
            gr.SetName('sgn')
            gr.Draw('ACP')  # '' sets up the scattering style
            gr1 = TGraphErrors(len_of_lt, x, yy['QCD'][s], ex, ey['QCD'][s])
            gr1.SetMarkerSize(1.0)
            gr1.SetMarkerStyle(1)
            gr.GetYaxis().SetTitleOffset(1.6)
            gr1.SetLineColor(2)
            gr1.SetLineWidth(2)
            gr1.SetName('QCD')
            #gr1.SetTitle('averaged ' + s)
            #gr1.GetXaxis().SetTitle('decaying length (mm)')
            #gr1.GetYaxis().SetTitle('mean frequency')
            gr1.Draw('CP')  # '' sets up the scattering style
            legend = TLegend(0.76, 0.56, 0.99, 0.88)
            legend.SetHeader('Entries: ' + eac0)
            legend.AddEntry('QCD', legendb, 'l')
            legend.AddEntry('sgn', legends, 'l')
            legend.Draw()
            for ct in cut_text:
                cut_text[ct].Draw()
            c1.Print(path1 + 'mean_' + s + var +
                     cuts.replace('(', '_').replace(')', '_').replace(
                         '&&', '_').replace('>', 'LG').replace('<', 'LS').
                     replace('=', 'EQ').replace('.', 'P').replace('-', 'N').
                     replace('Jet', 'J').replace('GenBquark', 'GBQ') + ".pdf")
        c1.Update()
        c1.Close()
        print('|||||||||||||||||||||||||||||||||||||||||||||||||||')
コード例 #11
0
def initialization(batch=True, font=default_font):
    '''-- ROOT initialization --'''

    print "Initializing ROOT ..."

    # general
    gROOT.Reset()
    gROOT.SetBatch(batch)
    gROOT.SetStyle("Plain")

    # gStyle
    gStyle.SetFillColor(0)
    gStyle.SetCanvasColor(10)
    gStyle.SetLineWidth(1)
    gStyle.SetPalette(8)
    gStyle.SetTextFont(font)
    #gStyle.SetTextSize(30)

    # Frame
    gStyle.SetFrameBorderMode(0)
    gStyle.SetFrameFillColor(0)

    # Pad
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadColor(0)
    gStyle.SetPadBottomMargin(0.1)
    gStyle.SetPadTopMargin(0.01)
    gStyle.SetPadLeftMargin(0.1)
    gStyle.SetPadRightMargin(0.01)
    gStyle.SetPadTickX(1)  # make ticks be on all 4 sides.
    gStyle.SetPadTickY(1)
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)

    # histogram
    gStyle.SetHistFillStyle(0)
    gStyle.SetOptTitle(0)
    gStyle.SetTitleSize(0.22)
    gStyle.SetTitleFontSize(10)
    gStyle.SetTitleFont(font)
    gStyle.SetTitleFont(font, "xyz")
    gStyle.SetTitleYOffset(1.0)
    gStyle.SetTitleXOffset(1.0)
    gStyle.SetTitleXSize(0.04)
    gStyle.SetTitleYSize(0.04)
    gStyle.SetTitleX(.15)
    gStyle.SetTitleY(.98)
    gStyle.SetTitleW(.70)
    gStyle.SetTitleH(.05)

    # statistics box
    gStyle.SetOptStat(0)
    gStyle.SetStatFont(font)
    gStyle.SetStatFontSize(10)
    gStyle.SetStatX(.91)
    gStyle.SetStatY(.90)
    gStyle.SetStatW(.15)
    gStyle.SetStatH(.15)

    # axis labels
    gStyle.SetLabelFont(font)
    gStyle.SetLabelFont(font, "xyz")
    gStyle.SetLabelSize(10, "xyz")
    # gStyle.SetGridColor(1)
    gStyle.SetLegendBorderSize(1)
コード例 #12
0
args = parser.parse_args()

if args.debug:
    logging.basicConfig(level=logging.DEBUG)
else:
    logging.basicConfig(level=logging.INFO)

logging.info("importing ROOT")
import ROOT
from ROOT import TCanvas, TGraph, TLine, gStyle, gROOT, gPad, TFile, TTree, TPaveText, TLegend, kBlack, TColor, kGray
#include "TGraph.h"
#include "TAxis.h"
#include "TH1.h"
logging.info("done")

gStyle.SetTitleFontSize(args.font_size)
gROOT.ForceStyle()

gStyle.SetTitleW(0.7)  # //per cent of the pad width
gStyle.SetTitleH(0.5)  # //per cent of the pad height
# none of these work


def rgb(r, g, b):
    '''rgb(r, g, b):

    from:
    http://webhome.phy.duke.edu/~dmb60/the-guide/
    TColor* color = gROOT->GetColor(TColor::GetColor(red,green,blue));//Use ints from 0 to 255 
    color->SetAlpha(0.5);//0 is fully transparent, 1 fully opaque
    hist->SetFillColor(color->GetNumber());
コード例 #13
0
    def initialize(fitresults=True, grid=False):
        gROOT.SetStyle("Plain")
        gStyle.SetOptFit()
        gStyle.SetOptStat(0)
        # 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.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.SetFrameFillColor(kWhite)
        gStyle.SetFrameFillStyle(1000)
        gStyle.SetFrameLineColor(1)
        gStyle.SetFrameLineStyle(1)
        gStyle.SetFrameLineWidth(1)

        # For the histo:
        gStyle.SetHistLineColor(1)
        gStyle.SetHistLineStyle(0)
        gStyle.SetHistLineWidth(2)

        gStyle.SetEndErrorSize(2)
        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)

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

        # Margins:
        gStyle.SetPadTopMargin(0.05)
        gStyle.SetPadLeftMargin(0.16)
        gStyle.SetPadRightMargin(0.04) # top group adaption, original is 0.02
        gStyle.SetPadBottomMargin(0.13)

        # For the Global title:

        gStyle.SetOptTitle(0)
        gStyle.SetTitleFont(42)
        gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        gStyle.SetTitleFillColor(10)
        gStyle.SetTitleFontSize(0.05)

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

        # For the axis labels:

        gStyle.SetLabelColor(1, "XYZ")
        gStyle.SetLabelFont(42, "XYZ")
        gStyle.SetLabelOffset(0.007, "XYZ")
        gStyle.SetLabelSize(0.05, "XYZ")
        #gStyle.SetLabelSize(0.04, "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)

        gStyle.SetPalette(1) #(1,0)

        # another top group addition
        gStyle.SetHatchesSpacing(1.0)

        # Postscript options:
        gStyle.SetPaperSize(20., 20.)
        # For graphs
        gStyle.SetErrorX(0)  # suppress error along x

        if grid:
          gStyle.SetPadGridX(gridOn)
          gStyle.SetPadGridY(gridOn)
          gStyle.SetGridColor(kGray)
コード例 #14
0
def tdrstyle():
    gROOT.SetStyle("Plain")
    
    gStyle.SetAxisColor(1, "XYZ")
    
    gStyle.SetCanvasColor(0)
    #gStyle.SetCanvasBorderSize(10)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetCanvasDefH(700)
    gStyle.SetCanvasDefW(700)
    gStyle.SetCanvasDefX(0)
    gStyle.SetCanvasDefY(0)
    
    gStyle.SetFitFormat("5.4g")
    gStyle.SetFuncColor(2)
    gStyle.SetFuncStyle(1)
    gStyle.SetFuncWidth(1)
    
    gStyle.SetFrameBorderMode(0)
    gStyle.SetFrameBorderSize(1)
    gStyle.SetFrameFillStyle(0)
    gStyle.SetFrameFillColor(0)
    gStyle.SetFrameLineColor(1)
    gStyle.SetFrameLineStyle(1)  # 0?
    gStyle.SetFrameLineWidth(1)  # 1?
    
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)
    
    #gStyle.SetHistFillColor(1)
    #gStyle.SetHistFillStyle(0)
    gStyle.SetHistLineColor(1)
    gStyle.SetHistLineStyle(0)
    gStyle.SetHistLineWidth(1)
    
    gStyle.SetLabelColor(1, "XYZ")
    gStyle.SetLabelFont(42,"XYZ")
    gStyle.SetLabelOffset(0.007,"XYZ")  # 0.010?
    gStyle.SetLabelSize(0.05,"XYZ")  # 0.04?
    
    gStyle.SetLegendBorderSize(0)
    gStyle.SetLegendFillColor(0)
    gStyle.SetLegendFont(42)
    
    gStyle.SetMarkerSize(1.0)
    gStyle.SetMarkerStyle(20)
    
    gStyle.SetLineColor(1)
    gStyle.SetLineWidth(2)
    #gStyle.SetLineScalePS(2)
    
    gStyle.SetOptDate(0)
    gStyle.SetOptFile(0)
    gStyle.SetOptFit(1)
    gStyle.SetOptStat(0)
    gStyle.SetOptTitle(0)
    #gStyle.SetOptLogx(0)
    #gStyle.SetOptLogy(0)
    #gStyle.SetOptLogz(0)
    
    gStyle.SetPadColor(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadBorderSize(10)
    gStyle.SetPadTopMargin(0.05)  # 0.08?
    gStyle.SetPadBottomMargin(0.13)
    gStyle.SetPadLeftMargin(0.16)
    gStyle.SetPadRightMargin(0.03)  # 0.05?
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
    
    gStyle.SetStatColor(0)
    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.SetStatX(0)
    #gStyle.SetStatY(0)
    
    #gStyle.SetTextSize(0.055)
    gStyle.SetTextFont(42)
    
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleColor(1)
    gStyle.SetTitleFont(42)
    gStyle.SetTitleColor(1,"XYZ")
    gStyle.SetTitleFont(42,"XYZ")
    gStyle.SetTitleSize(0.06,"XYZ")  # 0.05?
    #gStyle.SetTitleOffset(1.4,"XYZ")
    gStyle.SetTitleOffset(0.9,"X")
    gStyle.SetTitleOffset(1.20,"Y")
    gStyle.SetTitleFillColor(10)
    gStyle.SetTitleFontSize(0.05)
    gStyle.SetTitleTextColor(1)
    #gStyle.SetTitleH(0)
    #gStyle.SetTitleW(0)
    #gStyle.SetTitleX(0)
    #gStyle.SetTitleY(0.985)
    #gStyle.SetTitleStyle(1001)
    
    gStyle.SetPalette(1)
    #gStyle.SetNdivisions(510, "XYZ")  # 505?
    gStyle.SetNdivisions(505, "XYZ")
    gStyle.SetEndErrorSize(2)  # 2?
    #gStyle.SetErrorMarker(20)
    #gStyle.SetErrorX(0.)
    #gStyle.SetPaperSize(20.,20.)
    gStyle.SetStripDecimals(1)
    gStyle.SetTickLength(0.03, "XYZ")
    return 1
コード例 #15
0
def setStyle():

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBottomMargin(0.12)
    gStyle.SetPadLeftMargin(0.12)
    gStyle.SetCanvasColor(ROOT.kWhite)
    gStyle.SetCanvasDefH(600)
    #Height of canvas
    gStyle.SetCanvasDefW(600)
    #Width of canvas
    gStyle.SetCanvasDefX(0)
    #POsition on screen
    gStyle.SetCanvasDefY(0)
    gStyle.SetPadTopMargin(0.05)
    gStyle.SetPadBottomMargin(0.15)
    #0.13);
    gStyle.SetPadLeftMargin(0.11)
    #0.16);
    gStyle.SetPadRightMargin(0.05)
    #0.02);

    # For the Pad:
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadColor(ROOT.kWhite)
    gStyle.SetPadGridX(ROOT.kFALSE)
    gStyle.SetPadGridY(ROOT.kFALSE)
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)

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

    gStyle.SetAxisColor(1, "XYZ")
    gStyle.SetStripDecimals(ROOT.kTRUE)
    gStyle.SetTickLength(0.03, "XYZ")
    gStyle.SetNdivisions(505, "XYZ")
    gStyle.SetPadTickX(1)
    # To get tick marks on the opposite side of the frame
    gStyle.SetPadTickY(1)
    gStyle.SetGridColor(0)
    gStyle.SetGridStyle(3)
    gStyle.SetGridWidth(1)

    gStyle.SetTitleColor(1, "XYZ")
    gStyle.SetTitleFont(42, "XYZ")
    gStyle.SetTitleSize(0.05, "XYZ")
    gStyle.SetTitleXOffset(1.15)
    #0.9);
    gStyle.SetTitleYOffset(1.3)
    # => 1.15 if exponents

    gStyle.SetLabelColor(1, "XYZ")
    gStyle.SetLabelFont(42, "XYZ")
    gStyle.SetLabelOffset(0.007, "XYZ")
    gStyle.SetLabelSize(0.045, "XYZ")

    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetTitleTextColor(1)
    gStyle.SetTitleFillColor(10)
    gStyle.SetTitleFontSize(0.05)

    gStyle.SetOptStat(0)
    gStyle.SetOptTitle(0)
    gStyle.SetOptFit(1)

    NRGBs = 5
    NCont = 255
    stops = [0.00, 0.34, 0.61, 0.84, 1.00]
    red = [0.00, 0.00, 0.87, 1.00, 0.51]
    green = [0.00, 0.81, 1.00, 0.20, 0.00]
    blue = [0.51, 1.00, 0.12, 0.00, 0.00]
    stopsArray = array('d', stops)
    redArray = array('d', red)
    greenArray = array('d', green)
    blueArray = array('d', blue)
    TColor.CreateGradientColorTable(NRGBs, stopsArray, redArray, greenArray,
                                    blueArray, NCont)
    gStyle.SetNumberContours(NCont)
コード例 #16
0
def rooFit109():

    print ">>> setup model..."
    x = RooRealVar("x", "x", -10, 10)
    sigma = RooRealVar("sigma", "sigma", 3, 0.1, 10)
    mean = RooRealVar("mean", "mean", 0, -10, 10)
    gauss = RooGaussian("gauss", "gauss", x, RooConst(0),
                        sigma)  # RooConst(0) gives segfaults
    data = gauss.generate(RooArgSet(x), 100000)  # RooDataSet
    #sigma = 3.15 # overwrites RooRealVar with a float
    sigma.setVal(3.15)

    print ">>> plot data and slightly distorted model..."
    frame1 = x.frame(Title("Data with distorted Gaussian pdf"),
                     Bins(40))  # RooPlot
    data.plotOn(frame1, DataError(RooAbsData.SumW2))
    gauss.plotOn(frame1)

    print ">>> calculate chi^2..."
    # Show the chi^2 of the curve w.r.t. the histogram
    # If multiple curves or datasets live in the frame you can specify
    # the name of the relevant curve and/or dataset in chiSquare()
    print ">>>   chi^2 = %.2f" % frame1.chiSquare()

    print ">>> construct histograms with the residuals and pull of the data wrt the curve"
    hresid = frame1.residHist()  # RooHist
    hpull = frame1.pullHist()  # RooHist
    frame2 = x.frame(Title("Residual Distribution"))  # RooPlot
    frame2.addPlotable(hresid, "P")
    frame3 = x.frame(Title("Pull Distribution"))  # RooPlot
    frame3.addPlotable(hpull, "P")

    print ">>> draw functions and toy data on canvas..."
    canvas = TCanvas("canvas", "canvas", 100, 100, 2000, 400)
    canvas.Divide(3)
    for i, frame in enumerate([frame1, frame2, frame3], 1):
        canvas.cd(i)
        gPad.SetLeftMargin(0.14)
        gPad.SetRightMargin(0.04)
        frame.GetYaxis().SetTitleOffset(1.5)
        frame.GetYaxis().SetLabelOffset(0.010)
        frame.GetYaxis().SetTitleSize(0.045)
        frame.GetYaxis().SetLabelSize(0.042)
        frame.GetXaxis().SetTitleSize(0.045)
        frame.GetXaxis().SetLabelSize(0.042)
        frame.Draw()
    canvas.SaveAs("rooFit109.png")
    canvas.Close()

    # ratio/pull/residual plot
    print ">>> draw with pull plot..."
    canvas = TCanvas("canvas", "canvas", 100, 100, 1000, 1000)
    canvas.Divide(2)
    canvas.cd(1)
    gPad.SetPad("pad1", "pad1", 0, 0.33, 1, 1, 0, -1, 0)
    gPad.SetTopMargin(0.10)
    gPad.SetBottomMargin(0.03)
    gPad.SetLeftMargin(0.14)
    gPad.SetRightMargin(0.04)
    gPad.SetBorderMode(0)
    gStyle.SetTitleFontSize(0.062)
    frame1.GetYaxis().SetTitle("Events / %.3g GeV" % frame1.getFitRangeBinW())
    frame1.GetYaxis().SetTitleSize(0.059)
    frame1.GetYaxis().SetTitleOffset(1.21)
    #frame1.GetYaxis().SetLabelOffset(0.010)
    frame1.GetXaxis().SetLabelSize(0)
    frame1.GetYaxis().SetLabelSize(0.045)
    frame1.Draw()
    canvas.cd(2)
    gPad.SetPad("pad2", "pad2", 0, 0, 1, 0.33, 0, -1, 0)
    gPad.SetTopMargin(0.01)
    gPad.SetBottomMargin(0.30)
    gPad.SetLeftMargin(0.14)
    gPad.SetRightMargin(0.04)
    gPad.SetBorderMode(0)
    gPad.SetGridy(kTRUE)
    line1 = TLine(frame3.GetXaxis().GetXmin(), 0,
                  frame3.GetXaxis().GetXmax(), 0)
    line2 = TLine(frame3.GetXaxis().GetXmin(), 0,
                  frame3.GetXaxis().GetXmax(), 0)
    line1.SetLineColor(0)  # white to clear dotted grid lines
    line2.SetLineColor(12)  # dark grey
    line2.SetLineStyle(2)
    frame3.SetTitle("")
    frame3.GetYaxis().SetTitle("pull")
    frame3.GetXaxis().SetTitle("#Deltam^{2}_{ll} [GeV]")
    frame3.GetXaxis().SetTitleSize(0.13)
    frame3.GetYaxis().SetTitleSize(0.12)
    frame3.GetXaxis().SetTitleOffset(1.0)
    frame3.GetYaxis().SetTitleOffset(0.58)
    frame3.GetXaxis().SetLabelSize(0.10)
    frame3.GetYaxis().SetLabelSize(0.10)
    frame3.GetXaxis().SetLabelOffset(0.02)
    frame3.GetYaxis().SetLabelOffset(0.01)
    frame3.GetYaxis().SetRangeUser(-5, 5)
    frame3.GetYaxis().CenterTitle(True)
    frame3.GetYaxis().SetNdivisions(505)
    frame3.Draw("")
    line1.Draw("SAME")
    line2.Draw("SAME")
    frame3.Draw("SAME")
    canvas.SaveAs("rooFit109_ratiolike.png")
    canvas.Close()
コード例 #17
0
    def initStyle():
        gROOT.SetStyle("Plain")

        # For the canvas:
        gStyle.SetCanvasBorderMode(0)
        gStyle.SetCanvasColor(kWhite)
        gStyle.SetCanvasDefH(700)  #Height of canvas
        gStyle.SetCanvasDefW(700)  #Width of canvas
        gStyle.SetCanvasDefX(0)  #Position on screen
        gStyle.SetCanvasDefY(0)

        # For the line:
        gStyle.SetLineWidth(2)

        # For the Pad:
        gStyle.SetPadBorderMode(0)
        # gStyle.SetPadBorderSize(Width_t size = 1)
        gStyle.SetPadColor(kWhite)
        gStyle.SetPadGridX(True)
        gStyle.SetPadGridY(True)
        gStyle.SetGridColor(0)
        gStyle.SetGridStyle(3)
        gStyle.SetGridWidth(1)

        # For the frame:
        gStyle.SetFrameBorderMode(0)
        gStyle.SetFrameBorderSize(1)
        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(2)
        # gStyle.SetLegoInnerR(Float_t rad = 0.5)
        # gStyle.SetNumberContours(Int_t number = 20)

        gStyle.SetEndErrorSize(2)
        #gStyle.SetErrorMarker(20)
        gStyle.SetErrorX(0.)

        gStyle.SetMarkerStyle(8)
        gStyle.SetMarkerSize(1)

        #For the fit/function:
        gStyle.SetOptFit(0)
        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.11)
        gStyle.SetPadBottomMargin(0.13)
        gStyle.SetPadLeftMargin(0.17)
        gStyle.SetPadRightMargin(0.07)

        # For the Global title:
        gStyle.SetOptTitle(0)
        gStyle.SetTitleFont(42)
        gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        gStyle.SetTitleFillColor(10)
        gStyle.SetTitleFontSize(0.04)
        # gStyle.SetTitleH(0) # Set the height of the title box
        # gStyle.SetTitleW(0) # Set the width of the title box
        #gStyle.SetTitleX(0.35) # Set the position of the title box
        #gStyle.SetTitleY(0.986) # Set the position of the title box
        # gStyle.SetTitleStyle(Style_t style = 1001)
        #gStyle.SetTitleBorderSize(0)

        # For the axis titles:
        gStyle.SetTitleColor(1, "XYZ")
        gStyle.SetTitleFont(42, "XYZ")
        gStyle.SetTitleSize(0.05, "XYZ")
        # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size?
        # gStyle.SetTitleYSize(Float_t size = 0.02)
        gStyle.SetTitleXOffset(1.)
        gStyle.SetTitleYOffset(1.3)
        #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.035, "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)

        gStyle.SetPalette(1)  #(1,0)

        # another top group addition
        gStyle.SetHatchesSpacing(1.0)

        # Postscript options:
        gStyle.SetPaperSize(20., 20.)
        #gStyle.SetPaperSize(TStyle.kA4)
        #gStyle.SetPaperSize(27., 29.7)
        #TGaxis.SetMaxDigits(3)
        # 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.SetColorModelPS(1)

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

        #gStyle.cd()
        print "TDR Style initialized"
コード例 #18
0
ファイル: plotTools.py プロジェクト: jaimeleonh/HHbbtautau
def combinePlots(hlist,
                 legends,
                 plottingStuff,
                 path,
                 savescaffold,
                 logy=False,
                 normalize=False,
                 lumi=1000.):
    print "Combining list of plots"
    if len(hlist) == 0: raise RuntimeError("Empty list of plots")
    c = r.TCanvas("c", "c", 800, 800)

    binWidth = hlist[0].GetBinWidth(1)
    lowerEdge = hlist[0].GetBinCenter(1) - binWidth / 2
    upperEdge = hlist[0].GetBinCenter(hlist[0].GetNbinsX()) + binWidth / 2

    maximum = 0

    gStyle.SetOptStat(0)
    gStyle.SetTitleFontSize(.05)
    gStyle.SetLabelSize(.03, "XY")

    leg = r.TLegend(plottingStuff['legxlow'], plottingStuff['legylow'],
                    plottingStuff['legxhigh'], plottingStuff['legyhigh'])
    for iplot in range(len(hlist)):
        if hlist[iplot].Integral() > 0:
            hlist[iplot].Scale(1. / hlist[iplot].Integral())
        if hlist[iplot].GetMaximum() > maximum:
            maximum = hlist[iplot].GetMaximum()
        if legends[iplot] in markerColorsMerge:
            #hlist[iplot].SetFillColor(markerColorsMerge[legends[iplot]])
            hlist[iplot].SetMarkerColor(markerColorsMerge[legends[iplot]])
            hlist[iplot].SetLineColor(markerColorsMerge[legends[iplot]])
        else:
            #hlist[iplot].SetFillColor(markerColors[iplot % len(markerColors)])
            hlist[iplot].SetMarkerColor(markerColors[iplot %
                                                     len(markerColors)])
            hlist[iplot].SetLineColor(markerColors[iplot % len(markerColors)])

        if legends[iplot] == "VBFHHSM" or legends[iplot] == "GGHHSM_LO":
            hlist[iplot].SetLineStyle(r.kDashed)

        hlist[iplot].SetMarkerStyle(20)
        leg.AddEntry(hlist[iplot], legends[iplot], "PL")

    dummy_hist = r.TH1F(
        "dummy", " ;" + hlist[0].GetXaxis().GetTitle() +
        "; Normalized entries / {:.2f}".format(binWidth), hlist[0].GetNbinsX(),
        lowerEdge, upperEdge)
    dummy_hist.GetYaxis().SetRangeUser(
        0, 1.35 * maximum) if not logy else dummy_hist.GetYaxis().SetRangeUser(
            1E-3, 100 * maximum)
    # if logy: dummy_hist.SetMinimum(1E-3)
    dummy_hist.GetYaxis().SetTitleOffset(1.4)
    dummy_hist.Draw()

    for iplot in range(len(hlist)):
        hlist[iplot].Draw("histosame")

    leg.SetFillColor(4001)
    leg.SetBorderSize(0)
    leg.SetNColumns(2)
    leg.Draw()

    r.gPad.Update()
    #hlist[0].GetYaxis().SetRangeUser(plottingStuff['lowlimityaxis'], plottingStuff['highlimityaxis'])

    firstLabel = "#scale[1.5]{CMS} private work"
    otherStuff = ["channel", "selection", "region"]
    for elem in otherStuff:
        if elem in plottingStuff.keys():
            firstLabel += "," + (elem != "#tau#tau") * " "
            firstLabel += plottingStuff[elem]

    firsttex = r.TLatex()
    firsttex.SetTextSize(0.03)
    firsttex.DrawLatexNDC(0.11, 0.91, firstLabel)
    firsttex.Draw("same")

    secondtext = r.TLatex()
    toDisplay = r.TString()
    toDisplay = r.TString("{:.1f}".format(lumi / 1000.) + "fb^{-1}, 13 TeV")
    secondtext.SetTextSize(0.035)
    secondtext.SetTextAlign(31)
    secondtext.DrawLatexNDC(0.90, 0.91, toDisplay.Data())
    secondtext.Draw("same")

    r.gPad.SetTicks(1, 1)
    r.gPad.RedrawAxis()

    if logy: c.SetLogy()

    if not logy: c.SaveAs(path + savescaffold + ".png")
    else: c.SaveAs(path + savescaffold + "_logy.png")
    if not logy: c.SaveAs(path + savescaffold + ".pdf")
    else: c.SaveAs(path + savescaffold + "_logy.pdf")
    #if not logy : c.SaveAs(path + savescaffold + ".root")
    #else c.SaveAs(path + savescaffold + "_logy.root")

    c.Close()
    del c
コード例 #19
0
def CLICdpStyle():
    gROOT.SetStyle("Plain")
    gStyle.SetCanvasColor(root.kWhite)
    gStyle.SetFrameFillColor(root.kWhite)
    gStyle.SetStatColor(root.kWhite)
    gStyle.SetPadColor(root.kWhite)
    gStyle.SetFillColor(10)
    gStyle.SetTitleFillColor(root.kWhite)

    gStyle.SetPaperSize(20, 26)

    gStyle.SetDrawBorder(0)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetPadBorderMode(0)
    gStyle.SetFrameBorderMode(0)
    gStyle.SetLegendBorderSize(0)

    gStyle.SetTextSize(0.05)
    gStyle.SetTitleSize(0.06, "xyz")
    gStyle.SetLabelSize(0.06, "xyz")

    gStyle.SetLabelOffset(0.015, "xyz")
    gStyle.SetTitleOffset(1.2, "yz")
    gStyle.SetTitleOffset(1.17, "x")

    font = 42
    gStyle.SetTitleFont(font)
    gStyle.SetTitleFontSize(0.06)
    gStyle.SetStatFont(font)
    gStyle.SetStatFontSize(0.07)
    gStyle.SetTextFont(font)
    gStyle.SetLabelFont(font, "xyz")
    gStyle.SetTitleFont(font, "xyz")
    gStyle.SetTitleBorderSize(0)
    gStyle.SetStatBorderSize(1)
    gStyle.SetMarkerStyle(1)
    gStyle.SetLineWidth(2)
    gStyle.SetMarkerSize(1.2)
    gStyle.SetPalette(1)

    gStyle.SetOptTitle(0)
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)
    gStyle.SetEndErrorSize(5)

    gStyle.SetHistLineWidth(2)
    gStyle.SetFrameLineWidth(2)
    gStyle.SetFuncWidth(2)
    gStyle.SetHistLineColor(root.kBlack)
    gStyle.SetFuncColor(root.kBlack)
    gStyle.SetLabelColor(root.kBlack, "xyz")

    gStyle.SetPadBottomMargin(0.18)
    gStyle.SetPadTopMargin(0.11)
    gStyle.SetPadRightMargin(0.08)
    gStyle.SetPadLeftMargin(0.17)

    gStyle.SetNdivisions(506, "xy")

    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)

    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)

    gStyle.SetCanvasDefW(800)
    gStyle.SetCanvasDefH(700)

    gROOT.ForceStyle()
コード例 #20
0
    # kkbins.addUniform(30,fitphimin,fitphimax)
    traKFitData.plotOn(kkFrame, Name("Data"))
    kkTot.plotOn(kkFrame, RooFit.Normalization(1.0 / float(nfit)), Name("Pdf"))
    traKFitData.plotOn(kkFrame)
    kkTot.paramOn(kkFrame, RooFit.Layout(0.57, 0.99, 0.65))

    kkFrame.Draw()

    pullpad.cd()
    hpull = kkFrame.pullHist("Data", "Pdf")
    pullframe = mmtt_mass.frame(Title("Pull Distribution"),
                                Range(fitphimin, fitphimax))
    pullframe.SetAxisRange(-5.0, 5.0, "Y")
    #pullframe.GetXaxis().SetTitleSize(0.04)
    #pullframe.GetYaxis().SetTitleSize(0.03)
    gStyle.SetTitleFontSize(0.07)
    pullframe.addPlotable(hpull, "P")
    pullframe.Draw()

    lineup = TLine(fitphimin, 4.0, fitphimax, 4.0)
    lineup.SetLineColor(kRed)
    lineup.SetLineStyle(kDashed)
    lineup.Draw()

    linedw = TLine(fitphimin, -4.0, fitphimax, -4.0)
    linedw.SetLineColor(kRed)
    linedw.SetLineStyle(kDashed)
    linedw.Draw()

    kcanvas.SaveAs(region + "/kk_Phi_fit_" + region + ".png")
    kcanvas.SaveAs(region + "/kk_Phi_fit_" + region + ".root")
コード例 #21
0
ファイル: PlotMass.py プロジェクト: suatdonertas/Memoire
# Libraries #
import sys
import glob
import os
import re
import argparse
import math
import numpy as np
import ROOT
from ROOT import TFile, TTree, TCanvas, TPaveText, TPad, gPad, gStyle, TLegend, TH1F, gROOT, TLegend, TRatioPlot, TStyle, TF1, THStack, TColor, TImage, TLine, TPaveStats
from ROOT import kBlack, kBlue, kRed, kOrange, kYellow, kGreen

gROOT.SetBatch(True)

gStyle.SetOptStat("")
gStyle.SetTitleFontSize(.11)
gStyle.SetLabelSize(.03, "XY")

f = TFile.Open("outputDY.root")
t = f.Get("tree")

t.Draw("jj_M:NN_jj_M>>jj(100,0,2200,100,0,2200)", "", "colz")
jj = gROOT.FindObject("jj")

t.Draw("lljj_M:NN_lljj_M>>lljj(100,0,2800,100,0,2800)", "", "colz")
lljj = gROOT.FindObject("lljj")

c1 = TCanvas('c1', 'rec', 200, 10, 1400, 600)

pad1 = TPad('pad1', 'mbb', 0.02, 0.05, 0.49, 1, -1)
pad2 = TPad('pad2', 'mllbb', 0.51, 0.05, 0.98, 1, -1)
コード例 #22
0
    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.)
コード例 #23
0
def ana(tagname, verbosityLevel):
    CUT=0.1
    tag1="LossOfIntegratedLuminosity->GetXaxis()->SetBinLabel("
    tag2="graph->SetPoint("
    FILEPRE='tmp_plot_loss_run_tot_'
    
    sortedscenario=[]
    
    for scenario in range(0,len(tagname)):
        FILEIN=FILEPRE+str(scenario)+'.C'
        if verbosityLevel: print "opening file "+FILEIN
        f=open(FILEIN,'r')
        
        runlist={}
        losslist={}
        lossperrun={}
        
        for line in f.readlines():
            if tag1 in line:
                rec=line.split("SetBinLabel(")[1]
                item=int(rec.split(",")[0])-1
                val=rec.split(",")[1]
                val=val.split('"')[1]
                runlist[item]=val
            elif tag2 in line:
                rec=line.split("SetPoint(")[1]
                rec=rec.split(")")[0]
                item=int(rec.split(",")[0])
                val=abs(float(rec.split(",")[2]))
                losslist[item]=val
        
        for item in runlist.keys():
            lossperrun[runlist[item]]=losslist[item]
        
        if verbosityLevel: print lossperrun.items()
        sortedlist=sorted(lossperrun.items(), key=itemgetter(1),reverse=True)
        sortedscenario.append(sortedlist)
    
    if verbosityLevel: print sortedscenario
    from ROOT import TCanvas,TGraph,gStyle,gROOT,TH1F,TLatex,gPad

    gROOT.SetBatch(True)
    c1 = TCanvas("c1","c1",480,640)
    gStyle.SetOptStat(0)
    gStyle.SetTitleFontSize(0.03)
    for scenario in range(0,len(tagname)):
        filenametxt="lumiloss_"+tagname[scenario]+".txt"
        filetxt=open(filenametxt,'w')

        totloss=0
        plot= TH1F(tagname[scenario],tagname[scenario]+";lumi loss (pb-1);# runs",100,0.,2.)
        texlines=[]
        for item in sortedscenario[scenario]:
            (runno,lumiloss)=item
            filetxt.write(runno+" "+str(lumiloss)+"\n")
            plot.Fill(lumiloss)
            totloss+=lumiloss
            if lumiloss>CUT:
                texlines.append(runno+": "+"%3.2f"%lumiloss+"pb^{-1}")
        filetxt.close()
        if verbosityLevel: print "File: "+filenametxt+" written!"
        plot.Draw()
        gPad.SetLogy(1)
        
        linestep=-0.03
        xcoord = 0.60
        ycoord = 0.935
        tex0=[]
    
        for line in range(0,len(texlines)+2):
            if line==0: text="Total loss: "+"%3.2f"%totloss+" pb^{-1}"
            if line==1: text="Major losses (>0.1 pb^{-1}):"
            if line>1: text=texlines[line-2]
            tex0.append(TLatex(xcoord,ycoord,text))
            tex0[len(tex0)-1].SetNDC(True)
            tex0[len(tex0)-1].SetTextSize(0.03)
            tex0[len(tex0)-1].SetTextColor(1)
            tex0[len(tex0)-1].SetLineWidth(2)
            tex0[len(tex0)-1].Draw()
            ycoord+=linestep
        
        c1.Update()
        c1.Print("lumiloss_"+tagname[scenario]+".png")