Beispiel #1
0
def init():
    draw.set_default()
    # gStyle.SetTitleX(0.4)
    gStyle.SetTitleY(0.93)
    gStyle.SetStatColor(ROOT.kWhite)
Beispiel #2
0
def det_card(cards,detector,T0_error,t_range=10,T0_file=None):

    draw.set_default()

    nbins = 2 * (14,11)[detector[4]=='Y']
    name = '%6.6s_card_T0' % detector
    h = book_hist_det_card(name,name[:6],nbins)
    
    t0s = []
    n_points = {}
    n=0
    for name,card in cards.items():
        if name[:6]!=detector[:6]:
            continue
        bin = set_histogram_bin(h,name,card,T0_error)
        n_points[bin] = card.n_points
        
        t0s.append(card.T0)
        n += 1

    if not t0s:
        return h    # The histogram is empty!

    t0s.sort()
    t0s_median = t0s[len(t0s)/2]

    h().SetMinimum(t0s_median-t_range/2.)
    h().SetMaximum(t0s_median+t_range/2.)

    if T0_file:

        T0_file.write('\\begin{figure}[t]\n')
        T0_file.write('\\centering\n')
        T0_file.write('\\caption{Distribution of $T_0^u$ and $T_0^d$ values for {\\bf %s} detector.}\n' % detector)
        T0_file.write('\\label{fig:T0-%s}\n' % detector)
        T0_file.write('\\epsfxsize=355pt \\epsfbox{%s_card_T0.eps}\n' % detector)
        T0_file.write('\\end{figure}\n\n')

        T0_file.write('\\begin{table}[b]\n')
        T0_file.write('\\centering\n')
        T0_file.write('\\tiny\n')
        T0_file.write('\\caption{List of $T_0^u$ and $T_0^d$ for {\\bf %s} detector.}\n' % detector)
        T0_file.write('\\label{tbl:T0-%s}\n' % detector)
        T0_file.write('\\begin{tabular}{|c|c|c|c|c|c|c|} \\hline\n')
        T0_file.write('card & layer & data & $T_0$ & $|T_0^u-T_0^d|$ & $T_0^c$ & comment \\\\ \\hline\\hline\n')

        for bin in range(1,h().GetXaxis().GetNbins()+1,2):

            # Number of V-plot points
            n_ud=['\\ ','\\ ']
            for ud in range(2):
                try:
                    n_ud[ud] = latex_number(n_points[bin+ud])
                except:
                    pass

            # T0
            t0_u = '\\ '
            t0_d = '\\ '

            card = '\\ '

            label = h().GetXaxis().GetBinLabel(bin)
            if label:
                t0_u  = '%.2f' % h().GetBinContent(bin)
                

            label2 = h().GetXaxis().GetBinLabel(bin+1)
            if label2:
                t0_d  = '%.2f' % h().GetBinContent(bin+1)

            if not label:
                label = label2
            if label:
                n = label.find('mm-')
                if n<0:
                    print label
                card  = label[n+4:]
                label = label[:n+2]
                comment = '\\card%scomment' % aNUM(card)
            else:
                comment = ''

            if card=='\\ ':
                card = get_card_number(detector,bin)

            if not '\\ ' in [t0_u,t0_d]:
                dT     = '%.2f' % abs(h().GetBinContent(bin)-h().GetBinContent(bin+1))
                t0_avr = '%.2f' % ((h().GetBinContent(bin)+h().GetBinContent(bin+1))/2)
            else:
                dT     = ''
                t0_avr = ''

            #T0_file.write('%4s & %6s & %8s & %8s & %8s &  \\\\ \\hline \n' %
            #              (card,label,t0_u,t0_d,dT) )
            T0_file.write('\\parbox{11ex}{\\vspace{.7ex}%s \\newline %s\\vspace{.7ex}} & \n' % (card,label) )
            T0_file.write('\\parbox{2ex}{u  \\newline  d} & \n')
            T0_file.write('\\parbox{11ex}{%s \\newline %s} & \n' % (n_ud[0],n_ud[1]) )
            T0_file.write('\\parbox{11ex}{%s \\newline %s} & \n' % (t0_u,t0_d) )
            T0_file.write('%s &' % dT)
            T0_file.write('\\card%ssoft & %% t0_avr %s for %s %s\n' % ( (aNUM(card),0)[not card] ,t0_avr,detector,card) )
            T0_file.write('\\parbox{40ex}{%s}  %% card %s \n' % (comment,card) )
            T0_file.write('%%\\newcommand{\\card%scomment}{} %% %s %s\n' % (aNUM(card),detector,card) )
            T0_file.write('%%\\newcommand{\\card%ssoft}{}  %% %s %s %s  \n' % (aNUM(card),t0_avr,detector,card) )
            T0_file.write('\\\\ \\hline\n')

        T0_file.write('\\end{tabular}\n')
        T0_file.write('\\end{table}\n\n')
        T0_file.write('\\clearpage\n\n')

    return h
Beispiel #3
0
        t0s_diff[detector][card] = T0 - coral_T0[detector]

    hist = h['coral_t0_diff_det']()
    bin=1
    for det,cards in t0s_diff.items():
        for card,T0_diff in cards.items():
            hist.SetBinContent(bin,T0_diff)
            hist.SetBinError(bin,t0_error)
            hist.GetXaxis().SetBinLabel(bin,'%s %d' % (det,card))
            bin = bin+1

    return h

if __name__=='__main__':
    ROOT.gROOT.SetBatch(1)
    draw.set_default()
    
    try:
        import optparse
    except:
        sys.path.append('/afs/cern/ch/user/z/zviagine/public/local/lib')
        import optparse

    parser = optparse.OptionParser()
    draw.optparse_parameters(parser,'eps','400x300')
    parser.add_option('', '--dir',dest='dir',default='./',
                      help='Directory with the root files [default: "%default"]', type='string',metavar='PATH')

    parser.usage = '%prog [options] <cards.tex> <coral-t0.txt> <t0_error>'
    parser.description = 'Create plots for CORAL:T0 CARDS:T0 difference.'
Beispiel #4
0
def Vs_plot(geo,d='./',plot_print=draw.Plot()):

    draw.set_default()

    Vud = {}

    files = {}

    for f in os.listdir(d):
        r = re.match('T0_(?P<det>........)_geoID(?P<geo>\d+)\.root',f)
        
        if not r:
            continue
        if int(r.group('geo'))!=geo:
            continue

        # OK, file matches
        detector = r.group('det')
        ud = detector[6]    # either 'u' od 'd'
        if ud not in 'ud':
            print 'Bad detector name: %s' % detector

        if Vud.has_key(ud):
            raise 'Attempt to add a second "%s" detector="%s"!' % (ud,detector)

        Vud[ud] = {}
        Vud[ud]['det' ] = detector[:6]+detector[7:]     # Detector name without 'u' or 'd'
        Vud[ud]['file'] = os.path.join(d,f)

    if len(Vud)!=2:
        print 'Not all files (must be 2, found %d) are available for card=%d!' % (len(Vud),geo)
        return
        
    if Vud['u']['det']!=Vud['d']['det']:
        print 'Print detector names are different!! "%s"!="%s"' % (Vud['u']['det'],Vud['d']['det'])
        return
    else:
        detector = Vud['u']['det']
    
    canvas_name = 'Vs_%s_card%d' % (detector,geo)
    ROOT.gStyle.SetPadLeftMargin(0.2)
    c = TCanvas(canvas_name,canvas_name,plot_print.size_x,plot_print.size_y)
    c.Divide(2,1)

    objs = {}
    
    for i in range(2):
        ud = 'ud'[i]
        V = Vextract.get_V(Vud[ud]['file'])
        objs['V'+ud] = V['TH2F']
        objs['RT'+ud] = V['TGraph']
        c.cd(i+1)
        #Vextract.draw_V_RT(V['TH2F'],V['TGraph'])
        
        V_draw  = setV_opts(V['TH2F'],Vud[ud]['det'],geo)
        RT_draw = setRT_opts(V['TGraph'])
        
        V_draw.Draw()
        RT_draw.Draw()

    c.cd(0)
    plot_print.make(c)
    objs[c.GetName()] = c
    
    return objs