Exemplo n.º 1
0
    def WrapTauRecToolExecHandle(self, tool=None):

        self.TauProcessorAlgHandle().Tools = tool
        from AthenaCommon.AlgSequence import AlgSequence

        topSequence = AlgSequence()

        if jobproperties.Beam.beamType() != "cosmics":
            # Can I move this to different script?
            from AthenaCommon.AppMgr import ToolSvc
            from JetRec.JetRecConf import JetAlgorithm
            jetTrackAlg = JetAlgorithm("JetTrackAlg_forTaus")
            from JetRecTools.JetRecToolsConf import TrackVertexAssociationTool
            TauTVATool = TrackVertexAssociationTool(
                TrackParticleContainer="InDetTrackParticles",
                TrackVertexAssociation="JetTrackVtxAssoc_forTaus",
                VertexContainer="PrimaryVertices",
                MaxTransverseDistance=2.5 * mm,
                #MaxLongitudinalDistance = 2 *mm,
                MaxZ0SinTheta=3.0 * mm,
                #OutputLevel=2
            )
            ToolSvc += TauTVATool
            jetTrackAlg.Tools = [TauTVATool]
            topSequence += jetTrackAlg

            # import tauRec.TauAlgorithmsHolder as taualgs
            # add tauJVF tool to topSequence
            # taualgs.setupTauJVFTool

        topSequence += self.TauProcessorAlgHandle()
Exemplo n.º 2
0
def setupTauJVFTool():
    from AthenaCommon.AppMgr import ToolSvc

    """
    #Configures tau track selector tool for TJVA
    from InDetTrackSelectorTool.InDetTrackSelectorToolConf import InDet__InDetDetailedTrackSelectorTool
    InDetTrackSelectorToolForTJVA = InDet__InDetDetailedTrackSelectorTool(name = sPrefix + 'InDetTrackSelectorToolForTJVA',
                                                                pTMin                = 1000.,
                                                                IPd0Max              = 9999.*mm,
                                                                IPz0Max              = 9999.*mm,                                                                 
                                                                nHitPix              = 2,  # PixelHits + PixelDeadSensors
                                                                nHitSct              = 0,  # SCTHits + SCTDeadSensors
                                                                nHitSi               = 7,  # PixelHits + SCTHits + PixelDeadSensors + SCTDeadSensors
                                                                fitChi2OnNdfMax      = 99999,
                                                                TrackSummaryTool     = None,
                                                                Extrapolator         = getAtlasExtrapolator())        
        
    ToolSvc += InDetTrackSelectorToolForTJVA
    """
    from JetRec.JetRecConf import JetAlgorithm
    jetTrackAlg = JetAlgorithm(sPrefix+"JetTrackAlg_forTaus")

    """
    from JetRecTools.JetRecToolsConf import JetTrackSelectionTool
    ToolSvc += JetTrackSelectionTool(InputContainer = _DefaultTrackContainer, 
                                     OutputContainer="JetSelectedTracks_forTaus", 
                                     Selector=InDetTrackSelectorToolForTJVA, 
                                     OutputLevel=2
                                     # what is about ptmin, eta min/max???
                                     )
    """

    from JetRecTools.JetRecToolsConf import TrackVertexAssociationTool
    ToolSvc += TrackVertexAssociationTool(TrackParticleContainer = _DefaultTrackContainer ,
                                          TrackVertexAssociation=sPrefix+"JetTrackVtxAssoc_forTaus", 
                                          VertexContainer= _DefaultVertexContainer,
                                          MaxTransverseDistance = 2.5 *mm,
                                          MaxLongitudinalDistance = 2 *mm, 
                                          #OutputLevel=2
                                          )
    #jetTrackAlg.Tools = [ToolSvc.JetTrackSelectionTool , ToolSvc.TrackVertexAssociationTool ]                                          
    jetTrackAlg.Tools = [ToolSvc.TrackVertexAssociationTool ]                                          
    
    from AthenaCommon.AlgSequence import AlgSequence
    topSequence = AlgSequence()    
    topSequence+=jetTrackAlg
Exemplo n.º 3
0
def JetAlgFromTools(rtools, suffix="HI", persistify=True):
    #insert exe tools at front of list, e.g. tracksel and tvassoc for HI etc.
    HIJet_exe_tools = []
    from JetRec.JetRecFlags import jetFlags
    if jetFlags.useTruth() and not jetFlags.Enabled():
        HIJet_exe_tools += HITruthParticleCopy()
    #if jetFlags.useCells():  HIJet_exe_tools += [jtm.missingcells]
    if HIJetFlags.UseHITracks():
        HIJet_exe_tools += [jtm.tracksel_HI, jtm.gtracksel_HI, jtm.tvassoc_HI]
    rtools = HIJet_exe_tools + rtools
    from JetRec.JetRecConf import JetToolRunner
    runner = JetToolRunner("jetrun" + suffix,
                           Tools=rtools,
                           Timer=jetFlags.timeJetToolRunner())
    jtm.add(runner)

    from JetRec.JetRecConf import JetAlgorithm
    theAlg = JetAlgorithm("jetalg" + suffix)
    theAlg.Tools = [runner]
    from AthenaCommon.AlgSequence import AlgSequence
    topsequence = AlgSequence()
    topsequence += theAlg

    from GaudiKernel.Constants import DEBUG
    if jetFlags.debug > 0:

        jtm.setOutputLevel(runner, DEBUG)
        theAlg.OutputLevel = DEBUG

    if jetFlags.debug > 3:
        jtm.setOutputLevel(jtm.jetBuilderWithoutArea, DEBUG)

    if persistify:
        for t in rtools:
            if hasattr(t, "OutputContainer"):
                AddToOutputList(t.OutputContainer)
    return theAlg
Exemplo n.º 4
0
def getTVATool():
    _name = sPrefix + 'TVATool'

    if _name in cached_instances:
        return cached_instances[_name]

    from JetRecTools.JetRecToolsConf import TrackVertexAssociationTool
    TVATool = TrackVertexAssociationTool(
        "TVATool_forDiTaus",
        TrackParticleContainer="InDetTrackParticles",
        TrackVertexAssociation="JetTrackVtxAssoc_forDiTaus",
        VertexContainer="PrimaryVertices",
        MaxTransverseDistance=2.5,  # in mm
        MaxLongitudinalDistance=2  # in mm
    )
    from AthenaCommon.AppMgr import ToolSvc
    ToolSvc += TVATool

    from JetRec.JetRecConf import JetAlgorithm
    jetTrackAlg = JetAlgorithm(name=_name)
    jetTrackAlg.Tools = [TVATool]

    cached_instances[_name] = jetTrackAlg
    return jetTrackAlg
Exemplo n.º 5
0
def addJetRecoToAlgSequence(job=None,
                            useTruth=None,
                            eventShapeTools=None,
                            separateJetAlgs=None,
                            debug=None):

    myname = "JetAlgorithm: "

    # We need this to modify the global variable.
    global jetalg

    # Import message level flags.
    from GaudiKernel.Constants import DEBUG

    # Import the jet reconstruction control flags.
    from JetRec.JetRecFlags import jetFlags

    # Import the standard jet tool manager.
    from JetRec.JetRecStandardToolManager import jtm

    # Set sequence and flags as needed.
    if job == None:
        from AthenaCommon.AlgSequence import AlgSequence
        job = AlgSequence()
    if useTruth == None:
        useTruth = jetFlags.useTruth()
    if eventShapeTools == None:
        eventShapeTools = jetFlags.eventShapeTools()
        if eventShapeTools == None:
            eventShapeTools = []
    if separateJetAlgs == None:
        separateJetAlgs = jetFlags.separateJetAlgs()

    # Event shape tools.
    evstools = []
    evsDict = {
        "emtopo": ("EMTopoEventShape", jtm.emget),
        "lctopo": ("LCTopoEventShape", jtm.lcget),
        "empflow": ("EMPFlowEventShape", jtm.empflowget),
        "emcpflow": ("EMCPFlowEventShape", jtm.emcpflowget),
        "lcpflow": ("LCPFlowEventShape", jtm.lcpflowget),
    }

    if jetFlags.useTracks():
        evsDict["emtopo"] = ("EMTopoOriginEventShape", jtm.emoriginget)
        evsDict["lctopo"] = ("LCTopoOriginEventShape", jtm.lcoriginget)
    jetlog.info(myname + "Event shape tools: " + str(eventShapeTools))

    from RecExConfig.AutoConfiguration import IsInInputFile
    for evskey in eventShapeTools:
        from EventShapeTools.EventDensityConfig import configEventDensityTool
        if evskey in evsDict:
            (toolname, getter) = evsDict[evskey]
            if toolname in jtm.tools:
                jetlog.info(myname + "Skipping duplicate event shape: " +
                            toolname)
            else:
                jetlog.info(myname + "Adding event shape " + evskey)
                if not IsInInputFile("xAOD::EventShape", "Kt4" + toolname):
                    jtm += configEventDensityTool(toolname, getter, 0.4)
                    evstools += [jtm.tools[toolname]]
        else:
            jetlog.info(myname + "Invalid event shape key: " + evskey)
            raise Exception

    # Add the tool runner. It runs the jetrec tools.
    rtools = []
    # Add the truth tools.
    if useTruth:
        from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
        rtools += scheduleCopyTruthParticles()

        # build truth jet input :
        rtools += [jtm.truthpartcopy, jtm.truthpartcopywz]

    ## if jetFlags.useCells():
    ##   rtools += [jtm.missingcells] commented out : incompatible with trigger : ATR-9696
    if jetFlags.useTracks:
        rtools += [
            jtm.tracksel,
            jtm.tvassoc,
            jtm.trackselloose_trackjets,
        ]

    # Add the algorithm. It runs the jetrec tools.
    from JetRec.JetRecConf import JetAlgorithm
    ctools = []
    if jetFlags.useTracks:
        if not IsInInputFile("xAOD::CaloClusterContainer",
                             "LCOriginTopoClusters"):
            ctools += [jtm.JetConstitSeq_LCOrigin]
        if not IsInInputFile("xAOD::CaloClusterContainer",
                             "EMOriginTopoClusters"):
            ctools += [jtm.JetConstitSeq_EMOrigin]
    from JetRec.JetRecConf import JetToolRunner
    runners = []
    if len(ctools) > 0:
        jtm += JetToolRunner("jetconstit",
                             EventShapeTools=[],
                             Tools=ctools,
                             Timer=jetFlags.timeJetToolRunner())
        jtm.jetconstit
        runners = [jtm.jetconstit]

    if jetFlags.separateJetAlgs():

        jtm += JetToolRunner("jetrun",
                             EventShapeTools=evstools,
                             Tools=rtools,
                             Timer=jetFlags.timeJetToolRunner())
        runners += [jetrun]

        job += JetAlgorithm("jetalg")
        jetalg = job.jetalg
        jetalg.Tools = runners

        for t in jtm.jetrecs:
            jalg = JetAlgorithm("jetalg" + t.name())
            jalg.Tools = [t]
            job += jalg

    else:
        from JetRec.JetRecConf import JetToolRunner
        jtm += JetToolRunner("jetrun",
                             EventShapeTools=evstools,
                             Tools=rtools + jtm.jetrecs,
                             Timer=jetFlags.timeJetToolRunner())
        runners += [jtm.jetrun]

        job += JetAlgorithm("jetalg")
        jetalg = job.jetalg
        jetalg.Tools = runners
        if jetFlags.debug > 0:
            jtm.setOutputLevel(jtm.jetrun, DEBUG)
            jetalg.OutputLevel = DEBUG
        if jetFlags.debug > 1:
            for tool in jtm.jetrecs:
                jtm.setOutputLevel(tool, DEBUG)
        if jetFlags.debug > 2:
            for tool in jtm.finders:
                jtm.setOutputLevel(tool, DEBUG)
        if jetFlags.debug > 3:
            jtm.setOutputLevel(jtm.jetBuilderWithArea, DEBUG)
            jtm.setOutputLevel(jtm.jetBuilderWithoutArea, DEBUG)
Exemplo n.º 6
0
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
Exemplo n.º 7
0
rtools += jtm.jetrecs
from JetRec.JetRecConf import JetToolRunner
jtm += JetToolRunner("jetrun",
         EventShapeTools=evstools,
         Tools=rtools,
         Timer=jetFlags.timeJetToolRunner()
       )
jetrun = jtm.jetrun

# Add the algorithm. It runs the jetrec tools.
from JetRec.JetRecConf import JetAlgorithm

if jetFlags.separateJetAlgs():
    for t in rtools:
        jalg = JetAlgorithm("jetalg"+t.name())
        jalg.Tools = [t]
        job+= jalg
else:
    job += JetAlgorithm("jetalg")
    jetalg = job.jetalg
    jetalg.Tools = [jtm.jetrun]

    if jetFlags.debug > 0:
      jtm.setOutputLevel(jtm.jetrun, DEBUG)
      jetalg.OutputLevel = DEBUG

    if jetFlags.debug > 1:
      for tool in jtm.jetrecs:
        jtm.setOutputLevel(tool, DEBUG)

    if jetFlags.debug > 2:
Exemplo n.º 8
0
def addJetRecoToAlgSequence(job =None, useTruth =None, eventShapeTools =None,
                            separateJetAlgs= None, debug =None):

  myname = "JetAlgorithm: "

  # We need this to modify the global variable.
  global jetalg

  # Import message level flags.
  from GaudiKernel.Constants import DEBUG

  # Import the jet reconstruction control flags.
  from JetRec.JetRecFlags import jetFlags

  # Import the standard jet tool manager.
  from JetRec.JetRecStandardToolManager import jtm

  # Set sequence and flags as needed.
  if job == None:
    from AthenaCommon.AlgSequence import AlgSequence
    job = AlgSequence()
  if useTruth == None:
    useTruth = jetFlags.useTruth()
  if eventShapeTools == None:
    eventShapeTools = jetFlags.eventShapeTools()
    if eventShapeTools == None:
      eventShapeTools = []
  if separateJetAlgs == None:
    separateJetAlgs = jetFlags.separateJetAlgs()


  # Event shape tools.
  evstools = []
  evsDict = {
    "emtopo"   : ("EMTopoEventShape",   jtm.emget),
    "lctopo"   : ("LCTopoEventShape",   jtm.lcget),
    "empflow"  : ("EMPFlowEventShape",  jtm.empflowget),
    "emcpflow" : ("EMCPFlowEventShape", jtm.emcpflowget),
    "lcpflow"  : ("LCPFlowEventShape",  jtm.lcpflowget),
  }
  print myname + "Event shape tools: " + str(eventShapeTools)
  for evskey in eventShapeTools:
    from EventShapeTools.EventDensityConfig import configEventDensityTool
    if evskey in evsDict:
      (toolname, getter) = evsDict[evskey]
      if toolname in jtm.tools:
        print myname + "Skipping duplicate event shape: " + toolname
      else:
        print myname + "Adding event shape " + evskey
        jtm += configEventDensityTool(toolname, getter, 0.4)
        evstools += [jtm.tools[toolname]]
    else:
      print myname + "Invalid event shape key: " + evskey
      raise Exception

  # Add the tool runner. It runs the jetrec tools.
  rtools = []
  # Add the truth tools.
  if useTruth:    
    from JetRec.JetFlavorAlgs import scheduleCopyTruthParticles
    rtools += scheduleCopyTruthParticles()
    
    # build truth jet input :
    rtools += [ jtm.truthpartcopy, jtm.truthpartcopywz ]

  ## if jetFlags.useCells():
  ##   rtools += [jtm.missingcells] commented out : incompatible with trigger : ATR-9696
  if jetFlags.useTracks:
    rtools += [jtm.tracksel,
               jtm.tvassoc,
               jtm.trackselloose_trackjets,
               jtm.JetConstitSeq_LCOrigin,
               jtm.JetConstitSeq_EMOrigin,
               ]
    
  # Add the algorithm. It runs the jetrec tools.
  from JetRec.JetRecConf import JetAlgorithm

  if jetFlags.separateJetAlgs():

    from JetRec.JetRecConf import JetToolRunner
    jtm += JetToolRunner("jetrun",
                         EventShapeTools=evstools,
                         Tools=rtools,
                         Timer=jetFlags.timeJetToolRunner()
                         )
    jetrun = jtm.jetrun

    job += JetAlgorithm("jetalg")
    jetalg = job.jetalg
    jetalg.Tools = [jtm.jetrun]

    for t in jtm.jetrecs:
      # from JetRec.JetRecConf import JetToolRunner
      # jetrun_rec = JetToolRunner("jetrun"+t.name(),
      #                            EventShapeTools=[],
      #                            Tools=[t],
      #                            Timer=jetFlags.timeJetToolRunner()
      #                            )
      # jtm += jetrun_rec
      jalg = JetAlgorithm("jetalg"+t.name())
      jalg.Tools = [t]
      job+= jalg

  else:
    from JetRec.JetRecConf import JetToolRunner
    jtm += JetToolRunner("jetrun",
                         EventShapeTools=evstools,
                         Tools=rtools+jtm.jetrecs,
                         Timer=jetFlags.timeJetToolRunner()
                         )
    jetrun = jtm.jetrun

    job += JetAlgorithm("jetalg")
    jetalg = job.jetalg
    jetalg.Tools = [jtm.jetrun]
    if jetFlags.debug > 0:
      jtm.setOutputLevel(jtm.jetrun, DEBUG)
      jetalg.OutputLevel = DEBUG
    if jetFlags.debug > 1:
      for tool in jtm.jetrecs:
        jtm.setOutputLevel(tool, DEBUG)
    if jetFlags.debug > 2:
      for tool in jtm.finders:
        jtm.setOutputLevel(tool, DEBUG)
    if jetFlags.debug > 3:
      jtm.setOutputLevel(jtm.jetBuilderWithArea, DEBUG)
      jtm.setOutputLevel(jtm.jetBuilderWithoutArea, DEBUG)