diff --git a/TileCalorimeter/TileMonitoring/CMakeLists.txt b/TileCalorimeter/TileMonitoring/CMakeLists.txt index c2ef7632ef60f0c1a6a7098c86642cbf36a4f19d..a61a13156653328d8c62dece635701af1f233921 100644 --- a/TileCalorimeter/TileMonitoring/CMakeLists.txt +++ b/TileCalorimeter/TileMonitoring/CMakeLists.txt @@ -94,6 +94,16 @@ atlas_add_test( TileRODMonitorAlgorithm_test PROPERTIES TIMEOUT 600 POST_EXEC_SCRIPT nopost.sh) +atlas_add_test( TileTMDBMonitorAlgorithm_test + SCRIPT python -m TileMonitoring.TileTMDBMonitorAlgorithm + PROPERTIES TIMEOUT 600 + POST_EXEC_SCRIPT nopost.sh) + +atlas_add_test( TileTMDBDigitsMonitorAlgorithm_test + SCRIPT python -m TileMonitoring.TileTMDBDigitsMonitorAlgorithm + PROPERTIES TIMEOUT 600 + POST_EXEC_SCRIPT nopost.sh) + atlas_add_test( TileMonitoringConfig_test SCRIPT python -m TileMonitoring.TileMonitoringConfig PROPERTIES TIMEOUT 300 diff --git a/TileCalorimeter/TileMonitoring/python/TileMonitoringCfgHelper.py b/TileCalorimeter/TileMonitoring/python/TileMonitoringCfgHelper.py index 72312f926ff4945d6447c5080348ad8c542f8754..4ba90944b8ee28c571f61d91671070b3e2c7268a 100644 --- a/TileCalorimeter/TileMonitoring/python/TileMonitoringCfgHelper.py +++ b/TileCalorimeter/TileMonitoring/python/TileMonitoringCfgHelper.py @@ -6,7 +6,6 @@ @brief Helper functions for Run 3 Tile monitoring algorithm configuration ''' from TileCalibBlobObjs.Classes import TileCalibUtils as Tile - _cellNameEB = ['E3', 'E4', 'D4', 'D4', 'C10', 'C10', 'A12', 'A12', 'B11', 'B11', 'A13', 'A13', 'E1', 'E2', 'B12', 'B12', 'D5', 'D5', 'E3*', 'E4*', 'A14', 'A14', 'B13', 'B13', '', '', '', '', '', '', 'B14', 'A15', 'A15', '', '', 'B14', @@ -331,7 +330,7 @@ def addTile2DHistogramsArray(helper, algorithm, name = '', xvalue = '', yvalue = fullTitle = getTileHistogramTitle(title = title, run = run, **kwargs) tool.defineHistogram( fullName, path = fullPath, type = type, title = fullTitle, - xlabels = nxlabels, ylabels = nylabels, + xlabels = nxlabels, ylabels = nylabels, xbins = xbins, xmin = xmin, xmax = xmax, ybins = ybins, ymin = ymin, ymax = ymax, weight = weight) @@ -340,7 +339,7 @@ def addTile2DHistogramsArray(helper, algorithm, name = '', xvalue = '', yvalue = def addTileModuleChannelMapsArray(helper, algorithm, name, title, path, weight = '', subDirectory = False, type = 'TH2D', value = '', - run = '', triggers = [], perGain = False, separator = ''): + run = '', triggers = [], perGain = False, separator = '_'): ''' This function configures 2D histograms (maps) with Tile monitored value vs module and channel per partition. @@ -372,7 +371,7 @@ def addTileModuleChannelMapsArray(helper, algorithm, name, title, path, weight = def addTileModuleCorrelionMapsArray(helper, algorithm, name, title, path, weight = '', subDirectory = False, type = 'TH2D', value = '', run = '', - triggers = [], perGain = False, allPartitions = False, separator = ''): + triggers = [], perGain = False, allPartitions = False, separator = '_'): ''' This function configures 2D histograms (maps) with Tile monitored value vs module and channel per partition. @@ -406,7 +405,7 @@ def addTileModuleCorrelionMapsArray(helper, algorithm, name, title, path, weight def addTileModulePartitionMapsArray(helper, algorithm, name, title, path, weight = '', type = 'TH2D', value = '', run = '', triggers = [], - perGain = False, separator = ''): + perGain = False, separator = '_'): ''' This function configures 2D histograms (maps) with Tile monitored value vs module and partition. @@ -439,7 +438,7 @@ def addTileModulePartitionMapsArray(helper, algorithm, name, title, path, weight def addTileModuleDigitizerMapsArray(helper, algorithm, name, title, path, weight = '', subDirectory = False, type = 'TH2D', value = '', - run = '', triggers = [], perGain = False, separator = ''): + run = '', triggers = [], perGain = False, separator = '_'): ''' This function configures 2D histograms (maps) with Tile monitored value vs module and digitizer per partition. @@ -470,7 +469,7 @@ def addTileModuleDigitizerMapsArray(helper, algorithm, name, title, path, weight def addTileEtaPhiMapsArray(helper, algorithm, name, title, path, weight = '', type = 'TH2D', value = '', - run = '', triggers = [], perSample = True, perGain = False, separator = '', + run = '', triggers = [], perSample = True, perGain = False, separator = '_', etaTitle= '#eta', etabins = 21, etamin = -2.025, etamax = 2.025, phiTitle = '#phi', phibins = Tile.MAX_DRAWER, phimin = -3.15, phimax = 3.15): ''' @@ -589,44 +588,50 @@ def addTileModuleArray(helper, algorithm, name, title, path, def addTileTMDB_2DHistogramsArray(helper, algorithm, name = '', value = '', - title = '', path = '', type = 'TH2D', run = ''): + title = '', path = '', type = 'TH2D', run = ''): array = helper.addArray([int(Tile.MAX_ROS - 1)], algorithm, name) for postfix, tool in array.Tools.items(): ros = int(postfix.split('_').pop()) + 1 - + partition = getPartitionName(ros) nxlabels = getModuleLabels(partition) nylabels = getCellChannelTMDB_Labels(partition) ybins = len(nylabels) - + fullName = 'module,channel' + (',' + value if 'Profile' in type else '') + ';' fullName += getTileHistogramName(name, partition = partition) - + fullTitle = getTileHistogramTitle(title, run = run, partition = partition) - + tool.defineHistogram( fullName, path = path, type = type, title = fullTitle, xlabels = nxlabels, ylabels = nylabels, xbins = Tile.MAX_DRAWER, xmin = -0.5, xmax = Tile.MAX_DRAWER - 0.5, ybins = ybins, ymin = -0.5, ymax = ybins - 0.5) - def addTileTMDB_1DHistogramsArray(helper, algorithm, name = '', xvalue = '', value = '', title = '', - path = '', xbins = 0, xmin = 0, xmax = 0, type = 'TH1D', run = ''): + path = '', xbins = 0, xmin = 0, xmax = 0, type = 'TH1D', run = '', + perModule = False): for ros in range(1, Tile.MAX_ROS): partition = getPartitionName(ros) - histName = "{}_{}".format(name, partition) + baseName = "{}_{}".format(name, partition) nChannels = len(_cellNameTMDB_LB) if partition.startswith('L') else len(_cellNameTMDB_EB) - array = helper.addArray([nChannels], algorithm, histName) + dimensions = [int(Tile.MAX_DRAWER), nChannels] if perModule else [nChannels] + array = helper.addArray(dimensions, algorithm, baseName, topPath = 'Tile') for postfix, tool in array.Tools.items(): - channel = int(postfix.split('_').pop()) + elements = postfix.split('_') + channel = int(elements.pop()) + cell = getCellNameTMDB(partition, channel) + module = '{}'.format(int(elements.pop()) + 1).rjust(2,'0') if perModule else '' - fullName = xvalue + (',' + value if 'Profile' in type else '') + ';' - fullName += histName + '_' + getCellNameTMDB(partition, channel) + fullName = '{}{};{}{}_{}'.format(xvalue, (',' + value if 'Profile' in type else ''), + baseName, (module if perModule else ''), cell) - fullTitle = getTileHistogramTitle(title, run = run, partition = partition) + moduleOrPartition = 'Module ' + partition + module if perModule else 'Partition ' + partition + fullTitle = 'Run {} {} TMDB {}: {}'.format(run, moduleOrPartition, cell, title) + fullPath = path.replace('Tile/', '') if path.startswith('Tile/') else path - tool.defineHistogram( fullName, path = path, type = type, title = fullTitle, - xbins = xbins, xmin = xmin, xmax = xmax) \ No newline at end of file + tool.defineHistogram(fullName, path = fullPath, type = type, title = fullTitle, + xbins = xbins, xmin = xmin, xmax = xmax) diff --git a/TileCalorimeter/TileMonitoring/python/TileTMDBDigitsMonitorAlgorithm.py b/TileCalorimeter/TileMonitoring/python/TileTMDBDigitsMonitorAlgorithm.py index e056dc41f0c1e03ec141033a19787e2ee7a6f5af..d7cdc1cdfbd2cb0d4861ac838c531803ebfefcde 100644 --- a/TileCalorimeter/TileMonitoring/python/TileTMDBDigitsMonitorAlgorithm.py +++ b/TileCalorimeter/TileMonitoring/python/TileTMDBDigitsMonitorAlgorithm.py @@ -1,7 +1,6 @@ # # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration # - '''@file TileTMDBDigitsMonitorAlgorithm.py @author @date @@ -32,30 +31,30 @@ def TileTMDBDigitsMonitoringConfig(flags): - addTileTMDB_2DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDBDigitsPedestal', + addTileTMDB_2DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDB_DigitsPedestal', value = 'pedestal', title = 'Mean pedestal (sample[0])', - path = 'Tile/TMDBDigits', type='TProfile2D', run = run) - - addTileTMDB_2DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDBDigitsAmplitude', + path = 'Tile/TMDBDigits', type='TProfile2D', run = run) + + addTileTMDB_2DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDB_DigitsAmplitude', value = 'amplitude', title = 'Difference between maximum and minimum sample', path = 'Tile/TMDBDigits', type='TProfile2D', run = run) - - addTileTMDB_2DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDBDigitsHFN', + + addTileTMDB_2DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDB_DigitsHFN', value = 'HFN', title = 'Mean RMS of 7 samples (HFN)', - path = 'Tile/TMDBDigits', type='TProfile2D', run = run) - + path = 'Tile/TMDBDigits', type='TProfile2D', run = run) - addTileTMDB_1DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDBDigitsCellPedestal', - xvalue = 'pedestal', title = 'Pedestal (sample[0]);[ADC]', + + addTileTMDB_1DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDB_DigitsCellPedestal', + xvalue = 'pedestal', title = 'Pedestal (sample[0]);[ADC]', path = 'Tile/TMDBDigits', type='TH1D', run = run, xbins = 101, xmin = -0.5, xmax = 100.5) - addTileTMDB_1DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDBDigitsCellHFN', - xvalue = 'HFN', title = 'Mean RMS (HFN);[ADC]', + addTileTMDB_1DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDB_DigitsCellHFN', + xvalue = 'HFN', title = 'Mean RMS (HFN);[ADC]', path = 'Tile/TMDBDigits', type='TH1D', run = run, xbins = 41, xmin = -0.5, xmax = 40.5) - addTileTMDB_1DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDBDigitsCellAmplitude', + addTileTMDB_1DHistogramsArray(helper, tileTMDBDigitsMonAlg, name = 'TMDB_DigitsCellAmplitude', xvalue = 'amplitude', title = 'Difference between maximum and minimum sample;[ADC]', path = 'Tile/TMDBDigits', type='TH1D', run = run, xbins = 101, xmin = -0.5, xmax = 100.5) @@ -85,11 +84,12 @@ if __name__=='__main__': ConfigFlags.Output.HISTFileName = 'TileTMDBDigitsMonitorOutput.root' ConfigFlags.DQ.useTrigger = False ConfigFlags.DQ.enableLumiAccess = False - + ConfigFlags.Exec.MaxEvents = 3 + ConfigFlags.fillFromArgs() ConfigFlags.lock() # Initialize configuration object, add accumulator, merge, and run. - from AthenaConfiguration.MainServicesConfig import MainServicesCfg + from AthenaConfiguration.MainServicesConfig import MainServicesCfg cfg = MainServicesCfg(ConfigFlags) @@ -97,7 +97,7 @@ if __name__=='__main__': tileTypeNames = ['TileDigitsContainer/MuRcvDigitsCnt'] cfg.merge( ByteStreamReadCfg(ConfigFlags, type_names = tileTypeNames) ) - + tileTMDBDigitsMonitorAccumulator = TileTMDBDigitsMonitoringConfig(ConfigFlags) @@ -106,10 +106,10 @@ if __name__=='__main__': cfg.printConfig(withDetails = True, summariseProps = True) ConfigFlags.dump() - + cfg.store( open('TileTMDBDigitsMonitorAlgorithm.pkl','wb') ) - sc = cfg.run(maxEvents=-1) + sc = cfg.run() import sys sys.exit(not sc.isSuccess()) diff --git a/TileCalorimeter/TileMonitoring/python/TileTMDBMonitorAlgorithm.py b/TileCalorimeter/TileMonitoring/python/TileTMDBMonitorAlgorithm.py new file mode 100644 index 0000000000000000000000000000000000000000..8f2a57a9675072fa400008033daa1a7f9b4572ed --- /dev/null +++ b/TileCalorimeter/TileMonitoring/python/TileTMDBMonitorAlgorithm.py @@ -0,0 +1,122 @@ +# +# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# +''' +@file TileTMDBMonitorAlgorithm.py +@brief Python configuration of TileTMDBMonitorAlgorithm algorithm for the Run III +''' + +def TileTMDBMonitoringConfig(flags, **kwargs): + ''' Function to configure TileTMDBMonitorAlgorithm 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 TileConditions.TileCablingSvcConfig import TileCablingSvcCfg + result.merge( TileCablingSvcCfg(flags) ) + + from TileConditions.TileTMDBConfig import TileTMDBCondAlgCfg + result.merge( TileTMDBCondAlgCfg(flags) ) + + kwargs.setdefault('fillDetailedHistograms', False) + #fillDetailedHistograms = kwargs['fillDetailedHistograms'] + + # The following class will make a sequence, configure algorithms, and link + # them to GenericMonitoringTools + from AthenaMonitoring import AthMonitorCfgHelper + helper = AthMonitorCfgHelper(flags,'TileTMDBMonitoring') + + # Adding an TileTMDBMonitorAlgorithm algorithm to the helper + from AthenaConfiguration.ComponentFactory import CompFactory + tileTMDBMonAlg = helper.addAlgorithm(CompFactory.TileTMDBMonitorAlgorithm, 'TileTMDBMonAlg') + + for k, v in kwargs.items(): + setattr(tileTMDBMonAlg, k, v) + + run = str(flags.Input.RunNumber[0]) + + # Configure histogram with TileTMDBMonAlg algorithm execution time + executeTimeGroup = helper.addGroup(tileTMDBMonAlg, 'TileTMDBMonExecuteTime', 'Tile/') + executeTimeGroup.defineHistogram('TIME_execute', path = 'TMDB', type='TH1F', + title = 'Time for execute TileTMDBMonAlg algorithm;time [#ms]', + xbins = 100, xmin = 0, xmax = 100000) + + from TileMonitoring.TileMonitoringCfgHelper import addTileTMDB_1DHistogramsArray + + addTileTMDB_1DHistogramsArray(helper, tileTMDBMonAlg, name = 'TMDB_MeanPulse', + xvalue = 'sampleNumber', value = 'sample', path = 'Tile/TMDB/MeanPulse', + title = 'Mean pulse shape in TMDB;#sample;[ADC]', type = 'TProfile', + run = run, xbins = 7, xmin = -0.5, xmax = 6.5, perModule = True) + + addTileTMDB_1DHistogramsArray(helper, tileTMDBMonAlg, name = 'TMDB_Energy', + xvalue = 'energy', path = 'Tile/TMDB/NoiseAnalysis', + title = 'Energy in TMDB;E_{TMDB} [MeV]', type = 'TH1D', run = run, + xbins = 101, xmin = -1010, xmax = 1010, perModule = True) + + errorTitle = 'Energy difference between TMDB and correspoding Tile Cell (D) PMT;E_{D_PMT} - E_{TMDB} [MeV]' + addTileTMDB_1DHistogramsArray(helper, tileTMDBMonAlg, name = 'TMDB_CalibrationError', + xvalue = 'error', path = 'Tile/TMDB/CalibError', + title = errorTitle, type = 'TH1D', run = run, + xbins = 101, xmin = -1010, xmax = 1010, perModule = True) + + from TileMonitoring.TileMonitoringCfgHelper import addTileTMDB_2DHistogramsArray + + addTileTMDB_2DHistogramsArray(helper, tileTMDBMonAlg, name = 'TMDB_Energy', + value = 'energy', title = 'Energy [MeV] in TMDB', + path = 'Tile/TMDB', type='TProfile2D', run = run) + + addTileTMDB_2DHistogramsArray(helper, tileTMDBMonAlg, name = 'TMDB_PeakPosition', + value = 'peakPosition', title = 'Position of peak sample in TMDB', + path = 'Tile/TMDB', type='TProfile2D', run = run) + + accumalator = helper.result() + result.merge(accumalator) + return result + +if __name__=='__main__': + + # Setup the Run III behavior + from AthenaCommon.Configurable import Configurable + Configurable.configurableRun3Behavior = True + + # Setup logs + from AthenaCommon.Logging import log + from AthenaCommon.Constants import INFO + log.setLevel(INFO) + + # Set the Athena configuration flags + from AthenaConfiguration.AllConfigFlags import ConfigFlags + + from AthenaConfiguration.TestDefaults import defaultTestFiles + ConfigFlags.Input.Files = defaultTestFiles.RAW + ConfigFlags.Output.HISTFileName = 'TileTMDBMonitorOutput.root' + ConfigFlags.DQ.useTrigger = False + ConfigFlags.DQ.enableLumiAccess = False + ConfigFlags.Exec.MaxEvents = 3 + ConfigFlags.fillFromArgs() + ConfigFlags.lock() + + # Initialize configuration object, add accumulator, merge, and run. + from AthenaConfiguration.MainServicesConfig import MainServicesCfg + cfg = MainServicesCfg(ConfigFlags) + + from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg + tileTypeNames = ['TileRawChannelContainer/TileRawChannelCnt', + 'TileRawChannelContainer/MuRcvRawChCnt', + 'TileDigitsContainer/MuRcvDigitsCnt'] + cfg.merge( ByteStreamReadCfg(ConfigFlags, type_names = tileTypeNames) ) + + cfg.merge( TileTMDBMonitoringConfig(ConfigFlags) ) + + cfg.printConfig(withDetails = True, summariseProps = True) + ConfigFlags.dump() + + cfg.store( open('TileTMDBMonitorAlgorithm.pkl','wb') ) + + sc = cfg.run() + + import sys + # Success should be 0 + sys.exit(not sc.isSuccess()) diff --git a/TileCalorimeter/TileMonitoring/src/TileTMDBDigitsMonitorAlgorithm.cxx b/TileCalorimeter/TileMonitoring/src/TileTMDBDigitsMonitorAlgorithm.cxx index 26ce59a572b403a9bd84dfd32bfe1dc595ac7b33..82a4305b5c36af25d727ba2df930b52bab67519b 100644 --- a/TileCalorimeter/TileMonitoring/src/TileTMDBDigitsMonitorAlgorithm.cxx +++ b/TileCalorimeter/TileMonitoring/src/TileTMDBDigitsMonitorAlgorithm.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // Tile includes @@ -7,7 +7,7 @@ #include "TileIdentifier/TileHWID.h" #include "TileCalibBlobObjs/TileCalibUtils.h" -#include <math.h> +#include <math.h> // Athena includes #include "StoreGate/ReadHandle.h" @@ -36,9 +36,9 @@ StatusCode TileTMDBDigitsMonitorAlgorithm::initialize() { using Tile = TileCalibUtils; using namespace Monitored; - m_hfnGroups = buildToolMap<int>(m_tools, "TMDBDigitsHFN", Tile::MAX_ROS - 1); - m_pedGroups = buildToolMap<int>(m_tools, "TMDBDigitsPedestal", Tile::MAX_ROS - 1); - m_ampGroups = buildToolMap<int>(m_tools, "TMDBDigitsAmplitude", Tile::MAX_ROS - 1); + m_hfnGroups = buildToolMap<int>(m_tools, "TMDB_DigitsHFN", Tile::MAX_ROS - 1); + m_pedGroups = buildToolMap<int>(m_tools, "TMDB_DigitsPedestal", Tile::MAX_ROS - 1); + m_ampGroups = buildToolMap<int>(m_tools, "TMDB_DigitsAmplitude", Tile::MAX_ROS - 1); if (m_nChannels.size() != (Tile::MAX_ROS - 1)) { @@ -49,16 +49,15 @@ StatusCode TileTMDBDigitsMonitorAlgorithm::initialize() { std::vector<std::string> partitionName = {"LBA", "LBC", "EBA", "EBC"}; // ROS - 1 to partition name map for (unsigned int partition = 0; partition < Tile::MAX_ROS-1; ++partition) { m_cellPedGroups.push_back(buildToolMap<int>(m_tools, - "TMDBDigitsCellPedestal_" + partitionName[partition], + "TMDB_DigitsCellPedestal_" + partitionName[partition], m_nChannels[partition])); m_cellHFNGroups.push_back(buildToolMap<int>(m_tools, - "TMDBDigitsCellHFN_" + partitionName[partition], + "TMDB_DigitsCellHFN_" + partitionName[partition], m_nChannels[partition])); m_cellAmpGroups.push_back(buildToolMap<int>(m_tools, - "TMDBDigitsCellAmplitude_" + partitionName[partition], - m_nChannels[partition])); + "TMDB_DigitsCellAmplitude_" + partitionName[partition], + m_nChannels[partition])); } - return StatusCode::SUCCESS; } @@ -83,7 +82,7 @@ StatusCode TileTMDBDigitsMonitorAlgorithm::fillHistograms( const EventContext& c for (IdentifierHash hash : digitsContainer->GetAllCurrentHashes()) { const TileDigitsCollection* digitsCollection = digitsContainer->indexFindPtr (hash); - + int fragId = digitsCollection->identify(); unsigned int drawer = (fragId & 0x3F); unsigned int ros = fragId >> 8; @@ -110,7 +109,7 @@ StatusCode TileTMDBDigitsMonitorAlgorithm::fillHistograms( const EventContext& c double ped = digits[0]; pedestals[partition].push_back(ped); - + mean_samp /= n_digits; rms_samp = rms_samp / n_digits - mean_samp * mean_samp; rms_samp = (rms_samp > 0.0) ? sqrt(rms_samp * n_digits / (n_digits - 1)) : 0.0; @@ -132,7 +131,7 @@ StatusCode TileTMDBDigitsMonitorAlgorithm::fillHistograms( const EventContext& c cellAmplitudes[partition][channel].push_back(amplitude); } - } + } } } @@ -146,27 +145,27 @@ StatusCode TileTMDBDigitsMonitorAlgorithm::fillHistograms( const EventContext& c auto monHFN = Monitored::Collection("HFN", hfns[partition]); fill(m_tools[m_hfnGroups[partition]], monModule, monChannel, monHFN); - + auto monAmplitude = Monitored::Collection("amplitude", amplitudes[partition]); - fill(m_tools[m_ampGroups[partition]], monModule, monChannel, monAmplitude); + fill(m_tools[m_ampGroups[partition]], monModule, monChannel, monAmplitude); for (int channel = 0; channel < int(m_nChannels[partition]); ++channel) { if (!cellPedestals[partition][channel].empty()) { auto monPedestal = Monitored::Collection("pedestal", cellPedestals[partition][channel]); - fill(m_tools[m_cellPedGroups[partition][channel]], monPedestal); + fill(m_tools[m_cellPedGroups[partition][channel]], monPedestal); } if (!cellHFNs[partition][channel].empty()) { auto monHFN = Monitored::Collection("HFN", cellHFNs[partition][channel]); - fill(m_tools[m_cellHFNGroups[partition][channel]], monHFN); + fill(m_tools[m_cellHFNGroups[partition][channel]], monHFN); } if (!cellAmplitudes[partition][channel].empty()) { auto monAmplitude = Monitored::Collection("amplitude", cellAmplitudes[partition][channel]); - fill(m_tools[m_cellAmpGroups[partition][channel]], monAmplitude); + fill(m_tools[m_cellAmpGroups[partition][channel]], monAmplitude); } - } + } } - } + } + - return StatusCode::SUCCESS; } diff --git a/TileCalorimeter/TileMonitoring/src/TileTMDBMonitorAlgorithm.cxx b/TileCalorimeter/TileMonitoring/src/TileTMDBMonitorAlgorithm.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a06b73cf5adb1cf569c54a85115a9ea777edd8b3 --- /dev/null +++ b/TileCalorimeter/TileMonitoring/src/TileTMDBMonitorAlgorithm.cxx @@ -0,0 +1,208 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +#include "TileTMDBMonitorAlgorithm.h" +#include "TileIdentifier/TileHWID.h" + + +#include "StoreGate/ReadHandle.h" +#include "StoreGate/ReadCondHandle.h" + +StatusCode TileTMDBMonitorAlgorithm::initialize() { + + ATH_MSG_DEBUG("in initialize()"); + + // initialize superclass + ATH_CHECK( AthMonitorAlgorithm::initialize() ); + + ATH_CHECK( detStore()->retrieve(m_tileHWID) ); + + ATH_CHECK( m_cablingSvc.retrieve() ); + m_cabling = m_cablingSvc->cablingService(); + + ATH_CHECK( m_rawChannelContainerKey.initialize() ); + ATH_CHECK( m_muRcvRawChannelContainerKey.initialize() ); + ATH_CHECK( m_muRcvDigitsContainerKey.initialize() ); + ATH_CHECK( m_tileCondToolTMDB.retrieve() ); + + if (m_pulseEnergyRange.size() != 2) { + ATH_MSG_FATAL( "Size of PulseEnergyRange should be 2 (from,to), but is " << m_pulseEnergyRange.size() ); + return StatusCode::FAILURE; + } + + if (m_energyRange.size() != 2) { + ATH_MSG_FATAL( "Size of EnergyRange should be 2 (from,to), but is " << m_energyRange.size() ); + return StatusCode::FAILURE; + } + + using namespace Monitored; + + m_peakGroups = buildToolMap<int>(m_tools, "TMDB_PeakPosition", Tile::MAX_ROS - 1); + m_energyGroups = buildToolMap<int>(m_tools, "TMDB_Energy", Tile::MAX_ROS - 1); + + std::vector<std::string> partitionName = {"LBA", "LBC", "EBA", "EBC"}; // ROS - 1 to partition name map + int nChannels[] = {8, 8, 4, 4}; + for (unsigned int partition = 0; partition < Tile::MAX_ROS - 1; ++partition) { + + m_pulseGroups.push_back(buildToolMap<std::vector<int>>(m_tools, + "TMDB_MeanPulse_" + partitionName[partition], + Tile::MAX_DRAWER, nChannels[partition])); + + m_chanEnergyGroups.push_back(buildToolMap<std::vector<int>>(m_tools, + "TMDB_Energy_" + partitionName[partition], + Tile::MAX_DRAWER, nChannels[partition])); + + m_calibErrorGroups.push_back(buildToolMap<std::vector<int>>(m_tools, + "TMDB_CalibrationError_" + partitionName[partition], + Tile::MAX_DRAWER, nChannels[partition])); + + } + + return StatusCode::SUCCESS; +} + + +StatusCode TileTMDBMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const { + + // using Tile = TileCalibUtils; + + // In case you want to measure the execution time + auto timer = Monitored::Timer("TIME_execute"); + + float referenceEnergies[Tile::MAX_ROS - 1][Tile::MAX_DRAWER][8] = {{{0}}}; + + SG::ReadHandle<TileRawChannelContainer> rawChannelContainer(m_rawChannelContainerKey, ctx); + ATH_CHECK( rawChannelContainer.isValid() ); + + for (const TileRawChannelCollection* rawChannelCollection : *rawChannelContainer) { + if (rawChannelCollection->empty() ) continue; + + int fragId = rawChannelCollection->identify(); + int drawer = fragId & 0x3F; + int ros = fragId >> 8; + int partition = ros - 1; + + for (const TileRawChannel* rawChannel : *rawChannelCollection) { + + HWIdentifier adc_id = rawChannel->adc_HWID(); + int channel = m_tileHWID->channel(adc_id); + float energy = rawChannel->amplitude(); + + std::map<int, int>::const_iterator it = m_cellTMDB[partition].get().find(channel); + if (it != m_cellTMDB[partition].get().end()) { + int channelTMDB = (*it).second; + if ((ros < 3) && (drawer % 2 == 0)) { + ++channelTMDB; // In LB TMDB channels in even drawers are shifted by one + } + referenceEnergies[partition][drawer][channelTMDB] = energy; + } + + } + } + + std::vector<float> energies[Tile::MAX_ROS - 1]; + std::vector<int> energyDrawers[Tile::MAX_ROS - 1]; + std::vector<int> energyChannels[Tile::MAX_ROS - 1]; + + SG::ReadHandle<TileRawChannelContainer> muRcvRawChannelContainer(m_muRcvRawChannelContainerKey, ctx); + ATH_CHECK( muRcvRawChannelContainer.isValid() ); + + for (const TileRawChannelCollection* muRcvRawChannelCollection : *muRcvRawChannelContainer) { + if (muRcvRawChannelCollection->empty() ) continue; + + int fragId = muRcvRawChannelCollection->identify(); + int drawer = fragId & 0x3F; + int ros = fragId >> 8; + unsigned int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer); + int partition = ros - 1; + + for (const TileRawChannel* muRcvRawChannel : *muRcvRawChannelCollection) { + HWIdentifier adc_id = muRcvRawChannel->adc_HWID(); + int channel = m_tileHWID->channel(adc_id); + float amplitude = muRcvRawChannel->amplitude(); + float energy = m_tileCondToolTMDB->channelCalib(drawerIdx, channel, amplitude); + + energyDrawers[partition].push_back(drawer); + energyChannels[partition].push_back(channel); + energies[partition].push_back(energy); + + auto monEnergy = Monitored::Scalar<float>("energy", energy); + fill(m_tools[m_chanEnergyGroups[partition][drawer][channel]], monEnergy); + + auto monCalibError = Monitored::Scalar<float>("error", referenceEnergies[partition][drawer][channel] - energy); + fill(m_tools[m_calibErrorGroups[partition][drawer][channel]], monCalibError); + + ATH_MSG_VERBOSE(Tile::getDrawerString(ros, drawer) + << " TMDB channel " << channel + << ": energy [MeV] = " << energy); + } + } + + + std::vector<float> peakPositions[Tile::MAX_ROS - 1]; + std::vector<int> peakPositionDrawers[Tile::MAX_ROS - 1]; + std::vector<int> peakPositionChannels[Tile::MAX_ROS - 1]; + + SG::ReadHandle<TileDigitsContainer> muRcvDigitsContainer(m_muRcvDigitsContainerKey, ctx); + ATH_CHECK( muRcvDigitsContainer.isValid() ); + + for (const TileDigitsCollection* muRcvDigitsCollection : *muRcvDigitsContainer) { + if (muRcvDigitsCollection->empty() ) continue; + + int fragId = muRcvDigitsCollection->identify(); + int drawer = fragId & 0x3F; + int ros = fragId >> 8; + int partition = ros - 1; + + for (const TileDigits* muRcvDigits : *muRcvDigitsCollection) { + HWIdentifier adc_id = muRcvDigits->adc_HWID(); + int channel = m_tileHWID->channel(adc_id); + + float energy = referenceEnergies[partition][drawer][channel]; + if ((energy > m_pulseEnergyRange[0]) && (energy < m_pulseEnergyRange[1])) { + peakPositionDrawers[partition].push_back(drawer); + peakPositionChannels[partition].push_back(channel); + + std::vector<float> samples = muRcvDigits->samples(); + unsigned int nSamples = samples.size(); + std::vector<int> sampleNumbers(nSamples, 0); + std::iota(sampleNumbers.begin(), sampleNumbers.end(), 0); + + auto monSample = Monitored::Collection("sample", samples); + auto monSampleNumber = Monitored::Collection("sampleNumber", sampleNumbers); + + fill(m_tools[m_pulseGroups[partition][drawer][channel]], monSampleNumber, monSample); + + int peakPosition = std::distance(samples.begin(), std::max_element(samples.begin(), samples.end())); + peakPositions[partition].push_back(peakPosition); + ATH_MSG_VERBOSE(Tile::getDrawerString(ros, drawer) + << " TMDB channel " << channel + << ": peak position = " << peakPosition); + } + } + } + + + + for (unsigned int partition = 0; partition < Tile::MAX_ROS - 1; ++partition) { + if (!energies[partition].empty()) { + auto monModule = Monitored::Collection("module", energyDrawers[partition]); + auto monChannel = Monitored::Collection("channel", energyChannels[partition]); + auto monEnergy = Monitored::Collection("energy", energies[partition]); + fill(m_tools[m_energyGroups[partition]], monModule, monChannel, monEnergy); + } + + if (!peakPositions[partition].empty()) { + auto monModule = Monitored::Collection("module", peakPositionDrawers[partition]); + auto monChannel = Monitored::Collection("channel", peakPositionChannels[partition]); + auto monPeakPosition = Monitored::Collection("peakPosition", peakPositions[partition]); + fill(m_tools[m_peakGroups[partition]], monModule, monChannel, monPeakPosition); + } + } + + + fill("TileTMDBMonExecuteTime", timer); + + return StatusCode::SUCCESS; +} diff --git a/TileCalorimeter/TileMonitoring/src/TileTMDBMonitorAlgorithm.h b/TileCalorimeter/TileMonitoring/src/TileTMDBMonitorAlgorithm.h new file mode 100644 index 0000000000000000000000000000000000000000..f7f604bb510ee3870278c1ec581116c3a6e07969 --- /dev/null +++ b/TileCalorimeter/TileMonitoring/src/TileTMDBMonitorAlgorithm.h @@ -0,0 +1,94 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TILEMONITORING_TILETMDBMONITORALGORITHM_H +#define TILEMONITORING_TILETMDBMONITORALGORITHM_H + +#include "TileEvent/TileDigitsContainer.h" +#include "TileEvent/TileRawChannelContainer.h" +#include "TileConditions/ITileCondToolTMDB.h" +#include "TileConditions/TileCablingSvc.h" +#include "TileCalibBlobObjs/TileCalibUtils.h" + +#include "AthenaMonitoring/AthMonitorAlgorithm.h" +#include "AthenaMonitoringKernel/Monitored.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/ReadCondHandleKey.h" + +class TileHWID; +class TileCablingService; + +/** @class TileTMDBMonitorAlgorithm + * @brief Class for Tile TMDB based monitoring + */ + +class TileTMDBMonitorAlgorithm: public AthMonitorAlgorithm { + + public: + + using AthMonitorAlgorithm::AthMonitorAlgorithm; + virtual ~TileTMDBMonitorAlgorithm() = default; + virtual StatusCode initialize() override; + virtual StatusCode fillHistograms(const EventContext& ctx) const override; + + private: + + Gaudi::Property<std::vector<float>> m_pulseEnergyRange{this, + "PulseEnergyRange", {1000.0F, 5000.F}, "Energy [MeV] range for pulse shape"}; + + Gaudi::Property<std::vector<float>> m_energyRange{this, + "EnergyRange", {100.0F, 10000.F}, "Energy [MeV] range for pulse shape"}; + + Gaudi::Property<bool> m_fillDetailedHistograms{this, + "fillDetailedHistograms", false, "Fill monitoring histograms per TMDB channel"}; + + SG::ReadHandleKey<TileRawChannelContainer> m_rawChannelContainerKey{this, + "TileRawChannelContainer", "TileRawChannelCnt", "Input Tile raw channel container key"}; + + SG::ReadHandleKey<TileRawChannelContainer> m_muRcvRawChannelContainerKey{this, + "MuonReceiverRawChannelContainer", "MuRcvRawChCnt", "Input Tile muon receiver raw channel container key"}; + + SG::ReadHandleKey<TileDigitsContainer> m_muRcvDigitsContainerKey{this, + "MuonReceiverDigitsContainer", "MuRcvDigitsCnt", "Input Tile muon receiver digits container key"}; + + ToolHandle<ITileCondToolTMDB> m_tileCondToolTMDB{this, + "TileCondToolTMDB", "TileCondToolTMDB", "Tile TMDB conditions tool"}; + + /** + * @brief Name of Tile cabling service + */ + ServiceHandle<TileCablingSvc> m_cablingSvc{ this, + "TileCablingSvc", "TileCablingSvc", "The Tile cabling service"}; + + const TileHWID* m_tileHWID{nullptr}; + const TileCablingService* m_cabling{nullptr}; + + std::vector<int> m_peakGroups; + std::vector<int> m_energyGroups; + + std::vector<std::vector<std::vector<int>>> m_chanEnergyGroups; + std::vector<std::vector<std::vector<int>>> m_calibErrorGroups; + std::vector<std::vector<std::vector<int>>> m_pulseGroups; + + using Tile = TileCalibUtils; + + // Mapping from Tile raw channels to TMDB in LB for odd modules, + // in even modules TMDB channels are shifted by 1 + const std::map<int, int> m_cellTMDB_LB{{0, 0 /*D0*/}, + {13, 1 /*D1L*/}, {14, 2 /*D1R*/}, + {24, 3 /*D2R*/}, {25, 4 /*D2L*/}, + {41, 5 /*D3L*/}, {44, 6 /*D3R*/}}; + + // Mapping from Tile raw channels to TMDB in EB + const std::map<int, int> m_cellTMDB_EB{{16, 0 /*D5R*/}, {17, 1 /*D5L*/}, + {37, 2 /*D6L*/}, {38, 3 /*D6R*/}}; + + std::reference_wrapper<const std::map<int, int>> m_cellTMDB[Tile::MAX_ROS - 1] = {m_cellTMDB_LB, + m_cellTMDB_LB, + m_cellTMDB_EB, + m_cellTMDB_EB}; +}; + + +#endif // TILEMONITORING_TILETMDBMONITORALGORITHM_H diff --git a/TileCalorimeter/TileMonitoring/src/components/TileMonitoring_entries.cxx b/TileCalorimeter/TileMonitoring/src/components/TileMonitoring_entries.cxx index 6b42257bfd6fc082b30f323166ea0a535b76ab26..af8940d7f307e49b32971cf86043199c580ff5da 100644 --- a/TileCalorimeter/TileMonitoring/src/components/TileMonitoring_entries.cxx +++ b/TileCalorimeter/TileMonitoring/src/components/TileMonitoring_entries.cxx @@ -37,6 +37,7 @@ #include "../TileMuonFitMonitorAlgorithm.h" #include "../TileRODMonitorAlgorithm.h" #include "../TileTMDBDigitsMonitorAlgorithm.h" +#include "../TileTMDBMonitorAlgorithm.h" DECLARE_COMPONENT( TileFatherMonTool ) DECLARE_COMPONENT( TilePaterMonTool ) @@ -77,3 +78,4 @@ DECLARE_COMPONENT( TileRawChannelNoiseMonitorAlgorithm ) DECLARE_COMPONENT( TileMuonFitMonitorAlgorithm ) DECLARE_COMPONENT( TileRODMonitorAlgorithm ) DECLARE_COMPONENT( TileTMDBDigitsMonitorAlgorithm ) +DECLARE_COMPONENT( TileTMDBMonitorAlgorithm )