diff --git a/Control/AthenaCommon/python/AthenaCommonFlags.py b/Control/AthenaCommon/python/AthenaCommonFlags.py index 8bdf9fc99842917b5bf08a87e53c5642be77f31f..321b3ef4b1708d2a3f3473dd90b16921e7e5ef74 100755 --- a/Control/AthenaCommon/python/AthenaCommonFlags.py +++ b/Control/AthenaCommon/python/AthenaCommonFlags.py @@ -348,6 +348,12 @@ class MCChannelNumber(JobProperty): allowedTypes=['int'] StoredValue = 0 +class MCCampaign(JobProperty): + """MC campaign""" + statusOn=True + allowedTypes=['str'] + StoredValue = '' + ##----------------------------------------------------------------------------- ## 2nd step ## Definition of the AthenaCommon flag container @@ -392,6 +398,7 @@ jobproperties.AthenaCommonFlags.add_JobProperty(isOnlineStateless) jobproperties.AthenaCommonFlags.add_JobProperty(RuntimeStrictness) jobproperties.AthenaCommonFlags.add_JobProperty(DoFullChain) jobproperties.AthenaCommonFlags.add_JobProperty(MCChannelNumber) +jobproperties.AthenaCommonFlags.add_JobProperty(MCCampaign) ##----------------------------------------------------------------------------- ## 5th step diff --git a/Control/AthenaConfiguration/python/AllConfigFlags.py b/Control/AthenaConfiguration/python/AllConfigFlags.py index 49780a81794d58a135c67cf2c52a29a3efd4125b..23031cf3c28e8737b9d50d40caa509c52e194fb1 100644 --- a/Control/AthenaConfiguration/python/AllConfigFlags.py +++ b/Control/AthenaConfiguration/python/AllConfigFlags.py @@ -4,6 +4,7 @@ from AthenaCommon.SystemOfUnits import TeV from AthenaConfiguration.AthConfigFlags import AthConfigFlags, isGaudiEnv from AthenaConfiguration.AutoConfigFlags import GetFileMD, getInitialTimeStampsFromRunNumbers, getRunToTimestampDict, getSpecialConfigurationMetadata from AthenaConfiguration.Enums import BeamType, Format, ProductionStep, Project +from Campaigns.Utils import Campaign from PyUtils.moduleExists import moduleExists @@ -46,6 +47,7 @@ def _createCfgFlags(): acf.addFlag('Input.FailOnUnknownCollections', False) acf.addFlag('Input.ProjectName', lambda prevFlags : GetFileMD(prevFlags.Input.Files).get("project_name", "data17_13TeV")) # former global.ProjectName + acf.addFlag('Input.MCCampaign', lambda prevFlags : Campaign(GetFileMD(prevFlags.Input.Files).get("mc_campaign", "")), enum=Campaign) acf.addFlag('Input.TriggerStream', lambda prevFlags : GetFileMD(prevFlags.Input.Files).get("stream", "") if prevFlags.Input.Format == Format.BS else GetFileMD(prevFlags.Input.Files).get("triggerStreamOfFile", "")) # former global.TriggerStream acf.addFlag('Input.Format', lambda prevFlags : Format.BS if GetFileMD(prevFlags.Input.Files).get("file_type", "BS") == "BS" else Format.POOL, enum=Format) # former global.InputFormat diff --git a/Event/EventInfoMgt/python/TagInfoMgrConfig.py b/Event/EventInfoMgt/python/TagInfoMgrConfig.py index c2ba4a315cc111a87b49c6cb314f8f6a9584ace7..a3e9badaf9e10eaef220bc7c3548b83dc498b624 100644 --- a/Event/EventInfoMgt/python/TagInfoMgrConfig.py +++ b/Event/EventInfoMgt/python/TagInfoMgrConfig.py @@ -1,24 +1,27 @@ # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator, ConfigurationError from AthenaConfiguration.ComponentFactory import CompFactory -import os -def TagInfoMgrCfg(configFlags,tagValuePairs={}): - - #Sanity check: - if not isinstance(tagValuePairs,dict): +def TagInfoMgrCfg(flags, tagValuePairs={}): + # Sanity check: + if not isinstance(tagValuePairs, dict): raise ConfigurationError("Parameter extraTagValuePairs is supposed to be a dictionary") - #Build project-version string for the TagInfoMgr - project = os.getenv('AtlasProject',"Unknown") - version = os.getenv('AtlasVersion',"Unknown") + # Build project-version string for the TagInfoMgr + from os import getenv + project = getenv("AtlasProject", "Unknown") + version = getenv("AtlasVersion", "Unknown") atlasRelease=project+"-"+version tagValuePairs.update({"AtlasRelease" : atlasRelease}) - result=ComponentAccumulator() - result.addService(CompFactory.TagInfoMgr(ExtraTagValuePairs = tagValuePairs), primary=True) + from Campaigns.Utils import Campaign + if flags.Input.isMC and flags.Input.MCCampaign is not Campaign.Unknown: + tagValuePairs.update({"mc_campaign" : flags.Input.MCCampaign.value}) + + result = ComponentAccumulator() + result.addService(CompFactory.TagInfoMgr(ExtraTagValuePairs=tagValuePairs), primary=True) return result @@ -30,7 +33,7 @@ if __name__ == "__main__": ConfigFlags.lock() acc = TagInfoMgrCfg( ConfigFlags, {"SomeKey": "SomeValue"} ) - acc2 = TagInfoMgrCfg( ConfigFlags, {"OtherKey":"OtherValue", "SomeKey": "SomeValue"} ) + acc2 = TagInfoMgrCfg( ConfigFlags, {"OtherKey": "OtherValue", "SomeKey": "SomeValue"} ) acc.merge(acc2) assert "SomeKey" in acc.getService("TagInfoMgr").ExtraTagValuePairs diff --git a/Event/xAOD/xAODMetaData/Root/FileMetaDataAccessors_v1.cxx b/Event/xAOD/xAODMetaData/Root/FileMetaDataAccessors_v1.cxx index 0f3d9b573c4188e2986a4136e16b52b789c95fe0..8d24b96c5d13586fb61f29443d20f68ffc5a4c92 100644 --- a/Event/xAOD/xAODMetaData/Root/FileMetaDataAccessors_v1.cxx +++ b/Event/xAOD/xAODMetaData/Root/FileMetaDataAccessors_v1.cxx @@ -50,6 +50,7 @@ namespace xAOD { DECLARE_STRING_ACCESSOR( conditionsTag ); DECLARE_STRING_ACCESSOR( beamType ); DECLARE_STRING_ACCESSOR( simFlavour ); + DECLARE_STRING_ACCESSOR( mcCampaign ); default: std::cerr << "xAOD::FileMetaData_v1 ERROR No string accessor for " diff --git a/Event/xAOD/xAODMetaData/Root/FileMetaData_v1.cxx b/Event/xAOD/xAODMetaData/Root/FileMetaData_v1.cxx index 34542348f66ee6b2bd5f135918d1a27f9f6d2b28..2640720393ca0ea02a26fa94eba99391b605cf6d 100644 --- a/Event/xAOD/xAODMetaData/Root/FileMetaData_v1.cxx +++ b/Event/xAOD/xAODMetaData/Root/FileMetaData_v1.cxx @@ -431,6 +431,7 @@ std::ostream& operator<< ( std::ostream& out, PRINT_TYPE( mcProcID ); PRINT_TYPE( simFlavour ); PRINT_TYPE( isDataOverlay ); + PRINT_TYPE( mcCampaign ); default: out << "UNKNOWN (" << static_cast< int >( type ) << ")"; diff --git a/Event/xAOD/xAODMetaData/xAODMetaData/versions/FileMetaData_v1.h b/Event/xAOD/xAODMetaData/xAODMetaData/versions/FileMetaData_v1.h index 048d2cd838f1f9c9254caae52e79906072f15930..37641a337307fc0349c7839d202cd86ed62de7b5 100644 --- a/Event/xAOD/xAODMetaData/xAODMetaData/versions/FileMetaData_v1.h +++ b/Event/xAOD/xAODMetaData/xAODMetaData/versions/FileMetaData_v1.h @@ -75,8 +75,10 @@ namespace xAOD { simFlavour = 10, /// Used data overlay for backgrounds [bool] isDataOverlay = 11, + /// MC campaign [string] + mcCampaign = 12, /// End marker - END = 12 + END = 13 }; // enum MetaDataType /// Get a pre-defined string value out of the object diff --git a/Event/xAOD/xAODMetaDataCnv/src/FileMetaDataCreatorTool.cxx b/Event/xAOD/xAODMetaDataCnv/src/FileMetaDataCreatorTool.cxx index 6a6b9daca8ec7b10a6994f17820f7483d183d293..6092039167cd6d459b8c0ca37e069590a8adbfe7 100644 --- a/Event/xAOD/xAODMetaDataCnv/src/FileMetaDataCreatorTool.cxx +++ b/Event/xAOD/xAODMetaDataCnv/src/FileMetaDataCreatorTool.cxx @@ -223,6 +223,8 @@ StatusCode set(xAOD::FileMetaData::beamType, m_tagInfoMgr->findTag("beam_type")); + set(xAOD::FileMetaData::mcCampaign, m_tagInfoMgr->findTag("mc_campaign")); + std::string beamEnergy = m_tagInfoMgr->findTag("beam_energy"); try { set(xAOD::FileMetaData::beamEnergy, diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/AsgAnalysisAlgorithmsTest.py b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/AsgAnalysisAlgorithmsTest.py index 5f355ef5ea7a9d91e21fffaaa37f5fc832e6103d..3037431b930b3261ff3bc02caaed9728a68fa0f7 100644 --- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/AsgAnalysisAlgorithmsTest.py +++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/AsgAnalysisAlgorithmsTest.py @@ -229,19 +229,15 @@ def pileupConfigFiles(dataType): lumicalcfiles = [] else: lumicalcfiles = [ - # These need to be updated for release 22 data - # "GoodRunsLists/data15_13TeV/20170619/PHYS_StandardGRL_All_Good_25ns_276262-284484_OflLumi-13TeV-008.root", - # "GoodRunsLists/data16_13TeV/20180129/PHYS_StandardGRL_All_Good_25ns_297730-311481_OflLumi-13TeV-009.root", + "GoodRunsLists/data15_13TeV/20170619/PHYS_StandardGRL_All_Good_25ns_276262-284484_OflLumi-13TeV-008.root", + "GoodRunsLists/data16_13TeV/20180129/PHYS_StandardGRL_All_Good_25ns_297730-311481_OflLumi-13TeV-009.root", ] if dataType == "mc": prwfiles = [ - # These need to be updated for release 22 data and not - # be taken from cvmfs - #"/cvmfs/atlas.cern.ch/repo/sw/database/GroupData/dev/PileupReweighting/mc16_13TeV/pileup_mc16a_dsid410501_FS.root" + "PileupReweighting/mc20_common/mc20a.284500.physlite.prw.v1.root" ] else: - # We don't have a PRW file that works properly for the AFII file so we don't apply it in - # this case + # use fast sim case to test running without PRW prwfiles = [] return prwfiles, lumicalcfiles diff --git a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/PileupAnalysisSequence.py b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/PileupAnalysisSequence.py index 4adf8b7541faa4d69bb1eee4ee5d0b80f80320f2..c646852cb82d0ef05a6abdefb57b5e7a03a990b9 100644 --- a/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/PileupAnalysisSequence.py +++ b/PhysicsAnalysis/Algorithms/AsgAnalysisAlgorithms/python/PileupAnalysisSequence.py @@ -1,16 +1,17 @@ -# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration # AnaAlgorithm import(s): from AnaAlgorithm.AnaAlgSequence import AnaAlgSequence from AnaAlgorithm.DualUseConfig import createAlgorithm, addPrivateTool +from Campaigns.Utils import Campaign try: from AthenaCommon.Logging import logging except ImportError: import logging -prwlog = logging.getLogger('makePileupAnalysisSequence') +log = logging.getLogger('makePileupAnalysisSequence') -def makePileupAnalysisSequence( dataType, userPileupConfigs=[], userLumicalcFiles=[] , autoConfig=False ): +def makePileupAnalysisSequence( dataType, campaign=None, files=None, useDefaultConfig=False, userLumicalcFiles=None, userPileupConfigs=None ): """Create a PRW analysis algorithm sequence Keyword arguments: @@ -23,33 +24,49 @@ def makePileupAnalysisSequence( dataType, userPileupConfigs=[], userLumicalcFile # Create the analysis algorithm sequence object: seq = AnaAlgSequence( "PileupAnalysisSequence" ) - muMcFiles = userPileupConfigs[:] - if autoConfig: - from PileupReweighting.AutoconfigurePRW import getLumiCalcFiles,getMCMuFiles - userLumicalcFiles = getLumiCalcFiles() - if len(muMcFiles)==0: - muMcFiles = getMCMuFiles() - else: - prwlog.warning('Sent autoconfig and userPileupConfigs='+str(userPileupConfigs)) - prwlog.warning('Ignoring autoconfig and keeping user-specified files') - - if userLumicalcFiles==[]: - muDataFiles = ["GoodRunsLists/data15_13TeV/20170619/PHYS_StandardGRL_All_Good_25ns_276262-284484_OflLumi-13TeV-008.root", - "GoodRunsLists/data16_13TeV/20180129/PHYS_StandardGRL_All_Good_25ns_297730-311481_OflLumi-13TeV-009.root", - "GoodRunsLists/data17_13TeV/20180619/physics_25ns_Triggerno17e33prim.lumicalc.OflLumi-13TeV-010.root", - "GoodRunsLists/data18_13TeV/20190708/ilumicalc_histograms_None_348885-364292_OflLumi-13TeV-010.root" ] + # TODO: support per-campaign config + + toolConfigFiles = [] + toolLumicalcFiles = [] + if files is not None and (campaign is None or campaign is Campaign.Unknown or userPileupConfigs is None): + if campaign is None or campaign is Campaign.Unknown: + from Campaigns.Utils import getMCCampaign + campaign = getMCCampaign(files) + if campaign: + log.info(f'Autoconfiguring PRW with campaign: {campaign}') + else: + log.info('Campaign could not be determined.') + + if campaign: + if userPileupConfigs is None: + from PileupReweighting.AutoconfigurePRW import getConfigurationFiles + toolConfigFiles = getConfigurationFiles(campaign=campaign, files=files, useDefaultConfig=useDefaultConfig) + log.info('Setting PRW configuration based on input files') + + if toolConfigFiles: + log.info(f'Using PRW configuration: {", ".join(toolConfigFiles)}') + else: + log.info('Using user provided PRW configuration') + + if userPileupConfigs is not None: + toolConfigFiles = userPileupConfigs[:] + + if userLumicalcFiles is not None: + log.info('Using user-provided lumicalc files') + toolLumicalcFiles = userLumicalcFiles[:] else: - muDataFiles = userLumicalcFiles[:] + from PileupReweighting.AutoconfigurePRW import getLumicalcFiles + toolLumicalcFiles = getLumicalcFiles(campaign) # Set up the only algorithm of the sequence: alg = createAlgorithm( 'CP::PileupReweightingAlg', 'PileupReweightingAlg' ) addPrivateTool( alg, 'pileupReweightingTool', 'CP::PileupReweightingTool' ) - alg.pileupReweightingTool.ConfigFiles = muMcFiles - if not muMcFiles and dataType != "data": - prwlog.info("No PRW config files provided. Disabling reweighting") + alg.pileupReweightingTool.ConfigFiles = toolConfigFiles + if not toolConfigFiles and dataType != "data": + log.info("No PRW config files provided. Disabling reweighting") # Setting the weight decoration to the empty string disables the reweighting alg.pileupWeightDecoration = "" - alg.pileupReweightingTool.LumiCalcFiles = muDataFiles + alg.pileupReweightingTool.LumiCalcFiles = toolLumicalcFiles seq.append( alg, inputPropName = {} ) diff --git a/PhysicsAnalysis/AnalysisCommon/PileupReweighting/Root/PileupReweightingTool.cxx b/PhysicsAnalysis/AnalysisCommon/PileupReweighting/Root/PileupReweightingTool.cxx index a7635f1f5de20c5fe6a5773cdf57124263bdaf9b..e21633cd5e683f9955ea5ca9952ceb7183ffb6c9 100644 --- a/PhysicsAnalysis/AnalysisCommon/PileupReweighting/Root/PileupReweightingTool.cxx +++ b/PhysicsAnalysis/AnalysisCommon/PileupReweighting/Root/PileupReweightingTool.cxx @@ -57,7 +57,7 @@ PileupReweightingTool::PileupReweightingTool( const std::string& name ) :CP::TPi declareProperty("DataScaleFactorDOWN",m_downVariation=1./1.07,"Set to a value representing the 'down' fluctuation - will report a PRW_DATASF uncertainty to Systematic Registry"); declareProperty("VaryRandomRunNumber",m_varyRunNumber=false,"If true, then when doing systematic variations, RandomRunNumber will fluctuate as well. Off by default as believed to lead to overestimated uncertainties"); - declareProperty("PeriodAssignments", m_customPeriods={284500,222222,324300,300000,324300,344495,310000,344496,999999}, "Specify period number assignments to run numbers ranges - this is usually an expert option"); + declareProperty("PeriodAssignments", m_customPeriods={284500,222222,324300,300000,324300,344495,310000,344496,367384,410000,422633,999999}, "Specify period number assignments to run numbers ranges - this is usually an expert option"); declareProperty("GRLTool", m_grlTool, "If you provide a GoodRunsListSelectionTool, any information from lumicalc files will be automatically filtered" ); declareProperty("TrigDecisionTool",m_tdt, "When using the getDataWeight method, the TDT will be used to check decisions before prescale. Alternatively do expert()->SetTriggerBit('trigger',0) to flag which triggers are not fired before prescale (assumed triggers are fired if not specified)"); diff --git a/PhysicsAnalysis/AnalysisCommon/PileupReweighting/python/AutoconfigurePRW.py b/PhysicsAnalysis/AnalysisCommon/PileupReweighting/python/AutoconfigurePRW.py index 33fb31110b469348455127a59c6f17ad6d9ccef3..cb3d1fe3bda4008c06f213525e8a6ff4458806fd 100644 --- a/PhysicsAnalysis/AnalysisCommon/PileupReweighting/python/AutoconfigurePRW.py +++ b/PhysicsAnalysis/AnalysisCommon/PileupReweighting/python/AutoconfigurePRW.py @@ -1,78 +1,131 @@ -# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +from Campaigns.Utils import Campaign, getMCCampaign -# Helper functions for the configuration of pileup reweighting -reco_campaigns = { - 'mc16a' : ['r9280','r9287','r9364'], - 'mc16d' : ['r10069','r10201','r10211','r10212'], - 'mc16e' : ['r10724','r10726'] -} -# Function to get the campaign -def getCampaign(ami_tag = None, project = None): - # Attempt auto-configuration - if ami_tag is None or project is None: - # either is not set, get unset from InputFilePeeker - from RecExConfig.InputFilePeeker import inputFileSummary - if inputFileSummary is not None: - ami_tag = inputFileSummary['tag_info']['AMITag'] if ami_tag is None else ami_tag - project = inputFileSummary['tag_info']['project_name'] if project is None else project - - assert ami_tag is not None - assert project is not None - - for c in reco_campaigns: - for r in reco_campaigns[c]: - if r in ami_tag: - return c - - # MC-equivalent projects for data - if 'data18' in project: return 'mc16e' - elif 'data17' in project: return 'mc16d' - elif 'data16' in project or 'data15' in project: return 'mc16a' - - return None - -# Function to get the data lumicalc files -def getLumiCalcFiles(campaign = None): - # Attempt auto-configuration - campaign = campaign or getCampaign() - if campaign=='mc16a': - return ["GoodRunsLists/data15_13TeV/20170619/PHYS_StandardGRL_All_Good_25ns_276262-284484_OflLumi-13TeV-008.root", - "GoodRunsLists/data16_13TeV/20180129/PHYS_StandardGRL_All_Good_25ns_297730-311481_OflLumi-13TeV-009.root"] - elif campaign=='mc16d': - return ["GoodRunsLists/data17_13TeV/20180619/physics_25ns_Triggerno17e33prim.lumicalc.OflLumi-13TeV-010.root" ] - elif campaign=='mc16e': - return ["GoodRunsLists/data18_13TeV/20190708/ilumicalc_histograms_None_348885-364292_OflLumi-13TeV-010.root" ] - return [] - -def getMCMuFiles(data_type = None, campaign = None, dsid = None): +def getLumicalcFiles(campaign): + list = [] + + if campaign in [Campaign.MC16a, Campaign.MC20a]: + list.append( + 'GoodRunsLists/data15_13TeV/20170619/PHYS_StandardGRL_All_Good_25ns_276262-284484_OflLumi-13TeV-008.root' + ) + list.append( + 'GoodRunsLists/data16_13TeV/20180129/PHYS_StandardGRL_All_Good_25ns_297730-311481_OflLumi-13TeV-009.root' + ) + + elif campaign in [Campaign.MC16d, Campaign.MC20d]: + list.append( + 'GoodRunsLists/data17_13TeV/20180619/physics_25ns_Triggerno17e33prim.lumicalc.OflLumi-13TeV-010.root' + ) + + elif campaign in [Campaign.MC16e, Campaign.MC20e]: + list.append( + 'GoodRunsLists/data18_13TeV/20190318/ilumicalc_histograms_None_348885-364292_OflLumi-13TeV-010.root' + ) + + elif campaign in [Campaign.MC21a]: + list.append( + 'GoodRunsLists/data22_13p6TeV/20220902/ilumicalc_histograms_None_430536-430648_OflLumi-Run3-001.root' + ) + + else: + raise ValueError(f'Unsupported campaign {campaign}') + + if campaign in [Campaign.MC16a, Campaign.MC20a]: + assert(len(list) == 2) + else: + assert(len(list) == 1) + + return list + + +def actualMuFiles(campaign): + list = [] + + if campaign in [Campaign.MC16d, Campaign.MC20d]: + list.append( + 'GoodRunsLists/data17_13TeV/20180619/physics_25ns_Triggerno17e33prim.actualMu.OflLumi-13TeV-010.root' + ) + elif campaign in [Campaign.MC16e, Campaign.MC20e]: + list.append( + 'GoodRunsLists/data18_13TeV/20190318/physics_25ns_Triggerno17e33prim.actualMu.OflLumi-13TeV-010.root' + ) + + if campaign in [Campaign.MC16d, Campaign.MC20d, Campaign.MC16e, Campaign.MC20e]: + assert(len(list) == 1) + else: + assert(len(list) == 0) + + return list + + +def defaultConfigFiles(campaign): + list = [] + + if campaign in [Campaign.MC20a]: + list.append( + 'PileupReweighting/mc20_common/mc20a.284500.physlite.prw.v1.root' + ) + elif campaign in [Campaign.MC20d]: + list.append( + 'PileupReweighting/mc20_common/mc20d.300000.physlite.prw.v1.root' + ) + elif campaign in [Campaign.MC20e]: + list.append( + 'PileupReweighting/mc20_common/mc20e.310000.physlite.prw.v1.root' + ) + elif campaign in [Campaign.MC21a]: + list.append( + 'PileupReweighting/mc21_common/mc21a.410000.physlite.prw.v1.root' + ) + else: + raise ValueError(f'Unsupported campaign {campaign}') + + assert(len(list) == 1) + + return list + + +def getConfigurationFiles(campaign=None, dsid=None, data_type=None, files=None, useDefaultConfig=False): # Attempt auto-configuration - defaultDirectory = 'dev/PileupReweighting/share' - - if data_type is None or campaign is None or dsid is None: - # one is not set, get unset from InputFilePeeker - from RecExConfig.InputFilePeeker import inputFileSummary - if inputFileSummary is not None and 'IS_SIMULATION' in inputFileSummary['evt_type']: - # We are in an MC file - get the AMI tag - ami_tag = inputFileSummary['tag_info']['AMITag'] - campaign = getCampaign(ami_tag=ami_tag) - dsid = str(inputFileSummary['mc_channel_number'][0]) if dsid is None else dsid - sim_flavor = inputFileSummary['metadata']['/Simulation/Parameters']['SimulationFlavour'] - sim_type = 'FS' if sim_flavor in ['FullG4'] else 'AFII' - inputFile = defaultDirectory+'/DSID'+dsid[:3]+'xxx/pileup_'+campaign+'_dsid'+dsid+'_'+sim_type+'.root' - return [inputFile] + default_directory = 'dev/PileupReweighting/share' + configuration_files = [] + + if files is not None and (campaign is None or dsid is None or data_type is None): + if campaign is None: + campaign = getMCCampaign(files) + + if dsid is None or data_type is None: + from AthenaConfiguration.AutoConfigFlags import GetFileMD + metadata = GetFileMD(files) + if dsid is None: + dsid = str(metadata.get('mc_channel_number', 0)) + if data_type is None: + simulation_flavour = GetFileMD(files).get('Simulator', '') + if not simulation_flavour: + simulation_flavour = GetFileMD(files).get('SimulationFlavour', '') + data_type = 'mc' if simulation_flavour in ['', 'FullG4', 'FullG4_QS', 'FullG4_Longlived'] else 'afii' + + # data_type as in pileup analysis sequence: either 'data' or ('mc' or 'afii') + if data_type == 'data': + raise ValueError('Data is not supported') + + if data_type == 'mc': + simulation_type = 'FS' + elif data_type == 'afii': + simulation_type = 'AFII' + else: + raise ValueError(f'Invalid data_type {data_type}') + + configuration_files = actualMuFiles(campaign) + if useDefaultConfig: + configuration_files += defaultConfigFiles(campaign) + return configuration_files + + config = f'{default_directory}/DSID{dsid[:3]}xxx/pileup_{campaign.value}_dsid{dsid}_{simulation_type}.root' + from PathResolver import PathResolver + if not PathResolver.FindCalibFile(config): + return [] else: - # everything set explicitly - # data_type as in pileup analysis sequence: either 'data' or ('mc' or 'afii') - if data_type == "data": - return [] - if data_type == "mc": - sim_type = "FS" - elif data_type == "afii": - sim_type = "AFII" - else: - raise ValueError("Invalid data_type %s" % data_type) - - inputFile = defaultDirectory+'/DSID'+dsid[:3]+'xxx/pileup_'+campaign+'_dsid'+dsid+'_'+sim_type+'.root' - return [inputFile] - return [] + configuration_files.append(config) + return configuration_files diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYSLITE.py b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYSLITE.py index df64130a2f1fa687cabf92c6560b019f32f147b0..bec1c292352f8bdb7e5fa8981176b76e827aee0d 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYSLITE.py +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkPhys/share/PHYSLITE.py @@ -209,11 +209,15 @@ if DerivationFrameworkIsMonteCarlo: dataType = "mc" # Create a pile-up analysis sequence -from AsgAnalysisAlgorithms.PileupAnalysisSequence import makePileupAnalysisSequence -pileupSequence = makePileupAnalysisSequence( dataType ) -pileupSequence.configure( inputName = {}, outputName = {} ) -print( pileupSequence ) # For debugging -SeqPHYSLITE += pileupSequence +if DerivationFrameworkIsMonteCarlo: + from AsgAnalysisAlgorithms.PileupAnalysisSequence import makePileupAnalysisSequence + from RecExConfig.RecoFunctions import InputFileNames + from AthenaCommon.AthenaCommonFlags import athenaCommonFlags + from Campaigns.Utils import Campaign + pileupSequence = makePileupAnalysisSequence( dataType, campaign=Campaign(athenaCommonFlags.MCCampaign()), files=InputFileNames(), useDefaultConfig=True ) + pileupSequence.configure( inputName = {}, outputName = {} ) + print( pileupSequence ) # For debugging + SeqPHYSLITE += pileupSequence # Include, and then set up the electron analysis sequence: from EgammaAnalysisAlgorithms.ElectronAnalysisSequence import makeElectronAnalysisSequence @@ -377,7 +381,7 @@ PHYSLITESlimmingHelper.ExtraVariables = [ "MET_Core_AnalysisMET.name.mpx.mpy.sumet.source", "METAssoc_AnalysisMET.", "InDetTrackParticles.TTVA_AMVFVertices.TTVA_AMVFWeights.numberOfTRTHits.numberOfTRTOutliers", - "EventInfo.hardScatterVertexLink.RandomRunNumber", + "EventInfo.hardScatterVertexLink.RandomRunNumber.PileupWeight_NOSYS", "Kt4EMPFlowEventShape.Density", "TauTracks.pt.eta.phi.flagSet.trackLinks", ] diff --git a/Projects/AnalysisBase/package_filters.txt b/Projects/AnalysisBase/package_filters.txt index 263126ebbb8f1ad8965801cabdbb18ecd7e7e26d..04aa88735c466ef141c186eaef85ff10297c9860 100644 --- a/Projects/AnalysisBase/package_filters.txt +++ b/Projects/AnalysisBase/package_filters.txt @@ -114,6 +114,7 @@ + Reconstruction/LwtnnUtils + Simulation/SimulationConfig + Tools/ART ++ Tools/Campaigns + Tools/DirectIOART + Tools/PathResolver + Tools/PyUtils diff --git a/Projects/AthAnalysis/package_filters.txt b/Projects/AthAnalysis/package_filters.txt index ad410272925f68e2f4ee289c34c60c2a1b061c8d..bc3a02b30b325479a40a44320f86f1f7c3892b7b 100644 --- a/Projects/AthAnalysis/package_filters.txt +++ b/Projects/AthAnalysis/package_filters.txt @@ -109,8 +109,10 @@ + Reconstruction/egamma/egammaRecEvent + Reconstruction/egamma/egammaUtils + Reconstruction/tauRecTools ++ Simulation/SimulationConfig + Tools/PathResolver + Tools/ART ++ Tools/Campaigns + Tools/DirectIOART + Trigger/TrigAnalysis/TrigAnalysisInterfaces + Trigger/TrigAnalysis/TrigBunchCrossingTool diff --git a/Projects/AthGeneration/package_filters.txt b/Projects/AthGeneration/package_filters.txt index 45c87280bc2293bd30786d7cb7bfbb6fe3b3aa39..1148582bbcd1b3d565e80f289de6f09dab027820 100644 --- a/Projects/AthGeneration/package_filters.txt +++ b/Projects/AthGeneration/package_filters.txt @@ -191,6 +191,7 @@ + Reconstruction/RecExample/RecExConfig + Simulation/Tools/AtlasCLHEP_RandomGenerators + Tools/ART ++ Tools/Campaigns + Tools/PathResolver + Tools/PmbCxxUtils + Tools/PyJobTransforms diff --git a/Reconstruction/RecExample/RecExCommon/share/RecExCommon_topOptions.py b/Reconstruction/RecExample/RecExCommon/share/RecExCommon_topOptions.py index 0c891ba68ef273a9df0881d71ca8d6e33a86835b..a554d3b4fd222a8ced9ea3db3a07c5476b5e14da 100644 --- a/Reconstruction/RecExample/RecExCommon/share/RecExCommon_topOptions.py +++ b/Reconstruction/RecExample/RecExCommon/share/RecExCommon_topOptions.py @@ -137,6 +137,9 @@ svcMgr.TagInfoMgr.ExtraTagValuePairs.update({"beam_type": jobproperties.Beam.bea "project_name": str(rec.projectName()), "AtlasRelease_" + rec.OutputFileNameForRecoStep(): rec.AtlasReleaseVersion() }) +if athenaCommonFlags.MCCampaign(): + svcMgr.TagInfoMgr.ExtraTagValuePairs.update({"mc_campaign": athenaCommonFlags.MCCampaign()}) + # Set AMITag in /TagInfo from PyUtils import AMITagHelper AMITagHelper.SetAMITag(outputTag=rec.AMITag()) diff --git a/Tools/Campaigns/python/MC16.py b/Tools/Campaigns/python/MC16.py index 69a60c54a1be343c845e4f9bfb7270621b160280..6515cb995c66d4475420c2ae7e4d53ea5d2c0113 100644 --- a/Tools/Campaigns/python/MC16.py +++ b/Tools/Campaigns/python/MC16.py @@ -1,12 +1,14 @@ # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration -from SimulationConfig.SimEnums import SimulationFlavour, TruthStrategy -from LArConfiguration.LArConfigRun2 import LArConfigRun2PileUp, LArConfigRun2NoPileUp +from Campaigns.Utils import Campaign def MC16a(flags): """MC16a flags for MC to match 2015 and 2016 data""" + flags.Input.MCCampaign = Campaign.MC16a + flags.Beam.NumberOfCollisions = 20. + from LArConfiguration.LArConfigRun2 import LArConfigRun2PileUp LArConfigRun2PileUp(flags) flags.Digitization.HighGainEMECIW = True @@ -22,8 +24,11 @@ def MC16a(flags): def MC16d(flags): """MC16d flags for MC to match 2017 data""" + flags.Input.MCCampaign = Campaign.MC16d + flags.Beam.NumberOfCollisions = 20. + from LArConfiguration.LArConfigRun2 import LArConfigRun2PileUp LArConfigRun2PileUp(flags) flags.Tile.BestPhaseFromCOOL = False @@ -38,8 +43,11 @@ def MC16d(flags): def MC16e(flags): """MC16e flags for MC to match 2018 data""" + flags.Input.MCCampaign = Campaign.MC16e + flags.Beam.NumberOfCollisions = 20. + from LArConfiguration.LArConfigRun2 import LArConfigRun2PileUp LArConfigRun2PileUp(flags) flags.Tile.BestPhaseFromCOOL = False @@ -56,6 +64,7 @@ def MC16NoPileUp(flags): """MC16 flags for MC without pile-up""" flags.Beam.NumberOfCollisions = 0. + from LArConfiguration.LArConfigRun2 import LArConfigRun2NoPileUp LArConfigRun2NoPileUp(flags) flags.Tile.BestPhaseFromCOOL = False @@ -64,6 +73,7 @@ def MC16NoPileUp(flags): def MC16Simulation(flags): """MC16 flags for simulation""" + from SimulationConfig.SimEnums import SimulationFlavour, TruthStrategy flags.Sim.PhysicsList = 'FTFP_BERT_ATL' flags.Sim.TruthStrategy = TruthStrategy.MC15aPlus diff --git a/Tools/Campaigns/python/MC20.py b/Tools/Campaigns/python/MC20.py index d84fd6e0adaeae568564a39b571226f665c95f85..e9c3bcc8be16ce86d913471f87ba9dfe633357c8 100644 --- a/Tools/Campaigns/python/MC20.py +++ b/Tools/Campaigns/python/MC20.py @@ -1,16 +1,18 @@ # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration - from AthenaConfiguration.Enums import ProductionStep -from LArConfiguration.LArConfigRun2 import LArConfigRun2PileUp, LArConfigRun2NoPileUp +from Campaigns.Utils import Campaign def MC20a(flags): """MC20a flags for MC to match 2015 and 2016 data""" + flags.Input.MCCampaign = Campaign.MC20a + flags.Beam.NumberOfCollisions = 20. flags.Digitization.InputBeamSigmaZ = 42 flags.Digitization.UseUpdatedTGCConditions = True + from LArConfiguration.LArConfigRun2 import LArConfigRun2PileUp LArConfigRun2PileUp(flags) flags.Digitization.HighGainEMECIW = True @@ -35,11 +37,14 @@ def MC20a(flags): def MC20d(flags): """MC20d flags for MC to match 2017 data""" + flags.Input.MCCampaign = Campaign.MC20d + flags.Beam.NumberOfCollisions = 20. flags.Digitization.InputBeamSigmaZ = 42 flags.Digitization.UseUpdatedTGCConditions = True + from LArConfiguration.LArConfigRun2 import LArConfigRun2PileUp LArConfigRun2PileUp(flags) flags.Tile.BestPhaseFromCOOL = False @@ -63,11 +68,14 @@ def MC20d(flags): def MC20e(flags): """MC20e flags for MC to match 2018 data""" + flags.Input.MCCampaign = Campaign.MC20e + flags.Beam.NumberOfCollisions = 20. flags.Digitization.InputBeamSigmaZ = 42 flags.Digitization.UseUpdatedTGCConditions = True + from LArConfiguration.LArConfigRun2 import LArConfigRun2PileUp LArConfigRun2PileUp(flags) flags.Tile.BestPhaseFromCOOL = False @@ -96,6 +104,7 @@ def MC20NoPileUp(flags): flags.Digitization.UseUpdatedTGCConditions = True + from LArConfiguration.LArConfigRun2 import LArConfigRun2NoPileUp LArConfigRun2NoPileUp(flags) flags.Tile.BestPhaseFromCOOL = False diff --git a/Tools/Campaigns/python/MC21.py b/Tools/Campaigns/python/MC21.py index bd2ed515bcc3517b28cdfeeb35fac5dd138cfdfe..29e905c39300b61e1446b8c7df4cb9cd06f6e3f9 100644 --- a/Tools/Campaigns/python/MC21.py +++ b/Tools/Campaigns/python/MC21.py @@ -1,13 +1,15 @@ # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration -from SimulationConfig.SimEnums import SimulationFlavour, TruthStrategy from AthenaConfiguration.Enums import ProductionStep -from LArConfiguration.LArConfigRun3 import LArConfigRun3PileUp, LArConfigRun3NoPileUp +from Campaigns.Utils import Campaign def MC21a(flags): """MC21a flags for MC to match initial Run 3 data""" + flags.Input.MCCampaign = Campaign.MC21a + flags.Beam.NumberOfCollisions = 60. + from LArConfiguration.LArConfigRun3 import LArConfigRun3PileUp LArConfigRun3PileUp(flags) flags.Tile.BestPhaseFromCOOL = False @@ -45,6 +47,7 @@ def MC21NoPileUp(flags): flags.Beam.NumberOfCollisions = 0. flags.Input.ConditionsRunNumber = 410000 + from LArConfiguration.LArConfigRun3 import LArConfigRun3NoPileUp LArConfigRun3NoPileUp(flags) flags.Tile.BestPhaseFromCOOL = False @@ -64,6 +67,7 @@ def BeamspotSplitMC21a(): def MC21SimulationBase(flags): """MC21 base flags for simulation""" + from SimulationConfig.SimEnums import SimulationFlavour, TruthStrategy flags.Sim.PhysicsList = 'FTFP_BERT_ATL' flags.Sim.TruthStrategy = TruthStrategy.MC15aPlus diff --git a/Tools/Campaigns/python/PhaseII.py b/Tools/Campaigns/python/PhaseII.py index f2ae8416c654952e7ac2e02bcdf8febf58b430f5..946ff66323627d1149aa48cc41279b6550fada5f 100644 --- a/Tools/Campaigns/python/PhaseII.py +++ b/Tools/Campaigns/python/PhaseII.py @@ -1,6 +1,4 @@ # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration -from SimulationConfig.SimEnums import TruthStrategy - def PhaseIIPileUpBase(flags, collisions=200): """Phase-II Upgrade / Run 4 flags for MC with pile-up""" @@ -104,6 +102,7 @@ def PhaseIINoPileUp(flags): def PhaseIISimulation(flags): """Phase-II Upgrade / Run 4 flags for simulation""" + from SimulationConfig.SimEnums import TruthStrategy flags.Sim.PhysicsList = 'FTFP_BERT_ATL' flags.Sim.TruthStrategy = TruthStrategy.MC15aPlus diff --git a/Tools/Campaigns/python/Utils.py b/Tools/Campaigns/python/Utils.py new file mode 100644 index 0000000000000000000000000000000000000000..f8da028647e3d8eb6dfef4c76979cbd640165e61 --- /dev/null +++ b/Tools/Campaigns/python/Utils.py @@ -0,0 +1,46 @@ +# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +from AthenaConfiguration.Enums import FlagEnum +class Campaign(FlagEnum): + Unknown = '' + MC16a = 'mc16a' + MC16d = 'mc16d' + MC16e = 'mc16e' + MC20a = 'mc20a' + MC20d = 'mc20d' + MC20e = 'mc20e' + MC21a = 'mc21a' + +# Campaign run numbers (only latest campaigns) +campaign_runs = { + 284500: Campaign.MC20a, + 300000: Campaign.MC20d, + 310000: Campaign.MC20e, + 410000: Campaign.MC21a, +} + +# Function to get the campaign +def getMCCampaign(files): + # Auto-configure from file + from AthenaConfiguration.AutoConfigFlags import GetFileMD + metadata = GetFileMD(files) + mc_campaign = Campaign(metadata.get('mc_campaign', '')) + project_name = metadata.get('project_name', '') + run_numbers = metadata.get('runNumbers', []) + + if mc_campaign is not Campaign.Unknown: + return mc_campaign + + if run_numbers: + mc_campaign = campaign_runs.get(run_numbers[0], Campaign.Unknown) + + # MC-equivalent projects for data + if 'data22' in project_name: + return Campaign.MC21a + elif 'data18' in project_name: + return Campaign.MC20e + elif 'data17' in project_name: + return Campaign.MC20d + elif 'data16' in project_name or 'data15' in project_name: + return Campaign.MC20a + + return mc_campaign diff --git a/Tools/Campaigns/share/MC16a.py b/Tools/Campaigns/share/MC16a.py index 01e21645530f32cbbbcee21dcc576ada8a60dd01..23ea9265ea00b7a8da58759e1ddc467e3d8ad04f 100644 --- a/Tools/Campaigns/share/MC16a.py +++ b/Tools/Campaigns/share/MC16a.py @@ -1,4 +1,7 @@ # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags +from Campaigns.Utils import Campaign +athenaCommonFlags.MCCampaign.set_Value_and_Lock(Campaign.MC16a.value) from AthenaCommon.BeamFlags import jobproperties as bf bf.Beam.numberOfCollisions.set_Value_and_Lock(20.0) diff --git a/Tools/Campaigns/share/MC16d.py b/Tools/Campaigns/share/MC16d.py index e2faff8472f2dd67c7277fed02a5c8825ccdd9a1..50e7bcc7dfedaef1d1c7da6037b9b3389ccc5d1f 100644 --- a/Tools/Campaigns/share/MC16d.py +++ b/Tools/Campaigns/share/MC16d.py @@ -1,4 +1,7 @@ # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags +from Campaigns.Utils import Campaign +athenaCommonFlags.MCCampaign.set_Value_and_Lock(Campaign.MC16d.value) from AthenaCommon.BeamFlags import jobproperties as bf bf.Beam.numberOfCollisions.set_Value_and_Lock(20.0) diff --git a/Tools/Campaigns/share/MC16e.py b/Tools/Campaigns/share/MC16e.py index e2faff8472f2dd67c7277fed02a5c8825ccdd9a1..b733099e8dde32022b4e2fc8841e8dc18961081a 100644 --- a/Tools/Campaigns/share/MC16e.py +++ b/Tools/Campaigns/share/MC16e.py @@ -1,4 +1,7 @@ # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags +from Campaigns.Utils import Campaign +athenaCommonFlags.MCCampaign.set_Value_and_Lock(Campaign.MC16e.value) from AthenaCommon.BeamFlags import jobproperties as bf bf.Beam.numberOfCollisions.set_Value_and_Lock(20.0) diff --git a/Tools/Campaigns/share/MC20a.py b/Tools/Campaigns/share/MC20a.py index 829ee9589fcf59b0b1b454823ef573e4d969bc5a..687e958e126bf074ed5ed21cd6fe9357161c7af0 100644 --- a/Tools/Campaigns/share/MC20a.py +++ b/Tools/Campaigns/share/MC20a.py @@ -1,4 +1,7 @@ # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags +from Campaigns.Utils import Campaign +athenaCommonFlags.MCCampaign.set_Value_and_Lock(Campaign.MC20a.value) from AthenaCommon.BeamFlags import jobproperties as bf bf.Beam.numberOfCollisions.set_Value_and_Lock(20.0) diff --git a/Tools/Campaigns/share/MC20d.py b/Tools/Campaigns/share/MC20d.py index 9ce673b5a1bc0e6aa0ad165b79ea7670b3eb386d..b114282ac46dfffdf55773e39557aa6ab5f824e0 100644 --- a/Tools/Campaigns/share/MC20d.py +++ b/Tools/Campaigns/share/MC20d.py @@ -1,4 +1,7 @@ # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags +from Campaigns.Utils import Campaign +athenaCommonFlags.MCCampaign.set_Value_and_Lock(Campaign.MC20d.value) from AthenaCommon.BeamFlags import jobproperties as bf bf.Beam.numberOfCollisions.set_Value_and_Lock(20.0) diff --git a/Tools/Campaigns/share/MC20e.py b/Tools/Campaigns/share/MC20e.py index 9ce673b5a1bc0e6aa0ad165b79ea7670b3eb386d..552389304fcd2e5e751dc4f39d7ac763e257e6b2 100644 --- a/Tools/Campaigns/share/MC20e.py +++ b/Tools/Campaigns/share/MC20e.py @@ -1,4 +1,7 @@ # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags +from Campaigns.Utils import Campaign +athenaCommonFlags.MCCampaign.set_Value_and_Lock(Campaign.MC20e.value) from AthenaCommon.BeamFlags import jobproperties as bf bf.Beam.numberOfCollisions.set_Value_and_Lock(20.0) diff --git a/Tools/Campaigns/share/MC21a.py b/Tools/Campaigns/share/MC21a.py index 526c7afd32fcc5d4a909b0fa8da64851b30b6de1..5336ee2d30a6483007624c0a0310b5e6df239157 100644 --- a/Tools/Campaigns/share/MC21a.py +++ b/Tools/Campaigns/share/MC21a.py @@ -1,4 +1,7 @@ # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags +from Campaigns.Utils import Campaign +athenaCommonFlags.MCCampaign.set_Value_and_Lock(Campaign.MC21a.value) from AthenaCommon.BeamFlags import jobproperties as bf bf.Beam.numberOfCollisions.set_Value_and_Lock(60.0) diff --git a/Tools/PROCTools/data/q443_AOD_content.ref b/Tools/PROCTools/data/q443_AOD_content.ref index 494fe7c500bca3c0b842aacd6475a716948fb5b3..5e8d8299aee68a49fcc98762fb8ef32de837764e 100644 --- a/Tools/PROCTools/data/q443_AOD_content.ref +++ b/Tools/PROCTools/data/q443_AOD_content.ref @@ -726,6 +726,7 @@ FileMetaDataAuxDyn.beamType FileMetaDataAuxDyn.conditionsTag FileMetaDataAuxDyn.geometryVersion FileMetaDataAuxDyn.isDataOverlay +FileMetaDataAuxDyn.mcCampaign FileMetaDataAuxDyn.mcProcID FileMetaDataAuxDyn.simFlavour ForwardElectronClusters diff --git a/Tools/PROCTools/data/q445_AOD_content.ref b/Tools/PROCTools/data/q445_AOD_content.ref index 37ff340933be0f2c622d2d7965de2b027bb391c7..14a660aed09a434f2b31027dc0d108b5ec1666cc 100644 --- a/Tools/PROCTools/data/q445_AOD_content.ref +++ b/Tools/PROCTools/data/q445_AOD_content.ref @@ -346,6 +346,7 @@ FileMetaDataAuxDyn.beamType FileMetaDataAuxDyn.conditionsTag FileMetaDataAuxDyn.geometryVersion FileMetaDataAuxDyn.isDataOverlay +FileMetaDataAuxDyn.mcCampaign FileMetaDataAuxDyn.mcProcID FileMetaDataAuxDyn.simFlavour ForwardElectronClusters diff --git a/Tools/PROCTools/data/q446_AOD_content.ref b/Tools/PROCTools/data/q446_AOD_content.ref index 505f70eef0d5221448da44fff294c264167e7a78..24c0133b66a155b578255eec7d1b026c84af3e7b 100644 --- a/Tools/PROCTools/data/q446_AOD_content.ref +++ b/Tools/PROCTools/data/q446_AOD_content.ref @@ -246,6 +246,7 @@ FileMetaDataAuxDyn.beamType FileMetaDataAuxDyn.conditionsTag FileMetaDataAuxDyn.geometryVersion FileMetaDataAuxDyn.isDataOverlay +FileMetaDataAuxDyn.mcCampaign FileMetaDataAuxDyn.mcProcID FileMetaDataAuxDyn.simFlavour ForwardElectronClusters diff --git a/Tools/PyUtils/CMakeLists.txt b/Tools/PyUtils/CMakeLists.txt index b132ef9f967ff85add07b9998e23029eafc12d71..6de3adc1bbbdac773b1b49ba9d9ce823ce4a338e 100644 --- a/Tools/PyUtils/CMakeLists.txt +++ b/Tools/PyUtils/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration # Declare the package name: atlas_subdir( PyUtils ) @@ -11,6 +11,11 @@ if( XAOD_STANDALONE ) python/RootUtils.py python/Helpers.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) + atlas_install_scripts( bin/meta-reader.py bin/meta-diff.py + POST_BUILD_CMD ${ATLAS_FLAKE8} ) + + atlas_add_alias( meta-reader "meta-reader.py" ) + atlas_add_alias( meta-diff "meta-diff.py" ) else() # External dependencies: find_package( decorator ) diff --git a/Tools/PyUtils/python/MetaReader.py b/Tools/PyUtils/python/MetaReader.py index e11dbfd80e478f04ef0d23c3a8cd6ea199a9966e..d6ec129ec6489520cee3b17698920daa0078e64a 100644 --- a/Tools/PyUtils/python/MetaReader.py +++ b/Tools/PyUtils/python/MetaReader.py @@ -381,7 +381,7 @@ def read_metadata(filenames, file_type = None, mode = 'lite', promote = None, me meta_dict = make_peeker(meta_dict) if promote: - meta_dict = promote_keys(meta_dict) + meta_dict = promote_keys(meta_dict, mode) # If AnalysisBase the itemList must be grabbed another way if not isGaudiEnv(): @@ -919,11 +919,15 @@ def make_lite(meta_dict): meta_dict[filename][key].pop(item) if '/TagInfo' in file_content: - keys_to_keep = ['beam_energy', 'beam_type', 'GeoAtlas', 'IOVDbGlobalTag', 'AODFixVersion', 'project_name'] + keys_to_keep = ['beam_energy', 'beam_type', 'GeoAtlas', 'IOVDbGlobalTag', 'AODFixVersion', 'project_name', 'mc_campaign'] for item in list(meta_dict[filename]['/TagInfo']): if item not in keys_to_keep: meta_dict[filename]['/TagInfo'].pop(item) + + # default values: + if 'mc_campaign' not in meta_dict[filename]['/TagInfo']: + meta_dict[filename]['/TagInfo']['mc_campaign'] = '' return meta_dict @@ -955,7 +959,8 @@ def make_peeker(meta_dict): 'project_name', 'triggerStreamOfFile', 'AtlasRelease', - 'specialConfiguration' + 'specialConfiguration', + 'mc_campaign', ] for item in list(meta_dict[filename]['/TagInfo']): if item not in keys_to_keep: @@ -994,7 +999,7 @@ def make_peeker(meta_dict): return meta_dict -def promote_keys(meta_dict): +def promote_keys(meta_dict, mode): for filename, file_content in meta_dict.items(): md = meta_dict[filename] for key in file_content: @@ -1021,22 +1026,23 @@ def promote_keys(meta_dict): break if not isGaudiEnv() and key in md['metadata_items'] and 'FileMetaData' in key: - md.update(md[key]) - if 'beamType' in md[key]: md['beam_type'] = md[key]['beamType'] if 'runNumbers' in md[key]: - md['mc_event_number'] = md[key]['runNumbers'][0] + md['runNumbers'] = md[key]['runNumbers'] if 'mcProcID' in md[key]: md['mc_channel_number'] = int(md[key]['mcProcID']) + if 'mcCampaign' in md[key]: + md['mc_campaign'] = md[key]['mcCampaign'] + if 'lumiBlocks' in md[key]: md['lumiBlockNumbers'] = md[key]['lumiBlocks'] - if 'amiTag' in md[key]: - md['processingTags'] = md[key]['amiTag'] + if mode == 'peeker' and 'amiTag' in md[key]: + md['AMITag'] = md[key]['amiTag'] if 'beamEnergy' in md[key]: md['beam_energy'] = md[key]['beamEnergy'] @@ -1046,6 +1052,9 @@ def promote_keys(meta_dict): # EventType checks md['eventTypes'] = [] + if mode == 'peeker' and 'simFlavour' in md[key]: + md['SimulationFlavour'] = md[key]['simFlavour'] + if 'simFlavour' in md[key] and ('FullG4' in md[key]['simFlavour'] or 'ATLFAST' in md[key]['simFlavour']): md['eventTypes'].append('IS_SIMULATION') else: @@ -1056,7 +1065,14 @@ def promote_keys(meta_dict): else: md['eventTypes'].append('IS_TESTBEAM') - meta_dict[filename].pop(key) + if 'dataType' in md[key]: + md['processingTags'] = [md[key]['dataType']] + + if mode == 'peeker' and 'productionRelease' in md[key]: + md['AtlasRelease'] = md[key]['productionRelease'] + + if mode == 'lite': + meta_dict[filename].pop(key) break if '/TagInfo' in file_content: