dict_grNHitsVFAT[vfat].GetYaxis().SetTitle("N")

    # Write
    dirVFAT = dirVFATPlots.mkdir("VFAT%i" % vfat)
    dirVFAT.cd()
    dict_grNHitsVFAT[vfat].Write()
    dict_hVFATHitsVsLat[vfat].Write()
    if options.performFit:
        dict_fitNHitsVFAT_Sig[vfat].Write()
        dict_fitNHitsVFAT_Noise[vfat].Write()
    myT.Fill()
    pass

# Store - Summary
if options.performFit:
    canv_Summary = make3x8Canvas('canv_Summary', dict_grNHitsVFAT, 'APE1',
                                 dict_fitNHitsVFAT_Noise, '')
    canv_Summary.SaveAs(filename + '/Summary.png')
else:
    canv_Summary = make3x8Canvas('canv_Summary', dict_grNHitsVFAT, 'APE1')
    canv_Summary.SaveAs(filename + '/Summary.png')

# Store - Sig Over Bkg
if options.performFit:
    canv_SigOverBkg = r.TCanvas("canv_SigOverBkg", "canv_SigOverBkg", 600, 600)
    canv_SigOverBkg.cd()
    canv_SigOverBkg.cd().SetLogy()
    canv_SigOverBkg.cd().SetGridy()
    grVFATSigOverBkg.SetTitle("")
    grVFATSigOverBkg.SetMarkerStyle(21)
    grVFATSigOverBkg.SetMarkerSize(0.7)
    grVFATSigOverBkg.SetLineWidth(2)
    #2D distribution
    vRate2D[vfat] = r.TH2D("h2DRate_vthr_vs_chan_VFAT%i"%vfat,"VFAT%i;vfatCH;CFG_THR_ARM_DAC #left[DAC Units#right];Rate #left(Hz#right)"%vfat,128,-0.5,127.5,VT1_MAX+1,-0.5,VT1_MAX+0.5)
    vRate2D[vfat].GetYaxis().SetRangeUser(1e-1,1e9)

print 'Filling Histograms'
for event in inF.rateTree :
    if event.vfatCH == 128:
        vRate[event.vfatN].Fill(event.vth,event.Rate)
    else:
        vRate2D[event.vfatN].Fill(event.vfatCH,event.vth,event.Rate)

#Save Output
outF.cd()
from gempython.gemplotting.utils.anautilities import make3x8Canvas
from gempython.gemplotting.mapping.chamberInfo import chamber_vfatPos2PadIdx
canv_RateSummary = make3x8Canvas('canv_RateSummary', vRate, 'hist')
dirVFATPlots = outF.mkdir("VFAT_Plots")
dirRatePlots1D = dirVFATPlots.mkdir("Rate_Plots_1D")
for vfat in range(0,24):
    canv_RateSummary.cd(chamber_vfatPos2PadIdx[vfat]).SetLogy()
    canv_RateSummary.cd(chamber_vfatPos2PadIdx[vfat]).Update()
    dirRatePlots1D.cd()
    vRate[vfat].Write()
canv_RateSummary.SaveAs(filename+'/RateSummary1D.png')

canv_Rate2DSummary = make3x8Canvas('canv_Rate2DSummary', vRate2D, 'colz')
dirRatePlots2D = dirVFATPlots.mkdir("Rate_Plots_2D")
for vfat in range(0,24):
    canv_Rate2DSummary.cd(chamber_vfatPos2PadIdx[vfat]).SetLogz()
    canv_Rate2DSummary.cd(chamber_vfatPos2PadIdx[vfat]).Update()
    dirRatePlots2D.cd()
        dict_mGraph_ScurveSigma[-1].Add(
            dict_ScurveSigma[chamberAndScanDatePair][-1])

        canvScurveEffPed_DetSum.cd()
        if idx == 0:
            dict_ScurveEffPed[chamberAndScanDatePair][-1].Draw("E1")
        else:
            dict_ScurveEffPed[chamberAndScanDatePair][-1].Draw("sameE1")

        # Fill Legend - use VFAT0 of each
        plotLeg.AddEntry(dict_fitSum[chamberAndScanDatePair][0],
                         chamberAndScanDatePair[2], "LPE")
        pass

    # Draw multigraphs for summary cases
    canvFitSum_Grid = make3x8Canvas("scurveFitSummaryGridAllScandates",
                                    dict_mGraph_fitSum, "APE1")
    canvScurveMean_Grid = make3x8Canvas("scurveMeanGridAllScandates",
                                        dict_mGraph_ScurveMean, "APE1")
    canvScurveSigma_Grid = make3x8Canvas("scurveSigmaGridAllScandates",
                                         dict_mGraph_ScurveSigma, "APE1")

    canvScurveMean_Grid_iEta = make2x4Canvas(
        "scurveMeanGridByiEtaAllScandates", dict_mGraph_ScurveMeanByiEta,
        "APE1")
    canvScurveSigma_Grid_iEta = make2x4Canvas(
        "scurveSigmaGridByiEtaAllScandates", dict_mGraph_ScurveSigmaByiEta,
        "APE1")

    canvScurveMean_DetSum.cd()
    canvScurveMean_DetSum.cd().SetLogy()
    dict_mGraph_ScurveMean[-1].Draw("APE1")
            print("eog " + strCanvName)
            print ""

        # Store the Canvas
        canvPlot.Update()
        canvPlot.SaveAs(strCanvName)
        dirVFAT.cd()
        canvPlot.Write()
        pass

    # Make Summary Plot
    if options.all_plots:
        from gempython.gemplotting.utils.anautilities import make3x8Canvas
        strSummaryName = "summary_%s_vs_%s_%s" % (
            options.branchName, strIndepVarNoBraces, strStripOrChan)
        canv_summary = make3x8Canvas(strSummaryName, listPlots, strDrawOpt)

        strCanvName = "%s/%s.png" % (elogPath, strSummaryName)
        canv_summary.SaveAs(strCanvName)

        outF.cd()
        canv_summary.Write()

        print ""
        print "To view your plot, execute:"
        print("eog " + strCanvName)
        print ""

    print ""
    print "Your plot is stored in a TFile, to open it execute:"
    print("root " + strRootName)
Exemple #5
0
def compareLatResults(args):
    # Suppress all pop-ups from ROOT
    import ROOT as r
    r.gROOT.SetBatch(True)
    
    # Check Paths
    import os, sys
    from gempython.utils.wrappers import envCheck
    envCheck('DATA_PATH')
    envCheck('ELOG_PATH')
    elogPath = os.getenv('ELOG_PATH')

    # Get info from input file
    from gempython.gemplotting.utils.anautilities import getCyclicColor, getDirByAnaType, filePathExists, make3x8Canvas, parseListOfScanDatesFile
    parsedTuple = parseListOfScanDatesFile(args.filename,alphaLabels=args.alphaLabels)
    listChamberAndScanDate = parsedTuple[0]
    chamberName = listChamberAndScanDate[0][0]

    legPlot = r.TLegend(0.5,0.5,0.9,0.9)

    from gempython.utils.nesteddict import nesteddict as ndict
    dict_Histos = ndict()
    dict_Graphs = ndict()
    dict_MultiGraphs = {}
    
    print("Loading data from input list of scandates file")
    from gempython.gemplotting.utils.anaInfo import tree_names
    for idx,infoTuple in enumerate(listChamberAndScanDate):
        # Setup the path
        dirPath = getDirByAnaType("latency", infoTuple[0])
        if not filePathExists(dirPath, infoTuple[1]):
            print('Filepath {:s}/{:s} does not exist!'.format(dirPath, infoTuple[1]))
            print('Please cross-check, exiting!')
            sys.exit(os.EX_NOINPUT)
        filename = "{:s}/{:s}/{:s}".format(dirPath, infoTuple[1], tree_names["latencyAna"][0])
        if not os.path.isfile(filename):
            print('File {:s} does not exist!'.format(filename))
            print('Please cross-check, exiting!')
            sys.exit(os.EX_NOINPUT)

        # Load the file
        r.TH1.AddDirectory(False)
        scanFile   = r.TFile(filename,"READ")
        
        if scanFile.IsZombie():
            print("{:s} is a zombie!!!".format(filename))
            print("Please double check your input list of scandates: {:s}".format(args.filename))
            print("And then call this script again")
            raise IOError

        ###################
        # Get individual distributions
        ###################
        for vfat in range(24):
            baseDir = "VFAT_Plots/VFAT{0:d}".format(vfat)
            dict_Histos[infoTuple[2]][vfat] = scanFile.Get("{:s}/vfat{:d}HitsVsLat".format(baseDir,vfat))
            dict_Graphs[infoTuple[2]][vfat] = scanFile.Get("{:s}/g_N_vs_Lat_VFAT{:d}".format(baseDir,vfat))
            
            # Make the TMultiGraph Objects
            suffix = "VFAT{:d}".format(vfat)
            if idx == 0:
                dict_MultiGraphs[vfat] = r.TMultiGraph("mGraph_RateVsThrDac_vfat{:s}".format(suffix),suffix)

            # Set Style of TGraph
            dict_Graphs[infoTuple[2]][vfat].SetLineColor(getCyclicColor(idx))
            dict_Graphs[infoTuple[2]][vfat].SetMarkerColor(getCyclicColor(idx))
            dict_Graphs[infoTuple[2]][vfat].SetMarkerStyle(20+idx)
            dict_Graphs[infoTuple[2]][vfat].SetMarkerSize(0.8)

            # Add to the MultiGraph
            dict_MultiGraphs[vfat].Add(dict_Graphs[infoTuple[2]][vfat])

            ###################
            # Make an entry in the TLegend
            ###################
            if vfat == 0:
                print("infoTuple[2] = ", infoTuple[2])
                legPlot.AddEntry(
                        dict_Graphs[infoTuple[2]][vfat],
                        "{0}".format(infoTuple[2]),
                        "LPE")
                pass
            pass
    
    ###################
    # Make output ROOT file
    ###################
    outFileName = "{0}/compLatResults_{1}.root".format(elogPath,chamberName)
    outFile = r.TFile(outFileName,"RECREATE")

    ###################
    # Now Make plots
    ###################
    print("Making output plots")
    dict_canv = {}
    for vfat in range(24):
        # Make Output Canvas
        dict_canv[vfat] = r.TCanvas("canvLatResults_VFAT{0}".format(vfat),"Hits vs. CFG_LATENCY Value",700,700)
        dict_canv[vfat].cd()
        dict_MultiGraphs[vfat].Draw("APE1")
        dict_MultiGraphs[vfat].GetYaxis().SetTitle("Hits #left(A.U.#right)")
        dict_MultiGraphs[vfat].GetYaxis().SetRangeUser(0,args.eventsPerLat) # max is 40 MHz
        dict_MultiGraphs[vfat].GetXaxis().SetTitle("CFG_LATENCY #left(BX#right)")
        dict_MultiGraphs[vfat].Draw("APE1")

        # Draw Legend?
        if not args.noLeg:
            legPlot.Draw("same")
            pass

        # Make output image?
        if args.savePlots:
            dict_canv[vfat].SaveAs("{0}/{1}.png".format(elogPath,dict_canv[vfat].GetName()))
            pass

        # Store Output
        thisDirectory = outFile.mkdir("VFAT{0}".format(vfat))
        thisDirectory.cd()
        dict_MultiGraphs[vfat].Write()
        dict_canv[vfat].Write()
        pass

    # Make summary canvases, always save these
    canvLatResults_Summary = make3x8Canvas("canvLatResults_Summary",dict_MultiGraphs.values()[0:24],"APE1")
                
    # Draw Legend?
    if not args.noLeg:
        canvLatResults_Summary.cd(1)
        legPlot.Draw("same")
        pass

    # Save summary canvases (always)
    print("\nSaving Summary TCanvas Objects")
    #canvLatResults_Summary.SaveAs("{0}/{1}.png".format(elogPath,canvLatResults_Summary.GetName()))

    # Close output files
    outFile.Close()
    
    print("You can find all ROOT objects in:")
    print("\n\t{0}//compLatResults_{1}.root\n".format(elogPath,chamberName))

    print("You can find all plots in:")
    print("\n\t{0}\n".format(elogPath))

    print("Done")

    return