def set_palette(name="gray", ncontours=999): """Set a color palette from a given RGB list stops, red, green and blue should all be lists of the same length see set_decent_colors for an example""" if name == "gray" or name == "grayscale": stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [1.00, 0.84, 0.61, 0.34, 0.00] green = [1.00, 0.84, 0.61, 0.34, 0.00] blue = [1.00, 0.84, 0.61, 0.34, 0.00] # elif name == "whatever": # (define more palettes) else: # default palette, looks cool stops = [0.00, 0.34, 0.61, 0.84, 0.1] 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] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours)
def BPalette(): r = array([0., 0.0, 1.0, 1.0, 1.0]) b = array([0., 1.0, 0.0, 0.0, 1.0]) g = array([0., 0.0, 0.0, 1.0, 1.0]) stop = array([0., .25, .50, .75, 1.0]) TColor.CreateGradientColorTable(5, stop, r, g, b, 100) return
def GrayPalette(): R = array([0., 1.]) G = array([0., 1.]) B = array([0., 1.]) Stop = array([0., 1.]) TColor.CreateGradientColorTable(2, Stop, R, G, B, 100) return
def set2DStyle(self, opt="BasicRainBow"): gStyle.SetPadRightMargin( 0.2 ) # Leave more space to the right side of the current Pad to show the histogram scale if opt == "FancyRainBow": icol = 0 gStyle.SetFrameBorderMode(icol) gStyle.SetFrameFillColor(icol) gStyle.SetCanvasBorderMode(icol) gStyle.SetCanvasColor(icol) gStyle.SetPadBorderMode(icol) gStyle.SetPadColor(icol) gStyle.SetStatColor(icol) gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetOptFit(0) ncontours = 999 s = array.array('d', [0.00, 0.34, 0.61, 0.84, 1.00]) r = array.array('d', [0.00, 0.00, 0.87, 1.00, 0.51]) g = array.array('d', [0.00, 0.81, 1.00, 0.20, 0.00]) b = array.array('d', [0.51, 1.00, 0.12, 0.00, 0.00]) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours) if opt == "BasicRainBow": gStyle.SetPalette( 1 ) # This resets the color palette to a simple Rainbow Color Map w/ 50 colors. See https://root.cern.ch/doc/master/classTColor.html
def set_palette(name="palette", n=100, ncontours=999): """Set a color palette from a given RGB list stops, red, green and blue should all be lists of the same length see set_decent_colors for an example""" if name == "gray" or name == "grayscale": stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [1.00, 0.84, 0.61, 0.34, 0.00] green = [1.00, 0.84, 0.61, 0.34, 0.00] blue = [1.00, 0.84, 0.61, 0.34, 0.00] elif name == "myPalette": # (define more palettes) stops = range(n) stops = [-3 + float(i) / n for i in stops] Cb = 0.4 Cr = 0.6 blue = [-1 / Cb * i + 1 for i in stops] green = stops red = [1 / (1 - Cr) * i for i in stops] for i in range(len(stops)): if stops[i] < Cb: green[i] = 0 red[i] = 0 if stops[i] > Cb and stops[i] < Cr: blue[i] = 0 red[i] = 0 if stops[i] < 0.5: green[i] = stops[i] / (0.5 - Cb) else: green[i] = stops[i] / (0.5 - Cr) if stops[i] > Cr: green[i] = 0 blue[i] = 0 # stops = [0.00, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 1.00] # red = [0.00, 0.00, 0.00, 0.00, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 1.00] # green = [0.00, 0.10, 0.30, 0.60, 0.80, 0.60, 0.40, 0.20, 0.00, 0.00, 0.00] # blue = [0.50, 0.60, 0.70, 0.80, 0.50, 0.30, 0.00, 0.00, 0.00, 0.00, 0.00] else: # default palette, looks cool 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] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours)
def set_h2_color_style(): n_rgb = 5 n_contour = 255 stops = np.array([0.00, 0.34, 0.61, 0.84, 1.00]) reds = np.array([0.00, 0.00, 0.87, 1.00, 0.51]) greens = np.array([0.00, 0.81, 1.00, 0.20, 0.00]) blues = np.array([0.51, 1.00, 0.12, 0.00, 0.00]) TColor.CreateGradientColorTable(n_rgb, stops, reds, greens, blues, n_contour) gStyle.SetNumberContours(n_contour) gPad.SetRightMargin(0.2)
def setColorPalette(): nGradients = 100 palette = [] r = [0, 0/255., 227./255., 255/255., 244/255.] g = [0,0/255.,0/255.,237/255.,244/255.] b = [0,159/255.,102/255.,0/255.,244/255.] stop = [0,.25,.55,.9,1] FI = TColor.CreateGradientColorTable(5,array('d',stop),array('d',r),array('d',g),array('d',b),nGradients) for i in range(0,nGradients): palette.append(FI+i) gStyle.SetPalette(nGradients,array('i',palette))
def kBird(): red = array('d', [ 0.2082, 0.0592, 0.0780, 0.0232, 0.1802, 0.5301, 0.8186, 0.9956, 0.9764 ]) green = array('d', [ 0.1664, 0.3599, 0.5041, 0.6419, 0.7178, 0.7492, 0.7328, 0.7862, 0.9832 ]) blue = array('d', [ 0.5293, 0.8684, 0.8385, 0.7914, 0.6425, 0.4662, 0.3499, 0.1968, 0.0539 ]) stops = array('d', [0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0]) TColor.CreateGradientColorTable(9, stops, red, green, blue, 255)
def setpalette(name="rainbow", ncontours=99): """.. function::setpalette() Set a color palette from a given RGB list stops, red, green and blue should all be lists of the same length see set_decent_colors for an example""" from ROOT import TColor, gStyle from array import array if name == "gray" or name == "grayscale": stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [1.00, 0.84, 0.61, 0.34, 0.00] green = [1.00, 0.84, 0.61, 0.34, 0.00] blue = [1.00, 0.84, 0.61, 0.34, 0.00] elif name == 'darkbody': stops = [0.00, 0.25, 0.50, 0.75, 1.00] red = [0.00, 0.50, 1.00, 1.00, 1.00] green = [0.00, 0.00, 0.55, 1.00, 1.00] blue = [0.00, 0.00, 0.00, 0.00, 1.00] elif name == 'inv_darkbody': stops = [0.00, 0.25, 0.50, 0.75, 1.00] red = [1.00, 1.00, 1.00, 0.50, 0.00] green = [1.00, 1.00, 0.55, 0.00, 0.00] blue = [1.00, 0.00, 0.00, 0.00, 0.00] elif name == 'deepsea': stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [0.00, 0.09, 0.18, 0.09, 0.00] green = [0.01, 0.02, 0.39, 0.68, 0.97] blue = [0.17, 0.39, 0.62, 0.79, 0.97] elif name == 'forest': stops = [0.00, 0.25, 0.50, 0.75, 1.00] red = [0.93, 0.70, 0.40, 0.17, 0.00] green = [0.97, 0.89, 0.76, 0.64, 0.43] blue = [0.98, 0.89, 0.64, 0.37, 0.17] else: # default palette, looks cool 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] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours)
def kBird(): """Create the kBird color scheme.""" red = array('d', [ 0.2082, 0.0592, 0.0780, 0.0232, 0.1802, 0.5301, 0.8186, 0.9956, 0.9764 ]) grn = array('d', [ 0.1664, 0.3599, 0.5041, 0.6419, 0.7178, 0.7492, 0.7328, 0.7862, 0.9832 ]) blu = array('d', [ 0.5293, 0.8684, 0.8385, 0.7914, 0.6425, 0.4662, 0.3499, 0.1968, 0.0539 ]) stp = array('d', [0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0]) return TColor.CreateGradientColorTable(9, stp, red, grn, blu, 255)
def set_palette(): """ Set a color palette from a given RGB list. stops, red, green and blue should all be lists of the same length. """ stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [0.00, 0.00, 0.87, 1.00, 0.71] green = [0.10, 0.81, 1.00, 0.20, 0.10] blue = [0.61, 1.00, 0.12, 0.00, 0.00] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, 100) gStyle.SetNumberContours(100)
def set_palette(ncontours=999): """Set a color palette from a given RGB list stops, red, green and blue should all be lists of the same length see set_decent_colors for an example""" 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] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours) pass
def set_palette(name="default", ncontours=999, id=1 ): """Set a color palette from a given RGB list stops, red, green and blue should all be lists of the same length see set_decent_colors for an example""" if name == "gray" or name == "grayscale": # simple grayscale _palette[ name ] = id stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [1.00, 0.84, 0.61, 0.34, 0.00] green = [1.00, 0.84, 0.61, 0.34, 0.00] blue = [1.00, 0.84, 0.61, 0.34, 0.00] elif name == "diffs": # grayscale in abs(z) _palette[ name ] = id stops = [0.00, 0.08, 0.195,0.33, 0.50-0.0001,0.500, 0.500+0.0001, 0.670,0.805,0.920,1.000] red = [0.00/1.5, 0.34/1.5, 0.61/1.5, 0.84/1.5, 1.00, 1.000, 1.00, 0.84/1.5, 0.61/1.5, 0.34/1.5, 0.00] # green = [0.00/1.5, 0.34/1.5, 0.61/1.5, 0.84/1.5, 1.00, 1.000, 1.00, 0.84/1.5, 0.61/1.5, 0.34/1.5, 0.00] green = [0.00/1.5, 0.00/1.5, 0.00/1.5, 0.00/1.5, 1.00, 1.000, 1.00, 0.00/1.5, 0.00/1.5, 0.00/1.5, 0.00] # blue = [0.00/1.5, 0.34/1.5, 0.61/1.5, 0.84/1.5, 0.60, 0.600, 0.60, 0.84/1.5, 0.61/1.5, 0.34/1.5, 0.00] blue = [0.00/1.5, 0.00/1.5, 0.00/1.5, 0.00/1.5, 0.60, 0.600, 0.60, 0.00/1.5, 0.00/1.5, 0.00/1.5, 0.00] elif name == "bool": # simple 1 or 0 _palette[ name ] = id stops = [0.00,0.000001,1.00000] red = [0.00, 1.0,1.0] green = red blue = red else: # default smooth color gradient _palette[ name ] = id 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] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours)
def createColorSpectrum(): from ROOT import TColor from numpy import array granularity = 255 palette = [] #~ _stops = {"red":(0.00, 0.00, 0.87, 1.00, 0.51,1.),"green":(,0.5),"blue":(0,0,255,0.0)} stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [0.00, 0.09, 0.18, 0.09, 0.00] green = [0.01, 0.02, 0.39, 0.68, 0.97] blue = [0.17, 0.39, 0.62, 0.79, 0.97] #~ Double_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; #~ Double_t red[nRGBs] = { 0.00, 0.09, 0.18, 0.09, 0.00 }; #~ Double_t green[nRGBs] = { 0.01, 0.02, 0.39, 0.68, 0.97 }; #~ Double_t blue[nRGBs] = { 0.17, 0.39, 0.62, 0.79, 0.97 }; #~ 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] minStop = 0. maxStop = 1. #~ for name in sorted(_stops.keys(), key=lambda x: _stops[x][3]): #~ r, g, b, l = _stops[name] #~ red.append(r * 1. / 255.) #~ green.append(g * 1. / 255.) #~ blue.append(b * 1. / 255.) #~ stops.append((l - minStop) * 1. / maxStop) #~ legendColors[name] = TColor.GetColor(red[-1], green[-1], blue[-1]) print stops, red, green, blue ROOT.gStyle.SetNumberContours(granularity) baseColor = TColor.CreateGradientColorTable(len(stops), array(stops, "d"), array(red, "d"), array(green, "d"), array(blue, "d"), granularity) invertedPalette = [] for i in range(0, granularity): palette.append(baseColor + i) for i in range(1, granularity): invertedPalette.append(palette[-i]) invertedPalette.append(palette[0]) print invertedPalette ROOT.gStyle.SetPalette(granularity, array(invertedPalette, "i"))
def set_palette(name='', ncontours=999): if name == 'gray' or name == 'grayscale': stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [1.00, 0.84, 0.61, 0.34, 0.00] green = [1.00, 0.84, 0.61, 0.34, 0.00] blue = [1.00, 0.84, 0.61, 0.34, 0.00] else: # default palette, looks cool 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] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours)
def acustompalette(): NRGBs = 7 NCont = 100 ncolors = array('i', []) gStyle.SetNumberContours(NCont); stops = [ 0.00, 0.10, 0.25, 0.45, 0.60, 0.75, 1.00 ] red = [ 1.00, 0.00, 0.00, 0.00, 0.97, 0.97, 0.10 ] green = [ 1.00, 0.97, 0.30, 0.40, 0.97, 0.00, 0.00 ] blue = [ 1.00, 0.97, 0.97, 0.00, 0.00, 0.00, 0.00 ] stopsArray = array('d', stops) redArray = array('d', red) greenArray = array('d', green) blueArray = array('d', blue) first_color_number = TColor.CreateGradientColorTable(NRGBs, stopsArray, redArray, greenArray, blueArray, NCont); gStyle.SetNumberContours(NCont) palsize = NCont palette = [] for i in range(palsize): palette.append(first_color_number+i) palarray = array('i',palette) gStyle.SetPalette(palsize,palarray)
def set_fancy_2D_style(): icol = 0 gStyle.SetFrameBorderMode(icol) gStyle.SetFrameFillColor(icol) gStyle.SetCanvasBorderMode(icol) gStyle.SetCanvasColor(icol) gStyle.SetPadBorderMode(icol) gStyle.SetPadColor(icol) gStyle.SetStatColor(icol) gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetOptFit(0) ncontours = 999 s = array('d', [0.00, 0.34, 0.61, 0.84, 1.00]) r = array('d', [0.00, 0.00, 0.87, 1.00, 0.51]) g = array('d', [0.00, 0.81, 1.00, 0.20, 0.00]) b = array('d', [0.51, 1.00, 0.12, 0.00, 0.00]) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours)
def setStyle(): TColor.InitializeColors() stops = array('d', [ 0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000 ]) red = array('d', [ 0.9764, 0.9956, 0.8186, 0.5301, 0.1802, 0.0232, 0.0780, 0.0592, 0.2082 ]) green = array('d', [ 0.9832, 0.7862, 0.7328, 0.7492, 0.7178, 0.6419, 0.5041, 0.3599, 0.1664 ]) blue = array('d', [ 0.0539, 0.1968, 0.3499, 0.4662, 0.6425, 0.7914, 0.8385, 0.8684, 0.5293 ]) TColor.CreateGradientColorTable(9, stops, red, green, blue, 255, 1.0) gStyle.SetHatchesLineWidth(1) gStyle.SetNumberContours(255) gStyle.SetNdivisions(505, "xyz") gStyle.SetTitleBorderSize(0) gStyle.SetTitleColor(1) gStyle.SetTitleStyle(3013) gStyle.SetTitleFillColor(0) gStyle.SetTitleX(0.05) gStyle.SetTitleW(0.4) gStyle.SetTitleY(0.965) gStyle.SetTitleH(0.065) gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasBorderSize(3) gStyle.SetCanvasColor(0) gStyle.SetPadColor(0) gStyle.SetPadBorderMode(0) gStyle.SetFuncWidth(3) gStyle.SetPadGridY(False) gStyle.SetPadGridX(False) gStyle.SetFrameLineWidth(1) gStyle.SetMarkerSize(5) gStyle.SetPadTickX(True) gStyle.SetPadTickY(True) #gStyle.SetPalette(1) gStyle.SetHistLineWidth(3) gStyle.SetHistLineColor(1) gStyle.SetOptStat(0) gStyle.SetOptFit(0) gStyle.SetStatW(0.25) gStyle.SetStatH(0.25) gStyle.SetStatX(0.9) gStyle.SetStatY(0.9) gStyle.SetStatColor(0) gStyle.SetStatFormat("6.4g") gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.05) gStyle.SetPadBottomMargin(0.16) gStyle.SetPadLeftMargin(0.12) font = 42 gStyle.SetTextSize(.055) gStyle.SetTextFont(font) gStyle.SetLabelFont(font, "x") gStyle.SetTitleFont(font, "x") gStyle.SetLabelFont(font, "y") gStyle.SetTitleFont(font, "y") gStyle.SetLabelFont(font, "z") gStyle.SetTitleFont(font, "z") gStyle.SetTitleSize(.055, "x") gStyle.SetTitleSize(.055, "y") gStyle.SetTitleSize(.05, "z") gStyle.SetLabelSize(.05, "x") gStyle.SetLabelSize(.05, "y") gStyle.SetLabelSize(.05, "z") gStyle.SetLabelOffset(0.014, "x") gStyle.SetLabelOffset(0.006, "y") gStyle.SetLabelOffset(0.008, "z") gStyle.SetTitleOffset(1, "y") gStyle.SetTitleXOffset(1.2) # use bold lines and markers gStyle.SetMarkerStyle(20) gStyle.SetMarkerColor(1) gStyle.SetMarkerSize(1.2) gStyle.SetLineStyleString(2, "[12 12]") # postscript dashes gStyle.SetPadTickX(1) gStyle.SetPadTickY(1)
# ------------------------------------------------------------------------------------- # plot response matrices # (do this in the end as the normalization otherwise will mess up the unfolding result!) # ------------------------------------------------------------------------------------- ncontours = 256 stops = [0.00, 1.00] red = [0.99, 0.32] green = [0.99, 0.42] blue = [0.99, 0.9] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours) # ------------------------------------------------------------------------------------- # one-step unfolding # ------------------------------------------------------------------------------------- gStyle.SetPadRightMargin(0.12) cr = TCanvas("c_response", "", 800, 600) hEmpty2D = response.Hresponse().Clone() hEmpty2D.SetName("empty2D") hEmpty2D.Reset() hEmpty2D.GetXaxis().SetTitle("Reconstructed top jet p_{T} (GeV)") hEmpty2D.GetYaxis().SetTitle("Top quark p_{T} (GeV)") hEmpty2D.GetXaxis().SetLabelSize(0.045)
# CMS style CMS_lumi.cmsText = "CMS" CMS_lumi.extraText = "Preliminary" CMS_lumi.cmsTextSize = 0.80 CMS_lumi.lumiTextSize = 0.75 CMS_lumi.relPosX = 0.12 CMS_lumi.outOfFrame = True tdrstyle.setTDRStyle() # COLOR palette, see core/base/src/TColor.cxx red = array('d',[ 0.80, 0.90, 1.00, 0.60, 0.02, ]) green = array('d',[ 0.20, 0.80, 1.00, 0.80, 0.20, ]) blue = array('d',[ 0.10, 0.60, 1.00, 0.90, 0.65, ]) stops = array('d',[i/(len(red)-1.) for i in xrange(0,len(red))]) FI = TColor.CreateGradientColorTable(len(red), stops, red, green, blue, 100) kMyTemperature = array('i',[ FI+i for i in xrange(100)]) gStyle.SetPalette(100,kMyTemperature) DIR = "./output" PLOTS_DIR = "./postfit" DM_label = { 'DM0': "h^{#pm} decay mode", 'DM1': "h^{#pm}#pi^{0} decay mode", 'DM10': "h^{#pm}h^{#mp}h^{#pm} decay mode", 'DM11': "h^{#pm}h^{#mp}h^{#pm}#pi^{0} decay mode", 'all': "all old decay modes", 'combined': "combined", } bin_dict = { 1: 'DM0', 2: 'DM1', 3: 'DM10', 4: 'all', } varlabel = { 'm_2': "m_{#tau}", 'm_vis': "m_{vis}",
scale = 100 / TH_template_correct.Integral() TH_template_correct.Scale(scale) scale = 100 / TH_template_confused.Integral() TH_template_confused.Scale(scale) scale = 100 / TH_template_electron.Integral() TH_template_electron.Scale(scale) TH_template_correct.Write() TH_template_confused.Write() TH_template_electron.Write() TH_data_negative.Write() TH_data_positive.Write() gStyle.SetPalette(56) ''' Red = ( 1.00, 0.00, 0.00) Green = ( 0.00, 1.00, 0.00) Blue = ( 1.00, 0.00, 1.00) Length = ( 0.00, 0.50, 1.00 ) TColor.CreateGradientColorTable(3, Length, Red, Green, Blue, 50) ''' c1 = TCanvas() gPad.SetGrid() gPad.SetFrameFillColor(0) TH_template_correct.Draw('COLZ') TH_template_correct.SetStats(0) TH_template_correct.GetXaxis().SetTitle("#bf{Charge Confusion Estimator}") TH_template_correct.GetYaxis().SetTitle("#bf{TrdLikelihood}") c1.Update() c1.SaveAs("correct.pdf")
def make2DLimitPlot(xtitle, xvals, yvals, obs, exp, exp1plus, exp1minus, exp2plus, exp2minus, theory, **kwargs): use_ctau = kwargs.pop('use_ctau', False) do_interpolation = kwargs.pop('do_interpolation', True) debug = kwargs.pop('debug', True) mass_splitting = kwargs.pop('mass_splitting', '0.1') gStyle.SetOptTitle(0) gStyle.SetOptStat(0) axisTitleSize = 0.041 axisTitleOffset = 1.2 leftMargin = 0.15 rightMargin = 0.18 topMargin = 0.06 bottomMargin = 0.14 c1 = TCanvas("c1", "c1", 200, 10, 700, 600) c1.SetHighLightColor(2) c1.SetFillColor(0) c1.SetBorderMode(0) c1.SetBorderSize(2) c1.SetLeftMargin(leftMargin) c1.SetRightMargin(rightMargin) c1.SetTopMargin(topMargin) c1.SetBottomMargin(bottomMargin) c1.SetFrameBorderMode(0) c1.SetLogy(1) c1.SetLogx(1) c1.SetLogz(1) c1.SetTickx(1) c1.SetTicky(1) stops = np.array([0.00, 0.34, 0.61, 0.84, 1.00]) red = np.array([0.50, 0.50, 1.00, 1.00, 1.00]) green = np.array([0.50, 1.00, 1.00, 0.60, 0.50]) blue = np.array([1.00, 1.00, 0.50, 0.40, 0.50]) TColor.CreateGradientColorTable(len(stops), stops, red, green, blue, 255) gStyle.SetNumberContours(255) if debug: print "list of m1s:", xvals print "list of ys: ", yvals print "list of obs limits: ", obs if do_interpolation: data = interpolateObsLimit(xvals, yvals, obs, debug=debug, mass_splitting=mass_splitting) else: data = np.array([xvals, yvals, obs]) widthx = sorted(data[0])[0] / 10 widthy = sorted(data[1])[0] / 10 lowXs = [xval - widthx / 2 for xval in data[0]] highXs = [xval + widthx / 2 for xval in data[0]] lowYs = [yval - widthy / 2 for yval in data[1]] highYs = [yval + widthy / 2 for yval in data[1]] binsX = sorted(list(dict.fromkeys(lowXs + highXs))) binsY = sorted(list(dict.fromkeys(lowYs + highYs))) binsX = [(binsX[i] + binsX[i + 1]) / 2 if i != len(binsX) - 1 else binsX[i] for i in range(1, len(binsX) - 1, 2)] binsY = [(binsY[i] + binsY[i + 1]) / 2 if i != len(binsY) - 1 else binsY[i] for i in range(1, len(binsY) - 1, 2)] binsX.insert(0, sorted(lowXs)[0]) binsX.insert(len(binsX), sorted(highXs)[-1]) binsY.insert(0, sorted(lowYs)[0]) binsY.insert(len(binsY), sorted(highYs)[-1]) if debug: print "binsX ", binsX print "binsY ", binsY obs_xsec = TH2D('', '', len(binsX) - 1, array('d', binsX), len(binsY) - 1, array('d', binsY)) obs_xsec.GetXaxis().SetTitleSize(axisTitleSize) obs_xsec.GetXaxis().SetTitleOffset(axisTitleOffset - 0.3) obs_xsec.GetXaxis().SetTitle("m_{1} [GeV]") obs_xsec.GetXaxis().SetMoreLogLabels() obs_xsec.GetYaxis().SetTitleSize(axisTitleSize) obs_xsec.GetYaxis().SetTitleOffset(axisTitleOffset + 0.1) if use_ctau: obs_xsec.GetYaxis().SetTitle("c#tau [cm]") else: obs_xsec.GetYaxis().SetTitle( "y = #epsilon^{2} #alpha_{D} (m_{1}/m_{A'})^{4}") obs_xsec.GetZaxis().SetTitleSize(axisTitleSize - 0.005) obs_xsec.GetZaxis().SetTitleOffset(axisTitleOffset + 0.1) obs_xsec.GetZaxis().SetTitle( "#sigma_{95% CL} Br(A' #rightarrow #mu#mu) [pb]") obs_xsec.FillN(len(data[0]), array('d', data[0]), array('d', data[1]), array('d', data[2])) obs_xsec.GetZaxis().SetRangeUser(1e-4, 1e2) if do_interpolation: obs_xsec.Draw("COLZ") else: obs_xsec.Draw("COLZ TEXT") obs_mu = [x / y for x, y in zip(obs, theory)] plotLimitBoundary(c1, xvals, yvals, obs_mu, [1, kBlack], debug=debug, mass_splitting=mass_splitting) exp_mu = [x / y for x, y in zip(exp, theory)] plotLimitBoundary(c1, xvals, yvals, exp_mu, [2, kRed], debug=debug, mass_splitting=mass_splitting) CMS_lumi(c1, "137.2 fb^{-1} (13 TeV)", 0) c1.RedrawAxis() c1.Draw() wait(True)
cexp = GetContoursSmooth(gexp, 2, 1) cup = GetContoursSmooth(gup, 2, 2) cdown = GetContoursSmooth(gdown, 2, 2) cobs = GetContoursSmooth(gobs, 1, 1) cobsup = GetContoursSmooth(gobsup, 1, 2) cobsdown = GetContoursSmooth(gobsdown, 1, 2) #stops = [] ; red = [] ; green = [] ; blue = [] NRGBs = 5 NCont = 255 stops = array('d', [0.00, 0.34, 0.61, 0.84, 1.00]) red = array('d', [0.50, 0.50, 1.00, 1.00, 1.00]) green = array('d', [0.50, 1.00, 1.00, 0.60, 0.50]) blue = array('d', [1.00, 1.00, 0.50, 0.40, 0.50]) TColor.CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont) gStyle.SetNumberContours(NCont) gStyle.SetOptStat(0) hlim = glim.GetHistogram() hlim.SetAxisRange(0.0001, 1.3, "Z") hlim.SetTitle(";m_{gluino} [GeV];m_{LSP} [GeV]") hlim.Draw("colz") cexp.Draw("same") cup.Draw("same") cdown.Draw("same") cobs.Draw("same") cobsup.Draw("same") cobsdown.Draw("same") flimit = TFile(pattern + "/limit_scan.root", "recreate")
# text color #hcorr.SetMarkerColor(0) # setup color palette r = [0.0, 1.0, 1.0] g = [0.3, 1.0, 0.0] b = [1.0, 1.0, 0.0] stop = [.0, 0.5, 1.0] # convert to c arrays rarray = array('d',r) garray = array('d',g) barray = array('d',b) stoparray = array('d',stop) palsize = 100 fi = TColor.CreateGradientColorTable(3, stoparray, rarray, garray, barray, palsize) palette = [] for i in range(palsize): palette.append(fi+i) palarray = array('i',palette) gStyle.SetPalette(palsize,palarray) gStyle.SetOptStat(0) hcorr.Draw("COLZ TEXT") canvas.Print("plots/corr.png") canvas.Print("plots/corr.pdf") fcov.Close()
def setTDRStyle(logy): global tdrStyle #ro.gROOT.Macro( "setTDRStyle.C") # For the canvas: tdrStyle.SetCanvasBorderMode(0); tdrStyle.SetCanvasColor(ro.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(ro.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(2); # tdrStyle.SetLegoInnerR(Float_t rad = 0.5); # tdrStyle.SetNumberContours(Int_t number = 20); tdrStyle.SetEndErrorSize(2); # tdrStyle.SetErrorMarker(20); #tdrStyle.SetErrorX(0.); #tdrStyle.SetMarkerStyle(20); #For the fit/function: tdrStyle.SetOptFit(0); 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("emr"); # To display the mean and RMS: SetOptStat("mr"); tdrStyle.SetStatColor(ro.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.05); # For the Global title: tdrStyle.SetOptTitle(0); 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.03, "XYZ"); tdrStyle.SetLabelSize(0.05, "XYZ"); # For the axis: tdrStyle.SetAxisColor(1, "XYZ"); tdrStyle.SetStripDecimals(ro.kTRUE); tdrStyle.SetTickLength(0.03, "XYZ"); tdrStyle.SetNdivisions(510, "XYZ"); tdrStyle.SetPadTickX(1); # To get tick marks on the opposite side of the frame tdrStyle.SetPadTickY(1); # For the Legend: tdrStyle.SetLegendFont(42) tdrStyle.SetLegendFillColor(ro.kWhite) tdrStyle.SetLegendBorderSize(0) # Change for log plots: tdrStyle.SetOptLogx(0); tdrStyle.SetOptLogy(logy); tdrStyle.SetOptLogz(0); # Postscript options: tdrStyle.SetPaperSize(20.,20.); tdrStyle.SetPalette(1); #tdrStyle.SetHatchesLineWidth(5); #tdrStyle.SetHatchesSpacing(0.05); 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 ] TColor.CreateGradientColorTable(NRGBs, array("d",stops), array("d", red), array("d",green ), array("d", blue), NCont); #TColor.CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); #TColor.CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont); tdrStyle.SetNumberContours(NCont); #gROOT.ForceStyle(); tdrStyle.cd();
#gSystem = TSystem.gSystem #gStyle = TROOT.gStyle #gROOT = TROOT.gROOT gROOT.SetStyle("Plain") nColors = 51 s = [0.00, 0.25, 0.50, 0.75, 1.00] r = [0.99, 0.00, 0.87, 1.00, 0.70] g = [0.99, 0.81, 1.00, 0.20, 0.00] b = [0.99, 1.00, 0.12, 0.00, 0.00] ss = array('d', s) rr = array('d', r) gg = array('d', g) bb = array('d', b) TColor.CreateGradientColorTable(len(ss), ss, rr, gg, bb, nColors) gStyle.SetNumberContours(nColors) def exists(file): x = FileStat_t() return (not gSystem.GetPathInfo("%s" % (file), x)) def getData(runNumber, fstep, lstep, tsteps, islocal=False): print "Retrieving data..." if islocal: print "Searching in local cluster" else: print "Searching on CASTOR"
##draw only this analysis, with color map ##2D color map myC2D.SetLogz(1) #stops = np.array([0.0, 1.0]) #red = np.array([0.0, 0.8]) #green = np.array([0.3, 1.0]) #blue = np.array([0.5, 1.0]) stops = np.array([0.00, 0.34, 0.61, 0.84, 1.00]) red = np.array([0.50, 0.50, 1.00, 1.00, 1.00]) green = np.array([0.50, 1.00, 1.00, 0.60, 0.50]) blue = np.array([1.00, 1.00, 0.50, 0.40, 0.50]) TColor.CreateGradientColorTable(len(stops), stops, red, green, blue, 255) #gStyle.SetPalette(70) gStyle.SetNumberContours(255) #gStyle.InvertPalette() xbins_th2 = [] ybins_th2 = [] xbins_th2.append(100.0) for idx in range(len(lambda_points) - 1): xbins_th2.append(0.5 * (lambda_points[idx] + lambda_points[idx + 1]) * 1.454 - 6.0) xbins_th2.append(600.0) ybins_th2.append(9.0) for idx in range(len(ctau_points) - 1): ybins_th2.append(0.5 * (ctau_points[idx] + ctau_points[idx + 1])) ybins_th2.append(1.2e4)
class Calorimeter: '''class for calorimeter plotting''' #class members name = 'n' #ClassVar[TString] range_min = 0 #ClassVar[float] range_max = 0 #ClassVar[float] content = [] #ClassVar[list[float]] #of float ombox = [] #ClassVar[list[TBox]] #of TBox omtext = [] #ClassVar[list[TText]] #of TText source_foil = TLine() #ClassVar[TLine] it_label = '' #ClassVar[TText] fr_label = '' #ClassVar[TText] canvas = None #ClassVar[TCanvas] palette_index = 0 #ClassVar[int] fiber_map_lines = np.array([TLine]) ncalo = 712 #ClassVar[int] nmwall = 520 nxwall = 128 ngveto = 64 #constructor of calorimeter for calo in range(ncalo): content.append(0) range_min = range_max = -1 spacerx = 0.0125 spacery = 0.0250 mw_sizey = (1 - 4 * spacery) / (13 + 2) gv_sizey = mw_sizey xw_sizey = mw_sizey * 13. / 16. mw_sizex = (0.5 - 4 * spacerx) / (20 + 4) gv_sizex = mw_sizex * 20. / 16. xw_sizex = mw_sizex for mw0 in range(2): for mw1 in range(20): for mw2 in range(13): id = mw0 * 20 * 13 + mw1 * 13 + mw2 x1 = spacerx + 2 * xw_sizex + spacerx + 0.5 * mw0 + mw_sizex * ( mw1) if (mw0 == 1): #swap french in case of internal view x1 = spacerx + 2 * xw_sizex + spacerx + 0.5 * mw0 + mw_sizex * ( 19 - mw1) y1 = spacery + gv_sizey + spacery + mw_sizey * mw2 x2 = x1 + mw_sizex y2 = y1 + mw_sizey box = TBox(x1, y1, x2, y2) box.SetFillColor(0) box.SetLineWidth(1) ombox.append(box) text = TText( x1 + 0.33 * mw_sizex, y1 + 0.33 * mw_sizey, str(id).zfill(3) ) # "{:10.4f}".format(xid))#, TString::Form("%03d",id)) text.SetTextSize(0.02) omtext.append(text) for xw0 in range(2): for xw1 in range(2): for xw2 in range(2): for xw3 in range(16): id = 520 + xw0 * 2 * 2 * 16 + xw1 * 2 * 16 + xw2 * 16 + xw3 # x1 = 0 if xw0 == 0: if xw1 == 0: x1 = spacerx + xw_sizex * xw2 elif xw1 == 1: x1 = spacerx + 2 * xw_sizex + spacerx + 20 * mw_sizex + spacerx + ( 1 - xw2) * xw_sizex elif xw0 == 1: #wall ID if xw1 == 0: #side ID x1 = 0.5 + spacerx + 2 * xw_sizex + spacerx + 20 * mw_sizex + spacerx + ( 1 - xw2) * xw_sizex elif xw1 == 1: x1 = 0.5 + spacerx + xw_sizex * xw2 x2 = x1 + xw_sizex y1 = spacery + gv_sizey + spacery + xw_sizey * (xw3) y2 = spacery + gv_sizey + spacery + xw_sizey * (xw3 + 1) box = TBox(x1, y1, x2, y2) box.SetFillColor(0) box.SetLineWidth(1) ombox.append(box) text = TText(x1 + 0.33 * mw_sizex, y1 + 0.33 * mw_sizey, str(id).zfill(3)) text.SetTextSize(0.02) omtext.append(text) for gv0 in range(2): for gv1 in range(2): for gv2 in range(16): id = 520 + 128 + gv0 * 2 * 16 + gv1 * 16 + gv2 # x1 = 0 if gv0 == 0: #side ID 1 x1 = spacerx + 2 * xw_sizex + spacerx + gv_sizex * gv2 elif gv0 == 1: #wall ID 0 x1 = 0.5 + spacerx + 2 * xw_sizex + spacerx + gv_sizex * ( 16 - 1 - gv2) x2 = x1 + gv_sizex y1 = spacery + gv1 * (gv_sizey + spacery + 13 * mw_sizey + spacery) y2 = y1 + gv_sizey box = TBox(x1, y1, x2, y2) box.SetFillColor(0) box.SetLineWidth(1) ombox.append(box) text = TText(x1 + 0.33 * gv_sizex, y1 + 0.33 * gv_sizey, str(id).zfill(3)) text.SetTextSize(0.02) omtext.append(text) source_foil = TLine(0.5, spacery, 0.5, 1 - spacery) source_foil.SetLineWidth(2) it_label = TText( spacerx, spacery + gv_sizey + spacery + 13 * mw_sizey + spacery + 0.25 * gv_sizey, "ITALY") fr_label = TText( 0.5 + spacerx, spacery + gv_sizey + spacery + 13 * mw_sizey + spacery + 0.25 * gv_sizey, "FRANCE") it_label.SetTextSize(0.036) fr_label.SetTextSize(0.036) #fiber map line_h_IT = TLine(0.25 - 10 * mw_sizex, 2 * spacery + 9 * mw_sizey, 0.25 + 10 * mw_sizex, 2 * spacery + 9 * mw_sizey) line_v_A1A2_IT = TLine(0.25, 2 * spacery + 9 * mw_sizey, 0.25, 2 * spacery + 14 * mw_sizey) line_v_A3A4_IT = TLine(0.25 - 4 * mw_sizex, 2 * 0.025 + mw_sizey, 0.25 - 4 * mw_sizex, 2 * spacery + 9 * mw_sizey) line_v_A4A5_IT = TLine(0.25 + 4 * mw_sizex, 2 * 0.025 + mw_sizey, 0.25 + 4 * mw_sizex, 2 * spacery + 9 * mw_sizey) line_h_FR = TLine(0.75 - 10 * mw_sizex, 2 * spacery + 9 * mw_sizey, 0.75 + 10 * mw_sizex, 2 * spacery + 9 * mw_sizey) line_v_A1A2_FR = TLine(0.75, 2 * 0.025 + 9 * mw_sizey, 0.75, 2 * spacery + 14 * mw_sizey) line_v_A3A4_FR = TLine(0.75 - 4 * mw_sizex, 2 * spacery + mw_sizey, 0.75 - 4 * mw_sizex, 2 * spacery + 9 * mw_sizey) line_v_A4A5_FR = TLine(0.75 + 4 * mw_sizex, 2 * spacery + mw_sizey, 0.75 + 4 * mw_sizex, 2 * spacery + 9 * mw_sizey) line_veto_top_IT = TLine(0.25, 3 * spacery + 14 * mw_sizey, 0.25, 3 * spacery + 15 * mw_sizey) line_veto_bottom_left_IT = TLine(0.25 - 4 * gv_sizex, spacery, 0.25 - 4 * gv_sizex, spacery + mw_sizey) line_veto_bottom_right_IT = TLine(0.25 + 4 * gv_sizex, spacery, 0.25 + 4 * gv_sizex, spacery + mw_sizey) line_veto_top_FR = TLine(0.75, 3 * spacery + 14 * mw_sizey, 0.75, 3 * spacery + 15 * mw_sizey) line_veto_bottom_left_FR = TLine(0.75 - 4 * gv_sizex, spacery, 0.75 - 4 * gv_sizex, spacery + mw_sizey) line_veto_bottom_right_FR = TLine(0.75 + 4 * gv_sizex, spacery, 0.75 + 4 * gv_sizex, spacery + mw_sizey) line_xw_left_IT = TLine(spacerx, 0.5 + 2 * xw_sizey, spacerx + 2 * xw_sizex, 0.5 + 2 * xw_sizey) line_xw_right_IT = TLine(0.5 - spacerx - 2 * xw_sizex, 0.5 + 2 * xw_sizey, 0.5 - spacerx, 0.5 + 2 * xw_sizey) line_xw_left_FR = TLine(0.5 + spacerx, 0.5 + 2 * xw_sizey, 0.5 + spacerx + 2 * xw_sizex, 0.5 + 2 * xw_sizey) line_xw_right_FR = TLine(1 - spacerx - 2 * xw_sizex, 0.5 + 2 * xw_sizey, 1 - spacerx, 0.5 + 2 * xw_sizey) fiber_map_lines = np.array([line_h_IT, line_v_A1A2_IT, line_v_A3A4_IT, line_v_A4A5_IT, \ line_h_FR, line_v_A1A2_FR, line_v_A3A4_FR, line_v_A4A5_FR, \ line_veto_top_IT, line_veto_bottom_left_IT, line_veto_bottom_right_IT, \ line_veto_top_FR, line_veto_bottom_left_FR, line_veto_bottom_right_FR, \ line_xw_right_IT, line_xw_left_IT, \ line_xw_right_FR, line_xw_left_FR]) nRGBs = 6 stops = np.array([0.00, 0.20, 0.40, 0.60, 0.80, 1.00]) red = np.array([0.25, 0.00, 0.20, 1.00, 1.00, 0.90]) green = np.array([0.25, 0.80, 1.00, 1.00, 0.80, 0.00]) blue = np.array([1.00, 1.00, 0.20, 0.00, 0.00, 0.00]) palette_index = TColor.CreateGradientColorTable(nRGBs, stops, red, green, blue, 100) def setrange(self, xmin, xmax): self.range_min = xmin self.range_max = xmax return 0 def draw(self, fiber_map=False): if (self.canvas == None): self.canvas = TCanvas(self.name, "SuperNEMO calorimeter", 1750, 500) self.canvas.SetEditable(True) self.canvas.cd() for mw0 in range(2): for mw1 in range(20): for mw2 in range(13): id = mw0 * 20 * 13 + mw1 * 13 + mw2 self.ombox[id].Draw("l") self.omtext[id].Draw() for xw0 in range(2): for xw1 in range(2): for xw2 in range(2): for xw3 in range(16): id = 520 + xw0 * 2 * 2 * 16 + xw1 * 2 * 16 + xw2 * 16 + xw3 self.ombox[id].Draw("l") self.omtext[id].Draw() for gv0 in range(2): for gv1 in range(2): for gv2 in range(16): id = 520 + 128 + gv0 * 2 * 16 + gv1 * 16 + gv2 self.ombox[id].Draw("l") self.omtext[id].Draw() self.source_foil.Draw() self.it_label.Draw() self.fr_label.Draw() if fiber_map == True: for line in self.fiber_map_lines: line.SetLineColor(kBlack) line.SetLineStyle(9) line.SetLineWidth(3) line.Draw() self.canvas.SetEditable(False) gSystem.ProcessEvents() return 0 def reset(self): for calo in range(self.ncalo): self.content[calo] = 0 # for calo=0; calo<self.ncalo; ++calo) self.ombox[calo].SetFillColor(0) self.canvas.Modified() self.canvas.Update() gSystem.ProcessEvents() return 0 def setcontent(self, pmt, value): self.content[pmt] = value return 0 def update(self): content_min = self.content[0] content_max = self.content[0] if (self.range_min == -1): for calo in range(1, self.ncalo): if (self.content[calo] < content_min): content_min = self.content[calo] if (self.content[calo] > content_max): content_max = self.content[calo] else: self.range_min = 0 content_max = self.range_max for calo in range(self.ncalo): if (self.content[calo] != 0): self.ombox[calo].SetFillColor(self.palette_index + ( int)(99 * (self.content[calo] - content_min) / (content_max - content_min))) else: self.ombox[calo].SetFillColor(0) self.canvas.Modified() self.canvas.Update() gSystem.ProcessEvents() return 0 def save_canvas(self): self.canvas.SaveAs('sncalorimeter.png') return 0
def fSetPalette(name="palette", ncontours=999): from array import array from ROOT import TColor, gStyle """Set a color palette from a given RGB list stops, red, green and blue should all be lists of the same length see set_decent_colors for an example""" if name == "gray" or name == "grayscale": stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [1.00, 0.84, 0.61, 0.34, 0.00] green = [1.00, 0.84, 0.61, 0.34, 0.00] blue = [1.00, 0.84, 0.61, 0.34, 0.00] # elif name == "whatever": # (define more palettes) if name == "DeepSea": ncontours = 32 stops = [0.00, 0.34, 0.61, 0.84, 1.00] red = [0.00, 0.09, 0.18, 0.09, 0.00] green = [0.01, 0.02, 0.39, 0.68, 0.97] blue = [0.17, 0.39, 0.62, 0.79, 0.97] if name == "DarkBodyRadiator": ncontours = 32 stops = [0.00, 0.25, 0.50, 0.75, 1.00] red = [0.00, 0.50, 1.00, 1.00, 1.00] green = [0.00, 0.00, 0.55, 1.00, 1.00] blue = [0.00, 0.00, 0.00, 0.00, 1.00] if name == "BlueYellow": ncontours = 64 stops = [0.00, 0.50, 1.00] red = [0.00, 0.50, 1.00] green = [0.00, 0.50, 1.00] blue = [0.50, 0.50, 0.00] if name == "Green": ncontours = 64 stops = [0.00, 0.50, 1.00] red = [0.00, 0.00, 0.00] green = [0.50, 0.50, 0.50] blue = [0.00, 0.00, 0.00] if name == "Red": ncontours = 64 stops = [0.00, 0.50, 1.00] red = [0.50, 0.50, 0.50] green = [0.00, 0.00, 0.00] blue = [0.00, 0.00, 0.00] if name == "RainBow": ncontours = 64 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] else: # default palette, looks cool 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] s = array('d', stops) r = array('d', red) g = array('d', green) b = array('d', blue) npoints = len(s) TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) # For older ROOT versions #gStyle.CreateGradientColorTable(npoints, s, r, g, b, ncontours) gStyle.SetNumberContours(ncontours)
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)