Example #1
0
def materialBudget_Simul_vs_Reco(reco_file, label, debug=False):
    """Plot reco vs simulation material budget.
    
       Function are produces a direct comparison of the material
       budget as extracted from the reconstruction geometry and
       inferred from the simulation one.

    """

    setTDRStyle()

    # plots
    cumulative_matbdg_sim = createPlots_("x_vs_eta")
    cumulative_matbdg_rec = createPlotsReco_(reco_file, label, debug=False)

    cc = TCanvas("cc", "cc", 1024, 1024)
    cumulative_matbdg_sim.SetMinimum(0.)
    cumulative_matbdg_sim.SetMaximum(3.5)
    cumulative_matbdg_sim.GetXaxis().SetRangeUser(-3.0, 3.0)
    cumulative_matbdg_sim.SetLineColor(kOrange)
    cumulative_matbdg_rec.SetMinimum(0.)
    cumulative_matbdg_rec.SetMaximum(3.)
    cumulative_matbdg_rec.SetLineColor(kAzure + 1)
    l = TLegend(0.18, 0.8, 0.95, 0.92)
    l.AddEntry(cumulative_matbdg_sim, "Sim Material", "f")
    l.AddEntry(cumulative_matbdg_rec, "Reco Material", "f")
    cumulative_matbdg_sim.Draw("HIST")
    cumulative_matbdg_rec.Draw("HIST SAME")
    l.Draw()
    filename = "MaterialBdg_Reco_vs_Simul_%s.png" % label
    cc.SaveAs(filename)
Example #2
0
def materialBudget_Simul_vs_Reco(reco_file, label, geometry, debug=False):
    """Plot reco vs simulation material budget.
    
       Function are produces a direct comparison of the material
       budget as extracted from the reconstruction geometry and
       inferred from the simulation one.

    """

    setTDRStyle()

    # plots
    cumulative_matbdg_sim = createPlots_("x_vs_eta", geometry)
    cumulative_matbdg_rec = createPlotsReco_(reco_file, label, debug=False)

    cc = TCanvas("cc", "cc", 1024, 1024)
    cumulative_matbdg_sim.SetMinimum(0.)
    cumulative_matbdg_sim.SetMaximum(3.5)
    cumulative_matbdg_sim.GetXaxis().SetRangeUser(-3.0, 3.0)
    cumulative_matbdg_sim.SetLineColor(kOrange)
    cumulative_matbdg_rec.SetMinimum(0.)
    cumulative_matbdg_rec.SetMaximum(3.)
    cumulative_matbdg_rec.SetLineColor(kAzure+1)
    l = TLegend(0.18, 0.8, 0.95, 0.92)
    l.AddEntry(cumulative_matbdg_sim, "Sim Material", "f")
    l.AddEntry(cumulative_matbdg_rec, "Reco Material", "f")
    cumulative_matbdg_sim.Draw("HIST")
    cumulative_matbdg_rec.Draw("HIST SAME")
    l.Draw()
    filename = "MaterialBdg_Reco_vs_Simul_%s.png" % label
    cc.SaveAs(filename)
Example #3
0
def createCompoundPlots(detector, plot, geometry):
    """Produce the requested plot for the specified detector.

       Function that will plot the requested @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.

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

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

    hist_X0_elements = OrderedDict()

    # stack
    stackTitle = "%s;%s;%s" % (detector,
                                               plots[plot].abscissa,
                                               plots[plot].ordinate)
    stack_X0 = THStack("stack_X0", stackTitle);
    theLegend = TLegend(0.50, 0.70, 0.70, 0.90);

    def setRanges(h):
        legendSpace = 1. + 0.3 # 30%
        minY = h.GetYaxis().GetXmin()
        maxY = h.GetBinContent(h.GetMaximumBin()) * legendSpace
        h.GetYaxis().SetRangeUser(minY, maxY)

    for label, [num, color, leg] in six.iteritems(hist_label_to_num):
        # We don't want the sum to be added as part of the stack
        if label is 'SUM':
            continue
        hist_X0_elements[label] = get1DHisto_(detector,
                                              num + plots[plot].plotNumber,
                                              geometry)
        hist_X0_elements[label].SetFillColor(color)
        hist_X0_elements[label].SetLineColor(kBlack)
        stack_X0.Add(hist_X0_elements[label])
        if hist_X0_elements[label].Integral() > 0.: theLegend.AddEntry(hist_X0_elements[label], leg, "f")

    # canvas
    canname = "MBCan_1D_%s_%s"  % (detector, plot)
    can = TCanvas(canname, canname, 800, 800)
    can.Range(0,0,25,25)
    gStyle.SetOptTitle(0)

    # Draw
    setRanges(stack_X0.GetStack().Last())
    stack_X0.Draw("HIST");
    stack_X0.GetXaxis().SetLabelSize(0.035)
    stack_X0.GetYaxis().SetLabelSize(0.035)
    theLegend.Draw();

    cmsMark = TLatex()
    cmsMark.SetNDC();
    cmsMark.SetTextAngle(0);
    cmsMark.SetTextColor(kBlack);    
    cmsMark.SetTextFont(61)
    cmsMark.SetTextSize(5e-2)
    cmsMark.SetTextAlign(11)
    cmsMark.DrawLatex(0.16,0.86,"CMS")

    simuMark = TLatex()
    simuMark.SetNDC();
    simuMark.SetTextAngle(0);
    simuMark.SetTextColor(kBlack);    
    simuMark.SetTextSize(3e-2)
    simuMark.SetTextAlign(11)
    simuMark.DrawLatex(0.16,0.82,"#font[52]{Simulation Internal}")
 
    # Store
    can.Update();
    can.SaveAs( "%s/%s_%s_%s.pdf" 
                % (theDirname, detector, plot, geometry))
    can.SaveAs( "%s/%s_%s_%s.png" 
                % (theDirname, detector, plot, geometry))
Example #4
0
def create2DPlotsGeometryComparison(detector, plot, 
                                    geometryOld, geometryNew):

    setTDRStyle()

    print('Extracting plot: %s.'%(plot))
    goodToGo, theFiles = paramsGood_(detector,plot,
                                     geometryOld,geometryNew)

    if not goodToGo:
        return
    
    gStyle.SetOptStat(False)

    old2DHisto = get2DHisto_(detector,plots[plot].plotNumber,geometryOld)
    new2DHisto = get2DHisto_(detector,plots[plot].plotNumber,geometryNew)

    if plots[plot].iRebin:
        old2DHisto.Rebin2D()
        new2DHisto.Rebin2D()

    def setRanges(h):
        h.GetXaxis().SetRangeUser(plots[plot].xmin, plots[plot].xmax)
        h.GetYaxis().SetRangeUser(plots[plot].ymin, plots[plot].ymax)
        if plots[plot].histoMin != -1.:
            h.SetMinimum(plots[plot].histoMin)
        if plots[plot].histoMax != -1.:
            h.SetMaximum(plots[plot].histoMax)

    ratio2DHisto = copy.deepcopy(new2DHisto)
    ratio2DHisto.Divide(old2DHisto)
    # Ratio and Difference have the same call
    # But different 'Palette' range so we are
    # setting the range only for the Ratio
    ratio2DHisto.SetMinimum(0.2)
    ratio2DHisto.SetMaximum(1.8)
    setRanges(ratio2DHisto)

    diff2DHisto = copy.deepcopy(new2DHisto)
    diff2DHisto.Add(old2DHisto,-1.0)
    setRanges(diff2DHisto)


    def setPadStyle():
        gPad.SetLeftMargin(0.05)
        gPad.SetRightMargin(0.08)
        gPad.SetTopMargin(0.10)
        gPad.SetBottomMargin(0.10)
        gPad.SetLogz(plots[plot].zLog)
        gPad.SetFillColor(kWhite)
        gPad.SetBorderMode(0)

    can = TCanvas('can','can',
                  2724,1336)
    can.Divide(1,2)
    can.cd(1)
    setPadStyle()
    gPad.SetLogz(plots[plot].zLog)
    
    gStyle.SetOptStat(0)
    gStyle.SetFillColor(kWhite)
    gStyle.SetPalette(kTemperatureMap)

    ratio2DHisto.SetTitle("%s, Ratio: %s/%s;%s;%s"
                          %(plots[plot].quotaName,
                            geometryOld, geometryNew,
                            plots[plot].abscissa,
                            plots[plot].ordinate))
    ratio2DHisto.Draw('COLZ')

    can.Update()

    setUpPalette(ratio2DHisto,plot)

    etasTop = []
    if plots[plot].iDrawEta:
        etasTop.extend(drawEtaValues())

    can.cd(2)

    diff2DHisto.SetTitle('%s, Difference: %s - %s %s;%s;%s'
                         %(plots[plot].quotaName,geometryNew,geometryOld,detector,
                           plots[plot].abscissa,plots[plot].ordinate))
    setPadStyle()
    diff2DHisto.Draw("COLZ")
    can.Update()
    setUpPalette(diff2DHisto,plot)

    etasBottom = []
    if plots[plot].iDrawEta:
        etasBottom.extend(drawEtaValues())

    can.Modified()

    theDirname = "Images"

    if not checkFile_(theDirname):
        os.mkdir(theDirname)
        
    can.SaveAs( "%s/%s_Comparison_%s_%s_vs_%s.png"
                % (theDirname,detector,plot,geometryOld,geometryNew) )
    gStyle.SetStripDecimals(True)
Example #5
0
def createCompoundPlotsGeometryComparison(detector, plot, geometryOld,
                                          geometryNew):

    setTDRStyle()

    goodToGo, theFiles = paramsGood_(detector,plot,
                                     geometryOld,geometryNew)

    if not goodToGo:
        return

    oldHistos = OrderedDict()
    newHistos = OrderedDict()
    ratioHistos = OrderedDict()
    diffHistos = OrderedDict()

    def setUpCanvas(canvas):

        gStyle.SetOptStat(False)
    
        mainPadTop = [        
            TPad("mainPadTop"+str(i)+'_'+canvas.GetName(),
                 "mainPad"+str(i),
                 i*0.25, 0.60, (i+1)*0.25, 1.0)
            for i in range(4)
            ]
        
        subPadTop = [
            TPad("subPadTop"+str(i)+'_'+canvas.GetName(),
                "subPad"+str(i),
                 i*0.25, 0.50, (i+1)*0.25, 0.6)
            for i in range(4)
            ]
        
        mainPadBottom = [
            TPad("mainPadBottom"+str(i)+'_'+canvas.GetName(),
                 "subPad"+str(i),
                 i*0.25, 0.10, (i+1)*0.25, 0.5)
            for i in range(4)
            ]
        
        subPadBottom = [
            TPad("subPadBottom"+str(i)+'_'+canvas.GetName(),
                 "subPad"+str(i),
                 i*0.25, 0.00, (i+1)*0.25, 0.1)
            for i in range(4)
            ]
        
        mainPad = mainPadTop + mainPadBottom
        subPad = subPadTop + subPadBottom    
        
        leftMargin = 0.12
        rightMargin = 0.12
        topMargin = 0.12
        bottomMargin = 0.3
        for i in range(8):
            mainPad[i].SetLeftMargin(leftMargin)
            mainPad[i].SetRightMargin(rightMargin)
            mainPad[i].SetTopMargin(topMargin)
            mainPad[i].SetBottomMargin(1e-3)
            mainPad[i].Draw()
            subPad[i].SetLeftMargin(leftMargin)
            subPad[i].SetRightMargin(rightMargin)
            subPad[i].SetTopMargin(1e-3)
            subPad[i].SetBottomMargin(bottomMargin)
            subPad[i].Draw()

        return mainPad, subPad

    canComparison = TCanvas("canComparison","canComparison",2400,1200)
    mainPad, subPad = setUpCanvas(canComparison)


    def setStyleHistoSubPad(histo):
        histo.SetTitle('')
        histo.SetMarkerColor(kBlack)
        histo.SetMarkerStyle(20) # Circles
        histo.SetMarkerSize(.5)
        histo.SetLineWidth(1)

        histo.GetYaxis().SetTitleSize(14)
        histo.GetYaxis().SetTitleFont(43)
        histo.GetYaxis().SetLabelSize(0.17)
        histo.GetYaxis().SetTitleOffset(5.0)
        histo.GetYaxis().SetNdivisions(6,3,0)

        histo.GetXaxis().SetTitleSize(25)
        histo.GetXaxis().SetTitleFont(43)
        histo.GetXaxis().SetTitleOffset(6.0)
        histo.GetXaxis().SetLabelSize(0.17)

        return histo
        
    def makeRatio(histoX,histoY):
        # return stylized ratio histoX/histoY
        histoXOverY = copy.deepcopy(histoX)
        histoXOverY.Divide(histoY)
        histoXOverY.GetYaxis().SetTitle('#frac{%s}{%s}' % (geometryNew,geometryOld))

        return histoXOverY

    def makeDiff(histoNew,histoOld):
        # Return stylized histoNew - histoOld
        diff = copy.deepcopy(histoNew)
        diff.Add(histoOld,-1.0)
        diff.GetYaxis().SetTitle(geometryNew 
                                 + " - "
                                 + geometryOld)
        diff.GetYaxis().SetNdivisions(6,3,0)

        diff.GetXaxis().SetTitleSize(25)
        diff.GetXaxis().SetTitleFont(43)
        diff.GetXaxis().SetTitleOffset(3.5)
        diff.GetXaxis().SetLabelSize(0.17)
        
        return diff


    # Plotting the different categories

    def setUpTitle(detector,label,plot):
        title = 'Material Budget %s [%s];%s;%s' % (detector,label,
                                                   plots[plot].abscissa,
                                                   plots[plot].ordinate)
        return title

    def setUpLegend(gOld,gNew,label):
        legend = TLegend(0.4,0.7,0.7,0.85)
        legend.AddEntry(gOld,"%s %s [%s]"%(detector,geometryOld,label),"F") #(F)illed Box
        legend.AddEntry(gNew,"%s %s [%s]"%(detector,geometryNew,label),"P") #(P)olymarker
        legend.SetTextFont(42)
        legend.SetTextSize(0.03)
        return legend

    def setRanges(h):
        legendSpace = 1. + 0.3 # 30%
        minX = h.GetXaxis().GetXmin()
        maxX = h.GetXaxis().GetXmax()
        minY = h.GetYaxis().GetXmin()
        maxY = h.GetBinContent(h.GetMaximumBin()) * legendSpace
        h.GetYaxis().SetRangeUser(minY, maxY)
        h.GetXaxis().SetRangeUser(minX, maxX)


    ########### Ratio ###########

    counter = 0
    legends = OrderedDict() #KeepAlive
    for label, [num, color, leg] in six.iteritems(hist_label_to_num):

        mainPad[counter].cd()
        oldHistos[label] = get1DHisto_(detector,
                                       num+plots[plot].plotNumber
                                       ,geometryOld)
        oldHistos[label].SetTitle(setUpTitle(detector,leg,plot))
        oldHistos[label].SetFillColor(color)
        oldHistos[label].SetLineColor(kBlack)
        oldHistos[label].SetLineWidth(1)
        setRanges(oldHistos[label])
        oldHistos[label].Draw("HIST")

        newHistos[label] = get1DHisto_(detector,
                                       num+plots[plot].plotNumber
                                       ,geometryNew)
        newHistos[label].SetMarkerSize(.5)
        newHistos[label].SetMarkerStyle(20)
        newHistos[label].Draw('SAME P')

        legends[label]= setUpLegend(oldHistos[label],newHistos[label],
                                    leg);
        legends[label].Draw()

        # Ratio
        subPad[counter].cd()
        ratioHistos[label] = makeRatio( newHistos[label],oldHistos[label] )
        ratioHistos[label] = setStyleHistoSubPad(ratioHistos[label])
        ratioHistos[label].Draw("HIST P")

        counter += 1

    theDirname = "Images"

    if not checkFile_(theDirname):
        os.mkdir(theDirname)
        
    canComparison.SaveAs( "%s/%s_ComparisonRatio_%s_%s_vs_%s.png"
                          % (theDirname,detector,plot,geometryOld,geometryNew) )

    ######## Difference ########

    canDiff = TCanvas("canDiff","canDiff",2400,1200)

    mainPadDiff, subPadDiff = setUpCanvas(canDiff)
 
    counter = 0
    for label, [num, color, leg] in six.iteritems(hist_label_to_num):
        mainPadDiff[counter].cd()
        oldHistos[label].SetTitle(setUpTitle(detector,leg,plot))
        oldHistos[label].Draw("HIST")
        newHistos[label].Draw('SAME P')

        legends[label].Draw()

        # Difference
        subPadDiff[counter].cd()
        diffHistos[label] = makeDiff( newHistos[label],oldHistos[label] )
        diffHistos[label] = setStyleHistoSubPad(diffHistos[label])
        diffHistos[label].SetTitle('')
        diffHistos[label].SetFillColor(color+1)
        diffHistos[label].Draw("HIST")
        counter +=1

    canDiff.SaveAs( "%s/%s_ComparisonDifference_%s_%s_vs_%s.png"
                          % (theDirname,detector,plot,geometryOld,geometryNew) )
Example #6
0
def createCompoundPlots(detector, plot, geometry):
    """Produce the requested plot for the specified detector.

       Function that will plot the requested @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.

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

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

    hist_X0_elements = OrderedDict()

    # stack
    stackTitle = "%s;%s;%s" % (detector,
                                               plots[plot].abscissa,
                                               plots[plot].ordinate)
    stack_X0 = THStack("stack_X0", stackTitle);
    theLegend = TLegend(0.50, 0.70, 0.70, 0.90);

    def setRanges(h):
        legendSpace = 1. + 0.3 # 30%
        minY = h.GetYaxis().GetXmin()
        maxY = h.GetBinContent(h.GetMaximumBin()) * legendSpace
        h.GetYaxis().SetRangeUser(minY, maxY)

    for label, [num, color, leg] in six.iteritems(hist_label_to_num):
        # We don't want the sum to be added as part of the stack
        if label is 'SUM':
            continue
        hist_X0_elements[label] = get1DHisto_(detector,
                                              num + plots[plot].plotNumber,
                                              geometry)
        hist_X0_elements[label].SetFillColor(color)
        hist_X0_elements[label].SetLineColor(kBlack)
        stack_X0.Add(hist_X0_elements[label])
        if hist_X0_elements[label].Integral() > 0.: theLegend.AddEntry(hist_X0_elements[label], leg, "f")

    # canvas
    canname = "MBCan_1D_%s_%s"  % (detector, plot)
    can = TCanvas(canname, canname, 800, 800)
    can.Range(0,0,25,25)
    gStyle.SetOptTitle(0)

    # Draw
    setRanges(stack_X0.GetStack().Last())
    stack_X0.Draw("HIST");
    stack_X0.GetXaxis().SetLabelSize(0.035)
    stack_X0.GetYaxis().SetLabelSize(0.035)
    theLegend.Draw();

    cmsMark = TLatex()
    cmsMark.SetNDC();
    cmsMark.SetTextAngle(0);
    cmsMark.SetTextColor(kBlack);    
    cmsMark.SetTextFont(61)
    cmsMark.SetTextSize(5e-2)
    cmsMark.SetTextAlign(11)
    cmsMark.DrawLatex(0.16,0.86,"CMS")

    simuMark = TLatex()
    simuMark.SetNDC();
    simuMark.SetTextAngle(0);
    simuMark.SetTextColor(kBlack);    
    simuMark.SetTextSize(3e-2)
    simuMark.SetTextAlign(11)
    simuMark.DrawLatex(0.16,0.82,"#font[52]{Simulation Internal}")
 
    # Store
    can.Update();
    can.SaveAs( "%s/%s_%s_%s.pdf" 
                % (theDirname, detector, plot, geometry))
    can.SaveAs( "%s/%s_%s_%s.png" 
                % (theDirname, detector, plot, geometry))
Example #7
0
def create2DPlotsGeometryComparison(detector, plot, 
                                    geometryOld, geometryNew):

    setTDRStyle()

    print('Extracting plot: %s.'%(plot))
    goodToGo, theFiles = paramsGood_(detector,plot,
                                     geometryOld,geometryNew)

    if not goodToGo:
        return
    
    gStyle.SetOptStat(False)

    old2DHisto = get2DHisto_(detector,plots[plot].plotNumber,geometryOld)
    new2DHisto = get2DHisto_(detector,plots[plot].plotNumber,geometryNew)

    if plots[plot].iRebin:
        old2DHisto.Rebin2D()
        new2DHisto.Rebin2D()

    def setRanges(h):
        h.GetXaxis().SetRangeUser(plots[plot].xmin, plots[plot].xmax)
        h.GetYaxis().SetRangeUser(plots[plot].ymin, plots[plot].ymax)
        if plots[plot].histoMin != -1.:
            h.SetMinimum(plots[plot].histoMin)
        if plots[plot].histoMax != -1.:
            h.SetMaximum(plots[plot].histoMax)

    ratio2DHisto = copy.deepcopy(new2DHisto)
    ratio2DHisto.Divide(old2DHisto)
    # Ratio and Difference have the same call
    # But different 'Palette' range so we are
    # setting the range only for the Ratio
    ratio2DHisto.SetMinimum(0.2)
    ratio2DHisto.SetMaximum(1.8)
    setRanges(ratio2DHisto)

    diff2DHisto = copy.deepcopy(new2DHisto)
    diff2DHisto.Add(old2DHisto,-1.0)
    setRanges(diff2DHisto)


    def setPadStyle():
        gPad.SetLeftMargin(0.05)
        gPad.SetRightMargin(0.08)
        gPad.SetTopMargin(0.10)
        gPad.SetBottomMargin(0.10)
        gPad.SetLogz(plots[plot].zLog)
        gPad.SetFillColor(kWhite)
        gPad.SetBorderMode(0)

    can = TCanvas('can','can',
                  2724,1336)
    can.Divide(1,2)
    can.cd(1)
    setPadStyle()
    gPad.SetLogz(plots[plot].zLog)
    
    gStyle.SetOptStat(0)
    gStyle.SetFillColor(kWhite)
    gStyle.SetPalette(kTemperatureMap)

    ratio2DHisto.SetTitle("%s, Ratio: %s/%s;%s;%s"
                          %(plots[plot].quotaName,
                            geometryOld, geometryNew,
                            plots[plot].abscissa,
                            plots[plot].ordinate))
    ratio2DHisto.Draw('COLZ')

    can.Update()

    setUpPalette(ratio2DHisto,plot)

    etasTop = []
    if plots[plot].iDrawEta:
        etasTop.extend(drawEtaValues())

    can.cd(2)

    diff2DHisto.SetTitle('%s, Difference: %s - %s %s;%s;%s'
                         %(plots[plot].quotaName,geometryNew,geometryOld,detector,
                           plots[plot].abscissa,plots[plot].ordinate))
    setPadStyle()
    diff2DHisto.Draw("COLZ")
    can.Update()
    setUpPalette(diff2DHisto,plot)

    etasBottom = []
    if plots[plot].iDrawEta:
        etasBottom.extend(drawEtaValues())

    can.Modified()

    theDirname = "Images"

    if not checkFile_(theDirname):
        os.mkdir(theDirname)
        
    can.SaveAs( "%s/%s_Comparison_%s_%s_vs_%s.png"
                % (theDirname,detector,plot,geometryOld,geometryNew) )
    gStyle.SetStripDecimals(True)
Example #8
0
def createCompoundPlotsGeometryComparison(detector, plot, geometryOld,
                                          geometryNew):

    setTDRStyle()

    goodToGo, theFiles = paramsGood_(detector,plot,
                                     geometryOld,geometryNew)

    if not goodToGo:
        return

    oldHistos = OrderedDict()
    newHistos = OrderedDict()
    ratioHistos = OrderedDict()
    diffHistos = OrderedDict()

    def setUpCanvas(canvas):

        gStyle.SetOptStat(False)
    
        mainPadTop = [        
            TPad("mainPadTop"+str(i)+'_'+canvas.GetName(),
                 "mainPad"+str(i),
                 i*0.25, 0.60, (i+1)*0.25, 1.0)
            for i in range(4)
            ]
        
        subPadTop = [
            TPad("subPadTop"+str(i)+'_'+canvas.GetName(),
                "subPad"+str(i),
                 i*0.25, 0.50, (i+1)*0.25, 0.6)
            for i in range(4)
            ]
        
        mainPadBottom = [
            TPad("mainPadBottom"+str(i)+'_'+canvas.GetName(),
                 "subPad"+str(i),
                 i*0.25, 0.10, (i+1)*0.25, 0.5)
            for i in range(4)
            ]
        
        subPadBottom = [
            TPad("subPadBottom"+str(i)+'_'+canvas.GetName(),
                 "subPad"+str(i),
                 i*0.25, 0.00, (i+1)*0.25, 0.1)
            for i in range(4)
            ]
        
        mainPad = mainPadTop + mainPadBottom
        subPad = subPadTop + subPadBottom    
        
        leftMargin = 0.12
        rightMargin = 0.12
        topMargin = 0.12
        bottomMargin = 0.3
        for i in range(8):
            mainPad[i].SetLeftMargin(leftMargin)
            mainPad[i].SetRightMargin(rightMargin)
            mainPad[i].SetTopMargin(topMargin)
            mainPad[i].SetBottomMargin(1e-3)
            mainPad[i].Draw()
            subPad[i].SetLeftMargin(leftMargin)
            subPad[i].SetRightMargin(rightMargin)
            subPad[i].SetTopMargin(1e-3)
            subPad[i].SetBottomMargin(bottomMargin)
            subPad[i].Draw()

        return mainPad, subPad

    canComparison = TCanvas("canComparison","canComparison",2400,1200)
    mainPad, subPad = setUpCanvas(canComparison)


    def setStyleHistoSubPad(histo):
        histo.SetTitle('')
        histo.SetMarkerColor(kBlack)
        histo.SetMarkerStyle(20) # Circles
        histo.SetMarkerSize(.5)
        histo.SetLineWidth(1)

        histo.GetYaxis().SetTitleSize(14)
        histo.GetYaxis().SetTitleFont(43)
        histo.GetYaxis().SetLabelSize(0.17)
        histo.GetYaxis().SetTitleOffset(5.0)
        histo.GetYaxis().SetNdivisions(6,3,0)

        histo.GetXaxis().SetTitleSize(25)
        histo.GetXaxis().SetTitleFont(43)
        histo.GetXaxis().SetTitleOffset(6.0)
        histo.GetXaxis().SetLabelSize(0.17)

        return histo
        
    def makeRatio(histoX,histoY):
        # return stylized ratio histoX/histoY
        histoXOverY = copy.deepcopy(histoX)
        histoXOverY.Divide(histoY)
        histoXOverY.GetYaxis().SetTitle('#frac{%s}{%s}' % (geometryNew,geometryOld))

        return histoXOverY

    def makeDiff(histoNew,histoOld):
        # Return stylized histoNew - histoOld
        diff = copy.deepcopy(histoNew)
        diff.Add(histoOld,-1.0)
        diff.GetYaxis().SetTitle(geometryNew 
                                 + " - "
                                 + geometryOld)
        diff.GetYaxis().SetNdivisions(6,3,0)

        diff.GetXaxis().SetTitleSize(25)
        diff.GetXaxis().SetTitleFont(43)
        diff.GetXaxis().SetTitleOffset(3.5)
        diff.GetXaxis().SetLabelSize(0.17)
        
        return diff


    # Plotting the different categories

    def setUpTitle(detector,label,plot):
        title = 'Material Budget %s [%s];%s;%s' % (detector,label,
                                                   plots[plot].abscissa,
                                                   plots[plot].ordinate)
        return title

    def setUpLegend(gOld,gNew,label):
        legend = TLegend(0.4,0.7,0.7,0.85)
        legend.AddEntry(gOld,"%s %s [%s]"%(detector,geometryOld,label),"F") #(F)illed Box
        legend.AddEntry(gNew,"%s %s [%s]"%(detector,geometryNew,label),"P") #(P)olymarker
        legend.SetTextFont(42)
        legend.SetTextSize(0.03)
        return legend

    def setRanges(h):
        legendSpace = 1. + 0.3 # 30%
        minX = h.GetXaxis().GetXmin()
        maxX = h.GetXaxis().GetXmax()
        minY = h.GetYaxis().GetXmin()
        maxY = h.GetBinContent(h.GetMaximumBin()) * legendSpace
        h.GetYaxis().SetRangeUser(minY, maxY)
        h.GetXaxis().SetRangeUser(minX, maxX)


    ########### Ratio ###########

    counter = 0
    legends = OrderedDict() #KeepAlive
    for label, [num, color, leg] in six.iteritems(hist_label_to_num):

        mainPad[counter].cd()
        oldHistos[label] = get1DHisto_(detector,
                                       num+plots[plot].plotNumber
                                       ,geometryOld)
        oldHistos[label].SetTitle(setUpTitle(detector,leg,plot))
        oldHistos[label].SetFillColor(color)
        oldHistos[label].SetLineColor(kBlack)
        oldHistos[label].SetLineWidth(1)
        setRanges(oldHistos[label])
        oldHistos[label].Draw("HIST")

        newHistos[label] = get1DHisto_(detector,
                                       num+plots[plot].plotNumber
                                       ,geometryNew)
        newHistos[label].SetMarkerSize(.5)
        newHistos[label].SetMarkerStyle(20)
        newHistos[label].Draw('SAME P')

        legends[label]= setUpLegend(oldHistos[label],newHistos[label],
                                    leg);
        legends[label].Draw()

        # Ratio
        subPad[counter].cd()
        ratioHistos[label] = makeRatio( newHistos[label],oldHistos[label] )
        ratioHistos[label] = setStyleHistoSubPad(ratioHistos[label])
        ratioHistos[label].Draw("HIST P")

        counter += 1

    theDirname = "Images"

    if not checkFile_(theDirname):
        os.mkdir(theDirname)
        
    canComparison.SaveAs( "%s/%s_ComparisonRatio_%s_%s_vs_%s.png"
                          % (theDirname,detector,plot,geometryOld,geometryNew) )

    ######## Difference ########

    canDiff = TCanvas("canDiff","canDiff",2400,1200)

    mainPadDiff, subPadDiff = setUpCanvas(canDiff)
 
    counter = 0
    for label, [num, color, leg] in six.iteritems(hist_label_to_num):
        mainPadDiff[counter].cd()
        oldHistos[label].SetTitle(setUpTitle(detector,leg,plot))
        oldHistos[label].Draw("HIST")
        newHistos[label].Draw('SAME P')

        legends[label].Draw()

        # Difference
        subPadDiff[counter].cd()
        diffHistos[label] = makeDiff( newHistos[label],oldHistos[label] )
        diffHistos[label] = setStyleHistoSubPad(diffHistos[label])
        diffHistos[label].SetTitle('')
        diffHistos[label].SetFillColor(color+1)
        diffHistos[label].Draw("HIST")
        counter +=1

    canDiff.SaveAs( "%s/%s_ComparisonDifference_%s_%s_vs_%s.png"
                          % (theDirname,detector,plot,geometryOld,geometryNew) )