コード例 #1
0
ファイル: GetScalers.py プロジェクト: ktf/AliPhysics
def GetTriggerScalers(filename):
    inputfile = TFile.Open(filename)
    inputfile.cd("PtEMCalTriggerTask")
    gDirectory.ls()
    tasklist = gDirectory.Get("results")
    histlist = tasklist.FindObject("histosPtEMCalTriggerHistograms")
    gROOT.cd()
    triggerhist = histlist.FindObject("hEventTriggers")
    inputfile.Close()
    
    # Get number of Min. Bias counts
    mbcounts = GetCounts(triggerhist, "MinBias")
    print "MinBias counts: %d" %(mbcounts)

    triggerhist.GetAxis(0).SetRange(2,2)
    triggercounts = {}
    for trigger in triggerlookup.keys():
        if trigger == "MinBias":
            continue
        triggercounts[trigger] = GetCounts(triggerhist, trigger)
        print "Number of events for trigger %s: %d" %(trigger, triggercounts[trigger])
    
    hScalers = TH1D("triggerScalers", "trigger scalers", len(triggercounts), -0.5, len(triggercounts) - 0.5)
    counter = 1
    for trigger in triggercounts.keys():
        scaler = float(mbcounts)/float(triggercounts[trigger])
        print "Scaler for trigger %s: %f" %(trigger, scaler)
        hScalers.GetXaxis().SetBinLabel(counter, trigger)
        hScalers.SetBinContent(counter, scaler)
        counter += 1
        
    outputfile = TFile("TriggerScalers.root", "RECREATE")
    outputfile.cd()
    hScalers.Write()
    outputfile.Close()
コード例 #2
0
def printGDirectory():
    print ">>> gDirectory.GetName()\n%s" % gDirectory.GetName()
    print ">>> gDirectory.pwd()"
    gDirectory.pwd()
    print ">>> gDirectory.ls()"
    gDirectory.ls()
    print
コード例 #3
0
def GetTriggerScalers(filename):
    inputfile = TFile.Open(filename)
    inputfile.cd("PtEMCalTriggerTask")
    gDirectory.ls()
    tasklist = gDirectory.Get("results")
    histlist = tasklist.FindObject("histosPtEMCalTriggerHistograms")
    gROOT.cd()
    triggerhist = histlist.FindObject("hEventTriggers")
    inputfile.Close()

    # Get number of Min. Bias counts
    mbcounts = GetCounts(triggerhist, "MinBias")
    print "MinBias counts: %d" % (mbcounts)

    triggerhist.GetAxis(0).SetRange(2, 2)
    triggercounts = {}
    for trigger in triggerlookup.keys():
        if trigger == "MinBias":
            continue
        triggercounts[trigger] = GetCounts(triggerhist, trigger)
        print "Number of events for trigger %s: %d" % (trigger,
                                                       triggercounts[trigger])

    hScalers = TH1D("triggerScalers", "trigger scalers", len(triggercounts),
                    -0.5,
                    len(triggercounts) - 0.5)
    counter = 1
    for trigger in triggercounts.keys():
        scaler = float(mbcounts) / float(triggercounts[trigger])
        print "Scaler for trigger %s: %f" % (trigger, scaler)
        hScalers.GetXaxis().SetBinLabel(counter, trigger)
        hScalers.SetBinContent(counter, scaler)
        counter += 1

    outputfile = TFile("TriggerScalers.root", "RECREATE")
    outputfile.cd()
    hScalers.Write()
    outputfile.Close()
コード例 #4
0
def main(options, args):
    from ROOT import gROOT
    gROOT.SetBatch(options.batch)

    from lip.Tools.rootutils import loadToolsLib, getQuantilesGraphs, apply_modifs, xtitle, ytitle
    loadToolsLib()

    from ROOT import TCut, TCanvas, gDirectory, gPad, kRed, kBlue, kWhite, setStyle, gStyle, TLegend, HtmlHelper, HtmlTag, HtmlTable, HtmlPlot, TPaveText, kOpenCircle, TF1, TLine
    setStyle()
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)

    print "Getting list of files"
    files = getListOfFiles(options.indir, options.filePattern)

    chain = mkChain(files, options.treename)
    ## chain = mkChain(files[0:100],options.treename)
    ## chain = mkChain(files[0:1],options.treename)

    hth = HtmlHelper(options.outdir)
    hth.header().addobj(HtmlTag("link")).set("rel", "stylesheet").set(
        "type", "text/css").set("href", "../res/style.css")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../../res/jquery.js").txt(" ")
    hth.header().addobj(HtmlTag("script")).set("language", "javascript").set(
        "type", "text/javascript").set("src", "../res/style.js").txt(" ")
    hth.navbar().cell(HtmlTag("a")).firstChild().txt("..").set(
        "href", "../?C=M;O=D")
    wptag = hth.body().addobj(HtmlTag("pre"))
    tab = hth.body().add(HtmlTable())

    quants = {}
    objs = []

    var, binning = options.variable.split(":")
    limits = [float(i) for i in binning.split(",")[1:]]
    delta = 0.1 * max(abs(limits[0]), abs(limits[1]))
    limits[0] -= delta
    limits[1] += delta

    xlab = "p_{T} (GeV)"
    if options.vsnvtx:
        xlab = "N_{PV}"
    sig_style = [("SetLineColor", kBlue), ("SetMarkerColor", kBlue),
                 (xtitle, xlab), (ytitle, "%s cut" % var), ("SetFillStyle", 0),
                 ("SetMarkerColor", kOpenCircle)]
    bkg_style = [("SetLineColor", kRed), ("SetMarkerColor", kRed),
                 (xtitle, xlab), (ytitle, "%s cut" % var), ("SetFillStyle", 0)]
    lab_style = [("SetFillColor", kWhite), ("SetShadowColor", kWhite),
                 ("SetLineColor", kWhite), ("SetFillStyle", 0)]

    fitl = TF1("fitl", "pol1", 12, 19)
    fitr = TF1("fitl", "pol1", 20, 35)
    fita = TF1("fita", "pol1", 15, 25)

    ## wps = { "loose":[0,0.05,0.1,0.1,0.1], "medium":[0,0.10,0.2,0.2,0.2], "tight":[1,0.95,0.9,0.9,0.9] }
    wps = {
        "loose": [0, 0.05, 0.05, 0.05, 0.05],
        "medium": [0, 0.1, 0.1, 0.1, 0.1],
        "tight": [0, 0.2, 0.2, 0.2, 0.2]
    }
    if options.chs:
        wps = {
            "loose": [0, 0.02, 0.1, 0.1, 0.1],
            "medium": [0, 0.05, 0.2, 0.2, 0.2],
            "tight": [1, 0.95, 0.9, 0.9, 0.9]
        }
    wpf = {}
    for a in wps.keys():
        wpf[a] = {}
    wpref = 20.

    icat = 0
    for cut, name, vars in options.categories:
        print "Making TH2 ", name

        icat += 1
        vtxbins = [(10, 20), (20, 999), (1, 999)]
        if options.integrateall:
            vtxbins = [(1, 999)]
        ivtx = 0
        for vtx in vtxbins:
            print(name, ) + vtx
            hname = "%s_%d_%d" % ((name, ) + vtx)

            vtxcut = TCut("nvtx > %d && nvtx < %d" % vtx)

            if options.vsnvtx:
                chain.Draw(
                    "%s:nvtx>>h_sig_%s(50,0.5,50.5,%s)" %
                    (var, hname, binning),
                    TCut("jetPt>20") * vtxcut * TCut(cut) *
                    TCut(options.sigcut), "colz goff")
                chain.Draw(
                    "%s:nvtx>>h_bkg_%s(50,0.5,50.5,%s)" %
                    (var, hname, binning),
                    TCut("jetPt>20") * vtxcut * TCut(cut) *
                    TCut(options.bkgcut), "colz goff")
            else:
                chain.Draw(
                    "%s:jetPt>>h_sig_%s(25,10,60,%s)" % (var, hname, binning),
                    vtxcut * TCut(cut) * TCut(options.sigcut), "colz goff")
                chain.Draw(
                    "%s:jetPt>>h_bkg_%s(25,10,60,%s)" % (var, hname, binning),
                    vtxcut * TCut(cut) * TCut(options.bkgcut), "colz goff")

            gDirectory.ls()
            h_sig = gDirectory.Get("h_sig_%s" % hname)
            h_bkg = gDirectory.Get("h_bkg_%s" % hname)

            print "Getting quantiles ", hname
            sig_qvals = [0.1, 0.2, 0.3, 0.5, 0.02, 0.05, 0.15]
            bkg_qvals = [0.4, 0.7, 0.6, 0.8, 0.9, 0.95, 0.9]
            quants[hname] = getQuantilesGraphs(h_sig,
                                               sig_qvals), getQuantilesGraphs(
                                                   h_bkg, bkg_qvals)

            for i in range(len(sig_qvals)):
                if options.integrateall:
                    quants[hname][0][i].SetTitle(
                        "%1.0f%% efficiency" % (((1. - sig_qvals[i]) * 100.)))
                    if options.vsnvtx:
                        quants[hname][0][i].Fit(fita.Clone(), "R+")
                    else:
                        quants[hname][0][i].Fit(fitl.Clone(), "R+")
                        quants[hname][0][i].Fit(fitr.Clone(), "R+")
                    for wpn, wp in wps.iteritems():
                        if wp[0] == 0 and wp[icat] == sig_qvals[i]:
                            wpf[wpn]["%d_%s" % (icat, name)] = quants[hname][
                                0][i].GetListOfFunctions(
                                ), quants[hname][0][i].GetTitle()
                else:
                    quants[hname][0][i].SetTitle(
                        "%1.0f%% efficiency %d<N_{PV}<%d" %
                        (((1. - sig_qvals[i]) * 100., ) + vtx))
                style = sig_style + [("SetLineColor", kBlue - 2 * ivtx),
                                     ("SetMarkerColor", kBlue - 2 * ivtx)]
                apply_modifs(quants[hname][0][i], style)
                for f in quants[hname][0][i].GetListOfFunctions():
                    apply_modifs(f, style)

            for i in range(len(bkg_qvals)):
                if options.integrateall:
                    quants[hname][1][i].SetTitle("%1.0f%% rejection" %
                                                 ((bkg_qvals[i] * 100.)))
                    if options.vsnvtx:
                        quants[hname][1][i].Fit(fita.Clone(), "R+")
                    else:
                        quants[hname][1][i].Fit(fitl.Clone(), "R+")
                        quants[hname][1][i].Fit(fitr.Clone(), "R+")
                    for wpn, wp in wps.iteritems():
                        if wp[0] == 1 and wp[icat] == bkg_qvals[i]:
                            wpf[wpn]["%d_%s" % (icat, name)] = quants[hname][
                                1][i].GetListOfFunctions(
                                ), quants[hname][1][i].GetTitle()
                else:
                    quants[hname][1][i].SetTitle(
                        "%1.0f%% rejection  %d<N_{PV}<%d" %
                        ((bkg_qvals[i] * 100., ) + vtx))
                style = bkg_style + [("SetLineColor", kRed - 2 * ivtx),
                                     ("SetMarkerColor", kRed - 2 * ivtx)]
                apply_modifs(quants[hname][1][i], style)
                for f in quants[hname][1][i].GetListOfFunctions():
                    apply_modifs(f, style)
            ivtx += 1

        chain.Draw("nvtx>>h_nvtx_%s(50,0.5,50.5)" % (hname),
                   TCut(cut) * TCut(options.sigcut), "goff")
        canv = TCanvas("%s_nvtx" % (name), ("%s" % (name)), 800, 1000)
        canv.cd()
        h_nvtx = gDirectory.Get("h_nvtx_%s" % hname)
        line = TLine(h_nvtx.GetMean(), 0., h_nvtx.GetMean(),
                     h_nvtx.GetMaximum())
        h_nvtx.Draw("hist")
        line.Draw("same")
        objs.append(line)
        objs.append(canv)
        tab.row().cell(HtmlPlot(canv, False, "", True, True, True))

        nvals = len(sig_qvals)
        plotsperline = 4
        for i in range(nvals):
            if i % plotsperline == 0:
                row = tab.row()
            canv = TCanvas("%s_%d" % (name, i), ("%s_%d" % (name, i)), 800,
                           1000)
            canv.SetGridx(), canv.SetGridy()

            first = True
            for vtx in vtxbins:
                kname = "%s_%d_%d" % ((name, ) + vtx)
                if first:
                    quants[kname][0][i].Draw("ap")
                else:
                    quants[kname][0][i].Draw("p")
                quants[kname][1][i].Draw("p")
                quants[kname][0][i].GetYaxis().SetLimits(limits[0], limits[1])
                quants[kname][0][i].GetYaxis().SetRangeUser(
                    limits[0], limits[1])

                if first:
                    leg1 = TLegend(0.2, 0.95, 0.5, 1.0)
                    apply_modifs(leg1, lab_style)
                    leg2 = TLegend(0.5, 0.95, 0.8, 1.0)
                    apply_modifs(leg2, lab_style)
                    first = False

                leg1.AddEntry(quants[kname][0][i], "", "lp")
                leg2.AddEntry(quants[kname][1][i], "", "lp")

            leg1.Draw("SAME")
            leg2.Draw("SAME")

            lab = TPaveText(0.1, 0.95, 0.2, 1.0, "brNDC")
            apply_modifs(lab, lab_style)
            lab.AddText(name)
            lab.Draw("SAME")

            row.cell(HtmlPlot(canv, False, "", True, True, True))
            objs.append(lab)
            objs.append(leg1)
            objs.append(leg2)
            objs.append(canv)

    wpstr = "Working points\n"
    wpstr += "--------------\n"
    for wpn, wpfs in wpf.iteritems():
        wpstr += "\n%s\n" % wpn
        wpstr += "-------\n"
        keys = wpfs.keys()
        keys.sort()
        ## for cat,val in wpfs.iteritems():
        ##    funcs,tit = val
        for cat in keys:
            funcs, tit = wpfs[cat]
            wpstr += ("%s (%s) " % (cat.ljust(8), tit.ljust(14)))
            for f in funcs:
                if options.vsnvtx:
                    wpstr += "%1.0f-%1.0f: %1.3f " % (f.GetXmin(), f.GetXmax(),
                                                      f.GetParameter(1))
                else:
                    wpstr += "%1.0f-%1.0f: %1.2f " % (f.GetXmin(), f.GetXmax(),
                                                      f.Eval(wpref))
            wpstr += "\n"
    wptag.txt(str(wpstr))

    if not os.path.isdir(options.outdir):
        os.mkdir(options.outdir)
    hth.dump()

    return quants, objs
コード例 #5
0
ファイル: calcWp.py プロジェクト: anantoni/CMG
def main(options, args):
    from ROOT import gROOT
    gROOT.SetBatch(options.batch)

    from lip.Tools.rootutils import loadToolsLib, getQuantilesGraphs, apply_modifs, xtitle, ytitle
    loadToolsLib()

    from ROOT import TCut, TCanvas, gDirectory, gPad, kRed, kBlue, kWhite, setStyle, gStyle, TLegend, HtmlHelper, HtmlTag, HtmlTable, HtmlPlot, TPaveText, kOpenCircle, TF1, TLine
    setStyle()
    gStyle.SetOptStat(0)
    gStyle.SetOptFit(0)
    

    print "Getting list of files"
    files = getListOfFiles(options.indir,options.filePattern)
    
    chain = mkChain(files,options.treename)
    ## chain = mkChain(files[0:100],options.treename)
    ## chain = mkChain(files[0:1],options.treename)
    
    hth = HtmlHelper(options.outdir)
    hth.header().addobj( HtmlTag("link") ).set("rel","stylesheet").set("type","text/css").set("href","../res/style.css")  
    hth.header().addobj( HtmlTag("script") ).set("language","javascript").set("type","text/javascript").set("src","../../res/jquery.js").txt(" ")
    hth.header().addobj( HtmlTag("script") ).set("language","javascript").set("type","text/javascript").set("src","../res/style.js").txt(" ")
    hth.navbar().cell( HtmlTag("a") ).firstChild().txt("..").set("href","../?C=M;O=D")
    wptag = hth.body().addobj( HtmlTag("pre") )
    tab = hth.body().add( HtmlTable() )
    
    quants = { }
    objs = []
    
    var,binning = options.variable.split(":")
    limits = [ float(i) for i in  binning.split(",")[1:] ]
    delta = 0.1*max( abs(limits[0]),  abs(limits[1]))
    limits[0] -= delta
    limits[1] += delta

    xlab = "p_{T} (GeV)"
    if options.vsnvtx:
            xlab = "N_{PV}"
    sig_style = [ ("SetLineColor",kBlue), ("SetMarkerColor",kBlue), (xtitle,xlab), (ytitle,"%s cut" % var), ("SetFillStyle",0),  ("SetMarkerColor",kOpenCircle) ]
    bkg_style = [ ("SetLineColor",kRed), ("SetMarkerColor",kRed), (xtitle,xlab), (ytitle,"%s cut" % var), ("SetFillStyle",0) ]
    lab_style = [ ("SetFillColor",kWhite), ("SetShadowColor",kWhite), ("SetLineColor",kWhite), ("SetFillStyle",0) ]

    fitl =  TF1("fitl","pol1",12,19)
    fitr =  TF1("fitl","pol1",20,35)
    fita =  TF1("fita","pol1",15,25)

    ## wps = { "loose":[0,0.05,0.1,0.1,0.1], "medium":[0,0.10,0.2,0.2,0.2], "tight":[1,0.95,0.9,0.9,0.9] }
    wps = { "loose":[0,0.05,0.05,0.05,0.05], "medium":[0,0.1,0.1,0.1,0.1], "tight":[0,0.2,0.2,0.2,0.2] }
    if options.chs:
        wps = { "loose":[0,0.02,0.1,0.1,0.1], "medium":[0,0.05,0.2,0.2,0.2], "tight":[1,0.95,0.9,0.9,0.9] }
    wpf = { }
    for a in wps.keys():
        wpf[a] = {}
    wpref = 20.

    icat = 0
    for cut,name,vars in options.categories:
        print "Making TH2 ", name

        icat += 1
        vtxbins = [  (10,20), (20,999), (1,999) ]
        if options.integrateall:
            vtxbins = [  (1,999) ]
        ivtx = 0
        for vtx in vtxbins:
            print ( name, )+vtx
            hname = "%s_%d_%d" % ( ( name, )+vtx )

            vtxcut = TCut("nvtx > %d && nvtx < %d" % vtx)

            if options.vsnvtx:
                chain.Draw("%s:nvtx>>h_sig_%s(50,0.5,50.5,%s)" % (var, hname, binning), TCut("jetPt>20")*vtxcut*TCut(cut)*TCut(options.sigcut), "colz goff")
                chain.Draw("%s:nvtx>>h_bkg_%s(50,0.5,50.5,%s)" % (var, hname, binning), TCut("jetPt>20")*vtxcut*TCut(cut)*TCut(options.bkgcut), "colz goff")
            else:
                chain.Draw("%s:jetPt>>h_sig_%s(25,10,60,%s)" % (var, hname, binning), vtxcut*TCut(cut)*TCut(options.sigcut), "colz goff")
                chain.Draw("%s:jetPt>>h_bkg_%s(25,10,60,%s)" % (var, hname, binning), vtxcut*TCut(cut)*TCut(options.bkgcut), "colz goff")

            gDirectory.ls()
            h_sig = gDirectory.Get("h_sig_%s" % hname)
            h_bkg =  gDirectory.Get("h_bkg_%s" % hname)
            
            print "Getting quantiles ", hname 
            sig_qvals = [0.1,0.2,0.3,0.5,0.02 ,0.05, 0.15]
            bkg_qvals = [0.4,0.7,0.6,0.8,0.9 , 0.95, 0.9 ]
            quants[hname] = getQuantilesGraphs(h_sig,sig_qvals), getQuantilesGraphs(h_bkg,bkg_qvals)
            
            for i in range(len(sig_qvals)):
                if options.integrateall:
                    quants[hname][0][i].SetTitle("%1.0f%% efficiency" % (((1.-sig_qvals[i])*100.) ))
                    if options.vsnvtx:
                        quants[hname][0][i].Fit(fita.Clone(),"R+")
                    else:
                        quants[hname][0][i].Fit(fitl.Clone(),"R+")
                        quants[hname][0][i].Fit(fitr.Clone(),"R+")
                    for wpn,wp in wps.iteritems():
                        if wp[0] == 0 and wp[icat] == sig_qvals[i]:
                            wpf[wpn]["%d_%s" % (icat,name)] = quants[hname][0][i].GetListOfFunctions(),quants[hname][0][i].GetTitle()
                else:
                    quants[hname][0][i].SetTitle("%1.0f%% efficiency %d<N_{PV}<%d" % (((1.-sig_qvals[i])*100.,)+vtx) )
                style = sig_style+[("SetLineColor",kBlue-2*ivtx), ("SetMarkerColor",kBlue-2*ivtx)]
                apply_modifs(quants[hname][0][i], style)
                for f in quants[hname][0][i].GetListOfFunctions():
                    apply_modifs(f,style)

            
            for i in range(len(bkg_qvals)):
                if options.integrateall:
                    quants[hname][1][i].SetTitle("%1.0f%% rejection" % ((bkg_qvals[i]*100.) ))
                    if options.vsnvtx:
                        quants[hname][1][i].Fit(fita.Clone(),"R+")
                    else:
                        quants[hname][1][i].Fit(fitl.Clone(),"R+")
                        quants[hname][1][i].Fit(fitr.Clone(),"R+")
                    for wpn,wp in wps.iteritems():
                        if wp[0] == 1 and wp[icat] == bkg_qvals[i]:
                            wpf[wpn]["%d_%s" % (icat,name)] = quants[hname][1][i].GetListOfFunctions(),quants[hname][1][i].GetTitle()
                else:
                    quants[hname][1][i].SetTitle("%1.0f%% rejection  %d<N_{PV}<%d" % ((bkg_qvals[i]*100.,)+vtx) );
                style = bkg_style+[("SetLineColor",kRed-2*ivtx), ("SetMarkerColor",kRed-2*ivtx)] 
                apply_modifs(quants[hname][1][i],style)
                for f in quants[hname][1][i].GetListOfFunctions():
                    apply_modifs(f,style)
            ivtx += 1

        chain.Draw("nvtx>>h_nvtx_%s(50,0.5,50.5)"% (hname), TCut(cut)*TCut(options.sigcut), "goff")
        canv   = TCanvas("%s_nvtx"%(name),("%s"%(name)),800,1000)
        canv.cd()
        h_nvtx = gDirectory.Get("h_nvtx_%s"%hname)
        line = TLine(h_nvtx.GetMean(),0.,h_nvtx.GetMean(),h_nvtx.GetMaximum())
        h_nvtx.Draw("hist")
        line.Draw("same")
        objs.append(line)
        objs.append(canv)
        tab.row().cell( HtmlPlot(canv,False,"",True,True,True) )

        nvals = len(sig_qvals)
        plotsperline = 4
        for i in range(nvals):
            if i % plotsperline == 0:
                row = tab.row()
            canv   = TCanvas("%s_%d"%(name,i),("%s_%d"%(name,i)),800,1000)
            canv.SetGridx(), canv.SetGridy()

            first = True
            for vtx in vtxbins:
                kname = "%s_%d_%d" % ( ( name, )+vtx )
                if first:
                    quants[kname][0][i].Draw("ap")
                else:
                    quants[kname][0][i].Draw("p")
                quants[kname][1][i].Draw("p")
                quants[kname][0][i].GetYaxis().SetLimits(limits[0],limits[1])
                quants[kname][0][i].GetYaxis().SetRangeUser(limits[0],limits[1])

                if first:
                    leg1 = TLegend(0.2,0.95,0.5,1.0)
                    apply_modifs(leg1,lab_style)
                    leg2 = TLegend(0.5,0.95,0.8,1.0)
                    apply_modifs(leg2,lab_style)
                    first = False
                    
                leg1.AddEntry(quants[kname][0][i],"","lp")
                leg2.AddEntry(quants[kname][1][i],"","lp")
                
            leg1.Draw("SAME")
            leg2.Draw("SAME")
            
            lab = TPaveText(0.1,0.95,0.2,1.0,"brNDC")
            apply_modifs(lab,lab_style)
            lab.AddText(name)
            lab.Draw("SAME")

            row.cell( HtmlPlot(canv,False,"",True,True,True) )
            objs.append(lab)
            objs.append(leg1)
            objs.append(leg2)
            objs.append(canv)
            
    wpstr  = "Working points\n"
    wpstr += "--------------\n"
    for wpn,wpfs in wpf.iteritems():
        wpstr += "\n%s\n" % wpn
        wpstr += "-------\n"
        keys = wpfs.keys()
        keys.sort()
        ## for cat,val in wpfs.iteritems():
        ##    funcs,tit = val
        for cat in keys:
            funcs,tit = wpfs[cat]
            wpstr += ("%s (%s) " % (cat.ljust(8),tit.ljust(14)))
            for f in funcs:
                if options.vsnvtx:
                    wpstr += "%1.0f-%1.0f: %1.3f " % (f.GetXmin(), f.GetXmax(), f.GetParameter(1))
                else:
                    wpstr += "%1.0f-%1.0f: %1.2f " % (f.GetXmin(), f.GetXmax(), f.Eval(wpref))
            wpstr += "\n"
    wptag.txt(str(wpstr))

    if not os.path.isdir(options.outdir):
            os.mkdir(options.outdir)
    hth.dump()

    return quants, objs 
コード例 #6
0
            cut=allVertCut
        if opt=='-m':
            cut=mollerCut
        if opt=='-w':
            cut=wabCut
        if opt=='-e':
            ebeam=float(arg)
        if opt=='-c':
            clusterT=float(arg)
        if opt=='-z':
            targetZ=float(arg)
        if opt=='-h':
            print_usage()
            sys.exit(0)

print remainder[0]
#treeFile = TFile(sys.argv[1],"RECREATE")
#tree = TTree("ntuple","data from text tuple "+sys.argv[2])
print remainder[1:]
chain = TChain("ntuple")
for i in remainder[1:]:
	chain.Add(i,0)
print chain.GetEntries()
outFile = TFile(remainder[0],"RECREATE")
events = chain.CopyTree(cut.format(ebeam,clusterT,targetZ))
print events.GetEntries()
#outFile = TFile(remainder[0],"RECREATE")
#events.Write()
events.Write("ntuple",TTree.kOverwrite)
gDirectory.ls()
コード例 #7
0
ファイル: __init__.py プロジェクト: GaelTouquet/cpyroot
def ls():
    if gDirectory is None:
        print 'No current directory... open a root file?'
    else:
        gDirectory.ls()
コード例 #8
0
    print("WARNING: No Allpix Objects Library found, exitting")
    exit(1)

if (not os.path.isfile(lib_file_name)):
    print(
        "WARNING: no allpix library found, exiting (Use -l to manually set location of libraries)"
    )
    exit(1)
if (not os.path.isfile(root_file_name)):
    print("WARNING: " + root_file_name + " does not exist, exiting")
    exit(1)

# load library and rootfile
gSystem.Load(lib_file_name)
rootfile = ROOT.TFile(root_file_name)
gDirectory.ls()

McParticle = rootfile.Get('MCParticle')
PixelCharge = rootfile.Get('PixelCharge')
PropCharge = rootfile.Get('PropagatedCharge')
PixelHit = rootfile.Get('PixelHit')

# example of python dictionaries to fill
mc_global_endpoints = {'x': [], 'y': [], 'z': []}
mc_local_endpoints = {'x': [], 'y': [], 'z': []}
pixel_hit = {'x': [], 'y': [], 'signal': []}

# loop on pixel hit branch
empty_mc_branch = 0
print("Loading in Data...")
for iev in range(0, PixelHit.GetEntries()):
コード例 #9
0
ファイル: treeParticles.py プロジェクト: IzaakWN/CodeSnippets
# Author: Izaak Neutelings (June 2017)
from ROOT import TFile, TTree, gRandom, gDirectory
from array import array


def writeTree()
  print gDirectory.GetName()
  print gDirectory.ls()
  file = TFile("treeParticles.root", 'recreate')
  tree = TTree("tree_name", "tree title")
  
  nevts = 100
  Nmax = 10
  nParticles = array( 'i', [ 0 ] )
  pt = array( 'd', Nmax*[ 0. ] )
  tree.Branch( 'nParticles', nParticles, 'nParticles/I' )
  tree.Branch( 'pt', pt, 'pt[nParticles]/D' )
  
  for i in xrange(nevts):
    nParticles[0] = int(gRandom.Uniform()*10)
    for j in range(nParticles[0]):
       pt[j] = gRandom.Gaus(20,2)
    tree.Fill()
  
  tree.Draw("pt[0] >> h(100,0,10)")
  hist = gDirectory.Get("h")
  print gDirectory.GetName()
  print gDirectory.ls()
  print hist
  print type(hist)
  
コード例 #10
0
def ls():
    if gDirectory is None:
        print 'No current directory... open a root file?'
    else:
        gDirectory.ls()