def listBadAdcs(self, rosBeg=0, modBeg=0, rosEnd=5, modEnd=64): """ Print a formatted list of all ADCs with problems. """ self.log().info( "==============================================================") self.log().info( " Current list of affected ADCs ") self.log().info( "==============================================================") for ros in range(rosBeg, rosEnd): for mod in range(modBeg, min(modEnd, TileCalibUtils.getMaxDrawer(ros))): modName = TileCalibUtils.getDrawerString(ros, mod) for chn in range(TileCalibUtils.max_chan()): chnName = "channel %2i" % chn for adc in range(TileCalibUtils.max_gain()): gainName = "LG:" if adc: gainName = "HG:" prbs = self.getAdcProblems(ros, mod, chn, adc) for prbCode in sorted(prbs.keys()): prbDesc = prbs[prbCode] msg = "%s %s %s %2i (%s)" % ( modName, chnName, gainName, prbCode, prbDesc) self.log().info(msg) modName = " " * 5 chnName = " " * 10 gainName = " " * 3 self.log().info( "==============================================================")
def decode_status(chan, calib_blob): """ Given a module number `chan` and a `calib_blob` string, return the number of bad, good and affected channels in this module. It also returns a dictionary `prob` containing as keys the problem identifier and values the number of channels affected by that problem. """ if chan == 1000 or len(calib_blob) <= 24: # chan 1000 is a comment, and calib_blobs less than 24 in length cause # a crash. return None # Decode a Coral BLOB into a string b = make_blob(calib_blob) bch = TileCalibDrawerBch.getInstance(b) bad, good, affected = [], [], [] probs = {} decoder = TileBchDecoder(bch.getBitPatternVersion()) chn_adcs = product(xrange(TileCalibUtils.max_chan()), xrange(TileCalibUtils.max_gain())) # Stolen from near # http://alxr.usatlas.bnl.gov/lxr/source/atlas/TileCalorimeter/TileCalib/ # TileCalibBlobPython/python/TileBchTools.py#072 for chn, adc in chn_adcs: adcBits, chnBits = bch.getData(chn, adc, 0), bch.getData(chn, 2, 0) status = TileBchStatus(decoder.decode(chnBits, adcBits)) if status.isBad(): bad.append((chn, adc)) if status.isGood(): good.append((chn, adc)) if status.isAffected(): affected.append((chn, adc)) if not status.isGood(): prbs = status.getPrbs() # Build a dictionary for prb in prbs: key = prb, TileBchPrbs.getDescription(prb) probs[key] = probs.get(key, 0) + 1 return len(bad), len(good), len(affected), probs
def checkModuleForChanges(self, ros, drawer): """ Returns: - if nothing changed : 0 - if something changed and complete drawer is now good : -1 - if something changed but drawer is not completely good: >0 """ diffCnt = 0 allGood = True for chn in range(TileCalibUtils.max_chan()): for adc in range(TileCalibUtils.max_gain()): idx = self.__getAdcIdx(ros, drawer, chn, adc) newStatus = self.__newStat[idx] #=== count differences between old and new if newStatus != self.__oldStat[idx]: diffCnt += 1 #=== invalidate allGood if one ADC is not good if not newStatus.isGood(): allGood = False if diffCnt > 0 and allGood: return -1 return diffCnt
def fillTripsProbs(fileTrips, folderPath, tag, since , until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== get full folder tag folderTag = TileCalibUtils.getFullTag(folderPath, tag) util = cppyy.gbl.TileCalibUtils() default = cppyy.gbl.std.vector('unsigned int')() for i in range(util.max_drawer() + 1): default.push_back( 0 ) defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')() defVec.push_back(default) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db, folderPath, 'Bch') precisions = [[0 for drawer in range(util.max_drawer())] for ros in range(util.max_ros())] trips = [[0 for drawer in range(util.max_drawer())] for ros in range(util.max_ros())] parser = TileCalibTools.TileASCIIParser3(fileTrips, "Trip") dict = parser.getDict() log.info("Updating dictionary from file with %i entries", len(dict)) log.info("... filename: %s", fileTrips ) for key, trip in list(dict.items()): ros = key[0] mod = key[1] precisions[ros][mod] = len(trip[0]) - 2 trips[ros][mod] = float(trip[0]) tripsCalibDrawer = writer.getDrawer(util.trips_ros(), util.trips_drawer()) tripsCalibDrawer.init(defVec, util.max_ros(), 1) for ros in range(util.max_ros()): denominator = 10**max(precisions[ros]) for mod in range(util.max_drawer()): trip = int(trips[ros][mod] * denominator) tripsCalibDrawer.setData(ros, 0, mod, trip) tripsCalibDrawer.setData(ros, 0, util.max_drawer(), denominator) #=== register in DB writer.register(since, until, folderTag)
def getModuleLabels(partition): ''' This function returns list of Tile module names for given partition. Arguments: partition -- Tile partition name (LBA, LBC, EBA, EBC) ''' if partition == 'AllPart': labels = [str(module) for module in range(1, Tile.MAX_DRAWER + 1)] else: ros = {'LBA': 1, 'LBC': 2, 'EBA': 3, 'EBC': 4} labels = [ Tile.getDrawerString(ros[partition], module) for module in range(0, Tile.MAX_DRAWER) ] return labels
def __updateFromDb(self, db, folderPath, tag, runLumi, fillTable=1, ros=-1, module=-1): """ Updates the internal bad channel cache with the content found in the database. An open database instance (db) has to be provided. Tag and runNum are used to locate the set of bad channels to be read from the database. """ #=== try to open the db try: if not db.isOpen(): raise Exception("DB not open: ", db.databaseId()) except Exception as e: self.log().critical(e) return #=== print status information reader = TileCalibTools.TileBlobReader(db, folderPath, tag) if ros == -2: ros = 0 module = TileCalibUtils.definitions_draweridx() self.log().info("Updating dictionary from \'%s\'", db.databaseName()) self.log().info("... using tag \'%s\', run-lumi=%s", tag, runLumi) self.__multiVersion = reader.folderIsMultiVersion() self.__comment = reader.getComment(runLumi) self.log().info("... comment: %s", self.__comment) #=== loop over the whole detector rosmin = ros if ros >= 0 else 0 rosmax = ros + 1 if ros >= 0 else TileCalibUtils.max_ros() for ros in range(rosmin, rosmax): modmin = module if module >= 0 else 0 modmax = module + 1 if module >= 0 else TileCalibUtils.getMaxDrawer( ros) for mod in range(modmin, modmax): bch = reader.getDrawer(ros, mod, runLumi, False) if bch is None: if fillTable >= 0: self.log().warning( "Missing IOV in condDB: ros=%i mod=%i runLumi=%s", ros, mod, runLumi) continue bchDecoder = TileBchDecoder(bch.getBitPatternVersion()) for chn in range(TileCalibUtils.max_chan()): for adc in range(TileCalibUtils.max_gain()): #=== adc bits adcBits = bch.getData(chn, adc, 0) #=== channel bits (works always due to default policy) chnBits = bch.getData(chn, 2, 0) #=== build status from both adc and channel bits status = TileBchStatus( bchDecoder.decode(chnBits, adcBits)) if fillTable == 0: self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status elif fillTable == 1 or fillTable == -1: self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status elif fillTable == 2 or fillTable == -2: self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status else: self.__newStat[self.__getAdcIdx( ros, mod, chn, adc)] = status status1 = TileBchStatus( bchDecoder.decode(chnBits, adcBits)) self.__oldStat[self.__getAdcIdx( ros, mod, chn, adc)] = status1
def getBadTimingDefinition(self): """ Returns bad time status definition """ return self.getAdcStatus(0, TileCalibUtils.definitions_draweridx(), TileCalibUtils.badtiming_definition_chan(), 0)
db = TileCalibTools.openDbConn(schema, 'READONLY') folderTag = TileCalibTools.getFolderTag( schema if 'COMP200' in schema or 'OFLP200' in schema else db, folderPath, tag) log.info("Initializing folder %s with tag %s", folderPath, folderTag) #=== initialize blob reader blobReader = TileCalibTools.TileBlobReader(db, folderPath, folderTag) #blobReader.log().setLevel(logging.DEBUG) #=== get drawer with status at given run log.info("Initializing for run %d, lumiblock %d", run, lumi) flt = None r = 5 d = 0 nchan = TileCalibUtils.max_chan() ngain = TileCalibUtils.max_gain() while not flt: d -= 1 if d < 0: r -= 1 if r < 0: break d = TileCalibUtils.getMaxDrawer(r) - 1 flt = blobReader.getDrawer(r, d, (run, lumi), False, False) if flt: blobT = flt.getObjType() blobV = flt.getObjVersion() mchan = flt.getNChans() mgain = flt.getNGains() mval = flt.getObjSizeUint32()
#=== set database db = TileCalibTools.openDbConn(schema, 'READONLY') folderTag = TileCalibTools.getFolderTag(db if 'CONDBR2' in schema else schema, folderPath, tag) log.info("Initializing folder %s with tag %s", folderPath, folderTag) #=== create bad channel manager mgr = TileBchTools.TileBchMgr() mgr.setLogLvl(logLevel) mgr.initialize(db, folderPath, folderTag, (run, lumi), warn, -2) if iov or comment or warn < 0: blobReader = TileCalibTools.TileBlobReader(db, folderPath, folderTag) #=== Dump the current isBad definition isBadDef = mgr.getAdcProblems(0, TileCalibUtils.definitions_draweridx(), TileCalibUtils.bad_definition_chan(), 0) if len(list(isBadDef.keys())): log.info("isBad Definition: ") for prbCode in sorted(isBadDef.keys()): prbDesc = isBadDef[prbCode] msg = "- %2i (%s)" % (prbCode, prbDesc) log.info(msg) #=== Dump the current isBadTiming definition isBadTimingDef = mgr.getAdcProblems(0, TileCalibUtils.definitions_draweridx(), TileCalibUtils.badtiming_definition_chan(), 0) if len(list(isBadTimingDef.keys())): log.info("isBadTiming Definition: ") for prbCode in sorted(isBadTimingDef.keys()): prbDesc = isBadTimingDef[prbCode]
outfolderTag = TileCalibTools.getFolderTag(dbr, outfolderPath, outtag) log.info("Initializing folder %s with tag %s", folderPath, folderTag) iovAll = [] iovList = [] iovUntil = [] iovListMOD = [] iovListCMT = [] iovUntilCMT = [] blobReader = TileCalibTools.TileBlobReader(dbr, folderPath, folderTag) if iov: #=== filling the iovList log.info("Looking for IOVs") if moduleList != ['CMT']: for ros in range(rosmin, 5): for mod in range(min(64, TileCalibUtils.getMaxDrawer(ros))): modName = TileCalibUtils.getDrawerString(ros, mod) if len( moduleList ) > 0 and modName not in moduleList and 'ALL' not in moduleList: iovAll += [[]] else: iovMod = blobReader.getIOVsWithinRange(ros, mod) iovAll += [iovMod] iovList += iovMod if 'ALL' in moduleList: moduleList.remove('ALL') else: for ros in range(rosmin, 5): iovAll += [[]] * min(64, TileCalibUtils.getMaxDrawer(ros)) if 'CMT' in moduleList:
def TileRawChannelTimeMonitoringConfig(flags, **kwargs): ''' Function to configure TileRawChannelTimeMonitorAlgorithm algorithm in the monitoring system.''' # Define one top-level monitoring algorithm. The new configuration # framework uses a component accumulator. from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator result = ComponentAccumulator() from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg result.merge(TileDQstatusAlgCfg(flags)) from TileGeoModel.TileGMConfig import TileGMCfg result.merge(TileGMCfg(flags)) from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg result.merge(TileCablingSvcCfg(flags)) from TileConditions.TileBadChannelsConfig import TileBadChannelsCondAlgCfg result.merge(TileBadChannelsCondAlgCfg(flags, **kwargs)) kwargs.setdefault('CheckDCS', flags.Tile.useDCS) if kwargs['CheckDCS']: from TileConditions.TileDCSConfig import TileDCSCondAlgCfg result.merge(TileDCSCondAlgCfg(flags)) kwargs.setdefault('TriggerChain', '') # Partition pairs to monitor average time difference between partitions (ROS - 1) partitionPairs = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]] kwargs.setdefault('PartitionTimeDiffferncePairs', partitionPairs) # The following class will make a sequence, configure algorithms, and link # them to GenericMonitoringTools from AthenaMonitoring import AthMonitorCfgHelper helper = AthMonitorCfgHelper(flags, 'TileRawChannelTimeMonitoring') # Adding an TileCellMonitorAlgorithm algorithm to the helper from AthenaConfiguration.ComponentFactory import CompFactory TileRawChannelTimeMonitorAlgorithm = CompFactory.TileRawChannelTimeMonitorAlgorithm tileRawChanTimeMonAlg = helper.addAlgorithm( TileRawChannelTimeMonitorAlgorithm, 'TileRawChanTimeMonAlg') for k, v in kwargs.items(): setattr(tileRawChanTimeMonAlg, k, v) run = str(flags.Input.RunNumber[0]) # 1) Configure histogram with TileRawChannelTimeMonAlg algorithm execution time executeTimeGroup = helper.addGroup(tileRawChanTimeMonAlg, 'TileRawChanTimeMonExecuteTime', 'Tile/') executeTimeGroup.defineHistogram( 'TIME_execute', path='RawChannelTime', type='TH1F', title='Time for execute TileRawChanTimeMonAlg algorithm;time [#mus]', xbins=100, xmin=0, xmax=100000) from TileMonitoring.TileMonitoringCfgHelper import addTileModuleChannelMapsArray # 2) Configure histograms with status of Tile channel time per partition addTileModuleChannelMapsArray(helper, tileRawChanTimeMonAlg, name='TileAverageTime', title='Tile average time', path='Tile/RawChannelTime/Summary', type='TProfile2D', value='time', run=run) from TileMonitoring.TileMonitoringCfgHelper import addTile2DHistogramsArray # 3) Configure histograms with Tile partition average time vs luminosity block per partition addTile2DHistogramsArray( helper, tileRawChanTimeMonAlg, name='TileAverageTimeLB', xvalue='lumiBlock', yvalue='time', type='TH2D', title='Tile Average time vs LumiBlock;LumiBlock;t [ns]', path='Tile/RawChannelTime/Summary', run=run, perPartition=True, xbins=3000, xmin=-0.5, xmax=2999.5, ybins=149, ymin=-74.5, ymax=74.5) from TileMonitoring.TileMonitoringCfgHelper import getPartitionName # 4) Configure histograms with Tile partition average time difference vs luminosity block partitionPairs = kwargs['PartitionTimeDiffferncePairs'] partTimeDiffVsLBArray = helper.addArray([len(partitionPairs)], tileRawChanTimeMonAlg, 'TileAverageTimeDifferenceLB', topPath='Tile/RawChannelTime') for postfix, tool in partTimeDiffVsLBArray.Tools.items(): pairIdx = int(postfix.split('_').pop()) partitionName1, partitionName2 = [ getPartitionName(ros + 1) for ros in partitionPairs[pairIdx] ] title = 'Run %s: Average time between %s and %s' % ( run, partitionName1, partitionName2) title += ' vs luminosity block;LumiBlock;t [ns]' name = 'lumiBlock,time;TileAverageTimeDifferenceLB_%s-%s' % ( partitionName1, partitionName2) tool.defineHistogram(name, title=title, path='Summary', type='TProfile', xbins=1000, xmin=-0.5, xmax=999.5, opt='kAddBinsDynamically') from TileCalibBlobObjs.Classes import TileCalibUtils as Tile # 5) Configure histograms with Tile digitizer time vs luminosity block per digitizer maxDigitizer = 8 digiTimeVsLBArray = helper.addArray( [int(Tile.MAX_ROS - 1), int(Tile.MAX_DRAWER), maxDigitizer], tileRawChanTimeMonAlg, 'TileDigitizerTimeLB', topPath='Tile/RawChannelTime') for postfix, tool in digiTimeVsLBArray.Tools.items(): ros, module, digitizer = [int(x) for x in postfix.split('_')[1:]] moduleName = Tile.getDrawerString(ros + 1, module) title = 'Run ' + run + ' ' + moduleName + ' Digitizer ' + str( digitizer) title += ': Time vs luminosity block;LumiBlock;t [ns]' name = 'lumiBlock,time;TileDigitizerTimeLB_' + moduleName + '_DIGI_' + str( digitizer) path = getPartitionName(ros + 1) + '/' + moduleName tool.defineHistogram(name, title=title, path=path, type='TProfile', xbins=1000, xmin=-0.5, xmax=999.5, opt='kAddBinsDynamically') accumalator = helper.result() result.merge(accumalator) return result
def TileRawChannelNoiseMonitoringConfig(flags, **kwargs): ''' Function to configure TileRawChannelNoiseMonitorAlgorithm algorithm in the monitoring system.''' # Define one top-level monitoring algorithm. The new configuration # framework uses a component accumulator. from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator result = ComponentAccumulator() from TileRecUtils.TileDQstatusConfig import TileDQstatusAlgCfg result.merge(TileDQstatusAlgCfg(flags)) from TileGeoModel.TileGMConfig import TileGMCfg result.merge(TileGMCfg(flags)) from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg result.merge(TileCablingSvcCfg(flags)) from TileConditions.TileBadChannelsConfig import TileBadChannelsCondAlgCfg result.merge(TileBadChannelsCondAlgCfg(flags, **kwargs)) if 'TileCondToolEmscale' not in kwargs: from TileConditions.TileEMScaleConfig import TileCondToolEmscaleCfg emScaleTool = result.popToolsAndMerge(TileCondToolEmscaleCfg(flags)) kwargs['TileCondToolEmscale'] = emScaleTool kwargs.setdefault('CheckDCS', flags.Tile.useDCS) if kwargs['CheckDCS']: from TileConditions.TileDCSConfig import TileDCSCondAlgCfg result.merge(TileDCSCondAlgCfg(flags)) #kwargs.setdefault('TriggerChain', 'HLT_noalg_cosmiccalo_L1RD1_EMPTY') #FIXME kwargs.setdefault('TriggerTypes', [0x82]) kwargs.setdefault('Gain', 1) kwargs.setdefault('TileRawChannelContainer', flags.Tile.RawChannelContainer) # The following class will make a sequence, configure algorithms, and link # them to GenericMonitoringTools from AthenaMonitoring import AthMonitorCfgHelper helper = AthMonitorCfgHelper(flags, 'TileRawChanNoiseMonitoring') # Adding an TileCellMonitorAlgorithm algorithm to the helper from AthenaConfiguration.ComponentFactory import CompFactory TileRawChannelNoiseMonitorAlgorithm = CompFactory.TileRawChannelNoiseMonitorAlgorithm tileRawChanNoiseMonAlg = helper.addAlgorithm( TileRawChannelNoiseMonitorAlgorithm, 'TileRawChanNoiseMonAlg') for k, v in kwargs.items(): setattr(tileRawChanNoiseMonAlg, k, v) run = str(flags.Input.RunNumber[0]) # 1) Configure histogram with TileRawChanNoiseMonAlg algorithm execution time executeTimeGroup = helper.addGroup(tileRawChanNoiseMonAlg, 'TileRawChanNoiseMonExecuteTime', 'Tile/') executeTimeGroup.defineHistogram( 'TIME_execute', path='RawChannelNoise', type='TH1F', title='Time for execute TileRawChanNoiseMonAlg algorithm;time [#mus]', xbins=100, xmin=0, xmax=100000) from TileCalibBlobObjs.Classes import TileCalibUtils as Tile from TileMonitoring.TileMonitoringCfgHelper import getPartitionName, getCellName, getGainName # 2) Configure histograms with Tile raw channel amplitude per channel gainName = getGainName(kwargs['Gain']) dimensions = [ int(Tile.MAX_ROS) - 1, int(Tile.MAX_DRAWER), int(Tile.MAX_CHAN) ] chanAmpArray = helper.addArray(dimensions, tileRawChanNoiseMonAlg, 'TileRawChannelNoise', topPath='Tile/RawChannelNoise') for postfix, tool in chanAmpArray.Tools.items(): ros, module, channel = [int(x) for x in postfix.split('_')[1:]] partition = getPartitionName(ros + 1) moduleName = Tile.getDrawerString(ros + 1, module) cellName = getCellName(partition, channel) title = 'Run %s %s: Tile cell %s / channel %s amplitude (%s);Amplitude [ADC]' title = title % (run, moduleName, cellName, str(channel), gainName) name = 'amplitude;TileRawChannelNoise_%s_%s_ch_%s_%s' % ( moduleName, cellName, str(channel), gainName) tool.defineHistogram(name, title=title, path=partition, type='TH1F', xbins=81, xmin=-20.25, xmax=20.25) accumalator = helper.result() result.merge(accumalator) return result
from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("writeBch") import logging log.setLevel(logging.DEBUG) #=================================================================== #====================== FILL DB BELOW ============================== #=================================================================== db = TileCalibTools.openDb('SQLITE', 'COMP200', 'UPDATE') #=== ADC status folder folder = TileCalibTools.getTilePrefix(True,True)+"STATUS/ADC" #=== specify folder and tag folderTag = TileCalibUtils.getFullTag(folder, "COM-04") #=== create bad channel manager mgr = TileBchTools.TileBchMgr() mgr.setLogLvl(logging.DEBUG) #=== always initialize with no bad channels log.info("Initializing with no bad channels at tag=%s and time=%s", folderTag,(0,0)) mgr.initialize(db, folder, folderTag, (0,0)) #=== Define TileBchStatus.isBad() #=== Currently all channels with any problem are considered as bad and masked #=== ADC problems mgr.addAdcProblem(0, 1, 0, 0, TileBchPrbs.GeneralMaskAdc) mgr.addAdcProblem(0, 1, 0, 0, TileBchPrbs.AdcDead)
folderTag = TileCalibTools.getFolderTag(db, folderPath, tag) log.info("Initializing folder %s with tag %s", folderPath, folderTag) blobReader = TileCalibTools.TileBlobReader(db, folderPath, folderTag) import cppyy util = cppyy.gbl.TileCalibUtils() tripsCalibDrawer = blobReader.getDrawer(util.trips_ros(), util.trips_drawer(), (run,lumi)) if tripsCalibDrawer.getNChans() != util.max_ros() \ or tripsCalibDrawer.getObjSizeUint32() != (util.max_drawer() + 1): log.info("There no drawer trips probabilities in tag %s", folderTag) sys.exit(2) print ("") print ("Module\tTrip (probability)") print ("") for ros in range(1, util.max_ros()): denominator = tripsCalibDrawer.getData(ros, 0, util.max_drawer()) for mod in range(0, min(64, TileCalibUtils.getMaxDrawer(ros))): modName = TileCalibUtils.getDrawerString(ros, mod) trip = tripsCalibDrawer.getData(ros, 0, mod) #log.info("%s\t%s" % (modName, str(float(trip)/ denominator))) print ("%s\t%s" % (modName, str(float(trip)/ denominator))) #=== close DB db.closeDatabase()
def fillPed(filePed, tag, comment, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folder = TileCalibTools.getTilePrefix(True,True)+"NOISE/SAMPLE" #=== get full folder tag folderTag = TileCalibUtils.getFullTag(folder, tag) #=== create default (ADC counts) pedDef = [30.,50.] loGainDef = 0.8 hiGainDef = 1.6 defaultLo = cppyy.gbl.std.vector('float')() defaultLo.push_back(pedDef[0]) # pedestal mean value defaultLo.push_back(loGainDef) # pedestal rms defaultLo.push_back(0.0) # pedestal low frequency noise defaultLo.push_back(loGainDef) # pedestal HFN1 defaultLo.push_back(0.0) # pedestal HFN2 defaultLo.push_back(0.0) # pedestal HFN2/HFN1 ratio defaultHi = cppyy.gbl.std.vector('float')() defaultHi.push_back(pedDef[1]) # pedestal mean value defaultHi.push_back(hiGainDef) # pedestal rms defaultHi.push_back(0.0) # pedestal low frequency noise defaultHi.push_back(hiGainDef) # pedestal HFN1 defaultHi.push_back(0.0) # pedestal HFN2 defaultHi.push_back(0.0) # pedestal HFN2/HFN1 ratio defVec = cppyy.gbl.std.vector('std::vector<float>')() defVec.push_back(defaultLo) defVec.push_back(defaultHi) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db,folder,'Flt') writer.setComment(os.getlogin(),comment) parser = TileCalibTools.TileASCIIParser2(filePed,"") #=== loop over whole detector for ros in range(0,5): #for mod in range(64): for mod in range(0, min(64,TileCalibUtils.getMaxDrawer(ros))): #=== need to invalidate previous blob in DB when reading from ASCII file writer.zeroBlob(ros,mod) #=== init drawer with defaults for first entry calibDrawer = writer.getDrawer(ros,mod) if not calibDrawer.getNObjs(): log.info("Initializing drawer %i/%2i\t%i", ros,mod,calibDrawer.getNObjs()) calibDrawer.init(defVec,48,0) for chn in range(48): #=== loop over gains for adc in range(2): calibDrawer.setData(chn,adc,0,pedDef[adc]+(chn+1)/48.) values = parser.getData(ros,mod,chn,adc) if not len(values): log.warning("%i/%2i/%2i/%i: No value found in file", ros,mod,chn,adc) values = parser.getData(0,ros*4,chn,adc) if not len(values): log.warning("No default per partition available") values = parser.getData(0,0,chn,adc) if not len(values): log.warning("No global default available - give up") continue else: log.warning("Using global default") else: log.warning("Using default per partition") #=== the order of columns in the ASCII file is different to the order in DB lvl = float(values[0]) # pedestal level hfn = float(values[1]) # high frequency noise lfn = float(values[2]) # low frequency noise hfn1= float(values[3]) # hfn1 hfn2= float(values[4]) # hfn2 norm= float(values[5]) # hfn2/hfn1 log.debug("%i/%2i/%2i/%i: pedLvl=%f\thfn=%f\tlfn=%f\thfn1=%f\thfn2=%f\tnorm=%f", ros,mod,chn,adc, lvl,hfn,lfn,hfn1,hfn2,norm) calibDrawer.setData(chn,adc,0,lvl) calibDrawer.setData(chn,adc,1,hfn) calibDrawer.setData(chn,adc,2,lfn) calibDrawer.setData(chn,adc,3,hfn1) calibDrawer.setData(chn,adc,4,hfn2) calibDrawer.setData(chn,adc,5,norm) #=== register in DB writer.register(since, until, folderTag)
#=== the channel status depends on the definition of isBad stored #=== in the database drawer 1, channel 0 #=== isAffected = has a problem not included in isBad definition #=== isGood = has no problem at all rosinput = int(sys.argv[1]) if len(sys.argv) > 1 else 0 log.info("rosinput=%i", rosinput) if rosinput == 0: rosmin = 1 rosmax = 5 else: rosmin = rosinput rosmax = rosinput + 1 for ros in range(rosmin, rosmax): for mod in range(0, min(64, TileCalibUtils.getMaxDrawer(ros))): modName = TileCalibUtils.getDrawerString(ros, mod) log.info(40 * '=' + " ros %d, drawer %s", ros, modName) dbobjs = blobReader.getDBobjsWithinRange(ros, mod) if dbobjs is None: raise Exception( "No DB objects retrieved for ros=%d mod=%d (%s)" % (ros, mod, modName)) #print ("# IOVs: %d - will try to print container below..." % len(dbobjs)) #print (dbobjs) #.. keep track of validity range of identical and adjacent sets of conditions mergedSince = mergedUntil = None
folderPath = folderPath.split(",") folderTag = [] for fp in folderPath: ft = TileCalibTools.getFolderTag(schema, fp, tag) log.info("Initializing folder %s with tag %s", fp, ft) folderTag += [ft] multi = (len(folderPath) > 1) if multi and many: print("Can not calculate product of " + " ".join(folderPath) + " in multi-channel mode") sys.exit(2) #=== Get list of IOVs for given drawer or for comments record if ros != -1: modmax = min(modmax, TileCalibUtils.getMaxDrawer(ros)) if ros != -1 and modmin == modmax: COOL_part = ros COOL_chan = modmin - 1 elif ros == 0 and modmin == 1: COOL_part = ros COOL_chan = modmin - 1 else: COOL_part = -1 COOL_chan = 1000 idb = TileCalibTools.openDbConn(schema, 'READONLY') iovList = [] blobReader = [] for (fp, ft) in zip(folderPath, folderTag): try: br = TileCalibTools.TileBlobReader(idb, fp, ft)
def fillAutoCr(filePed, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folder = TileCalibTools.getTilePrefix(True, True) + "NOISE/AUTOCR" #=== get full folder tag folderTag = TileCalibUtils.getFullTag(folder, tag) #=== common noise autocr defaults (no correlation) default = cppyy.gbl.std.vector('float')() for i in range(6): default.push_back(0.) defVec = cppyy.gbl.std.vector('std::vector<float>')() defVec.push_back(default) defVec.push_back(default) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db, folder, 'Flt') writer.setComment(os.getlogin(), "Giulio's file for LBC test n.0, 2009-02-27") parser = TileCalibTools.TileASCIIParser(filePed, "AutoCr") #=== initialize all channels and write global default util = cppyy.gbl.TileCalibUtils() for ros in range(util.max_ros()): for drawer in range(util.getMaxDrawer(ros)): writer.zeroBlob(ros, drawer) calibDrawer = writer.getDrawer(0, 0) calibDrawer.init(defVec, 1, 1) #=== loop over whole detector for ros in range(1, 5): for mod in range(64): #=== need to invalidate previous blob in DB when reading from ASCII file writer.zeroBlob(ros, mod) for chn in range(48): values = parser.getData(ros, mod, chn) if not len(values): log.warning("%i/%2i/%2i/x: No value found in file", ros, mod, chn) continue #=== init drawer with defaults for first entry calibDrawer = writer.getDrawer(ros, mod) if not calibDrawer.getNObjs(): log.info("Initializing drawer %i/%2i\t%i", ros, mod, calibDrawer.getNObjs()) calibDrawer.init(defVec, 48, 1) #=== fill in realistic values for adc in range(2): line = "%i/%2i/%2i/%i: " % (ros, mod, chn, adc) for i in range(6): value = float(values[adc * 6 + i]) calibDrawer.setData(chn, adc, i, value) line += "%f " % (value, ) log.debug(line) #=== register in DB writer.register(since, until, folderTag)
import logging log.setLevel(logging.DEBUG) #=== set database db = TileCalibTools.openDbConn(schema, 'READONLY') folderTag = TileCalibTools.getFolderTag(db, folderPath, tag) log.info("Initializing folder %s with tag %s", folderPath, folderTag) #=== initialize blob reader blobReader = TileCalibTools.TileBlobReader(db, folderPath, folderTag) #blobReader.log().setLevel(logging.DEBUG) #=== get drawer with status at given run log.info("Initializing ros %d, drawer %d for run %d, lumiblock %d", ros, drawer, run, lumi) log.info("... %s", blobReader.getComment((run, lumi))) log.info("\n") #=== get float for a given ADC flt = blobReader.getDrawer(ros, drawer, (run, lumi)) modName = TileCalibUtils.getDrawerString(ros, drawer) msg = "%s ch %i gn %i :" % (modName, channel, adc) if nval < 1: nval = flt.getObjSizeUint32() for val in range(0, nval): msg += " %f" % flt.getData(channel, adc, val) print(msg) #=== close DB db.closeDatabase()
if ros < 1 or ros > 4: raise Exception("Invalid ros=%i" % ros) if mod < 0 or mod > 63: raise Exception("Invalid module=%i" % mod) if run1 < run: raise Exception("Invalid validity range: %i < %i" % (run1, run)) log.info("ros=%i mod=%i since=%s until=%s comment=%s", ros, mod, since, until, comment) #=================================================================== #====================== FILL DB BELOW ============================== #=================================================================== db = TileCalibTools.openDb('SQLITE', 'OFLP200', 'UPDATE') #=== specify folder and tag folderTag = TileCalibUtils.getFullTag(folder, tag) #=== create bad channel manager mgr = TileBchTools.TileBchMgr() mgr.setLogLvl(logging.DEBUG) #=== initialize bch mgr with conditions from DB log.info("Initializing with conditions from tag=%s and time=%s", folderTag, since) mgr.initialize(db, folder, folderTag, since) #=== Tuples of empty channels emptyChannelLongBarrel = (30, 31, 43) emptyChannelExtendedBarrel = (18, 19, 24, 25, 26, 27, 28, 29, 33, 34, 42, 43, 44, 45, 46, 47) #=== Add problems with mgr.addAdcProblem(ros, drawer, channel, adc, problem)
#=== get drawer with status at given run log.info("Initializing ros %d, drawer %d for run %d, lumiblock %d", ros, drawer, run, lumi) log.info("... %s", blobReader.getComment((run, lumi))) ofc = blobReader.getDrawer(ros, drawer, (run, lumi)) #=== get other OFC parameters nchann = ofc.getNChans() nfields = ofc.getNFields() nsamples = ofc.getNSamples() nphases = ofc.getNPhases() log.info("") log.info("nchann = %d", nchann) log.info("nfields = %d", nfields) log.info("nphases = %d", nphases) log.info("nsamples = %d", nsamples) log.info("") log.info("OFC for %s channel %d adc %d field %d\n", TileCalibUtils.getDrawerString(ros, drawer), channel, adc, field) #=== get OFC field for given adc, sample and phase for iphase in range(abs(nphases)): phase = ofc.getPhase(channel, adc, iphase) msg = "phase %6.1f ns :" % phase for smp in range(0, nsamples): msg += " %f" % ofc.getOfc(field, channel, adc, phase, smp) print(msg) #=== close DB db.closeDatabase()
db2 = TileCalibTools.openDb('SQLITE', instance2, 'READONLY', schema2, sqlfn2) #if tag: # folderTag = TileCalibUtils.getFullTag(folderPath, tag) #else: # folderTag = "" #if tag2: # folderTag2 = TileCalibUtils.getFullTag(folderPath2, tag2) #else: # folderTag2 = "" if tag.startswith('TileO'): folderTag = tag elif tag: folderTag = TileCalibUtils.getFullTag(folderPath, tag) else: folderTag = "" if tag2.startswith('TileO'): folderTag2 = tag2 elif tag2: folderTag2 = TileCalibUtils.getFullTag(folderPath2, tag2) else: folderTag2 = "" #================================================== from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("readFromCool") import logging
#=== resolve folder tag from global tag folderTag = TileCalibTools.getFolderTag(db, folder, globalTag) #--- or the folderTag can be specified like this: #folderTag = TileCalibUtils.getFullTag(folder, "COM-00") #=== get a blob reader blobReader = TileCalibTools.TileBlobReader(db, folder, folderTag) #=== write out the comment associated to current values in DB comment = blobReader.getComment(pointInTime) print("Comment: \"%s\"" % comment) #=== Loop over the whole detector #--- including default drawers with ros = [0,...,19] for ros in range(TileCalibUtils.max_ros()): for mod in range(TileCalibUtils.getMaxDrawer(ros)): #=== get the TileCalibDrawerFlt correcponding to module drawer = blobReader.getDrawer(ros, mod, pointInTime) #=== loop over all the channels for chn in range(TileCalibUtils.max_chan()): for adc in range(TileCalibUtils.max_gain()): ped = drawer.getData(chn, adc, 0) hfn = drawer.getData(chn, adc, 1) #=== currently lfn is not filled, but should be in the future lfn = 0. if drawer.getObjSizeUint32() > 2:
from TileCalibBlobPython.TileCalibLogger import getLogger log = getLogger("writeBch") import logging log.setLevel(logging.DEBUG) #=================================================================== #====================== FILL DB BELOW ============================== #=================================================================== db = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'UPDATE') #=== ADC status folder folder = TileCalibTools.getTilePrefix(True, True) + "STATUS/ADC" #=== specify folder and tag folderTag = TileCalibUtils.getFullTag(folder, "RUN2-HLT-UPD1-00") #=== create bad channel manager mgr = TileBchTools.TileBchMgr() mgr.setLogLvl(logging.DEBUG) #=== always initialize with no bad channels log.info("Initializing with no bad channels at tag=%s and time=%s", folderTag, (0, 0)) mgr.initialize(db, folder, folderTag, (0, 0)) #=== Tuples of empty channels emptyChannelLongBarrel = (30, 31, 43) emptyChannelExtendedBarrel = (18, 19, 24, 25, 26, 27, 28, 29, 33, 34, 42, 43, 44, 45, 46, 47) #=== Add problems with mgr.addAdcProblem(ros, drawer, channel, adc, problem)
def commitToDb(self, db, folderPath, tag, bitPatVer, author, comment, since, until=(MAXRUN, MAXLBK), untilCmt=None, moduleList=[]): """ Commits the differences compared to the set of bad channels read in with the initialze function to the provided database. - author : author name (string) - comment : a comment (string) - sinceRun, sinceLbk : start of IOV for which bad channels are valid - untilRun, untilLbk : end of IOV for which bad channels are valid """ #=== check db status try: if not db.isOpen(): raise Exception("DB not open: ", db.databaseId()) except Exception as e: raise (e) multiVersion = self.__multiVersion writer = TileCalibTools.TileBlobWriter(db, folderPath, 'Bch', multiVersion) if len(comment) or isinstance(author, tuple): writer.setComment(author, comment) nUpdates = 0 goodComment = True #=== get latest state from db if moduleList != ['CMT']: if since != (MINRUN, MINLBK): justBefore = list(since) if justBefore[1] > MINLBK: justBefore[1] = justBefore[1] - 1 else: justBefore[0] = justBefore[0] - 1 justBefore[1] = MAXLBK justBefore = tuple(justBefore) if self.__mode != 2: self.log().info( "Reading db state just before %s, i.e. at %s", since, justBefore) self.__updateFromDb(db, folderPath, tag, justBefore, 0) else: self.log().info( "Using previous bad channel list from input DB") self.log().info( "And comparing it with new list of bad channels") else: if self.__mode != 2: reader = TileCalibTools.TileBlobReader(db, folderPath, tag) multiVersion = reader.folderIsMultiVersion() self.log().info( "Filling db from %s, resetting old status cache", list(since)) self.__oldStat = len(self.__oldStat) * [TileBchStatus()] #=== print status information self.log().info("Committing changes to DB \'%s\'", db.databaseId()) self.log().info( "... using tag \'%s\' and [run,lumi] range: [%i,%i] - [%i,%i]", tag, since[0], since[1], until[0], until[1]) if isinstance(author, tuple) and len(author) == 3: self.log().info("... author : \'%s\'", author[0]) self.log().info("... comment: \'%s\'", author[1]) else: self.log().info("... author : \'%s\'", author) self.log().info("... comment: \'%s\'", comment) #=== default for drawer initialization loGainDefVec = cppyy.gbl.std.vector('unsigned int')() loGainDefVec.push_back(0) hiGainDefVec = cppyy.gbl.std.vector('unsigned int')() hiGainDefVec.push_back(0) comChnDefVec = cppyy.gbl.std.vector('unsigned int')() comChnDefVec.push_back(0) cppyy.makeClass('std::vector<unsigned int>') defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')() defVec.push_back(loGainDefVec) defVec.push_back(hiGainDefVec) defVec.push_back(comChnDefVec) #=== loop over the whole detector bchDecoder = TileBchDecoder(bitPatVer) for ros in range(0, TileCalibUtils.max_ros()): for mod in range(TileCalibUtils.getMaxDrawer(ros)): modName = TileCalibUtils.getDrawerString(ros, mod) nChange = self.checkModuleForChanges(ros, mod) if nChange == 0 and (len(moduleList) == 0 or modName not in moduleList or 'ALL' not in moduleList): #=== do nothing if nothing changed continue if nChange == -1: nUpdates += 1 self.log().info("Drawer %s reset to GOOD", modName) if modName not in comment and not ( "ONL" not in folderPath or "syncALL" not in comment): goodComment = False self.log().error( "Comment string - '%s' - doesn't contain drawer %s", comment, modName) writer.zeroBlob(ros, mod) else: nUpdates += 1 self.log().info("Applying %2i changes to drawer %s", nChange, modName) if modName not in comment and ("ONL" not in folderPath or "syncALL" not in comment): goodComment = False self.log().error( "Comment string - '%s' - doesn't contain drawer %s", comment, modName) drawer = writer.getDrawer(ros, mod) drawer.init(defVec, TileCalibUtils.max_chan(), bitPatVer) for chn in range(TileCalibUtils.max_chan()): #=== get low gain bit words wordsLo = bchDecoder.encode( self.getAdcStatus(ros, mod, chn, 0)) chBits = wordsLo[0] loBits = wordsLo[1] #=== get high gain bit words wordsHi = bchDecoder.encode( self.getAdcStatus(ros, mod, chn, 1)) chBits = wordsHi[0] | chBits hiBits = wordsHi[1] #=== set low, high and common channel word in calibDrawer drawer.setData(chn, 0, 0, loBits) drawer.setData(chn, 1, 0, hiBits) drawer.setData(chn, 2, 0, chBits) #=== synchronizing channel status in low and high gain if wordsLo[0] != chBits: self.log().info( "Drawer %s ch %2d - sync LG status with HG ", modName, chn) status = TileBchStatus( bchDecoder.decode(chBits, loBits)) self.setAdcStatus(ros, mod, chn, 0, status) if wordsHi[0] != chBits: self.log().info( "Drawer %s ch %2d - sync HG status with LG ", modName, chn) status = TileBchStatus( bchDecoder.decode(chBits, hiBits)) self.setAdcStatus(ros, mod, chn, 1, status) #=== register if nUpdates > 0 or moduleList == ['CMT']: if goodComment: self.log().info( "Attempting to register %i modified drawers...", nUpdates) if untilCmt is not None and untilCmt != until: if moduleList != ['CMT'] and until > since: writer.register(since, until, tag, 1) if untilCmt > since: writer.register(since, untilCmt, tag, -1) else: writer.register(since, until, tag) else: self.log().error( "Aborting update due to errors in comment string") else: self.log().warning( "No drawer modifications detected, ignoring commit request")
def TileJetMonitoringConfig(flags, **kwargs): ''' Function to configure TileJetMonitorAlgorithm algorithm in the monitoring system.''' # Define one top-level monitoring algorithm. The new configuration # framework uses a component accumulator. from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator result = ComponentAccumulator() from TileGeoModel.TileGMConfig import TileGMCfg result.merge(TileGMCfg(flags)) from LArGeoAlgsNV.LArGMConfig import LArGMCfg result.merge(LArGMCfg(flags)) from TileConditions.TileCablingSvcConfig import TileCablingSvcCfg result.merge(TileCablingSvcCfg(flags)) from TileConditions.TileBadChannelsConfig import TileBadChanToolCfg badChanTool = result.popToolsAndMerge(TileBadChanToolCfg(flags)) # The following class will make a sequence, configure algorithms, and link # them to GenericMonitoringTools from AthenaMonitoring import AthMonitorCfgHelper helper = AthMonitorCfgHelper(flags, 'TileMonitoring') # Adding an TileJetMonitorAlgorithm algorithm to the helper from AthenaConfiguration.ComponentFactory import CompFactory tileJetMonAlg = helper.addAlgorithm(CompFactory.TileJetMonitorAlgorithm, 'TileJetMonAlg') tileJetMonAlg.TileBadChanTool = badChanTool tileJetMonAlg.TriggerChain = '' for k, v in kwargs.items(): setattr(tileJetMonAlg, k, v) DoEnergyProfiles = kwargs.get( 'DoEnergyProfiles', tileJetMonAlg._descriptors['DoEnergyProfiles'].default) Do1DHistograms = kwargs.get( 'Do1DHistograms', tileJetMonAlg._descriptors['Do1DHistograms'].default) DoEnergyDiffHistograms = kwargs.get( 'DoEnergyDiffHistograms', tileJetMonAlg._descriptors['DoEnergyDiffHistograms'].default) if flags.DQ.DataType not in ('heavyioncollisions', 'cosmics'): jvtTool = CompFactory.JetVertexTaggerTool() jetContainer = kwargs.get( 'JetContainer', tileJetMonAlg._descriptors['JetContainer'].default) jvtTool.JetContainer = jetContainer tileJetMonAlg.JVT = jvtTool jetCleaningTool = CompFactory.JetCleaningTool() jetCleaningTool.CutLevel = "LooseBad" jetCleaningTool.DoUgly = False tileJetMonAlg.JetCleaningTool = jetCleaningTool result.addPublicTool(jetCleaningTool) jetPtMin = 20000 jetTrackingEtaLimit = 2.4 eventCleaningTool = CompFactory.ECUtils.EventCleaningTool() eventCleaningTool.JetCleaningTool = jetCleaningTool eventCleaningTool.PtCut = jetPtMin eventCleaningTool.EtaCut = jetTrackingEtaLimit eventCleaningTool.JvtDecorator = "passJvt" eventCleaningTool.OrDecorator = "passOR" eventCleaningTool.CleaningLevel = jetCleaningTool.CutLevel tileJetMonAlg.EventCleaningTool = eventCleaningTool tileJetMonAlg.JetTrackingEtaLimit = jetTrackingEtaLimit tileJetMonAlg.JetPtMin = jetPtMin tileJetMonAlg.DoEventCleaning = True tileJetMonAlg.DoJetCleaning = True else: tileJetMonAlg.DoEventCleaning = False tileJetMonAlg.DoJetCleaning = False # 1) Configure histogram with TileJetMonAlg algorithm execution time executeTimeGroup = helper.addGroup(tileJetMonAlg, 'TileJetMonExecuteTime', 'Tile/') executeTimeGroup.defineHistogram( 'TIME_execute', path='Jet', type='TH1F', title='Time for execute TileJetMonAlg algorithm;time [#mus]', xbins=300, xmin=0, xmax=300000) from TileMonitoring.TileMonitoringCfgHelper import addValueVsModuleAndChannelMaps, getPartitionName runNumber = flags.Input.RunNumber[0] # 2) Configure 2D histograms (profiles/maps) with Tile channel time vs module and channel per partion (DQ summary) channelTimeDQGroup = helper.addGroup(tileJetMonAlg, 'TileJetChanTimeDQ', 'Tile/Jet/') addValueVsModuleAndChannelMaps(channelTimeDQGroup, name='tileJetChanTime', title='Average time with jets', path='DQ', type='TProfile2D', value='time', run=str(runNumber)) gains = ['LG', 'HG'] partitions = ['LBA', 'LBC', 'EBA', 'EBC'] # 3a) Configure 1D histograms with Tile channel time per partition channelTimeGroup = helper.addGroup(tileJetMonAlg, 'TileJetChanTime', 'Tile/Jet/ChanTime/') for partition in partitions: title = 'Partition ' + partition + ': Tile Channel Time;time [ns];N' name = 'channelTime' + partition path = partition channelTimeGroup.defineHistogram(name, title=title, path=path, type='TH1F', xbins=600, xmin=-30.0, xmax=30.0) # 3b) Configure 1D histograms with Tile channel time per partition for extended barrels without scintillators for partition in ['EBA', 'EBC']: title = 'Partition ' + partition + ': Tile Channel Time (without scintillators);time [ns];N' name = 'channelTime' + partition + '_NoScint' path = partition channelTimeGroup.defineHistogram(name, title=title, path=path, type='TH1F', xbins=600, xmin=-30.0, xmax=30.0) # Energy upper limits of the cell-time histograms energiesHG = [ 500, 1000, 2000, 4000, 6000, 8000, 10000, 13000, 16000, 20000 ] energiesLG = [25000, 30000, 40000, 50000, 65000, 80000] energiesALL = {'LG': energiesLG, 'HG': energiesHG} tileJetMonAlg.CellEnergyUpperLimitsHG = energiesHG tileJetMonAlg.CellEnergyUpperLimitsLG = energiesLG # 4) Configure histograms with Tile cell time in energy slices per partition and gain cellTimeGroup = helper.addGroup(tileJetMonAlg, 'TileJetCellTime', 'Tile/Jet/CellTime/') for partition in partitions: for gain in gains: index = 0 energies = energiesALL[gain] for index in range(0, len(energies) + 1): toEnergy = energies[index] if index < len(energies) else None fromEnergy = energies[index - 1] if index > 0 else None name = 'Cell_time_' + partition + '_' + gain + '_slice_' + str( index) title = 'Partition ' + partition + ': ' + gain + ' Tile Cell time in energy range' if not toEnergy: title += ' > ' + str(fromEnergy) + ' MeV; time [ns]' elif not fromEnergy: title += ' < ' + str(toEnergy) + ' MeV; time [ns]' else: title += ' [' + str(fromEnergy) + ' .. ' + str( toEnergy) + ') MeV; time [ns]' cellTimeGroup.defineHistogram(name, title=title, path=partition, type='TH1F', xbins=600, xmin=-30.0, xmax=30.0) if DoEnergyProfiles: # 5) Configure 1D histograms (profiles) with Tile cell energy profile in energy slices per partition and gain cellEnergyProfileGroup = helper.addGroup(tileJetMonAlg, 'TileJetCellEnergyProfile', 'Tile/Jet/CellTime/') for partition in partitions: for gain in gains: name = 'index_' + partition + '_' + gain name += ',energy_' + partition + '_' + gain name += ';Cell_ene_' + partition + '_' + gain + '_prof' title = 'Partition ' + partition + ': ' + gain + ' Tile Cell energy profile;Slice;Energy [MeV]' xmax = len(energiesALL[gain]) + 0.5 nbins = len(energiesALL[gain]) + 1 cellEnergyProfileGroup.defineHistogram(name, title=title, path=partition, type='TProfile', xbins=nbins, xmin=-0.5, xmax=xmax) else: # 6) Configure 1D histograms with Tile cell energy in energy slices per partition, gain and slice cellEnergyGroup = helper.addGroup(tileJetMonAlg, 'TileJetCellEnergy', 'Tile/Jet/CellTime/') for partition in partitions: for gain in gains: energies = energiesALL[gain] for index in range(0, len(energies) + 1): toEnergy = energies[index] if index < len( energies) else 2 * energies[index - 1] fromEnergy = energies[index - 1] if index > 0 else -1000 name = 'Cell_ene_' + partition + '_' + gain + '_slice_' + str( index) title = 'Partition ' + partition + ': ' + gain + ' Tile Cell Energy' title += ' in energy range [' + str( fromEnergy) + ' .. ' + str( toEnergy) + ') MeV;Energy [MeV]' cellEnergyGroup.defineHistogram(name, title=title, path=partition, type='TH1F', xbins=100, xmin=fromEnergy, xmax=toEnergy) from TileCalibBlobObjs.Classes import TileCalibUtils as Tile if Do1DHistograms: # 7) Configure 1D histograms with Tile channel time per channel channelTime1DGroup = helper.addGroup(tileJetMonAlg, 'TileJetChanTime1D', 'Tile/Jet/ChanTime/') for ros in range(1, Tile.MAX_ROS): for module in range(0, Tile.MAX_DRAWER): for channel in range(0, Tile.MAX_CHAN): moduleName = Tile.getDrawerString(ros, module) title = 'Time in ' + moduleName + ' channel ' + str( channel) + ';time [ns];N' name = moduleName + '_ch_' + str(channel) + '_1d' path = getPartitionName(ros) + '/' + moduleName channelTime1DGroup.defineHistogram(name, title=title, path=path, type='TH1F', xbins=600, xmin=-30.0, xmax=30.0) if DoEnergyDiffHistograms: # 7) Configure 1D histograms with Tile cell relative energy difference between two channels per even channel energyDiffGroup = helper.addGroup(tileJetMonAlg, 'TileJetEnergyDiff', 'Tile/Jet/EnergyDiff/') for ros in range(1, Tile.MAX_ROS): for module in range(0, Tile.MAX_DRAWER): for channel in range(0, Tile.MAX_CHAN): if not channel % 2: for gain in gains: moduleName = Tile.getDrawerString(ros, module) title = 'Tile Cell Energy difference in ' + moduleName + ' channel ' + str( channel) + ' ' + gain title += ';#frac{ene1 - ene2}{ene1 + ene2}' name = moduleName + '_enediff_' + gain + '_ch1_' + str( channel) path = getPartitionName(ros) + '/' + moduleName energyDiffGroup.defineHistogram(name, title=title, path=path, type='TH1F', xbins=100, xmin=-1.0, xmax=1.0) accumalator = helper.result() result.merge(accumalator) return result
def __getAdcIdx(self, ros, drawer, channel, adc): """ Private function, calculating the index of a given ADC for the internal cache. """ return TileCalibUtils.getAdcIdx(ros, drawer, channel, adc)
def fillIntegrator(fileInt, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)): #=== construct folder path folder = TileCalibTools.getTilePrefix(True, True) + "INTEGRATOR" #=== get full folder tag folderTag = TileCalibUtils.getFullTag(folder, tag) #=== create default values for each of the six gains 1 to 6 # for each gain there is: # gain, error of the gain, chi2 of the fit, pedestal # DAC for pedestal, sigma of pedestal distribution # RMS of pedestal distribution, sigma of the RMS dv = [] dv.append((2.814, 0.023, -1, -1, 80, -1, -1, -1)) dv.append((26.010, 0.230, -1, -1, 80, -1, -1, -1)) dv.append((28.810, 0.240, -1, -1, 80, -1, -1, -1)) dv.append((54.810, 0.480, -1, -1, 70, -1, -1, -1)) dv.append((75.790, 0.677, -1, -1, 70, -1, -1, -1)) dv.append((101.800, 0.900, -1, -1, 70, -1, -1, -1)) #=== number of integrator gains and value per gain ngain = 6 nperg = 8 defVec = cppyy.gbl.std.vector('std::vector<float>')() for i in range(ngain): defaultGain = cppyy.gbl.std.vector('float')() for v in dv[i]: defaultGain.push_back(v) defVec.push_back(defaultGain) #===================================================== #=== fill #===================================================== writer = TileCalibTools.TileBlobWriter(db, folder, 'Flt') writer.setComment(os.getlogin(), "Jalal's values with non-zero defaults, 2008-12-05") parser = TileCalibTools.TileASCIIParser(fileInt, "IntGain") #=== initialize all channels and write global default util = cppyy.gbl.TileCalibUtils() for ros in range(util.max_ros()): for drawer in range(util.getMaxDrawer(ros)): writer.zeroBlob(ros, drawer) calibDrawer = writer.getDrawer(0, 0) calibDrawer.init(defVec, 1, 1) #=== loop over whole detector for ros in range(1, 5): for mod in range(64): #=== need to invalidate previous blob in DB when reading from ASCII file writer.zeroBlob(ros, mod) for chn in range(48): values = parser.getData(ros, mod, chn) if not len(values): log.warning("%i/%2i/%2i/x: No value found in file", ros, mod, chn) continue #=== init drawer with defaults for first entry calibDrawer = writer.getDrawer(ros, mod) if not calibDrawer.getNObjs(): log.info("Initializing drawer %i/%2i\t%i", ros, mod, calibDrawer.getNObjs()) calibDrawer.init(defVec, 48, 1) #=== loop over gains for adc in range(ngain): line = "%i/%2i/%2i/%i: " % (ros, mod, chn, adc) for v in range(nperg): value = float(values[adc * nperg + v]) calibDrawer.setData(chn, adc, v, value) line += "%f " % (value, ) log.debug(line) #=== register in DB writer.register(since, until, folderTag)
folder1 = "/TILE/ONL01/NOISE/SAMPLE" folder2 = "/TILE/ONL01/NOISE/OFNI" if 'COMP200' in schema: folder1 = "/TILE/OFL01/NOISE/SAMPLE" log.info("Initializing ros %d, drawer %d for run %d, lumiblock %d", ros, drawer, run, lumi) for folderPath in [folder1, folder2]: folderTag = TileCalibTools.getFolderTag(db, folderPath, tag) log.info("Initializing folder %s with tag %s", folderPath, folderTag) blobReader = TileCalibTools.TileBlobReader(db, folderPath, folderTag) log.info("... %s", blobReader.getComment((run, lumi))) blob = blobReader.getDrawer(ros, drawer, (run, lumi)) if folderPath.find("SAMPLE") != -1: ped = blob.getData(channel, adc, 0) hfn = blob.getData(channel, adc, 1) lfn = blob.getData(channel, adc, 2) else: rms = blob.getData(channel, adc, 0) plp = blob.getData(channel, adc, 1) log.info("\n") print( "%s ch %i gn %i : PED = %f HFN = %f LFN = %f OF_RMS = %f PILEUP = %f" % (TileCalibUtils.getDrawerString( ros, drawer), channel, adc, ped, hfn, lfn, rms, plp)) #=== close DB db.closeDatabase()