def getListOfCmdTuples(filename, anaType): """ Returns a list of tuples where each element is: ``(anaType, cName, scandate)`` Args: filename (string): Physical filename of input file, see :any:`parseListOfScanDatesFile` for details on expected format anaType (string): String matching a key in :any:`utils.anaInfo.ana_config` """ from gempython.gemplotting.utils.anaInfo import ana_config from gempython.gemplotting.utils.anautilities import parseListOfScanDatesFile import os # Check anaType is understood if anaType not in ana_config.keys(): print "getListOfCmdTuples() - Invalid analysis specificed, please select only from the list:" print ana_config.keys() exit(os.EX_USAGE) parsedTuple = parseListOfScanDatesFile(filename, alphaLabels=True) ret_list_cmd_tuples = [] for item in parsedTuple[0]: ret_list_cmd_tuples.append((anaType, item[0], item[1])) return ret_list_cmd_tuples
buildHome = os.getenv('BUILD_HOME') dataPath = os.getenv('DATA_PATH') elogPath = os.getenv('ELOG_PATH') # Get info from input file from gempython.gemplotting.utils.anautilities import getDirByAnaType, filePathExists, makeListOfScanDatesFile, parseListOfScanDatesFile if (listOfScanDatesFile is None and options.chamberName is not None): makeListOfScanDatesFile(options.chamberName, options.anaType, options.startDate, options.endDate, ztrim=options.ztrim) listOfScanDatesFile = '%s/listOfScanDates.txt' % (getDirByAnaType( options.anaType, options.chamberName, options.ztrim)) pass parsedTuple = parseListOfScanDatesFile(listOfScanDatesFile, alphaLabels=True) listChamberAndScanDate = parsedTuple[0] # Setup output scandates list outputScanDatesName = listOfScanDatesFile.strip('.txt') outputScanDatesName += "_Input4GemPlotter.txt" outputScanDatesFile = open(outputScanDatesName, 'w+') outputScanDatesFile.write('ChamberName\tscandate\n') # invert chamber_config from mapping.chamberInfo import chamber_config, GEBtype linkByChamber = dict( (value, key) for key, value in chamber_config.iteritems()) ## Only in python 2.7 and up # linkByChamber = { value:key for key,value in chamber_config.iteritems() }
list_VFATs = [] if options.vfatList != None: list_VFATs = map(int, options.vfatList.split(',')) elif options.vfat != None: list_VFATs.append(options.vfat) else: print "You must specify at least one VFAT to be considered" exit(os.EX_USAGE) # Check that the user supplied a latency value if options.latSig is None and not options.bkgSub: print "You must specify the latency bin of the signal peak (--latSig) or ask for background subtracted analysis (--bkgSub)" exit(os.EX_USAGE) # Get info from input file parsedTuple = parseListOfScanDatesFile(options.filename) parsedAnalysisList = parsedTuple[0] strIndepVar = parsedTuple[1] # Loop Over inputs list_EffData = [] strChamberName = "" for analysisTuple in parsedAnalysisList: if len(strChamberName) == 0: strChamberName = analysisTuple[0] tuple_eff = calcEff(analysisTuple[0], analysisTuple[1], list_VFATs, options.latSig, options.bkgSub) list_EffData.append( (float(analysisTuple[2]), tuple_eff[0], tuple_eff[1]))
listVFATs = map(int, options.vfatList.split(',')) elif options.vfat != None: listVFATs.append(options.vfat) else: print("You must specify at least one VFAT to be considered") exit(os.EX_USAGE) # Check anaType is understood if options.anaType not in tree_names.keys(): print("Invalid analysis specificed, please select only from the list:") print(tree_names.keys()) exit(os.EX_USAGE) pass # Get info from input file parsedTuple = parseListOfScanDatesFile(options.filename, options.alphaLabels) listDataPtTuples = parsedTuple[0] strIndepVar = parsedTuple[1] # Do we make strip/channel level plot? vfatCH = None strip = None strDrawOpt = "APE1" strStripOrChan = "All" if options.strip is not None: # Set the strip or channel name if options.channels: vfatCH = options.strip strStripOrChan = "vfatCH{0}".format(options.strip) else: strip = options.strip
def compareSBitThreshResults(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, getSummaryCanvas, parseArmDacCalFile, parseListOfScanDatesFile parsedTuple = parseListOfScanDatesFile(args.filename, alphaLabels=args.alphaLabels) listChamberAndScanDate = parsedTuple[0] chamberName = listChamberAndScanDate[0][0] thrDacName = parsedTuple[1] gemType = "ge11" from gempython.tools.hw_constants import vfatsPerGemVariant # Parse calibration file if present arrayCalInfo = None if args.calFileARM is not None: arrayCalInfo = parseArmDacCalFile( args.calFileARM, gemType=gemType) # arrayCalInfo[i][vfatN] for coef of x^(4-i) 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 = {} for idx, infoTuple in enumerate(listChamberAndScanDate): # Setup the path dirPath = getDirByAnaType("sbitRateor", 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}/SBitRatePlots.root".format(dirPath, infoTuple[1]) # Load the file r.TH1.AddDirectory(False) scanFile = r.TFile(filename, "READ") if scanFile.IsZombie(): print("{0} is a zombie!!!".format(filename)) print( "Please double check your input list of scandates: {0}".format( args.filename)) print("And then call this script again") raise IOError ################### # Get individual distributions ################### for vfat in range(vfatsPerGemVariant[gemType]): dict_Histos[infoTuple[2]][vfat] = scanFile.Get( "VFAT{0}/THR_ARM_DAC/g1D_rate_vs_THR-ARM-DAC_vfat{0}".format( vfat)) dict_Graphs[infoTuple[2]][vfat] = r.TGraph( dict_Histos[infoTuple[2]][vfat]) # Do we convert x-axis to charge units? if arrayCalInfo is not None: for pt in range(dict_Graphs[infoTuple[2]][vfat].GetN()): valX = r.Double() valY = r.Double() dict_Graphs[infoTuple[2]][vfat].GetPoint(pt, valX, valY) valX_Q = 0 for coef in range(0, 5): valX_Q += arrayCalInfo[coef][vfat] * pow( valX, 4 - coef) dict_Graphs[infoTuple[2]][vfat].SetPoint(pt, valX_Q, valY) pass pass # Make the TMultiGraph Objects suffix = "VFAT{0}".format(vfat) if idx == 0: dict_MultiGraphs[vfat] = r.TMultiGraph( "mGraph_RateVsThrDac_vfat{0}".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: legPlot.AddEntry(dict_Graphs[infoTuple[2]][vfat], "{0} = {1}".format(thrDacName, infoTuple[2]), "LPE") pass pass ################### # Make output ROOT file ################### outFileName = "{0}/compSbitThresh_{1}.root".format(elogPath, chamberName) outFile = r.TFile(outFileName, "RECREATE") # Plot Containers dict_canv = {} ################### # Now Make plots ################### for vfat in range(vfatsPerGemVariant[gemType]): # Make Output Canvas dict_canv[vfat] = r.TCanvas("canvSBitRate_VFAT{0}".format(vfat), "SBIT Rate by THR DAC", 700, 700) dict_canv[vfat].cd() dict_canv[vfat].cd().SetLogy() dict_MultiGraphs[vfat].Draw("APE1") dict_MultiGraphs[vfat].GetYaxis().SetTitle("Rate #left(Hz#right)") dict_MultiGraphs[vfat].GetYaxis().SetRangeUser(1e-1, 5e8) # max is 40 MHz if arrayCalInfo is not None: dict_MultiGraphs[vfat].GetXaxis().SetTitle( "Threshold #left(fC#right)") dict_MultiGraphs[vfat].GetXaxis().SetRangeUser(0, 20) else: dict_MultiGraphs[vfat].GetXaxis().SetTitle( "CFG_THR_ARM_DAC #left(DAC#right)") dict_MultiGraphs[vfat].GetXaxis().SetRangeUser(0, 125) pass 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 canvSBitRate_Summary = getSummaryCanvas( dict_MultiGraphs.values()[0:vfatsPerGemVariant[gemType]], name="canvSBitRate_Summary", drawOpt="APE1", gemType=gemType) for vfatCanv in range(1, vfatsPerGemVariant[gemType] + 1): canvSBitRate_Summary.cd(vfatCanv).SetLogy() # Draw Legend? if not args.noLeg: canvSBitRate_Summary.cd(1) legPlot.Draw("same") pass # Save summary canvases (always) print("\nSaving Summary TCanvas Objects") canvSBitRate_Summary.SaveAs("{0}/{1}.png".format( elogPath, canvSBitRate_Summary.GetName())) # Close output files outFile.Close() print("You can find all ROOT objects in:") print("\n\t{0}/compSbitThresh_{1}.root\n".format(elogPath, chamberName)) print("You can find all plots in:") print("\n\t{0}\n".format(elogPath)) print("Done") return
type=str, help="Delimiter used in infilename, default is tab character", default="\t") parser.add_argument( "--noSavedPlots", action="store_true", help="If provided then output png & pdf files will not be made") parser.add_argument("--outFile", type=str, help="Name of output TFile to be produced", default="phaseScanResults.root") args = parser.parse_args() # Parse input file from gempython.gemplotting.utils.anautilities import getPhaseScanPlots, parseListOfScanDatesFile phaseTuple = parseListOfScanDatesFile(args.infilename, delim=args.delim)[0] # Check Paths from gempython.utils.wrappers import envCheck envCheck('DATA_PATH') import os dataPath = os.getenv('DATA_PATH') # Make Phase Scan Plots import ROOT as r outF = r.TFile(args.outFile, "RECREATE") for scan in phaseTuple: cName = scan[0] scandate = scan[1] phaseScanFile = "{0}/{1}/gbtPhaseScan_{1}_{2}.log".format(
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