def ConfigureDoTruth(): if rec.doTruth.is_locked(): logAutoConfiguration.info( "rec.doTruth=%s is locked. Auto-config will not attempt to change it." % rec.doTruth()) return from PyUtils.MetaReaderPeeker import metadata, convert_itemList if metadata['file_type'] == 'BS' and metadata['eventTypes'][ 0] != 'IS_SIMULATION': rec.doTruth.set_Value_and_Lock(False) logAutoConfiguration.info( "Input is bytestream. Auto-configuring doTruth=%s" % rec.doTruth()) if metadata['file_type'] == 'POOL': itemsList = convert_itemList(layout='#join') itemsHaveTruth = False for item in itemsList: if item.startswith('McEventCollection#') or item.startswith( "xAOD::TruthEventContainer#"): itemsHaveTruth = True rec.doTruth.set_Value_and_Lock(itemsHaveTruth) if itemsHaveTruth: logAutoConfiguration.info( "Input has McEventCollection. Auto-configuring doTruth=%s" % rec.doTruth()) else: logAutoConfiguration.info( "Input has no McEventCollection. Auto-configuring doTruth=%s" % rec.doTruth()) return
def __addRingerInputToList(streamList, containerType, storeTypeStr): from PyUtils.MetaReaderPeeker import convert_itemList, convert_metadata_items if storeTypeStr == 'metadata_itemsDic': itemDict = convert_metadata_items(layout='dict') if storeTypeStr == 'eventdata_itemsDic': itemDict = convert_itemList(layout='dict') try: keys = itemDict[containerType] #keys = [ itemDict[dkey] for dkey in itemDict if containerType in dkey ] if keys: for key in keys: mlog.debug('Appending container %s#%s in input file to output file', \ containerType, \ key) outputName = '%s#%s' % (containerType, key) if not outputName in streamList: streamList.append(outputName) # Code used to retrieve metadata container in early 22.0.X #if type(key) in (list, tuple): # import re # for k in key: # k = re.sub(r'(.+)(_v\d+_)(.+)', r'\1#\3', k) # streamList.append( '%s' % k ) # streamList.append( '%s#%s' % (containerType, key) ) # mlog.warning('Using old key format %s, while expected was cont#key.', key) except KeyError: pass
def IsInInputFile(collectionname, key=None): logAutoConfiguration.info("in IsInInputFile...") try: from PyUtils.MetaReaderPeeker import metadata, convert_itemList if metadata['file_type'] == 'POOL': try: ItemDic = convert_itemList(layout='dict') if collectionname in ItemDic: logAutoConfiguration.info( "found collection with name %s in input file." % collectionname) print(ItemDic[collectionname]) if key is None: logAutoConfiguration.info( "no explicit storegate key given. Returning True") return True if key in ItemDic[collectionname]: logAutoConfiguration.info( "collection with key %s is in input file. Returning True" % key) return True else: logAutoConfiguration.info( "collection with key %s is NOT in input file. Returning False" % key) return False logAutoConfiguration.info("Shouldn't be here !") return False except Exception: logAutoConfiguration.warning( "IsInInputFile: Something's wrong. Wrong file:%s ", metadata['file_name']) import traceback logAutoConfiguration.warning(traceback.format_exc()) except Exception: logAutoConfiguration.warning( "Could not run IsInInputFile. input file maybe not specified at this point" ) # logAutoConfiguration.info( "looks like object of name %s is NOT in input file. Returning False" % key) return False
# Input file dataFile = "/afs/cern.ch/atlas/project/rig/referencefiles/MC/valid1.110401.PowhegPythia_P2012_ttbar_nonallhad.e3099_s2578/RDO.04919495._000958.pool.root.1" from AthenaCommon.AthenaCommonFlags import athenaCommonFlags athenaCommonFlags.FilesInput=[dataFile,dataFile] # AutoConfiguration from RecExConfig.RecFlags import rec rec.AutoConfiguration = ['everything'] import RecExConfig.AutoConfiguration as auto auto.ConfigureFromListOfKeys(rec.AutoConfiguration()) from RecExConfig.ObjKeyStore import objKeyStore, CfgKeyStore from PyUtils.MetaReaderPeeker import convert_itemList objKeyStore.addManyTypesInputFile(convert_itemList(layout = '#join')) #---------------------------------------------------------------------------------# # Detector Description from AtlasGeoModel import SetGeometryVersion from AtlasGeoModel import GeoModelInit from LArGeoAlgsNV.LArGeoAlgsNVConf import LArDetectorToolNV from TileGeoModel.TileGeoModelConf import TileDetectorTool ServiceMgr.GeoModelSvc.DetectorTools += [ LArDetectorToolNV(ApplyAlignments = True, GeometryConfig = "RECO"), TileDetectorTool(GeometryConfig = "RECO") ] from CaloDetMgrDetDescrCnv import CaloDetMgrDDCnv
def configure(self): log = logging.getLogger("HLTTriggergetter.py") from AthenaCommon.AlgSequence import AlgSequence topSequence = AlgSequence() # If no xAOD::EventInfo is found in a POOL file, schedule conversion from old EventInfo from AthenaCommon.GlobalFlags import globalflags if globalflags.InputFormat.is_pool(): from RecExConfig.ObjKeyStore import objKeyStore from PyUtils.MetaReaderPeeker import convert_itemList objKeyStore.addManyTypesInputFile(convert_itemList(layout='#join')) from AthenaCommon.AlgSequence import AthSequencer condSeq = AthSequencer("AthCondSeq") if (not objKeyStore.isInInput("xAOD::EventInfo")) and (not hasattr( condSeq, "xAODMaker::EventInfoCnvAlg")): from xAODEventInfoCnv.xAODEventInfoCnvAlgDefault import xAODEventInfoCnvAlgDefault xAODEventInfoCnvAlgDefault(sequence=condSeq) if jobproperties.Global.InputFormat() == 'bytestream': # Decode ROIB::RoIBResult from ByteStream from TrigT1ResultByteStream.TrigT1ResultByteStreamConfig import L1ByteStreamDecodersRecExSetup L1ByteStreamDecodersRecExSetup() log.info("Loading RegionSelector") from AthenaCommon.AppMgr import ServiceMgr from RegionSelector.RegSelSvcDefault import RegSelSvcDefault ServiceMgr += RegSelSvcDefault() # Configure the Data Preparation for Calo if TriggerFlags.doCalo(): try: from TrigT2CaloCommon.TrigT2CaloCommonConfig import TrigDataAccess ServiceMgr.ToolSvc += TrigDataAccess() except ImportError: include('TrigT2CaloCommon/TrigDataAccessConfigured.py') if TriggerFlags.doFTK(): # FTK algorithm inclusions # TrigFTK_DataProviderSvc moved to TrigFTK_RecExample pass if TriggerFlags.doHLT(): log.info("configuring HLT Steering") from TrigSteering.TrigSteeringConfig import TrigSteer_HLT, ReruningTrigSteer_HLT if TriggerFlags.doFEX(): # schedule the conversion of the L1Calo ROIB data to topo simulation input # this ROIB converter should only be scheduled if # - we run on data # - L1Calo simulation has not been scheduled # - and ROIB converter has not been scheduled yet before if globalflags.DataSource()=='data' \ and not hasattr( topSequence, 'CPCMX' ) \ and not hasattr( topSequence, 'RoiB2TopoInputDataCnv' ): log.info("Setting up RoiB2TopoInputDataCnv") from L1TopoSimulation.L1TopoSimulationConfig import RoiB2TopoInputDataCnv roib2Topo = RoiB2TopoInputDataCnv() topSequence += roib2Topo log.info( "configuring HLT merged system, for normal running (FEX + Hypo)" ) TrigSteer_HLT = TrigSteer_HLT( 'TrigSteer_HLT', hltFile=TriggerFlags.inputHLTconfigFile(), lvl1File=TriggerFlags.inputLVL1configFile()) TrigSteer_HLT.doHypo = TriggerFlags.doHypo() if not TriggerFlags.doFEX() and TriggerFlags.doHypo(): log.info("configuring merged HLT for re-running (Hypo only)") TrigSteer_HLT = ReruningTrigSteer_HLT( 'TrigSteer_HLT', hltFile=TriggerFlags.inputHLTconfigFile(), lvl1File=TriggerFlags.inputLVL1configFile()) # TrigSteer_HLT.doL1TopoSimulation = TriggerFlags.doL1Topo() # this later needs to be extented to also run when we take data with L1Topo TrigSteer_HLT.doL1TopoSimulation = True # always needs to run if the HLT is simulated if hasattr(TrigSteer_HLT.LvlTopoConverter, 'MuonInputProvider'): try: # this is temporary until TrigT1Muctpi-00-06-29 is in the release from TrigT1Muctpi.TrigT1MuctpiConfig import L1MuctpiTool from AthenaCommon.AppMgr import ToolSvc ToolSvc += L1MuctpiTool() TrigSteer_HLT.LvlTopoConverter.MuonInputProvider.MuctpiSimTool = L1MuctpiTool( ) except ImportError: pass from AthenaCommon.GlobalFlags import globalflags if globalflags.DataSource() != 'data': log.info( "Muon eta/phi encoding with reduced granularity for MC (L1Topo emulation for HLT seeding)" ) TrigSteer_HLT.LvlTopoConverter.MuonInputProvider.MuonEncoding = 1 # reduced granularity muon input else: log.info( "Muon eta/phi encoding with full granularity for data (L1Topo emulation for HLT seeding) - should be faced out" ) TrigSteer_HLT.LvlTopoConverter.MuonInputProvider.MuonEncoding = 0 # full granularity muon input - should be faced out from TrigEDMConfig.TriggerEDM import getHLTPreregistrationList, getEDMLibraries TrigSteer_HLT.Navigation.ClassesToPreregister = getHLTPreregistrationList( ) TrigSteer_HLT.Navigation.Dlls = getEDMLibraries() monitoringTools(TrigSteer_HLT) topSequence += TrigSteer_HLT if TriggerFlags.writeBS(): # declare objects to go to BS (from the lists above) ## if TriggerFlags.doLVL2(): ## from TrigEDMConfig.TriggerEDM import getL2BSList ## TrigSteer_L2.Navigation.ClassesToPayload = getL2BSList() ## TrigSteer_L2.Navigation.ClassesToPreregister = [] ## ## if TriggerFlags.doEF(): ## from TrigEDMConfig.TriggerEDM import getEFBSList ## TrigSteer_EF.Navigation.ClassesToPayload = getEFBSList() ## TrigSteer_EF.Navigation.ClassesToPreregister = [] ## try: ## from TrigEDMConfig.TriggerEDM import getEFDSList ## TrigSteer_EF.Navigation.ClassesToPayload_DSonly = getEFDSList() ## except ImportError: ## log.warning("DataScouting not available in this release") if TriggerFlags.doHLT(): from TrigEDMConfig.TriggerEDM import getHLTBSList TrigSteer_HLT.Navigation.ClassesToPayload = getHLTBSList() TrigSteer_HLT.Navigation.ClassesToPreregister = [] try: from TrigEDMConfig.TriggerEDM import getHLTDSList TrigSteer_HLT.Navigation.ClassesToPayload_DSonly = getHLTDSList( ) except ImportError: log.warning("DataScouting not available in this release") #configure tools for serialization from TrigSerializeTP.TrigSerializeTPConf import TrigSerTPTool TrigSerToolTP = TrigSerTPTool('TrigSerTPTool') from TrigEDMConfig.TriggerEDM import getTPList TrigSerToolTP.TPMap = getTPList(TriggerFlags.doHLT()) from AthenaCommon.AppMgr import ToolSvc ToolSvc += TrigSerToolTP from TrigSerializeCnvSvc.TrigSerializeCnvSvcConf import TrigSerializeConvHelper TrigSerializeConvHelper = TrigSerializeConvHelper(doTP=True) ToolSvc += TrigSerializeConvHelper #do not activate T/P of EF classes at L2 ## if TriggerFlags.doLVL2(): ## from TrigEDMConfig.TriggerEDM import getL2BSTypeList ## TrigSerToolTP.ActiveClasses = getL2BSTypeList() ## if TriggerFlags.doEF(): ## from TrigEDMConfig.TriggerEDM import getL2BSTypeList, getEFBSTypeList ## TrigSerToolTP.ActiveClasses = getL2BSTypeList() + getEFBSTypeList() if TriggerFlags.doHLT(): from TrigEDMConfig.TriggerEDM import getHLTBSTypeList TrigSerToolTP.ActiveClasses = getHLTBSTypeList() from TriggerJobOpts.HLTTriggerResultGetter import HLTTriggerResultGetter result = HLTTriggerResultGetter() # noqa: F841 return True
def keyInInputFile(sgKey): """check, if the given StoreGate key is in the current input file """ from PyUtils.MetaReaderPeeker import convert_itemList return sgKey in convert_itemList(layout='dict')
def EDMDecodingVersion(): log = logging.getLogger("EDMDecodingVersion") # BYTESTREAM: decide Run3 or later based on ROD version, decide Run1/Run2 based on run number if globalflags.InputFormat.is_bytestream(): # Check HLT ROD version in first event of first input file from AthenaCommon.AthenaCommonFlags import athenaCommonFlags inputFileName = athenaCommonFlags.FilesInput()[0] if not inputFileName and athenaCommonFlags.isOnline(): log.info( "Online reconstruction mode, no input file available. Leaving default TriggerFlags.EDMDecodingVersion=%d", TriggerFlags.EDMDecodingVersion()) return import eformat from libpyeformat_helper import SubDetector bs = eformat.istream(inputFileName) rodVersionM = -1 rodVersionL = -1 # Find the first HLT ROBFragment in the first event for robf in bs[0]: if robf.rob_source_id().subdetector_id() == SubDetector.TDAQ_HLT: rodVersionM = robf.rod_minor_version() >> 8 rodVersionL = robf.rod_minor_version() & 0xFF log.debug("HLT ROD minor version from input file is %d.%d", rodVersionM, rodVersionL) break if rodVersionM < 0 or rodVersionL < 0: log.warning( "Cannot determine HLT ROD version from input file, falling back to runNumber-based decision" ) elif rodVersionM >= 1: TriggerFlags.EDMDecodingVersion = 3 log.info( "Decoding version set to 3, because running on BS file with HLT ROD version %d.%d", rodVersionM, rodVersionL) return # Use run number to determine decoding version from RecExConfig.AutoConfiguration import GetRunNumber runNumber = GetRunNumber() boundary_run12 = 230000 boundary_run23 = 368000 if runNumber <= 0: log.error( "Cannot determine decoding version because run number %d is invalid. Leaving the default version %d", runNumber, TriggerFlags.EDMDecodingVersion()) elif runNumber < boundary_run12: # Run-1 data TriggerFlags.EDMDecodingVersion = 1 TriggerFlags.doMergedHLTResult = False log.info( "Decoding version set to 1 based on BS file run number (runNumber < %d)", boundary_run12) elif runNumber < boundary_run23: # Run-2 data TriggerFlags.EDMDecodingVersion = 2 log.info( "Decoding version set to 2 based on BS file run number (%d < runNumber < %d)", boundary_run12, boundary_run23) else: # Run-3 data TriggerFlags.EDMDecodingVersion = 3 log.info( "Decoding version set to 3 based on BS file run number (runNumber > %d)", boundary_run23) else: # POOL files: decide based on HLT output type present in file from RecExConfig.ObjKeyStore import cfgKeyStore from PyUtils.MetaReaderPeeker import convert_itemList cfgKeyStore.addManyTypesInputFile(convert_itemList(layout='#join')) TriggerFlags.doMergedHLTResult = True if cfgKeyStore.isInInputFile("HLT::HLTResult", "HLTResult_EF"): TriggerFlags.EDMDecodingVersion = 1 TriggerFlags.doMergedHLTResult = False log.info( "Decoding version set to 1, because HLTResult_EF found in POOL file" ) elif cfgKeyStore.isInInputFile("xAOD::TrigNavigation", "TrigNavigation"): TriggerFlags.EDMDecodingVersion = 2 log.info( "Decoding version set to 2, because TrigNavigation found in POOL file" ) elif cfgKeyStore.isInInputFile("xAOD::TrigCompositeContainer", "HLTNav_Summary"): TriggerFlags.EDMDecodingVersion = 3 log.info( "Decoding version set to 3, because HLTNav_Summary found in POOL file" ) elif rec.readRDO(): # If running Trigger on RDO input (without previous trigger result), choose Run-2 or Run-3 based on doMT if TriggerFlags.doMT(): TriggerFlags.EDMDecodingVersion = 3 log.info( "Decoding version set to 3, because running Trigger with doMT=True" ) else: TriggerFlags.EDMDecodingVersion = 2 log.info( "Decoding version set to 2, because running Trigger with doMT=False" ) else: log.warning( "Cannot recognise HLT EDM format, leaving default TriggerFlags.EDMDecodingVersion=%d", TriggerFlags.EDMDecodingVersion())
try: topSequence.InDetBeamSpotFinder.UseLBFromViewed = config[ 'UseLBFromViewed'] topSequence.InDetBeamSpotFinder.UseLBFromAccepted = config[ 'UseLBFromAccepted'] except: print 'ERROR: You are using an older version of InDetBeamSpotFinder - please update to InDetBeamSpotFinder-01-00-29 or later' print topSequence.InDetBeamSpotFinder # Get the list of additional vertex collections in the input file pvcollections_keys = [] from PyUtils.MetaReaderPeeker import convert_itemList input_file_items = convert_itemList() for cxx_type, sg_key in input_file_items: if cxx_type != 'VxContainer': continue #if sg_key == 'VxPrimaryCandidate': # continue # ignore the default collection pvcollections_keys.append(sg_key) print "JW Found VxContainers:" print pvcollections_keys # create the beamspot finder algorithms for each collection if not 'doMultiVertex' in dir(): doMultiVertex = True if doMultiVertex: for i in pvcollections_keys:
def addTruthJetsIfNotExising(truth_jets_name): ''' Add algorithm to create the truth jets collection unless the collection exists already, or a truth jet finder is already running ''' from RecExConfig.AutoConfiguration import IsInInputFile # the jet collection name does not exist in the input file # add a jet finder algorithm in front of the monitoring if the algorithm # does not yet exist. if not IsInInputFile('xAOD::JetContainer', truth_jets_name): try: from AthenaCommon.Logging import logging log = logging.getLogger('InDetPhysValMonitoring/addTruthJets.py') from PyUtils.MetaReaderPeeker import convert_itemList, metadata eventdata_itemsDic = convert_itemList(layout='dict') log.info( 'DEBUG addTruthJetsIfNotExising {} not in {} [file_type={}]'. format(truth_jets_name, eventdata_itemsDic, metadata['file_type'])) if truth_jets_name in eventdata_itemsDic: return except: pass # Access the algorithm sequence: from AthenaCommon.AlgSequence import AlgSequence, AthSequencer topSequence = AlgSequence() # extract the jet finder type and main parameter import re extract_alg = re.search('^([^0-9]+)([0-9]+)TruthJets', truth_jets_name) if extract_alg != None: alg_type = extract_alg.group(1) alg_param_str = extract_alg.group(2) else: alg_type = 'AntiKt' alg_param_str = 4 jet_finder_alg_name = "jetalg" + alg_type + alg_param_str + 'TruthJets' # add the jet finder unless it exists already in the alg sequence from InDetPhysValDecoration import findAlg, findMonMan alg_pos = findAlg([jet_finder_alg_name]) if alg_pos == None: from JetRec.JetRecStandard import jtm mon_man_index = findMonMan() # configure truth jet finding ? from JetRec.JetRecFlags import jetFlags jetFlags.useTruth = True jetFlags.useTracks = False jetFlags.truthFlavorTags = [ "BHadronsInitial", "BHadronsFinal", "BQuarksFinal", "CHadronsInitial", "CHadronsFinal", "CQuarksFinal", "TausFinal", "Partons", ] # tool to create truth jet finding inputs truth_part_copy_name = 'truthpartcopy' dir(jtm) create_truth_jet_input = None if not hasattr(jtm, truth_part_copy_name): from MCTruthClassifier.MCTruthClassifierConfig import firstSimCreatedBarcode from MCTruthClassifier.MCTruthClassifierConf import MCTruthClassifier truth_classifier_name = 'JetMCTruthClassifier' if not hasattr(jtm, truth_classifier_name): from AthenaCommon.AppMgr import ToolSvc if not hasattr(ToolSvc, truth_classifier_name): truthClassifier = MCTruthClassifier( name=truth_classifier_name, barcodeG4Shift=firstSimCreatedBarcode(), ParticleCaloExtensionTool="") else: truthClassifier = getattr(ToolSvc, truth_classifier_name) truthClassifier.barcodeG4Shift = firstSimCreatedBarcode( ) jtm += truthClassifier else: truthClassifier = getattr(jtm, truth_classifier_name) truthClassifier.barcodeG4Shift = firstSimCreatedBarcode() from ParticleJetTools.ParticleJetToolsConf import CopyTruthJetParticles create_truth_jet_input = CopyTruthJetParticles( truth_part_copy_name, OutputName="JetInputTruthParticles", MCTruthClassifier=truthClassifier) jtm += create_truth_jet_input else: create_truth_jet_input = getattr(jtm, truth_part_copy_name) jet_finder_tool = jtm.addJetFinder(truth_jets_name, alg_type, float(alg_param_str) / 10., "truth", ptmin=5000) jet_tools = [] from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles jet_tools += scheduleCopyTruthParticles() jet_tools += [create_truth_jet_input] jet_tools += jtm.jetrecs # add the jet finder in front of the monitoring from JetRec.JetRecConf import JetAlgorithm from JetRec.JetRecConf import JetToolRunner jtm += JetToolRunner( "jetrun", Tools=jet_tools, EventShapeTools=[], # OutputLevel = 1, Timer=jetFlags.timeJetToolRunner()) # jet_finder_alg = JetAlgorithm(jet_finder_alg_name, jet_tools) jet_finder_alg = JetAlgorithm(jet_finder_alg_name) # jet_finder_alg.OutputLevel = 1 jet_finder_alg.Tools = [jtm.jetrun] if mon_man_index != None: topSequence.insert(mon_man_index, jet_finder_alg) else: topSequence += jet_finder_alg
def checkContainerInInputFile(container_type, container_name): if container_type in convert_itemList(layout='dict'): if container_name in convert_itemList(layout='dict')[container_type]: return True return False
from OutputStreamAthenaPool.MultipleStreamManager import MSMgr from PyUtils.MetaReaderPeeker import convert_itemList inputObjects = convert_itemList(layout=None) def __addInput(stream, skip=[]): for element in inputObjects: type_key = "%s#%s" % element if type_key not in skip: stream.AddItem(type_key) elStream = MSMgr.NewPoolStream('elXAODStream', 'elXAOD.pool.root') __addInput(elStream) phStream = MSMgr.NewPoolRootStream('phXAODStream', 'phXAOD.pool.root') tauStream = MSMgr.NewPoolRootStream('tauXAODStream', 'tauXAOD.pool.root') from TrigNavTools.TrigNavToolsConfig import navigationThinningSvc from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__DerivationKernel dk = DerivationFramework__DerivationKernel() tokeep = { 'electron': [ 'HLT_TrigElectronContainer_L2ElectronFex', 'HLT_TrigElectronContainer_L2IDCaloFex', 'HLT_xAOD__TrigElectronContainer_L2ElectronFex',