Beispiel #1
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.SetTitleOffset(1.5, "xy")
    gStyle.SetTitleFont(62, "bla")

    gStyle.SetPadBottomMargin(0.15)
    gStyle.SetPadTopMargin(0.10)
    gStyle.SetPadLeftMargin(0.22)
    gStyle.SetPadRightMargin(0.05)

    gStyle.SetStatX(0.88)
    gStyle.SetStatY(0.87)
    gStyle.SetNdivisions(505)

    gStyle.SetCanvasColor(-1)
    gStyle.SetPadColor(-1)
    gStyle.SetFrameFillColor(-1)
    gStyle.SetTitleFillColor(-1)
    gStyle.SetFillColor(-1)
    gStyle.SetFillStyle(4000)
    gStyle.SetStatStyle(0)
    gStyle.SetTitleStyle(0)
    gStyle.SetCanvasBorderSize(0)
    gStyle.SetFrameBorderSize(0)
    gStyle.SetLegendBorderSize(0)
    gStyle.SetStatBorderSize(0)
    gStyle.SetTitleBorderSize(0)
def create2DPlots(detector, plot, plotnum, plotmat, dosingledetector=True):
    """Produce the requested plot for the specified detector.

       Function that will plot the requested 2D-@plot for the
       specified @detector. The specified detector could either be a
       real detector or a compound one. The list of available plots
       are the keys of plots dictionary imported from plot_utils.
    """

    #gStyle.Reset()
    #Better to use an underscore.
    plotmat = plotmat.replace(" ", "_")

    if plotmat != "":
        theDirname = ('Images/%s' % plotmat).replace(" ", "")
    else:
        theDirname = 'Images'

    if not checkFile_(theDirname):
        os.mkdir(theDirname)
    if not os.path.isdir(('Images/%s/ZPlusZoom' % plotmat).replace(" ", "")):
        os.mkdir(('Images/%s/ZPlusZoom' % plotmat).replace(" ", ""))
    if not os.path.isdir(('Images/%s/ZMinusZoom' % plotmat).replace(" ", "")):
        os.mkdir(('Images/%s/ZMinusZoom' % plotmat).replace(" ", ""))

    goodToGo, theDetectorFilename = paramsGood_(detector, plot)
    if not goodToGo:
        return

    theDetectorFile = TFile(theDetectorFilename)

    prof2d_X0_det_total = TProfile2D()
    prof2d_X0_det_total.Reset()

    # get TProfiles
    #prof2d_X0_det_total = theDetectorFile.Get('%s' % plots[plot].plotNumber)
    prof2d_X0_det_total = theDetectorFile.Get('%s' % plotnum)
    print "=================================================================="
    print plotnum

    # histos
    prof2d_X0_det_total.__class__ = TProfile2D
    hist_X0_total = prof2d_X0_det_total.ProjectionXY()

    # keep files live forever
    files = []
    if detector in COMPOUNDS.keys() and not dosingledetector:
        #When the loop was:
        #for subDetector in COMPOUNDS[detector][1:]:
        #and the detector was single it never went in the loop and read the single file
        #from above. I alter this to COMPOUNDS[detector] to do the multi material budget plot.
        #This won't effect the single detector due to the alter in the if above
        for subDetector in COMPOUNDS[detector]:
            # filenames of single components
            subDetectorFilename = "matbdg_%s.root" % subDetector

            # open file
            if not checkFile_(subDetectorFilename):
                print("Error, missing file %s" % subDetectorFilename)
                continue

            subDetectorFile = TFile(subDetectorFilename)
            files.append(subDetectorFile)
            print("*** Open file... %s" % subDetectorFilename)

            # subdetector profiles
            prof2d_X0_det_total = subDetectorFile.Get('%s' %
                                                      plots[plot].plotNumber)
            prof2d_X0_det_total.__class__ = TProfile2D

            # add to summary histogram
            hist_X0_total.Add(
                prof2d_X0_det_total.ProjectionXY(
                    "B_%s" % prof2d_X0_det_total.GetName()), +1.000)

    # # properties
    #gStyle.SetPalette(1)
    gStyle.SetStripDecimals(False)
    # #

    # Create "null" histo
    minX = 1.03 * prof2d_X0_det_total.GetXaxis().GetXmin()
    maxX = 1.03 * prof2d_X0_det_total.GetXaxis().GetXmax()
    minY = 1.03 * prof2d_X0_det_total.GetYaxis().GetXmin()
    maxY = 1.03 * prof2d_X0_det_total.GetYaxis().GetXmax()

    frame = TH2F("frame", "", 10, minX, maxX, 10, minY, maxY)
    frame.SetMinimum(0.1)
    frame.SetMaximum(10.)
    frame.GetXaxis().SetTickLength(frame.GetXaxis().GetTickLength() * 0.50)
    frame.GetYaxis().SetTickLength(frame.GetXaxis().GetTickLength() / 4.)

    # Ratio
    if plots[plot].iRebin:
        prof2d_X0_det_total.Rebin2D()

    # stack
    hist2dTitle = ('%s %s;%s;%s;%s' %
                   (plots[plot].quotaName, detector, plots[plot].abscissa,
                    plots[plot].ordinate, plots[plot].quotaName))

    if dosingledetector:
        hist2d_X0_total = prof2d_X0_det_total
    else:
        hist2d_X0_total = hist_X0_total
    hist2d_X0_total.SetTitle(hist2dTitle)
    frame.SetTitle(hist2dTitle)
    frame.SetTitleOffset(0.5, "Y")

    #If here you put different histomin,histomaxin plot_utils you won't see anything
    #for the material plots.
    if plots[plot].histoMin != -1.:
        hist2d_X0_total.SetMinimum(plots[plot].histoMin)
    if plots[plot].histoMax != -1.:
        hist2d_X0_total.SetMaximum(plots[plot].histoMax)

    #
    can2name = "MBCan_2D_%s_%s_%s" % (detector, plot, plotmat)
    can2 = TCanvas(can2name, can2name, 2480 + 248, 580 + 58 + 58)
    can2.SetTopMargin(0.1)
    can2.SetBottomMargin(0.1)
    can2.SetLeftMargin(0.04)
    can2.SetRightMargin(0.06)
    can2.SetFillColor(kWhite)
    gStyle.SetOptStat(0)
    gStyle.SetTitleFillColor(0)
    gStyle.SetTitleBorderSize(0)

    #hist2d_X0_total.SetMaximum(hist2d_X0_total.GetMaximum())
    # Color palette
    # gStyle.SetPalette()#1
    acustompalette()
    ex1 = TExec("ex1", "acustompalette();")
    ex1.Draw()

    #for i in range(100): MyPaletteArray.append(i+1)

    #gStyle.SetPalette(first_color_number);

    # Log?
    can2.SetLogz(plots[plot].zLog)

    # Draw in colors
    #frame.Draw()
    #hist2d_X0_total.Draw("COLZsame") #Dummy draw to create the palette object
    hist2d_X0_total.Draw("COLZ")  #Dummy draw to create the palette object

    # Store
    can2.Update()

    #Aesthetic
    palette = hist2d_X0_total.GetListOfFunctions().FindObject("palette")
    if palette:
        palette.__class__ = TPaletteAxis
        palette.SetX1NDC(0.945)
        palette.SetX2NDC(0.96)
        palette.SetY1NDC(0.1)
        palette.SetY2NDC(0.9)
        palette.GetAxis().SetTickSize(.01)
        palette.GetAxis().SetTitle("")
        if plots[plot].zLog:
            palette.GetAxis().SetLabelOffset(-0.01)
    paletteTitle = TLatex(1.12 * maxX, maxY, plots[plot].quotaName)
    paletteTitle.SetTextAngle(90.)
    paletteTitle.SetTextSize(0.05)
    paletteTitle.SetTextAlign(31)
    paletteTitle.Draw()
    hist2d_X0_total.GetYaxis().SetTickLength(
        hist2d_X0_total.GetXaxis().GetTickLength() / 4.)
    hist2d_X0_total.GetYaxis().SetTickLength(
        hist2d_X0_total.GetXaxis().GetTickLength() / 4.)
    hist2d_X0_total.SetTitleOffset(0.5, "Y")
    hist2d_X0_total.GetYaxis().SetTitleOffset(0.45)
    #hist2d_X0_total.GetXaxis().SetTitleOffset(1.15);
    #hist2d_X0_total.GetXaxis().SetNoExponent(True)
    #hist2d_X0_total.GetYaxis().SetNoExponent(True)

    #Add eta labels
    keep_alive = []
    if plots[plot].iDrawEta:
        keep_alive.extend(drawEtaValues())

    can2.Modified()
    hist2d_X0_total.SetContour(255)

    # Store
    can2.Update()
    can2.Modified()

    can2.SaveAs("%s/%s_%s%s.pdf" % (theDirname, detector, plot, plotmat))
    can2.SaveAs("%s/%s_%s%s.png" % (theDirname, detector, plot, plotmat))
    #can2.SaveAs( "%s/%s_%s%s.root" % (theDirname, detector, plot, plotmat))

    #Zoom in a little bit
    if plot == "x_vs_z_vs_Rsum" or plot == "l_vs_z_vs_Rsum" or plot == "x_vs_z_vs_Rsumcos" or plot == "l_vs_z_vs_Rsumcos" or plot == "x_vs_z_vs_Rloc" or plot == "l_vs_z_vs_Rloc" or plot == "x_vs_z_vs_Rloccos" or plot == "l_vs_z_vs_Rloccos":
        #Z+
        #hist2d_X0_total.GetXaxis().SetLimits( 3100., 5200.)
        if dosingledetector:
            hist2d_X0_total.GetXaxis().SetRangeUser(3100., 5400.)
        else:
            hist2d_X0_total.GetXaxis().SetRangeUser(0., 7000.)
        #Do not draw eta values in the zoom case
        keep_alive = []
        #hist2d_X0_total.Draw("COLZ")
        can2.Update()
        can2.Modified()
        can2.SaveAs("%s/%s/%s_%s%s_ZplusZoom.pdf" %
                    (theDirname, "ZPlusZoom", detector, plot, plotmat))
        can2.SaveAs("%s/%s/%s_%s%s_ZplusZoom.png" %
                    (theDirname, "ZPlusZoom", detector, plot, plotmat))
        #Z-
        #hist2d_X0_total.GetXaxis().SetLimits( 3100., 5200.)
        if dosingledetector:
            hist2d_X0_total.GetXaxis().SetRangeUser(-5400., -3100.)
        else:
            hist2d_X0_total.GetXaxis().SetRangeUser(0., -7000.)
        #Do not draw eta values in the zoom case
        keep_alive = []
        #hist2d_X0_total.Draw("COLZ")
        can2.Update()
        can2.Modified()
        can2.SaveAs("%s/%s/%s_%s%s_ZminusZoom.pdf" %
                    (theDirname, "ZMinusZoom", detector, plot, plotmat))
        can2.SaveAs("%s/%s/%s_%s%s_ZminusZoom.png" %
                    (theDirname, "ZMinusZoom", detector, plot, plotmat))

    gStyle.SetStripDecimals(True)
def createPlots2D_(plot, compounddetectorname):
    """2D material budget map to know exactly what we are adding.
    """

    #IBs = ["InnerServices", "Phase2PixelBarrel", "TIB", "TIDF", "TIDB"]
    theDirname = "Figures"

    hist_X0_detectors = OrderedDict()
    if plot not in plots.keys():
        print("Error: chosen plot name not known %s" % plot)
        return

    # We need to keep the file content alive for the lifetime of the
    # full function....
    subDetectorFiles = []

    hist_X0_elements = OrderedDict()
    prof_X0_elements = OrderedDict()

    for subDetector, color in DETECTORS.iteritems():
        subDetectorFilename = "matbdg_%s.root" % subDetector
        if not checkFile_(subDetectorFilename):
            print("Error opening file: %s" % subDetectorFilename)
            continue

        subDetectorFiles.append(TFile(subDetectorFilename))
        subDetectorFile = subDetectorFiles[-1]
        print("Opening file: %s" % subDetectorFilename)
        prof_X0_XXX = subDetectorFile.Get("%d" % plots[plot].plotNumber)

        #hist_X0_detectors[subDetector] = prof_X0_XXX
        hist_X0_detectors[subDetector] = prof_X0_XXX.ProjectionXY("_pxy", "B")
        print subDetector

    # First Plot: BeamPipe + Tracker + ECAL + HCal + HGCal + MB + MGNT

    # Create "null" histo
    minX = 1.03 * hist_X0_detectors["BeamPipe"].GetXaxis().GetXmin()
    maxX = 1.03 * hist_X0_detectors["BeamPipe"].GetXaxis().GetXmax()
    minY = 1.03 * hist_X0_detectors["BeamPipe"].GetYaxis().GetXmin()
    maxY = 1.03 * hist_X0_detectors["BeamPipe"].GetYaxis().GetXmax()

    frame = TH2F("frame", "", 10, minX, maxX, 10, minY, maxY)
    frame.SetMinimum(0.1)
    frame.SetMaximum(10.)
    frame.GetXaxis().SetTickLength(frame.GetXaxis().GetTickLength() * 0.50)
    frame.GetYaxis().SetTickLength(frame.GetXaxis().GetTickLength() / 4.)

    hist2d_X0_total = hist_X0_detectors["BeamPipe"]

    # stack
    hist2dTitle = (
        '%s %s;%s;%s;%s' %
        (plots[plot].quotaName, "All detectors", plots[plot].abscissa,
         plots[plot].ordinate, plots[plot].quotaName))

    hist2d_X0_total.SetTitle(hist2dTitle)
    frame.SetTitle(hist2dTitle)
    frame.SetTitleOffset(0.5, "Y")

    #If here you put different histomin,histomaxin plot_utils you won't see anything
    #for the material plots.
    if plots[plot].histoMin != -1.:
        hist2d_X0_total.SetMinimum(plots[plot].histoMin)
    if plots[plot].histoMax != -1.:
        hist2d_X0_total.SetMaximum(plots[plot].histoMax)

    #
    # canvas
    can_SubDetectors = TCanvas("can_SubDetectors", "can_SubDetectors",
                               2480 + 248, 580 + 58 + 58)
    can_SubDetectors.SetTopMargin(0.1)
    can_SubDetectors.SetBottomMargin(0.1)
    can_SubDetectors.SetLeftMargin(0.04)
    can_SubDetectors.SetRightMargin(0.06)
    can_SubDetectors.SetFillColor(kWhite)
    gStyle.SetOptStat(0)
    gStyle.SetTitleFillColor(0)
    gStyle.SetTitleBorderSize(0)
    gStyle.SetOptTitle(0)

    hist2d_X0_total.GetYaxis().SetTickLength(
        hist2d_X0_total.GetXaxis().GetTickLength() / 4.)
    hist2d_X0_total.GetYaxis().SetTickLength(
        hist2d_X0_total.GetXaxis().GetTickLength() / 4.)
    hist2d_X0_total.SetTitleOffset(0.5, "Y")
    hist2d_X0_total.GetYaxis().SetTitleOffset(0.50)
    #hist2d_X0_total.GetXaxis().SetTitleOffset(1.15);
    #hist2d_X0_total.GetXaxis().SetNoExponent(True)
    #hist2d_X0_total.GetYaxis().SetNoExponent(True)

    # colors
    for det, color in DETECTORS.iteritems():
        hist_X0_detectors[det].SetMarkerColor(color)
        hist_X0_detectors[det].SetFillColor(color)

    for det, histo in hist_X0_detectors.iteritems():
        print det
        histo.Draw("same")

    # Legenda
    theLegend_SubDetectors = TLegend(0.100, 0.7, 0.90,
                                     0.90)  #(0.180,0.8,0.98,0.90)
    theLegend_SubDetectors.SetNColumns(3)
    theLegend_SubDetectors.SetFillColor(0)
    theLegend_SubDetectors.SetFillStyle(0)
    theLegend_SubDetectors.SetBorderSize(0)

    for det, histo in hist_X0_detectors.iteritems():
        theLegend_SubDetectors.AddEntry(histo, det, "f")
    #theLegend_SubDetectors.AddEntry(hgbound1, "HGCal Eta Boundaries [1.3, 3.0]",  "l")

    theLegend_SubDetectors.Draw()

    # text
    text_SubDetectors = TPaveText(0.100, 0.627, 0.322, 0.687,
                                  "NDC")  #(0.180,0.727,0.402,0.787,"NDC")
    text_SubDetectors.SetFillColor(0)
    text_SubDetectors.SetBorderSize(0)
    text_SubDetectors.AddText("CMS Simulation")
    text_SubDetectors.SetTextAlign(11)
    text_SubDetectors.Draw()

    #Add eta labels
    keep_alive = []
    if plots[plot].iDrawEta:
        keep_alive.extend(drawEtaValues())

    # Store
    can_SubDetectors.Update()
    if not checkFile_(theDirname):
        os.mkdir(theDirname)
    can_SubDetectors.SaveAs("%s/MaterialBdg_%s_%s.png" %
                            (theDirname, compounddetectorname, plot))
    #It seems that it is too heavy to create .pdf and .root
    #can_SubDetectors.SaveAs("%s/MaterialBdg_FromVertexToEndofHGCal_%s.pdf" % (theDirname, plot))
    #can_SubDetectors.SaveAs("%s/MaterialBdg_FromVertexToEndofHGCal_%s.root" % (theDirname, plot))

    hist2d_X0_total.GetXaxis().SetRangeUser(0., 7000.)
    #Draw eta values in the zoom case
    keep_alive = []
    keep_alive.extend(drawHalfEtaValues())
    #hist2d_X0_total.Draw("COLZ")
    can_SubDetectors.Update()
    can_SubDetectors.Modified()
    can_SubDetectors.SaveAs("%s/MaterialBdg_%s_%s_Zpluszoom.png" %
                            (theDirname, compounddetectorname, plot))
Beispiel #4
0
def setStyle():
    gStyle.SetCanvasColor(0)
    gStyle.SetCanvasBorderSize(10)
    gStyle.SetCanvasBorderMode(0)
    gStyle.SetCanvasDefH(700)
    gStyle.SetCanvasDefW(700)

    gStyle.SetPadColor(0)
    gStyle.SetPadBorderSize(10)
    gStyle.SetPadBorderMode(0)
    gStyle.SetPadBottomMargin(0.13)
    gStyle.SetPadTopMargin(0.08)
    gStyle.SetPadLeftMargin(0.15)
    gStyle.SetPadRightMargin(0.05)
    gStyle.SetPadGridX(0)
    gStyle.SetPadGridY(0)
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)

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

    gStyle.SetNdivisions(505)

    gStyle.SetLineWidth(2)
    gStyle.SetHistLineWidth(2)
    gStyle.SetFrameLineWidth(2)
    gStyle.SetLegendFillColor(root.kWhite)
    gStyle.SetLegendFont(42)
    gStyle.SetMarkerSize(1.2)
    gStyle.SetMarkerStyle(20)

    gStyle.SetLabelSize(0.040, "X")
    gStyle.SetLabelSize(0.040, "Y")

    gStyle.SetLabelOffset(0.010, "X")
    gStyle.SetLabelOffset(0.010, "Y")

    gStyle.SetLabelFont(42, "X")
    gStyle.SetLabelFont(42, "Y")

    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleFont(42)
    gStyle.SetTitleFont(42, "X")
    gStyle.SetTitleFont(42, "Y")

    gStyle.SetTitleSize(0.045, "X")
    gStyle.SetTitleSize(0.045, "Y")

    gStyle.SetTitleOffset(1.4, "X")
    gStyle.SetTitleOffset(1.4, "Y")

    gStyle.SetTextSize(0.055)
    gStyle.SetTextFont(42)

    gStyle.SetOptStat(0)
Beispiel #5
0
from ROOT import gDirectory
from math import fabs
from os import path
import sys
from ROOT import *
from ROOT import gROOT, gRandom, gStyle
from ROOT import TCanvas, TF1, TH1F, TH2F, TGLabel
gROOT.Reset()

gROOT.SetStyle("Pub")
gStyle.SetPadColor(10)
gStyle.SetGridColor(16)
gStyle.SetFrameFillColor(10)
gStyle.SetFillColor(10)
gStyle.SetTitleFillColor(10)
gStyle.SetTitleBorderSize(0)
gStyle.SetCanvasColor(10)
gStyle.SetStatColor(10)
gStyle.SetLabelSize(0.08, "xyz")
gStyle.SetTitleSize(0.08, "xyz")
gStyle.SetFrameLineWidth(1)
gStyle.SetHistLineWidth(1)
gStyle.SetNdivisions(510, "x")
gStyle.SetNdivisions(508, "y")
gStyle.SetNdivisions(8, "z")
gStyle.SetTickLength(0.03, "x")
gStyle.SetTickLength(0.03, "y")
gStyle.SetTickLength(0.03, "z")
gStyle.SetFrameBorderSize(1)
gStyle.SetLegendBorderSize(1)
gStyle.SetCanvasBorderSize(1)
Beispiel #6
0
def create2DPlots(detector, plot, geometry):
    """Produce the requested plot for the specified detector.

       Function that will plot the requested 2D-@plot for the
       specified @detector. The specified detector could either be a
       real detector or a compound one. The list of available plots
       are the keys of plots dictionary (imported from plot_utils).

    """

    theDirname = 'Images'
    if not checkFile_(theDirname):
        os.mkdir(theDirname)

    goodToGo, theDetectorFilename = paramsGood_(detector, plot, geometry)
    if not goodToGo:
        return

    theDetectorFile = TFile(theDetectorFilename)

    hist_X0_total = get2DHisto_(detector,plots[plot].plotNumber,geometry)

    # # properties
    gStyle.SetStripDecimals(False)

    # Ratio
    if plots[plot].iRebin:
        hist_X0_total.Rebin2D()

    # stack
    hist2dTitle = ('%s %s;%s;%s;%s' % (plots[plot].quotaName,
                                       detector,
                                       plots[plot].abscissa,
                                       plots[plot].ordinate,
                                       plots[plot].quotaName))

    hist_X0_total.SetTitle(hist2dTitle)
    hist_X0_total.SetTitleOffset(0.5,"Y")

    if plots[plot].histoMin != -1.:
        hist_X0_total.SetMinimum(plots[plot].histoMin)
    if plots[plot].histoMax != -1.:
        hist_X0_total.SetMaximum(plots[plot].histoMax)

    can2name = "MBCan_2D_%s_%s" % (detector, plot)
    can2 = TCanvas(can2name, can2name, 2480+248, 580+58+58)
    can2.SetTopMargin(0.1)
    can2.SetBottomMargin(0.1)
    can2.SetLeftMargin(0.04)
    can2.SetRightMargin(0.06)
    can2.SetFillColor(kWhite)
    gStyle.SetOptStat(0)
    gStyle.SetTitleFillColor(0)
    gStyle.SetTitleBorderSize(0)

    # Color palette
    gStyle.SetPalette(kGreyScale)

    # Log?
    can2.SetLogz(plots[plot].zLog)

    # Draw in colors
    hist_X0_total.Draw("COLZ")

    # Store
    can2.Update()

    #Aesthetic
    setUpPalette(hist_X0_total,plot)

    #Add eta labels
    keep_alive = []
    if plots[plot].iDrawEta:
        keep_alive.extend(drawEtaValues())

    can2.Modified()
    hist_X0_total.SetContour(255)

    # Store
    can2.Update()
    can2.Modified()

    can2.SaveAs( "%s/%s_%s_%s_bw.pdf" 
                 % (theDirname, detector, plot, geometry))
    can2.SaveAs( "%s/%s_%s_%s_bw.png" 
                 % (theDirname, detector, plot, geometry))
    gStyle.SetStripDecimals(True)
Beispiel #7
0
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)
Beispiel #8
0
def create2DPlots(detector, plot):
    """Produce the requested plot for the specified detector.

       Function that will plot the requested 2D-@plot for the
       specified @detector. The specified detector could either be a
       real detector or a compound one. The list of available plots
       are the keys of plots dictionary (imported from plot_utils.

    """

    theDirname = 'Images'
    if not checkFile_(theDirname):
        os.mkdir(theDirname)

    goodToGo, theDetectorFilename = paramsGood_(detector, plot)
    if not goodToGo:
        return

    theDetectorFile = TFile(theDetectorFilename)

    # get TProfiles
    prof2d_X0_det_total = theDetectorFile.Get('%s' % plots[plot].plotNumber)

    # histos
    prof2d_X0_det_total.__class__ = TProfile2D
    hist_X0_total = prof2d_X0_det_total.ProjectionXY()

    # keep files live forever
    files = []
    if detector in COMPOUNDS.keys():
        for subDetector in COMPOUNDS[detector][1:]:
            # filenames of single components
            subDetectorFilename = "matbdg_%s.root" % subDetector

            # open file
            if not checkFile_(subDetectorFilename):
                print("Error, missing file %s" % subDetectorFilename)
                continue

            subDetectorFile = TFile(subDetectorFilename)
            files.append(subDetectorFile)
            print("*** Open file... %s" % subDetectorFilename)

            # subdetector profiles
            prof2d_X0_det_total = subDetectorFile.Get('%s' %
                                                      plots[plot].plotNumber)
            prof2d_X0_det_total.__class__ = TProfile2D

            # add to summary histogram
            hist_X0_total.Add(
                prof2d_X0_det_total.ProjectionXY(
                    "B_%s" % prof2d_X0_det_total.GetName()), +1.000)

    # # properties
    gStyle.SetPalette(1)
    gStyle.SetStripDecimals(False)
    # #

    # Create "null" histo
    minX = 1.03 * hist_X0_total.GetXaxis().GetXmin()
    maxX = 1.03 * hist_X0_total.GetXaxis().GetXmax()
    minY = 1.03 * hist_X0_total.GetYaxis().GetXmin()
    maxY = 1.03 * hist_X0_total.GetYaxis().GetXmax()

    frame = TH2F("frame", "", 10, minX, maxX, 10, minY, maxY)
    frame.SetMinimum(0.1)
    frame.SetMaximum(10.)
    frame.GetXaxis().SetTickLength(frame.GetXaxis().GetTickLength() * 0.50)
    frame.GetYaxis().SetTickLength(frame.GetXaxis().GetTickLength() / 4.)

    # Ratio
    if plots[plot].iRebin:
        hist_X0_total.Rebin2D()

    # stack
    hist2dTitle = ('%s %s;%s;%s;%s' %
                   (plots[plot].quotaName, detector, plots[plot].abscissa,
                    plots[plot].ordinate, plots[plot].quotaName))

    hist2d_X0_total = hist_X0_total
    frame.SetTitle(hist2dTitle)
    frame.SetTitleOffset(0.5, "Y")

    if plots[plot].histoMin != -1.:
        hist2d_X0_total.SetMinimum(plots[plot].histoMin)
    if plots[plot].histoMax != -1.:
        hist2d_X0_total.SetMaximum(plots[plot].histoMax)

    #
    can2name = "MBCan_2D_%s_%s" % (detector, plot)
    can2 = TCanvas(can2name, can2name, 2480 + 248, 580 + 58 + 58)
    can2.SetTopMargin(0.1)
    can2.SetBottomMargin(0.1)
    can2.SetLeftMargin(0.04)
    can2.SetRightMargin(0.06)
    can2.SetFillColor(kWhite)
    gStyle.SetOptStat(0)
    gStyle.SetTitleFillColor(0)
    gStyle.SetTitleBorderSize(0)

    # Color palette
    gStyle.SetPalette(1)

    # Log?
    can2.SetLogz(plots[plot].zLog)

    # Draw in colors
    frame.Draw()
    hist2d_X0_total.Draw("COLZsame")  #Dummy draw to create the palette object

    # Store
    can2.Update()

    #Aesthetic
    palette = hist2d_X0_total.GetListOfFunctions().FindObject("palette")
    if palette:
        palette.__class__ = TPaletteAxis
        palette.SetX1NDC(0.945)
        palette.SetX2NDC(0.96)
        palette.SetY1NDC(0.1)
        palette.SetY2NDC(0.9)
        palette.GetAxis().SetTickSize(.01)
        palette.GetAxis().SetTitle("")
        if plots[plot].zLog:
            palette.GetAxis().SetLabelOffset(-0.01)
    paletteTitle = TLatex(1.12 * maxX, maxY, plots[plot].quotaName)
    paletteTitle.SetTextAngle(90.)
    paletteTitle.SetTextSize(0.05)
    paletteTitle.SetTextAlign(31)
    paletteTitle.Draw()
    hist2d_X0_total.GetYaxis().SetTickLength(
        hist2d_X0_total.GetXaxis().GetTickLength() / 4.)
    hist2d_X0_total.GetYaxis().SetTickLength(
        hist2d_X0_total.GetXaxis().GetTickLength() / 4.)
    hist2d_X0_total.SetTitleOffset(0.5, "Y")
    hist2d_X0_total.GetXaxis().SetNoExponent(True)
    hist2d_X0_total.GetYaxis().SetNoExponent(True)

    #Add eta labels
    keep_alive = []
    if plots[plot].iDrawEta:
        keep_alive.extend(drawEtaValues())

    can2.Modified()
    hist2d_X0_total.SetContour(255)

    # Store
    can2.Update()
    can2.Modified()

    can2.SaveAs("%s/%s_%s_bw.pdf" % (theDirname, detector, plot))
    can2.SaveAs("%s/%s_%s_bw.png" % (theDirname, detector, plot))
    gStyle.SetStripDecimals(True)
Beispiel #9
0
def applyRootStyle():

    from ROOT import gROOT, gStyle, kWhite, kBlack, TColor

    # Start from a plain default
    gROOT.SetStyle("Plain")

    lhcbMarkerType = 8
    lhcbMarkerSize = 0.8
    lhcbFont = 62
    lhcbStatFontSize = 0.02
    lhcbStatBoxWidth = 0.12
    lhcbStatBoxHeight = 0.12
    lhcbWidth = 1
    lhcbTextSize = 0.05
    lhcbLabelSize = 0.035
    lhcbAxisLabelSize = 0.035
    lhcbForeColour = kBlack

    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBorderMode(0)

    # canvas options
    gStyle.SetCanvasBorderSize(0)
    gStyle.SetCanvasBorderMode(0)

    # fonts
    gStyle.SetTextFont(lhcbFont)
    gStyle.SetTextSize(lhcbTextSize)
    gStyle.SetLabelFont(lhcbFont, "x")
    gStyle.SetLabelFont(lhcbFont, "y")
    gStyle.SetLabelFont(lhcbFont, "z")
    gStyle.SetLabelSize(lhcbLabelSize, "x")
    gStyle.SetLabelSize(lhcbLabelSize, "y")
    gStyle.SetLabelSize(lhcbLabelSize, "z")
    gStyle.SetTitleFont(lhcbFont)
    gStyle.SetTitleSize(lhcbAxisLabelSize, "x")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "y")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "z")
    gStyle.SetTitleColor(kWhite)
    gStyle.SetTitleFillColor(kWhite)
    gStyle.SetTitleColor(kBlack)
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(kBlack)

    # set title position
    gStyle.SetTitleX(0.15)
    gStyle.SetTitleY(0.97)
    # turn off Title box
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(lhcbForeColour)
    gStyle.SetTitleColor(lhcbForeColour)

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

    # Grid
    # gStyle.SetGridStyle(3)

    # label offsets
    gStyle.SetLabelOffset(0.015)

    # by default, do not display histogram decorations:
    gStyle.SetOptStat(1111)
    # show probability, parameters and errors
    gStyle.SetOptFit(1011)

    # look of the statistics box:
    gStyle.SetStatBorderSize(1)
    gStyle.SetStatFont(lhcbFont)
    gStyle.SetStatFontSize(lhcbStatFontSize)
    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatW(lhcbStatBoxWidth)
    gStyle.SetStatH(lhcbStatBoxHeight)

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

    # histogram divisions
    gStyle.SetNdivisions(505, "x")
    gStyle.SetNdivisions(510, "y")

    # Style for 2D zcol plots
    NRGBs = 5
    NCont = 255
    from array import array
    stops = array('d', [0.00, 0.34, 0.61, 0.84, 1.00])
    red = array('d', [0.00, 0.00, 0.87, 1.00, 0.51])
    green = array('d', [0.00, 0.81, 1.00, 0.20, 0.00])
    blue = array('d', [0.51, 1.00, 0.12, 0.00, 0.00])
    TColor().CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont)
    gStyle.SetNumberContours(NCont)

    # Force the style
    gROOT.ForceStyle()
Beispiel #10
0
def rootStyle(batchMode=True):
    from ROOT import gROOT, gStyle, kWhite, kBlack

    # No info messages
    gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;")

    # Batch mode (no TCanvas)
    gROOT.SetBatch(batchMode)

    # Start from a plain default
    gROOT.SetStyle("Plain")

    lhcbMarkerType = 8
    lhcbMarkerSize = 0.8
    lhcbFont = 62
    lhcbStatFontSize = 0.02
    lhcbStatBoxWidth = 0.12
    lhcbStatBoxHeight = 0.12
    lhcbWidth = 1
    lhcbTextSize = 0.05
    lhcbLabelSize = 0.035
    lhcbAxisLabelSize = 0.035
    lhcbForeColour = kBlack

    gStyle.SetFrameBorderMode(0)
    gStyle.SetPadBorderMode(0)

    # canvas options
    gStyle.SetCanvasBorderSize(0)
    gStyle.SetCanvasBorderMode(0)

    # fonts
    gStyle.SetTextFont(lhcbFont)
    gStyle.SetTextSize(lhcbTextSize)
    gStyle.SetLabelFont(lhcbFont, "x")
    gStyle.SetLabelFont(lhcbFont, "y")
    gStyle.SetLabelFont(lhcbFont, "z")
    gStyle.SetLabelSize(lhcbLabelSize, "x")
    gStyle.SetLabelSize(lhcbLabelSize, "y")
    gStyle.SetLabelSize(lhcbLabelSize, "z")
    gStyle.SetTitleFont(lhcbFont)
    gStyle.SetTitleSize(lhcbAxisLabelSize, "x")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "y")
    gStyle.SetTitleSize(lhcbAxisLabelSize, "z")
    gStyle.SetTitleColor(kWhite)
    gStyle.SetTitleFillColor(kWhite)
    gStyle.SetTitleColor(kBlack)
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(kBlack)

    # set title position
    gStyle.SetTitleX(0.15)
    gStyle.SetTitleY(0.97)
    # turn off Title box
    gStyle.SetTitleBorderSize(0)
    gStyle.SetTitleTextColor(lhcbForeColour)
    gStyle.SetTitleColor(lhcbForeColour)

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

    # label offsets
    gStyle.SetLabelOffset(0.015)

    # by default, do not display histogram decorations:
    gStyle.SetOptStat(1111)
    # show probability, parameters and errors
    gStyle.SetOptFit(1011)

    # look of the statistics box:
    gStyle.SetStatBorderSize(1)
    gStyle.SetStatFont(lhcbFont)
    gStyle.SetStatFontSize(lhcbStatFontSize)
    gStyle.SetStatX(0.9)
    gStyle.SetStatY(0.9)
    gStyle.SetStatW(lhcbStatBoxWidth)
    gStyle.SetStatH(lhcbStatBoxHeight)

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

    # histogram divisions
    gStyle.SetNdivisions(505, "x")
    gStyle.SetNdivisions(510, "y")

    # Force the style
    gROOT.ForceStyle()
def set_root_env():
    #//TStyle* genieStyle = new TStyle("genieStyle", "GENIE Style")
    #//set the background color to white
    gStyle.SetFillColor(10)
    gStyle.SetFrameFillColor(10)
    gStyle.SetCanvasColor(10)
    gStyle.SetPadColor(10)
    gStyle.SetTitleFillColor(0)
    gStyle.SetStatColor(10)

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

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

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

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

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

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

    #set the margins
    gStyle.SetPadBottomMargin(0.18)
    gStyle.SetPadTopMargin(0.08)
    gStyle.SetPadRightMargin(0.08)
    gStyle.SetPadLeftMargin(0.17)

    #set axis label and title text sizes
    gStyle.SetLabelFont(42, "xyz")
    gStyle.SetLabelSize(0.04, "xyz")
    gStyle.SetLabelOffset(0.015, "xyz")
    gStyle.SetTitleFont(42, "xyz")
    gStyle.SetTitleSize(0.04, "xyz")
    gStyle.SetTitleOffset(1.4, "y")
    gStyle.SetTitleOffset(1.3, "x")
    gStyle.SetStatFont(42)
    gStyle.SetStatFontSize(0.07)
    gStyle.SetTitleBorderSize(1)
    gStyle.SetStatBorderSize(0)
    gStyle.SetTextFont(42)
    gStyle.SetTitleW(0.5)
    gStyle.SetTitleH(0.1)

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

    #set the number of divisions to show
    gStyle.SetNdivisions(506, "xy")
    #gStyle.SetPadTickX(-50202)

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

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

    #turn off stats
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)

    #marker/line settings
    #gStyle.SetMarkerStyle(20)
    gStyle.SetMarkerSize(.95)  #0.7
    gStyle.SetLineWidth(2)
    gStyle.SetErrorX(0)
    gStyle.SetHistLineStyle(0)  #It was 3 for a dotted line

    #done
    gStyle.cd()
    gROOT.ForceStyle()
Beispiel #12
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()
Beispiel #13
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
Beispiel #14
0
    def initStyle():
        gROOT.SetStyle("Plain")
        gStyle.SetOptFit()

        # For the canvas:
        gStyle.SetCanvasBorderMode(0)
        gStyle.SetCanvasColor(TStyle.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(TStyle.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(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)
        #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.SetOptStat(1)
        gStyle.SetStatBorderSize(0)
        gStyle.SetOptStat('emr')
        gStyle.SetOptFile(0)
        gStyle.SetStatColor(TStyle.kWhite)
        gStyle.SetStatFont(42)
        gStyle.SetStatFontSize(0.025)
        gStyle.SetStatTextColor(1)
        gStyle.SetStatFormat("6.4g")
        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.15)
        gStyle.SetPadTopMargin(0.05)
        #gStyle.SetPadBottomMargin(0.13)
        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(1)
        gStyle.SetTitleFont(42)
        #gStyle.SetTitleColor(1)
        gStyle.SetTitleTextColor(1)
        #gStyle.SetTitleFillColor(0)
        gStyle.SetTitleFontSize(0.07)
        # gStyle.SetTitleH(0) # Set the height of the title box
        # gStyle.SetTitleW(0) # Set the width of the title box
        gStyle.SetTitleX(0.14)  # Set the position of the title box
        gStyle.SetTitleY(1.025)  # 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.06, "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(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.04, "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.)
        #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"
Beispiel #15
0
    def __init__(
        self,
        tuples,  # A list or dictionary of input file paths.
        name=None,
        out_dir=None,  # The directory where the output should go.
        out_file=None,  # The name of the output file (including ".root")
        save=True,
        v=False,
        tt_names=["tuplizer/events"],  # The names of the input TTrees
        count=None,
        use_condor=False,
    ):
        # Basic configuration:
        gROOT.SetBatch()  # Prevent ROOT canvas windows from opening

        # Arguments and variables:
        self.name = inspect.stack()[1][
            1][:-3] if name == None else name  # This makes the name attribute be the script name if it's not already called something.
        self.time_string = utilities.time_string(
        )[:-4]  # A time string indicating when the analyzer was created
        self.save = save
        self.count = count
        self.condor = use_condor
        self.out_file = out_file
        self.out_dir = out_dir
        self.tuples_in = tuples  # This is useful debugging.
        self.tuples = {}
        self.tt_names = tt_names

        # Organize input:
        if isinstance(tuples, str):
            tuples = [tuples]
        if isinstance(tuples, list):
            if all(isinstance(tup, str) for tup in tuples):
                self.tuples = {self.name: tuples}
            elif all(isinstance(tup, dataset.dataset) for tup in tuples):
                for tup in tuples:
                    if tup.process not in self.tuples:
                        self.tuples[tup.process] = []
                    self.tuples[tup.process].append(tup)
            else:
                print "ERROR (analyzer): unrecognized input:"
                print self.tuples_in
                sys.exit()
        elif isinstance(tuples, dict):
            self.tuples = tuples
        else:
            print "ERROR (analyzer): \"tuples\" should be a string, list, or dictionary."
            print "tuples = {}".format(tuples)
            sys.exit()

        # Calculate event number if necessary:
        if self.count == None:
            if any([
                    isinstance(tup, str) for tup in utilities.flatten_list(
                        [thing for thing in self.tuples.values()])
            ]):
                self.count = True
            else:
                self.count = False

        ## Create TChains:
        if v: print "Making TChain(s) ..."
        self.tt_in = {}
        self.tt_info = {}
        self.tc = TCanvas("tc_{}".format(name), "tc_{}".format(name), 500, 500)
        SetOwnership(self.tc, 0)
        samples = self.tuples.keys()
        for sample, tups in self.tuples.items():
            ns = []

            # Handle different input schemes (either list of tuples or list of file names):
            food = 2 if isinstance(tups[0], dataset.dataset) else 1
            if food == 2:
                # A bit KLUDGY:
                fs = []
                for tup in tups:
                    fs += [
                        f if not tup.dir.eos else
                        "root://cmsxrootd.fnal.gov/" + f for f in tup.files
                    ]
                    ns += tup.ns
                tups = fs
            if v: print "\tMaking TChain(s) for {} ...".format(sample)
            #			self.tt_in[sample] = []
            if not self.tt_names: tt_names = [sample]
            for tt_name in tt_names:
                if v: print "\t\tTChain named {}:".format(tt_name)
                tt = TChain(tt_name)
                for tup in tups:
                    tt.Add(tup)
                    if v: print "\t\t+ {}".format(tup)
                SetOwnership(tt, 0)
                if (len(tt_names) > 1) and (len(samples) > 1):
                    key = "_".join([sample, tt_name])
                elif (len(tt_names) > 1) and (len(samples) == 1):
                    key = tt_name
                elif len(tt_names) == 1:
                    key = sample
                else:
                    print "ERROR (analyzer.__init__): The tuples configuration is weird:\n{}".format(
                        self.tuples)
                    sys.exit()
                self.tt_in[key] = tt
                info = {"ns": ns}
                self.tt_info[key] = info
#				self.tc[key] = TCanvas("tc_{}".format(key), "tc_{}".format(key), 500, 500)
#				SetOwnership(self.tc[key], 0)

# ROOT setup:
#		if v: print "\tSetting up ROOT ..."
        gROOT.SetStyle("Plain")
        gStyle.SetTitleBorderSize(0)
        gStyle.SetPalette(1)
        #		SetOwnership(gROOT, 0)

        # Organize output:
        if save:
            # Set attributes to defaults if they aren't set:
            ## Output directory:
            if not out_dir and not self.condor:
                self.out_dir = "results/{}_{}".format(self.name,
                                                      self.time_string)
            elif self.condor:
                self.out_dir = "."

            if not os.path.exists(self.out_dir): os.makedirs(self.out_dir)
            ## Output file:
            if not out_file and not self.condor:
                self.out_file = "{}_{}.root".format(self.name,
                                                    self.time_string)
            if self.condor: self.out_file = "job_{}.root".format(self.condor)

            # Define new attributes:
            self.out_path = self.out_dir + "/" + self.out_file
            ## ROOT output:
            self.out = TFile(self.out_path, "RECREATE")
            SetOwnership(self.out, 0)
            ### Tuple output:
            self.tt_out = {}
            for key, tt in self.tt_in.iteritems():
                self.tt_out[key] = TTree(key, 'anatuple')
                SetOwnership(self.tt_out[key], 0)
            ### Histograms:
            self.plots = []

        # Event loops
        self.loops = {}
        for key, tt in self.tt_in.iteritems():
            self.loops[key] = event_loop(self, key)