Exemplo n.º 1
0
    def btagging_postSystemRec(self, topSequence):
        """
        This fixes the uptodate BTagging calibration conditions tag.
        """

        from AthenaCommon.AppMgr import ToolSvc

        JetCollectionList = [ 'AntiKt4EMTopoJets',]

        SA = 'AODFix_'
        from BTagging.BTaggingConfiguration import getConfiguration
        BTagConf = getConfiguration("AODFix")
        BTagConf.PrefixxAODBaseName(False)
        BTagConf.PrefixVertexFinderxAODBaseName(False)

        BTagConf.doNotCheckForTaggerObstacles()
        from BTagging.BTaggingConf import Analysis__StandAloneJetBTaggerAlg as StandAloneJetBTaggerAlg

        btag = "BTagging_"
        AuthorSubString = [ btag+name[:-4] for name in JetCollectionList]
        for i, jet in enumerate(JetCollectionList):
            try:
                btagger = BTagConf.setupJetBTaggerTool(ToolSvc, JetCollection=jet[:-4],
                                                       AddToToolSvc=True, SetupScheme="Retag",
                                                       TaggerList = ['IP2D', 'IP3D', 'MultiSVbb1',  'MultiSVbb2', 'SV1', 'JetFitterNN', 'SoftMu', 'MV2c10', 'MV2c10mu', 'MV2c10rnn', 'JetVertexCharge', 'MV2c100', 'MV2cl100' , 'DL1', 'DL1rnn', 'DL1mu', 'RNNIP'])
                SAbtagger = StandAloneJetBTaggerAlg(name=SA + AuthorSubString[i].lower(),
                                          JetBTaggerTool=btagger,
                                          JetCollectionName = jet,
                                          )

                topSequence += SAbtagger
            except AttributeError as error:
                print '#BTAG# --> ' + str(error)
                print '#BTAG# --> ' + jet
                print '#BTAG# --> ' + AuthorSubString[i]
# JetCollections = copy.deepcopy(JetCollectionExKtSubJetList)
# _taggerList = defaultTaggers
# include("RetagFragment_ExKt.py")
# #########################################################
# ### Second round of b-tagging on exkt parent jet only ###
# #########################################################
# JetCollections = copy.deepcopy(JetCollections_BeforeBTag)
# _taggerList = defaultTaggers + specialTaggers
# include("RetagFragment_ExKt.py")

# JetCollections = JetCollections_BeforeBTag

if doRetag:

  from BTagging.BTaggingConfiguration import getConfiguration
  btag_conf = getConfiguration()

  # Stuff from Dan: dump more information on vertices
  # replace JetFitter
  # TODO: figure out if this is running,
  #       and how to get the resulting vertices
  from BTagging.BTaggingConfiguration import cloneToolCollection, getToolCollections
  jfname = ("JetFitterCollection", "DG")
  cloneToolCollection(*jfname)
  for jc_long in JetCollections:
    jc = jc_long[:-4]
    btag_conf.addTool('JetFitterTagNNDG', ToolSvc, "BTagTrackToJetAssociator",jc)
    jfvx = btag_conf.getTool("NewJetFitterVxFinderDG", "BTagTrackToJetAssociator",jc)
    jfvx.VertexClusteringProbabilityCut = 1.0
    apple = btag_conf.getJetCollectionSecVertexingTool(jc)
    print "DANTAGGING!", jc
Exemplo n.º 3
0
    def buildModifiers(self, modifiersin, finder, getters, altname, output,
                       calibOpt):
        from GaudiKernel.Proxy.Configurable import ConfigurableAlgTool
        from JetRec.JetRecConf import JetFinder
        outmods = []
        inmods = self.getModifiers(modifiersin, altname)
        ncalib = 0
        for mod in inmods:
            jetlog.info(self.prefix + "Adding modifier " + str(mod))
            mod0 = ""
            # Split mod = a:b:c... into mod0="a" and modarr = [a, b, c, ...]
            if type(mod) == str:
                if len(mod) == 0: continue
                modarr = mod.split(":")
                mod0 = modarr[0]
            # Fully configured tool.
            if isinstance(mod, ConfigurableAlgTool):
                self.msg(2, "  Adding modifier " + mod.name())
                outmods += [mod]
            # Add jet calibration:
            #   calib:XXX:CALIB - Applies calibration sequence XXX (see JetRecCalibrationFinder)
            #                     using JetCalibrationTool with configuration (or key) CONFIG.
            elif mod0 == "calib":
                ncalib += 1
                alg = finder.JetAlgorithm
                rad = finder.JetRadius
                get = getters[0]
                inp = get.Label
                copt = calibOpt
                if type(calibOpt) == str and len(calibOpt):
                    calargs = calibOpt.split(":")
                else:
                    calargs = modarr[1:]
                if len(calargs) == 0:
                    copt = jetFlags.defaultCalibOpt
                    if type(copt) == str and len(copt):
                        calargs = copt.split(":")
                    else:
                        jetlog.info(
                            self.prefix +
                            'ERROR: If the modifier "calib" is used, then calibOpt or jetFlags.CalibOpt must be a non-blank string.'
                        )
                        jetlog.info(
                            self.prefix +
                            'ERROR: Another alternative is to use the modifier string format "calib:<OPT>", e.g. "calib:a"'
                        )
                        raise Exception
                if len(calargs) == 0 or calargs[0] == "":
                    jetlog.info(self.prefix +
                                "ERROR: Calibration requested without option.")
                    jetlog.info(
                        self.prefix +
                        "       Add calibOpt to tool string, jet build command or to jetFlags.defaultCalibOpt"
                    )
                    raise Exception
                seq = calargs[0]
                if seq == "none":
                    jetlog.info(self.prefix + "Skipping calibration.")
                    continue
                config = ""
                evsprefix = "Kt4"
                if len(calargs) > 1:
                    config = calargs[1]
                if len(calargs) > 2:
                    evsprefix = calargs[2]
                self.msg(
                    0, "  Adding " + seq + " calibration for " + alg + " R=" +
                    str(rad) + " " + inp)
                self.msg(0, "  Configuration key/file: " + config)
                self.msg(0, "  Event shape prefix: " + evsprefix)
                from JetRec.JetRecCalibrationFinder import jrcf
                calmod = jrcf.find(alg, rad, inp, seq, config, evsprefix)
                jetlog.info(self.prefix + "Adding calib modifier " +
                            str(calmod))
                outmods += [calmod]
            # truthassoc - Does truth jet association replacing the input name with "Truth"
            elif mod == "truthassoc":
                sinp = getters[0].Label.split("Origin")[0]
                salg = finder.JetAlgorithm
                srad = str(int(10 * finder.JetRadius))
                cname = output.replace(sinp, "Truth")
                if cname == output:
                    jetlog.info(sinp, cname, output)
                    raise TypeError
                # Check that the building of the association tool has been scheduled.
                if not cname in self.jetcons:
                    jetlog.info(
                        self.prefix +
                        "Truth association skipped because container is missing: "
                        + cname)
                    jetlog.info(
                        self.prefix +
                        "Add to jetcons if input stream is expected to have this."
                    )
                tname = mod + "_" + salg + srad
                if not tname in self.tools:
                    from JetMomentTools.JetMomentToolsConf import JetPtAssociationTool
                    self += JetPtAssociationTool(tname,
                                                 InputContainer=cname,
                                                 AssociationName="GhostTruth")
                outmods += [self.tools[tname]]
            # trackassoc - Does track jet association replacing the input name with "Track"
            elif mod == "trackassoc":
                sinp = getters[0].Label.split("Origin")[0]
                salg = finder.JetAlgorithm
                srad = str(int(10 * finder.JetRadius))
                cname = output.replace(sinp, "PV0Track")
                if cname == output:
                    jetlog.info(sinp, cname, output)
                    raise TypeError
                # Check that the building of the association tool has been scheduled.
                if not cname in self.jetcons:
                    jetlog.info(
                        self.prefix +
                        "Track association skipped because container is missing: "
                        + cname)
                    jetlog.info(
                        self.prefix +
                        "Add to jetcons if input stream is expected to have this."
                    )
                else:
                    tname = mod + "_" + salg + srad
                    if not tname in self.tools:
                        from JetMomentTools.JetMomentToolsConf import JetPtAssociationTool
                        self += JetPtAssociationTool(
                            tname,
                            InputContainer=cname,
                            AssociationName="GhostTrack")
                    outmods += [self.tools[tname]]
            # jetfilter - Filter to remove jets with pT < self.ptminFilter
            elif mod == "jetfilter":
                if self.ptminFilter <= 0:
                    jetlog.info(self.prefix +
                                "Jet filter requested without a threshold.")
                    raise Exception
                tname = "jetpt" + str(self.ptminFilter)
                if not tname in self.tools:
                    from JetRec.JetRecConf import JetFilterTool
                    self.add(JetFilterTool(tname, PtMin=self.ptminFilter))
                outmods += [self.tools[tname]]
            # btag - btagging
            elif mod == "btag":
                from BTagging.BTaggingConfiguration import getConfiguration
                ConfInstance = getConfiguration()
                from AthenaCommon.AppMgr import ToolSvc
                sinp = getters[0].Label
                salg = finder.JetAlgorithm
                srad = str(int(10 * finder.JetRadius))
                bspec = salg + srad + sinp
                jetlog.info(self.prefix + "Scheduling btagging for " + bspec)
                btagger = ConfInstance.setupJetBTaggerTool(ToolSvc, bspec)
                jetlog.info(btagger)
                self.add(btagger)
                outmods += [btagger]
            elif mod == "largeR":
                outmods += jtm.modifiersMap["largeR"]
            else:
                raise TypeError
        # Check calibration.
        if calibOpt != "":
            if ncalib == 0:
                jetlog.info(self.prefix + "Calibration option (" + calibOpt +
                            ") provided without any calibration modifiers.")
            elif ncalib > 1:
                jetlog.info(self.prefix + "Calibration option (" + calibOpt +
                            ") provided with multiple calibration modifiers.")
                raise Exception

        return outmods
# -- for calibration from COOL
from BTagging.BTaggingFlags import BTaggingFlags
include("JetTagCalibration/BTagCalibrationBroker_Trig_jobOptions.py")
BTagCalibrationBrokerTool_Trig.folders[:] = [
]  # Wipe folders; these will be dynamically filled by the configuration code
from BTagging.BTaggingConfiguration import getConfiguration
ConfInst = getConfiguration("Trig")
ConfInst.registerTool("BTagCalibrationBrokerTool",
                      BTagCalibrationBrokerTool_Trig)

# NOTE: The reason for this file is that we want to be able to set up a default configuration when requested by a Python function. However for some reason if we include JetTagCalibration/BTagCalibrationBroker_jobOptions.py at that location then the BTagCalibrationBrokerTool name will not be accessible afterwards, and we need to be able to register it. This file is included from BTaggingConfiguration_LoadTools.py.
Exemplo n.º 5
0
# -- for calibration from COOL
from BTagging.BTaggingFlags import BTaggingFlags
include("JetTagCalibration/BTagCalibrationBroker_jobOptions.py")
BTagCalibrationBrokerTool.taggers[:] = [
]  # Wipe folders; these will be dynamically filled by the configuration code
from BTagging.BTaggingConfiguration import getConfiguration
ConfInst = getConfiguration()
ConfInst.registerTool("BTagCalibrationBrokerTool", BTagCalibrationBrokerTool)

# NOTE: The reason for this file is that we want to be able to set up a default configuration when requested by a Python function. However for some reason if we include JetTagCalibration/BTagCalibrationBroker_jobOptions.py at that location then the BTagCalibrationBrokerTool name will not be accessible afterwards, and we need to be able to register it. This file is included from BTaggingConfiguration_LoadTools.py.
Exemplo n.º 6
0
  def buildModifiers(self, modifiersin, finder, getters, altname, output, calibOpt):
    from GaudiKernel.Proxy.Configurable import ConfigurableAlgTool
    from JetRec.JetRecConf import JetFinder
    outmods = []
    inmods = self.getModifiers(modifiersin, altname)
    ncalib = 0
    for mod in inmods:
      print self.prefix + "Adding modifier " + str(mod)
      mod0 = ""
      # Split mod = a:b:c... into mod0="a" and modarr = [a, b, c, ...]
      if type(mod) == str:
        if len(mod) == 0: continue
        modarr = mod.split(":")
        mod0 = modarr[0]
      # Fully configured tool.
      if isinstance(mod, ConfigurableAlgTool):
        self.msg(2, "  Adding modifier " + mod.name())
        outmods += [mod]
      # Add jet calibration:
      #   calib:XXX:CALIB - Applies calibration sequence XXX (see JetRecCalibrationFinder)
      #                     using JetCalibrationTool with configuration (or key) CONFIG.
      elif mod0 == "calib":
        ncalib += 1
        alg = finder.JetAlgorithm
        rad = finder.JetRadius
        get = getters[0]
        inp = get.Label
        copt = calibOpt
        if type(calibOpt)==str and len(calibOpt):
          calargs = calibOpt.split(":")
        else:
          calargs = modarr[1:]
        if len(calargs) == 0:
          copt = jetFlags.defaultCalibOpt
          if type(copt)==str and len(copt):
            calargs = copt.split(":")
          else:
            print self.prefix + 'ERROR: If the modifier "calib" is used, then calibOpt or jetFlags.CalibOpt must be a non-blank string.'
            print self.prefix + 'ERROR: Another alternative is to use the modifier string format "calib:<OPT>", e.g. "calib:a"'
            raise Exception
        if len(calargs) == 0 or calargs[0]=="":
          print self.prefix + "ERROR: Calibration requested without option."
          print self.prefix + "       Add calibOpt to tool string, jet build command or to jetFlags.defaultCalibOpt"
          raise Exception
        seq = calargs[0]
        if seq == "none":
          print self.prefix + "Skipping calibration."
          continue
        config = ""
        evsprefix = "Kt4"
        if len(calargs) > 1:
          config = calargs[1]
        if len(calargs) > 2:
          evsprefix = calargs[2]
        self.msg(0, "  Adding " + seq + " calibration for " + alg + " R=" + str(rad) + " " + inp)
        self.msg(0, "  Configuration key/file: " + config)
        self.msg(0, "  Event shape prefix: " + evsprefix)
        from JetRec.JetRecCalibrationFinder import jrcf
        calmod = jrcf.find(alg, rad, inp, seq, config, evsprefix)
        print self.prefix + "Adding calib modifier " + str(calmod)
        outmods += [calmod]
      # truthassoc - Does truth jet association replacing the input anme with "Truth"
      elif mod == "truthassoc":
        sinp = getters[0].Label
        salg = finder.JetAlgorithm
        srad = str(int(10*finder.JetRadius))
        cname = output.replace(sinp, "Truth")
        if cname == output:
            print sinp, cname, output
            raise TypeError
        # Check that the building of the association tool has been scheduled.
        if not cname in self.jetcons:
          print self.prefix + "Truth association skipped because container is missing: " + cname
          print self.prefix + "Add to jetcons if input stream is expected to have this."
        tname = mod + "_" + salg + srad
        if not tname in self.tools:
          from JetMomentTools.JetMomentToolsConf import JetPtAssociationTool
          self += JetPtAssociationTool(tname, InputContainer=cname, AssociationName="GhostTruth")
        outmods += [self.tools[tname]]
      # trackassoc - Does track jet association replacing the input name with "Track"
      elif mod == "trackassoc":
        sinp = getters[0].Label
        salg = finder.JetAlgorithm
        srad = str(int(10*finder.JetRadius))
        cname = output.replace(sinp, "PV0Track")
        if cname == output:
            print sinp, cname, output
            raise TypeError
        # Check that the building of the association tool has been scheduled.
        if not cname in self.jetcons:
          print self.prefix + "Track association skipped because container is missing: " + cname
          print self.prefix + "Add to jetcons if input stream is expected to have this."
        else:
          tname = mod + "_" + salg + srad
          if not tname in self.tools:
            from JetMomentTools.JetMomentToolsConf import JetPtAssociationTool
            self += JetPtAssociationTool(tname, InputContainer=cname, AssociationName="GhostTrack")
          outmods += [self.tools[tname]]
      # jetfilter - Filter to remove jets with pT < self.ptminFilter
      elif mod == "jetfilter":
        if self.ptminFilter <= 0:
          print self.prefix + "Jet filter requested without a threshold."
          raise Exception
        tname = "jetpt" + str(self.ptminFilter)
        if not tname in self.tools:
          from JetRec.JetRecConf import JetFilterTool
          self.add( JetFilterTool(tname, PtMin=self.ptminFilter) ) 
        outmods += [self.tools[tname]]
      # btag - btagging
      elif mod == "btag":
        from BTagging.BTaggingConfiguration import getConfiguration
        ConfInstance = getConfiguration()
        from AthenaCommon.AppMgr import ToolSvc 
        sinp = getters[0].Label
        salg = finder.JetAlgorithm
        srad = str(int(10*finder.JetRadius))
        bspec = salg + srad + sinp
        print self.prefix + "Scheduling btagging for " + bspec
        btagger = ConfInstance.setupJetBTaggerTool(ToolSvc, bspec)
        print btagger
        self.add(btagger)
        outmods += [btagger]
      elif mod == "largeR":
        outmods += jtm.modifiersMap["largeR"]
      else:
        raise TypeError
    # Check calibration.
    if calibOpt != "":
      if ncalib==0:
        print self.prefix + "Calibration option (" + calibOpt + ") provided without any calibration modifiers."
      elif ncalib > 1:
        print self.prefix + "Calibration option (" + calibOpt + ") provided with multiple calibration modifiers."
        raise Exception

        
    return outmods
Exemplo n.º 7
0
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration

from TrigBjetHypo.TrigBjetHypoConf import TrigGSCFex
#from TrigBjetHypo.TrigGSCFexTuning import *

from AthenaCommon.Logging import logging
from AthenaCommon.SystemOfUnits import mm, GeV  #commented here

from AthenaCommon.AppMgr import ToolSvc
from BTagging.BTaggingFlags import BTaggingFlags  #commented here
from BTagging.BTaggingConfiguration import getConfiguration  #commented here
BTagConfig = getConfiguration("Trig")  #commented here
BTagConfig.PrefixxAODBaseName(False)  #commented here
BTagConfig.PrefixVertexFinderxAODBaseName(False)  #commented here
BTagConfigSetupStatus = BTagConfig.setupJetBTaggerTool(
    ToolSvc,
    "AntiKt4EMTopo",
    SetupScheme="Trig",
    TaggerList=BTaggingFlags.TriggerTaggers)  #commented here
from JetRec.JetRecCalibrationFinder import jrcf
JetConfigSetupStatus = True

# johns hack
from JetCalibTools.JetCalibToolsConf import JetCalibrationTool


def getGSCFexInstance(instance):
    return GSCFex(instance=instance, name="EFGSCFex_EFID")


def getGSCFexSplitInstance(instance):
Exemplo n.º 8
0
# -- for calibration from COOL
from BTagging.BTaggingFlags import BTaggingFlags
include("JetTagCalibration/BTagCalibrationBroker_AODFix_jobOptions.py")
BTagCalibrationBrokerTool_AODFix.folders[:] = [
]  # Wipe folders; these will be dynamically filled by the configuration code
from BTagging.BTaggingConfiguration import getConfiguration
ConfInst = getConfiguration("AODFix")
ConfInst.registerTool("BTagCalibrationBrokerTool",
                      BTagCalibrationBrokerTool_AODFix)

# NOTE: The reason for this file is that we want to be able to set up a default configuration when requested by a Python function. However for some reason if we include JetTagCalibration/BTagCalibrationBroker_jobOptions.py at that location then the BTagCalibrationBrokerTool name will not be accessible afterwards, and we need to be able to register it. This file is included from BTaggingConfiguration_LoadTools.py.
Exemplo n.º 9
0
def Initiate(ConfInstance=None):
  """Sets up the basic global tools required for B-Tagging. This function is idempotent; it will not run again if it has run once. It is
  typically called by other functions in this file to make sure the basic global tools exist.

  The function returns True if B-Tagging is initialized or has been before. It returns False if it B-Tagging has been switched off for various
  reasons (these are checked in the checkFlagsUsingBTaggingFlags function).

  If the B-tagging calibration broker has been registered we assume initiation has already been performed; this allows users to setup their own initiation code."""

  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  if ConfInstance._Initialized:
    return True

  from AtlasGeoModel.CommonGMJobProperties import CommonGeometryFlags as commonGeoFlags
  from AtlasGeoModel.InDetGMJobProperties import InDetGeometryFlags as geoFlags
  from IOVDbSvc.CondDB import conddb
  # Declare the COOL folder to the CondInputLoader
  btagrun1=False
  if conddb.dbdata == 'COMP200':
    btagrun1=True
  elif conddb.isMC:
    # The Run() parameter only exists for ATLAS-R1(...) and ATLAS-R2(...) geo tags,
    # not for ATLAS-GEO(...) and ATLAS-IBL(...) ones. Hence if Run() is undefined,
    # presence of IBL is used to switch between Run1/Run2
    btagrun1 = (commonGeoFlags.Run() == "RUN1" or (commonGeoFlags.Run() == "UNDEFINED" and geoFlags.isIBL() == False))
  if (btagrun1):
    print (ConfInstance.BTagTag()+' - INFO - Setting up Run 1 configuration')
    BTaggingFlags.JetFitterNN=True
    BTaggingFlags.SV2    =True
    BTaggingFlags.JetVertexCharge=False
    BTaggingFlags.SoftMu=False
    BTaggingFlags.MV2c10mu=False
    BTaggingFlags.MV2c10rnn=False
    BTaggingFlags.MV2cl100=False
    BTaggingFlags.RNNIP=False
    BTaggingFlags.DL1=False
    BTaggingFlags.DL1mu=False
    BTaggingFlags.DL1rnn=False
  else:
    print (ConfInstance.BTagTag()+' - INFO - Setting up Run 2 configuration')

  if ConfInstance._name == "Trig":
    BTaggingFlags.MV2c20=True

  print (ConfInstance.BTagTag()+' - INFO - Initializing default basic tools')

  if ConfInstance.checkFlagsUsingBTaggingFlags():

    #Print the flags
    BTaggingFlags.Print()

    #If debugging do a check of the tool collection structure
    if(BTaggingFlags.OutputLevel < 3):
      from BTagging.BTaggingConfiguration import checkToolCollectionStructure
      checkToolCollectionStructure()

    #Get TheTruthCollectionKey from input
    TheTruthCollectionKey = 'TruthEvents'
    BTaggingFlags.RetagJets = BTaggingFlags.Jets
    if BTaggingFlags.AutoInspectInputFile:
      from AthenaCommon.GlobalFlags import globalflags
      if globalflags.InputFormat == 'pool':
        try:
          from RecExConfig.InputFilePeeker import inputFileSummary
          BTaggingFlags.RetagJets = []
          for i in inputFileSummary['eventdata_items']:
            if i[0] == 'McEventCollection':
              # TheTruthCollectionKey = i[1] # disable taking the name from the input file?
              pass
            elif i[0] == 'JetCollection':
              jetC1 = (i[1]).replace('AODJets','')
              jetC = jetC1.replace('Jets','')
              if jetC in BTaggingFlags.Jets:
                BTaggingFlags.RetagJets += [ jetC ]
        except Exception:
          print (ConfInstance.BTagTag()+' - WARNING - Automatic inspection of input file failed (file too old?)')
          import traceback
          traceback.print_exc()

    print (ConfInstance.BTagTag()+' - Using ', TheTruthCollectionKey, ' as truth key')
#    print (ConfInstance.BTagTag()+' - Re-tagging these jet collections: ', BTaggingFlags.RetagJets)

    #
    # ============ Setup basic services
    #
    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
    if not hasattr(svcMgr, 'THistSvc'):
      from GaudiSvc.GaudiSvcConf import THistSvc
      svcMgr += THistSvc()
    if not 'topSequence' in dir():
      from AthenaCommon.AlgSequence import AlgSequence
      topSequence = AlgSequence()


    #Create and add our condition algorithm to the Condition Sequencer

    SetupConditionAlgorithm(ConfInstance)

    #
    # ========== Add tools now
    #

    # -------------- Calibration Broker --------------
    from AthenaCommon.AppMgr import ToolSvc
    from AthenaCommon.Resilience import treatException,protectedInclude
    if ConfInstance._name == "" or ConfInstance._name == "Trig":
      # No calibration broker setup - The condition algorithm is used
      pass
    elif ConfInstance._name == "AODFix":
      protectedInclude("BTagging/BTagCalibBroker_AODFix_jobOptions.py")
      BTagCalibrationBrokerTool = ConfInstance.getTool("BTagCalibrationBrokerTool")
    else:
      print (ConfInstance.BTagTag()+' - ERROR - Configuration instance "'+ConfInstance._name+'" has no calibration broker setup specified!')
      raise RuntimeError
    # -------------- \Calibration Broker --------------

    # -- for reference mode:
    if BTaggingFlags.Runmodus == 'reference':

      svcMgr.THistSvc.Output += ["RefFile DATAFILE='BTagCalibALL.root' OPT='RECREATE'"]

    ConfInstance._Initialized = True
    return True
  else:
    print (ConfInstance.BTagTag()+' - WARNING - Tool initialization requested but B-Tagging is not possible for the current dataset.')
    return False
Exemplo n.º 10
0
def SetupJetCollection(JetCollection, TaggerList=[], SetupScheme="Default", ConfInstance=None):
  """General function which can setup up a default B-Tagging configuration. Returns True if successful. Returns False if B-Tagging has
  been disabled for some reason. Also calls Initiate if needed. The function does nothing (and returns True) if a configuration for a given
  jet collection already exists; therefore the function is idempotent.

  The TaggerList holds a list of BTaggingFlags tagger names. Only these will be set up. If left empty the default taggers will be used instead.
  Note that if an unlisted tagger is a prerequisite of another tagger which is listed it will be set up nonetheless.

  The specific setup used depends on SetupScheme. This allows us to support multiple different default setup which can be easily set by users."""
  from BTagging.BTaggingConfiguration import taggerIsPossible
  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  print(ConfInstance.BTagTag()+" - INFO - Setting up b-tagging for jet collection '"+JetCollection+"' using scheme: "+SetupScheme)
  if len(TaggerList) == 0:
    print(ConfInstance.BTagTag()+" - INFO - Using default taggers.")
  else:
    print(ConfInstance.BTagTag()+" - INFO - Using the following taggers: "+str(TaggerList))
  if not Initiate(ConfInstance):
    # If initiation fails; return False
    print(ConfInstance.BTagTag()+" - ERROR - Basic initialization failed; disabling b-tagging!")
    return False
  if ConfInstance.jetCollectionExists(JetCollection):
    if SetupScheme != "Default":
      print(ConfInstance.BTagTag()+" - WARNING - Requesting setup of jet collection '"+JetCollection+"' with non-default scheme '"+SetupScheme+"' but")
      print(ConfInstance.BTagTag()+" - WARNING - there is already a configuration for this jet collection. This scheme will therefore be ignored.")
    elif len(TaggerList) > 0:
      print(ConfInstance.BTagTag()+" - WARNING - Requesting setup of jet collection '"+JetCollection+"' with non-default list of taggers, but")
      print(ConfInstance.BTagTag()+" - WARNING - there is already a configuration for this jet collection. This list will therefore be ignored.")
    else:
      if BTaggingFlags.OutputLevel < 3:
        print(ConfInstance.BTagTag()+" - DEBUG - SetupJetCollection called on jet collection which already exists. This is no problem, but any settings")
        print(ConfInstance.BTagTag()+" - DEBUG - you pass to it using this function will be ignored.")
    return True
  ReturnValue = True
  TaggerList = list(TaggerList) # Just in case we might break something
  if len(TaggerList) == 0:
    # Load the default taggers (for now we use BTaggingFlags for this)
    for tagger in BTaggingFlags._tags:
      if BTaggingFlags.IsEnabled(tagger):
        TaggerList.append(tagger)
  ApprovedTaggerList = []
  # Check whether the flags actually this tagger to run
  for tagger in TaggerList:
    if ConfInstance._IgnoreTaggerObstacles:
      ApprovedTaggerList.append(tagger)
    elif taggerIsPossible(tagger):
      ApprovedTaggerList.append(tagger)
  if len(ApprovedTaggerList) == 0:
    print(ConfInstance.BTagTag()+' - WARNING - No taggers specified, or none of them can run with the present settings. Opting out of b-tagging for '+JetCollection)
    print(ConfInstance.BTagTag()+' - WARNING - B-tagging might not function properly!')
    return False
  try:
    exec ('ReturnValue = SetupJetCollection'+SetupScheme+'(JetCollection, ApprovedTaggerList, ConfInstance)')
  except:
    print(ConfInstance.BTagTag()+" - ERROR - Attempted setup for scheme '"+SetupScheme+"' failed! Possibly this scheme does not exist or is improperly implemented!")
    raise
  if not ReturnValue:
    print(ConfInstance.BTagTag()+" - WARNING - A problem has occurred during the execution of SetupJetCollection"+SetupScheme)
    print(ConfInstance.BTagTag()+" - WARNING - B-tagging might not function properly!")
  return ReturnValue
def SetupJetCollectionTrig(JetCollection, TaggerList, ConfInstance = None):
  """Sets up the trigger B-Tagging configuration for jet collection called JetCollection. Returns True if successful. The function does nothing 
  (and returns True) if a configuration for the given jet collection already exists; therefore the function is idempotent.

  TaggerList is a list of taggers (the names coming from BTaggingFlags._tags (see SetupJetCollection() for how the default is filled))."""
  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  from AthenaCommon.AppMgr import ToolSvc

  # -- setup basic b-tagging tool for this jet collection
  # Note that we are not storing this tool on a variable on purpose; there is now a different one per jet collection and therefore
  # subsequent scripts cannot depend on this variable (since it would just hold the last one initialized).
  ConfInstance.addJetCollectionTool(JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3,
                                  options={'BTagLabelingTool'            : ConfInstance.getTool("thisBTagLabeling", JetCollection=JetCollection),
                                           'storeSecondaryVerticesInJet' : BTaggingFlags.writeSecondaryVertices})
  
  # Setup associators
  BTagTrackToJetAssociator = ConfInstance.setupTrackAssociator('BTagTrackToJetAssociator', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SoftMu' in TaggerList or 'SoftMuChi2' in TaggerList:
    BTagMuonToJetAssociator = ConfInstance.setupMuonAssociator('Muons', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
  else:
    BTagMuonToJetAssociator = None
  if 'SoftEl' in TaggerList:
    BTagElectronToJetAssociator = ConfInstance.setupElectronAssociator('Electrons', JetCollection, ToolSvc, 
                                                                     Verbose = BTaggingFlags.OutputLevel < 3,
                                                                     PhotonCollectionName = 'Photons')
  else:
    BTagElectronToJetAssociator = None
  if 'MultiSVbb1' in TaggerList or 'MultiSVbb2' in TaggerList:
    ConfInstance.setupTrackAssociator('BTagTrackToJetAssociatorBB', JetCollection, ToolSvc,
                                    Verbose = BTaggingFlags.OutputLevel < 3,
                                    options={'shareTracks': False,
                                             'useVariableSizedTrackCone' : True,
                                             'coneSizeFitPar1' : 3.15265e-01,
                                             'coneSizeFitPar2' : -3.66502e-01,
                                             'coneSizeFitPar3' : -1.56387e-05})
  
  # NOTE: The secondary vertex finders etc. don't need to be set up here depending on the flags; they are set up when needed by the
  # taggers below.

  # Setup all taggers
      
  if 'IP2D' in TaggerList:
    ConfInstance.addTool('IP2DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP2DNeg' in TaggerList:
    ConfInstance.addTool('IP2DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP3D' in TaggerList:
    ConfInstance.addTool('IP3DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP3DNeg' in TaggerList:
    ConfInstance.addTool('IP3DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV1' in TaggerList:
    ConfInstance.addTool('SV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV1Flip' in TaggerList:
    ConfInstance.addTool('SV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV0' in TaggerList:
    ConfInstance.addTool('SV0Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'MultiSVbb1' in TaggerList:
    ConfInstance.addTool('MultiSVbb1Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MultiSVbb2' in TaggerList:
    ConfInstance.addTool('MultiSVbb2Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'JetFitterNN' in TaggerList:
    ConfInstance.addTool('JetFitterTagNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if 'IP3D' in TaggerList:
      ConfInstance.addTool('JetFitterTagCOMBNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'JetFitterNNFlip' in TaggerList:
    ConfInstance.addTool('JetFitterTagNNFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if 'IP3DNeg' in TaggerList:
      ConfInstance.addTool('JetFitterTagCOMBNNIP3DNeg', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'MV1' in TaggerList:
    ConfInstance.addTool('MV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MVb' in TaggerList:
    ConfInstance.addTool('MVbTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MVbFlip' in TaggerList:
    ConfInstance.addTool('MVbFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1c' in TaggerList:
    ConfInstance.addTool('MV1cTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1cFlip' in TaggerList:
    ConfInstance.addTool('MV1cFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1Flip' in TaggerList:
    ConfInstance.addTool('MV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c00' in TaggerList:
    ConfInstance.addTool('MV2c00Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c00Flip' in TaggerList:
    ConfInstance.addTool('MV2c00FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c10' in TaggerList:
    ConfInstance.addTool('MV2c10Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c10Flip' in TaggerList:
    ConfInstance.addTool('MV2c10FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c20' in TaggerList:
    ConfInstance.addTool('MV2c20Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c20Flip' in TaggerList:
    ConfInstance.addTool('MV2c20FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c100' in TaggerList:
    ConfInstance.addTool('MV2c100Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c100Flip' in TaggerList:
    ConfInstance.addTool('MV2c100FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2m' in TaggerList:
    ConfInstance.addTool('MV2mTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2mFlip' in TaggerList:
    ConfInstance.addTool('MV2mFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'JetVertexCharge' in TaggerList:   #LC FIXME
    ConfInstance.addTool('JetVertexCharge', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if BTaggingFlags.OutputLevel < 3:
    ConfInstance.printAllTools()
      # NOTE: Printing all tools might be excessive; however the adding of future tools might affect the earlier ones; so printing
      # only really makes sense at the end, so we either have to do it each time; or get people to add the print command in their
      # jobOptions. Let us go for the excessive printing in this case; which is only done if debugging anyway.

  # Return True to denote all was successful
  return True
def SetupJetCollectionRetag(JetCollection, TaggerList, ConfInstance = None):
  """Sets up the B-Tagging configuration for jet collection called JetCollection. Returns True if successful. The function does nothing 
  (and returns True) if a configuration for the given jet collection already exists; therefore the function is idempotent.

  This function is meant to be used for retagging, many tools will not be set up, and those that are, will not check for prerequisites.

  TaggerList is a list of taggers (the names coming from BTaggingFlags._tags (see SetupJetCollection() for how the default is filled))."""
  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  from AthenaCommon.AppMgr import ToolSvc

  # -- setup basic b-tagging tool for this jet collection
  # Note that we are not storing this tool on a variable on purpose; there is now a different one per jet collection and therefore
  # subsequent scripts cannot depend on this variable (since it would just hold the last one initialized).
  ConfInstance.addJetCollectionTool(JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3,
                                  options={'BTagLabelingTool'            : ConfInstance.getTool("thisBTagLabeling", JetCollection=JetCollection),
                                           'storeSecondaryVerticesInJet' : BTaggingFlags.writeSecondaryVertices})
  
  # Setup all taggers
      
  # if 'IP2D' in TaggerList:
  #   ConfInstance.addTool('IP2DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'IP2DNeg' in TaggerList:
  #   ConfInstance.addTool('IP2DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'IP3D' in TaggerList:
  #   ConfInstance.addTool('IP3DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'IP3DNeg' in TaggerList:
  #   ConfInstance.addTool('IP3DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'SV1' in TaggerList:
  #   ConfInstance.addTool('SV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'SV1Flip' in TaggerList:
  #   ConfInstance.addTool('SV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'SV0' in TaggerList:
  #   ConfInstance.addTool('SV0Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  # if 'MultiSVbb1' in TaggerList:
  #   ConfInstance.addTool('MultiSVbb1Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'MultiSVbb2' in TaggerList:
  #   ConfInstance.addTool('MultiSVbb2Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  # if 'JetFitterNN' in TaggerList:
  #   ConfInstance.addTool('JetFitterTagNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  #   if 'IP3D' in TaggerList:
  #     ConfInstance.addTool('JetFitterTagCOMBNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                          CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  # if 'JetFitterNNFlip' in TaggerList:
  #   ConfInstance.addTool('JetFitterTagNNFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  #   if 'IP3DNeg' in TaggerList:
  #     ConfInstance.addTool('JetFitterTagCOMBNNIP3DNeg', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                          CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  if 'MV1' in TaggerList:
    ConfInstance.addTool('MV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MVb' in TaggerList:
    ConfInstance.addTool('MVbTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MVbFlip' in TaggerList:
    ConfInstance.addTool('MVbFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV1c' in TaggerList:
    ConfInstance.addTool('MV1cTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV1cFlip' in TaggerList:
    ConfInstance.addTool('MV1cFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV1Flip' in TaggerList:
    ConfInstance.addTool('MV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2c00' in TaggerList:
    ConfInstance.addTool('MV2c00Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2c00Flip' in TaggerList:
    ConfInstance.addTool('MV2c00FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2c10' in TaggerList:
    ConfInstance.addTool('MV2c10Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2c10Flip' in TaggerList:
    ConfInstance.addTool('MV2c10FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2c20' in TaggerList:
    ConfInstance.addTool('MV2c20Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2c20Flip' in TaggerList:
    ConfInstance.addTool('MV2c20FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2c100' in TaggerList:
    ConfInstance.addTool('MV2c100Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2c100Flip' in TaggerList:
    ConfInstance.addTool('MV2c100FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2m' in TaggerList:
    ConfInstance.addTool('MV2mTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV2mFlip' in TaggerList:
    ConfInstance.addTool('MV2mFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'JetVertexCharge' in TaggerList:   #LC FIXME
    ConfInstance.setupMuonAssociator('Muons', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
    ConfInstance.addTool('JetVertexCharge', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  if BTaggingFlags.OutputLevel < 3:
    ConfInstance.printAllTools()
      # NOTE: Printing all tools might be excessive; however the adding of future tools might affect the earlier ones; so printing
      # only really makes sense at the end, so we either have to do it each time; or get people to add the print command in their
      # jobOptions. Let us go for the excessive printing in this case; which is only done if debugging anyway.

  # Return True to denote all was successful
  return True
def SetupJetCollectionDefault(JetCollection, TaggerList, ConfInstance = None):
  """Sets up the default B-Tagging configuration for jet collection called JetCollection. Returns True if successful. The function does nothing 
  (and returns True) if a configuration for the given jet collection already exists; therefore the function is idempotent.

  TaggerList is a list of taggers (the names coming from BTaggingFlags._tags (see SetupJetCollection() for how the default is filled))."""
  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  # IMPORTANT NOTE: Many tools here exist globally, but this is okay; the addTool() function is idempotent; no additional tools will be set up.
  # They will just be registered to the specified jet collection (if not already the case).

  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  # NOTE: If there is any need to have different setup scheme then there is support for this.
  # See the SetupJetCollection() function. Your new function should have the following name:
  # SetupJetCollectionX(JetCollection, TaggerList)
  # where X is the name for your scheme. These functions should return True if all went well
  # and False if something went wrong.
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  # NOTE: Many things are now commented out; these correspond to tools/taggers which
  # are not yet ported to release 19. Maybe they never will. The code is there to be used
  # if a porting attempt is made. Typically the code here should be fine; only the corresponding
  # configuration scripts require an update (BTaggingConfiguration_SomeTagger.py).
  # The associator tools (specifically the lepton one and the one for MultiSV) has not been
  # comment out; their code should still be up to date.
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  from AthenaCommon.AppMgr import ToolSvc

  # -- setup basic b-tagging tool for this jet collection
  # Note that we are not storing this tool on a variable on purpose; there is now a different one per jet collection and therefore
  # subsequent scripts cannot depend on this variable (since it would just hold the last one initialized).
  ConfInstance.addJetCollectionTool(JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3,
                                  options={'BTagLabelingTool'            : ConfInstance.getTool("thisBTagLabeling", JetCollection=JetCollection),
                                           'storeSecondaryVerticesInJet' : BTaggingFlags.writeSecondaryVertices})
  
  # Setup associators
  BTagTrackToJetAssociator = ConfInstance.setupTrackAssociator('BTagTrackToJetAssociator', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SoftMu' in TaggerList or 'SoftMuChi2' in TaggerList:
    BTagMuonToJetAssociator = ConfInstance.setupMuonAssociator('Muons', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
  else:
    BTagMuonToJetAssociator = None
  if 'SoftEl' in TaggerList:
    BTagElectronToJetAssociator = ConfInstance.setupElectronAssociator('Electrons', JetCollection, ToolSvc, 
                                                                     Verbose = BTaggingFlags.OutputLevel < 3,
                                                                     PhotonCollectionName = 'Photons')
  else:
    BTagElectronToJetAssociator = None
  if 'MultiSVbb1' in TaggerList or 'MultiSVbb2' in TaggerList:
    ConfInstance.setupTrackAssociator('BTagTrackToJetAssociatorBB', JetCollection, ToolSvc,
                                    Verbose = BTaggingFlags.OutputLevel < 3,
                                    options={'shareTracks': False,
                                             'useVariableSizedTrackCone' : True,
                                             'coneSizeFitPar1' : 3.15265e-01,
                                             'coneSizeFitPar2' : -3.66502e-01,
                                             'coneSizeFitPar3' : -1.56387e-05})
  
  # NOTE: The secondary vertex finders etc. don't need to be set up here depending on the flags; they are set up when needed by the
  # taggers below.

  # Setup all taggers
      
#          if BTaggingFlags.IP1D:
#            addTool('IP1DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP2D' in TaggerList:
    ConfInstance.addTool('IP2DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DFlip:
#            addTool('IP2DFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DPos:
#            addTool('IP2DPosTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP2DNeg' in TaggerList:
    ConfInstance.addTool('IP2DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DSpc:
#            addTool('IP2DSpcTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DSpcFlip:
#            addTool('IP2DSpcFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DSpcPos:
#            addTool('IP2DSpcPosTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DSpcNeg:
#            addTool('IP2DSpcNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP3D' in TaggerList:
    ConfInstance.addTool('IP3DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DFlip:
#            addTool('IP3DFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DPos:
#            addTool('IP3DPosTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP3DNeg' in TaggerList:
    ConfInstance.addTool('IP3DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DSpc:
#            addTool('IP3DSpcTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DSpcFlip:
#            addTool('IP3DSpcFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DSpcPos:
#            addTool('IP3DSpcPosTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DSpcNeg:
#            addTool('IP3DSpcNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'SV1' in TaggerList:
    ConfInstance.addTool('SV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV2' in TaggerList:
    ConfInstance.addTool('SV2Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV1Flip' in TaggerList:
    ConfInstance.addTool('SV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.SV2:
#            addTool('SV2Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.SV2Flip:
#            addTool('SV2FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV0' in TaggerList:
    ConfInstance.addTool('SV0Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'MultiSVbb1' in TaggerList:
    ConfInstance.addTool('MultiSVbb1Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MultiSVbb2' in TaggerList:
    ConfInstance.addTool('MultiSVbb2Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.MultiSV:
#            # The name of this tagger was misspelled in the old code; I fixed it (Wouter)
#            addTool('MultiSVTag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose =  BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.JetProb:
#            addTool('JetProbTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.JetProbFlip:
#              addTool('JetProbFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.SoftEl:
#            addTool('SoftElectronTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.SoftMu:
#            addTool('SoftMuonTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.SoftMuChi2:
#            addTool('SoftMuonTagChi2', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.BasicJetFitter:
#            addTool('JetFitterTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.IP3D:
#              addTool('JetFitterCOMB', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.JetFitterTag:
#            addTool('NewJetFitterTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.IP3D:
#              addTool('NewJetFitterCOMB', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'JetFitterNN' in TaggerList:
    ConfInstance.addTool('JetFitterTagNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if 'IP3D' in TaggerList:
      ConfInstance.addTool('JetFitterTagCOMBNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.JetFitterTagFlip:
#            addTool('NewJetFitterTagFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.IP3DNeg:
#              addTool('NewJetFitterFlipCOMB', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'JetFitterNNFlip' in TaggerList:
    ConfInstance.addTool('JetFitterTagNNFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.IP3DPos:
#              addTool('JetFitterTagCOMBNNIP3DPos', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if 'IP3DNeg' in TaggerList:
      ConfInstance.addTool('JetFitterTagCOMBNNIP3DNeg', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.TrackCounting:
#            addTool('TrackCounting', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.TrackCountingFlip:
#            addTool('TrackCountingFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
       
#          if BTaggingFlags.GbbNNTag:
#            addTool('GbbNNTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
       
  if 'MV1' in TaggerList:
    ConfInstance.addTool('MV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MVb' in TaggerList:
    ConfInstance.addTool('MVbTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MVbFlip' in TaggerList:
    ConfInstance.addTool('MVbFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1c' in TaggerList:
    ConfInstance.addTool('MV1cTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1cFlip' in TaggerList:
    ConfInstance.addTool('MV1cFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1Flip' in TaggerList:
    ConfInstance.addTool('MV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#  if BTaggingFlags.MV2:
#    addTool('MV2Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c00' in TaggerList:
    ConfInstance.addTool('MV2c00Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c00Flip' in TaggerList:
    ConfInstance.addTool('MV2c00FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c10' in TaggerList:
    ConfInstance.addTool('MV2c10Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c10Flip' in TaggerList:
    ConfInstance.addTool('MV2c10FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c20' in TaggerList:
    ConfInstance.addTool('MV2c20Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c20Flip' in TaggerList:
    ConfInstance.addTool('MV2c20FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c100' in TaggerList:
    ConfInstance.addTool('MV2c100Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2c100Flip' in TaggerList:
    ConfInstance.addTool('MV2c100FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2m' in TaggerList:
    ConfInstance.addTool('MV2mTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV2mFlip' in TaggerList:
    ConfInstance.addTool('MV2mFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'JetVertexCharge' in TaggerList:
    ConfInstance.addTool('JetVertexCharge', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'ExKtbb' in TaggerList:
    ConfInstance.addTool('ExKtbbTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.MV2Flip:
#            addTool('MV2FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  # -- b-tagging tool is now fully configured.

  if BTaggingFlags.OutputLevel < 3:
    ConfInstance.printAllTools()
      # NOTE: Printing all tools might be excessive; however the adding of future tools might affect the earlier ones; so printing
      # only really makes sense at the end, so we either have to do it each time; or get people to add the print command in their
      # jobOptions. Let us go for the excessive printing in this case; which is only done if debugging anyway.

  # Return True to denote all was successful
  return True
def Initiate(ConfInstance=None):
  """Sets up the basic global tools required for B-Tagging. This function is idempotent; it will not run again if it has run once. It is
  typically called by other functions in this file to make sure the basic global tools exist.

  The function returns True if B-Tagging is initialized or has been before. It returns False if it B-Tagging has been switched off for various
  reasons (these are checked in the checkFlagsUsingBTaggingFlags function).

  If the B-tagging calibration broker has been registered we assume initiation has already been performed; this allows users to setup their own initiation code."""

  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  if ConfInstance._Initialized:
    return True
  
  from AtlasGeoModel.InDetGMJobProperties import GeometryFlags as geoFlags
  # The Run() parameter only exists for ATLAS-R1(...) and ATLAS-R2(...) geo tags,
  # not for ATLAS-GEO(...) and ATLAS-IBL(...) ones. Hence if Run() is undefined,
  # presence of IBL is used to switch between Run1/Run2
  if (geoFlags.Run() == "RUN1" or (geoFlags.Run() == "UNDEFINED" and geoFlags.isIBL() == False)):
    print ConfInstance.BTagTag()+' - INFO - Setting up Run 1 configuration'
    BTaggingFlags.JetFitterNN=True
    BTaggingFlags.SV2    =True
    BTaggingFlags.JetFitterCharm=False
    
  if ConfInstance.getTool("BTagCalibrationBrokerTool"):
    print ConfInstance.BTagTag()+' - INFO - BTagCalibrationBrokerTool already exists prior to default initialization; assuming user set up entire initialization him/herself. Note however that if parts of the initalization were not set up, and a later tool requires them, they will be set up at that point automatically with default settings.'
    ConfInstance._Initialized = True
    return True

  print ConfInstance.BTagTag()+' - INFO - Initializing default basic tools'

  if ConfInstance.checkFlagsUsingBTaggingFlags():

    #Print the flags
    BTaggingFlags.Print()

    #If debugging do a check of the tool collection structure
    if(BTaggingFlags.OutputLevel < 3):
      from BTagging.BTaggingConfiguration import checkToolCollectionStructure
      checkToolCollectionStructure()

    #Get TheTruthCollectionKey from input
    TheTruthCollectionKey = 'TruthEvents'
    BTaggingFlags.RetagJets = BTaggingFlags.Jets
    if BTaggingFlags.AutoInspectInputFile:
      from AthenaCommon.GlobalFlags import globalflags
      if globalflags.InputFormat == 'pool':
        try:
          from RecExConfig.InputFilePeeker import inputFileSummary
          BTaggingFlags.RetagJets = []
          for i in inputFileSummary['eventdata_items']:
            if i[0] == 'McEventCollection':
              # TheTruthCollectionKey = i[1] # disable taking the name from the input file?
              pass
            elif i[0] == 'JetCollection':
              jetC1 = (i[1]).replace('AODJets','')
              jetC = jetC1.replace('Jets','')
              if jetC in BTaggingFlags.Jets:
                BTaggingFlags.RetagJets += [ jetC ]
        except Exception, err:
          print ConfInstance.BTagTag()+' - WARNING - Automatic inspection of input file failed (file too old?)'

    print ConfInstance.BTagTag()+' - Using ', TheTruthCollectionKey, ' as truth key'
#    print ConfInstance.BTagTag()+' - Re-tagging these jet collections: ', BTaggingFlags.RetagJets

    #
    # ============ Setup basic services
    #
    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
    if not hasattr(svcMgr, 'THistSvc'):
      from GaudiSvc.GaudiSvcConf import THistSvc
      svcMgr += THistSvc()
    if not 'topSequence' in dir():
      from AthenaCommon.AlgSequence import AlgSequence
      topSequence = AlgSequence()

    # 
    # ========== Add tools now
    #
    
    # -------------- Calibration Broker --------------
    from AthenaCommon.AppMgr import ToolSvc
    from AthenaCommon.Resilience import treatException,protectedInclude
    if ConfInstance._name == "":
      protectedInclude("BTagging/BTagCalibBroker_jobOptions.py") # New file which includes the file from JetCalibration and also registers it via registerTool() so it will be recognized by the various addTool() functions.
      BTagCalibrationBrokerTool = ConfInstance.getTool("BTagCalibrationBrokerTool") # In case this variable is needed
    elif ConfInstance._name == "Trig":
      protectedInclude("BTagging/BTagCalibBroker_Trig_jobOptions.py")
      BTagCalibrationBrokerTool = ConfInstance.getTool("BTagCalibrationBrokerTool")
    else:
      print ConfInstance.BTagTag()+' - ERROR - Configuration instance "'+ConfInstance._name+'" has no calibration broker setup specified!'
      raise RuntimeError
    # -------------- \Calibration Broker --------------
    

    global BTagJetTruthMatching
    global BTagLeptonTruthTool
    global thisBTagLabeling
    # FF: disable cone-based labelling as this is now being done as a part of jet reconstruction
    BTagJetTruthMatching = None
    BTagLeptonTruthTool = None
    thisBTagLabeling = None

    # -- to label jets with truth information
    #from JetRec.JetRecFlags import jetFlags
    #if jetFlags.useTruth():
    #  # Jet Label
    #  if BTaggingFlags.jetTruthMatching == 'matchQuark' or BTaggingFlags.jetTruthMatching == 'jetTrackTruthMatching':
    #    BTagJetTruthMatching = addTool("BTagJetTruthMatching", 
    #                                   ToolSvc = ToolSvc, 
    #                                   Verbose = BTaggingFlags.OutputLevel < 3,
    #                                   options = {'subtype' : BTaggingFlags.jetTruthMatching},
    #                                   SuppressNonCloneWarning=True)        
    #    BTagJetTruthMatching.McEventCollection = TheTruthCollectionKey
    #  else:
    #    BTagJetTruthMatching = None
    #    print("#BTAG# - WARNING - BTaggingFlags.jetTruthMatching has unsupported value!")
    #  # Lepton Truth Match
    #  #BTagLeptonTruthTool = addTool('BTagLeptonTruthTool', ToolSvc = ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
    #  #BTagLeptonTruthTool.McEventCollection = TheTruthCollectionKey
    #  BTagLeptonTruthTool = None # TEMPORARY: BTagLeptonTruthTool not implemented yet?
    #  # Labeling tool
    #  thisBTagLabeling = addTool("thisBTagLabeling", ToolSvc = ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3,
    #                                        options = {'JetTruthMatchTool' : BTagJetTruthMatching,
    #                                                   #'LeptonTruthTool'   : BTagLeptonTruthTool}, TEMPORARY: BTagLeptonTruthTool not implemented yet?
    #                                                   },
    #                                        SuppressNonCloneWarning=True)
    #else:
    #  BTagJetTruthMatching = None
    #  BTagLeptonTruthTool  = None
    #  thisBTagLabeling = None
      # NOTE: These variables no longer serve any purpose, since any tool can be retrieved using getTool

    # -- for reference mode:
    if BTaggingFlags.Runmodus == 'reference':
      
      svcMgr.THistSvc.Output += ["RefFile DATAFILE='BTagCalibALL.root' OPT='RECREATE'"]
      #for key in BTaggingFlags.Jets:
      #  for tagger in ['JetProb','IP1D','IP2D','IP2DSpc','IP3D','IP3DSpc','SV1','SV2','SoftMu','SoftEl','JetFitterTagNN','JetFitterCOMBNN']:
      #    if BTaggingFlags.IsEnabled(tagger):
      #      RefileName = "BTaggingRef"+tagger+key+".root"
      #      svcMgr.THistSvc.Output += ["RefFile"+tagger+key+" DATAFILE='"+RefileName+"' OPT='RECREATE'"]

    ConfInstance._Initialized = True
    return True
def SetupJetCollection(JetCollection, TaggerList=[], SetupScheme="Default", ConfInstance=None):
  """General function which can setup up a default B-Tagging configuration. Returns True if successful. Returns False if B-Tagging has
  been disabled for some reason. Also calls Initiate if needed. The function does nothing (and returns True) if a configuration for a given
  jet collection already exists; therefore the function is idempotent.

  The TaggerList holds a list of BTaggingFlags tagger names. Only these will be set up. If left empty the default taggers will be used instead.
  Note that if an unlisted tagger is a prerequisite of another tagger which is listed it will be set up nonetheless.

  The specific setup used depends on SetupScheme. This allows us to support multiple different default setup which can be easily set by users."""
  from BTagging.BTaggingConfiguration import taggerIsPossible
  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  print(ConfInstance.BTagTag()+" - INFO - Setting up b-tagging for jet collection '"+JetCollection+"' using scheme: "+SetupScheme)
  if len(TaggerList) == 0:
    print(ConfInstance.BTagTag()+" - INFO - Using default taggers.")
  else:
    print(ConfInstance.BTagTag()+" - INFO - Using the following taggers: "+str(TaggerList))
  if not Initiate(ConfInstance):
    # If initiation fails; return False
    print(ConfInstance.BTagTag()+" - ERROR - Basic initialization failed; disabling b-tagging!")
    return False
  if ConfInstance.jetCollectionExists(JetCollection):
    if SetupScheme != "Default":
      print(ConfInstance.BTagTag()+" - WARNING - Requesting setup of jet collection '"+JetCollection+"' with non-default scheme '"+SetupScheme+"' but")
      print(ConfInstance.BTagTag()+" - WARNING - there is already a configuration for this jet collection. This scheme will therefore be ignored.")
    elif len(TaggerList) > 0:
      print(ConfInstance.BTagTag()+" - WARNING - Requesting setup of jet collection '"+JetCollection+"' with non-default list of taggers, but")
      print(ConfInstance.BTagTag()+" - WARNING - there is already a configuration for this jet collection. This list will therefore be ignored.")
    else:
      if BTaggingFlags.OutputLevel < 3:
        print(ConfInstance.BTagTag()+" - DEBUG - SetupJetCollection called on jet collection which already exists. This is no problem, but any settings")
        print(ConfInstance.BTagTag()+" - DEBUG - you pass to it using this function will be ignored.")
    return True
  ReturnValue = True
  TaggerList = list(TaggerList) # Just in case we might break something
  if len(TaggerList) == 0:
    # Load the default taggers (for now we use BTaggingFlags for this)
    for tagger in BTaggingFlags._tags:
      if BTaggingFlags.IsEnabled(tagger):
        TaggerList.append(tagger)
  ApprovedTaggerList = []
  # Check whether the flags actually this tagger to run
  for tagger in TaggerList:
    if ConfInstance._IgnoreTaggerObstacles:
      ApprovedTaggerList.append(tagger)
    elif taggerIsPossible(tagger):
      ApprovedTaggerList.append(tagger)
  if len(ApprovedTaggerList) == 0:
    print(ConfInstance.BTagTag()+' - WARNING - No taggers specified, or none of them can run with the present settings. Opting out of b-tagging for '+JetCollection)
    print(ConfInstance.BTagTag()+' - WARNING - B-tagging might not function properly!')
    return False
  try:
    exec 'ReturnValue = SetupJetCollection'+SetupScheme+'(JetCollection, ApprovedTaggerList, ConfInstance)'
  except:
    print(ConfInstance.BTagTag()+" - ERROR - Attempted setup for scheme '"+SetupScheme+"' failed! Possibly this scheme does not exist or is improperly implemented!")
    raise
  if not ReturnValue:
    print(ConfInstance.BTagTag()+" - WARNING - A problem has occurred during the execution of SetupJetCollection"+SetupScheme)
    print(ConfInstance.BTagTag()+" - WARNING - B-tagging might not function properly!")
  return ReturnValue
Exemplo n.º 16
0
AppendOutputList(jetFlags.jetAODList)
JetAlgFromTools(jtm.HIJetRecs, suffix="HI", persistify=True)
HIJetFlags.IteratedEventShapeKey = cell_level_shape_key

# code cloned from BTagging_jobOptions.py
# to allow b-tagging over HI jets

if HIJetFlags.DoHIBTagging():

    if not BTaggingFlags.DoNotSetupBTagging:  # Temporary measure so the JetRec people can test setting this all up from their side.
        #
        # ========== Load and configure everything
        #

        from BTagging.BTaggingConfiguration import getConfiguration
        ConfInstance = getConfiguration()

        if ConfInstance.checkFlagsUsingBTaggingFlags():

            #Jet collections
            JetCollectionList = ['AntiKt4HIJets']
            from JetRec.JetRecFlags import jetFlags

            BTaggingFlags.Jets = [name[:-4] for name in JetCollectionList]

            #BTagging list
            btag = ConfInstance.getOutputFilesPrefix(
            )  #BTaggingFlags.OutputFilesBTag #"BTagging_"

            #TODO define name author (now BTagging_AntiKt4LCTopo)
            AuthorSubString = [btag + name[:-4] for name in JetCollectionList]
Exemplo n.º 17
0
  # run exactly once; if B-tagging is enabled.
  #
  # DOING SO WILL MAKE THE CODE COMPATIBLE WITH A FUTURE CHANGE IN JETREC
  # WHERE THEY WILL RETRIEVE OUR BTAGGING FUNCTION IF REQUESTED BY A USER.
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# <================= IMPORTANT ==============================================>

import re

if not BTaggingFlags.DoNotSetupBTagging: # Temporary measure so the JetRec people can test setting this all up from their side.
  #
  # ========== Load and configure everything
  #
  
  from BTagging.BTaggingConfiguration import getConfiguration
  ConfInstance = getConfiguration()

  if ConfInstance.checkFlagsUsingBTaggingFlags():

    #Jet collections
    JetCollectionList = ['AntiKt4LCTopoJets', 'AntiKt10LCTopoJets', 'AntiKt4EMTopoJets', 'AntiKt4TrackJets', 'AntiKt3TrackJets', 'AntiKt2TrackJets']
    from JetRec.JetRecFlags import jetFlags
    if jetFlags.useTruth():
      JetCollectionList += [ 'AntiKt10TruthWZJets', 'AntiKt4TruthWZJets' ]

    #WOUTER: Moved these into the BTaggingsFlags.py file.
    #BTaggingFlags.CalibrationChannelAliases += [ "AntiKt4EMTopo->AntiKt4TopoEM" ]
    #BTaggingFlags.CalibrationChannelAliases += [ "AntiKt4LCTopo->AntiKt4LCTopo,AntiKt4TopoEM" ]
    #BTaggingFlags.CalibrationChannelAliases += [ "AntiKt10LCTopo->AntiKt6LCTopo,AntiKt6TopoEM,AntiKt4TopoEM" ]
    #BTaggingFlags.CalibrationChannelAliases += [ "AntiKt10Truth->AntiKt6TopoEM,AntiKt4TopoEM" ]
    #BTaggingFlags.CalibrationChannelAliases += [ "AntiKt10TruthWZ->AntiKt6TopoEM,AntiKt4TopoEM" ]
Exemplo n.º 18
0
def SetupJetCollectionDefault(JetCollection, TaggerList, ConfInstance = None):
  """Sets up the default B-Tagging configuration for jet collection called JetCollection. Returns True if successful. The function does nothing
  (and returns True) if a configuration for the given jet collection already exists; therefore the function is idempotent.

  TaggerList is a list of taggers (the names coming from BTaggingFlags._tags (see SetupJetCollection() for how the default is filled))."""
  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  # IMPORTANT NOTE: Many tools here exist globally, but this is okay; the addTool() function is idempotent; no additional tools will be set up.
  # They will just be registered to the specified jet collection (if not already the case).

  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  # NOTE: If there is any need to have different setup scheme then there is support for this.
  # See the SetupJetCollection() function. Your new function should have the following name:
  # SetupJetCollectionX(JetCollection, TaggerList)
  # where X is the name for your scheme. These functions should return True if all went well
  # and False if something went wrong.
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  # NOTE: Many things are now commented out; these correspond to tools/taggers which
  # are not yet ported to release 19. Maybe they never will. The code is there to be used
  # if a porting attempt is made. Typically the code here should be fine; only the corresponding
  # configuration scripts require an update (BTaggingConfiguration_SomeTagger.py).
  # The associator tools (specifically the lepton one and the one for MultiSV) has not been
  # comment out; their code should still be up to date.
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  from AthenaCommon.AppMgr import ToolSvc

  # -- setup basic b-tagging tool for this jet collection
  # Note that we are not storing this tool on a variable on purpose; there is now a different one per jet collection and therefore
  # subsequent scripts cannot depend on this variable (since it would just hold the last one initialized).
  ConfInstance.addJetCollectionTool(JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3,
                                  options={ 'storeSecondaryVerticesInJet' : BTaggingFlags.writeSecondaryVertices})

  # Setup associators
  BTagTrackToJetAssociator = ConfInstance.setupTrackAssociator(
                                  'BTagTrackToJetAssociator'
                                , JetCollection
                                , ToolSvc
                                , Verbose = BTaggingFlags.OutputLevel < 3
                                )


  if 'SoftMu' in TaggerList or 'SoftMuChi2' in TaggerList:
    BTagMuonToJetAssociator = ConfInstance.setupMuonAssociator('Muons', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
  else:
    BTagMuonToJetAssociator = None
  if 'MultiSVbb1' in TaggerList or 'MultiSVbb2' in TaggerList:
    ConfInstance.setupTrackAssociator('BTagTrackToJetAssociatorBB', JetCollection, ToolSvc,
                                    Verbose = BTaggingFlags.OutputLevel < 3,
                                    options={'shareTracks': False,
                                             'useVariableSizedTrackCone' : True,
                                             'coneSizeFitPar1' : 3.15265e-01,
                                             'coneSizeFitPar2' : -3.66502e-01,
                                             'coneSizeFitPar3' : -1.56387e-05})

  # NOTE: The secondary vertex finders etc. don't need to be set up here depending on the flags; they are set up when needed by the
  # taggers below.

  # Setup all taggers

#          if BTaggingFlags.IP1D:
#            addTool('IP1DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP2D' in TaggerList:
    ConfInstance.addTool('IP2DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DFlip:
#            addTool('IP2DFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DPos:
#            addTool('IP2DPosTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP2DNeg' in TaggerList:
    ConfInstance.addTool('IP2DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DSpc:
#            addTool('IP2DSpcTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DSpcFlip:
#            addTool('IP2DSpcFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DSpcPos:
#            addTool('IP2DSpcPosTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP2DSpcNeg:
#            addTool('IP2DSpcNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP3D' in TaggerList:
    ConfInstance.addTool('IP3DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'RNNIP' in TaggerList:
    ConfInstance.addTool('RNNIPTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel)
  if 'RNNIPNeg' in TaggerList:
    ConfInstance.addTool('RNNIPNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel)

#          if BTaggingFlags.IP3DFlip:
#            addTool('IP3DFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DPos:
#            addTool('IP3DPosTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'IP3DNeg' in TaggerList:
    ConfInstance.addTool('IP3DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DSpc:
#            addTool('IP3DSpcTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DSpcFlip:
#            addTool('IP3DSpcFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DSpcPos:
#            addTool('IP3DSpcPosTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.IP3DSpcNeg:
#            addTool('IP3DSpcNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'SV1' in TaggerList:
    ConfInstance.addTool('SV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV2' in TaggerList:
    ConfInstance.addTool('SV2Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV1Flip' in TaggerList:
    ConfInstance.addTool('SV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.SV2:
#            addTool('SV2Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.SV2Flip:
#            addTool('SV2FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV0' in TaggerList:
    ConfInstance.addTool('SV0Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'MultiSVbb1' in TaggerList:
    ConfInstance.addTool('MultiSVbb1Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MultiSVbb2' in TaggerList:
    ConfInstance.addTool('MultiSVbb2Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.MultiSV:
#            # The name of this tagger was misspelled in the old code; I fixed it (Wouter)
#            addTool('MultiSVTag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose =  BTaggingFlags.OutputLevel < 3)

  if 'SoftMu' in TaggerList:
    ConfInstance.addTool('SoftMuonTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.SoftMuChi2:
#            addTool('SoftMuonTagChi2', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.BasicJetFitter:
#            addTool('JetFitterTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.IP3D:
#              addTool('JetFitterCOMB', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.JetFitterTag:
#            addTool('NewJetFitterTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.IP3D:
#              addTool('NewJetFitterCOMB', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'JetFitterNN' in TaggerList:
    ConfInstance.addTool('JetFitterTagNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'JetFitterCOMBNN' in TaggerList:
    ConfInstance.addTool('JetFitterTagCOMBNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.JetFitterTagFlip:
#            addTool('NewJetFitterTagFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.IP3DNeg:
#              addTool('NewJetFitterFlipCOMB', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'JetFitterNNFlip' in TaggerList:
    ConfInstance.addTool('JetFitterTagNNFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#            if BTaggingFlags.IP3DPos:
#              addTool('JetFitterTagCOMBNNIP3DPos', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if 'IP3DNeg' in TaggerList:
      ConfInstance.addTool('JetFitterTagCOMBNNIP3DNeg', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

#          if BTaggingFlags.TrackCounting:
#            addTool('TrackCounting', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
#          if BTaggingFlags.TrackCountingFlip:
#            addTool('TrackCountingFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)


  if 'MV1' in TaggerList:
    ConfInstance.addTool('MV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1c' in TaggerList:
    ConfInstance.addTool('MV1cTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1cFlip' in TaggerList:
    ConfInstance.addTool('MV1cFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'MV1Flip' in TaggerList:
    ConfInstance.addTool('MV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'JetVertexCharge' in TaggerList:
    ConfInstance.addTool('JetVertexCharge', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'ExKtbb_Hbb_MV2Only' in TaggerList:
    ConfInstance.addTool('ExKtbb_Hbb_MV2OnlyTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'ExKtbb_Hbb_MV2andJFDRSig' in TaggerList:
    ConfInstance.addTool('ExKtbb_Hbb_MV2andJFDRSigTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'ExKtbb_Hbb_MV2andTopos' in TaggerList:
    ConfInstance.addTool('ExKtbb_Hbb_MV2andToposTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  #MultivariateTagManager
  #list of mvtm taggers that are also in TaggerList
  mvtm_active_taggers = list(set(mvtm_taggers) & set(TaggerList))
  mvtm_active_flip_taggers = list(set(mvtm_flip_taggers) & set(TaggerList))

  if 'TagNtupleDumper' in TaggerList:
    tag = ConfInstance.addTool('TagNtupleDumper', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    BTaggingFlags.MVTagToolList.append(tag)

  #add all the taggers that use MVTM
  for mvtm_tagger in mvtm_active_taggers:
    tag = ConfInstance.addTool(mvtm_tagger+'Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if tag not in BTaggingFlags.MVTagToolList:
      BTaggingFlags.MVTagToolList.append(tag)

  #add all the flip taggers that use MVTM
  for mvtm_tagger in mvtm_active_flip_taggers:
    tag = ConfInstance.addTool(mvtm_tagger+'Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if tag not in BTaggingFlags.MVFlipTagToolList:
      BTaggingFlags.MVFlipTagToolList.append(tag)

  #set up MVTM if any of its taggers are active
  if (mvtm_active_taggers):
    if 'RNNIP' not in TaggerList:
      BTaggingFlags.MultivariateTagManagerAuxBranches = []
    ConfInstance.addTool('MultivariateTagManager', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  #set up MVTMFlip
  if (mvtm_active_flip_taggers):
    ConfInstance.addTool('MultivariateFlipTagManager', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  # -- b-tagging tool is now fully configured.

  if BTaggingFlags.OutputLevel < 3:
      ConfInstance.printAllTools()
      # NOTE: Printing all tools might be excessive; however the adding of future tools might affect the earlier ones; so printing
      # only really makes sense at the end, so we either have to do it each time; or get people to add the print command in their
      # jobOptions. Let us go for the excessive printing in this case; which is only done if debugging anyway.

  # Return True to denote all was successful
  return True
### VD: this is if you want to re-tag with another calibration file
from BTagging.BTaggingFlags import BTaggingFlags

#### if the new file is already in the datatbase: simple edit the name
###############BTaggingFlags.CalibrationTag = 'BTagCalibRUN12-08-10'

#### if you want to use your own calibration file use this part below
######BTaggingFlags.CalibrationFromLocalReplica = True
######BTaggingFlags.CalibrationFolderRoot = '/GLOBAL/BTagCalib/'
######BTaggingFlags.CalibrationTag = "antonello"
######BTaggingFlags.JetVertexCharge=False

include("RetagFragment.py")
if doRetag:
  from BTagging.BTaggingConfiguration import getConfiguration
  BTagConf = getConfiguration()
  ip3d =BTagConf.getTool("IP3DTag", "BTagTrackToJetAssociator","AntiKt4EMTopo")
  #ip3d.OutputLevel=DEBUG
  ####ip3d.SortingMode="SortZ0D0"
  ####ip3d.NtrkMax=8
  ####ip3d.SignWithSvx=True
  ip3dTrkSel=BTagConf.getTool("IP3DTrackSelector", "BTagTrackToJetAssociator","AntiKt4EMTopo")
  ####ip3dTrkSel.nHitPix=1
  ip3dLH=BTagConf.getTool("IP3DNewLikelihoodTool", "BTagTrackToJetAssociator","AntiKt4EMTopo")
  ip2d  =BTagConf.getTool("IP2DTag", "BTagTrackToJetAssociator","AntiKt4EMTopo")
  ###############################ip2d.SortingMode="SortPt"
  mv2c20 =BTagConf.getTool("MV2c20Tag", "BTagTrackToJetAssociator","AntiKt4EMTopo")
  ###mv2c20.OutputLevel=DEBUG

##########################################################################################################################################################
##########################################################################################################################################################
Exemplo n.º 20
0
def SetupJetCollectionRetag(JetCollection, TaggerList, ConfInstance = None):
  """Sets up the B-Tagging configuration for jet collection called JetCollection. Returns True if successful. The function does nothing
  (and returns True) if a configuration for the given jet collection already exists; therefore the function is idempotent.

  This function is meant to be used for retagging, many tools will not be set up, and those that are, will not check for prerequisites.

  TaggerList is a list of taggers (the names coming from BTaggingFlags._tags (see SetupJetCollection() for how the default is filled))."""
  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()

  from AthenaCommon.AppMgr import ToolSvc

  # -- setup basic b-tagging tool for this jet collection
  # Note that we are not storing this tool on a variable on purpose; there is now a different one per jet collection and therefore
  # subsequent scripts cannot depend on this variable (since it would just hold the last one initialized).
  ConfInstance.addJetCollectionTool(JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3,
                                  options={ 'storeSecondaryVerticesInJet' : BTaggingFlags.writeSecondaryVertices})

  # Setup all taggers

  # if 'IP2D' in TaggerList:
  #   ConfInstance.addTool('IP2DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'IP2DNeg' in TaggerList:
  #   ConfInstance.addTool('IP2DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'IP3D' in TaggerList:
    # We need to setup both BTagTrackToVertexTool and BTagTrackToVertexIPEstimator here since the IP3D setup line
    # has CheckOnlyInsideToolCollection set to True, but these two tools are outside the IP3D tool collection and are needed anyway for IP3D.
    ConfInstance.addTool('BTagTrackToVertexTool', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=False, DoNotSetUpParticleAssociators=True)
    ConfInstance.addTool('BTagTrackToVertexIPEstimator', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=False, DoNotSetUpParticleAssociators=True)
    ConfInstance.addTool('IP3DTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  if 'RNNIP' in TaggerList:
    ConfInstance.addTool('RNNIPTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  # if 'IP3DNeg' in TaggerList:
  #   ConfInstance.addTool('IP3DNegTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'SV1' in TaggerList:
  #   ConfInstance.addTool('SV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'SV1Flip' in TaggerList:
  #   ConfInstance.addTool('SV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'SV0' in TaggerList:
  #   ConfInstance.addTool('SV0Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  # if 'MultiSVbb1' in TaggerList:
  #   ConfInstance.addTool('MultiSVbb1Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  # if 'MultiSVbb2' in TaggerList:
  #   ConfInstance.addTool('MultiSVbb2Tag', ToolSvc, 'BTagTrackToJetAssociatorBB', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  # if 'JetFitterNN' in TaggerList:
  #   ConfInstance.addTool('JetFitterTagNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  #   if 'IP3D' in TaggerList:
  #     ConfInstance.addTool('JetFitterTagCOMBNN', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                          CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  # if 'JetFitterNNFlip' in TaggerList:
  #   ConfInstance.addTool('JetFitterTagNNFlip', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                        CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  #   if 'IP3DNeg' in TaggerList:
  #     ConfInstance.addTool('JetFitterTagCOMBNNIP3DNeg', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
  #                          CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  if 'MV1' in TaggerList:
    ConfInstance.addTool('MV1Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  if 'MV1c' in TaggerList:
    ConfInstance.addTool('MV1cTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV1cFlip' in TaggerList:
    ConfInstance.addTool('MV1cFlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'MV1Flip' in TaggerList:
    ConfInstance.addTool('MV1FlipTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)
  if 'JetVertexCharge' in TaggerList:   #LC FIXME
    #ConfInstance.setupMuonAssociator('Muons', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
    ConfInstance.addTool('JetVertexCharge', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3,
                         CheckOnlyInsideToolCollection=True, DoNotSetUpParticleAssociators=True)

  #MultivariateTagManager
  #list of mvtm taggers that are also in TaggerList
  mvtm_active_taggers = list(set(mvtm_taggers) & set(TaggerList))
  mvtm_active_flip_taggers = list(set(mvtm_flip_taggers) & set(TaggerList))

  #set up MVTM if any of its taggers are active
  if (mvtm_active_taggers):
    MVTM = ConfInstance.addTool('MultivariateTagManager', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if 'RNNIP' in TaggerList:
      MVTM.arbitraryAuxData = BTaggingFlags.MultivariateTagManagerAuxBranches
    else:
      MVTM.arbitraryAuxData=[]

  #set up MVTMFlip
  if (mvtm_active_flip_taggers):
    MVTMFlip = ConfInstance.addTool('MultivariateFlipTagManager', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'TagNtupleDumper' in TaggerList:
    tag = ConfInstance.addTool('TagNtupleDumper', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    MVTM.MVTagToolList.append(tag)

  #add all the taggers that use MVTM
  for mvtm_tagger in mvtm_active_taggers:
    tag = ConfInstance.addTool(mvtm_tagger+'Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if tag not in MVTM.MVTagToolList:
      MVTM.MVTagToolList.append(tag)

  #add all the flip taggers that use MVTM
  for mvtm_tagger in mvtm_active_flip_taggers:
    tag = ConfInstance.addTool(mvtm_tagger+'Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if tag not in MVTMFlip.MVTagToolList:
      MVTMFlip.MVTagToolList.append(tag)

  if BTaggingFlags.OutputLevel < 3:
    ConfInstance.printAllTools()
      # NOTE: Printing all tools might be excessive; however the adding of future tools might affect the earlier ones; so printing
      # only really makes sense at the end, so we either have to do it each time; or get people to add the print command in their
      # jobOptions. Let us go for the excessive printing in this case; which is only done if debugging anyway.

  # Return True to denote all was successful
  return True
# -- for calibration from COOL
from BTagging.BTaggingFlags import BTaggingFlags
include("JetTagCalibration/BTagCalibrationBroker_jobOptions.py")
BTagCalibrationBrokerTool.folders[:] = [] # Wipe folders; these will be dynamically filled by the configuration code
from BTagging.BTaggingConfiguration import getConfiguration
ConfInst = getConfiguration()
ConfInst.registerTool("BTagCalibrationBrokerTool", BTagCalibrationBrokerTool)

# NOTE: The reason for this file is that we want to be able to set up a default configuration when requested by a Python function. However for some reason if we include JetTagCalibration/BTagCalibrationBroker_jobOptions.py at that location then the BTagCalibrationBrokerTool name will not be accessible afterwards, and we need to be able to register it. This file is included from BTaggingConfiguration_LoadTools.py.
Exemplo n.º 22
0
def SetupJetCollectionTrig(JetCollection, TaggerList, ConfInstance = None):
  """Sets up the trigger B-Tagging configuration for jet collection called JetCollection. Returns True if successful. The function does nothing
  (and returns True) if a configuration for the given jet collection already exists; therefore the function is idempotent.

  TaggerList is a list of taggers (the names coming from BTaggingFlags._tags (see SetupJetCollection() for how the default is filled))."""
  if ConfInstance is None:
    from BTagging.BTaggingConfiguration import getConfiguration
    ConfInstance = getConfiguration()
  from AthenaCommon.AppMgr import ToolSvc

  # -- setup basic b-tagging tool for this jet collection
  # Note that we are not storing this tool on a variable on purpose; there is now a different one per jet collection and therefore
  # subsequent scripts cannot depend on this variable (since it would just hold the last one initialized).
  ConfInstance.addJetCollectionTool(JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3,
                                  options={ 'storeSecondaryVerticesInJet' : BTaggingFlags.writeSecondaryVertices})

  # Setup associators
  BTagTrackToJetAssociator = ConfInstance.setupTrackAssociator('BTagTrackToJetAssociator', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'SoftMu' in TaggerList or 'SoftMuChi2' in TaggerList:
    BTagMuonToJetAssociator = ConfInstance.setupMuonAssociator('Muons', JetCollection, ToolSvc, Verbose = BTaggingFlags.OutputLevel < 3)
  else:
    BTagMuonToJetAssociator = None
  if 'MultiSVbb1' in TaggerList or 'MultiSVbb2' in TaggerList:
    ConfInstance.setupTrackAssociator('BTagTrackToJetAssociatorBB', JetCollection, ToolSvc,
                                    Verbose = BTaggingFlags.OutputLevel < 3,
                                    options={'shareTracks': False,
                                             'useVariableSizedTrackCone' : True,
                                             'coneSizeFitPar1' : 3.15265e-01,
                                             'coneSizeFitPar2' : -3.66502e-01,
                                             'coneSizeFitPar3' : -1.56387e-05})

  # NOTE: The secondary vertex finders etc. don't need to be set up here depending on the flags; they are set up when needed by the
  # taggers below.

  # Setup all taggers

  #Now the basic taggers:
  if 'IP2D' in TaggerList:
    ConfInstance.addTool("IP2DTag_Trig", ToolSvc, 'BTagTrackToJetAssociator', JetCollection)
  if 'IP3D' in TaggerList:
    ConfInstance.addTool('IP3DTag_Trig', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  if 'SV1' in TaggerList:
    ConfInstance.addTool('SV1Tag_Trig', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    ConfInstance.addTool('JetFitterTagNN_Trig', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  if 'IP2DTrigHybrid' in TaggerList:
    ConfInstance.addTool('IP2DTrigHybridTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose=BTaggingFlags.OutputLevel < 3)
  if 'IP3DTrigHybrid' in TaggerList:
    ConfInstance.addTool('IP3DTrigHybridTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose=BTaggingFlags.OutputLevel < 3)
  if 'MV2c10TrigHybrid' in TaggerList:
    ConfInstance.addTool('MV2c10TrigHybridTag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose=BTaggingFlags.OutputLevel < 3)

  # Activate MultivariateTagManager if any of its taggers are in TaggerList
  #list of mvtm taggers that are also in TaggerList
  mvtm_active_taggers = list(set(mvtm_taggers) & set(TaggerList))
  mvtm_active_flip_taggers = list(set(mvtm_flip_taggers) & set(TaggerList))
  mvtm_active_trighybrid_taggers = list(set(mvtm_trighybrid_taggers) & set(TaggerList))

  #add all the taggers that use MVTM
  for mvtm_tagger in mvtm_active_taggers:
    tag = ConfInstance.addTool(mvtm_tagger+'Tag_Trig', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if tag not in BTaggingFlags.MVTagToolList:
      BTaggingFlags.MVTagToolList.append(tag)

  #add all the flip taggers that use MVTM
  for mvtm_tagger in mvtm_active_flip_taggers:
    tag = ConfInstance.addTool(mvtm_tagger+'Tag_Trig', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
    if tag not in BTaggingFlags.MVFlipTagToolList:
      BTaggingFlags.MVFlipTagToolList.append(tag)

  #set up MVTM if any of its taggers are active
  if (mvtm_active_taggers):
    if 'RNNIP' not in TaggerList:
      BTaggingFlags.MultivariateTagManagerAuxBranches = []
    MVTM = ConfInstance.addTool('MultivariateTagManager_Trig', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  #set up MVTMFlip
  #if (mvtm_active_flip_taggers):
  #  MVTMFlip = ConfInstance.addTool('MultivariateFlipTagManager_Trig', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)

  #if 'TagNtupleDumper' in TaggerList:
  #  tag = ConfInstance.addTool('TagNtupleDumper', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose = BTaggingFlags.OutputLevel < 3)
  #  MVTM.MVTagToolList.append(tag)

  # set up MVTMHybrid
  if (mvtm_active_trighybrid_taggers):
    MVTMTrigHybrid = ConfInstance.addTool('MultivariateTrigHybridTagManager', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose=BTaggingFlags.OutputLevel < 3)

  # add all the hybrid tuning taggers that use MVTM
  for mvtm_tagger in mvtm_active_trighybrid_taggers:
    tag = ConfInstance.addTool(mvtm_tagger + 'Tag', ToolSvc, 'BTagTrackToJetAssociator', JetCollection, Verbose=BTaggingFlags.OutputLevel < 3)
    if tag not in MVTMTrigHybrid.MVTagToolList:
      MVTMTrigHybrid.MVTagToolList.append(tag)

  if BTaggingFlags.OutputLevel < 3:
    ConfInstance.printAllTools()
      # NOTE: Printing all tools might be excessive; however the adding of future tools might affect the earlier ones; so printing
      # only really makes sense at the end, so we either have to do it each time; or get people to add the print command in their
      # jobOptions. Let us go for the excessive printing in this case; which is only done if debugging anyway.

  # Return True to denote all was successful
  return True
#### if the new file is already in the datatbase: simple edit the name
#BTaggingFlags.CalibrationTag = 'BTagCalibRUN12-08-18'
#### if you want to use your own calibration file use this part below
if RETAG & (LocalCalibSuffix != 'WHATEVER'):
    BTaggingFlags.CalibrationFromLocalReplica = True
    BTaggingFlags.TrigCalibrationFolderRoot = '/GLOBAL/TrigBTagCalib/'
    BTaggingFlags.TrigCalibrationTag = LocalCalibSuffix
#### if you want to use the real actual calibration
#if RETAG:
#    BTaggingFlags.TrigCalibrationFolderRoot = '/GLOBAL/TrigBTagCalib/'
#    BTaggingFlags.TrigCalibrationTag = 'TrigBTagCalibRUN12-08-12'

#BTaggingFlags.Jets = ['AntiKt4EMTopo']

BTagConf = getConfiguration("Trig")
ip3d = BTagConf.getTool("IP3DTag", "BTagTrackToJetAssociator", "AntiKt4EMTopo")
ip3dTrkSel = BTagConf.getTool("IP3DTrackSelector", "BTagTrackToJetAssociator",
                              "AntiKt4EMTopo")
ip3dLH = BTagConf.getTool("IP3DNewLikelihoodTool", "BTagTrackToJetAssociator",
                          "AntiKt4EMTopo")
ip2d = BTagConf.getTool("IP2DTag", "BTagTrackToJetAssociator", "AntiKt4EMTopo")
mv2c20 = BTagConf.getTool("MV2c20Tag", "BTagTrackToJetAssociator",
                          "AntiKt4EMTopo")

BTagConf.PrefixxAODBaseName(False)
BTagConf.PrefixVertexFinderxAODBaseName(False)
BTagConf.doNotCheckForTaggerObstacles()
NotInJetToolManager = []  # For jet collections

btagger = BTagConf.setupJetBTaggerTool(ToolSvc,
Exemplo n.º 24
0
    def other_postSystemRec(self, topSequence):
        """
        Please seperate out this function into multiple functions
        """
        from AthenaCommon.AppMgr import ToolSvc

        if self.isMC:

            from ParticleJetTools.ParticleJetToolsConf import CopyFlavorLabelTruthParticles
            from ParticleJetTools.ParticleJetToolsConf import ParticleJetDeltaRLabelTool

            ptypes = ["TausFinal", "BHadronsFinal", "CHadronsFinal"]
            for ptype in ptypes:
                AODFix_ctp = CopyFlavorLabelTruthParticles(
                    "AODFix_CopyTruthTag" + ptype)
                AODFix_ctp.ParticleType = ptype
                AODFix_ctp.OutputName = "AODFix_TruthLabel" + ptype
                ToolSvc += AODFix_ctp

            AODFix_JetDeltaRLabelTool = ParticleJetDeltaRLabelTool(
                "AODFix_jetdrlabeler",
                LabelName="HadronConeExclTruthLabelID",
                BLabelName="ConeExclBHadronsFinal",
                CLabelName="ConeExclCHadronsFinal",
                TauLabelName="ConeExclTausFinal",
                BParticleCollection="AODFix_TruthLabelBHadronsFinal",
                CParticleCollection="AODFix_TruthLabelCHadronsFinal",
                TauParticleCollection="AODFix_TruthLabelTausFinal",
                PartPtMin=5000.0,
                JetPtMin=0.0,
                DRMax=0.3,
                MatchMode="MinDR")
            ToolSvc += AODFix_JetDeltaRLabelTool

            AODFix_FatJetDeltaRLabelTool = ParticleJetDeltaRLabelTool(
                "AODFix_fatjetdrlabeler",
                LabelName="HadronConeExclTruthLabelID",
                BLabelName="ConeExclBHadronsFinal",
                CLabelName="ConeExclCHadronsFinal",
                TauLabelName="ConeExclTausFinal",
                BParticleCollection="AODFix_TruthLabelBHadronsFinal",
                CParticleCollection="AODFix_TruthLabelCHadronsFinal",
                TauParticleCollection="AODFix_TruthLabelTausFinal",
                PartPtMin=5000.0,
                JetPtMin=0.0,
                DRMax=1.0,
                MatchMode="MinDR")
            ToolSvc += AODFix_FatJetDeltaRLabelTool

            AODFix_TrackJetDeltaRLabelTool = ParticleJetDeltaRLabelTool(
                "AODFix_trackjetdrlabeler",
                LabelName="HadronConeExclTruthLabelID",
                BLabelName="ConeExclBHadronsFinal",
                CLabelName="ConeExclCHadronsFinal",
                TauLabelName="ConeExclTausFinal",
                BParticleCollection="AODFix_TruthLabelBHadronsFinal",
                CParticleCollection="AODFix_TruthLabelCHadronsFinal",
                TauParticleCollection="AODFix_TruthLabelTausFinal",
                PartPtMin=5000.0,
                JetPtMin=4500.0,
                DRMax=0.3,
                MatchMode="MinDR")

            ToolSvc += AODFix_TrackJetDeltaRLabelTool

            from JetRec.JetRecConf import JetRecTool
            JetRecTool_AntiKt4EMTopo = JetRecTool(
                "AODFix_AntiKt4EMTopoJets",
                InputContainer="AntiKt4EMTopoJets",
                OutputContainer="AntiKt4EMTopoJets",
                JetModifiers=[ToolSvc.AODFix_jetdrlabeler])
            ToolSvc += JetRecTool_AntiKt4EMTopo
            JetRecTool_AntiKt4LCTopo = JetRecTool(
                "AODFix_AntiKt4LCTopoJets",
                InputContainer="AntiKt4LCTopoJets",
                OutputContainer="AntiKt4LCTopoJets",
                JetModifiers=[ToolSvc.AODFix_jetdrlabeler])
            ToolSvc += JetRecTool_AntiKt4LCTopo
            JetRecTool_AntiKt10LCTopo = JetRecTool(
                "AODFix_AntiKt10LCTopoJets",
                InputContainer="AntiKt10LCTopoJets",
                OutputContainer="AntiKt10LCTopoJets",
                JetModifiers=[ToolSvc.AODFix_fatjetdrlabeler])
            ToolSvc += JetRecTool_AntiKt10LCTopo
            JetRecTool_AntiKt2PV0Track = JetRecTool(
                "AODFix_AntiKt2PV0TrackJets",
                InputContainer="AntiKt2PV0TrackJets",
                OutputContainer="AntiKt2PV0TrackJets",
                JetModifiers=[ToolSvc.AODFix_trackjetdrlabeler])
            ToolSvc += JetRecTool_AntiKt2PV0Track
            JetRecTool_AntiKt3PV0Track = JetRecTool(
                "AODFix_AntiKt3PV0TrackJets",
                InputContainer="AntiKt3PV0TrackJets",
                OutputContainer="AntiKt3PV0TrackJets",
                JetModifiers=[ToolSvc.AODFix_trackjetdrlabeler])
            ToolSvc += JetRecTool_AntiKt3PV0Track
            JetRecTool_AntiKt4PV0Track = JetRecTool(
                "AODFix_AntiKt4PV0TrackJets",
                InputContainer="AntiKt4PV0TrackJets",
                OutputContainer="AntiKt4PV0TrackJets",
                JetModifiers=[ToolSvc.AODFix_trackjetdrlabeler])
            ToolSvc += JetRecTool_AntiKt4PV0Track

            from JetRec.JetRecConf import JetAlgorithm
            topSequence += JetAlgorithm(
                "jetalgAODFix",
                Tools=[
                    ToolSvc.AODFix_CopyTruthTagCHadronsFinal,
                    ToolSvc.AODFix_CopyTruthTagBHadronsFinal,
                    ToolSvc.AODFix_CopyTruthTagTausFinal,
                    ToolSvc.AODFix_AntiKt2PV0TrackJets,
                    ToolSvc.AODFix_AntiKt3PV0TrackJets,
                    ToolSvc.AODFix_AntiKt4PV0TrackJets,
                    ToolSvc.AODFix_AntiKt4EMTopoJets,
                    ToolSvc.AODFix_AntiKt4LCTopoJets,
                    ToolSvc.AODFix_AntiKt10LCTopoJets
                ])

        JetCollectionList = [
            'AntiKt4EMTopoJets', 'AntiKt4LCTopoJets', 'AntiKt2TrackJets',
            'AntiKt3TrackJets', 'AntiKt4TrackJets'
        ]

        SA = 'AODFix_'
        from BTagging.BTaggingConfiguration import getConfiguration
        BTagConf = getConfiguration("AODFix")
        BTagConf.PrefixxAODBaseName(False)
        BTagConf.PrefixVertexFinderxAODBaseName(False)

        BTagConf.doNotCheckForTaggerObstacles()
        from BTagging.BTaggingConf import Analysis__StandAloneJetBTaggerAlg as StandAloneJetBTaggerAlg

        btag = "BTagging_"
        AuthorSubString = [btag + name[:-4] for name in JetCollectionList]
        for i, jet in enumerate(JetCollectionList):
            try:
                btagger = BTagConf.setupJetBTaggerTool(ToolSvc,
                                                       JetCollection=jet[:-4],
                                                       AddToToolSvc=True,
                                                       SetupScheme="Retag",
                                                       TaggerList=[
                                                           'IP3D', 'MV2c00',
                                                           'MV2c10', 'MV2c20',
                                                           'MV2c100', 'MV2m',
                                                           'MV2c10hp',
                                                           'MV2cl100', 'MVb'
                                                       ])
                jet = jet.replace("Track", "PV0Track")
                SAbtagger = StandAloneJetBTaggerAlg(
                    name=SA + AuthorSubString[i].lower(),
                    JetBTaggerTool=btagger,
                    JetCollectionName=jet,
                )

                topSequence += SAbtagger
            except AttributeError as error:
                print '#BTAG# --> ' + str(error)
                print '#BTAG# --> ' + jet
                print '#BTAG# --> ' + AuthorSubString[i]

        # MET AODFix
        from METReconstruction.METAssocConfig import AssocConfig, getAssociator
        from METReconstruction.METReconstructionConf import METBadTrackEventFilter
        from AthenaCommon.AlgSequence import AthSequencer
        METMapSequence = AthSequencer("MET_LCEM_SelectionSequence_AODFix")
        topSequence += METMapSequence

        from AthenaCommon import CfgMgr
        newtrkseltool = CfgMgr.InDet__InDetTrackSelectionTool(
            "IDTrkSel_METAssoc_AODFix",
            CutLevel="TightPrimary",
            maxZ0SinTheta=3,
            maxD0overSigmaD0=2)
        ToolSvc += newtrkseltool

        METMapSequence += METBadTrackEventFilter(
            "METBadTrackEventFilter_AODFix", TrackSelectorTool=newtrkseltool)

        LCtermlist = ['LCJet', 'Muon', 'Ele', 'Gamma', 'Tau', 'Soft']
        LCAssociators = [
            getAssociator(AssocConfig(config),
                          suffix='AntiKt4LCTopo',
                          doPFlow=False,
                          trkseltool=newtrkseltool) for config in LCtermlist
        ]
        LCAssocTool = CfgMgr.met__METAssociationTool(
            'MET_AssociationTool_AntiKt4LCTopo_AODFix',
            METAssociators=LCAssociators,
            METSuffix='AntiKt4LCTopo',
            AllowOverwrite=True,
            TCSignalState=1)  # LC clusters
        ToolSvc += LCAssocTool

        EMtermlist = ['EMJet', 'Muon', 'Ele', 'Gamma', 'Tau', 'Soft']
        EMAssociators = [
            getAssociator(AssocConfig(config),
                          suffix='AntiKt4EMTopo',
                          doPFlow=False,
                          trkseltool=newtrkseltool) for config in EMtermlist
        ]
        EMAssocTool = CfgMgr.met__METAssociationTool(
            'MET_AssociationTool_AntiKt4EMTopo_AODFix',
            METAssociators=EMAssociators,
            METSuffix='AntiKt4EMTopo',
            AllowOverwrite=True,
            TCSignalState=0)  # EM clusters
        ToolSvc += EMAssocTool

        METAssocAlg_LCEM = CfgMgr.met__METRecoAlg(
            name='METAssociation_LCEM_AODFix',
            RecoTools=[LCAssocTool, EMAssocTool])
        METMapSequence += METAssocAlg_LCEM

        from METUtilities.METMakerConfig import getMETMakerAlg
        METMakerAlg_LC = getMETMakerAlg('AntiKt4LCTopo', confsuffix="_AODFix")
        METMakerAlg_LC.AllowOverwrite = True
        METMakerAlg_EM = getMETMakerAlg('AntiKt4EMTopo', confsuffix="_AODFix")
        METMakerAlg_EM.AllowOverwrite = True
        METMapSequence += METMakerAlg_LC
        METMapSequence += METMakerAlg_EM

        #Only run pflow AOD fix if input file contains AntKt4EMPFlowJets - should be the case for all samples, except HI samples
        from RecExConfig.ObjKeyStore import cfgKeyStore
        if cfgKeyStore.isInInputFile("xAOD::JetContainer",
                                     "AntiKt4EMPFlowJets"):

            #Now we need to rerun the particle flow jet finding

            #This configuration should be identical to the AntiKt4EMPflowJets configured in:
            #http://acode-browser2.usatlas.bnl.gov/lxr-rel20/source/atlas/Reconstruction/Jet/JetRec/share/JetRec_jobOptions.py
            #with the addJetFinder function (in the svn tag for 20.7)
            particleFlowJetFinder_AntiKt4 = CfgMgr.JetFinder(
                "AntiKt4EMPFlowJetsFinder_AODFix")
            particleFlowJetFinder_AntiKt4.JetAlgorithm = "AntiKt"
            particleFlowJetFinder_AntiKt4.JetRadius = 0.4
            particleFlowJetFinder_AntiKt4.GhostArea = 0.01
            particleFlowJetFinder_AntiKt4.PtMin = 2000

            #Then we setup a jet builder to calculate the areas needed for the rho subtraction
            particleFlowJetBuilder_AntiKt4 = CfgMgr.JetFromPseudojet(
                "jblda_AODFix", Attributes=["ActiveArea", "ActiveArea4vec"])
            ToolSvc += particleFlowJetBuilder_AntiKt4
            particleFlowJetFinder_AntiKt4.JetBuilder = particleFlowJetBuilder_AntiKt4
            ToolSvc += particleFlowJetFinder_AntiKt4

            #Now we setup a JetRecTool which will use the above JetFinder
            particleFlowJetRecTool = CfgMgr.JetRecTool(
                "AntiKt4EMPFlowJets_AODFix")
            particleFlowJetRecTool.JetFinder = particleFlowJetFinder_AntiKt4
            ToolSvc += particleFlowJetRecTool

            jpjretriever = CfgMgr.JetPseudojetRetriever("jpjretriever")
            ToolSvc += jpjretriever

            pflowRetriever = CfgMgr.CP__RetrievePFOTool(
                "pflowretriever_AODFix")
            ToolSvc += pflowRetriever

            trk_trackselloose = CfgMgr.InDet__InDetTrackSelectionTool(
                "trk_trackselloose_AODFix", CutLevel="Loose")
            ToolSvc += trk_trackselloose

            trackselloose = CfgMgr.JetTrackSelectionTool(
                "trackselloose",
                InputContainer="InDetTrackParticles",
                OutputContainer="JetSelectedTracks",
                Selector=trk_trackselloose)
            ToolSvc += trackselloose

            tracksel = CfgMgr.JetTrackSelectionTool(
                "tracksel_AODFix",
                InputContainer="InDetTrackParticles",
                OutputContainer="JetSelectedTracks_AODFix",
                Selector=trk_trackselloose)
            ToolSvc += tracksel

            tighttva = CfgMgr.CP__TightTrackVertexAssociationTool(
                "jetTighTVAtool_AODFix", dzSinTheta_cut=3, doPV=True)
            ToolSvc += tighttva

            tvassoc = CfgMgr.TrackVertexAssociationTool(
                "tvassoc_AODFix",
                TrackParticleContainer="InDetTrackParticles",
                TrackVertexAssociation="JetTrackVtxAssoc_AODFix",
                VertexContainer="PrimaryVertices",
                TrackVertexAssoTool=tighttva,
            )
            ToolSvc += tvassoc

            # Ghost tracks.
            ghostScaleFactor = 1e-40
            gtrackget = CfgMgr.TrackPseudoJetGetter(
                "gtrackget_AODFix",
                InputContainer=tracksel.OutputContainer,
                Label="GhostTrack",
                OutputContainer="PseudoJetGhostTracks_AODFix",
                TrackVertexAssociation=tvassoc.TrackVertexAssociation,
                SkipNegativeEnergy=True,
                GhostScale=ghostScaleFactor)
            ToolSvc += gtrackget

            # Muon segments
            gmusegget = CfgMgr.MuonSegmentPseudoJetGetter(
                "gmusegget_AODFix",
                InputContainer="MuonSegments",
                Label="GhostMuonSegment",
                OutputContainer="PseudoJetGhostMuonSegment_AODFix",
                Pt=1.e-20)
            ToolSvc += gmusegget

            # AntiKt2 track jets.
            gakt2trackget = CfgMgr.PseudoJetGetter(
                "gakt2trackget_AODFix",  # give a unique name
                InputContainer="AntiKt2PV0TrackJets",  # SG key
                Label=
                "GhostAntiKt2TrackJet",  # this is the name you'll use to retrieve associated ghosts
                OutputContainer="PseudoJetGhostAntiKt2TrackJet_AODFix",
                SkipNegativeEnergy=True,
                GhostScale=
                ghostScaleFactor,  # This makes the PseudoJet Ghosts, and thus the reco flow will treat them as so.
            )
            ToolSvc += gakt2trackget

            # AntiKt3 track jets.
            gakt3trackget = CfgMgr.PseudoJetGetter(
                "gakt3trackget_AODFix",  # give a unique name
                InputContainer="AntiKt3PV0TrackJets",  # SG key
                Label=
                "GhostAntiKt3TrackJet",  # this is the name you'll use to retrieve associated ghosts
                OutputContainer="PseudoJetGhostAntiKt3TrackJet_AODFix",
                SkipNegativeEnergy=True,
                GhostScale=
                ghostScaleFactor,  # This makes the PseudoJet Ghosts, and thus the reco flow will treat them as so.
            )
            ToolSvc += gakt3trackget

            # AntiKt4 track jets.
            gakt4trackget = CfgMgr.PseudoJetGetter(
                "gakt4trackget_AODFix",  # give a unique name
                InputContainer="AntiKt4PV0TrackJets",  # SG key
                Label=
                "GhostAntiKt4TrackJet",  # this is the name you'll use to retrieve associated ghosts
                OutputContainer="PseudoJetGhostAntiKt4TrackJet_AODFix",
                SkipNegativeEnergy=True,
                GhostScale=
                ghostScaleFactor,  # This makes the PseudoJet Ghosts, and thus the reco flow will treat them as so.
            )
            ToolSvc += gakt4trackget

            # Truth.
            mctc = None
            truthpartcopy = None
            gtruthget = None
            gtruthgetters = []
            rtools = []
            rtools += [tracksel, tvassoc]
            if self.isMC:
                mctc = CfgMgr.MCTruthClassifier(
                    name="JetMCTruthClassifier_AODFix",
                    ParticleCaloExtensionTool="")
                ToolSvc += mctc

                truthpartcopy = CfgMgr.CopyTruthJetParticles(
                    "truthpartcopy_AODFix",
                    OutputName="JetInputTruthParticles_AODFix",
                    MCTruthClassifier=mctc)
                ToolSvc += truthpartcopy

                gtruthget = CfgMgr.PseudoJetGetter(
                    "gtruthget_AODFix",
                    Label="GhostTruth",
                    InputContainer=truthpartcopy.OutputName,
                    OutputContainer="PseudoJetGhostTruth_AODFix",
                    GhostScale=ghostScaleFactor,
                    SkipNegativeEnergy=True,
                )
                ToolSvc += gtruthget

                # Truth flavor tags.
                truthFlavourTags = [
                    "BHadronsInitial",
                    "BHadronsFinal",
                    "BQuarksFinal",
                    "CHadronsInitial",
                    "CHadronsFinal",
                    "CQuarksFinal",
                    "TausFinal",
                    "WBosons",
                    "ZBosons",
                    "HBosons",
                    "TQuarksFinal",
                    "Partons",
                ]
                for ptype in truthFlavourTags:
                    gtruthgetters.append(
                        CfgMgr.PseudoJetGetter(
                            "gtruthget_" + ptype + "_AODFix",
                            InputContainer="TruthLabel" + ptype + "_AODFix",
                            Label="Ghost" + ptype,
                            OutputContainer="PseudoJetGhost" + ptype +
                            "_AODFix",
                            SkipNegativeEnergy=True,
                            GhostScale=ghostScaleFactor,
                        ))
                    ToolSvc += gtruthgetters[-1]

                    toolname = "CopyTruthTag" + ptype + "_AODFix"
                    print "Scheduling " + toolname
                    ptmin = 5000
                    if ptype == "Partons":
                        ctp = CfgMgr.CopyTruthPartons(toolname)
                    elif ptype in [
                            "WBosons", "ZBosons", "HBosons", "TQuarksFinal"
                    ]:
                        ctp = CfgMgr.CopyBosonTopLabelTruthParticles(toolname)
                        ctp.ParticleType = ptype
                        ptmin = 100000
                    else:
                        ctp = CfgMgr.CopyFlavorLabelTruthParticles(toolname)
                        ctp.ParticleType = ptype
                    ctp.OutputName = "TruthLabel" + ptype + "_AODFix"
                    ctp.PtMin = ptmin
                    ToolSvc += ctp
                    rtools.append(ctp)

                # build truth jet input :
                rtools += [truthpartcopy]

            jetrun = CfgMgr.JetToolRunner(
                "jetrun_AODFix",
                Tools=rtools,
            )
            ToolSvc += jetrun

            #Setup a pseudojetgetter to deal with input objects
            empflowget = CfgMgr.PFlowPseudoJetGetter(
                "empflowget_AODFix",
                Label="EMPFlow",
                OutputContainer="PseudoJetEMPFlow_AODFix",
                RetrievePFOTool=pflowRetriever,
                InputIsEM=True,
                CalibratePFO=False,
                SkipNegativeEnergy=True,
                UseVertices=True)
            ToolSvc += empflowget

            empfgetters = [
                empflowget, gtrackget, gmusegget, gakt2trackget, gakt3trackget,
                gakt4trackget
            ]
            if self.isMC:
                empfgetters += [gtruthget] + gtruthgetters

            particleFlowJetRecTool.PseudoJetGetters = empfgetters
            particleFlowJetRecTool.Overwrite = True
            particleFlowJetRecTool.OutputContainer = "AntiKt4EMPFlowJets"

            #setup calibration tools - only want to do area subtraction (as is done in Tier0)
            jetdefn = particleFlowJetFinder_AntiKt4.JetAlgorithm + str(
                int(10 * particleFlowJetFinder_AntiKt4.JetRadius +
                    0.1)) + empflowget.Label
            pflowJetCalibToolName_AODFix = "calib_" + jetdefn + "_pflow_A_AODFix"
            ToolSvc += CfgMgr.JetCalibrationTool(
                "pflowJetCalibTool_AODFix",
                JetCollection=jetdefn,
                ConfigFile="PFlowJES_September2014.config",
                CalibSequence="JetArea",
                RhoKey="Kt4EMPFlowEventShape")
            particleFlowJetRecTool.JetModifiers = [
                ToolSvc.pflowJetCalibTool_AODFix
            ]

            #now we setup the other modifiers we need
            ToolSvc += CfgMgr.JetFilterTool("jetFilter_AODFix", PtMin=5000)
            particleFlowJetRecTool.JetModifiers += [ToolSvc.jetFilter_AODFix]

            #common_ungroomed_modifiers start here
            ToolSvc += CfgMgr.JetWidthTool("width_AODFix")
            particleFlowJetRecTool.JetModifiers += [ToolSvc.width_AODFix]

            ToolSvc += CfgMgr.JetIsolationTool(
                "jetisol_AODFix",
                IsolationCalculations=["IsoDelta:2:SumPt", "IsoDelta:3:SumPt"])
            particleFlowJetRecTool.JetModifiers += [ToolSvc.jetisol_AODFix]

            ToolSvc += CfgMgr.KtDeltaRTool("ktdr_AODFix", JetRadius=0.4)
            particleFlowJetRecTool.JetModifiers += [ToolSvc.ktdr_AODFix]

            ToolSvc += CfgMgr.NSubjettinessTool("nsubjettiness_AODFix",
                                                Alpha=1.0)
            particleFlowJetRecTool.JetModifiers += [
                ToolSvc.nsubjettiness_AODFix
            ]

            ToolSvc += CfgMgr.KTSplittingScaleTool("ktsplitter_AODFix")
            particleFlowJetRecTool.JetModifiers += [ToolSvc.ktsplitter_AODFix]

            ToolSvc += CfgMgr.AngularityTool("angularity_AODFix")
            particleFlowJetRecTool.JetModifiers += [ToolSvc.angularity_AODFix]

            ToolSvc += CfgMgr.DipolarityTool("dipolarity_AODFix",
                                             SubJetRadius=0.3)
            particleFlowJetRecTool.JetModifiers += [ToolSvc.dipolarity_AODFix]

            ToolSvc += CfgMgr.PlanarFlowTool("planarflow_AODFix")
            particleFlowJetRecTool.JetModifiers += [ToolSvc.planarflow_AODFix]

            ToolSvc += CfgMgr.KtMassDropTool("ktmassdrop_AODFix")
            particleFlowJetRecTool.JetModifiers += [ToolSvc.ktmassdrop_AODFix]

            ToolSvc += CfgMgr.EnergyCorrelatorTool("encorr_AODFix", Beta=1.0)
            particleFlowJetRecTool.JetModifiers += [ToolSvc.encorr_AODFix]

            ToolSvc += CfgMgr.CenterOfMassShapesTool("comshapes_AODFix")
            particleFlowJetRecTool.JetModifiers += [ToolSvc.comshapes_AODFix]

            #common_ungroomed_modifiers that are for MC only

            ## (JM) Now introduced an isMC flag, so can remove this suff.
            # #First we check if the file is MC or data using the metadata (not allowed to use reco flags om AODFix)
            # from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
            # theInputFile_AODFix = athenaCommonFlags.PoolAODInput.get_Value()[0]
            # import PyUtils.AthFile as af
            # haveParticleJetTools_AODFix = False
            # f = af.fopen(theInputFile_AODFix)
            # if 'evt_type' in f.infos.keys():
            #     import re
            #     if re.match(str(f.infos['evt_type'][0]), 'IS_SIMULATION') :
            #         try:
            #             haveParticleJetTools_AODFix = True
            #         except:
            #             haveParticleJetTools_AODFix = False

            #         if haveParticleJetTools_AODFix:
            #             ToolSvc += CfgMgr.Analysis__JetPartonTruthLabel("partontruthlabel_AODFix")
            #             particleFlowJetRecTool.JetModifiers += [ToolSvc.partontruthlabel_AODFix]

            #             ToolSvc += CfgMgr.Analysis__JetQuarkLabel("jetquarklabel_AODFix",McEventCollection = "TruthEvents")
            #             ToolSvc += CfgMgr.Analysis__JetConeLabeling("truthpartondr_AODFix",JetTruthMatchTool = ToolSvc.jetquarklabel_AODFix)
            #             particleFlowJetRecTool.JetModifiers += [ToolSvc.truthpartondr_AODFix]

            #This is the replacement
            if self.isMC:
                ToolSvc += CfgMgr.Analysis__JetPartonTruthLabel(
                    "partontruthlabel_AODFix")
                particleFlowJetRecTool.JetModifiers += [
                    ToolSvc.partontruthlabel_AODFix
                ]

                ToolSvc += CfgMgr.Analysis__JetQuarkLabel(
                    "jetquarklabel_AODFix", McEventCollection="TruthEvents")
                ToolSvc += CfgMgr.Analysis__JetConeLabeling(
                    "truthpartondr_AODFix",
                    JetTruthMatchTool=ToolSvc.jetquarklabel_AODFix)
                particleFlowJetRecTool.JetModifiers += [
                    ToolSvc.truthpartondr_AODFix
                ]
            ## end of JM modificatoin

            #common_ungroomed_modifiers end here

            # Modifiers for topo (and pflow) jets.
            jetens = CfgMgr.JetCaloEnergies("jetens_AODFix")
            ToolSvc += jetens

            larhvcorr = CfgMgr.JetLArHVTool("larhvcorr_AODFix")
            ToolSvc += larhvcorr

            caloqual_cluster = CfgMgr.JetCaloQualityTool(
                "caloqual_cluster_AODFix",
                TimingCuts=[5, 10],
                Calculations=[
                    "LArQuality", "N90Constituents", "FracSamplingMax",
                    "NegativeE", "Timing", "HECQuality", "Centroid",
                    "AverageLArQF", "BchCorrCell"
                ],
            )
            ToolSvc += caloqual_cluster

            # Jet vertex fraction with selection.
            jvf = CfgMgr.JetVertexFractionTool(
                "jvf_AODFix",
                VertexContainer="PrimaryVertices",
                AssociatedTracks="GhostTrack",
                TrackVertexAssociation=tvassoc.TrackVertexAssociation,
                TrackSelector=trackselloose,
                JVFName="JVF")
            ToolSvc += jvf

            # Jet vertex tagger.
            jvt = CfgMgr.JetVertexTaggerTool(
                "jvt_AODFix",
                VertexContainer="PrimaryVertices",
                TrackParticleContainer="InDetTrackParticles",
                AssociatedTracks="GhostTrack",
                TrackVertexAssociation=tvassoc.TrackVertexAssociation,
                TrackSelector=trackselloose,
                JVTName="Jvt",
                K_JVFCorrScale=0.01,
                Z0Cut=3.0,
                PUTrkPtCut=30000.0)
            ToolSvc += jvt

            # Jet track info.
            trkmoms = CfgMgr.JetTrackMomentsTool(
                "trkmoms_AODFix",
                VertexContainer="PrimaryVertices",
                AssociatedTracks="GhostTrack",
                TrackVertexAssociation=tvassoc.TrackVertexAssociation,
                TrackMinPtCuts=[500, 1000],
                TrackSelector=trackselloose)
            ToolSvc += trkmoms

            charge = CfgMgr.JetChargeTool("charge_AODFix", K=1.0)
            ToolSvc += charge

            particleFlowJetRecTool.JetModifiers += [
                jetens, larhvcorr, caloqual_cluster, jvf, jvt, trkmoms, charge
            ]

            if self.isMC:
                truthassoc = CfgMgr.JetPtAssociationTool(
                    "truthassoc_AntiKt4_AODFix",
                    InputContainer="AntiKt4TruthJets",
                    AssociationName="GhostTruth")
                ToolSvc += truthassoc

                jetdrlabeler = CfgMgr.ParticleJetDeltaRLabelTool(
                    "jetdrlabeler_AODFix",
                    LabelName="HadronConeExclTruthLabelID",
                    BLabelName="ConeExclBHadronsFinal",
                    CLabelName="ConeExclCHadronsFinal",
                    TauLabelName="ConeExclTausFinal",
                    BParticleCollection="TruthLabelBHadronsFinal_AODFix",
                    CParticleCollection="TruthLabelCHadronsFinal_AODFix",
                    TauParticleCollection="TruthLabelTausFinal_AODFix",
                    PartPtMin=5000.0,
                    JetPtMin=4500.0,
                    DRMax=0.3,
                    MatchMode="MinDR")
                ToolSvc += jetdrlabeler

                particleFlowJetRecTool.JetModifiers += [
                    truthassoc, jetdrlabeler
                ]

            JetType = 'PFlowJet'
            PFtermlist = ['PFlowJet', 'Muon', 'Ele', 'Gamma', 'Tau', 'Soft']
            newpfotool = CfgMgr.CP__RetrievePFOTool('MET_PFOTool_AODFix')
            ToolSvc += newpfotool

            PFAssociators = [
                getAssociator(AssocConfig(config),
                              suffix='AntiKt4EMPFlow',
                              doPFlow=True,
                              trkseltool=newtrkseltool,
                              pfotool=newpfotool) for config in PFtermlist
            ]
            PFAssocTool = CfgMgr.met__METAssociationTool(
                'MET_AssociationTool_AntiKt4EMPFlow_AODFix',
                METAssociators=PFAssociators,
                METSuffix='AntiKt4EMPFlow',
                AllowOverwrite=True)
            ToolSvc += PFAssocTool

            METAssocAlg_PFlow = CfgMgr.met__METRecoAlg(
                name='METAssociation_PFlow_AODFix', RecoTools=[PFAssocTool])
            METMakerAlg_PF = getMETMakerAlg('AntiKt4EMPFlow',
                                            confsuffix="_AODFix")
            METMakerAlg_PF.AllowOverwrite = True

            #Set up our own sequence
            ParticleFlowJetSequence = AthSequencer(
                "ParticleFlowSelectionSequence")
            topSequence += ParticleFlowJetSequence

            #Add an event filter to our sequence
            ParticleFlowJetSequence += CfgMgr.ParticleFlowEventFilter_r207(
                "ParticleFlowEventFilter_r207")
            #Add the particle flow jet finding to our sequence
            ParticleFlowJetSequence += CfgMgr.JetAlgorithm(
                "pflowJetAlg_AODFix",
                Tools=[jetrun, ToolSvc.AntiKt4EMPFlowJets_AODFix])
            #Add MET map builder to our sequence
            ParticleFlowJetSequence += METAssocAlg_PFlow
            #Build the reference MET container
            ParticleFlowJetSequence += METMakerAlg_PF
# -- for calibration from COOL
from BTagging.BTaggingFlags import BTaggingFlags
include("JetTagCalibration/BTagCalibrationBroker_Trig_jobOptions.py")
BTagCalibrationBrokerTool_Trig.folders[:] = [] # Wipe folders; these will be dynamically filled by the configuration code
from BTagging.BTaggingConfiguration import getConfiguration
ConfInst = getConfiguration("Trig")
ConfInst.registerTool("BTagCalibrationBrokerTool", BTagCalibrationBrokerTool_Trig)

# NOTE: The reason for this file is that we want to be able to set up a default configuration when requested by a Python function. However for some reason if we include JetTagCalibration/BTagCalibrationBroker_jobOptions.py at that location then the BTagCalibrationBrokerTool name will not be accessible afterwards, and we need to be able to register it. This file is included from BTaggingConfiguration_LoadTools.py.
Exemplo n.º 26
0
printfunc("List of containers")
printfunc(BTaggingAODList)
if len(BTaggingAODList) == 0:
    # The list is empty if b-tagging was not set up; the typical use case for this is the ESDtoAOD step.
    # Apparently we are not allowed to use wildcards in the container names... (and they cause problems for HLT).
    # Therefore, we duplicate here some code from BTagging/share/BTagging_jobOptions.py to specify the relevant Jet collections.
    # Clearly this duplication is undesirable and should be replaced with a single function.
    #JetCollectionList = ['AntiKt4LCTopoJets', 'AntiKt10LCTopoJets', 'AntiKt4EMTopoJets', 'AntiKt4TrackJets', 'AntiKt3TrackJets']
    JetCollectionList = [
        'AntiKt4LCTopoJets', 'AntiKt4EMTopoJets', 'AntiKt4TrackJets',
        'AntiKt4EMPFlowJets', 'AntiKt2TrackJets', 'AntiKt4HIJets'
    ]
    from JetRec.JetRecFlags import jetFlags
    # VD: disbling b-tagging on TruthJets
    #if jetFlags.useTruth():
    #  JetCollectionList += [ 'AntiKt10TruthWZJets', 'AntiKt4TruthWZJets' ]
    from BTagging.BTaggingConfiguration import getConfiguration
    BTagConf = getConfiguration()
    for coll in JetCollectionList:
        BTagConf.RegisterOutputContainersForJetCollection(coll[:-4])
    BTaggingAODList = BTaggingFlags.btaggingAODList

#    BTaggingAODList += ["xAOD::BTaggingAuxContainer#*"]
#    BTaggingAODList += ["xAOD::BTaggingContainer#*"]
#    BTaggingAODList += ["xAOD::BTagVertexContainer#*"]
#    BTaggingAODList += ["xAOD::BTagVertexAuxContainer#*"]
#    BTaggingAODList += ["xAOD::VertexContainer#BTagging*"]
#    BTaggingAODList += ["xAOD::VertexAuxContainer#BTagging*"]

printfunc("#BTAG# AOD output container list: " + str(BTaggingAODList))