Пример #1
0
def _project(tree,
             var,
             selection='',
             weight=1.0,
             bins=None,
             includeover=False):

    h = None
    if var.count(':') == 0:
        ## Hist (1D)
        if bins:
            if isinstance(bins, tuple):
                assert len(bins) == 3
                h = Hist(*bins)
            elif isinstance(bins, list):
                h = Hist(bins)
            else:
                assert False
        else:
            assert False
    elif var.count(':') == 1:
        ## Hist2D
        ## like rootpy, we use a convention where var=x:y, unlike ROOT
        varx, vary = var.split(':')
        var = ':'.join([vary, varx])
        if bins:
            if isinstance(bins, tuple):
                assert len(bins) == 6
                h = Hist2D(*bins)
            elif isinstance(bins, list):
                ## TODO: support variable bins for Hist2D
                h = Hist2D(*bins)
                #assert False
            else:
                assert False
        else:
            assert False
    else:
        assert False

    assert h
    #            kwargs['hist'] = h

    ## add the weight to the selection via a TCut
    weighted_selection = str(selection)
    if weight and weight != 1.0:
        weighted_selection = Cut(weighted_selection)
        weighted_selection = weighted_selection * weight
        weighted_selection = str(weighted_selection)

    tree.Draw('%s>>%s' % (var, h.GetName()), weighted_selection)

    ##    print tree.GetSelectedRows() ## debuging

    #    for event in t:
    #        x = getattr(event, var)
    #        h.fill(x)

    if h:
        h.SetDirectory(0)

        #        elist = ROOT.gDirectory.Get('elist')
        #        elist.Print('all')

        if var.count(':') == 0 and includeover:
            ## include overflow for Hist (1D)
            nbins = h.GetNbinsX()
            c1 = h.GetBinContent(nbins)
            c2 = h.GetBinContent(nbins + 1)
            e1 = h.GetBinError(nbins)
            e2 = h.GetBinError(nbins + 1)
            h.SetBinContent(nbins, c1 + c2)
            h.SetBinError(
                nbins,
                math.sqrt((c1 * e1 * e1 + c2 * e2 * e2) /
                          (c1 + c2)) if c1 + c2 != 0.0 else 0.0)
            h.SetBinContent(nbins + 1, 0.0)
            h.SetBinError(nbins + 1, 0.0)

    return h
Пример #2
0
    sci_trigger_r_obj.t_trigger.get_entry(i)
    if not sci_trigger_r_obj.t_trigger.abs_gps_valid: continue
    trigger_hist.fill((sci_trigger_r_obj.t_trigger.abs_gps_week -
                       sci_trigger_r_obj.start_week) * 604800 +
                      (sci_trigger_r_obj.t_trigger.abs_gps_second -
                       sci_trigger_r_obj.start_second))
    for j in xrange(25):
        if sci_trigger_r_obj.t_trigger.trig_accepted[j]:
            modules_hist[j].fill((sci_trigger_r_obj.t_trigger.abs_gps_week -
                                  sci_trigger_r_obj.start_week) * 604800 +
                                 (sci_trigger_r_obj.t_trigger.abs_gps_second -
                                  sci_trigger_r_obj.start_second))

for i in xrange(1, nbins + 1):
    trigger_hist.SetBinContent(i, trigger_hist.GetBinContent(i) / args.bw)
    trigger_hist.SetBinError(i, trigger_hist.GetBinError(i) / args.bw)
    for j in xrange(25):
        modules_hist[j].SetBinContent(
            i, modules_hist[j].GetBinContent(i) / args.bw)
        modules_hist[j].SetBinError(i,
                                    modules_hist[j].GetBinError(i) / args.bw)
print ' - drawing ... '
y_max = 0
for i in xrange(25):
    if modules_hist[i].GetMaximum() > y_max:
        y_max = modules_hist[i].GetMaximum()
for i in xrange(25):
    modules_hist[i].SetMaximum(y_max * 1.1)

canvas_trigger = Canvas(1000,
                        800,