示例#1
0
def addExtraMonitoring():
    '''
  IF monitoring is wished for GSF or DBM TrackParticles find the monitoring manager and 
  add the corresponding monitoring tools.
  '''
    # hack to add monitors for DBM and GSF
    # the job option fragment which adds the InDetPhysValMonitoringTool for the default tracks
    # will call this method, so can abuse this method to also add the monitoring tools for DBM and GSF tracks
    try:
        from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags
        # flags are at this stage already initialised, so do not need to  InDetPhysValFlags.init()
        if InDetPhysValFlags.doValidateGSFTracks(
        ) or InDetPhysValFlags.doValidateDBMTracks(
        ) or InDetPhysValFlags.doValidateTightPrimaryTracks():
            mon_index = findMonMan()
            if mon_index != None:
                from AthenaCommon.AlgSequence import AlgSequence
                topSequence = AlgSequence()
                mon_manager = topSequence.getChildren()[mon_index]
                from InDetPhysValMonitoring.InDetPhysValMonitoringTool import InDetPhysValMonitoringTool

    except ImportError:
        import sys, traceback
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print "*** print_tb:"
        traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
        print "*** print_exception:"
        traceback.print_exception(exc_type,
                                  exc_value,
                                  exc_traceback,
                                  limit=2,
                                  file=sys.stdout)
        print "*** print_exc:"
        traceback.print_exc()
        raise
示例#2
0
def addDecorator():
    '''
  Add the track particle decoration algorithm to the top sequence. 
  The algorithm is to be run on RAW/RDO since it depends on full hit information
  which is generally not available at later stages. The decorations added by this
  algorithm are used by InDetPhysValMonitoring tool.
  '''

    decorators = []

    decorators.append(InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlg())

    from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags
    InDetPhysValFlags.init()
    if InDetPhysValFlags.doValidateGSFTracks():
        # cannot add the decorator for GSF tracks at this moment because the egamma algorithm has not been
        # constructed yet.
        # so this does not work: decorators.append( InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlgGSF() )
        # Can only schedule a user algorithm :
        from RecExConfig.RecFlags import rec
        rec.UserExecs += [
            'from InDetPhysValMonitoring.InDetPhysValDecoration import addGSFTrackDecoratorAlg;addGSFTrackDecoratorAlg();'
        ]

    # from  InDetRecExample.InDetJobProperties import InDetFlags
    from InDetRecExample.InDetKeys import InDetKeys
    # for backward compatibility check whether DBM has been added already
    if InDetPhysValFlags.doValidateDBMTracks() and hasattr(
            InDetKeys, 'DBMTrackParticles'):
        # and InDetFlags.doDBM()
        decorators.append(
            InDetPhysValDecoratorAlg.InDetPhysValDecoratorAlgDBM())

    _addDecorators(decorators)
示例#3
0
def addGSFTrackDecoratorAlg():
    '''
   Search egamma algorithm and add the GSF TrackParticle decorator after the it.
   '''
    from InDetPhysValMonitoring.InDetPhysValDecoration import _addDecorators

    from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags
    if InDetPhysValFlags.doValidateGSFTracks():
        # print ('DEBUG add addGSFTrackDecoratorAlg')
        decorators = getGSFTrackDecorators()
        from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags
        from InDetPhysValMonitoring.ConfigUtils import extractCollectionPrefix
        for col in InDetPhysValFlags.validateExtraTrackCollections():
            prefix = extractCollectionPrefix(col)
            decorators += getTrackDecorators(
                TrackParticleContainerName=prefix + "TrackParticles")
        # add the InDetPhysValDecoratorAlgGSF after the egamma algorithms ran
        # they build the GSF track particles.
        _addDecorators(decorators, ['egamma', 'egammaTruthAssociationAlg'])

        # To allow for proper decoration of GSF TrackParticles
        #  - have to switch of slimming for GSF Tracks at time of creation
        #  - must slim GSF Tracks after decoration since the unslimmed GSF Tracks cannot be persistified

        from AthenaCommon.AppMgr import ToolSvc
        # print (ToolSvc)
        # print ('DEBUG has EMBremCollectionBuilder %s' % hasattr(ToolSvc,'EMBremCollectionBuilder'))
        if hasattr(ToolSvc, 'EMBremCollectionBuilder'):
            decor_index = findAlg([decorators[0].getName()],
                                  search_outputstream_otherwise=False)
            if decor_index is not None:
                from TrkTrackSlimmer.TrkTrackSlimmerConf import Trk__TrackSlimmer as ConfigurableTrackSlimmer
                slimmer = ConfigurableTrackSlimmer(
                    name="RealGSFTrackSlimmer",
                    TrackLocation=[InDetPhysValKeys.GSFTracksUnslimmed],
                    SlimmedTrackLocation=[InDetPhysValKeys.GSFTracks],
                    TrackSlimmingTool=ToolSvc.EMBremCollectionBuilder.
                    TrackSlimmingTool)

                from InDetPhysValMonitoring.InDetPhysValMonitoringConf import DummyTrackSlimmingTool
                slimming_tool = DummyTrackSlimmingTool()
                ToolSvc += slimming_tool
                ToolSvc.EMBremCollectionBuilder.TrackSlimmingTool = slimming_tool
                ToolSvc.EMBremCollectionBuilder.OutputTrackContainerName = InDetPhysValKeys.GSFTracksUnslimmed
                # ToolSvc.ResidualPullCalculator.OutputLevel = 1

                from AthenaCommon.AlgSequence import AlgSequence
                topSequence = AlgSequence()
                topSequence.insert(decor_index + 1, slimmer)
示例#4
0
def addDecoratorIfNeeded():
    '''
    Run the InDet decoration algorithm if it has not been ran yet.
   '''

    if not canAddDecorator():
        print 'DEBUG addDecoratorIfNeeded ? Stage is too early or too late for running the decoration. Needs reconstructed tracks. Try again during next stage ?'
        return

    meta_data = getMetaData()
    if len(meta_data) == 0:
        # decoration has not been ran
        addDecorator()

    # if DBM or GSF tracks need to be monitored schedule addExtraMonitoring as user algorithm, so that
    # the monitoring manager exists already.
    from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags
    InDetPhysValFlags.init()
        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();'
                ]
示例#6
0
    excludedVertexAuxData = "-vxTrackAtVertex.-MvfFitInfo.-isInitialized.-VTAV"

    if InDetFlags.keepAdditionalHitsOnTrackParticle():
        excludedAuxData = "-caloExtension.-cellAssociation.-clusterAssociation"
    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 += [
示例#7
0
import InDetPhysValMonitoring.InDetPhysValDecoration
decoration = InDetPhysValMonitoring.InDetPhysValDecoration.addDecoratorIfNeeded()

# add ID physics validation monitoring tool

from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags
import InDetPhysValMonitoring.InDetPhysValMonitoringTool as InDetPhysValMonitoringTool

mons=[ (True                                             , InDetPhysValMonitoringTool.getInDetPhysValMonitoringTool),
       (InDetPhysValFlags.doValidateLooseTracks()        , InDetPhysValMonitoringTool.getInDetPhysValMonitoringToolLoose),
       (InDetPhysValFlags.doValidateTightPrimaryTracks() , InDetPhysValMonitoringTool.getInDetPhysValMonitoringToolTightPrimary),
       (InDetPhysValFlags.doValidateDBMTracks()          , InDetPhysValMonitoringTool.getInDetPhysValMonitoringToolDBM),
       (InDetPhysValFlags.doValidateGSFTracks()          , InDetPhysValMonitoringTool.getInDetPhysValMonitoringToolGSF)
     ]

for enabled, creator in mons :
    if enabled :
        monMan.AthenaMonTools += [ creator() ]


from InDetPhysValMonitoring.InDetPhysValMonitoringTool import getInDetPhysValMonitoringTool
from  InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags
from  InDetPhysValMonitoring.ConfigUtils import extractCollectionPrefix
for col in InDetPhysValFlags.validateExtraTrackCollections() :
    prefix=extractCollectionPrefix(col)
    monMan.AthenaMonTools += [ getInDetPhysValMonitoringTool(name                       = 'InDetPhysValMonitoringTool'+prefix,
                                                             SubFolder                  = prefix+'Tracks/',
                                                             TrackParticleContainerName = prefix+'TrackParticles') ]
示例#8
0
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 = 'AntiKt4LCTopoJets'
            kwargs = setDefaults(kwargs,
                                 JetContainerName=jets_name,
                                 FillTrackInJetPlots=True)
            from InDetPhysValMonitoring.addTruthJets import addTruthJetsIfNotExising
            addTruthJetsIfNotExising(jets_name)
            if InDetPhysValFlags.doValidateTracksInBJets():
                kwargs = setDefaults(kwargs, FillTrackInBJetPlots=True)

        else:
            kwargs = setDefaults(kwargs,
                                 JetContainerName='',
                                 FillTrackInJetPlots=False)

        #adding the VeretxTruthMatchingTool
        from InDetTruthVertexValidation.InDetTruthVertexValidationConf import InDetVertexTruthMatchTool
        kwargs = setDefaults(
            kwargs,
            useVertexTruthMatchTool=True,
            VertexTruthMatchTool=toolFactory(InDetVertexTruthMatchTool))

        #Options for Truth Strategy : Requires full pile-up truth containers for some
        if InDetPhysValFlags.setTruthStrategy(
        ) == 'All' or InDetPhysValFlags.setTruthStrategy() == 'PileUp':
            from RecExConfig.AutoConfiguration import IsInInputFile
            if IsInInputFile('xAOD::TruthPileupEventContainer',
                             'TruthPileupEvents'):
                kwargs = setDefaults(
                    kwargs, PileupSwitch=InDetPhysValFlags.setTruthStrategy())
            else:
                print(
                    'WARNING Truth Strategy for InDetPhysValMonitoring set to %s but TruthPileupEvents are missing in the input; resetting to HardScatter only'
                    % (InDetPhysValFlags.setTruthStrategy()))
        elif InDetPhysValFlags.setTruthStrategy() != 'HardScatter':
            print(
                'WARNING Truth Strategy for for InDetPhysValMonitoring set to invalid option %s; valid flags are ["HardScatter", "All", "PileUp"]'
                % (InDetPhysValFlags.setTruthStrategy()))

    else:
        # disable truth monitoring for data
        kwargs = setDefaults(
            kwargs,
            TruthParticleContainerName='',
            TruthVertexContainerName='',
            TruthEvents='',
            TruthPileupEvents='',
            TruthSelectionTool='',
            # the jet container is actually meant to be a truth jet container
            JetContainerName='',
            FillTrackInJetPlots=False,
            FillTrackInBJetPlots=False)

    # Control the number of output histograms
    if InDetPhysValFlags.doPhysValOutput():
        kwargs = setDefaults(kwargs, SkillLevel=100)

    elif InDetPhysValFlags.doExpertOutput():
        kwargs = setDefaults(kwargs, SkillLevel=200)

    # hack to remove example physval monitor
    from RecExConfig.AutoConfiguration import IsInInputFile
    if not IsInInputFile('xAOD::JetContainer', 'AntiKt4EMTopoJets'):
        add_remover = True
        from RecExConfig.RecFlags import rec
        try:
            for elm in rec.UserExecs:
                if elm.find('removePhysValExample') > 0:
                    add_remover = False
                    break
        except:
            pass
        if add_remover:
            rec.UserExecs += [
                'from InDetPhysValMonitoring.InDetPhysValMonitoringTool import removePhysValExample;removePhysValExample();'
            ]

    return InDetPhysValMonitoring.InDetPhysValMonitoringConf.InDetPhysValMonitoringTool(
        **kwargs)
示例#9
0
import InDetPhysValMonitoring.InDetPhysValDecoration
decoration = InDetPhysValMonitoring.InDetPhysValDecoration.addDecoratorIfNeeded(
)

# add ID physics validation monitoring tool

from InDetPhysValMonitoring.InDetPhysValMonitoringTool import InDetPhysValMonitoringTool
from InDetPhysValMonitoring.InDetPhysValJobProperties import InDetPhysValFlags

indet_mon_tool = InDetPhysValMonitoringTool.InDetPhysValMonitoringTool()
ToolSvc += [indet_mon_tool]
monMan.AthenaMonTools += [indet_mon_tool]

if InDetPhysValFlags.doValidateDBMTracks():
    indet_mon_tool_DBM = InDetPhysValMonitoringTool.InDetPhysValMonitoringToolDBM(
    )
    ToolSvc += [indet_mon_tool_DBM]
    monMan.AthenaMonTools += [indet_mon_tool_DBM]

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]