From 231019a8e53de5d33a115ee5aa661a539f9094a1 Mon Sep 17 00:00:00 2001 From: Goetz Gaycken <goetz.gaycken@cern.ch> Date: Fri, 13 Dec 2019 18:26:27 +0100 Subject: [PATCH] Allow to monitor additional track collections (backport from master). Generalised InDetPhysValMonitoring configuration to allow monitoring additional track collections. --- .../InDetRecExample/share/InDetxAODCreator.py | 24 ++ .../InDetRecExample/share/WriteInDetAOD.py | 6 + .../InDetRecExample/share/WriteInDetESD.py | 7 + .../python/ConfigUtils.py | 61 +---- .../python/HistogramDefinitionSvc.py | 32 +-- .../python/InDetPhysValDecoration.py | 210 ++++++--------- .../python/InDetPhysValJobProperties.py | 13 +- .../python/InDetPhysValMonitoringTool.py | 241 ++++++++---------- .../python/TrackSelectionTool.py | 51 +--- .../share/PhysValInDet_jobOptions.py | 43 ++-- 10 files changed, 276 insertions(+), 412 deletions(-) diff --git a/InnerDetector/InDetExample/InDetRecExample/share/InDetxAODCreator.py b/InnerDetector/InDetExample/InDetRecExample/share/InDetxAODCreator.py index abfab11da8126..cf535a2f8bd32 100644 --- a/InnerDetector/InDetExample/InDetRecExample/share/InDetxAODCreator.py +++ b/InnerDetector/InDetExample/InDetRecExample/share/InDetxAODCreator.py @@ -50,6 +50,22 @@ ToolSvc += InDetxAODParticleCreatorTool if InDetFlags.doPrintConfigurables(): print InDetxAODParticleCreatorTool +def createTrackParticlesFromTracks(track_collection, track_particle_collection) : + creator_alg = xAODMaker__TrackParticleCnvAlg(track_particle_collection+"Creator", + xAODContainerName = track_particle_collection, + xAODTrackParticlesFromTracksContainerName = track_particle_collection, + TrackContainerName = track_collection, + TrackParticleCreator = InDetxAODParticleCreatorTool, + AODContainerName = "", + AODTruthContainerName = "", + ConvertTrackParticles = doConversion, + ConvertTracks = doCreation, + AddTruthLink = False, + TrackTruthContainerName = "", + PrintIDSummaryInfo = True) + return creator_alg + + if (doCreation or doConversion):# or InDetFlags.useExistingTracksAsInput()) : <---- [XXX JDC Should we included this? # problems appear when nothing should # be done but @@ -74,6 +90,13 @@ if (doCreation or doConversion):# or InDetFlags.useExistingTracksAsInput()) : <- xAODTrackParticleCnvAlg.TrackTruthContainerName = InputTrackCollectionTruth xAODTrackParticleCnvAlg.PrintIDSummaryInfo = True topSequence += xAODTrackParticleCnvAlg + + from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags + from InDetPhysValMonitoring.ConfigUtils import extractCollectionPrefix + for col in InDetPhysValFlags.validateExtraTrackCollections() : + prefix=extractCollectionPrefix(col) + topSequence += createTrackParticlesFromTracks(prefix+"Tracks",prefix+"TrackParticles") + if InDetFlags.doDBMstandalone() or InDetFlags.doDBM(): xAODDBMTrackParticleCnvAlg = xAODMaker__TrackParticleCnvAlg(InDetKeys.xAODDBMTrackParticleContainer()) xAODDBMTrackParticleCnvAlg.xAODContainerName = InDetKeys.xAODDBMTrackParticleContainer() @@ -107,6 +130,7 @@ if not InDetFlags.doVertexFinding(): xAODVertexCnvAlgDBM.TPContainerName = InDetKeys.xAODDBMTrackParticleContainer() topSequence += xAODVertexCnvAlgDBM + #For forward tracks, no separate collection for ITK, since they are already merged if (InDetFlags.doForwardTracks() and InDetFlags.doParticleCreation() and not InDetFlags.doSLHC()) or doConversion: xAODForwardTrackParticleCnvAlg = xAODMaker__TrackParticleCnvAlg(InDetKeys.xAODForwardTrackParticleContainer()) diff --git a/InnerDetector/InDetExample/InDetRecExample/share/WriteInDetAOD.py b/InnerDetector/InDetExample/InDetRecExample/share/WriteInDetAOD.py index 7fbe14dd1196e..232b631b08e00 100755 --- a/InnerDetector/InDetExample/InDetRecExample/share/WriteInDetAOD.py +++ b/InnerDetector/InDetExample/InDetRecExample/share/WriteInDetAOD.py @@ -17,6 +17,12 @@ if InDetFlags.doxAOD(): excludedAuxData = "-caloExtension.-cellAssociation.-clusterAssociation" InDetAODList+=['xAOD::TrackParticleContainer#'+InDetKeys.xAODTrackParticleContainer()] InDetAODList+=['xAOD::TrackParticleAuxContainer#'+InDetKeys.xAODTrackParticleContainer()+'Aux.' + excludedAuxData] + from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags + from InDetPhysValMonitoring.ConfigUtils import extractCollectionPrefix + for col in InDetPhysValFlags.validateExtraTrackCollections() : + prefix=extractCollectionPrefix(col) + InDetAODList+=['xAOD::TrackParticleContainer#'+prefix+'TrackParticles'] + InDetAODList+=['xAOD::TrackParticleAuxContainer#'+prefix+'TrackParticlesAux.' + excludedAuxData] if not InDetFlags.doSLHC(): InDetAODList+=['xAOD::TrackParticleContainer#'+InDetKeys.xAODForwardTrackParticleContainer()] InDetAODList+=['xAOD::TrackParticleAuxContainer#'+InDetKeys.xAODForwardTrackParticleContainer()+'Aux.' + excludedAuxData] diff --git a/InnerDetector/InDetExample/InDetRecExample/share/WriteInDetESD.py b/InnerDetector/InDetExample/InDetRecExample/share/WriteInDetESD.py index a509109c2a944..306270062916a 100755 --- a/InnerDetector/InDetExample/InDetRecExample/share/WriteInDetESD.py +++ b/InnerDetector/InDetExample/InDetRecExample/share/WriteInDetESD.py @@ -159,6 +159,13 @@ if InDetFlags.doxAOD(): InDetESDList+=['xAOD::TrackParticleContainer#'+InDetKeys.xAODTrackParticleContainer()] InDetESDList+=['xAOD::TrackParticleAuxContainer#'+InDetKeys.xAODTrackParticleContainer()+'Aux.' + excludedAuxData] + from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags + from InDetPhysValMonitoring.ConfigUtils import extractCollectionPrefix + for col in InDetPhysValFlags.validateExtraTrackCollections() : + prefix=extractCollectionPrefix(col) + InDetESDList+=['xAOD::TrackParticleContainer#'+prefix+'TrackParticles'] + InDetESDList+=['xAOD::TrackParticleAuxContainer#'+prefix+'TrackParticlesAux.' + excludedAuxData] + if InDetFlags.doStoreTrackSeeds(): InDetESDList+=['xAOD::TrackParticleContainer#'+InDetKeys.SiSPSeedSegments()+"TrackParticle"] InDetESDList+=['xAOD::TrackParticleAuxContainer#'+InDetKeys.SiSPSeedSegments()+"TrackParticle"+'Aux.' + excludedAuxData] diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/ConfigUtils.py b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/ConfigUtils.py index 21c7653dfb988..e6d849c024422 100644 --- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/ConfigUtils.py +++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/ConfigUtils.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration def dumpConfigurables(obj) : print '==== %s ====' % obj.name() @@ -12,61 +12,12 @@ def dumpConfigurables(obj) : except : print ' %s not an attribute' % (cfg) -def injectNameArgument(inFunction): - configurable_base_classes = ['ConfigurableAlgTool','ConfigurableAlgorithm'] - ''' - Auxiliary method to inject a name argument in the keyword argument dictionary - ''' - - def setConfigurables(_cls) : - class_stack = [_cls] - - the_base_class = None - while len(class_stack) > 0 : - the_class = class_stack.pop() - for base in the_class.__bases__ : - if base.__name__ in configurable_base_classes : - _cls.configurables = the_class.configurables - break - class_stack.append(base) - return - - def outFunction(*args,**kwargs): - _cls = args[0] - - # set the name argument to be equal to the class name - import copy - kw_cp=copy.copy(kwargs) - kw_cp['name']=_cls.__name__ - - if len(_cls.configurables)==0 : - setConfigurables(_cls) - - return inFunction(*args,**kw_cp) - - return outFunction - - -def checkKWArgs(inFunction): - ''' - Auxiliary method to check that only a name kw arg is given. - ''' - - def outFunction(*args,**kwargs): - if len(kwargs)>1 or kwargs.keys()[0] != 'name' : - raise(' No keyword arguments shall be given') - - return inFunction(*args,**kwargs) - - return outFunction - -def _args( kwargs, **extra_kwargs) : - import copy - _kwargs = copy.copy(kwargs) - for kw in extra_kwargs : - _kwargs[kw] = extra_kwargs[kw] - return _kwargs; +def extractCollectionPrefix(track_collection_name) : + return track_collection_name[:-6] if track_collection_name[-6:] == 'Tracks' else track_collection_name +def setDefaults( kwargs, **extra_kwargs) : + extra_kwargs.update(kwargs) + return extra_kwargs def toolFactory( tool_class ): from AthenaCommon.AppMgr import ToolSvc diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/HistogramDefinitionSvc.py b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/HistogramDefinitionSvc.py index b2375aa9cd49e..641acf64e6aa5 100644 --- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/HistogramDefinitionSvc.py +++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/HistogramDefinitionSvc.py @@ -1,31 +1,15 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -from ConfigUtils import injectNameArgument,checkKWArgs,_args +from ConfigUtils import setDefaults #,dumpConfigurables import InDetPhysValMonitoring.InDetPhysValMonitoringConf -class HistogramDefinitionSvc(object) : +def getHistogramDefinitionSvc(**kwargs) : ''' - Namespace for Histogram definition services + Default HistogramDefinitionSvc ''' - def __init__(self) : - raise('must not be instantiated. Only child classes should be instantiated.') - - class HistogramDefinitionSvc(InDetPhysValMonitoring.InDetPhysValMonitoringConf.HistogramDefinitionSvc) : - ''' - Default HistogramDefinitionSvc - ''' - @injectNameArgument - def __new__(cls, *args, **kwargs) : - return InDetPhysValMonitoring.InDetPhysValMonitoringConf.HistogramDefinitionSvc.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(HistogramDefinitionSvc.HistogramDefinitionSvc,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # special parameters of the default HistogramDefinitionSvc - self.DefinitionSource="InDetPVMPlotDefRun2.xml" - self.DefinitionFormat="text/xml" + kwargs = setDefaults(kwargs, + DefinitionSource="InDetPVMPlotDefRun2.xml", + DefinitionFormat="text/xml") + return InDetPhysValMonitoring.InDetPhysValMonitoringConf.HistogramDefinitionSvc(**kwargs) diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValDecoration.py b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValDecoration.py index 3be901f49538c..51ca01d54e68b 100644 --- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValDecoration.py +++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValDecoration.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # block('InDetPhysValMonitoring/InDetPhysValDecoration.py') import ConfigUtils @@ -96,106 +96,43 @@ def setMetaData() : # print 'DEBUG add meta data %s.' % svcMgr.TagInfoMgr.ExtraTagValuePairs -from ConfigUtils import _args -from ConfigUtils import injectNameArgument +from ConfigUtils import setDefaults from ConfigUtils import dumpConfigurables -from ConfigUtils import checkKWArgs from ConfigUtils import toolFactory from InDetTrackHoleSearch.InDetTrackHoleSearchConf import InDet__InDetTrackHoleSearchTool -class InDetHoleSearchTool(object) : - ''' - Namespace for inner detector hole search tools - ''' - def __init__(self) : - raise('must not be instantiated. Only child classes should be instantiated.') - - class PhysValMonInDetHoleSearchTool(InDet__InDetTrackHoleSearchTool) : - ''' - default inner detector hole search tool - ''' - @injectNameArgument - def __new__(cls, *args, **kwargs) : - # if cls.__name__ in cls.configurables : - # print 'WARNING configurable %s exists already ' % cls.__name__ - return InDet__InDetTrackHoleSearchTool.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - from AthenaCommon.AppMgr import ToolSvc, ServiceMgr - # If InDetSCT_ConditionsSummarySvc instance configured by InDetRecConditionsAccess.py is available, use it. - # Otherwise, the default SCT_ConditionsSummarySvc instance is used. - # @TODO find a better to solution to get the correct service for the current job. - SctSummarySvc = "InDetSCT_ConditionsSummarySvc" - if not hasattr(ServiceMgr, SctSummarySvc): - SctSummarySvc = "SCT_ConditionsSummarySvc" - from InDetRecExample.InDetJobProperties import InDetFlags - super(InDetHoleSearchTool.PhysValMonInDetHoleSearchTool,self).__init__(**_args( kwargs, - name = self.__class__.__name__, - Extrapolator = ToolSvc.InDetExtrapolator, - SctSummarySvc = SctSummarySvc, - usePixel = True, - useSCT = True, - checkBadSCTChip = InDetFlags.checkDeadElementsOnTrack(), - # OutputLevel = 1, - CountDeadModulesAfterLastHit = True) ) - - -import InDetPhysValMonitoring.InDetPhysValMonitoringConf -class InDetPhysHitDecoratorTool(object) : - ''' - Namespace for hit decoration tool - ''' - def __init__(self) : - raise('must not be instantiated. Only child classes should be instantiated.') - - class InDetPhysHitDecoratorTool(InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysHitDecoratorTool) : - @injectNameArgument - def __new__(cls, *args, **kwargs) : - return InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysHitDecoratorTool.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetPhysHitDecoratorTool.InDetPhysHitDecoratorTool,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # custom configuration here: - self.InDetTrackHoleSearchTool = toolFactory(InDetHoleSearchTool.PhysValMonInDetHoleSearchTool) - - -# Configuration of InDetPhysValDecoratorAlg algorithms -# -import InDetPhysValMonitoring.InDetPhysValMonitoringConf -class InDetPhysValDecoratorAlg(object) : - ''' - Namespace for track aprticle decoration algorithms - ''' - def __init__(self) : - raise('must not be instantiated. Only child classes should be instantiated.') - - class InDetPhysValDecoratorAlg(InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysValDecoratorAlg) : - ''' - Default track particle decoration algorithm. - This algorithm will decorate the InDetTrackParticles. - ''' - @injectNameArgument - def __new__(cls, *args, **kwargs) : - return InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysValDecoratorAlg.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlg,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # custom configurations below: - self.InDetPhysHitDecoratorTool = toolFactory(InDetPhysHitDecoratorTool.InDetPhysHitDecoratorTool) - # self.InDetPhysHitDecoratorTool.OutputLevel=1 - from InDetPhysValMonitoring.InDetPhysValJobProperties import isMC - if not isMC() : - # disable truth monitoring for data - self.TruthParticleContainerName = '' +def getPhysValMonInDetHoleSearchTool(**kwargs) : + ''' + default inner detector hole search tool + ''' + from AthenaCommon.AppMgr import ToolSvc, ServiceMgr + # If InDetSCT_ConditionsSummarySvc instance configured by InDetRecConditionsAccess.py is available, use it. + # Otherwise, the default SCT_ConditionsSummarySvc instance is used. + # @TODO find a better to solution to get the correct service for the current job. + SctSummarySvc = "InDetSCT_ConditionsSummarySvc" + if not hasattr(ServiceMgr, SctSummarySvc): + SctSummarySvc = "SCT_ConditionsSummarySvc" + from InDetRecExample.InDetJobProperties import InDetFlags + kwargs=setDefaults( kwargs, + name = 'PhysValMonInDetHoleSearchTool', + Extrapolator = ToolSvc.InDetExtrapolator, + SctSummarySvc = SctSummarySvc, + usePixel = True, + useSCT = True, + checkBadSCTChip = InDetFlags.checkDeadElementsOnTrack(), + # OutputLevel = 1, + CountDeadModulesAfterLastHit = True) + + return InDet__InDetTrackHoleSearchTool(**kwargs) + + +def getInDetPhysHitDecoratorTool(**kwargs) : + kwargs=setDefaults(kwargs,name='InDetPhysHitDecoratorTool') + if 'InDetTrackHoleSearchTool' not in kwargs : + kwargs=setDefaults(kwargs,InDetTrackHoleSearchTool = toolFactory(getPhysValMonInDetHoleSearchTool)) + + import InDetPhysValMonitoring.InDetPhysValMonitoringConf + return InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysHitDecoratorTool(**kwargs) class InDetPhysValKeys : @@ -212,32 +149,43 @@ class InDetPhysValKeys : # @todo should be used also in InDetPhysValMonitoring.py GSFTrackParticles = 'GSFTrackParticles' -class InDetPhysValDecoratorAlg(InDetPhysValDecoratorAlg) : - - class InDetPhysValDecoratorAlgGSF(InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlg) : - ''' - Algorithm to decorate GSF track particles. - ''' - def __init__(self, **kwargs) : - super(InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlgGSF,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - # custom configuration below: - self.TrackParticleContainerName=InDetPhysValKeys.GSFTrackParticles - - - class InDetPhysValDecoratorAlgDBM(InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlg) : - ''' - Algorithm to decorate DBM Track particles. - ''' - def __init__(self, **kwargs) : - super(InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlgDBM,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - # custom configuration below: - from InDetRecExample.InDetKeys import InDetKeys - self.TrackParticleContainerName=InDetKeys.DBMTrackParticles() +def getInDetPhysValDecoratorAlg(**kwargs) : + ''' + Default track particle decoration algorithm. + This algorithm will decorate the InDetTrackParticles. + ''' + kwargs=setDefaults(kwargs, + name = 'InDetPhysValDecoratorAlg') + if 'InDetPhysHitDecoratorTool' not in kwargs : + kwargs=setDefaults(kwargs, + InDetPhysHitDecoratorTool = toolFactory(getInDetPhysHitDecoratorTool)) + + # self.InDetPhysHitDecoratorTool.OutputLevel=1 + from InDetPhysValMonitoring.InDetPhysValJobProperties import isMC + if not isMC() : + # disable truth monitoring for data + kwargs=setDefaults(kwargs, TruthParticleContainerName = '') + + import InDetPhysValMonitoring.InDetPhysValMonitoringConf + return InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysValDecoratorAlg(**kwargs) + +def getInDetPhysValDecoratorAlgGSF(**kwargs) : + ''' + Algorithm to decorate GSF track particles. + ''' + return getInDetPhysValDecoratorAlg( **setDefaults(kwargs, + name = 'InDetPhysValDecoratorAlgGSF', + TrackParticleContainerName =InDetPhysValKeys.GSFTrackParticles)) + +def getInDetPhysValDecoratorAlgDBM(**kwargs) : + ''' + Algorithm to decorate DBM track particles. + ''' + from InDetRecExample.InDetKeys import InDetKeys + return getInDetPhysValDecoratorAlg( **setDefaults(kwargs, + name = 'InDetPhysValDecoratorAlgDBM', + TrackParticleContainerName =InDetKeys.DBMTrackParticles() )) # Debugging # import trace @@ -294,12 +242,11 @@ def addGSFTrackDecoratorAlg() : Search egamma algorithm and add the GSF TrackParticle decorator after the it. ''' from InDetPhysValMonitoring.InDetPhysValDecoration import _addDecorators - from InDetPhysValMonitoring.InDetPhysValDecoration import InDetPhysValDecoratorAlg - from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags if InDetPhysValFlags.doValidateGSFTracks() : # print 'DEBUG add addGSFTrackDecoratorAlg' - decorators=[InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlgGSF() ] + decorators=[getInDetPhysValDecoratorAlgGSF()] + # add the InDetPhysValDecoratorAlgGSF after the egamma algorithms ran # they build the GSF track particles. _addDecorators( decorators, ['egamma','egammaTruthAssociationAlg'] ) @@ -344,7 +291,7 @@ def addDecorator() : decorators=[] - decorators.append( InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlg() ) + decorators.append( getInDetPhysValDecoratorAlg() ) from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags InDetPhysValFlags.init() @@ -361,10 +308,17 @@ def addDecorator() : # for backward compatibility check whether DBM has been added already if InDetPhysValFlags.doValidateDBMTracks() and hasattr(InDetKeys,'DBMTrackParticles') : # and InDetFlags.doDBM() - decorators.append( InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlgDBM() ) + decorators.append( getInDetPhysValDecoratorAlgDBM() ) + + from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags + from InDetPhysValMonitoring.ConfigUtils import extractCollectionPrefix + for col in InDetPhysValFlags.validateExtraTrackCollections() : + prefix=extractCollectionPrefix(col) + decorators += [ getInDetPhysValDecoratorAlg(name = 'InDetPhysValDecoratorAlg'+prefix, + TrackParticleContainerName = prefix+"TrackParticles") ] _addDecorators( decorators ) - + def addExtraMonitoring() : ''' IF monitoring is wished for GSF or DBM TrackParticles find the monitoring manager and diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValJobProperties.py b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValJobProperties.py index c2cdc56117157..f4bb109f8aaef 100644 --- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValJobProperties.py +++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValJobProperties.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # ## purpose Python module to hold common flags to configure the InDetPhysValMonitoring @@ -67,6 +67,12 @@ class doValidateTracksInJets(InDetPhysValFlagsJobProperty): allowedTypes = ['bool'] StoredValue = False +class validateExtraTrackCollections(InDetPhysValFlagsJobProperty) : + """List of extra track collection names to be validated in addition to Tracks.""" + statusOn = True + allowedTypes = ['list'] + StoredValue = [] + from InDetRecExample.InDetJobProperties import Enabled ##----------------------------------------------------------------------------- @@ -122,10 +128,11 @@ jobproperties.add_Container(InDetPhysValJobProperties) _list_InDetPhysValJobProperties = [ Enabled, doValidateDBMTracks, - doValidateGSFTracks, + doValidateGSFTracks, doValidateLooseTracks, doValidateTightPrimaryTracks, - doValidateTracksInJets + doValidateTracksInJets, + validateExtraTrackCollections ] for j in _list_InDetPhysValJobProperties: diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValMonitoringTool.py b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValMonitoringTool.py index 6e9d441c958ba..00b11607f6eea 100644 --- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValMonitoringTool.py +++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValMonitoringTool.py @@ -1,6 +1,6 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -from ConfigUtils import injectNameArgument,checkKWArgs,_args,serviceFactory,toolFactory +from ConfigUtils import setDefaults,serviceFactory,toolFactory import InDetPhysValMonitoring.InDetPhysValMonitoringConf @@ -27,142 +27,101 @@ def removePhysValExample() : for child in topSequence.getChildren() : print 'DEBUG top sequence has %s' % (child.getName()) -class InDetPhysValMonitoringTool(object) : - ''' - Namespace for inner detector hole search tools - ''' - def __init__(self) : - raise('must not be instantiated. Only child classes should be instantiated.') - - class InDetPhysValMonitoringTool(InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysValMonitoringTool) : - ''' - Default InDetPhysValMonitoringTool for InDetTrackParticles - ''' - @injectNameArgument - def __new__(cls, *args, **kwargs) : - print "DEBUG InDetPhysValMonitoringTool.py InDetPhysValMonitoringTool.InDetPhysValMonitoringTool %s" %kwargs['name'] - return InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysValMonitoringTool.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetPhysValMonitoringTool.InDetPhysValMonitoringTool,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # special parameters of the default InDetPhysValMonitoringTool - self.useTrackSelection = False - self.EnableLumi = False - - # create the HistogramDefinitionSvc - # at the moment there can only be one HistogramDefinitionSvc - from InDetPhysValMonitoring.HistogramDefinitionSvc import HistogramDefinitionSvc - #self.HistogramDefinitionSvc = - serviceFactory(HistogramDefinitionSvc.HistogramDefinitionSvc) - - from InDetPhysValMonitoring.InDetPhysValJobProperties import isMC,InDetPhysValFlags - if isMC() : - self.TruthParticleContainerName = "TruthParticles" - if InDetPhysValFlags.doValidateTracksInJets() : - self.jetContainerName ='AntiKt4TruthJets' - self.FillTrackInJetPlots = True - from InDetPhysValMonitoring.addTruthJets import addTruthJetsIfNotExising - addTruthJetsIfNotExising(self.jetContainerName) - else : - self.jetContainerName ='' - self.FillTrackInJetPlots = False - - - else : - # disable truth monitoring for data - self.TruthParticleContainerName = '' - # the jet container is actually meant to be a truth jet container - self.jetContainerName ='' - - - # hack to remove example phyval monitor - from RecExConfig.AutoConfiguration import IsInInputFile - if not IsInInputFile('xAOD::JetContainer','AntiKt4EMTopoJets') : - from RecExConfig.RecFlags import rec - rec.UserExecs += ['from InDetPhysValMonitoring.InDetPhysValMonitoringTool import removePhysValExample;removePhysValExample();'] - - - class InDetPhysValMonitoringToolLoose(InDetPhysValMonitoringTool) : - ''' - InDetPhysValMonitoringTool for track particles which pass the loose selection - ''' - #@injectNameArgument - #def __new__(cls, *args, **kwargs) : - # return InDetPhysValMonitoringTool.InDetPhysValMonitoringTool.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetPhysValMonitoringTool.InDetPhysValMonitoringToolLoose,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # special parameters of the InDetPhysValMonitoringTool for monitoring loose tracks - self.SubFolder='Loose/' - self.useTrackSelection = True - - from InDetPhysValMonitoring.TrackSelectionTool import InDetTrackSelectionTool - self.TrackSelectionTool = toolFactory(InDetTrackSelectionTool.InDetTrackSelectionToolLoose) - - - class InDetPhysValMonitoringToolTightPrimary(InDetPhysValMonitoringTool) : - ''' - InDetPhysValMonitoringTool for track particles which pass the tight primary selection - ''' - #@injectNameArgument - #def __new__(cls, *args, **kwargs) : - # return InDetPhysValMonitoringTool.InDetPhysValMonitoringTool.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetPhysValMonitoringTool.InDetPhysValMonitoringToolTightPrimary,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # special parameters of the InDetPhysValMonitoringTool for monitoring tight primary tracks - self.SubFolder='TightPrimary/' - self.useTrackSelection = True - - from InDetPhysValMonitoring.TrackSelectionTool import InDetTrackSelectionTool - self.TrackSelectionTool = toolFactory(InDetTrackSelectionTool.InDetTrackSelectionToolTightPrimary) - - class InDetPhysValMonitoringToolGSF(InDetPhysValMonitoringTool) : - ''' - InDetPhysValMonitoringTool for GSF track particles - ''' - #@injectNameArgument - #def __new__(cls, *args, **kwargs) : - # return InDetPhysValMonitoringTool.InDetPhysValMonitoringTool.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetPhysValMonitoringTool.InDetPhysValMonitoringToolGSF,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # special parameters of the GSF InDetPhysValMonitoringTool - self.TrackParticleContainerName = 'GSFTrackParticles' - self.SubFolder='GSF/' - - - class InDetPhysValMonitoringToolDBM(InDetPhysValMonitoringTool) : - ''' - InDetPhysValMonitoringTool for DBM track particles - ''' - #@injectNameArgument - #def __new__(cls, *args, **kwargs) : - # return InDetPhysValMonitoringTool.InDetPhysValMonitoringTool.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetPhysValMonitoringTool.InDetPhysValMonitoringToolDBM,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # special parameters of the GSF InDetPhysValMonitoringTool - from InDetRecExample.InDetKeys import InDetKeys - self.TrackParticleContainerName=InDetKeys.DBMTracks() - self.SubFolder='DBM/' +def getInDetPhysValMonitoringTool(**kwargs) : + kwargs=setDefaults(kwargs, + useTrackSelection = False, + EnableLumi = False) + + # create the HistogramDefinitionSvc + # at the moment there can only be one HistogramDefinitionSvc + from InDetPhysValMonitoring.HistogramDefinitionSvc import getHistogramDefinitionSvc + #self.HistogramDefinitionSvc = + serviceFactory(getHistogramDefinitionSvc) + + from InDetPhysValMonitoring.InDetPhysValJobProperties import isMC,InDetPhysValFlags + if isMC() : + from InDetPhysValMonitoring.InDetPhysValDecoration import getInDetRttTruthSelectionTool + kwargs=setDefaults(kwargs, TruthParticleContainerName = "TruthParticles") + if 'TruthSelectionTool' not in kwargs : + kwargs=setDefaults(kwargs, TruthSelectionTool = getInDetRttTruthSelectionTool() ) + if InDetPhysValFlags.doValidateTracksInJets() : + jets_name='AntiKt4TruthJets' + kwargs=setDefaults(kwargs, + jetContainerName = jets_name, + FillTrackInJetPlots = True) + from InDetPhysValMonitoring.addTruthJets import addTruthJetsIfNotExising + addTruthJetsIfNotExising(jets_name) + else : + kwargs=setDefaults(kwargs, + jetContainerName ='' , + FillTrackInJetPlots = False) + + else : + # disable truth monitoring for data + kwargs=setDefaults(kwargs, + TruthParticleContainerName = '', + # TruthVertexContainerName = '', + # TruthEventKey = '', + # TruthPileupEventKey = '', + # TruthSelectionTool = '', + # the jet container is actually meant to be a truth jet container + jetContainerName ='', + FillTrackInJetPlots = False) + + # hack to remove example phyval monitor + from RecExConfig.AutoConfiguration import IsInInputFile + if not IsInInputFile('xAOD::JetContainer','AntiKt4EMTopoJets') : + add_remover=True; + from RecExConfig.RecFlags import rec + for elm in rec.UserExecs : + if elm.find('removePhysValExample')>0 : + add_remover=False + break + if add_remover : + rec.UserExecs += ['from InDetPhysValMonitoring.InDetPhysValMonitoringTool import removePhysValExample;removePhysValExample();'] + + return InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysValMonitoringTool(**kwargs) + + +def getInDetPhysValMonitoringToolLoose(**kwargs) : + if 'TrackSelectionTool' not in kwargs : + from InDetPhysValMonitoring.TrackSelectionTool import InDetTrackSelectionTool + kwargs=setDefaults(kwargs, TrackSelectionTool = toolFactory(InDetTrackSelectionTool.getInDetTrackSelectionToolLoose)) + + kwargs=setDefaults(kwargs, + name = 'InDetPhysValMonitoringToolLoose', + SubFolder = 'Loose/', + useTrackSelection = True) + + return getInDetPhysValMonitoringTool(**kwargs) + +def getInDetPhysValMonitoringToolTightPrimary(**kwargs) : + if 'TrackSelectionTool' not in kwargs : + from InDetPhysValMonitoring.TrackSelectionTool import InDetTrackSelectionTool + kwargs=setDefaults(kwargs, TrackSelectionTool = toolFactory(InDetTrackSelectionTool.getInDetTrackSelectionToolTightPrimary)) + + kwargs=setDefaults(kwargs, + name = 'InDetPhysValMonitoringToolTightPrimary', + SubFolder = 'TightPrimary/', + useTrackSelection = True) + + return getInDetPhysValMonitoringTool(**kwargs) + +def getInDetPhysValMonitoringToolGSF(**kwargs) : + kwargs=setDefaults(kwargs, + name = 'InDetPhysValMonitoringToolGSF', + SubFolder = 'GSF/', + TrackParticleContainerName = 'GSFTrackParticles', + useTrackSelection = True) + + return getInDetPhysValMonitoringTool(**kwargs) + +def getInDetPhysValMonitoringToolDBM(**kwargs) : + from InDetRecExample.InDetKeys import InDetKeys + kwargs=setDefaults(kwargs, + name = 'InDetPhysValMonitoringToolDBM', + SubFolder = 'DBM/', + TrackParticleContainerName = InDetKeys.DBMTracks(), + useTrackSelection = True) + + return getInDetPhysValMonitoringTool(**kwargs) diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/TrackSelectionTool.py b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/TrackSelectionTool.py index 90b888e37f419..84199a40c2d93 100644 --- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/TrackSelectionTool.py +++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/TrackSelectionTool.py @@ -1,47 +1,20 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -from ConfigUtils import injectNameArgument,checkKWArgs,_args,serviceFactory +from ConfigUtils import setDefaults from InDetTrackSelectionTool.InDetTrackSelectionToolConf import InDet__InDetTrackSelectionTool -class InDetTrackSelectionTool(object) : +def getInDetTrackSelectionToolLoose(**kwargs) : ''' - Namespace for inner detector hole search tools + Default InDetTrackSelectionTool for InDetTrackParticles ''' - def __init__(self) : - raise('must not be instantiated. Only child classes should be instantiated.') - - class InDetTrackSelectionToolLoose(InDet__InDetTrackSelectionTool) : - ''' - Default InDetTrackSelectionTool for InDetTrackParticles - ''' - @injectNameArgument - def __new__(cls, *args, **kwargs) : - return InDet__InDetTrackSelectionTool.__new__(cls,*args,**kwargs) + kwargs = setDefaults(kwargs,CutLevel = "Loose" ) + return InDet__InDetTrackSelectionTool(**kwargs) - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetTrackSelectionTool.InDetTrackSelectionToolLoose,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # special parameters of the InDetTrackSelectionToolLoose - self.CutLevel = "Loose" - - class InDetTrackSelectionToolTightPrimary(InDet__InDetTrackSelectionTool) : - ''' - Default InDetTrackSelectionTool for InDetTrackParticles - ''' - @injectNameArgument - def __new__(cls, *args, **kwargs) : - return InDet__InDetTrackSelectionTool.__new__(cls,*args,**kwargs) - - @checkKWArgs - def __init__(self, **kwargs) : - super(InDetTrackSelectionTool.InDetTrackSelectionToolTightPrimary,self)\ - .__init__(**_args( kwargs, - name = self.__class__.__name__)) - - # special parameters of the InDetTrackSelectionToolTightPrimary - self.CutLevel = "TightPrimary" +def getInDetTrackSelectionToolTightPrimary(**kwargs) : + ''' + Default InDetTrackSelectionTool for InDetTrackParticles + ''' + kwargs = setDefaults(kwargs, CutLevel = "TightPrimary" ) + return InDet__InDetTrackSelectionTool(**kwargs) diff --git a/PhysicsAnalysis/PhysicsValidation/PhysValMonitoring/share/PhysValInDet_jobOptions.py b/PhysicsAnalysis/PhysicsValidation/PhysValMonitoring/share/PhysValInDet_jobOptions.py index f6180f2d7f951..29eeb4c3a5ee4 100644 --- a/PhysicsAnalysis/PhysicsValidation/PhysValMonitoring/share/PhysValInDet_jobOptions.py +++ b/PhysicsAnalysis/PhysicsValidation/PhysValMonitoring/share/PhysValInDet_jobOptions.py @@ -3,29 +3,28 @@ decoration = InDetPhysValMonitoring.InDetPhysValDecoration.addDecoratorIfNeeded( # add ID physics validation monitoring tool -from InDetPhysValMonitoring.InDetPhysValMonitoringTool import InDetPhysValMonitoringTool from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags +import InDetPhysValMonitoring.InDetPhysValMonitoringTool as InDetPhysValMonitoringTool -indet_mon_tool = InDetPhysValMonitoringTool.InDetPhysValMonitoringTool() -ToolSvc += [indet_mon_tool] -monMan.AthenaMonTools += [indet_mon_tool] +mons=[ (True , InDetPhysValMonitoringTool.getInDetPhysValMonitoringTool), + (InDetPhysValFlags.doValidateLooseTracks() , InDetPhysValMonitoringTool.getInDetPhysValMonitoringToolLoose), + (InDetPhysValFlags.doValidateTightPrimaryTracks() , InDetPhysValMonitoringTool.getInDetPhysValMonitoringToolTightPrimary), + (InDetPhysValFlags.doValidateDBMTracks() , InDetPhysValMonitoringTool.getInDetPhysValMonitoringToolDBM), + (InDetPhysValFlags.doValidateGSFTracks() , InDetPhysValMonitoringTool.getInDetPhysValMonitoringToolGSF) + ] -if InDetPhysValFlags.doValidateDBMTracks(): - indet_mon_tool_DBM = InDetPhysValMonitoringTool.InDetPhysValMonitoringToolDBM() - ToolSvc += [ indet_mon_tool_DBM ] - monMan.AthenaMonTools += [ indet_mon_tool_DBM ] +for enabled, creator in mons : + if enabled : + tool = creator() + ToolSvc += [ tool ] + monMan.AthenaMonTools += [ tool ] -if InDetPhysValFlags.doValidateGSFTracks(): - indet_mon_tool_GSF = InDetPhysValMonitoringTool.InDetPhysValMonitoringToolGSF() - ToolSvc += [ indet_mon_tool_GSF ] - monMan.AthenaMonTools += [ indet_mon_tool_GSF ] - -if InDetPhysValFlags.doValidateLooseTracks(): - indet_mon_tool_Loose = InDetPhysValMonitoringTool.InDetPhysValMonitoringToolLoose() - ToolSvc += [ indet_mon_tool_Loose ] - monMan.AthenaMonTools += [ indet_mon_tool_Loose ] - -if InDetPhysValFlags.doValidateTightPrimaryTracks(): - indet_mon_tool_TightPrimary = InDetPhysValMonitoringTool.InDetPhysValMonitoringToolTightPrimary() - ToolSvc += [ indet_mon_tool_TightPrimary ] - monMan.AthenaMonTools += [ indet_mon_tool_TightPrimary ] +from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags +from InDetPhysValMonitoring.ConfigUtils import extractCollectionPrefix +for col in InDetPhysValFlags.validateExtraTrackCollections() : + prefix=extractCollectionPrefix(col) + tool = InDetPhysValMonitoringTool.getInDetPhysValMonitoringTool(name = 'InDetPhysValMonitoringTool'+prefix, + SubFolder = prefix+'Tracks/', + TrackParticleContainerName = prefix+'TrackParticles') + ToolSvc += [ tool ] + monMan.AthenaMonTools += [ tool ] -- GitLab