Beispiel #1
0
            gr_minus.SetMarkerSize(3)
            gr_minus.SetMarkerStyle(21)
            gr_minus.SetMarkerColor(4)

            gr_plus.Draw("ep same")
            gr_minus.Draw("ep same")
            canvas.Update()

            axis = TGaxis(ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymin(),
                          ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymax(), 0, 2,
                          510, "+L")
            axis.SetTitle("Temperature (before - after) [degC]")
            axis.SetTitleOffset(1.5)
            axis.SetTitleFont(42)
            axis.SetLineColor(6)
            axis.SetTextColor(6)
            axis.SetLabelFont(42)
            axis.Draw()

            gr_temp.SetLineColor(6)
            gr_temp.SetLineWidth(4)
            gr_temp.SetMarkerSize(3)
            gr_temp.SetMarkerStyle(22)
            gr_temp.SetMarkerColor(6)

            label = ROOT.TLatex(0.68, 0.75, klayer)
            label.SetNDC()

            label2 = ROOT.TLatex(0.2, 0.93, "CMS")
            label2.SetNDC()
Beispiel #2
0
class Differential1D:

    """ Base class for displaying 1D differential plots.  

    Produces a plot comparing the baseline geometry (base) to the geometry specified by
    the geom arguement.  The quantity plotted is given by the "stat" option, and is
    limited to the different statistics created by the StarBASE application.  At present,
    these include:

    stat="radlen"  :: plots number of radiation lengths of material encountered
                      ... need to add more stats

    The plot will show a solid histogram for the baseline geometry, with the comparison
    geometry shown with red hashes.  The fractional difference (baseline-comp)/baseline
    is shown at the bottom in blue, scaled according to the alternate axis at the right.

    base:       selects the baseline geometry.                     [Mandatory]
    geom:       selects the comparison geometry.                   [Mandatory]
    volume:     selects the volume to be compared.                 [Mandatory]
    geomvolume: selects the volume in the comparison geometry.     [Default: same]
    stat:       selects the statistic to compare.                  [Default: radlen]
    xmin, xmax: x-axis range.                                      [Optional]
    ymin, ymax: y-axis range.                                      [Optional]
    """

    def __init__(self, 
                 base,                   geom,
                 volume="EMSS",          geomvolume="same",
                 stat="radlen",                    
                 xmin=+0.,                xmax=-1.,
                 ymin=+0.,                ymax=-1.,
                 canvas=0,
                 legend=False
                 ):

        self.name = volume
        self.base = base
        self.geom = geom

        baseFile = get_geom_file(base)                                       # get the files
        compFile = get_geom_file(geom)

        hname = "h_"+stat+"_"+volume+"_eta"                             # retrive the histograms from the files
        print "Get histo: " + str(hname)


        self.histo_base = stat_histo( stat, volume, file=baseFile )
        if ( geomvolume == "same" ):
            self.histo_comp = stat_histo( stat, volume, compFile )
        else:
            self.histo_comp = stat_histo( stat, geomvolume, compFile )

        self.histo_diff = self.histo_base.Clone( hname + "_diff" )      # difference the histograms
        self.histo_diff.Add( self.histo_comp, -1.0 )
        self.histo_diff.Divide(self.histo_base)                         # diff will be (old-new)/old * 100%

        if ( canvas == 0 ):
            canvas = TCanvas("temp"+base+geom+volume+geomvolume,"Differential 1D: baseline="+base+" compare="+geom,500,400);
            self.canvas = canvas

        # Detect and apply optional x-axis range
        if ( xmax > xmin ):
            self.histo_base.GetXaxis().SetRangeUser(xmin,xmax)
            self.histo_comp.GetXaxis().SetRangeUser(xmin,xmax)
        # ... or zoom in on an appropriate scale
        else:
#            auto_range( self.histo_base )
#            auto_range( self.histo_comp )
            xmin = auto_min( self.histo_base )
            xmax = auto_max( self.histo_base )
            self.histo_base.GetXaxis().SetRangeUser(xmin,xmax)
            self.histo_comp.GetXaxis().SetRangeUser(xmin,xmax)

#        xmin = TMath.Min( self.histo_base.GetXaxis().GetXmin(),self.histo_comp.GetXaxis().GetXmin() )
#        xmax = TMath.Max( self.histo_base.GetXaxis().GetXmax(),self.histo_comp.GetXaxis().GetXmax() )

#        print "xmin="+str(xmin)
#        print "xmax="+str(xmax)

        # Detect and apply optional y-axis range
        if ( ymax > ymin ):
            self.histo_base.GetYaxis().SetRangeUser(ymin,ymax)
        else:
            ymin = self.histo_base.GetMinimum()
            ymax = TMath.Max( self.histo_base.GetMaximum(),
                              self.histo_comp.GetMaximum())
            ymax *= 1.05

        # Current range in y-axis extends from 0 to ymax.  We want
        # to expand this to go from -0.2*ymax to ymax.
        ymin = -0.2 * ymax
        self.histo_base.GetYaxis().SetRangeUser(ymin,ymax)

        # Draw the baseline and comparison histograms
        self.histo_base.SetLineWidth(2)
        self.histo_base.SetFillStyle(1001)
        self.histo_base.SetFillColor(22)
        self.histo_base.Draw()

        self.histo_comp.SetLineColor(2)
        self.histo_comp.SetLineStyle(2)
        self.histo_comp.SetFillStyle(3345)
        self.histo_comp.SetFillColor(2)
        self.histo_comp.Draw("same")

        # Rescale difference histogram so that it is in percent
        self.histo_diff.Scale(100.0)

        # This is the maximum of the histogram.
        yfull_max = self.histo_diff.GetMaximum()
        yfull_min = self.histo_diff.GetMinimum()
        yfull = TMath.Max( yfull_max, TMath.Abs( yfull_min ) )
        self.max_differential = yfull

        yfull *= 1.3

        if ( yfull == 0. ):
            yfull = 1.0

        # We need to rescale the histogram so that it fits w/in 10% of ymax
        self.histo_diff.Scale( 0.10 * ymax / yfull )

        # Next we shift the histogram down by 0.1 * ymax
        nbinx=self.histo_diff.GetNbinsX();
        i=1
        while ( i<=nbinx ):
            self.histo_diff[i] -= 0.1 * ymax
            i+=1
        
        # Reset the line color and draw on the same plot
        self.histo_diff.SetLineColor(4)
        self.histo_diff.Draw("same")

        self.line = TLine(xmin, -0.1 * ymax, xmax, -0.1*ymax )
        self.line.SetLineStyle(3)
        self.line.Draw()

        # And superimpose an axis on the  new plot
        xa = xmax

        self.axis = TGaxis( xa, -0.2*ymax, xa, 0.0, -yfull, +yfull, 50510, "-+L" )
        self.axis.SetLabelSize(0.03)
        self.axis.SetLabelOffset(-0.02)
        self.axis.SetLineColor(4)
        self.axis.SetTextColor(4)
        self.axis.SetLabelColor(4)
        self.axis.SetNdivisions(4)
#       self.axis.SetTitle("(base-comp)/base [%]")
        self.axis.SetTitleSize(0.0175)
        self.axis.SetTitleOffset(-0.5)
        self.axis.Draw();

        # Add the legend if requested
        if ( legend ):
            self.legend = TLegend( 0.78, 0.80, 0.98, 0.98 )
            self.legend.AddEntry( self.histo_base, base )
            self.legend.AddEntry( self.histo_comp, geom )
            self.legend.AddEntry( self.histo_diff, "#frac{"+base+"-"+geom+"}{"+base+"} [%]" )
            self.legend.Draw()