def launchArgs(shelf,link,slot,run,vt1,vt1bump,config,cName,ztrim): import datetime,os,sys import subprocess from subprocess import CalledProcessError from chamberInfo import chamber_config from gempython.utils.wrappers import runCommand dataPath = os.getenv('DATA_PATH') filename="%s/%s/trim/z%f/config/SCurveData_Trimmed/SCurveFitData.root"%(dataPath,cName,options.ztrim) cmd = ["confChamber.py","-s%d"%(slot),"-g%d"%(link),"--shelf=%i"%(shelf)] if run: cmd.append("--run") pass if config: cmd.append("--vt1bump=%d"%(vt1bump)) cmd.append("--vfatConfig=%s/configs/z%.1f/vfatConfig_%s.txt"%(dataPath,ztrim,cName)) cmd.append("--chConfig=%s/configs/z%.1f/chConfig_%s.txt"%(dataPath,ztrim,cName)) else: if not os.path.isfile(filename): print "No trim configuration exists for z = %f for %s"%(ztrim,cName) return cmd.append("--filename=%s"%(filename)) pass cmd.append("--vt1=%d"%(vt1)) try: runCommand(cmd) except CalledProcessError as e: print "Caught exception",e pass return
def makeScanDir(slot, ohN, scanType, startTime, shelf=1, chamber_config=None): """ Makes a directory to store the output scan data and returns the directory path ohN - optohybrid number scanType - scanType, see ana_config.keys() from gempython.gemplotting.utils.anaInfo startTime - an instance of a datetime shelf - uTCA shelf number chamber_config - chamber_config dictionary """ ohKey = (shelf, slot, ohN) if chamber_config is None: from gempython.gemplotting.mapping.chamberInfo import chamber_config from gempython.gemplotting.utils.anautilities import getDirByAnaType if ohKey in chamber_config.keys(): dirPath = getDirByAnaType(scanType, chamber_config[ohKey]) else: dirPath = getDirByAnaType(scanType, "") setupCmds = [] setupCmds.append(["mkdir", "-p", dirPath + "/" + startTime]) setupCmds.append(["chmod", "g+rw", dirPath + "/" + startTime]) setupCmds.append(["unlink", dirPath + "/current"]) setupCmds.append(["ln", "-s", startTime, dirPath + "/current"]) for cmd in setupCmds: runCommand(cmd) return "{:s}/{:s}".format(dirPath, startTime)
def updateVFAT3ConfFilesOnAMC(cardName, link, filename, dacName): """ Updates """ if not os.path.isfile(filename): raise IOError("File {1} {0}does not exist or is not readable{1}".format(colors.READ,colors.ENDC)) from gempython.utils.wrappers import runCommand gemuserHome = "/mnt/persistent/gemuser/" # Copy Files copyFilesCmd = [ 'scp', filename, 'gemuser@{0}:{1}'.format(cardName,gemuserHome) ] runCommand(copyFilesCmd) fileOnCTP7=filename.split("/")[-1] # Update stored vfat config replaceStr = "/mnt/persistent/gemdaq/scripts/replace_parameter.sh -f {0}/{1} {2} {3}".format( gemuserHome, fileOnCTP7, dacName.replace("CFG_",""), link) transferCmd = [ 'ssh', 'gemuser@{0}'.format(cardName), 'sh -c "{0}"'.format(replaceStr) ] runCommand(transferCmd) return
def ultraScurve(args): """ Launches a call of ultraScurve.py args - object returned by argparse.ArgumentParser.parse_args() """ startTime = datetime.datetime.now().strftime("%Y.%m.%d.%H.%M") # Determine number of OH's cardName = getCardName(args.shelf,args.slot) amcBoard = HwAMC(cardName, args.debug) print('opened connection') from gempython.vfatqc.utils.scanUtils import launchSCurve for ohN in range(0,amcBoard.nOHs): # Skip masked OH's if( not ((args.ohMask >> ohN) & 0x1)): continue ohKey = (args.shelf,args.slot,ohN) print("Launching scurve for shelf{0} slot{1} OH{2} detector {3}".format(args.shelf,args.slot,ohN,chamber_config[ohKey])) # Get & make the output directory dirPath = makeScanDir(args.slot, ohN, "scurve", startTime, args.shelf) logFile = "%s/scanLog.log"%(dirPath) # Launch the scurve launchSCurve( cardName = cardName, chMax = args.chMax, chMin = args.chMin, filename = "{}/SCurveData.root".format(dirPath), latency = args.latency, link = ohN, logFile = logFile, makeLogFile = True, mspl = args.mspl, nevts = args.nevts, setChanRegs = False, vfatmask = (args.vfatmask if (args.vfatmask is not None) else amcBoard.getLinkVFATMask(ohN)), voltageStepPulse = True, gemType = args.gemType, detType = args.detType) # Execute runCommand( ["chmod","-R","g+r",dirPath] ) print("Finished scurve for shelf{0} slot{1} OH{2} detector {3}".format(args.shelf,args.slot,ohN,chamber_config[ohKey])) print("Finished all scurves for all optohybrids on shelf{0} slot{1} in ohMask: 0x{2:x}".format(args.shelf,args.slot,args.ohMask)) return
def executeCmd(cmd, dirPath): """ Executes the command specified by cmd, writes a logfile to dirPath cmd - list which defines a command, see runCommand from gempython.utils.wrappers dirPath - physical filepath """ from subprocess import CalledProcessError try: log = file("%s/scanLog.log"%(dirPath),"w") runCommand(cmd,log) except CalledProcessError as e: print("Caught exception: {0}".format(e)) except Exception as e: print("Caught exception: {0}".format(e)) finally: runCommand( ["chmod","-R","g+rw",dirPath] ) return
tmpChamberInfoFile.write('chamber_config = {\n') for i, cName in enumerate(listOfChamberNames): if i == 0: tmpChamberInfoFile.write('\t %i:"%s"\n' % (i, cName)) else: tmpChamberInfoFile.write('\t , %i:"%s"\n' % (i, cName)) tmpChamberInfoFile.write('}\n') # Write the GEBtype dict - treat them all as long (sub-optimal) tmpChamberInfoFile.write('GEBtype = {\n') for i, cName in enumerate(listOfChamberNames): if i == 0: tmpChamberInfoFile.write('\t %i:"long"\n' % (i)) else: tmpChamberInfoFile.write('\t , %i:"long"\n' % (i)) tmpChamberInfoFile.write('}\n') tmpChamberInfoFile.close() tarBallCmd.append("chamberInfo.py_tmp") # Make the tarball if options.debug: print "tarball command:" for cmd in tarBallCmd: print cmd else: runCommand(tarBallCmd) print "Your tarball can be found at %s: " % (options.tarBallName) deleteTmpChamberInfo = ["rm", "chamberInfo.py_tmp"] runCommand(deleteTmpChamberInfo)
thrArmDac2Q_Slope = tuple_calInfo[0] thrArmDac2Q_Intercept = tuple_calInfo[1] ztrim = options.ztrim chMin = options.chMin chMax = options.chMax + 1 print('trimming at z = %f' % ztrim) if options.dirPath == None: envCheck('DATA_PATH') dataPath = os.getenv('DATA_PATH') startTime = datetime.datetime.now().strftime("%Y.%m.%d.%H.%M") print(startTime) dirPath = '%s/%s/trim/z%f' % (dataPath, chamber_config[options.gtx], ztrim) runCommand(["unlink", "%s/current" % dirPath]) runCommand(['mkdir', '-p', '%s/%s' % (dirPath, startTime)]) runCommand([ "ln", "-s", '%s/%s' % (dirPath, startTime), '%s/current' % dirPath ]) dirPath = '%s/%s' % (dirPath, startTime) else: dirPath = options.dirPath pass if not options.resume: # Declare the hardware board and bias all vfats vfatBoard = HwVFAT(options.slot, options.gtx, options.shelf, options.debug)
############### # TRIMDAC = 0 ############### # Configure for initial scan for vfat in range(0, 24): writeVFAT(ohboard, options.gtx, vfat, "ContReg3", tRanges[vfat], 0) zeroAllVFATChannels(ohboard, options.gtx, mask=0x0) # Scurve scan with trimdac set to 0 filename0 = "%s/SCurveData_trimdac0_range0.root" % dirPath runCommand([ "ultraScurve.py", "--shelf=%i" % (options.shelf), "-s%d" % (options.slot), "-g%d" % (options.gtx), "--filename=%s" % (filename0), "--vfatmask=%i" % (options.vfatmask) ]) muFits_0 = fitScanData(filename0) for vfat in range(0, 24): for ch in range(CHAN_MIN, CHAN_MAX): if muFits_0[4][vfat][ch] < 0.1: masks[vfat][ch] = True #calculate the sup and set trimVcal sup = ndict() supCH = ndict() for vfat in range(0, 24): if (tRangeGood[vfat]): continue sup[vfat] = 999.0 supCH[vfat] = -1
# Check if file exists, if it does not write to output as commented line but skip to next input if not filePathExists(dirPath, tree_names[options.anaType][0]): outputScanDatesFile.write( '#%s\t%s\n' % (chamberAndScanDatePair[0], chamberAndScanDatePair[1])) continue outputScanDatesFile.write( '%s\t%s\n' % (chamberAndScanDatePair[0], chamberAndScanDatePair[1])) # Input file jobInputFile = "%s/%s" % (dirPath, tree_names[options.anaType][0]) # stdout jobStdOut = "%s/stdout" % dirPath runCommand(["mkdir", "-p", jobStdOut]) if len(os.listdir(jobStdOut)) > 0: runCommand(['rm', '%s/jobOut.txt' % (jobStdOut)]) pass # stderr jobStdErr = "%s/stderr" % dirPath runCommand(["mkdir", "-p", jobStdErr]) if len(os.listdir(jobStdErr)) > 0: runCommand(['rm', '%s/jobErr.txt' % (jobStdErr)]) pass # script to be run by the cluster jobScriptName = "%s/clusterJob.sh" % dirPath jobScript = open(jobScriptName, 'w+') jobScript.write('#!/bin/zsh\n')
def launchAnaArgs(anaType, cName, cType, scandate, scandatetrim=None, ztrim=4.0, chConfigKnown=False, channels=False, panasonic=False): import os import subprocess from subprocess import CalledProcessError from anaInfo import ana_config from gempython.utils.wrappers import runCommand dataPath = os.getenv('DATA_PATH') dirPath = "" elogPath = "%s/%s" % (os.getenv('ELOG_PATH'), scandate) print "Analysis Requested: %s" % (anaType) #Build Commands cmd = [ana_config[anaType]] postCmds = [] postCmds.append(["mkdir", "-p", "%s" % (elogPath)]) if anaType == "latency": dirPath = "%s/%s/%s/trk/%s/" % (dataPath, cName, anaType, scandate) filename = dirPath + "LatencyScanData.root" if not os.path.isfile(filename): print "No file to analyze. %s does not exist" % (filename) return cmd.append("--infilename=%s" % (filename)) cmd.append("--outfilename=%s" % ("latencyAna.root")) postCmds.append([ "cp", "%s/LatencyScanData/Summary.png" % (dirPath), "%s/LatencySumary_%s.png" % (elogPath, cName) ]) postCmds.append([ "cp", "%s/LatencyScanData/MaxHitsPerLatByVFAT.png" % (dirPath), "%s/MaxHitsPerLatByVFAT_%s.png" % (elogPath, cName) ]) postCmds.append([ "cp", "%s/LatencyScanData/SignalOverSigPBkg.png" % (dirPath), "%s/SignalOverSigPBkg_%s.png" % (elogPath, cName) ]) pass elif anaType == "scurve": dirPath = "%s/%s/%s/%s/" % (dataPath, cName, anaType, scandate) filename = dirPath + "SCurveData.root" if not os.path.isfile(filename): print "No file to analyze. %s does not exist" % (filename) return cmd.append("--infilename=%s" % (filename)) cmd.append("--outfilename=%s" % ("SCurveFitData.root")) cmd.append("--fit") cmd.append("--type=%s" % (cType)) if channels: cmd.append("--channels") pass if panasonic: cmd.append("--panasonic") pass postCmds.append([ "cp", "%s/SCurveData/Summary.png" % (dirPath), "%s/SCurveSummary_%s_ztrim%2.2f.png" % (elogPath, cName, ztrim) ]) postCmds.append([ "cp", "%s/SCurveData/chConfig.txt" % (dirPath), "%s/chConfig_%s_ztrim%2.2f.txt" % (elogPath, cName, ztrim) ]) pass elif anaType == "threshold": dirPath = "%s/%s/%s/channel/%s/" % (dataPath, cName, anaType, scandate) filename = dirPath + "ThresholdScanData.root" if not os.path.isfile(filename): print "No threshold file to analyze. %s does not exist" % ( filename) return cmd.append("--infilename=%s" % (filename)) cmd.append("--outfilename=%s" % ("ThresholdPlots.root")) if chConfigKnown: cmd.append("--chConfigKnown") dirPath_Trim = "%s/%s/trim/z%f/%s/SCurveData_Trimmed/" % ( dataPath, cName, ztrim, scandatetrim) filename_Trim = dirPath_Trim + "SCurveFitData.root" if not os.path.isfile(filename_Trim): print "No scurve fit data file to analyze. %s does not exist" % ( filename_Trim) return cmd.append("--fileScurveFitTree=%s" % (filename_Trim)) pass postCmds.append([ "cp", "%s/ThresholdScanData/ThreshSummary.png" % (dirPath), "%s/ThreshSummary_%s.png" % (elogPath, cName) ]) postCmds.append([ "cp", "%s/ThresholdScanData/ThreshPrunedSummary.png" % (dirPath), "%s/ThreshPrunedSummary_%s.png" % (elogPath, cName) ]) postCmds.append([ "cp", "%s/ThresholdScanData/vfatConfig.txt" % (dirPath), "%s/vfatConfig_%s.txt" % (elogPath, cName) ]) if chConfigKnown: postCmds.append([ "cp", "%s/ThresholdScanData/chConfig_MasksUpdated.txt" % (dirPath), "%s/chConfig_MasksUpdated_%s.txt" % (elogPath, cName) ]) pass pass elif anaType == "trim": dirPath = "%s/%s/%s/z%f/%s/" % (dataPath, cName, anaType, ztrim, scandate) filename = dirPath + "SCurveData_Trimmed.root" if not os.path.isfile(filename): print "No file to analyze. %s does not exist" % (filename) return cmd.append("--infilename=%s" % (filename)) cmd.append("--outfilename=%s" % ("SCurveFitData.root")) cmd.append("--fit") cmd.append("--type=%s" % (cType)) if channels: cmd.append("--channels") pass if panasonic: cmd.append("--panasonic") pass postCmds.append([ "cp", "%s/SCurveData_Trimmed/Summary.png" % (dirPath), "%s/SCurveSummaryTrimmed_%s_ztrim%2.2f.png" % (elogPath, cName, ztrim) ]) postCmds.append([ "cp", "%s/SCurveData_Trimmed/chConfig.txt" % (dirPath), "%s/chConfigTrimmed_%s_ztrim%2.2f.txt" % (elogPath, cName, ztrim) ]) pass #Execute Commands try: log = file("%s/anaLog.log" % (dirPath), "w") #runCommand(cmd,log) runCommand(cmd) for item in postCmds: runCommand(item) pass except CalledProcessError as e: print "Caught exception", e pass return
outDir = "{0}/{1}".format(getDataPath(), chamber_config[ohKey]) else: cName = "Detector" outDir = getElogPath() pass # Write VREF_ADC Info filename_vref_adc = "{0}/NominalValues-CFG_VREF_ADC.txt".format(outDir) print("Writing 'CFG_VREF_ADC' to file: {0}".format(filename_vref_adc)) dbInfo.to_csv(path_or_buf=filename_vref_adc, sep="\t", columns=['vfatN', 'vref_adc'], header=False, index=False, mode='w') runCommand(["chmod", "g+rw", filename_vref_adc]) # Write IREF Info filename_iref = "{0}/NominalValues-CFG_IREF.txt".format(outDir) print("Writing 'CFG_IREF' to file: {0}".format(filename_iref)) dbInfo.to_csv(path_or_buf=filename_iref, sep="\t", columns=['vfatN', 'iref'], header=False, index=False, mode='w') runCommand(["chmod", "g+rw", filename_iref]) # Write ADC0 Info filename_adc0 = "{0}/calFile_ADC0_{1}.txt".format(outDir, cName) print("Writing 'ADC0' Calibration file: {0}".format(filename_adc0))
def launchAnaArgs(anaType, cName, cType, scandate, scandatetrim=None, ztrim=4.0, chConfigKnown=False, channels=False, panasonic=False, latFit=False, latSigRange=None, latSigMaskRange=None): import os import subprocess from subprocess import CalledProcessError from gempython.gemplotting.utils.anaInfo import ana_config from gempython.gemplotting.utils.anautilities import getDirByAnaType from gempython.utils.wrappers import runCommand #dataPath = os.getenv('DATA_PATH') dirPath = getDirByAnaType(anaType, cName, ztrim) elogPath = "%s/%s"%(os.getenv('ELOG_PATH'),scandate) print "Analysis Requested: %s"%(anaType) #Build Commands cmd = [ana_config[anaType]] postCmds = [] postCmds.append(["mkdir","-p","%s"%(elogPath)]) if anaType == "latency": dirPath = "%s/%s/"%(dirPath,scandate) filename = dirPath + "LatencyScanData.root" if not os.path.isfile(filename): print "No file to analyze. %s does not exist"%(filename) return os.EX_NOINPUT cmd.append("--infilename=%s"%(filename)) cmd.append("--outfilename=%s"%("latencyAna.root")) if latFit: cmd.append("--fit") cmd.append("--latSigMaskRange=%s"%(latSigMaskRange)) cmd.append("--latSigRange=%s"%(latSigRange)) postCmds.append(["cp","%s/LatencyScanData/Summary.png"%(dirPath), "%s/LatencySumary_%s.png"%(elogPath,cName)]) postCmds.append(["cp","%s/LatencyScanData/MaxHitsPerLatByVFAT.png"%(dirPath), "%s/MaxHitsPerLatByVFAT_%s.png"%(elogPath,cName)]) if latFit: postCmds.append(["cp","%s/LatencyScanData/SignalOverBkg.png"%(dirPath), "%s/SignalOverBkg_%s.png"%(elogPath,cName)]) postCmds.append(["cp","%s/LatencyScanData/SignalNoBkg.png"%(dirPath), "%s/SignalNoBkg_%s.png"%(elogPath,cName)]) pass elif anaType == "scurve": dirPath = "%s/%s/"%(dirPath,scandate) filename = dirPath + "SCurveData.root" if not os.path.isfile(filename): print "No file to analyze. %s does not exist"%(filename) return os.EX_NOINPUT cmd.append("--infilename=%s"%(filename)) cmd.append("--outfilename=%s"%("SCurveFitData.root")) cmd.append("--fit") cmd.append("--type=%s"%(cType)) if channels: cmd.append("--channels") pass if panasonic: cmd.append("--panasonic") pass postCmds.append(["cp","%s/SCurveData/Summary.png"%(dirPath), "%s/SCurveSummary_%s_ztrim%2.2f.png"%(elogPath,cName,ztrim)]) postCmds.append(["cp","%s/SCurveData/chConfig.txt"%(dirPath), "%s/chConfig_%s_ztrim%2.2f.txt"%(elogPath,cName,ztrim)]) pass elif "threshold" in anaType: dirPath = "%s/%s/"%(dirPath,scandate) filename = dirPath + "ThresholdScanData.root" if not os.path.isfile(filename): print "No threshold file to analyze. %s does not exist"%(filename) return os.EX_NOINPUT cmd.append("--infilename=%s"%(filename)) cmd.append("--outfilename=%s"%("ThresholdPlots.root")) if "thresholdvf" in anaType: cmd.append("--pervfat") if chConfigKnown: cmd.append("--chConfigKnown") # dirPath_Trim = "%s/%s/trim/z%f/%s/SCurveData_Trimmed/"%(dataPath,cName,ztrim,scandatetrim) dirPath_Trim = "%s/%s/SCurveData_Trimmed/"%(getDirByAnaType("trim", cName, ztrim),scandatetrim) filename_Trim = dirPath_Trim + "SCurveFitData.root" if not os.path.isfile(filename_Trim): print "No scurve fit data file to analyze. %s does not exist"%(filename_Trim) return os.EX_NOINPUT cmd.append("--fileScurveFitTree=%s"%(filename_Trim)) pass postCmds.append(["cp","%s/ThresholdScanData/ThreshSummary.png"%(dirPath), "%s/ThreshSummary_%s.png"%(elogPath,cName)]) postCmds.append(["cp","%s/ThresholdScanData/ThreshPrunedSummary.png"%(dirPath), "%s/ThreshPrunedSummary_%s.png"%(elogPath,cName)]) postCmds.append(["cp","%s/ThresholdScanData/vfatConfig.txt"%(dirPath), "%s/vfatConfig_%s.txt"%(elogPath,cName)]) if chConfigKnown: postCmds.append(["cp","%s/ThresholdScanData/chConfig_MasksUpdated.txt"%(dirPath), "%s/chConfig_MasksUpdated_%s.txt"%(elogPath,cName)]) pass pass elif anaType == "trim": dirPath = "%s/%s/"%(dirPath,scandate) filename = dirPath + "SCurveData_Trimmed.root" if not os.path.isfile(filename): print "No file to analyze. %s does not exist"%(filename) return os.EX_NOINPUT cmd.append("--infilename=%s"%(filename)) cmd.append("--outfilename=%s"%("SCurveFitData.root")) cmd.append("--fit") cmd.append("--type=%s"%(cType)) if channels: cmd.append("--channels") pass if panasonic: cmd.append("--panasonic") pass postCmds.append(["cp","%s/SCurveData_Trimmed/Summary.png"%(dirPath), "%s/SCurveSummaryTrimmed_%s_ztrim%2.2f.png"%(elogPath,cName,ztrim)]) postCmds.append(["cp","%s/SCurveData_Trimmed/chConfig.txt"%(dirPath), "%s/chConfigTrimmed_%s_ztrim%2.2f.txt"%(elogPath,cName,ztrim)]) pass #Execute Commands try: log = file("%s/anaLog.log"%(dirPath),"w") returncode = runCommand(cmd,log) if returncode != 0: print "Error: command exited with non-zero code %d" % returncode return returncode for item in postCmds: returncode = runCommand(item) if returncode != 0: print "Error: command exited with non-zero code %d" % returncode return returncode pass except CalledProcessError as e: print "Caught exception",e return -1 pass return 0
format(gemType, "ge11, ge21, me0")) ##### END nVFATS = vfatsPerGemVariant[gemType] from gempython.gemplotting.mapping.chamberInfo import CHANNELS_PER_VFAT as maxChans # Get run number fields = args.infile.split("_") if "run" in fields[0]: runNo = fields[0] else: runNo = "runUnknown" pass # Make output dir in $ELOG_PATH from gempython.utils.wrappers import runCommand runCommand(["mkdir", "{0}/{1}".format(elogPath, runNo)]) # Make nested containers from gempython.utils.nesteddict import nesteddict as ndict baseDir = ndict() # baseDir[slot][oh] -> string vfatDirs = ["VFAT-{0}".format(x) for x in range(nVFATS)] allVFATsLatency = ndict() # allVFATsLatency[slot][oh] -> histogram dictMapping = ndict() # dictMapping[slot][oh] -> mapping dict latencyMean = ndict() # latencyMean[slot][oh] -> histogram latencyRMS = ndict() # latencyRMS[slot][oh] -> histogram vfatHitMulti = ndict() # vfatHitMulti[slot][oh][vfatN] -> histogram vfatLatHists = ndict() # vfatHists[slot][oh][vfatN] -> histogram vfatLatHists2D = ndict() # vfatHists2D[slot][oh][vfatN] -> histogram # Get channel mapping?
def iterativeTrim(args, dict_dirPaths, identifier, dict_chanRegData=None, dict_calFiles=None): """ Takes an scurve at a given set of channel registers (all 0's if not provided) and returns a dictionary of numpy arrays with fit results (see gempythong.gemplotting.fitting.fitScanData for details on the output container). args - Namespace produced by ArgumentParser.parse_args dirPath - Output filepath location that scurve raw data should be saved at identifier - Unique string identifier to be used for each iteration chanRegData - structure numpy array containing channel register data, expected dtype values are: [('CALPULSE_ENABLE','bool'),('MASK','bool'),('ZCC_TRIM_POLARITY','bool'), ('ZCC_TRIM_AMPLITUDE','uint8'),('ARM_TRIM_POLARITY','bool'),('ARM_TRIM_AMPLITUDE','uint8')]. If provided these values will be written to the channel registers of all unmaksed VFATs. calInfo - Tuple of numpy arrays providing CFG_CAL_DAC calibration info, idx = 0 (1) for slopw (intercept) indexed by VFAT position """ from ctypes import c_uint32 import root_numpy as rp from gempython.vfatqc.utils.scanUtils import launchSCurve dictOfFiles = {} for ohN in range(0, amcBoard.nOHs): # Skip masked OH's if (not ((args.ohMask >> ohN) & 0x1)): continue ohKey = (args.shelf, args.slot, ohN) # Get Channel Register Info if dict_chanRegData is None: setChanRegs = False cArray_trimVal = None cArray_trimPol = None else: setChanRegs = True detName = chamber_config[ohKey] gemType = detName[:detName.find('-')].lower() cArray_trimVal = ( c_uint32 * (vfatsPerGemVariant[gemType] * CHANNELS_PER_VFAT))( *dict_chanRegData[ohN]["ARM_TRIM_AMPLITUDE"]) cArray_trimPol = ( c_uint32 * (vfatsPerGemVariant[gemType] * CHANNELS_PER_VFAT))( *dict_chanRegData[ohN]["ARM_TRIM_POLARITY"]) pass # Set filename of this scurve isZombie = True filename = "{:s}/SCurveData_{:s}.root".format(dict_dirPaths[ohN], identifier) dictOfFiles[ohKey] = (filename, chamber_config[ohKey], GEBtype[ohKey]) if os.path.isfile(filename): scurveRawFile = r.TFile(filename, "READ") isZombie = scurveRawFile.IsZombie() # Take the scurves in sequence (it is not possible to take scurves in parallel) if not isZombie: try: thisTree = scurveRawFile.scurveTree except AttributeError as error: print("Caught exception {:s}".format(error)) print("Going to re-take scurve corresponding to: {:s}".format( filename)) launchSCurve(calSF=args.calSF, cardName=getCardName(args.shelf, args.slot), chMax=args.chMax, chMin=args.chMin, debug=args.debug, filename=filename, latency=args.latency, link=ohN, mspl=args.pulseStretch, nevts=args.nevts, setChanRegs=setChanRegs, trimARM=cArray_trimVal, trimARMPol=cArray_trimPol, vfatmask=args.vfatmask, voltageStepPulse=not args.currentPulse) print("scurve finished") else: print("File {:s} either doesn't exist or is a zombie".format( filename)) print("Going to re-take scurve corresponding to: {:s}".format( filename)) launchSCurve(calSF=args.calSF, cardName=getCardName(args.shelf, args.slot), chMax=args.chMax, chMin=args.chMin, debug=args.debug, filename=filename, latency=args.latency, link=ohN, mspl=args.pulseStretch, nevts=args.nevts, setChanRegs=setChanRegs, trimARM=cArray_trimVal, trimARMPol=cArray_trimPol, vfatmask=args.vfatmask, voltageStepPulse=not args.currentPulse) print("scurve finished") pass # Make the analysis output directories and set permissions from gempython.utils.wrappers import runCommand for scurveFile in dictOfFiles.values(): runCommand( ["mkdir", "-p", "{0}".format(scurveFile[0].replace(".root", ""))]) os.system("chmod -R g+rw {0} 2> /dev/null".format( scurveFile[0].replace(".root", ""))) # Do the analysis in parallel from multiprocessing import Pool from gempython.gemplotting.utils.anautilities import getNumCores2Use, init_worker pool = Pool(getNumCores2Use(args), initializer=init_worker ) # Allocate number of CPU's based on getNumCores2Use() from gempython.gemplotting.utils.scurveAlgos import anaUltraScurveStar import itertools, sys, traceback try: print( "Launching scurve analysis processes, this may take some time, please be patient" ) pool.map_async( anaUltraScurveStar, itertools.izip( [args for geoAddr in dictOfFiles.keys()], # args namespace [scurveFile[0] for scurveFile in dictOfFiles.values()], # scurveFilename [dict_calFiles[geoAddr] for geoAddr in dictOfFiles.keys()], # calFile [scurveFile[2] for scurveFile in dictOfFiles.values()], # GEBtype [ scurveFile[0].replace(".root", "") for scurveFile in dictOfFiles.values() ], # outputDir [None for geoAddr in dictOfFiles.keys()] # vfatList )).get(7200) # wait at most 2 hours except KeyboardInterrupt: printRed("Caught KeyboardInterrupt, terminating workers") pool.terminate() raise Exception("Analysis failed.") except Exception as err: printRed("Caught {0}: {1}, terminating workers".format( type(err), err.message)) pool.terminate() traceback.print_exc(file=sys.stdout) raise Exception("Analysis failed.") except: # catch *all* exceptions e = sys.exc_info()[0] printRed("Caught non-Python Exception %s" % (e)) pool.terminate() traceback.print_exc(file=sys.stdout) raise Exception("Analysis failed.") else: printGreen("Analysis Completed Successfully") pool.close() pool.join() scurveFitResults = {} for ohN in range(0, amcBoard.nOHs): # Skip masked OH's if (not ((args.ohMask >> ohN) & 0x1)): continue from gempython.gemplotting.utils.anaInfo import tree_names filename = "{0}/{1}".format( dict_dirPaths[ohN], tree_names["itertrimAna"][0].format(IDENTIFIER=identifier)) # Load the file r.TH1.AddDirectory(False) scanFile = r.TFile(filename, "READ") if not scanFile.IsOpen(): raise IOError( "iterativeTrim(): File {0} is not open or is not readable". format(filename)) if scanFile.IsZombie(): raise IOError( "iterativeTrim(): File {0} is a zombie".format(filename)) # Determine vfatID list_bNames = ['vfatN', 'vfatID'] array_vfatData = rp.tree2array(tree=scanFile.scurveFitTree, branches=list_bNames) array_vfatData = np.unique(array_vfatData) # Get scurve data for this arm dac value (used for boxplots) list_bNames = ['vfatCH', 'vfatN', 'threshold', 'noise'] scurveFitData = rp.tree2array(tree=scanFile.scurveFitTree, branches=list_bNames) scurveFitResults[ohN] = scurveFitData return scurveFitResults
def launchSCurve(**kwargs): """ Launches an scurve scan at a given set of trim settings Support arguments: calSF - int, value of the CFG_CAL_FS register cardName - string, name or ip address of AMC in uTCA crate chMask - array of ints, size 3072, indicates channels to mask; idx = vfatN * 128 + channel chMax - int, maximum channel chMin - int, minimum channel debug - boolean, print debugging information filename - string, physical filename indicating absolute path of scurve outputfile latency - int, latency to take the scruve at link - int, optohybrid number on cardName logFile - str, filepath to write the log file of the scurve call makeLogFile - bool, writes a log file of the scurve call, if logFile not provided defaults to /tmp/scurveLog_<time>.log mspl - int, value of MSPL or CFG_PULSE_STRETCH to use nevts - int, number of events to take in the scan setChanRegs - boolean, write VFAT channel registers if True vfatmask - int, vfatmask to use apply, 24-bit number, 1 in n^th bit indicates n^th vfat is masked voltageStepPulse - boolean, use voltage step pulse (true) instead of current pulse (false) trimARM - array of ints, size 3072, indicating trim amplitude to set for arming comparator; idx = vfatN * 128 + channel trimARMPol - as trimARM but sets trim polarity trimZCC - as trimARM but for the ZCC comparator trimZCCPol - as trimZCC but sets trim polarity gemType - gem generation (ge11, ge21 or me0) detType - gem detector type """ import datetime startTime = datetime.datetime.now().strftime("%Y.%m.%d.%H.%M") # Set defaults calSF = 0 cardName = None chMask = None chMax = 127 chMin = 0 debug = False filename = None latency = 33 link = 0 logFile = "/tmp/scurveLog_{}.log".format(startTime) makeLogFile = False mspl = 3 nevts = 100 setChanRegs = False shelf = None slot = None vfatmask = 0x0 voltageStepPulse = False trimARM = None trimARMPol = None trimZCC = None trimZCCPol = None gemType = "ge11" detType = "short" # Get defaults from kwargs from gempython.vfatqc.utils.qcutilities import getGeoInfoFromCardName if "calSF" in kwargs: calSF = kwargs["calSF"] if "cardName" in kwargs: cardName = kwargs["cardName"] geoInfo = getGeoInfoFromCardName(cardName) shelf = geoInfo["shelf"] slot = geoInfo["slot"] if "chMask" in kwargs: chMask = kwargs["chMask"] if "chMax" in kwargs: chMax = kwargs["chMax"] if "chMin" in kwargs: chMin = kwargs["chMin"] if "debug" in kwargs: debug = kwargs["debug"] if "filename" in kwargs: filename = kwargs["filename"] if "latency" in kwargs: latency = kwargs["latency"] if "link" in kwargs: link = kwargs["link"] if "logFile" in kwargs: logFile = kwargs["logFile"] if "makeLogFile" in kwargs: makeLogFile = kwargs["makeLogFile"] if "mspl" in kwargs: mspl = kwargs["mspl"] if "nevts" in kwargs: nevts = kwargs["nevts"] if "setChanRegs" in kwargs: setChanRegs = kwargs["setChanRegs"] if "shelf" in kwargs: shelf = kwargs["shelf"] if "slot" in kwargs: slot = kwargs["slot"] if "vfatmask" in kwargs: vfatmask = kwargs["vfatmask"] if "voltageStepPulse" in kwargs: voltageStepPulse = kwargs["voltageStepPulse"] if "trimARM" in kwargs: trimARM = kwargs["trimARM"] if "trimARMPol" in kwargs: trimARMPol = kwargs["trimARMPol"] if "trimZCC" in kwargs: trimZCC = kwargs["trimZCC"] if "trimZCCPol" in kwargs: trimZCCPol = kwargs["trimZCCPol"] if "gemType" in kwargs: gemType = kwargs["gemType"] if "detType" in kwargs: detType = kwargs["detType"] # Check minimum arguments import os if (not ((shelf is not None) and (slot is not None))): raise Exception( "launchSCurve(): You must provide either an AMC network alias (e.g. 'eagle60'), an AMC ip address, or a geographic address (e.g. 'gem-shelf01-amc04')", os.EX_USAGE) if filename is None: raise Exception( "launchSCurve(): You must provide a filename for this scurve. Exiting", os.EX_USAGE) # Set the channel registers if setChanRegs: if debug: print("opening an RPC connection to %s" % cardName) vfatBoard = HwVFAT(cardName, link, debug) if debug: print("setting channel registers") rpcResp = vfatBoard.setAllChannelRegisters(chMask=chMask, trimARM=trimARM, trimARMPol=trimARMPol, trimZCC=trimZCC, trimZCCPol=trimZCCPol, vfatMask=vfatmask, debug=debug) if rpcResp != 0: raise Exception( "RPC response was non-zero, setting channel registers failed") # Make the command to be launched cmd = [ "ultraScurve.py", "--shelf=%i" % (shelf), "--slot=%i" % (slot), "-g%d" % (link), "--gemType=%s" % (gemType), "--detType=%s" % (detType), "--chMin=%i" % (chMin), "--chMax=%i" % (chMax), "--latency=%i" % (latency), "--mspl=%i" % (mspl), "--nevts=%i" % (nevts), "--vfatmask=0x%x" % (vfatmask), "--filename=%s" % (filename) ] if voltageStepPulse: cmd.append("--voltageStepPulse") else: cmd.append("--calSF=%i" % (calSF)) if debug: cmd.append("--debug") # launch the command if debug: print("launching an scurve with command:") command = "" for word in cmd: command = "%s %s" % (command, word) print(command) print("launching scurve for filename: %s" % filename) if makeLogFile: log = file(logFile, "w") runCommand(cmd, log) else: runCommand(cmd) return
parser.add_argument("-e", "--extChanMapping", type=str, default=None, help="Physical filename of a custom, non-default, channel mapping (optional)") parser.add_argument("--doNotFit", action="store_true", help="Do not attempt to fit scurves; only the summary plot showing the 2D scurve data will be generated") parser.add_argument("--maxChi2", type=float,dest="maxChi2",default=maxChi2Default,help="Max acceptable chi2 in scurve fits") parser.add_argument("--isVFAT2", action="store_true", help="Provide this argument if input data was acquired from vfat2") parser.add_argument("-v", "--vfatList", type=str, default=None, help="Comma separated list of VFAT positions to consider for analysis. If not provided default will be all positions") parser.add_argument("-z", "--zscore", type=float, default=3.5, help="Z-Score for Outlier Identification in MAD Algo") from gempython.gemplotting.utils.scurveAlgos import anaUltraScurve parser.set_defaults(func=anaUltraScurve, outfilename="SCurveFitData.root") args = parser.parse_args() # Make output directory from gempython.utils.wrappers import runCommand filePath = args.infilename.replace('.root','') runCommand(["mkdir", "-p", "{0}".format(filePath)]) runCommand(["chmod", "g+rw", "{0}".format(filePath)]) if args.vfatList is not None: vfatList = [int(vfat) for vfat in args.vfatList.split(",")] else: vfatList = None # Run Analysis from gempython.utils.gemlogger import printRed import os, sys, traceback try: args.func(args,args.infilename,args.calFile,args.GEBtype,filePath,vfatList) except RuntimeError as err: printRed("RuntimeError: {0}".format(err.message)) traceback.print_exc(file=sys.stdout)
writeVFAT(ohboard, options.gtx, vfat, "ContReg3", tRanges[vfat], options.debug) zeroAllVFATChannels(ohboard,options.gtx,mask=0x0,debug=options.debug) # Scurve scan with trimdac set to 0 filename0 = "%s/SCurveData_trimdac0_range0.root"%dirPath cmd = [ "ultraScurve.py", "--shelf=%i"%(options.shelf), "-s%d"%(options.slot), "-g%d"%(options.gtx), "--filename=%s"%(filename0), "--vfatmask=0x%x"%(options.vfatmask), "--nevts=%i"%(options.nevts)] if options.debug: cmd.append("--debug") runCommand(cmd) muFits_0 = fitScanData(filename0) for vfat in range(0,24): for ch in range(CHAN_MIN,CHAN_MAX): if muFits_0[4][vfat][ch] < 0.1: masks[vfat][ch] = True #calculate the sup and set trimVcal sup = ndict() supCH = ndict() for vfat in range(0,24): if(tRangeGood[vfat]): continue sup[vfat] = 999.0 supCH[vfat] = -1 for ch in range(CHAN_MIN,CHAN_MAX): if(masks[vfat][ch]): continue
def launchTestsArgs(tool, shelf, slot, link, chamber, vfatmask, scanmin, scanmax, nevts, stepSize=1, vt1=None,vt2=0,mspl=None,perchannel=False,trkdata=False,ztrim=4.0, config=False,amc13local=False,t3trig=False, randoms=0, throttle=0, internal=False, debug=False): import datetime,os,sys import subprocess from subprocess import CalledProcessError from mapping.chamberInfo import chamber_config from gempython.utils.wrappers import runCommand startTime = datetime.datetime.now().strftime("%Y.%m.%d.%H.%M") dataPath = os.getenv('DATA_PATH') scanType = "vt1" dataType = "VT1Threshold" #Build Commands setupCmds = [] preCmd = None cmd = ["%s"%(tool),"-s%i"%(slot),"-g%i"%(link),"--shelf=%i"%(shelf), "--nevts=%i"%(nevts), "--vfatmask=0x%x"%(vfatmask)] if debug: cmd.append( "--debug") if tool == "ultraScurve.py": scanType = "scurve" dataType = "SCurve" dirPath = "%s/%s/%s/"%(dataPath,chamber_config[link],scanType) setupCmds.append( ["mkdir","-p",dirPath+startTime] ) setupCmds.append( ["unlink",dirPath+"current"] ) setupCmds.append( ["ln","-s",startTime,dirPath+"current"] ) dirPath = dirPath+startTime cmd.append( "--filename=%s/SCurveData.root"%dirPath ) if mspl: cmd.append( "--mspl=%i"%(mspl) ) preCmd = ["confChamber.py","-s%i"%(slot),"-g%i"%(link),"--shelf=%i"%(shelf)] if vt1 in range(256): preCmd.append("--vt1=%i"%(vt1)) pass pass elif tool == "trimChamber.py": scanType = "trim" dataType = None preCmd = ["confChamber.py","-s%i"%(slot),"-g%i"%(link),"--shelf=%i"%(shelf)] if vt1 in range(256): preCmd.append("--vt1=%i"%(vt1)) pass dirPath = "%s/%s/%s/z%f/"%(dataPath,chamber_config[link],scanType,ztrim) setupCmds.append( ["mkdir","-p",dirPath+startTime] ) setupCmds.append( ["unlink",dirPath+"current"] ) setupCmds.append( ["ln","-s",startTime,dirPath+"current"] ) dirPath = dirPath+startTime cmd.append("--ztrim=%f"%(ztrim)) if vt1 in range(256): cmd.append("--vt1=%i"%(vt1)) pass cmd.append( "--dirPath=%s"%dirPath ) pass elif tool == "ultraThreshold.py": scanType = "threshold" if vt2 in range(256): cmd.append("--vt2=%i"%(vt2)) pass if perchannel: cmd.append("--perchannel") scanType = scanType + "/channel" pass else: scanType = scanType + "/vfat" if trkdata: cmd.append("--trkdata") scanType = scanType + "/trk" pass else: scanType = scanType + "/trig" pass pass dirPath = "%s/%s/%s/"%(dataPath,chamber_config[link],scanType) setupCmds.append( ["mkdir","-p",dirPath+startTime] ) setupCmds.append( ["unlink",dirPath+"current"] ) setupCmds.append( ["ln","-s",startTime,dirPath+"current"] ) dirPath = dirPath+startTime cmd.append( "--filename=%s/ThresholdScanData.root"%dirPath ) pass elif tool == "fastLatency.py": scanType = "latency/trig" dirPath = "%s/%s/%s/"%(dataPath,chamber_config[link],scanType) setupCmds.append( ["mkdir","-p",dirPath+startTime] ) setupCmds.append( ["unlink",dirPath+"current"] ) setupCmds.append( ["ln","-s",startTime,dirPath+"current"] ) dirPath = dirPath+startTime cmd.append( "--filename=%s/FastLatencyScanData.root"%dirPath ) if mspl: cmd.append( "--mspl=%i"%(mspl) ) pass elif tool == "ultraLatency.py": scanType = "latency/trk" dirPath = "%s/%s/%s/"%(dataPath,chamber_config[link],scanType) setupCmds.append( ["mkdir","-p",dirPath+startTime] ) setupCmds.append( ["unlink",dirPath+"current"] ) setupCmds.append( ["ln","-s",startTime,dirPath+"current"] ) dirPath = dirPath+startTime cmd.append( "--filename=%s/LatencyScanData.root"%dirPath ) cmd.append( "--scanmin=%i"%(scanmin) ) cmd.append( "--scanmax=%i"%(scanmax) ) cmd.append( "--throttle=%i"%(throttle) ) if stepSize > 0: cmd.append( "--stepSize=%i"%(stepSize) ) pass if mspl: cmd.append( "--mspl=%i"%(mspl) ) pass if amc13local: cmd.append( "--amc13local") pass if t3trig: cmd.append( "--t3trig") pass if randoms > 0: cmd.append( "--randoms=%i"%(randoms)) pass if internal: cmd.append( "--internal") pass pass #Execute Commands try: for setupCmd in setupCmds: runCommand(setupCmd) pass log = file("%s/scanLog.log"%(dirPath),"w") if preCmd and config: runCommand(preCmd,log) pass runCommand(cmd,log) except CalledProcessError as e: print "Caught exception",e pass return
def launchTestsArgs(tool, shelf, slot, link, chamber, scanmin, scanmax, nevts, stepSize=1, vt1=None, vt2=0, mspl=None, perchannel=False, trkdata=False, ztrim=4.0, config=False, amc13local=False, t3trig=False, randoms=0, throttle=0): import datetime, os, sys import subprocess from subprocess import CalledProcessError from chamberInfo import chamber_config from gempython.utils.wrappers import runCommand startTime = datetime.datetime.now().strftime("%Y.%m.%d.%H.%M") dataPath = os.getenv('DATA_PATH') scanType = "vt1" dataType = "VT1Threshold" #Build Commands setupCmds = [] preCmd = None cmd = [ "%s" % (tool), "-s%d" % (slot), "-g%d" % (link), "--shelf=%i" % (shelf) ] if tool == "ultraScurve.py": scanType = "scurve" dataType = "SCurve" dirPath = "%s/%s/%s/" % (dataPath, chamber_config[link], scanType) setupCmds.append(["mkdir", "-p", dirPath + startTime]) setupCmds.append(["unlink", dirPath + "current"]) setupCmds.append(["ln", "-s", startTime, dirPath + "current"]) dirPath = dirPath + startTime cmd.append("--filename=%s/SCurveData.root" % dirPath) if mspl: cmd.append("--mspl=%d" % (mspl)) preCmd = ["confChamber.py", "-s%d" % (slot), "-g%d" % (link)] if vt1 in range(256): preCmd.append("--vt1=%d" % (vt1)) pass pass elif tool == "trimChamber.py": scanType = "trim" dataType = None preCmd = ["confChamber.py", "-s%d" % (slot), "-g%d" % (link)] if vt1 in range(256): preCmd.append("--vt1=%d" % (vt1)) pass dirPath = "%s/%s/%s/z%f/" % (dataPath, chamber_config[link], scanType, ztrim) setupCmds.append(["mkdir", "-p", dirPath + startTime]) setupCmds.append(["unlink", dirPath + "current"]) setupCmds.append(["ln", "-s", startTime, dirPath + "current"]) dirPath = dirPath + startTime cmd.append("--ztrim=%f" % (ztrim)) if vt1 in range(256): cmd.append("--vt1=%d" % (vt1)) pass cmd.append("--dirPath=%s" % dirPath) pass elif tool == "ultraThreshold.py": scanType = "threshold" if vt2 in range(256): cmd.append("--vt2=%d" % (vt2)) pass if perchannel: cmd.append("--perchannel") scanType = scanType + "/channel" pass else: scanType = scanType + "/vfat" if trkdata: cmd.append("--trkdata") scanType = scanType + "/trk" pass else: scanType = scanType + "/trig" pass pass dirPath = "%s/%s/%s/" % (dataPath, chamber_config[link], scanType) setupCmds.append(["mkdir", "-p", dirPath + startTime]) setupCmds.append(["unlink", dirPath + "current"]) setupCmds.append(["ln", "-s", startTime, dirPath + "current"]) dirPath = dirPath + startTime cmd.append("--filename=%s/ThresholdScanData.root" % dirPath) pass elif tool == "fastLatency.py": scanType = "latency/trig" dirPath = "%s/%s/%s/" % (dataPath, chamber_config[link], scanType) setupCmds.append(["mkdir", "-p", dirPath + startTime]) setupCmds.append(["unlink", dirPath + "current"]) setupCmds.append(["ln", "-s", startTime, dirPath + "current"]) dirPath = dirPath + startTime cmd.append("--filename=%s/FastLatencyScanData.root" % dirPath) cmd.append("--nevts=%d" % (nevts)) if mspl: cmd.append("--mspl=%d" % (mspl)) pass elif tool == "ultraLatency.py": scanType = "latency/trk" dirPath = "%s/%s/%s/" % (dataPath, chamber_config[link], scanType) setupCmds.append(["mkdir", "-p", dirPath + startTime]) setupCmds.append(["unlink", dirPath + "current"]) setupCmds.append(["ln", "-s", startTime, dirPath + "current"]) dirPath = dirPath + startTime cmd.append("--filename=%s/LatencyScanData.root" % dirPath) cmd.append("--scanmin=%d" % (scanmin)) cmd.append("--scanmax=%d" % (scanmax)) cmd.append("--nevts=%d" % (nevts)) cmd.append("--throttle=%i" % (throttle)) if stepSize > 0: cmd.append("--stepSize=%d" % (stepSize)) pass if mspl: cmd.append("--mspl=%d" % (mspl)) pass if amc13local: cmd.append("--amc13local") pass if t3trig: cmd.append("--t3trig") pass if randoms > 0: cmd.append("--randoms=%i" % (randoms)) pass pass #Execute Commands try: for setupCmd in setupCmds: runCommand(setupCmd) pass log = file("%s/scanLog.log" % (dirPath), "w") if preCmd and config: runCommand(preCmd, log) pass runCommand(cmd, log) except CalledProcessError as e: print "Caught exception", e pass return
if mapping is None: mapping = mappath+size+"ChannelMap_VFAT3-HV3b-V1_V2_V4.txt" elif not os.path.isfile(mapping): raise IOError("No such file or directory", mapping) else: pass filename = path+"/sbitReadOut" outfilename = args.outfilename #import sys #from subprocess import call from gempython.utils.wrappers import runCommand print("Analyzing: '{0}'".format( path)) runCommand(["mkdir", "-p", filename]) """ At the moment the output of the sbitReadout.py are .dat files with headers that will automatically fill the ROOT TTree. However ther is one last ':' in the first line that shouldn't be there; consequently the ReadFile function is not able to understand the header. So before reading these .dat files, one has to be sure to remove the ':' To achieve this the following command is needed (removes the last : in the header of all .dat files in the input path) """ # os.system("find "+path+" -iname \*.dat -exec sed -i 's/7\/i:/7\/i/g' {} \;") # Set default histo behavior import ROOT as r r.TH1.SetDefaultSumw2(False) r.gROOT.SetBatch(True) r.gStyle.SetOptStat(1111111) # Loading the dictionary with the mapping from gempython.gemplotting.utils.anautilities import getSummaryCanvas, getSummaryCanvasByiEta, getMapping
zeroAllVFATChannels(ohboard, options.gtx, mask=0x0, debug=options.debug) # Scurve scan with trimdac set to 0 filename0 = "%s/SCurveData_trimdac0_range0.root" % dirPath cmd = [ "ultraScurve.py", "--shelf=%i" % (options.shelf), "-s%d" % (options.slot), "-g%d" % (options.gtx), "--filename=%s" % (filename0), "--vfatmask=0x%x" % (options.vfatmask), "--nevts=%i" % (options.nevts) ] if options.debug: cmd.append("--debug") runCommand(cmd) muFits_0 = fitScanData(filename0) for vfat in range(0, 24): for ch in range(CHAN_MIN, CHAN_MAX): if muFits_0[4][vfat][ch] < 0.1: masks[vfat][ch] = True #calculate the sup and set trimVcal sup = ndict() supCH = ndict() for vfat in range(0, 24): if (tRangeGood[vfat]): continue sup[vfat] = 999.0 supCH[vfat] = -1 for ch in range(CHAN_MIN, CHAN_MAX): if (masks[vfat][ch]): continue
def makeListOfScanDatesFile(chamberName, anaType, startDate=None, endDate=None, delim='\t', ztrim=4): """ Given a starting scandate startDate and an ending scandate endDate this will make a text file for chamberName which is a two-column list of scandates for anaType compatible with parseListOfScanDatesFile() chamberName - Chamber name, expected to be in chamber_config.values() startDate - starting scandate in YYYY.MM.DD.hh.mm format, if None then the earliest possible date is used endDate - ending scandate in YYYY.MM.DD.hh.mm format, if None then today is used (latest possible date) delim - delimiter to use in output file name """ from gempython.utils.wrappers import envCheck, runCommand envCheck('DATA_PATH') import datetime startDay = datetime.date(datetime.MINYEAR,1,1) if startDate is not None: startDateInfo = [ int(info) for info in startDate.split(".") ] startDay = datetime.date(startDateInfo[0], startDateInfo[1], startDateInfo[2]) pass endDay = datetime.date.today() if endDate is not None: endDateInfo = [ int(info) for info in endDate.split(".") ] endDat = datetime.date(endDateInfo[0], endDateInfo[1], endDateInfo[2]) pass import os dirPath = getDirByAnaType(anaType, chamberName, ztrim) listOfScanDates = os.listdir(dirPath) try: listOfScanDatesFile = open('%s/listOfScanDates.txt'%dirPath,'w+') except IOError as e: print "Exception:", e print "Failed to open write output file" print "Is the below directory writeable?" print "" print "\t%s"%dirPath print "" exit(os.EX_IOERR) pass listOfScanDatesFile.write('ChamberName%sscandate\n'%delim) for scandate in listOfScanDates: if "current" == scandate: continue try: scandateInfo = [ int(info) for info in scandate.split('.') ] except ValueError as e: print "Skipping directory %s/%s"%(dirPath,scandate) continue thisDay = datetime.date(scandateInfo[0],scandateInfo[1],scandateInfo[2]) if (startDay < thisDay and thisDay <= endDay): listOfScanDatesFile.write('%s%s%s\n'%(chamberName,delim,scandate)) pass pass listOfScanDatesFile.close() runCommand( ['chmod','g+rw','%s/listOfScanDates.txt'%dirPath] ) return