diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTagRun3Config.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTagRun3Config.py index a223f6da0499d46e9876923fb63c77754bf8c0b1..32e075b6e6017079c9599133483cae4db9ed05aa 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTagRun3Config.py +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTagRun3Config.py @@ -273,11 +273,6 @@ def JetBTaggerSplitAlgsCfg(inputFlags, JetCollection="", TaggerList=[], SecVerte ] } - if jet in postTagDL2JetToTrainingMap: - #Remove DL1 and RNNIP from taggers list, those taggers are run with HighLevelBTagAlg - TaggerList.remove('RNNIP') - TaggerList.remove('DL1') - #Track Association TrackToJetAssociators = list(set(SecVertexingAndAssociators.values())) diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfigFlags.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfigFlags.py index aac662b631f99284b55a10a19a6ad235c2abe770..ac81f5186b83e919fecd434598bb2e83ef81bb53 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfigFlags.py +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfigFlags.py @@ -5,9 +5,9 @@ from AthenaConfiguration.AthConfigFlags import AthConfigFlags def createBTaggingConfigFlags(): btagcf = AthConfigFlags() - btagcf.addFlag("BTagging.run2TaggersList", ['IP2D','IP3D','SV1','SoftMu','JetFitterNN','MV2c10','MV2c10mu','MV2c10rnn','MV2c100','MV2cl100','RNNIP','DL1','DL1mu','DL1rnn']) + btagcf.addFlag("BTagging.run2TaggersList", ['IP2D','IP3D','SV1','SoftMu','JetFitterNN','MV2c10']) btagcf.addFlag("BTagging.Run2TrigTaggers", ['IP2D','IP3D','SV1','JetFitterNN','MV2c10']) - btagcf.addFlag("BTagging.Run3NewTrigTaggers", ['RNNIP','DL1','DL1rnn']) + btagcf.addFlag("BTagging.Run3NewTrigTaggers", []) # Disable JetVertexCharge ATLASRECTS-4506 btagcf.addFlag("BTagging.RunModus", "analysis") # reference mode used in FlavourTagPerformanceFramework (RetagFragment.py) btagcf.addFlag("BTagging.ReferenceType", "ALL") # reference type for IP and SV taggers (B, UDSG, ALL) diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration.py index bdd0e39487fb3df279baf0361069a18d079edd40..7fa23ccd205515dec64c53716c485df1c97c2c89 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration.py +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration.py @@ -42,7 +42,6 @@ from BTagging.BTaggingConfiguration_IP3DNegTag import * from BTagging.BTaggingConfiguration_IP3DTag import * from BTagging.BTaggingConfiguration_IP3DTrigTag import * from BTagging.BTaggingConfiguration_IP3DTrigHybridTag import * -from BTagging.BTaggingConfiguration_RNNIPTag import * # Jet fitter taggers #from BTagging.BTaggingConfiguration_JetFitterCOMB import * @@ -107,27 +106,18 @@ from BTagging.BTaggingConfiguration_MV2c100Tag import * from BTagging.BTaggingConfiguration_MV2c100FlipTag import * from BTagging.BTaggingConfiguration_MV2cl100Tag import * from BTagging.BTaggingConfiguration_MV2cl100FlipTag import * -from BTagging.BTaggingConfiguration_MV2mTag import * -from BTagging.BTaggingConfiguration_MV2mFlipTag import * from BTagging.BTaggingConfiguration_MV2c10hpTag import * from BTagging.BTaggingConfiguration_MV2c10hpFlipTag import * #JetVertexCharge tool from BTagging.BTaggingConfiguration_JetVertexCharge import * -#ExKtbb tool -from BTagging.BTaggingConfiguration_ExKtbbTag import * - # MultivariateTagManager from BTagging.BTaggingConfiguration_MultivariateTagManager import * from BTagging.BTaggingConfiguration_MultivariateTrigTagManager import * from BTagging.BTaggingConfiguration_MultivariateFlipTagManager import * from BTagging.BTaggingConfiguration_MultiTrigHybridTagManager import * -# DL1 tagger -from BTagging.BTaggingConfiguration_DL1Tag import * -from BTagging.BTaggingConfiguration_DL1FlipTag import * - # TagNtupleDumper from BTagging.BTaggingConfiguration_TagNtupleDumper import * diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_ExKtbbTag.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_ExKtbbTag.py deleted file mode 100644 index 7ec236efc3f75cdee7c8bc7eb166138f7348bead..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_ExKtbbTag.py +++ /dev/null @@ -1,121 +0,0 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration - -# Configuration functions for ExKtbbTag -# Author: Qi Zeng (2015) - -from BTagging.BTaggingFlags import BTaggingFlags - -metaExKtbb_Hbb_MV2OnlyTag = { 'IsATagger' : True, - 'xAODBaseName' : 'ExKtbb', - 'DependsOn' : ['MV2c20Tag', - 'BTagCalibrationBrokerTool'], - 'CalibrationTaggers' :['ExKtbb',], - 'PassByPointer' : {'calibrationTool' : 'BTagCalibrationBrokerTool'}, - 'ToolCollection' : 'ExKtbbTag', - } - -metaExKtbb_Hbb_MV2andJFDRSigTag = { 'IsATagger' : True, - 'xAODBaseName' : 'ExKtbb', - 'DependsOn' : ['MV2c20Tag', - 'BTagCalibrationBrokerTool'], - 'CalibrationTaggers' :['ExKtbb',], - 'PassByPointer' : {'calibrationTool' : 'BTagCalibrationBrokerTool'}, - 'ToolCollection' : 'ExKtbbTag', - } - -metaExKtbb_Hbb_MV2andToposTag = { 'IsATagger' : True, - 'xAODBaseName' : 'ExKtbb', - 'DependsOn' : ['MV2c20Tag', - 'BTagCalibrationBrokerTool'], - 'CalibrationTaggers' :['ExKtbb',], - 'PassByPointer' : {'calibrationTool' : 'BTagCalibrationBrokerTool'}, - 'ToolCollection' : 'ExKtbbTag', - } - -def toolExKtbb_Hbb_MV2OnlyTag(name, useBTagFlagsDefaults = True, **options): - """Sets up a ExKtbbTag tool and returns it. - - The following options have BTaggingFlags defaults: - - see below - - input: name: The name of the tool (should be unique). - useBTagFlagsDefaults : Whether to use BTaggingFlags defaults for options that are not specified. - **options: Python dictionary with options for the tool. - output: The actual tool, which can then by added to ToolSvc via ToolSvc += output.""" - if useBTagFlagsDefaults: - defaults = { 'OutputLevel' : BTaggingFlags.OutputLevel, - 'Runmodus' : BTaggingFlags.Runmodus, - 'tagMode' : 'Hbb', - 'BDTMode' : 'MV2Only', - 'taggerNameBase' : 'ExKtbb', - 'ForceCalibrationChannel' : 'Default', - 'debug' : False, - - 'SubJetLabel' : 'ExKt2SubJets', - 'JFOnlyVtx' : False, - } - for option in defaults: - options.setdefault(option, defaults[option]) - options['name'] = name - from JetTagTools.JetTagToolsConf import Analysis__ExKtbbTag - return Analysis__ExKtbbTag(**options) - -def toolExKtbb_Hbb_MV2andJFDRSigTag(name, useBTagFlagsDefaults = True, **options): - """Sets up a ExKtbbTag tool and returns it. - - The following options have BTaggingFlags defaults: - - see below - - input: name: The name of the tool (should be unique). - useBTagFlagsDefaults : Whether to use BTaggingFlags defaults for options that are not specified. - **options: Python dictionary with options for the tool. - output: The actual tool, which can then by added to ToolSvc via ToolSvc += output.""" - if useBTagFlagsDefaults: - defaults = { 'OutputLevel' : BTaggingFlags.OutputLevel, - 'Runmodus' : BTaggingFlags.Runmodus, - 'tagMode' : 'Hbb', - 'BDTMode' : 'MV2andJFDRSig', - 'taggerNameBase' : 'ExKtbb', - 'ForceCalibrationChannel' : 'Default', - 'debug' : False, - - 'SubJetLabel' : 'ExKt2SubJets', - 'JFOnlyVtx' : False, - } - for option in defaults: - options.setdefault(option, defaults[option]) - options['name'] = name - from JetTagTools.JetTagToolsConf import Analysis__ExKtbbTag - return Analysis__ExKtbbTag(**options) - -def toolExKtbb_Hbb_MV2andToposTag(name, useBTagFlagsDefaults = True, **options): - """Sets up a ExKtbbTag tool and returns it. - - The following options have BTaggingFlags defaults: - - see below - - input: name: The name of the tool (should be unique). - useBTagFlagsDefaults : Whether to use BTaggingFlags defaults for options that are not specified. - **options: Python dictionary with options for the tool. - output: The actual tool, which can then by added to ToolSvc via ToolSvc += output.""" - if useBTagFlagsDefaults: - defaults = { 'OutputLevel' : BTaggingFlags.OutputLevel, - 'Runmodus' : BTaggingFlags.Runmodus, - 'tagMode' : 'Hbb', - 'BDTMode' : 'MV2andTopos', - 'taggerNameBase' : 'ExKtbb', - 'ForceCalibrationChannel' : 'Default', - 'debug' : False, - - 'SubJetLabel' : 'ExKt2SubJets', - 'JFOnlyVtx' : False, - } - for option in defaults: - options.setdefault(option, defaults[option]) - options['name'] = name - from JetTagTools.JetTagToolsConf import Analysis__ExKtbbTag - return Analysis__ExKtbbTag(**options) - diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_IP3DTrigTag.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_IP3DTrigTag.py index e0b1afbe5803aaecdae00540768215fd43becdd9..b8131a3a656e976d83e400b87852dd533057f68b 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_IP3DTrigTag.py +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_IP3DTrigTag.py @@ -77,7 +77,6 @@ def toolIP3DTag_Trig(name, useBTagFlagsDefaults = True, **options): trackGradeFactory= toolIP3DDetailedTrackGradeFactory('IP3DDetailedTrackGradeFactory') trackSelectorTool = toolIP3DTrackSelector('IP3DTrackSelector') inDetTrackSelectionTool = toolInDetTrackSelector('InDetTrackSelector') - trackVertexAssociationTool = toolSpecialTrackAssociator('SpecialTrackAssociator') likelihood = toolIP3DNewLikelihoodTool('IP3DNewLikelihoodTool') defaults = { 'OutputLevel' : BTaggingFlags.OutputLevel, 'Runmodus' : BTaggingFlags.Runmodus, @@ -103,7 +102,6 @@ def toolIP3DTag_Trig(name, useBTagFlagsDefaults = True, **options): 'SVForIPTool' : svForIPTool, 'trackGradeFactory' : trackGradeFactory, 'TrackToVertexIPEstimator' : trackToVertexIPEstimator, - 'TrackVertexAssociationTool' : trackVertexAssociationTool, } for option in defaults: options.setdefault(option, defaults[option]) diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_LoadTools.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_LoadTools.py index 42e036c80fa9622e55a2b4694644d5597db7e5b4..fe39ce6866b47a5003a47406844624c5df2caea0 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_LoadTools.py +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_LoadTools.py @@ -195,7 +195,7 @@ def SetupConditionAlgorithm(ConfInstance=None): if globalflags.DataSource()=='data': readkeycalibpath = readkeycalibpath.replace("/GLOBAL/BTagCalib","/GLOBAL/Onl/BTagCalib") connSchema = "GLOBAL" - Taggers = ['IP2D','IP3D','SV1','SoftMu','JetFitterNN','MV2c10','MV2c10mu','MV2c10rnn','MV2c100','MV2cl100','RNNIP','DL1','DL1mu','DL1rnn'] + Taggers = ['IP2D','IP3D','SV1','SoftMu','JetFitterNN','MV2c10'] #JetVertexCharge disable ATLASRECTS-4506 histoskey = "JetTagCalibHistosKey" conddb.addFolder(connSchema, readkeycalibpath, className='CondAttrListCollection') @@ -368,10 +368,6 @@ def SetupJetCollectionDefault(JetCollection, TaggerList, ConfInstance = None): # 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) diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_MV2mFlipTag.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_MV2mFlipTag.py deleted file mode 100644 index 3e9eb3be45bc7c4822341db9caf20de05172764d..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_MV2mFlipTag.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration - -# Configuration functions for MV2mFlipTag -# Author: Wouter van den Wollenberg (2013-2014) -from BTagging.BTaggingFlags import BTaggingFlags - -metaMV2mFlipTag = { 'IsATagger' : False,#True, - 'xAODBaseName' : 'MV2mFlip', - 'DependsOn' : ['AtlasExtrapolator', - 'BTagCalibrationBrokerTool', - 'BTagTrackToVertexTool'], - 'CalibrationTaggers' : ['MV2m',], - 'PassByPointer' : {'calibrationTool' : 'BTagCalibrationBrokerTool'}, - 'ToolCollection' : 'MV2mFlipTag'} - -def toolMV2mFlipTag(name, useBTagFlagsDefaults = True, **options): - """Sets up a MV2mTag tool and returns it. - - The following options have BTaggingFlags defaults: - - OutputLevel default: BTaggingFlags.OutputLevel - Runmodus default: BTaggingFlags.Runmodus - taggerName default: "MV2mFlip" - taggerNameBase default: "MV2m" - forceMV2CalibrationAlias default: BTaggingFlags.ForceMV2CalibrationAlias - MV2CalibAlias default: BTaggingFlags.MV2CalibAlias - - input: name: The name of the tool (should be unique). - useBTagFlagsDefaults : Whether to use BTaggingFlags defaults for options that are not specified. - **options: Python dictionary with options for the tool. - output: The actual tool, which can then by added to ToolSvc via ToolSvc += output.""" - from BTagging.MV2defaultValues import default_values - from BTagging.MV2defaultValues import MVTM_varNames - - if useBTagFlagsDefaults: - defaults = { 'OutputLevel' : BTaggingFlags.OutputLevel, - 'Runmodus' : BTaggingFlags.Runmodus, - 'taggerName' : 'MV2mFlip', - 'taggerNameBase' : 'MV2m', - 'forceMV2CalibrationAlias' : BTaggingFlags.ForceMV2CalibrationAlias, - 'MV2CalibAlias' : BTaggingFlags.MV2CalibAlias, - 'defaultvals' : default_values, - 'MVTMvariableNames' : MVTM_varNames, - } - for option in defaults: - options.setdefault(option, defaults[option]) - options['name'] = name - from JetTagTools.JetTagToolsConf import Analysis__MV2Tag - return Analysis__MV2Tag(**options) diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_MV2mTag.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_MV2mTag.py deleted file mode 100644 index 0faf182adc80e91930755f0892bba7fda64b3259..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_MV2mTag.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration - -# Configuration functions for MV2mTag -# Author: Wouter van den Wollenberg (2013-2014) -from BTagging.BTaggingFlags import BTaggingFlags - -metaMV2mTag = { 'IsATagger' : False,#True, - 'xAODBaseName' : 'MV2m', - 'DependsOn' : ['AtlasExtrapolator', - 'BTagCalibrationBrokerTool', - 'BTagTrackToVertexTool'], - 'CalibrationTaggers' : ['MV2m',], - 'PassByPointer' : {'calibrationTool' : 'BTagCalibrationBrokerTool'}, - 'ToolCollection' : 'MV2mTag'} - -def toolMV2mTag(name, useBTagFlagsDefaults = True, **options): - """Sets up a MV2mTag tool and returns it. - - The following options have BTaggingFlags defaults: - - OutputLevel default: BTaggingFlags.OutputLevel - Runmodus default: BTaggingFlags.Runmodus - taggerName default: "MV2m" - taggerNameBase default: "MV2m" - forceMV2CalibrationAlias default: BTaggingFlags.ForceMV2CalibrationAlias - MV2CalibAlias default: BTaggingFlags.MV2CalibAlias - - input: name: The name of the tool (should be unique). - useBTagFlagsDefaults : Whether to use BTaggingFlags defaults for options that are not specified. - **options: Python dictionary with options for the tool. - output: The actual tool, which can then by added to ToolSvc via ToolSvc += output.""" - from BTagging.MV2defaultValues import default_values - from BTagging.MV2defaultValues import MVTM_varNames - - if useBTagFlagsDefaults: - defaults = { 'OutputLevel' : BTaggingFlags.OutputLevel, - 'Runmodus' : BTaggingFlags.Runmodus, - 'taggerName' : 'MV2m', - 'taggerNameBase' : 'MV2m', - 'forceMV2CalibrationAlias' : BTaggingFlags.ForceMV2CalibrationAlias, - 'MV2CalibAlias' : BTaggingFlags.MV2CalibAlias, - 'defaultvals' : default_values, - 'MVTMvariableNames' : MVTM_varNames, - } - for option in defaults: - options.setdefault(option, defaults[option]) - options['name'] = name - from JetTagTools.JetTagToolsConf import Analysis__MV2Tag - return Analysis__MV2Tag(**options) diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_RNNIPTag.py b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_RNNIPTag.py deleted file mode 100644 index f7a4353f3775e6abd4c9a9ed30891e4414fb4509..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/python/BTaggingConfiguration_RNNIPTag.py +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration - -# Configuration for RNNIP -# -# Note that a lot of tools and settings are borrowed from IP3D, so -# this probably won't work without IP3D also turned on. We'll need an -# expter to figure out how to make taggers independant. -from BTagging.BTaggingFlags import BTaggingFlags - -def buildRNNIP(basename, is_flipped=False, calibration=None): - cal_dir = calibration or basename - meta = {'IsATagger' : True, - 'xAODBaseName' : basename, - 'CalibrationTaggers' : [cal_dir], - 'DependsOn' : [#'AtlasExtrapolator', - #'BTagTrackToVertexTool', - #'InDetVKalVxInJetTool', - #'BTagTrackToVertexIPEstimator', - #'IP3DTrackSelector', - #'InDetTrackSelector', - #'SpecialTrackAssociator', - #'SVForIPTool_IP3D', - #'IP3DBasicTrackGradeFactory', - #'IP3DDetailedTrackGradeFactory'], - ], - 'PassByPointer' : { - #'SVForIPTool' : 'SVForIPTool_IP3D', - #'trackSelectorTool' : 'IP3DTrackSelector', - #'trackGradeFactory' : 'IP3DDetailedTrackGradeFactory'}, - #'TrackToVertexIPEstimator' : 'BTagTrackToVertexIPEstimator'}, - }, - 'PassTracksAs' : 'trackAssociationName', - 'ToolCollection' : 'IP3DTag' } - - def tool(name, useBTagFlagsDefaults = True, **options): - """Sets up a IP3DTag tool and returns it. - - The following options have BTaggingFlags defaults: - - """ - if useBTagFlagsDefaults: - grades= [ "0HitIn0HitNInExp2","0HitIn0HitNInExpIn","0HitIn0HitNInExpNIn","0HitIn0HitNIn", - "0HitInExp", "0HitIn", - "0HitNInExp", "0HitNIn", - "InANDNInShared", "PixShared", "SctShared", - "InANDNInSplit", "PixSplit", - "Good"] - - from BTagging.BTaggingConfiguration_CommonTools import toolBTagTrackToVertexIPEstimator as toolBTagTrackToVertexIPEstimator - trackToVertexIPEstimator = toolBTagTrackToVertexIPEstimator('TrkToVxIPEstimator') - from BTagging.BTaggingConfiguration_IP3DTag import toolSVForIPTool_IP3D as toolSVForIPTool_IP3D - svForIPTool = toolSVForIPTool_IP3D('SVForIPTool') - from BTagging.BTaggingConfiguration_IP3DTag import toolIP3DDetailedTrackGradeFactory as toolIP3DDetailedTrackGradeFactory - trackGradeFactory = toolIP3DDetailedTrackGradeFactory('RNNIPDetailedTrackGradeFactory') - from BTagging.BTaggingConfiguration_IP3DTag import toolIP3DTrackSelector as toolIP3DTrackSelector - trackSelectorTool = toolIP3DTrackSelector('IP3DTrackSelector') - defaults = { - 'OutputLevel' : BTaggingFlags.OutputLevel, - 'trackGradePartitions' : grades , - 'RejectBadTracks' : True, - 'originalTPCollectionName' : BTaggingFlags.TrackParticleCollectionName, - 'NetworkConfig' : BTaggingFlags.RNNIPConfig, - 'unbiasIPEstimation' : False, - #'trackAssociation' : "Tracks" } - 'SecVxFinderName' : 'SV1', - 'calibration_directory' : cal_dir, - 'writeInputsToBtagObject' : BTaggingFlags.WriteRNNInputs, - 'trackSelectorTool' : trackSelectorTool, - 'SVForIPTool' : svForIPTool, - 'trackGradeFactory' : trackGradeFactory, - 'TrackToVertexIPEstimator' : trackToVertexIPEstimator, - } - if is_flipped: - defaults.update({ - 'flipIPSign' : True, - 'usePosIP' : True, - 'useNegIP' : False, - }) - for option in defaults: - options.setdefault(option, defaults[option]) - options['name'] = name - from JetTagTools.JetTagToolsConf import Analysis__RNNIPTag - return Analysis__RNNIPTag(**options) - - return tool, meta - - -toolRNNIPTag, metaRNNIPTag = buildRNNIP('RNNIP') -toolRNNIPNegTag, metaRNNIPNegTag = buildRNNIP( - 'RNNIPNegTag', is_flipped=True, calibration='RNNIP') diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/CMakeLists.txt b/PhysicsAnalysis/JetTagging/JetTagTools/CMakeLists.txt index d51a90313acf8d447eb6d2d58526b0e1dd22f18a..2d29de37c055219c33831612971471dc96992967 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/CMakeLists.txt +++ b/PhysicsAnalysis/JetTagging/JetTagTools/CMakeLists.txt @@ -57,7 +57,6 @@ find_package( Boost COMPONENTS filesystem thread system ) find_package( CLHEP ) #find_package( Eigen ) find_package( lwtnn ) -find_package( FastJet ) find_package( ROOT COMPONENTS TMVA Core Tree MathCore Hist RIO pthread MathMore Minuit Minuit2 Matrix Physics HistPainter Rint RooFitCore RooFit ) @@ -81,12 +80,12 @@ atlas_add_library( JetTagToolsLib src/MV1Tag.cxx src/MV2Tag.cxx src/JetFitterVariablesFactory.cxx src/MSVVariablesFactory.cxx src/MultiSVTag.cxx src/SoftMuonTag.cxx - src/ExKtbbTagTool.cxx src/MultivariateTagManager.cxx + src/MultivariateTagManager.cxx src/DL1Tag.cxx src/TagNtupleDumper.cxx src/RNNIPTag.cxx PUBLIC_HEADERS JetTagTools INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${LWTNN_INCLUDE_DIRS} - PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${FASTJET_INCLUDE_DIRS} + PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} DEFINITIONS ${CLHEP_DEFINITIONS} LINK_LIBRARIES ${ROOT_LIBRARIES} ${CLHEP_LIBRARIES} ${LWTNN_LIBRARIES} @@ -97,7 +96,7 @@ atlas_add_library( JetTagToolsLib MuonSelectorToolsLib MuonMomentumCorrectionsLib TrkNeuralNetworkUtilsLib InDetSVWithMuonToolLib ITrackToVertex - PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${FASTJET_LIBRARIES} AthenaKernel + PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} AthenaKernel Navigation xAODMuon JetEDM Particle ITrackToVertex TrkEventPrimitives TrkLinks TrkTrack TrkTrackSummary VxJetVertex VxVertex VxSecVertex TrkVertexFitterInterfaces InDetTrackSelectionToolLib diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/BTagVariables.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/BTagVariables.h index de9ef3046dceb968e65a9f68daacd96b1a2c97a4..959e4638c5bfa358e46448b54ce599582293f634 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/BTagVariables.h +++ b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/BTagVariables.h @@ -69,19 +69,6 @@ namespace btagvar { static const char* JF_DETA = "jf_deta"; static const char* JF_SIG3D = "jf_sig3d"; - static const char* JF_NTRK_VTX1 = "nTrk_vtx1";//"jf_ntrk_vtx1"; - static const char* JF_MASS_VTX1 = "mass_first_vtx";//"jf_m_vtx1"; - static const char* JF_E_VTX1 = "e_first_vtx";//"jf_e_vtx1"; - static const char* JF_E_FRAC_VTX1 = "e_frac_vtx1";//"jf_efc_vtx1"; - static const char* JF_L3D_VTX1 = "closestVtx_L3D";//"jf_L3d_vtx1"; - static const char* JF_Lxy_VTX1 = "JF_Lxy1";//"jf_Lxy_vtx1"; - static const char* JF_RAPIDITY_VTX1_MAX = "vtx1_MaxTrkRapidity_jf_path";//"jf_trky_max_vtx1"; - static const char* JF_RAPIDITY_VTX1_AVG = "vtx1_AvgTrkRapidity_jf_path";//"jf_trky_avg_vtx1"; - static const char* JF_RAPIDITY_VTX1_MIN = "vtx1_MinTrkRapidity_jf_path";//"jf_trky_min_vtx1"; - static const char* JF_RAPIDITY_MAX = "MaxTrkRapidity_jf_path";//"jf_trky_max"; - static const char* JF_RAPIDITY_MIN = "MinTrkRapidity_jf_path";//"jf_trky_min"; - static const char* JF_RAPIDITY_AVG = "AvgTrkRapidity_jf_path";//"jf_trky_avg"; - static const char* TRKSUM_NTRK = "trkSum_ntrk"; static const char* TRKSUM_SPT = "trkSum_sPt"; static const char* TRKSUM_VPT = "trkSum_vPt"; diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/DL1Tag.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/DL1Tag.h deleted file mode 100644 index 7ff88f2a49ddc0bce498ab2650800fb86b697826..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/DL1Tag.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef BTAGTOOLS_DL1TAG_C -#define BTAGTOOLS_DL1TAG_C - -/****************************************************** - @class DL1Tag - Package : JetTagTools - Created : September 2015 - DESCRIPTION: - This class computes the Neural Network probability for being b-jet, - c-jet or uds-jet for a single event. - @authors Dan Guest, Luke de Oliveira, Marie Lanfermann -********************************************************/ -#include "AthenaBaseComps/AthAlgTool.h" -#include "JetTagTools/IMultivariateJetTagger.h" -#include "JetTagCalibration/JetTagCalibCondData.h" - -#include <vector> -#include <istream> -#include <atomic> - -namespace xAOD { - class Vertex_v1; - typedef Vertex_v1 Vertex; -} - -namespace lwt { - class LightweightNeuralNetwork; -} - -namespace Analysis { - - class DL1Tag : public extends<AthAlgTool, IMultivariateJetTagger> - { - public: - DL1Tag(const std::string& name, - const std::string& n, - const IInterface*); - - virtual ~DL1Tag(); - virtual StatusCode initialize() override; - virtual StatusCode finalize() override; - - virtual - void assignProbability(xAOD::BTagging* BTag, - const std::map<std::string,double>& inputs, - const std::string& jetauthor) const override; - - private: - typedef std::map<std::string, double> var_map; - - /** Key of calibration data: */ - SG::ReadCondHandleKey<JetTagCalibCondData> m_readKey{this, "HistosKey", "JetTagCalibHistosKey", "Key of input (derived) JetTag calibration data"}; - std::unique_ptr<const lwt::LightweightNeuralNetwork> - load_calibration(const std::string& jetauthor, - std::vector<lwt::Input>& variables, - var_map& defaults) const; - - std::unique_ptr<const lwt::LightweightNeuralNetwork> - build_nn(std::istream& nn_config_istream, - std::vector<lwt::Input>& variables, - var_map& defaults) const; - void fill_outputs(xAOD::BTagging* BTag, var_map outputs) const; - - std::string m_calibrationDirectory; - std::string m_calibrationSubDirectory; - std::string m_xAODBaseName; - bool m_forceDL1CalibrationAlias; - std::string m_DL1CalibAlias; - - std::unique_ptr<const lwt::LightweightNeuralNetwork> m_localNN; - var_map m_local_defaults; - std::vector<lwt::Input> m_local_variables; - - //error checking - mutable std::atomic<int> m_n_compute_errors; - - std::string m_LocalNNConfigFile; - - /** This switch is needed to indicate what to do. The algorithm can be run to produce - reference histograms from the given MC files (m_runModus=0) or to work in analysis mode - (m_runModus=1) where already made reference histograms are read.*/ - std::string m_runModus; //!< 0=Do not read histos, 1=Read referece histos (analysis mode) - }; // end class - -}// end Analysis namespace - -#endif diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ExKtbbTag.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ExKtbbTag.h deleted file mode 100644 index 5be2fea17730cdd30214484497e554c7c4601d14..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ExKtbbTag.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef JETTAGTOOLS_EXKTBBTAG_H -#define JETTAGTOOLS_EXKTBBTAG_H - -/****************************************************** - @class ExKtbbTag - Identification of double b-hadron jets - @ author Qi Zeng -********************************************************/ - -#include "AthenaBaseComps/AthAlgTool.h" -#include "GaudiKernel/ToolHandle.h" -#include "JetTagTools/ITagTool.h" - -// std -#include <string> - -// xAOD EDM -#include "xAODTracking/VertexContainer.h" -#include "xAODJet/JetContainer.h" -#include "xAODBTagging/BTaggingContainer.h" -#include "xAODBTagging/BTagVertexContainer.h" - -// ROOT -#include "TLorentzVector.h" - -// TMVA -#include "TMVA/IMethod.h" -#include "TMVA/MethodBase.h" -namespace TMVA { class Reader; } - -// CalibrationBroker -namespace Analysis { class CalibrationBroker; } - -typedef Eigen::Matrix<double, 3, 3, 0, 3, 3> AmgSymMatrix3D; - -namespace Analysis { - - class ExKtbbTag : public AthAlgTool , virtual public ITagTool { - - public: - ExKtbbTag(const std::string&,const std::string&,const IInterface*); - - /** - Implementations of the methods defined in the abstract base class - */ - virtual ~ExKtbbTag(); - StatusCode initialize(); - StatusCode finalize(); - - /** Set the primary vertex. TODO: This is temporary ! The primary vertex should - be part of the JetTag IParticle interface implementation. The trouble with - ElementLink and persistency has to be solved for that. Revisit ... */ - void setOrigin(const xAOD::Vertex* priVtx); - - StatusCode tagJet(xAOD::Jet& jetToTag, xAOD::BTagging* BTag, const std::string &jetName); - - void finalizeHistos() {}; - - private: - - // global variables // - - std::string m_runModus; // "reference" means to produce variables for performance study; "analysis" means output weight with given reference histogram - std::string m_tagMode; // "Hbb", or "gbb" - std::string m_BDTMode; // "MV2Only", "MV2andJFDRSig", or "MV2andTopos" - std::string m_taggerNameBase; // prefix in BTaggingContainer -- mostly used in code - std::string m_xAODBaseName; // something required by base class - std::string m_ForceCalibChannel; // force to use this jet channel in calibration broker. Empty means default jet author. "Default" means "AntiKt10LCTopoTrimmedPtFrac5SmallR20" in "Hbb" tagMode and "AntiKt4LCTopo" in "gbb" tagMode - bool m_debug; - - // variables for tagger // - - std::string m_SubJetLabel; // label to access subjet information - bool m_JFOnlyVtx; // whether we insist JF should have at least one vtx with at least 2 tracks - - /** Storage for the primary vertex. Can be removed when JetTag provides origin(). */ - // this pointer does not need to be deleted in the destructor (because it - // points to something in storegate) - const xAOD::Vertex* m_priVtx = 0; - - /////////////////////////////////////////////// - // Functions related to variable calculation // - /////////////////////////////////////////////// - - // high-level functionality // - - bool CalculateInputVariables(xAOD::Jet& jetToTag, xAOD::BTagging* BTag); - - bool JetTagAnalysisMode(xAOD::Jet& jetToTag, xAOD::BTagging* BTag); - bool JetTagReferenceMode(xAOD::Jet& jetToTag, xAOD::BTagging* BTag); - - // medium-level functionality// - - double GetDoubleMV2c20(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2); - double GetSingleMV2c20(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2); - - int GetSV1NtrksDiff(const xAOD::BTagging* bjet, const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool doValidDualSV1); - int GetJFNtrksDiff(const xAOD::BTagging* bjet, const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool doValidDualJF, bool onlyVtx); - - double GetSV1CombMass(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool doValidDualSV1); - double GetJFCombMass(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool doValidDualJF, bool onlyVtx, bool doNeutralCorrection); - - double GetSV1DRSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, double& DR, double& DR_error); - double GetJFDRSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool onlyVtx, double& DR, double& DR_error); - - double GetSV1DR3DSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, double& dR3D, double& dR3D_error); - - double GetSV1DLSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, double& dL, double& dL_error); - double GetJFDLSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool onlyVtx, double& dL, double& dL_error); - - // low-level functionality // - - static bool SortPt(const xAOD::Jet* j1, const xAOD::Jet* j2) {return j1->pt() > j2->pt();} - - std::vector<const xAOD::Vertex*> GetSV1vertices(const xAOD::BTagging* bjet); - bool IsValidSV1(std::vector<const xAOD::Vertex*> input); - bool SV1DualValid(std::vector<const xAOD::Vertex*> vtx1, std::vector<const xAOD::Vertex*> vtx2); - - std::vector<const xAOD::BTagVertex*> GetJFVertices(const xAOD::BTagging* bjet); - std::vector<float> GetJFfittedPosition(const xAOD::BTagging* bjet, std::vector<float>& JFfittedCov); - bool IsValidJF(const xAOD::BTagging* bjet, bool onlyVtx); - bool JFDualValid(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool onlyVtx); - int JFntrk(const xAOD::BTagging* bjet, bool onlyVtx); - TLorentzVector JFMomentum(const xAOD::BTagging* bjet, bool onlyVtx, bool doNeutralCorrection); - double JFEffectiveDecayLength(const xAOD::BTagging* bjet, bool onlyVtx, double& error); - - double LimitUpperBound(double input, double start, double limit){ - if(input > start) return start + (limit-start)/TMath::Pi()*2.*TMath::ATan(TMath::Pi()/2./(limit-start)*(input-start)); - else return input; - } - - std::vector<Amg::Vector3D> GetVtxEigenVariation(Amg::Vector3D vtxPosition, AmgSymMatrix3D vtxCovMatrix); - double GeneralDRSignificance3D(Amg::Vector3D vtx1, AmgSymMatrix3D vtx1_CovMatrix, Amg::Vector3D vtx2, AmgSymMatrix3D vtx2_CovMatrix, double& dR3D, double& dR3D_error); - - //////////////////////////////////// - // Functions related to final BDT // - //////////////////////////////////// - - std::string m_taggerName; // actual taggerName - - ToolHandle<CalibrationBroker> m_calibrationTool; - - std::map<std::string, TMVA::Reader*> m_tmvaReaders; // key should be alias + m_taggerCalibName - std::map<std::string, TMVA::MethodBase*> m_tmvaMethod; // key should be alias + m_taggerCalibName - std::vector<std::string> m_undefinedReaders; - - std::string GetPtBin(const xAOD::Jet* jetToTag); - - std::map<std::string, float*> m_tmvaVariables; // key should be the same as those used in BDT - bool InitTMVAVariables(std::string BDTMode); - bool FillTMVAVariables(std::string BDTMode, const xAOD::Jet* jetToTag, const xAOD::BTagging* BTag); - bool BundleTMVAVariables(std::string BDTMode, TMVA::Reader* tmvaReader); - - std::vector<double> m_ptbinlist; - - - }; // End class - - inline void ExKtbbTag::setOrigin(const xAOD::Vertex* priVtx) { m_priVtx = priVtx; } - -} // End namespace - -#endif diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ExKtbbTagTool.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ExKtbbTagTool.h deleted file mode 100644 index 13f639fb112d074efc7645d0b97d3e05d0ed5c21..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/ExKtbbTagTool.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef JETTAGTOOLS_EXKTBBTAGTOOL_H -#define JETTAGTOOLS_EXKTBBTAGTOOL_H - -/* - Author : Qi Zeng - Email : qzeng@cern.ch - - This is a Tool based on JetModifierBase, to run exclusive kt algorithm on any existing jet collection - Many thanks to Giordon Stark and Miles Wu who actually implement the exclusive kt subjet finder in JetEtMiss pkg - and help me setup this in b-tagging pkg - - This tool is supposed to be called by a stand-alone algorithm that will call in the jet collection from event store and - load JetModifiers. It should be run before the b-tagging, but after jet finding - - This is basically just an interface to call SubjetFinderTool. However, we need to overwrite some subjet collection information, - which might be important for b-tagging purpose -*/ - -#include "JetRec/JetModifierBase.h" -#include "AsgTools/ToolHandle.h" -#include "JetSubStructureMomentTools/SubjetRecorderTool.h" -#include "JetSubStructureUtils/SubjetFinder.h" - -namespace Analysis{ - -class ExKtbbTagTool : public JetModifierBase { - ASG_TOOL_CLASS(ExKtbbTagTool, IJetModifier) - - public: - // Constructor from tool name. - ExKtbbTagTool(std::string myname); - - virtual StatusCode initialize(); - - // Inherited method to modify a jet. - virtual int modifyJet(xAOD::Jet& jet) const; - - private: - // subjet finding parameter - std::string m_JetAlgorithm; - float m_JetRadius; - float m_PtMin; - int m_ExclusiveNJets; - - // related to subjet recording - std::string m_InputJetContainerName; // Mainly used to build correct link from subjet to parent jet - ToolHandle<ISubjetRecorderTool> m_SubjetRecorderTool; - - - std::string m_SubjetLabel; // must be exactly the same label as the one used by SubjetRecorder inside SubjetFinder. - // At this moment, there is no way to figure out this name given SubjetFinderTool - std::string m_SubjetContainerName; // must be exactly the same container name as the one used by SubjetRecorder inside SubjetFinder. - // At this moment, there is no way to figure out this name given SubjetFinderTool - std::string m_SubjetAlgorithm_BTAG; - float m_SubjetRadius_BTAG; - - std::vector<fastjet::PseudoJet> constituentPseudoJets(xAOD::Jet& jet) const; -}; - -} - -#endif diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/IPTag.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/IPTag.h index 1bae284ddb9660df937ec4b571a6e278951c2f60..9a9b0ef2fa2da2d0f78598ad3952891eafac8563 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/IPTag.h +++ b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/IPTag.h @@ -24,7 +24,6 @@ namespace Reco { class ITrackToVertex; } namespace Trk { class ITrackToVertexIPEstimator; } // following two are temporary (to be moved to a separate Tool) namespace InDet { class IInDetTrackSelectionTool; } -namespace CP { class ITrackVertexAssociationTool;} namespace Analysis { @@ -162,10 +161,6 @@ namespace Analysis { /** InDetTrackSelectorTool (temporary: to be moved to a separate Tool) */ ToolHandle< InDet::IInDetTrackSelectionTool > m_InDetTrackSelectorTool; - /** TrackVertex associator (temporary: to be moved to a separate Tool) */ - ToolHandle< CP::ITrackVertexAssociationTool > m_TightTrackVertexAssociationTool; - - // VD: for debugging mutable std::atomic<int> m_nbjet; mutable std::atomic<int> m_ncjet; diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/MultivariateTagManager.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/MultivariateTagManager.h index dad842cb602620ede8b8e7e7255d3327b4a0785f..22bdbfc75b207f1847e2fa457f4e7c5d4b679474 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/MultivariateTagManager.h +++ b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/MultivariateTagManager.h @@ -57,7 +57,6 @@ namespace Analysis { void fill_sv1(var_map& inputs, xAOD::BTagging& BTag) const; void fill_jetfitter(var_map& inputs, xAOD::BTagging& BTag) const; void fill_mvb(var_map& inputs, xAOD::Jet& jet, xAOD::BTagging& BTag) const; - void fill_mv2cl100(var_map& inputs, xAOD::BTagging& BTag) const; void fill_trkSum(var_map& inputs, xAOD::BTagging& BTag) const; void fill_softmuon(var_map& inputs, xAOD::BTagging& BTag) const; diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/RNNIPTag.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/RNNIPTag.h deleted file mode 100644 index bf571e5354f350325cbcd8774be426cc8e3c9273..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/RNNIPTag.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef JETTAGTOOLS_RNNIPTAG_H -#define JETTAGTOOLS_RNNIPTAG_H - -/****************************************************** - @class RNNIPTag - b-jet tagger based on 2D or 3D impact parameter - @author CPPM Marseille -********************************************************/ - -#include "AthenaBaseComps/AthAlgTool.h" -#include "GaudiKernel/ToolHandle.h" -#include "CxxUtils/checker_macros.h" -#include "JetTagTools/ITagTool.h" -#include "JetTagCalibration/JetTagCalibCondData.h" - -#include "xAODTracking/TrackParticleContainerFwd.h" - -#include <vector> -#include <functional> -#include <memory> -#include <sstream> -#include <mutex> - -namespace Reco { class ITrackToVertex; } -namespace Trk { class ITrackToVertexIPEstimator; } -// following two are temporary (to be moved to a separate Tool) -namespace InDet { class IInDetTrackSelectionTool; } -namespace CP { class ITrackVertexAssociationTool;} - -namespace lwt { - class LightweightRNN; - struct JSONConfig; - typedef std::map<std::string, double> ValueMap; -} - -namespace Analysis { - - - class IPInfo; - class TrackSelector; - class TrackGrade; - class GradedTrack; - class TrackGradePartition; - class SVForIPTool; - class ITrackGradeFactory; - - // track struct, and sorting functions - struct IPxDInfo; - typedef std::function<bool(const IPxDInfo&, const IPxDInfo&)> TrackSorter; - - class RNNIPTag : public extends<AthAlgTool, ITagTool> - { - public: - RNNIPTag(const std::string&,const std::string&,const IInterface*); - - /** - Implementations of the methods defined in the abstract base class - */ - virtual ~RNNIPTag(); - virtual StatusCode initialize() override; - virtual StatusCode finalize() override; - - virtual StatusCode tagJet(const xAOD::Vertex& priVtx, - const xAOD::Jet& jetToTag, - xAOD::BTagging& BTag, - const std::string &jetName) const override; - - virtual void finalizeHistos() override {} - - private: - - std::vector<IPxDInfo> get_track_info( - const xAOD::Vertex& priVtx, - const std::vector<GradedTrack>&, - const Amg::Vector3D& unit, - const std::vector<const xAOD::TrackParticle*>& v0_tracks) const; - - void add_tags(xAOD::BTagging& tag, const std::string& author, - std::vector<IPxDInfo>& tracks) const; - - /** base name string for persistification in xaod */ - std::string m_xAODBaseName; - - /// VD: bool switches - bool m_flipIP; // reverse impact parameter signs for - // negative tag calibration method - bool m_flipZIP; // reverse Z impact parameter signs - // for negative tag calibration method - bool m_usePosIP; // use tracks with positive impact - // parameter for tagging - bool m_useNegIP; // use tracks with negative impact - // parameter for tagging - bool m_useZIPSignForPosNeg; // use Z impact parameter sign as well - // to select Pos and Neg tracks - bool m_use2DSignForIP3D; // force to use 2D IP sign even for IP3D IP - bool m_useD0SignForZ0; // force to use transverse IP sign for - // Z impact parameter for IP3D - bool m_rejectBadTracks; // TODO: Do we need this? - // bool m_SignWithSvx; - bool m_unbiasIPEstimation; // remove track from vertex when computing IP - - // we can save the sorted inputs for each tagger for debugging and - // optimization - bool m_writeInputsToBtagObject; - bool m_writeTrackLinks; - - //// VD: other (non-bool) configurables - /** Name of the track-to-jet association in the BTagging object */ - std::string m_trackAssociationName; - - /** Key of calibration data: */ - SG::ReadCondHandleKey<JetTagCalibCondData> m_readKey{this, "HistosKey", "JetTagCalibHistosKey", "Key of input (derived) JetTag calibration data"}; - /** forcing the calibration folder of a given collection */ - std::string m_ForcedCalibName; - - // Initalize with a config name and path to a network If the - // network path is empty we read from the calib db Note that this - // won't support reading different local files for different jet - // collections. - std::map<std::string, std::string > m_network_cfg; - - // At runtime, we can run a list of networks for each track - // sorting. Networks include the configuration name, which is used - // for the DB lookup and to name the saved output. - // - // This structure also owns the network instance. - struct Network { - Network(const std::string& name, const lwt::JSONConfig&); - std::string name; - std::shared_ptr<lwt::LightweightRNN> network; - std::vector<std::string> outputs; - }; - typedef std::vector<Network> Networks; - - // Each network list is grouped with its sort function. - typedef std::vector<std::pair<TrackSorter, Networks> > SortGroups; - mutable std::map<std::string, SortGroups > m_networks ATLAS_THREAD_SAFE; - // Serialize access to m_networks. - mutable std::mutex m_networksMutex ATLAS_THREAD_SAFE; - - // load the calibration file from the COOL db - const SortGroups& get_networks_for(const std::string& author) const; - //void register_hist(const std::string& name = "/rnnip"); - std::string get_calib_string( - const std::string& author, - const std::string& name = "/rnnip") const; - std::string m_calibrationDirectory; - - /** names of fools for getting the secondary vertex information */ - std::string m_secVxFinderNameForV0Removal; - std::string m_secVxFinderNameForIPSign; - std::string m_secVxFinderName; - - //// VD: auxiliary information to be stored - /** information to persistify: */ - std::string m_originalTPCollectionName; - //const xAOD::TrackParticleContainer* m_originalTPCollection; - /** track classification. */ - std::vector<std::string> m_trackGradePartitionsDefinition; - std::vector<TrackGradePartition*> m_trackGradePartitions; - - //// VD: list of tools below - /** Track selection cuts for IPTagging */ - ToolHandle< TrackSelector > m_trackSelectorTool; - - /** Pointer to the SV tool */ - ToolHandle< SVForIPTool > m_SVForIPTool; - - /** ToolHandle for the ITrackGradeFactory tool */ - ToolHandle< ITrackGradeFactory > m_trackGradeFactory; - - /** GP: Tool for the estimation of the IPs to the Vertex */ - ToolHandle< Trk::ITrackToVertexIPEstimator > m_trackToVertexIPEstimator; - - // VD: for debugging - //int m_nbjet; - //int m_ncjet; - //int m_nljet; - - }; // End class - -} // End namespace - -#endif diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/SVTag.h b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/SVTag.h index 731c86cf9a06a64407919b7ed67cbc5167596425..86b20365b75ad975dfa88762df6db0168fa3bddd 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/SVTag.h +++ b/PhysicsAnalysis/JetTagging/JetTagTools/JetTagTools/SVTag.h @@ -99,6 +99,7 @@ namespace Analysis // flag to turn ON/OFF the use of \DeltaR(jet,PV-SV) in the likelihood bool m_useDRJPVSV; bool m_isFlipped; // true if tagger is configured in flipped mode. in that case adjusts DRJPVSV computation + bool m_save_probabilities; }; // End class diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/python/DL1TagConfig.py b/PhysicsAnalysis/JetTagging/JetTagTools/python/DL1TagConfig.py deleted file mode 100644 index eb8b81c993d616ebe197c4c049a2a67129539cd0..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/python/DL1TagConfig.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration - -from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator -from AthenaConfiguration.ComponentFactory import CompFactory - -# import the DL1Tag configurable -Analysis__DL1Tag=CompFactory.Analysis.DL1Tag - -# define the class -def DL1TagCfg(flags, name = 'DL1', scheme = '', useBTagFlagsDefaults = True, **options): - """Sets up a DL1Tag tool and returns it. - - The following options have BTaggingFlags defaults: - - Runmodus default: BTagging.RunModus - taggerName default: "DL1" - taggerNameBase default: "DL1" - forceDL1CalibrationAlias default: BTaggingFlags.ForceDL1CalibrationAlias - DL1CalibAlias default: BTaggingFlags.DL1CalibAlias - - input: name: The name of the tool (should be unique). - useBTagFlagsDefaults : Whether to use BTaggingFlags defaults for options that are not specified. - **options: Python dictionary with options for the tool. - output: The actual tool""" - acc = ComponentAccumulator() - options['name'] = name + 'Tag' - basename = name - DL1LocalNNConfig = '' - ForceDL1CalibrationAlias = True - DL1CalibAlias = 'AntiKt4EMTopo' - options['xAODBaseName'] = basename - options['LocalNNConfigurationFile'] = DL1LocalNNConfig - if scheme == 'Trig': - options['HistosKey'] = 'JetTagTrigCalibHistosKey' - - if useBTagFlagsDefaults: - defaults = { 'Runmodus' : flags.BTagging.RunModus, - 'forceDL1CalibrationAlias' : ForceDL1CalibrationAlias, - 'DL1CalibAlias' : DL1CalibAlias, - 'calibration_directory' : basename, - } - for option in defaults: - options.setdefault(option, defaults[option]) - acc.setPrivateTools(Analysis__DL1Tag(**options)) - - return acc diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/python/IP3DTagConfig.py b/PhysicsAnalysis/JetTagging/JetTagTools/python/IP3DTagConfig.py index 52c8d9d768a0ca2a7c473ea462c2bfe359516e03..67e32dd93f4d6f2909f82a6bc56bfe2caa7ae3b7 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/python/IP3DTagConfig.py +++ b/PhysicsAnalysis/JetTagging/JetTagTools/python/IP3DTagConfig.py @@ -8,7 +8,6 @@ from JetTagTools.IPDetailedTrackGradeFactoryConfig import IPDetailedTrackGradeFa from JetTagTools.IPTrackSelectorConfig import IPTrackSelectorCfg from JetTagTools.NewLikelihoodToolConfig import NewLikelihoodToolCfg from JetTagTools.InDetTrackSelectorConfig import InDetTrackSelectorCfg -from JetTagTools.SpecialTrackAssociatorConfig import SpecialTrackAssociatorCfg # import the IPTag configurable Analysis__IPTag=CompFactory.Analysis.IPTag @@ -44,7 +43,6 @@ def IP3DTagCfg( flags, name = 'IP3DTag', PrimaryVertexCollectionName="", scheme trackSelectorTool = acc.popToolsAndMerge(IPTrackSelectorCfg(flags, 'IP3DTrackSelector')) likelihood = acc.popToolsAndMerge(NewLikelihoodToolCfg(flags, 'IP3DNewLikelihoodTool', 'IP3D', scheme)) inDetTrackSelectionTool = acc.popToolsAndMerge(InDetTrackSelectorCfg('InDetTrackSelector')) - trackVertexAssociationTool = acc.popToolsAndMerge(SpecialTrackAssociatorCfg('SpecialTrackAssociator', PrimaryVertexCollectionName)) defaults = { 'Runmodus' : flags.BTagging.RunModus, 'referenceType' : flags.BTagging.ReferenceType, @@ -65,7 +63,6 @@ def IP3DTagCfg( flags, name = 'IP3DTag', PrimaryVertexCollectionName="", scheme 'trackGradeFactory' : trackGradeFactory, 'TrackToVertexIPEstimator' : trackToVertexIPEstimator, 'InDetTrackSelectionTool' : inDetTrackSelectionTool, - 'TrackVertexAssociationTool' : trackVertexAssociationTool, } for option in defaults: options.setdefault(option, defaults[option]) diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/python/MultivariateTagManagerConfig.py b/PhysicsAnalysis/JetTagging/JetTagTools/python/MultivariateTagManagerConfig.py index 312896d3ab795722a887f6a218199b0d052ed0a3..2a5c963d3a5279be4886c5d7da10593b9775bd5f 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/python/MultivariateTagManagerConfig.py +++ b/PhysicsAnalysis/JetTagging/JetTagTools/python/MultivariateTagManagerConfig.py @@ -2,7 +2,6 @@ from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.ComponentFactory import CompFactory -from JetTagTools.DL1TagConfig import DL1TagCfg from JetTagTools.MV2TagConfig import MV2TagCfg # import the MultivariateTagManager configurable @@ -26,23 +25,11 @@ def MultivariateTagManagerCfg(flags, name = 'MultivariateTagManager', TaggerList MultivariateTagManagerAuxBranches = [] MultivariateTagManagerAuxBranches += ['SMT_discriminant'] #ATLASRECTS-5381 - if 'DL1rnn' in TaggerList or 'MV2c10rnn' in TaggerList: + if 'MV2c10rnn' in TaggerList: #RNNIP output variables are needed rnnip_outputs = ['b','c','u','tau'] MultivariateTagManagerAuxBranches += ['rnnip_p' + x for x in rnnip_outputs] - if 'DL1' in TaggerList: - dl1 = acc.popToolsAndMerge(DL1TagCfg(flags, 'DL1', scheme)) - mvtagtoollist.append(dl1) - - if 'DL1mu' in TaggerList: - dl1 = acc.popToolsAndMerge(DL1TagCfg(flags, 'DL1mu', scheme)) - mvtagtoollist.append(dl1) - - if 'DL1rnn' in TaggerList: - dl1 = acc.popToolsAndMerge(DL1TagCfg(flags, 'DL1rnn', scheme)) - mvtagtoollist.append(dl1) - if 'MV2c10' in TaggerList: mv2 = acc.popToolsAndMerge(MV2TagCfg(flags, 'MV2c10', scheme)) mvtagtoollist.append(mv2) @@ -55,15 +42,6 @@ def MultivariateTagManagerCfg(flags, name = 'MultivariateTagManager', TaggerList mv2 = acc.popToolsAndMerge(MV2TagCfg(flags, 'MV2c10rnn', scheme)) mvtagtoollist.append(mv2) - if 'MV2c100' in TaggerList: - mv2 = acc.popToolsAndMerge(MV2TagCfg(flags, 'MV2c100', scheme)) - mvtagtoollist.append(mv2) - - - if 'MV2cl100' in TaggerList: - mv2 = acc.popToolsAndMerge(MV2TagCfg(flags, 'MV2cl100', scheme)) - mvtagtoollist.append(mv2) - #Check if input has been scheduled #if IP2D not added .... diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/python/RNNIPTagConfig.py b/PhysicsAnalysis/JetTagging/JetTagTools/python/RNNIPTagConfig.py deleted file mode 100644 index 94133fd92a528657f0cf4dadc0aa22405ffcbe35..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/python/RNNIPTagConfig.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration - -from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator -from AthenaConfiguration.ComponentFactory import CompFactory -from JetTagTools.BTagTrackToVertexIPEstimatorConfig import BTagTrackToVertexIPEstimatorCfg -from JetTagTools.SVForIPToolConfig import SVForIPToolCfg -from JetTagTools.IPDetailedTrackGradeFactoryConfig import IPDetailedTrackGradeFactoryCfg -from JetTagTools.IPTrackSelectorConfig import IPTrackSelectorCfg - -# import the IPTag configurable -Analysis__RNNIPTag=CompFactory.Analysis.RNNIPTag - -def RNNIPTagCfg( flags, name = 'RNNIP', scheme = '', calibration=None, useBTagFlagsDefaults = True, **options ): - """Sets up a RNNIPTag tool and returns it. - - The following options have BTaggingFlags defaults: - - trackGradePartitions default: [ "Good", "BlaShared", "PixShared", "SctShared", "0HitBLayer" ] - RejectBadTracks default: False - SecVxFinderName default: "SV1" - - input: name: The name of the tool (should be unique). - useBTagFlagsDefaults : Whether to use BTaggingFlags defaults for options that are not specified. - **options: Python dictionary with options for the tool. - output: The actual tool.""" - - acc = ComponentAccumulator() - options['name'] = name - basename = 'RNNIP' - RNNIPConfig = {'rnnip':''} - WriteRNNInputs = False - options['xAODBaseName'] = basename - options['trackAssociationName'] = 'BTagTrackToJetAssociator' - if scheme == 'Trig': - options['HistosKey'] = 'JetTagTrigCalibHistosKey' - cal_dir = calibration or basename - is_flipped=False - if (scheme == "Flip"): - is_flipped=True - - if useBTagFlagsDefaults: - trackToVertexIPEstimator = acc.popToolsAndMerge(BTagTrackToVertexIPEstimatorCfg(flags, 'TrkToVxIPEstimator')) - svForIPTool = acc.popToolsAndMerge(SVForIPToolCfg('SVForIPTool')) - trackGradeFactory = acc.popToolsAndMerge(IPDetailedTrackGradeFactoryCfg('RNNIPDetailedTrackGradeFactory')) - trackSelectorTool = acc.popToolsAndMerge(IPTrackSelectorCfg(flags, 'RNNIPTrackSelector')) - - defaults = { - 'trackGradePartitions' : flags.BTagging.Grades, - 'RejectBadTracks' : True, - 'NetworkConfig' : RNNIPConfig, - 'unbiasIPEstimation' : False, - 'SecVxFinderName' : 'SV1', - 'calibration_directory' : cal_dir, - 'writeInputsToBtagObject' : WriteRNNInputs, - 'trackSelectorTool' : trackSelectorTool, - 'SVForIPTool' : svForIPTool, - 'trackGradeFactory' : trackGradeFactory, - 'TrackToVertexIPEstimator' : trackToVertexIPEstimator, - } - if is_flipped: - defaults.update({ - 'flipIPSign' : True, - 'usePosIP' : True, - 'useNegIP' : False, - }) - - for option in defaults: - options.setdefault(option, defaults[option]) - - acc.setPrivateTools(Analysis__RNNIPTag( **options)) - - return acc diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/DL1Tag.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/DL1Tag.cxx deleted file mode 100644 index 908f1a7982bff94fb8c0ff8279fed4b4b3956566..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/DL1Tag.cxx +++ /dev/null @@ -1,274 +0,0 @@ -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -////////////////////////////////////////////////////////////////////////////// -/// Name : DL1Tag -/// Package : JetTagTools -/// Author : Marie Lanfermann (Universite de Geneve), Dan Guest (UC Irvine) -/// Created : 2015 -/// -/// DESCRIPTION: -/// -/// This class computes the Neural Network probability for being b-jet, -/// c-jet or uds-jet for a single event. The NN is constructed outside Atheana -/// using standard Data Science libraries, i.e. Keras (Theano or TensorFlow backend) -/// for the actual training. -/// -///////////////////////////////////////////////////////////////////////////// - -#include "GaudiKernel/IToolSvc.h" -#include "xAODTracking/TrackParticle.h" - -#include "JetTagTools/DL1Tag.h" - -#include "xAODBTagging/BTagging.h" -#include "xAODJet/Jet.h" - -#include "TObjString.h" - -#include <fstream> -#include <sstream> -#include <algorithm> -#include <iostream> -#include <limits> -#include <cmath> - -namespace{ - // copy the inputs, but with NaN replaced with default values. Don't - // do anything with NaN values with no defined default. - std::map<std::string, double> replace_nan_with_defaults( - const std::map<std::string, double>& inputs, - const std::map<std::string, double>& defaults); - - std::map<std::string, double> add_check_variables( - const std::map<std::string, double>& inputs); - - // use this value when an output isn't defined by the NN - const double missing_weight = 0.; -} - -namespace Analysis { - - DL1Tag::DL1Tag(const std::string& name, const std::string& n, const IInterface* p): - base_class(name, n,p), - m_calibrationDirectory("DL1"), - m_n_compute_errors(0), - m_runModus("analysis") - { - // access to JSON NN configuration file from COOL: - declareProperty("calibration_directory", m_calibrationDirectory); - declareProperty("forceDL1CalibrationAlias", m_forceDL1CalibrationAlias = true); - declareProperty("DL1CalibAlias", m_DL1CalibAlias = "AntiKt4TopoEM"); - declareProperty("xAODBaseName", m_xAODBaseName); - - // global configuration - declareProperty("Runmodus", m_runModus); - declareProperty("LocalNNConfigurationFile", m_LocalNNConfigFile); - } - - DL1Tag::~DL1Tag() { - } - - StatusCode DL1Tag::initialize() { - // prepare readKey for calibration data: - ATH_CHECK(m_readKey.initialize()); - - // Read in the configuration of the neural net for DL1: - if (m_LocalNNConfigFile.size() != 0) { // retrieve map of NN config and default values from local JSON file - std::ifstream nn_config_ifstream(m_LocalNNConfigFile); - m_localNN = build_nn(nn_config_ifstream, - m_local_variables, - m_local_defaults); - } - else { // done in condition algorithm - } - - ATH_MSG_DEBUG(" Initialization of DL1Tag successful" ); - return StatusCode::SUCCESS; - } - - - std::unique_ptr<const lwt::LightweightNeuralNetwork> - DL1Tag::build_nn(std::istream& nn_config_istream, - std::vector<lwt::Input>& variables, - var_map& defaults) const - { - lwt::JSONConfig nn_config = lwt::parse_json(nn_config_istream); - ATH_MSG_DEBUG("#BTAG# making NN with " << nn_config.layers.size() << " layers"); - - if (!(std::find((nn_config.outputs).begin(), (nn_config.outputs).end(), "bottom") != (nn_config.outputs).end())) { - ATH_MSG_WARNING( "#BTAG# b-tagger without b-tagging option 'bottom' - please check the NN output naming convention."); - } - - defaults = std::move(nn_config.defaults); - variables = std::move(nn_config.inputs); - return std::make_unique<lwt::LightweightNeuralNetwork>(variables, nn_config.layers, nn_config.outputs); - } - - std::unique_ptr<const lwt::LightweightNeuralNetwork> - DL1Tag::load_calibration(const std::string& jetauthor, - std::vector<lwt::Input>& variables, - var_map& defaults) const - { - SG::ReadCondHandle<JetTagCalibCondData> readCdo(m_readKey); - lwt::JSONConfig nn_config = readCdo->retrieveDL1NN(m_calibrationDirectory , jetauthor); - - if (nn_config.layers.size() == 0){ //catch if no NN config was found - std::string fuller_name = m_calibrationDirectory + "/" + - jetauthor + "/net_configuration"; - throw std::logic_error("Cannot retrieve NN config build from string: " + fuller_name); - } - - ATH_MSG_DEBUG("#BTAG# making NN with " << nn_config.layers.size() << " layers"); - - if (!(std::find((nn_config.outputs).begin(), (nn_config.outputs).end(), "bottom") != (nn_config.outputs).end())) { - ATH_MSG_WARNING( "#BTAG# b-tagger without b-tagging option 'bottom' - please check the NN output naming convention."); - } - defaults = std::move(nn_config.defaults); - variables = std::move(nn_config.inputs); - return std::make_unique<lwt::LightweightNeuralNetwork>(variables, nn_config.layers, nn_config.outputs); - } - - StatusCode DL1Tag::finalize() { // all taken care of in destructor - if (m_n_compute_errors > 0) { - ATH_MSG_WARNING("Neural network was unable to compute. Number of errors: "+ std::to_string(m_n_compute_errors)); - } - - ATH_MSG_DEBUG(" #BTAG# Finalization of DL1Tag successfull" ); - return StatusCode::SUCCESS; - } - - void DL1Tag::fill_outputs(xAOD::BTagging *BTag, var_map outputs) const { - if(m_runModus=="analysis") { - if (!outputs.count("charm")) { - BTag->setVariable<double>(m_xAODBaseName, "pc", missing_weight); - } - else if (outputs.count("charm")) { - BTag->setVariable<double>(m_xAODBaseName, "pc", outputs.at("charm")); - } - - if (!outputs.count("light") && !outputs.count("bottom")) { - BTag->setVariable<double>(m_xAODBaseName, "pu", missing_weight); - } - else if (outputs.count("light")) { - BTag->setVariable<double>(m_xAODBaseName, "pu", outputs.at("light")); - } - - if (outputs.count("bottom")) { - BTag->setVariable<double>(m_xAODBaseName, "pb", outputs.at("bottom")); - if (!outputs.count("light")) { - BTag->setVariable<double>(m_xAODBaseName, "pu", 1.-outputs.at("bottom")); - } - } - else if (!outputs.count("bottom")) { - BTag->setVariable<double>(m_xAODBaseName, "pb", missing_weight); - ATH_MSG_WARNING( "#BTAG# b-tagger without b-tagging option: " << outputs.at("bottom")); - } - ATH_MSG_DEBUG("#BTAG# NN output b: " << outputs.at("bottom") << - " c: " << outputs.at("charm") << " u: " << outputs.at("light")); - } - } - - void DL1Tag::assignProbability(xAOD::BTagging *BTag, - const var_map &inputs, - const std::string& assigned_jet_author) const - { - std::string jetauthor = assigned_jet_author; - - std::unique_ptr<const lwt::LightweightNeuralNetwork> nn; - const lwt::LightweightNeuralNetwork* nn_ptr = nullptr; - - var_map defaults; - const var_map* defaults_ptr; - - std::vector<lwt::Input> variables; - const std::vector<lwt::Input>* variables_ptr; - - if (m_LocalNNConfigFile.size()==0) { - if (m_forceDL1CalibrationAlias) { - jetauthor = m_DL1CalibAlias; - } - ATH_MSG_DEBUG("#BTAG# Jet author set (via forceDL1CalibrationAlias) to: " << jetauthor ); - if ( jetauthor.empty() ) { - ATH_MSG_WARNING(" #BTAG# Hypothesis or jetauthor is empty." - " No likelihood value given back. "); - } - try { - nn = load_calibration(jetauthor, variables, defaults); - nn_ptr = nn.get(); - defaults_ptr = &defaults; - variables_ptr = &variables; - } catch (std::exception& e) { - ATH_MSG_WARNING( - "problem loading calibration for " + jetauthor + - " (" + e.what() + "), skipping this jet"); - return; - } - } - else { - jetauthor = "local"; - nn_ptr = m_localNN.get(); - defaults_ptr = &m_local_defaults; - variables_ptr = &m_local_variables; - } - - var_map complete_inputs = add_check_variables(inputs); - var_map cleaned_inputs = replace_nan_with_defaults(complete_inputs, *defaults_ptr); - - for (const lwt::Input& var : *variables_ptr) { - if (cleaned_inputs.count(var.name) && std::isnan(cleaned_inputs.at(var.name))) { - ATH_MSG_WARNING( "#BTAG# 'nan' input for variable " + var.name + " --> will result in 'nan' classification output. Check NN configuration file for default settings."); - } - } - - var_map outputs; - try { - outputs = nn_ptr->compute(cleaned_inputs); - } catch (lwt::NNEvaluationException& e) { - ATH_MSG_WARNING("Can't compute outputs, probably missing input values"); - m_n_compute_errors++; - return; - } - - fill_outputs(BTag, outputs); - } //end assign_probability -} - -namespace { - std::map<std::string, double> replace_nan_with_defaults( - const std::map<std::string, double>& inputs, - const std::map<std::string, double>& defaults) { - // return a new map with the NaN values replaced where possible. - std::map<std::string, double> outputs; - - // loop over all inputs and create map of cleaned inputs - for (const auto& in: inputs) { - if (std::isnan(in.second) && defaults.count(in.first)) { - outputs[in.first] = defaults.at(in.first); - } else { - outputs[in.first] = in.second; - } - } - return outputs; - } // end replace_nan_with_defaults - - std::map<std::string, double> add_check_variables( - const std::map<std::string, double>& inputs) { - // return a new map with additional binary variables for each input variable - std::map<std::string, double> complete_inputs; - - for (const auto& in: inputs) { - // copy everything from the inputs map - complete_inputs.insert(std::make_pair(in.first, in.second)); - // add binary check variables - if (std::isnan(in.second)) { - complete_inputs.insert(std::make_pair(in.first + "_check", 1.)); - } - else { - complete_inputs.insert(std::make_pair(in.first + "_check", 0.)); - } - } - return complete_inputs; - }// end add_check_variables -} // end namespace diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/ExKtbbTag.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/ExKtbbTag.cxx deleted file mode 100644 index e6d2f803b6d19390f93215f951eeaaf7336d33da..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/ExKtbbTag.cxx +++ /dev/null @@ -1,1187 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -#include "JetTagTools/ExKtbbTag.h" - -#include "GaudiKernel/IToolSvc.h" -#include "xAODBTagging/SecVtxHelper.h" // extract SV information -#include "xAODTracking/TrackParticleContainer.h" - -#include <algorithm> -#include "TVector3.h" -#include "TMath.h" -#include "TList.h" -#include "TMVA/Reader.h" - -#include "JetTagCalibration/CalibrationBroker.h" - - -namespace Analysis { - -/** - @class ExKtbbTag - Identification of double b-hadron jets ( g->bb or H->bb jets) through exclusive kt subjet b-tagging - @author Qi. Zeng - - Input variables ("reference") are all computed in MeV - However, they are all converted to GeV when feeding into BDT, as the training was done in GeV -*/ - -ExKtbbTag::ExKtbbTag(const std::string& t, const std::string& n, const IInterface* p) - : AthAlgTool(t,n,p), - m_runModus("analysis"), - m_tagMode("Hbb"), - m_BDTMode("MV2andJFDRSig"), - m_taggerNameBase("ExKtbb"), - m_xAODBaseName("ExKtbb"), - m_ForceCalibChannel(""), - m_debug(false), - m_SubJetLabel("ExKt2SubJets"), - m_JFOnlyVtx(false), - m_calibrationTool("BTagCalibrationBroker") -{ - declareInterface<ITagTool>(this); - - // global configuration - declareProperty("Runmodus", m_runModus); - declareProperty("calibrationTool", m_calibrationTool); - declareProperty("tagMode", m_tagMode); - declareProperty("BDTMode", m_BDTMode); - declareProperty("taggerNameBase", m_taggerNameBase); - declareProperty("xAODBaseName", m_xAODBaseName); - declareProperty("ForceCalibrationChannel", m_ForceCalibChannel); - declareProperty("debug", m_debug); - - // variables for tagger - declareProperty("SubJetLabel", m_SubJetLabel); - declareProperty("JFOnlyVtx", m_JFOnlyVtx); - - m_priVtx = 0; -} - - -ExKtbbTag::~ExKtbbTag() { - // empty for now // -} - - -StatusCode ExKtbbTag::initialize() { - - // Actual tagger name // - - m_taggerName = m_taggerNameBase + "_" + m_tagMode; - - // PtBinList // - - m_ptbinlist = { // in GeV - 400., - 800., - 1250., - 2000., - 3000., - }; - - // Calibration Broker Initialization // - - StatusCode sc = m_calibrationTool.retrieve(); - if ( sc.isFailure() ) { - ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_calibrationTool); - return sc; - } else { - ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_calibrationTool); - } - - for(unsigned int index = 0; index < m_ptbinlist.size()-1; index++){ - TString tmp = TString::Format("PtBin%i", int(index)); - m_calibrationTool->registerHistogram(m_taggerNameBase, m_taggerNameBase + "Calib_" + m_tagMode + "_" + m_BDTMode + "_" + tmp.Data()); - } - - // clear relevant maps/vectors // - - m_tmvaReaders.clear(); - m_tmvaMethod.clear(); - m_undefinedReaders.clear(); - - // Initialize BDT variables // - - if(!InitTMVAVariables(m_BDTMode)){ - ATH_MSG_ERROR("#BTAG# Unable to initialize TMVA variables for ExKtbbTag"); - return StatusCode::FAILURE; - } - - return StatusCode::SUCCESS; -} - - -StatusCode ExKtbbTag::finalize() { - - // delete readers // - - std::map<std::string, TMVA::Reader*>::iterator pos = m_tmvaReaders.begin(); - for( ; pos != m_tmvaReaders.end(); ++pos ) delete pos->second; - std::map<std::string, TMVA::MethodBase*>::iterator posm = m_tmvaMethod.begin(); - for( ; posm != m_tmvaMethod.end(); ++posm ) delete posm->second; - - // delete BDT variables // - - std::map<std::string, float*>::iterator posv = m_tmvaVariables.begin(); - for( ; posv != m_tmvaVariables.end(); ++posv ) delete posv->second; - - return StatusCode::SUCCESS; -} - -StatusCode ExKtbbTag::tagJet(xAOD::Jet& jetToTag, xAOD::BTagging* BTag, const std::string &jetName) { - - // set jet author information // - - if(m_ForceCalibChannel.empty()){ - std::string alias = m_calibrationTool->channelAlias(jetname); - - m_ForceCalibChannel = alias; - } - else if(m_ForceCalibChannel == "Default"){ - if(m_tagMode == "Hbb") m_ForceCalibChannel = "AntiKt10LCTopoTrimmedPtFrac5SmallR20"; - else if(m_tagMode == "gbb") m_ForceCalibChannel = "AntiKt4LCTopo"; - else{ - ATH_MSG_ERROR("#BTAG# Undefined tag mode: " << m_tagMode.data()); - return StatusCode::FAILURE; - } - } - else{ - // empty // - } - - if(!CalculateInputVariables(jetToTag, BTag)){ - ATH_MSG_ERROR("Error in CalculateInputVariables()!"); - return StatusCode::FAILURE; - } - - if(m_runModus == "reference"){ - if(!JetTagReferenceMode(jetToTag, BTag)){ - ATH_MSG_ERROR("Error in JetTagReferenceMode()!"); - return StatusCode::FAILURE; - } - } - else if(m_runModus == "analysis"){ - if(!JetTagAnalysisMode(jetToTag, BTag)){ - ATH_MSG_ERROR("Error in JetTagAnalysisMode()!"); - return StatusCode::FAILURE; - } - } - else{ - ATH_MSG_ERROR("Unidentified run mode: " << m_runModus.c_str()); - return StatusCode::FAILURE; - } - - return StatusCode::SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////////////////////// - -bool ExKtbbTag::CalculateInputVariables(xAOD::Jet& jetToTag, xAOD::BTagging* BTag){ - if(m_debug) ATH_MSG_INFO("Entering CalculateInputVariables"); - - // Initialization - BTag->setVariable<double>(m_taggerName, "DoubleMV2c20", -1.1); - BTag->setVariable<double>(m_taggerName, "SingleMV2c20", -1.1); - - BTag->setVariable<int>(m_taggerName, "SV1NtrksDiff", -20); - BTag->setVariable<int>(m_taggerName, "JFNtrksDiff", -20); - - BTag->setVariable<double>(m_taggerName, "SV1CombMass", -1.); - BTag->setVariable<double>(m_taggerName, "JFCombMass", -1.); - - BTag->setVariable<double>(m_taggerName, "SV1DR", -1.); - BTag->setVariable<double>(m_taggerName, "SV1DRError", -1.); - BTag->setVariable<double>(m_taggerName, "SV1DRSignificance", -1.); - - BTag->setVariable<double>(m_taggerName, "JFDR", -1.); - BTag->setVariable<double>(m_taggerName, "JFDRError", -1.); - BTag->setVariable<double>(m_taggerName, "JFDRSignificance", -1.); - - BTag->setVariable<double>(m_taggerName, "SV1DR3D", -1.); - BTag->setVariable<double>(m_taggerName, "SV1DR3DError", -1.); - BTag->setVariable<double>(m_taggerName, "SV1DR3DSignificance", -1.); - - BTag->setVariable<double>(m_taggerName, "SV1DL", -1.); - BTag->setVariable<double>(m_taggerName, "SV1DLError", -1.); - BTag->setVariable<double>(m_taggerName, "SV1DLSignificance", -1.); - - BTag->setVariable<double>(m_taggerName, "JFDL", -1.); - BTag->setVariable<double>(m_taggerName, "JFDLError", -1.); - BTag->setVariable<double>(m_taggerName, "JFDLSignificance", -1.); - - if(m_debug) ATH_MSG_INFO("Fetching subjets"); - - // Bug fix in 20.7. Rebuild the link to subjet. - - auto SubjetContainer = evtStore()->tryRetrieve<xAOD::JetContainer>(jetToTag.auxdata<std::string>(m_SubJetLabel + "_ContainerName")); - if(SubjetContainer == 0){ - ATH_MSG_ERROR("Unable to get subjet container " << m_SubJetLabel << "_ContainerName !"); - return false; - } - - auto SubjetIndexList = jetToTag.auxdata<std::vector<int> >(m_SubJetLabel + "_IndexList"); - std::vector<const xAOD::Jet*> ExKtSubJets; - for(auto index : SubjetIndexList){ - ExKtSubJets.push_back(SubjetContainer->at(index)); - } - - // overwrite the original subjet link built in subjetrecorder, since it might be broken after b-tagging deep-copy - - jetToTag.setAssociatedObjects(m_SubJetLabel, ExKtSubJets); - - if(m_debug) ATH_MSG_INFO("Check if subjets ptr is valid"); - - // check if each subjet is valid - for(auto subjet : ExKtSubJets){ - if(!subjet){ - ATH_MSG_ERROR("Empty ptr to subjet! You will crash soon..."); - return false; - } - } - - if(m_debug) ATH_MSG_INFO("Sort subjets by pT"); - - std::sort(ExKtSubJets.begin(), ExKtSubJets.end(), ExKtbbTag::SortPt); - - if(m_debug) ATH_MSG_INFO("Begin computing inputs"); - - // validity check - if(ExKtSubJets.size() == 2){ - const xAOD::BTagging* bjet_LeadExKtSubJet = xAOD::BTaggingUtilities::getBTagging( *ExKtSubJets[0] ); - const xAOD::BTagging* bjet_SubLeadExKtSubJet = xAOD::BTaggingUtilities::getBTagging( *ExKtSubJets[1] ); - - - if( (!bjet_LeadExKtSubJet) || (!bjet_SubLeadExKtSubJet) ){ - ATH_MSG_ERROR("Exclusive kt subjet is not well b-tagged!"); - return false; - } - - BTag->setVariable<double>(m_taggerName, "DoubleMV2c20", GetDoubleMV2c20(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet)); - BTag->setVariable<double>(m_taggerName, "SingleMV2c20", GetSingleMV2c20(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet)); - - BTag->setVariable<int>(m_taggerName, "SV1NtrksDiff", GetSV1NtrksDiff(BTag, bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, true)); - BTag->setVariable<int>(m_taggerName, "JFNtrksDiff", GetJFNtrksDiff(BTag, bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, true, m_JFOnlyVtx)); - - BTag->setVariable<double>(m_taggerName, "SV1CombMass", GetSV1CombMass(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, true)); - BTag->setVariable<double>(m_taggerName, "JFCombMass", GetJFCombMass(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, true, m_JFOnlyVtx, true)); - - double SV1DR, SV1DRError; - BTag->setVariable<double>(m_taggerName, "SV1DRSignificance", GetSV1DRSignificance(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, SV1DR, SV1DRError)); - BTag->setVariable<double>(m_taggerName, "SV1DR", SV1DR); - BTag->setVariable<double>(m_taggerName, "SV1DRError", SV1DRError); - - double JFDR, JFDRError; - BTag->setVariable<double>(m_taggerName, "JFDRSignificance", GetJFDRSignificance(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, m_JFOnlyVtx, JFDR, JFDRError)); - BTag->setVariable<double>(m_taggerName, "JFDR", JFDR); - BTag->setVariable<double>(m_taggerName, "JFDRError", JFDRError); - - double SV1DR3D, SV1DR3DError; - BTag->setVariable<double>(m_taggerName, "SV1DR3DSignificance", GetSV1DR3DSignificance(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, SV1DR3D, SV1DR3DError)); - BTag->setVariable<double>(m_taggerName, "SV1DR3D", SV1DR3D); - BTag->setVariable<double>(m_taggerName, "SV1DR3DError", SV1DR3DError); - - double SV1DL, SV1DLError; - BTag->setVariable<double>(m_taggerName, "SV1DLSignificance", GetSV1DLSignificance(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, SV1DL, SV1DLError)); - BTag->setVariable<double>(m_taggerName, "SV1DL", SV1DL); - BTag->setVariable<double>(m_taggerName, "SV1DLError", SV1DLError); - - double JFDL, JFDLError; - BTag->setVariable<double>(m_taggerName, "JFDLSignificance", GetJFDLSignificance(bjet_LeadExKtSubJet, bjet_SubLeadExKtSubJet, m_JFOnlyVtx, JFDL, JFDLError)); - BTag->setVariable<double>(m_taggerName, "JFDL", JFDL); - BTag->setVariable<double>(m_taggerName, "JFDLError", JFDLError); - } - else if(ExKtSubJets.size() == 3){ - ATH_MSG_WARNING("Exclusive kt with N=3 is not supported yet! Jet will be skipped"); - return true; - } - else{ - ATH_MSG_WARNING("Unable to process Exclusive kt with N=" << ExKtSubJets.size() <<". Jet will be skipped"); - return true; - } - - - if(m_debug) ATH_MSG_INFO("Leaving CalculateInputVariables"); - - return true; -} - -bool ExKtbbTag::JetTagAnalysisMode(xAOD::Jet& jetToTag, xAOD::BTagging* BTag){ - if(m_debug) ATH_MSG_INFO("Entering JetTagAnalysisMode"); - - // Retrieve correct calibration file - std::string taggerCalibName = m_taggerNameBase + "Calib_" + m_tagMode + "_" + m_BDTMode + "_" + GetPtBin(&jetToTag); - std::pair<TList*, bool> calib = m_calibrationTool->retrieveTObject<TList>(m_taggerNameBase, m_ForceCalibChannel, taggerCalibName); - - // keyname for TMVAReader cache - std::string keyname = m_ForceCalibChannel + "/" + taggerCalibName; - - bool calibHasChanged = calib.second; - if(calibHasChanged){ // initiate TMVA - - if(!calib.first){ // catch exception - ATH_MSG_WARNING("#BTAG# TList cannot be retrieved -> no calibration for " << m_taggerNameBase << "/" << m_ForceCalibChannel << "/" << taggerCalibName); - BTag->setVariable<double>(m_taggerName, m_BDTMode, -100); - return true; - } - - m_calibrationTool->updateHistogramStatus(m_taggerNameBase, m_ForceCalibChannel, taggerCalibName, false); - - TList* list = calib.first; - - std::ostringstream iss; - for(int i=0; i<list->GetSize(); ++i) { - TObjString* ss = (TObjString*)list->At(i); - std::string sss = ss->String().Data(); - //KM: if it doesn't find "<" in the string, it starts from non-space character - int posi = sss.find('<')!=std::string::npos ? sss.find('<') : sss.find_first_not_of(" "); - std::string tmp = sss.erase(0,posi); - iss << tmp.data(); - } - - TMVA::Reader* tmvaReader = new TMVA::Reader(); - BundleTMVAVariables(m_BDTMode, tmvaReader); - - TMVA::IMethod* method = tmvaReader->BookMVA(TMVA::Types::kBDT, iss.str().data()); - TMVA::MethodBase* methodBase = dynamic_cast<TMVA::MethodBase*>(method); - - // overwrite to the map or reader now - auto pos = m_tmvaReaders.find(keyname); - if(pos != m_tmvaReaders.end()){ - delete pos->second; - m_tmvaReaders.erase(pos); - } - - auto posMethod = m_tmvaMethod.find(keyname); - if(posMethod != m_tmvaMethod.end()){ - delete posMethod->second; - m_tmvaMethod.erase(posMethod); - } - - m_tmvaReaders.insert( std::make_pair(keyname, tmvaReader) ); - m_tmvaMethod.insert( std::make_pair(keyname, methodBase) ); - } - - // assign values to BDT variables - FillTMVAVariables(m_BDTMode, &jetToTag, BTag); - - // Finally compute the weight - double FinalWeight = -100.; - auto posReader = m_tmvaReaders.find(keyname); - if(posReader == m_tmvaReaders.end()){ - int alreadyWarned = std::count(m_undefinedReaders.begin(), m_undefinedReaders.end(), keyname); - if(alreadyWarned == 0){ - ATH_MSG_WARNING("#BTAG# no TMVA reader defined for " << keyname); - m_undefinedReaders.push_back(keyname); - } - } - else{ - auto posMethod = m_tmvaMethod.find(keyname); - if(posMethod->second != 0){ - FinalWeight = posReader->second->EvaluateMVA(posMethod->second); - } - else{ - ATH_MSG_WARNING("#BTAG# Empty TMVA::Method for " << keyname); - } - } - - BTag->setVariable<double>(m_taggerName, m_BDTMode, FinalWeight); - - if(m_debug) ATH_MSG_INFO("Leaving JetTagAnalysisMode"); - - return true; -} - -bool ExKtbbTag::JetTagReferenceMode(xAOD::Jet& /*jetToTag*/, xAOD::BTagging* /*BTag*/){ - if(m_debug) ATH_MSG_INFO("Entering JetTagReferenceMode"); - - // No need to do anything, since all reference variable has been computed earlier // - - if(m_debug) ATH_MSG_INFO("Leaving JetTagReferenceMode"); - - return true; -} - -////////////////////////////////////////////////////////////////////////////////////////////////////// - -double ExKtbbTag::GetDoubleMV2c20(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2){ - double FirstMV2c20 = bjet1->auxdata<double>("MV2c20_discriminant"); - double SecondMV2c20 = bjet2->auxdata<double>("MV2c20_discriminant"); - - return std::min(FirstMV2c20, SecondMV2c20); -} - -double ExKtbbTag::GetSingleMV2c20(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2){ - double FirstMV2c20 = bjet1->auxdata<double>("MV2c20_discriminant"); - double SecondMV2c20 = bjet2->auxdata<double>("MV2c20_discriminant"); - - return std::max(FirstMV2c20, SecondMV2c20); -} - -int ExKtbbTag::GetSV1NtrksDiff(const xAOD::BTagging* bjet, const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool doValidDualSV1){ - auto SV1vertices_bjet = GetSV1vertices(bjet); - auto SV1vertices_bjet1 = GetSV1vertices(bjet1); - auto SV1vertices_bjet2 = GetSV1vertices(bjet2); - - bool isValidDualSV1 = SV1DualValid(SV1vertices_bjet1, SV1vertices_bjet2); - - if( (doValidDualSV1) && (!isValidDualSV1) ) return -20; - - return (IsValidSV1(SV1vertices_bjet1) ? SV1vertices_bjet1[0]->nTrackParticles() : 0) + (IsValidSV1(SV1vertices_bjet2) ? SV1vertices_bjet2[0]->nTrackParticles() : 0) - (IsValidSV1(SV1vertices_bjet) ? SV1vertices_bjet[0]->nTrackParticles() : 0); -} - -int ExKtbbTag::GetJFNtrksDiff(const xAOD::BTagging* bjet, const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool doValidDualJF, bool onlyVtx){ - bool isValidDualJF = JFDualValid(bjet1, bjet2, onlyVtx); - - if( (doValidDualJF) && (!isValidDualJF) ) return -20; - - return IsValidJF(bjet1, onlyVtx) * JFntrk(bjet1, onlyVtx) + IsValidJF(bjet2, onlyVtx) * JFntrk(bjet2, onlyVtx) - IsValidJF(bjet, onlyVtx) * JFntrk(bjet, onlyVtx); -} - -double ExKtbbTag::GetSV1CombMass(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool doValidDualSV1){ - auto SV1vertices_bjet1 = GetSV1vertices(bjet1); - auto SV1vertices_bjet2 = GetSV1vertices(bjet2); - - bool isValidDualSV1 = SV1DualValid(SV1vertices_bjet1, SV1vertices_bjet2); - - if( (doValidDualSV1) && (!isValidDualSV1) ) return -1.; - - std::vector<ElementLink<xAOD::TrackParticleContainer> > SV1Tracks_bjet1 = bjet1->SV1_TrackParticleLinks(); - std::vector<ElementLink<xAOD::TrackParticleContainer> > SV1Tracks_bjet2 = bjet2->SV1_TrackParticleLinks(); - - std::vector<ElementLink<xAOD::TrackParticleContainer> > SV1Tracks_Comb = SV1Tracks_bjet1; - SV1Tracks_Comb.insert(SV1Tracks_Comb.end(), SV1Tracks_bjet2.begin(), SV1Tracks_bjet2.end()); - - TLorentzVector SumSV1TracksP4; - for(auto el_track : SV1Tracks_Comb){ - if(!el_track.isValid()){ - ATH_MSG_WARNING("Invalid element link to SV1_TrackParticles. It will be skipped"); - continue; - } - - if(*el_track == 0){ - ATH_MSG_WARNING("Null ptr returned for SV1_TrackParticles. It will be skipped"); - continue; - } - - SumSV1TracksP4 += ((*el_track)->p4()); - } - - // return SumSV1TracksP4.M()/1000.; // MeV->GeV - return SumSV1TracksP4.M(); -} - -double ExKtbbTag::GetJFCombMass(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool doValidDualJF, bool onlyVtx, bool doNeutralCorrection){ - bool isValidDualJF = JFDualValid(bjet1, bjet2, onlyVtx); - - if( (doValidDualJF) && (!isValidDualJF) ) return -1.; - - TLorentzVector SumP4 = JFMomentum(bjet1, onlyVtx, doNeutralCorrection) + JFMomentum(bjet2, onlyVtx, doNeutralCorrection); - // return SumP4.M()/1000.; // MeV->GeV - return SumP4.M(); -} - -double ExKtbbTag::GetSV1DRSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, double& DR, double& DR_error){ - DR = -1.; - DR_error = -1.; - - auto SV1vertices_bjet1 = GetSV1vertices(bjet1); - auto SV1vertices_bjet2 = GetSV1vertices(bjet2); - - if(!SV1DualValid(SV1vertices_bjet1, SV1vertices_bjet2)) return -1.; - - auto FirstSV1 = SV1vertices_bjet1[0]; - auto SecondSV1 = SV1vertices_bjet2[0]; - - // calculate DR - auto function_SV1DR = [](Amg::Vector3D vtx1, Amg::Vector3D vtx2, Amg::Vector3D PV)->double{ - TVector3 vtx1_pv(vtx1(0) - PV(0), vtx1(1) - PV(1), vtx1(2) - PV(2)); - TVector3 vtx2_pv(vtx2(0) - PV(0), vtx2(1) - PV(1), vtx2(2) - PV(2)); - - return vtx1_pv.DeltaR(vtx2_pv); - }; - - DR = function_SV1DR(FirstSV1->position(), SecondSV1->position(), m_priVtx->position()); - - // calculate error on DR - auto FirstSV1_variations = GetVtxEigenVariation(FirstSV1->position(), FirstSV1->covariancePosition()); - auto SecondSV1_variations = GetVtxEigenVariation(SecondSV1->position(), SecondSV1->covariancePosition()); - auto PV_variations = GetVtxEigenVariation(m_priVtx->position(), m_priVtx->covariancePosition()); - - double sumerror2_FirstSV1 = 0.; - double sumerror2_SecondSV1 = 0.; - double sumerror2_PV = 0.; - for(unsigned int index = 0; index < 3; index++){ - double error_FirstSV1 = std::max( fabs(function_SV1DR(FirstSV1_variations[2*index], SecondSV1->position(), m_priVtx->position()) - DR), fabs(function_SV1DR(FirstSV1_variations[2*index+1], SecondSV1->position(), m_priVtx->position()) - DR) ); - sumerror2_FirstSV1 += (error_FirstSV1 * error_FirstSV1); - - double error_SecondSV1 = std::max( fabs(function_SV1DR(FirstSV1->position(), SecondSV1_variations[2*index], m_priVtx->position()) - DR), fabs(function_SV1DR(FirstSV1->position(), SecondSV1_variations[2*index+1], m_priVtx->position()) - DR) ); - sumerror2_SecondSV1 += (error_SecondSV1 * error_SecondSV1); - - double error_PV = std::max( fabs(function_SV1DR(FirstSV1->position(), SecondSV1->position(), PV_variations[2*index]) - DR), fabs(function_SV1DR(FirstSV1->position(), SecondSV1->position(), PV_variations[2*index+1]) - DR) ); - sumerror2_PV += (error_PV * error_PV); - } - - DR_error = TMath::Sqrt(sumerror2_FirstSV1 + sumerror2_SecondSV1 + sumerror2_PV); - - double output = 0.; - if(DR_error == 0.){ - ATH_MSG_WARNING("Zero error obtained in GetSV1DRSignificance, which is very unlikely"); - output = 999.; - } - else{ - output = DR/DR_error; - } - - return LimitUpperBound(output, 50, 100); -} - -double ExKtbbTag::GetJFDRSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool onlyVtx, double& DR, double& DR_error){ - DR = -1.; - DR_error = -1.; - - if(!JFDualValid(bjet1, bjet2, onlyVtx)) return -1.; - - std::vector<float> fittedPosition_bjet1; - std::vector<float> fittedCov_bjet1; - fittedPosition_bjet1 = GetJFfittedPosition(bjet1, fittedCov_bjet1); - - std::vector<float> fittedPosition_bjet2; - std::vector<float> fittedCov_bjet2; - fittedPosition_bjet2 = GetJFfittedPosition(bjet2, fittedCov_bjet2); - - // get DR - auto function_JFAxis3D = [](double theta, double phi)->TVector3{ - TVector3 axis; - axis.SetMagThetaPhi(1., theta, phi); - return axis; - }; - - auto function_JFDR = [](TVector3 axis1, TVector3 axis2)->double{ - return axis1.DeltaR(axis2); - }; - - double theta_bjet1 = fittedPosition_bjet1[4]; - double phi_bjet1 = fittedPosition_bjet1[3]; - double theta_bjet2 = fittedPosition_bjet2[4]; - double phi_bjet2 = fittedPosition_bjet2[3]; - DR = function_JFDR(function_JFAxis3D(theta_bjet1, phi_bjet1), function_JFAxis3D(theta_bjet2, phi_bjet2)); - - // get error - double Error_theta_bjet1 = std::max( fabs(function_JFDR(function_JFAxis3D(theta_bjet1 + TMath::Sqrt(fittedCov_bjet1[4]), phi_bjet1), function_JFAxis3D(theta_bjet2, phi_bjet2)) - DR), fabs(function_JFDR(function_JFAxis3D(theta_bjet1 - TMath::Sqrt(fittedCov_bjet1[4]), phi_bjet1), function_JFAxis3D(theta_bjet2, phi_bjet2)) - DR) ); - double Error_phi_bjet1 = std::max( fabs(function_JFDR(function_JFAxis3D(theta_bjet1, phi_bjet1 + TMath::Sqrt(fittedCov_bjet1[3])), function_JFAxis3D(theta_bjet2, phi_bjet2)) - DR), fabs(function_JFDR(function_JFAxis3D(theta_bjet1, phi_bjet1 - TMath::Sqrt(fittedCov_bjet1[3])), function_JFAxis3D(theta_bjet2, phi_bjet2)) - DR) ); - double Error_theta_bjet2 = std::max( fabs(function_JFDR(function_JFAxis3D(theta_bjet1, phi_bjet1), function_JFAxis3D(theta_bjet2 + TMath::Sqrt(fittedCov_bjet2[4]), phi_bjet2)) - DR), fabs(function_JFDR(function_JFAxis3D(theta_bjet1, phi_bjet1), function_JFAxis3D(theta_bjet2 - TMath::Sqrt(fittedCov_bjet2[4]), phi_bjet2)) - DR) ); - double Error_phi_bjet2 = std::max( fabs(function_JFDR(function_JFAxis3D(theta_bjet1, phi_bjet1), function_JFAxis3D(theta_bjet2, phi_bjet2 + TMath::Sqrt(fittedCov_bjet2[3]))) - DR), fabs(function_JFDR(function_JFAxis3D(theta_bjet1, phi_bjet1), function_JFAxis3D(theta_bjet2, phi_bjet2 - TMath::Sqrt(fittedCov_bjet2[3]))) - DR) ); - - DR_error = TMath::Sqrt( Error_theta_bjet1*Error_theta_bjet1 + Error_phi_bjet1*Error_phi_bjet1 + Error_theta_bjet2*Error_theta_bjet2 + Error_phi_bjet2*Error_phi_bjet2 ); - - double output = 0.; - if(DR_error == 0.){ - ATH_MSG_WARNING("Zero error obtained in GetJFDRSignificance, which is very unlikely"); - output = 999.; - } - else{ - output = DR/DR_error; - } - - return LimitUpperBound(output, 50, 100); -} - -double ExKtbbTag::GetSV1DR3DSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, double& dR3D, double& dR3D_error){ - dR3D = -1.; - dR3D_error = -1; - - auto SV1vertices_bjet1 = GetSV1vertices(bjet1); - auto SV1vertices_bjet2 = GetSV1vertices(bjet2); - - if(!SV1DualValid(SV1vertices_bjet1, SV1vertices_bjet2)) return -1.; - - auto FirstSV1 = SV1vertices_bjet1[0]; - auto SecondSV1 = SV1vertices_bjet2[0]; - - return GeneralDRSignificance3D(FirstSV1->position(), FirstSV1->covariancePosition(), SecondSV1->position(), SecondSV1->covariancePosition(), dR3D, dR3D_error); -} - -double ExKtbbTag::GetSV1DLSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, double& dL, double& dL_error){ - dL = -1.; - dL_error = -1.; - - auto SV1vertices_bjet1 = GetSV1vertices(bjet1); - auto SV1vertices_bjet2 = GetSV1vertices(bjet2); - - if(!SV1DualValid(SV1vertices_bjet1, SV1vertices_bjet2)) return -1.; - - auto FirstSV1 = SV1vertices_bjet1[0]; - auto SecondSV1 = SV1vertices_bjet2[0]; - - // calculate dL - auto function_GetDL = [](Amg::Vector3D vtx1, Amg::Vector3D vtx2, Amg::Vector3D pv)->double{ - double l1 = TMath::Sqrt((vtx1 - pv).dot(vtx1 - pv)); - double l2 = TMath::Sqrt((vtx2 - pv).dot(vtx2 - pv)); - - return fabs(l1-l2); - }; - - dL = function_GetDL(FirstSV1->position(), SecondSV1->position(), m_priVtx->position()); - - // Calculate Error - std::vector<Amg::Vector3D> FirstSV1_variations = GetVtxEigenVariation(FirstSV1->position(), FirstSV1->covariancePosition()); - std::vector<Amg::Vector3D> SecondSV1_variations = GetVtxEigenVariation(SecondSV1->position(), SecondSV1->covariancePosition()); - std::vector<Amg::Vector3D> PV_variations = GetVtxEigenVariation(m_priVtx->position(), m_priVtx->covariancePosition()); - - double sumerror2_FirstSV1 = 0.; - double sumerror2_SecondSV1 = 0.; - double sumerror2_PV = 0.; - - for(unsigned int index = 0; index < 3; index++){ - double error_FirstSV1 = std::max(fabs(function_GetDL(FirstSV1_variations[2*index], SecondSV1->position(), m_priVtx->position()) - dL), fabs(function_GetDL(FirstSV1_variations[2*index+1], SecondSV1->position(), m_priVtx->position()) - dL)); - sumerror2_FirstSV1 += (error_FirstSV1 * error_FirstSV1); - - double error_SecondSV1 = std::max(fabs(function_GetDL(FirstSV1->position(), SecondSV1_variations[2*index], m_priVtx->position()) - dL), fabs(function_GetDL(FirstSV1->position(), SecondSV1_variations[2*index+1], m_priVtx->position()) - dL)); - sumerror2_SecondSV1 += (error_SecondSV1 * error_SecondSV1); - - double error_PV = std::max(fabs(function_GetDL(FirstSV1->position(), SecondSV1->position(), PV_variations[2*index]) - dL), fabs(function_GetDL(FirstSV1->position(), SecondSV1->position(), PV_variations[2*index+1]) - dL)); - sumerror2_PV += (error_PV * error_PV); - } - - dL_error = TMath::Sqrt(sumerror2_FirstSV1 + sumerror2_SecondSV1 + sumerror2_PV); - - double output = 0.; - if(dL_error == 0.){ - ATH_MSG_WARNING("Zero error obtained in GetSV1DLSignificance, which is very unlikely"); - output = 999.; - } - else{ - output = dL/dL_error; - } - - return LimitUpperBound(output, 50, 100); -} - -double ExKtbbTag::GetJFDLSignificance(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool onlyVtx, double& dL, double& dL_error){ - dL = -1.; - dL_error = -1.; - - if(!JFDualValid(bjet1, bjet2, onlyVtx)) return -1.; - - std::vector<float> fittedPosition_bjet1; - std::vector<float> fittedCov_bjet1; - fittedPosition_bjet1 = GetJFfittedPosition(bjet1, fittedCov_bjet1); - - std::vector<float> fittedPosition_bjet2; - std::vector<float> fittedCov_bjet2; - fittedPosition_bjet2 = GetJFfittedPosition(bjet2, fittedCov_bjet2); - - // get dL - auto function_GetDL = [](double l1, double l2)->double{ - return fabs(l1-l2); - }; - - double l1,l1_error; - l1 = JFEffectiveDecayLength(bjet1, onlyVtx, l1_error); - - double l2,l2_error; - l2 = JFEffectiveDecayLength(bjet2, onlyVtx, l2_error); - - dL = function_GetDL(l1, l2); - - double error_l1 = std::max(fabs(function_GetDL(l1 + l1_error, l2) - dL), fabs(function_GetDL(l1 - l1_error, l2) - dL)); - double error_l2 = std::max(fabs(function_GetDL(l1, l2 + l2_error) - dL), fabs(function_GetDL(l1, l2 - l2_error) - dL)); - - dL_error = TMath::Sqrt(error_l1*error_l1 + error_l2*error_l2); - - double output = 0.; - if(dL_error == 0.){ - ATH_MSG_WARNING("Zero error obtained in GetJFDLSignificance, which is very unlikely"); - output = 999.; - } - else{ - output = dL/dL_error; - } - - return LimitUpperBound(output, 50, 100); -} - - -///////////////////////////////////////////////////////////////////////////////////////////////////// - -std::vector<const xAOD::Vertex*> ExKtbbTag::GetSV1vertices(const xAOD::BTagging* bjet){ - std::vector<ElementLink<xAOD::VertexContainer> > SV1vertices; - try{ - SV1vertices = bjet->auxdata<std::vector<ElementLink<xAOD::VertexContainer> > >("SV1_vertices"); - } - catch(...){ - ATH_MSG_WARNING("Unable to get \"SV1_vertices\" from bjet"); - } - - std::vector<const xAOD::Vertex*> output; - for(auto el_vtx : SV1vertices){ - if(!el_vtx.isValid()){ - ATH_MSG_WARNING("Invalid element link to SV1 vtx. It will be skipped"); - continue; - } - - const xAOD::Vertex* vtx = (*el_vtx); - if(vtx == 0){ - ATH_MSG_WARNING("Null ptr returned for SV1 vtx. It will be skipped"); - continue; - } - - output.push_back(vtx); - } - - return output; -} - -bool ExKtbbTag::IsValidSV1(std::vector<const xAOD::Vertex*> input){ - if(input.size() > 1){ - ATH_MSG_WARNING("Get more than 1 SV1 vtx! Only first one will be used."); - } - - return input.size() > 0; -} - -bool ExKtbbTag::SV1DualValid(std::vector<const xAOD::Vertex*> vtx1, std::vector<const xAOD::Vertex*> vtx2){ - return IsValidSV1(vtx1) && IsValidSV1(vtx2); -} - -std::vector<const xAOD::BTagVertex*> ExKtbbTag::GetJFVertices(const xAOD::BTagging* bjet){ - std::vector<ElementLink<xAOD::BTagVertexContainer> > jfvertices; - try{ - jfvertices = bjet->auxdata<std::vector<ElementLink<xAOD::BTagVertexContainer> > >("JetFitter_JFvertices"); - } catch(...){ - ATH_MSG_WARNING("Unable to get \"JetFitter_JFvertices\""); - } - - std::vector<const xAOD::BTagVertex*> output; - for(auto el_vtx : jfvertices){ - if(!el_vtx.isValid()){ - ATH_MSG_WARNING("Invalid element link to JF vertices. It will be skipped"); - continue; - } - - const xAOD::BTagVertex* vtx = (*el_vtx); - if(vtx == 0){ - ATH_MSG_WARNING("Null ptr returned for JF vertices. It will be skipped"); - continue; - } - - output.push_back(vtx); - } - - return output; -} - -std::vector<float> ExKtbbTag::GetJFfittedPosition(const xAOD::BTagging* bjet, std::vector<float>& JFfittedCov){ - std::vector<float> JFfittedPosition; - JFfittedCov.clear(); - - try{ - JFfittedPosition = bjet->auxdata<std::vector<float> >("JetFitter_fittedPosition"); - JFfittedCov = bjet->auxdata<std::vector<float> >("JetFitter_fittedCov"); - } - catch(...){ - ATH_MSG_WARNING("Unable to get \"JetFitter_fittedCov\" and/or \"JetFitter_fittedCov\""); - } - - return JFfittedPosition; -} - -bool ExKtbbTag::IsValidJF(const xAOD::BTagging* bjet, bool onlyVtx){ - int JFnvtx = 0; bjet->taggerInfo(JFnvtx, xAOD::JetFitter_nVTX); - int JFnsingletrks = 0; bjet->taggerInfo(JFnsingletrks, xAOD::JetFitter_nSingleTracks); - - if(onlyVtx) return JFnvtx > 0; - else return (JFnvtx > 0) || (JFnsingletrks > 0); -} - -bool ExKtbbTag::JFDualValid(const xAOD::BTagging* bjet1, const xAOD::BTagging* bjet2, bool onlyVtx){ - return IsValidJF(bjet1, onlyVtx) && IsValidJF(bjet2, onlyVtx); -} - -int ExKtbbTag::JFntrk(const xAOD::BTagging* bjet, bool onlyVtx){ - if(!IsValidJF(bjet, onlyVtx)){ - return -1; - } - else{ - int JFnvtxtrk = 0; bjet->taggerInfo(JFnvtxtrk, xAOD::JetFitter_nTracksAtVtx); - int JFnsingletrks = 0; bjet->taggerInfo(JFnsingletrks, xAOD::JetFitter_nSingleTracks); - - if(onlyVtx) return JFnvtxtrk; - else return JFnvtxtrk + JFnsingletrks; - } -} - -TLorentzVector ExKtbbTag::JFMomentum(const xAOD::BTagging* bjet, bool onlyVtx, bool doNeutralCorrection){ - // Initialization - TLorentzVector SumChargeP4(0., 0., 0., 0.); - TLorentzVector SumNeutralP4(0., 0., 0., 0.); - double SumPtAdd = 0.; - - // quit for invalid jF - if(!IsValidJF(bjet, onlyVtx)) return SumChargeP4; - - // get necessary ingredient - std::vector<const xAOD::BTagVertex*> jfvertices = GetJFVertices(bjet); - - std::vector<float> fittedPosition; std::vector<float> fittedCov; - fittedPosition = GetJFfittedPosition(bjet, fittedCov); - - // fitted direction - TVector3 JFDir(1., 1., 1.); - JFDir.SetMagThetaPhi(1., fittedPosition[4], fittedPosition[3]); - - // number of vtx (with at least 2 tracks) - int nVtx = 0; - bjet->taggerInfo(nVtx, xAOD::JetFitter_nVTX); - - // loop over vertices - for(unsigned int ivtx = 0; ivtx < jfvertices.size(); ivtx++){ - auto JFVtx = jfvertices[ivtx]; - - // reject negative vtx - if(fittedPosition[5+ivtx] < 0) continue; - - // loop over tracks on vtx - TLorentzVector TrackOnVtxP4(0., 0., 0., 0.); - for(auto el_track : JFVtx->track_links()){ - if(!el_track.isValid()){ - ATH_MSG_WARNING("Missing link to tracks associated to JF vtx. It will be skipped"); - continue; - } - - auto track = (*el_track); - - TrackOnVtxP4 += track->p4(); - } - - // get neutral momentum - TVector3 JFDir_scale; JFDir_scale.SetMagThetaPhi(TrackOnVtxP4.Vect().Dot(JFDir), JFDir.Theta(), JFDir.Phi()); - TVector3 NeutralOnVtxP3 = JFDir_scale - TrackOnVtxP4.Vect(); - TLorentzVector NeutralOnVtxP4; NeutralOnVtxP4.SetVectM(NeutralOnVtxP3, 0.); - - // summation - if(!onlyVtx){ - SumChargeP4 += TrackOnVtxP4; - SumNeutralP4 += NeutralOnVtxP4; - SumPtAdd += TrackOnVtxP4.Perp(JFDir); - } - else{ - if( (nVtx > 0 && JFVtx->track_links().size() > 1) || (nVtx == 0) ){ - SumChargeP4 += TrackOnVtxP4; - SumNeutralP4 += NeutralOnVtxP4; - SumPtAdd += TrackOnVtxP4.Perp(JFDir); - } - } - - } - - if(doNeutralCorrection){ - return SumChargeP4 + SumNeutralP4; - } - else{ - return SumChargeP4; - } -} - -double ExKtbbTag::JFEffectiveDecayLength(const xAOD::BTagging* bjet, bool onlyVtx, double& error){ - double decaylength = -1.; - error = -1.; - - if(!IsValidJF(bjet, onlyVtx)) return decaylength; - - auto jfvertices = GetJFVertices(bjet); - std::vector<float> fittedPosition; - std::vector<float> fittedCov; - fittedPosition = GetJFfittedPosition(bjet, fittedCov); - - // number of vtx (with at least 2 tracks) - int nVtx = 0; - bjet->taggerInfo(nVtx, xAOD::JetFitter_nVTX); - - // loop over vertices - double sum_l = 0.; - double sum_inverror2 = 0.; - for(unsigned int ivtx = 0; ivtx < jfvertices.size(); ivtx++){ - auto JFVtx = jfvertices[ivtx]; - - // reject negative vtx - if(fittedPosition[5+ivtx] < 0) continue; - - double l = fittedPosition[5+ivtx]; - double error2 = fittedCov[5+ivtx]; - - if(error2 == 0.){ - ATH_MSG_WARNING("Get 0 error for a fitted vtx decay length"); - continue; - } - - if(!onlyVtx){ - sum_l += (l/error2); - sum_inverror2 += (1./error2); - } - else{ - if( (nVtx > 0 && JFVtx->track_links().size() > 1) || (nVtx == 0) ){ - sum_l += (l/error2); - sum_inverror2 += (1./error2); - } - } - } - - // get result - decaylength = sum_l/sum_inverror2; - error = 1./TMath::Sqrt(sum_inverror2); - - return decaylength; -} - -// calculate all eigen variation of vtx position -std::vector<Amg::Vector3D> ExKtbbTag::GetVtxEigenVariation(Amg::Vector3D vtxPosition, AmgSymMatrix3D vtxCovMatrix){ - std::vector<Amg::Vector3D> output; - - // solve eigen system - Eigen::SelfAdjointEigenSolver<AmgSymMatrix3D> EigenSolver(vtxCovMatrix); - if(EigenSolver.info() != Eigen::Success){ - ATH_MSG_WARNING("Input matrix is not Hermitian, which should be impossible for covariant matrix!"); - return output; - } - - auto EigenValues = EigenSolver.eigenvalues(); - auto EigenVectors = EigenSolver.eigenvectors(); - - // get variation - for(unsigned int index = 0; index < 3; index++){ - Amg::Vector3D vtxPositionVariation_Up; - vtxPositionVariation_Up(0) = vtxPosition(0) + TMath::Sqrt(EigenValues(index)) * EigenVectors(0, index); - vtxPositionVariation_Up(1) = vtxPosition(1) + TMath::Sqrt(EigenValues(index)) * EigenVectors(1, index); - vtxPositionVariation_Up(2) = vtxPosition(2) + TMath::Sqrt(EigenValues(index)) * EigenVectors(2, index); - - Amg::Vector3D vtxPositionVariation_Down; - vtxPositionVariation_Down(0) = vtxPosition(0) - TMath::Sqrt(EigenValues(index)) * EigenVectors(0, index); - vtxPositionVariation_Down(1) = vtxPosition(1) - TMath::Sqrt(EigenValues(index)) * EigenVectors(1, index); - vtxPositionVariation_Down(2) = vtxPosition(2) - TMath::Sqrt(EigenValues(index)) * EigenVectors(2, index); - - output.push_back(vtxPositionVariation_Up); - output.push_back(vtxPositionVariation_Down); - } - - return output; -} - -double ExKtbbTag::GeneralDRSignificance3D(Amg::Vector3D vtx1, AmgSymMatrix3D vtx1_CovMatrix, Amg::Vector3D vtx2, AmgSymMatrix3D vtx2_CovMatrix, double& dR3D, double& dR3D_error){ - dR3D = -1.; - dR3D_error = -1.; - - std::vector<Amg::Vector3D> vtx1_variations = GetVtxEigenVariation(vtx1, vtx1_CovMatrix); - std::vector<Amg::Vector3D> vtx2_variations = GetVtxEigenVariation(vtx2, vtx2_CovMatrix); - - auto function_GetdR3D = [](Amg::Vector3D input1, Amg::Vector3D input2)->double{ - return TMath::Sqrt((input1 - input2).dot(input1 - input2)); - }; - - dR3D = function_GetdR3D(vtx1, vtx2); - - double sumerror_vtx1 = 0.; - double sumerror_vtx2 = 0.; - for(unsigned int index = 0; index < 3; index++){ - double error_vtx1 = std::max(fabs(function_GetdR3D(vtx1_variations[2*index], vtx2) - dR3D), fabs(function_GetdR3D(vtx1_variations[2*index+1], vtx2) - dR3D)); - sumerror_vtx1 += (error_vtx1 * error_vtx1); - - double error_vtx2 = std::max(fabs(function_GetdR3D(vtx1, vtx2_variations[2*index]) - dR3D), fabs(function_GetdR3D(vtx1, vtx2_variations[2*index+1]) - dR3D)); - sumerror_vtx2 += (error_vtx2 * error_vtx2); - } - - double sumerror = sumerror_vtx1 + sumerror_vtx2; - dR3D_error = TMath::Sqrt(sumerror); - - double significance = 0.; - if(dR3D_error == 0.){ - ATH_MSG_WARNING("Zero error obtained in GeneralDRSignificance3D, which is very unlikely."); - significance = 999.; - } - else{ - significance = dR3D/dR3D_error; - } - - significance = LimitUpperBound(significance, 50, 100); - return significance; -} - -std::string ExKtbbTag::GetPtBin(const xAOD::Jet* jetToTag){ - double pt = jetToTag->pt()/1000.; // MeV -> GeV - - if(pt < m_ptbinlist.front()){ // underflow bin -- first pt bin - pt = m_ptbinlist.front() + 1; - } - - if(pt >= m_ptbinlist.back()){ // overflow bin -- last pt bin - pt = m_ptbinlist.back() - 1; - } - - for(unsigned int index = 0; index < m_ptbinlist.size()-1; index++){ - double ptmin = m_ptbinlist[index]; - double ptmax = m_ptbinlist[index+1]; - - if( (pt >= ptmin) && (pt < ptmax) ) return TString::Format("PtBin%i", int(index)).Data(); - } - - ATH_MSG_WARNING("How can you reach this line?!"); - return "PtBin-1"; -} - -bool ExKtbbTag::InitTMVAVariables(std::string BDTMode){ - m_tmvaVariables.clear(); - - // common variables - m_tmvaVariables["JetPt"] = new float(0.); - m_tmvaVariables["JetEta"] = new float(0.); - - if(BDTMode == "MV2Only"){ - m_tmvaVariables["ExKt_DoubleMV2c20"] = new float(0.); - m_tmvaVariables["ExKt_SingleMV2c20"] = new float(0.); - } - else if(BDTMode == "MV2andJFDRSig"){ - m_tmvaVariables["ExKt_DoubleMV2c20"] = new float(0.); - m_tmvaVariables["ExKt_SingleMV2c20"] = new float(0.); - m_tmvaVariables["ExKt_JFDRSignificance"] = new float(0.); - } - else if(BDTMode == "MV2andTopos"){ - m_tmvaVariables["ExKt_DoubleMV2c20"] = new float(0.); - m_tmvaVariables["ExKt_SingleMV2c20"] = new float(0.); - m_tmvaVariables["ExKt_SV1CombMass_ValidDualSV1 := (ExKt_ValidDualSV1 ? ExKt_SV1CombMass : -1.)"] = new float(0.); - m_tmvaVariables["ExKt_JFNtrksDiff_ValidDualJF := (ExKt_ValidDualJF ? ExKt_JFNtrksDiff : -20.)"] = new float(0.); - m_tmvaVariables["ExKt_JFDRSignificance"] = new float(0.); - m_tmvaVariables["ExKt_JFDLSignificance"] = new float(0.); - } - else{ - ATH_MSG_ERROR("#BTAG# Undefined BDTMode " << BDTMode); - return false; - } - - return true; -} - -bool ExKtbbTag::FillTMVAVariables(std::string BDTMode, const xAOD::Jet* jetToTag, const xAOD::BTagging* BTag){ - // common variables - // unit in GeV - - *(m_tmvaVariables["JetPt"]) = jetToTag->pt()/1000.; // MeV->GeV - *(m_tmvaVariables["JetEta"]) = jetToTag->eta(); - - if(BDTMode == "MV2Only"){ - double DoubleMV2c20; - if(!BTag->variable<double>(m_taggerName, "DoubleMV2c20", DoubleMV2c20)) ATH_MSG_WARNING("#BTAG# Unable to get \"DoubleMV2c20\""); - double SingleMV2c20; - if(!BTag->variable<double>(m_taggerName, "SingleMV2c20", SingleMV2c20)) ATH_MSG_WARNING("#BTAG# Unable to get \"SingleMV2c20\""); - - *(m_tmvaVariables["ExKt_DoubleMV2c20"]) = DoubleMV2c20; - *(m_tmvaVariables["ExKt_SingleMV2c20"]) = SingleMV2c20; - } - else if(BDTMode == "MV2andJFDRSig"){ - double DoubleMV2c20; - if(!BTag->variable<double>(m_taggerName, "DoubleMV2c20", DoubleMV2c20)) ATH_MSG_WARNING("#BTAG# Unable to get \"DoubleMV2c20\""); - double SingleMV2c20; - if(!BTag->variable<double>(m_taggerName, "SingleMV2c20", SingleMV2c20)) ATH_MSG_WARNING("#BTAG# Unable to get \"SingleMV2c20\""); - double JFDRSignificance; - if(!BTag->variable<double>(m_taggerName, "JFDRSignificance", JFDRSignificance)) ATH_MSG_WARNING("#BTAG# Unable to get \"JFDRSignificance\""); - - *(m_tmvaVariables["ExKt_DoubleMV2c20"]) = DoubleMV2c20; - *(m_tmvaVariables["ExKt_SingleMV2c20"]) = SingleMV2c20; - *(m_tmvaVariables["ExKt_JFDRSignificance"]) = JFDRSignificance; - } - else if(BDTMode == "MV2andTopos"){ - double DoubleMV2c20; - if(!BTag->variable<double>(m_taggerName, "DoubleMV2c20", DoubleMV2c20)) ATH_MSG_WARNING("#BTAG# Unable to get \"DoubleMV2c20\""); - double SingleMV2c20; - if(!BTag->variable<double>(m_taggerName, "SingleMV2c20", SingleMV2c20)) ATH_MSG_WARNING("#BTAG# Unable to get \"SingleMV2c20\""); - double SV1CombMass; - if(!BTag->variable<double>(m_taggerName, "SV1CombMass", SV1CombMass)) ATH_MSG_WARNING("#BTAG# Unable to get \"SV1CombMass\""); - int JFNtrksDiff = 0; - if(!BTag->variable<int>(m_taggerName, "JFNtrksDiff", JFNtrksDiff)) ATH_MSG_WARNING("#BTAG# Unable to get\"JFNtrksDiff\""); - double JFDRSignificance; - if(!BTag->variable<double>(m_taggerName, "JFDRSignificance", JFDRSignificance)) ATH_MSG_WARNING("#BTAG# Unable to get \"JFDRSignificance\""); - double JFDLSignificance; - if(!BTag->variable<double>(m_taggerName, "JFDLSignificance", JFDLSignificance)) ATH_MSG_WARNING("#BTAG# Unable to get \"JFDLSignificance\""); - - *(m_tmvaVariables["ExKt_DoubleMV2c20"]) = DoubleMV2c20; - *(m_tmvaVariables["ExKt_SingleMV2c20"]) = SingleMV2c20; - *(m_tmvaVariables["ExKt_SV1CombMass_ValidDualSV1 := (ExKt_ValidDualSV1 ? ExKt_SV1CombMass : -1.)"]) = (SV1CombMass < 0. ? -1 : SV1CombMass/1000.); // MeV->GeV - *(m_tmvaVariables["ExKt_JFNtrksDiff_ValidDualJF := (ExKt_ValidDualJF ? ExKt_JFNtrksDiff : -20.)"]) = JFNtrksDiff*1.0; // double->int - *(m_tmvaVariables["ExKt_JFDRSignificance"]) = JFDRSignificance; - *(m_tmvaVariables["ExKt_JFDLSignificance"]) = JFDLSignificance; - } - else{ - ATH_MSG_ERROR("#BTAG# Undefined BDTMode " << BDTMode); - return false; - } - - return true; -} - -bool ExKtbbTag::BundleTMVAVariables(std::string BDTMode, TMVA::Reader* tmvaReader){ - if(!tmvaReader){ - ATH_MSG_ERROR("#BTAG# Null ptr to tmvaReader!"); - return false; - } - - // Cannot do this simple trick, as TMVA reuqires the order to be exactly same!! - // Stupid! - // for(auto iter = m_tmvaVariables.begin(); iter != m_tmvaVariables.end(); iter++){ - // tmvaReader->AddVariable(iter->first, iter->second); - // } - - std::vector<std::string> OrderedInputs; - - if(BDTMode == "MV2Only"){ - OrderedInputs = { - "JetPt", - "JetEta", - "ExKt_DoubleMV2c20", - "ExKt_SingleMV2c20", - }; - } - else if(BDTMode == "MV2andJFDRSig"){ - OrderedInputs = { - "JetPt", - "JetEta", - "ExKt_DoubleMV2c20", - "ExKt_SingleMV2c20", - "ExKt_JFDRSignificance", - }; - } - else if(BDTMode == "MV2andTopos"){ - OrderedInputs = { - "JetPt", - "JetEta", - "ExKt_DoubleMV2c20", - "ExKt_SingleMV2c20", - "ExKt_SV1CombMass_ValidDualSV1 := (ExKt_ValidDualSV1 ? ExKt_SV1CombMass : -1.)", - "ExKt_JFNtrksDiff_ValidDualJF := (ExKt_ValidDualJF ? ExKt_JFNtrksDiff : -20.)", - "ExKt_JFDRSignificance", - "ExKt_JFDLSignificance", - }; - } - else{ - ATH_MSG_ERROR("#BTAG# Undefined BDTMode " << BDTMode); - return false; - } - - for(auto iter = OrderedInputs.begin(); iter != OrderedInputs.end(); iter++){ - std::string key = *iter; - if(m_tmvaVariables.find(key) == m_tmvaVariables.end()){ - ATH_MSG_WARNING("#BTAG# Variable " << key << " not initialized! This is not supposed to happen. Initializing it here."); - m_tmvaVariables[key] = new float(0.); - } - - tmvaReader->AddVariable(key, m_tmvaVariables[key]); - } - - return true; -} - -}//end namespace - - - diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/ExKtbbTagTool.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/ExKtbbTagTool.cxx deleted file mode 100644 index 65b35e08c914635c72adee6cdc51b1ee2f1be7b2..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/ExKtbbTagTool.cxx +++ /dev/null @@ -1,171 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -#include "JetTagTools/ExKtbbTagTool.h" - -#include "xAODJet/JetContainer.h" -#include "xAODJet/JetContainerInfo.h" -#include "JetEDM/IConstituentUserInfo.h" -#include "JetEDM/FastJetUtils.h" - -namespace Analysis{ - -ExKtbbTagTool::ExKtbbTagTool(std::string myname): - JetModifierBase(myname), - m_JetAlgorithm(""), - m_JetRadius(0.), - m_PtMin(0.), - m_ExclusiveNJets(0), - m_InputJetContainerName(""), - m_SubjetRecorderTool("SubjetRecorderTool"), - m_SubjetLabel(""), - m_SubjetContainerName(""), - m_SubjetAlgorithm_BTAG(""), - m_SubjetRadius_BTAG(0.) -{ - declareProperty("JetAlgorithm", m_JetAlgorithm); - declareProperty("JetRadius", m_JetRadius); - declareProperty("PtMin", m_PtMin); - declareProperty("ExclusiveNJets", m_ExclusiveNJets); - - declareProperty("InputJetContainerName", m_InputJetContainerName); - declareProperty("SubjetRecorder", m_SubjetRecorderTool); - declareProperty("SubjetLabel", m_SubjetLabel); - declareProperty("SubjetContainerName", m_SubjetContainerName); - declareProperty("SubjetAlgorithm_BTAG", m_SubjetAlgorithm_BTAG); - declareProperty("SubjetRadius_BTAG", m_SubjetRadius_BTAG); -} - -StatusCode ExKtbbTagTool::initialize(){ - if(m_SubjetRecorderTool.retrieve().isFailure()){ - ATH_MSG_ERROR("#BTAG# Unable to retrieve SubjetRecorder Tool"); - return StatusCode::FAILURE; - } - else{ - ATH_MSG_INFO("#BTAG# Successfully retrieve SubjetRecorder Tool"); - } - - return StatusCode::SUCCESS; -} - -int ExKtbbTagTool::modifyJet(xAOD::Jet& jet) const { - - // run subjet finding // - - xAOD::JetAlgorithmType::ID ialg = xAOD::JetAlgorithmType::algId(m_JetAlgorithm); - fastjet::JetAlgorithm fjalg = xAOD::JetAlgorithmType::fastJetDef(ialg); - - JetSubStructureUtils::SubjetFinder subjetFinder(fjalg, m_JetRadius, m_PtMin, m_ExclusiveNJets); - std::vector<fastjet::PseudoJet> constituents_pj = constituentPseudoJets(jet); - // std::vector<fastjet::PseudoJet> constituents = jet::JetConstituentFiller::constituentPseudoJets(jet); - fastjet::PseudoJet sum_constituents_pj = fastjet::join(constituents_pj); - std::vector<fastjet::PseudoJet> subjets_pj = subjetFinder.result(sum_constituents_pj); - - // record subjets // - - auto subjets_nonconst = m_SubjetRecorderTool->recordSubjets(subjets_pj, jet); // since we are using customized constituent pseudo-jet, constituents information will not be stored here - - // store the subjet container name and index // - - // We do this since ElementLink to the subjet could be broken after the deep-copy in b-tagging part. This was not a problem before 20.7. The reason behind it is still unknown. - // Assuming the subjet container order is un-changed during b-tagging deep-copy, which SHOULD be valid. - - std::vector<const xAOD::Jet*> ExKtSubJets; - if(!jet.getAssociatedObjects<xAOD::Jet>(m_SubjetLabel.c_str(), ExKtSubJets)){ - ATH_MSG_WARNING("Unable to fetch subjet collection in ExKtbbTagTool::modifyJet : " << m_SubjetLabel.c_str()); - ATH_MSG_WARNING("Nothing to be done for this problem. But you might crash very soon."); - } - - jet.auxdata<std::string>(m_SubjetLabel + "_ContainerName") = m_SubjetContainerName; - - std::vector<int> SubjetIndexVector; - for(auto subjet : ExKtSubJets){ - SubjetIndexVector.push_back(subjet->index()); - } - jet.auxdata<std::vector<int> >(m_SubjetLabel + "_IndexList") = SubjetIndexVector; - - // overwrite something / store constituents // - - for(unsigned int index_subjet = 0; index_subjet < subjets_nonconst.size(); index_subjet++){ - auto subjet_nonconst = subjets_nonconst[index_subjet]; - auto subjet_pj = subjets_pj[index_subjet]; - - // jet finding - subjet_nonconst->setAlgorithmType(xAOD::JetAlgorithmType::algId(m_SubjetAlgorithm_BTAG)); - subjet_nonconst->setSizeParameter(m_SubjetRadius_BTAG); - - // jet input type - subjet_nonconst->setInputType(jet.getInputType()); - - // setup constituents - - // check if constituents has been filled before - if(subjet_nonconst->numConstituents() == 0){ - - for(auto pj_constituent : subjet_pj.constituents()){ - int index_constituent = pj_constituent.user_index(); // index in parent jet constituent vector - - auto el_constituent = jet.constituentLinks()[index_constituent]; - - if(!el_constituent.isValid()){ - ATH_MSG_WARNING("#BTAG# Element link to jet constituent is inValid! It will still be stored anyway ... "); - } - - subjet_nonconst->addConstituent(el_constituent, 1.0); - } - - } - else{ - ATH_MSG_WARNING("#BTAG# Constituent link to subjet is already built, which is NOT expected!"); - } - - // set correct constituent signal state - subjet_nonconst->setConstituentsSignalState(jet.getConstituentsSignalState()); - - // add parent jet information, in case the "parent" link is broken - auto el_parent = subjet_nonconst->auxdata<ElementLink<xAOD::JetContainer> >("Parent"); - if(!el_parent.isValid()){ - ATH_MSG_WARNING("#BTAG# Element link from ExKtSubjet to parent jet is invalid! No backup parent link information will be stored."); - } - else{ - subjet_nonconst->auxdata<std::string>("Parent_ContainerName") = m_InputJetContainerName; - subjet_nonconst->auxdata<int>("Parent_Index") = jet.index(); - } - - } - - // for(auto subjet : ExKtSubJets){ - // if(!subjet){ - // std::cout << "Empty ptr to subjet in ExKtbbTagTool::modifyJet at position 2!" << std::endl; - // } - // } - - return 0; -} - -std::vector<fastjet::PseudoJet> ExKtbbTagTool::constituentPseudoJets(xAOD::Jet& jet) const{ - // code adapted from JetConstituentFiller.cxx - // Cannot use JetConstituentFiller utils due to code crash from unknown reason - // It seems the fastjet link is broken after a deep copy of parent jet - // but anyway ... - - std::vector<fastjet::PseudoJet> constituents; - - xAOD::JetConstituentVector constituents_tmp = jet.getConstituents(); - xAOD::JetConstituentVector::iterator it = constituents_tmp.begin(); - xAOD::JetConstituentVector::iterator itE = constituents_tmp.end(); - - int index = 0; - for( ; it !=itE; ++it){ - fastjet::PseudoJet constituent_pj = fastjet::PseudoJet( it->Px(), it->Py(), it->Pz(), it->E() ); // this is guaranteed to be the scale used in jet finding - constituent_pj.set_user_index(index); // each constituent_pj will store index in parent jet constituent ve tor - constituents.push_back( constituent_pj ); - - index++; - } - - return constituents; -} - -} diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/IPTag.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/IPTag.cxx index 5579c147db251f152939bc9bab159eb86948fca4..0819e0e040970e1844318e93ef7f3dabee2f6588 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/IPTag.cxx +++ b/PhysicsAnalysis/JetTagging/JetTagTools/src/IPTag.cxx @@ -25,7 +25,6 @@ #include "TrkVertexFitterInterfaces/ITrackToVertexIPEstimator.h" #include "ParticleJetTools/JetFlavourInfo.h" #include "InDetTrackSelectionTool/IInDetTrackSelectionTool.h" -#include "TrackVertexAssociationTool/ITrackVertexAssociationTool.h" #include "TH1.h" #include <cmath> #include <sstream> @@ -92,8 +91,7 @@ namespace Analysis { m_SVForIPTool("Analysis::SVForIPTool", this), m_trackGradeFactory("Analysis::BasicTrackGradeFactory", this), m_trackToVertexIPEstimator(this), - m_InDetTrackSelectorTool("InDet::InDetTrackSelectionTool", this), - m_TightTrackVertexAssociationTool("CP::TrackVertexAssociationTool", this) + m_InDetTrackSelectorTool("InDet::InDetTrackSelectionTool", this) { // global configuration: declareProperty("Runmodus" , m_runModus); @@ -147,7 +145,6 @@ namespace Analysis { declareProperty("trackGradeFactory" , m_trackGradeFactory ); declareProperty("TrackToVertexIPEstimator" , m_trackToVertexIPEstimator ); declareProperty("InDetTrackSelectionTool" , m_InDetTrackSelectorTool ); // - declareProperty("TrackVertexAssociationTool", m_TightTrackVertexAssociationTool); // } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -351,16 +348,9 @@ namespace Analysis { } else { ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_InDetTrackSelectorTool); } - if ( m_TightTrackVertexAssociationTool.retrieve().isFailure() ) { - ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_TightTrackVertexAssociationTool); - return StatusCode::FAILURE; - } else { - ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_TightTrackVertexAssociationTool); - } } else { m_InDetTrackSelectorTool.disable(); - m_TightTrackVertexAssociationTool.disable(); } return StatusCode::SUCCESS; @@ -448,8 +438,7 @@ namespace Analysis { int nbTrak = 0; std::vector< ElementLink< xAOD::TrackParticleContainer > > associationLinks = BTag.auxdata<std::vector<ElementLink<xAOD::TrackParticleContainer> > >(m_trackAssociationName); - double sumTrkpT = 0; unsigned ntrk=0; - TLorentzVector pseudoTrackJet(0,0,0,0); + double sumTrkpT = 0; if( associationLinks.size() == 0 ) { ATH_MSG_VERBOSE("#BTAG# Could not find tracks associated with BTagging object as " << m_trackAssociationName); } else { @@ -460,15 +449,6 @@ namespace Analysis { for( trkIter = associationLinks.begin(); trkIter != associationLinks.end() ; ++trkIter ) { const xAOD::TrackParticle* aTemp = **trkIter; - if (m_impactParameterView=="3D") { - if (m_InDetTrackSelectorTool->accept(*aTemp, &priVtx) ) { - if (m_TightTrackVertexAssociationTool->isCompatible(*aTemp, priVtx)) { - TLorentzVector tmpTrack(0,0,0,0); - tmpTrack.SetPtEtaPhiM( aTemp->pt(), aTemp->eta(), aTemp->phi(),0); - pseudoTrackJet+=tmpTrack; ntrk++; - } - } - } if (m_trackSelectorTool->selectTrack(priVtx.position(), aTemp)) @@ -503,14 +483,6 @@ namespace Analysis { } } } - // temporary: storing these variables (which aren't IP3D-specific) ought to be moved to a separate Tool - if (m_xAODBaseName == "IP3D") { - BTag.auxdata<unsigned>("trkSum_ntrk") = ntrk; - BTag.auxdata<float>("trkSum_SPt") = sumTrkpT; - BTag.auxdata<float>("trkSum_VPt") = pseudoTrackJet.Pt(); - BTag.auxdata<float>("trkSum_VEta") = (pseudoTrackJet.Pt() != 0) ? pseudoTrackJet.Eta() : 1000; - } - ATH_MSG_VERBOSE("#BTAG# #tracks = " << nbTrak); ATH_MSG_VERBOSE("#BTAG# the z of the primary = " << priVtx.position().z()); diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/MultivariateTagManager.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/MultivariateTagManager.cxx index dd4dc2013de363394891af7fa34134528922b238..618b3c4677a6f7b2f38b0bab681163161d85d386 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/MultivariateTagManager.cxx +++ b/PhysicsAnalysis/JetTagging/JetTagTools/src/MultivariateTagManager.cxx @@ -120,7 +120,6 @@ namespace Analysis { fill_jetfitter(inputs, BTag); // fill JetFitter variables fill_sv0(priVtx, inputs, BTag); // fill sv0 variables fill_sv1(inputs, BTag); // fill sv1 variables - fill_mv2cl100(inputs, BTag); // fill MV2cl100 variables fill_trkSum(inputs,BTag); fill_softmuon(inputs,BTag); @@ -565,167 +564,6 @@ namespace Analysis { inputs[btagvar::SV1_DISTMATLAY] = sv1_distmatlay; } - void MultivariateTagManager::fill_mv2cl100(var_map& inputs, xAOD::BTagging& BTag) const { - // Generating MV2cl100 variables - std::vector< ElementLink< xAOD::TrackParticleContainer > > assocTracks; - try{ - assocTracks = BTag.auxdata<std::vector<ElementLink<xAOD::TrackParticleContainer> > >("BTagTrackToJetAssociator"); - } catch (std::exception& e) { - ATH_MSG_WARNING("problem loading associated tracks," - "skipping this jet"); - return; - } - - std::vector<ElementLink<xAOD::BTagVertexContainer> > jfvertices; - try { - jfvertices = BTag.auxdata<std::vector<ElementLink<xAOD::BTagVertexContainer> > >("JetFitter_JFvertices"); - } catch (std::exception& e) { - ATH_MSG_WARNING("problem loading JF vertices," - " skipping this jet"); - } - - std::vector<float> fittedPosition = BTag.auxdata<std::vector<float> >("JetFitter_fittedPosition"); - - //MV2cl100 default values - int nTrk_vtx1 = INT_MISSING; - float mass_first_vtx = NAN; - float e_first_vtx = NAN; - float e_frac_vtx1 = NAN; - float closestVtx_L3D = NAN; - float JF_Lxy1 = NAN; - float vtx1_MaxTrkRapidity_jf_path = NAN; - float vtx1_AvgTrkRapidity_jf_path = NAN; - float vtx1_MinTrkRapidity_jf_path = NAN; - float MaxTrkRapidity_jf_path = NAN; - float MinTrkRapidity_jf_path = NAN; - float AvgTrkRapidity_jf_path = NAN; - - if (assocTracks.size() > 0 && fittedPosition.size() > 0) { - - ATH_MSG_VERBOSE("#BTAG# MV2: calculating MV2cl100 inputs."); - - float jf_phi = fittedPosition[3]; - float jf_theta = fittedPosition[4]; - TVector3 flightDir(0,0,0); - flightDir.SetMagThetaPhi(1., jf_theta, jf_phi ); //flight directon of JF decay chain - - //loop over position of JF vertices, find index of secondary vertex - int secondary_vertex_index = INT_MISSING; - for (unsigned int jfv = 0; jfv < jfvertices.size(); jfv++) { - - float tmpL3D = fittedPosition[jfv + 5]; - - - if (tmpL3D > 0 && (std::isnan(closestVtx_L3D) || closestVtx_L3D > tmpL3D) ){ - - closestVtx_L3D = tmpL3D; - secondary_vertex_index = jfv; - } - } - - //loop over tracks, collect total 4 momentum, and 4 momentum of secondary vertex, calculate pseudo rapidity of track - TLorentzVector tracksTot4Mom(0,0,0,0); - TLorentzVector tracksTot4Mom_firstVtx(0,0,0,0); - float sumTrackRapidity = 0; - float vtx1_sumTrackRapidity = 0; - int vtx1_first_track =0; - float track_mass = 139.570; - int trkIndex=0; - //track loop - for(auto trkIter = assocTracks.begin(); trkIter != assocTracks.end(); ++trkIter) { - const xAOD::TrackParticle* aTemp = **trkIter; - uint8_t getInt(0); - aTemp->summaryValue(getInt, xAOD::numberOfPixelHits); - int nSi = getInt; - aTemp->summaryValue(getInt, xAOD::numberOfSCTHits); - nSi += getInt; - if (nSi < 2) continue; - - TLorentzVector trk; - trk.SetPtEtaPhiM(aTemp->pt(), aTemp->eta(), aTemp->phi(), track_mass); - tracksTot4Mom += trk; - - TVector3 trkvector(0,0,0); - trkvector = trk.Vect(); - - float trackRapidity = (trkvector.Mag2()>0 ? tan( 0.5*trkvector.Angle(flightDir) ) : 0); // steps to protect against log(0) - - trackRapidity = (trackRapidity < 0.000001 ? (-1)*log(0.000001) : (-1)*log(trackRapidity) ); // value of 0.000001 should provide enough margin for typical values of trackRapidity - - - sumTrackRapidity += trackRapidity; - - if(trkIndex==0){ - MaxTrkRapidity_jf_path = trackRapidity; - MinTrkRapidity_jf_path = trackRapidity; - }else{ - MaxTrkRapidity_jf_path = trackRapidity > MaxTrkRapidity_jf_path ? trackRapidity : MaxTrkRapidity_jf_path; - MinTrkRapidity_jf_path = trackRapidity < MinTrkRapidity_jf_path ? trackRapidity : MinTrkRapidity_jf_path; - } - - if(secondary_vertex_index >= 0){ - //get track links to secondary vertex - const xAOD::BTagVertex *tmpVertex = *(jfvertices.at(secondary_vertex_index)); - const std::vector< ElementLink<xAOD::TrackParticleContainer> > tmpVect = tmpVertex->track_links(); - //check association to JF vertex - int particleInCollection = 0; - - for (unsigned int iT = 0; iT < tmpVect.size(); iT++) { - if (aTemp == *(tmpVect.at(iT))) particleInCollection=1; - } - if (particleInCollection){ - - if(nTrk_vtx1 < 0){ - nTrk_vtx1 = 0; - } - nTrk_vtx1 += 1; - - tracksTot4Mom_firstVtx += trk; - vtx1_sumTrackRapidity += trackRapidity; - - if(!vtx1_first_track){ - vtx1_MaxTrkRapidity_jf_path = trackRapidity; - vtx1_MinTrkRapidity_jf_path = trackRapidity; - vtx1_first_track=1; - }else{ - vtx1_MaxTrkRapidity_jf_path = trackRapidity > vtx1_MaxTrkRapidity_jf_path ? trackRapidity : vtx1_MaxTrkRapidity_jf_path; - vtx1_MinTrkRapidity_jf_path = trackRapidity < vtx1_MinTrkRapidity_jf_path ? trackRapidity : vtx1_MinTrkRapidity_jf_path; - } - - } - } - - trkIndex++; - } //end of trk loop - - // assign the remaining MV2cl100 variables - AvgTrkRapidity_jf_path = trkIndex > 0 ? sumTrackRapidity/trkIndex : 0; - - if(nTrk_vtx1 > 0){ - JF_Lxy1 = closestVtx_L3D*sin(jf_theta); - mass_first_vtx = tracksTot4Mom_firstVtx.M(); - e_first_vtx = tracksTot4Mom_firstVtx.E(); - e_frac_vtx1 = e_first_vtx/tracksTot4Mom.E(); - vtx1_AvgTrkRapidity_jf_path = vtx1_sumTrackRapidity/nTrk_vtx1; - } - - } // end of if (assocTracks.size() > 0 && fittedPosition.size() > 0 - - inputs[btagvar::JF_NTRK_VTX1] = nan_if_placeholder(nTrk_vtx1); - inputs[btagvar::JF_MASS_VTX1 ] = mass_first_vtx ; - inputs[btagvar::JF_E_VTX1 ] = e_first_vtx ; - inputs[btagvar::JF_E_FRAC_VTX1 ] = e_frac_vtx1; - inputs[btagvar::JF_L3D_VTX1 ] = closestVtx_L3D ; - inputs[btagvar::JF_Lxy_VTX1 ] = JF_Lxy1 ; - inputs[btagvar::JF_RAPIDITY_VTX1_MAX ] = vtx1_MaxTrkRapidity_jf_path; - inputs[btagvar::JF_RAPIDITY_VTX1_AVG ] = vtx1_AvgTrkRapidity_jf_path; - inputs[btagvar::JF_RAPIDITY_VTX1_MIN ] = vtx1_MinTrkRapidity_jf_path; - inputs[btagvar::JF_RAPIDITY_MAX ] = MaxTrkRapidity_jf_path; - inputs[btagvar::JF_RAPIDITY_MIN ] = MinTrkRapidity_jf_path; - inputs[btagvar::JF_RAPIDITY_AVG ] = AvgTrkRapidity_jf_path; - - } // end of fill_mv2cl100 - void MultivariateTagManager::fill_arbitrary_aux_data( var_map& inputs, xAOD::BTagging& BTag) const { diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/RNNIPTag.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/RNNIPTag.cxx deleted file mode 100644 index f093904bd03e57df9de854cf357b47220e58d9ea..0000000000000000000000000000000000000000 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/RNNIPTag.cxx +++ /dev/null @@ -1,754 +0,0 @@ -/* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration -*/ - -#include "JetTagTools/RNNIPTag.h" -#include "lwtnn/LightweightNeuralNetwork.hh" -#include "lwtnn/parse_json.hh" -#include "lwtnn/Exceptions.hh" - -#include "JetTagTools/TrackSelector.h" -#include "JetTagTools/GradedTrack.h" -#include "JetTagTools/SVForIPTool.h" -#include "JetTagTools/ITrackGradeFactory.h" - -#include "JetTagInfo/TrackGrade.h" -#include "JetTagInfo/TrackGradesDefinition.h" - -#include "TrkVertexFitterInterfaces/ITrackToVertexIPEstimator.h" - -#include "xAODTracking/TrackParticle.h" -#include "xAODTracking/TrackParticleContainer.h" - -#include "ITrackToVertex/ITrackToVertex.h" - -#include "CLHEP/Vector/LorentzVector.h" -#include "GeoPrimitives/GeoPrimitives.h" -#include "GeoPrimitives/GeoPrimitivesHelpers.h" -#include "GaudiKernel/IToolSvc.h" - -#include <cmath> -#include <fstream> -#include <algorithm> -#include <vector> -#include <string> - -// locally used functions and typedefs -namespace { - using namespace Analysis; - typedef std::map<std::string, std::vector<double> > VectorMap; - VectorMap get_nn_inputs(const std::vector<IPxDInfo>&); - size_t fill_posteriors(xAOD::BTagging&, - const std::string& author, - const std::vector<std::string>& names, - const lwt::ValueMap& = lwt::ValueMap()); - void fill_inputs(xAOD::BTagging&, - const std::string& author, - const lwt::VectorMap& inputs); - - typedef std::vector<ElementLink<xAOD::TrackParticleContainer> > TrackLinks; - - // keys to lookup track sorting info - const std::string SORT_BY = "sort_by"; - const std::string UNKNOWN_SORT = "unknown_sort"; - std::string get_sort_name(const lwt::JSONConfig& cfg); - TrackSorter get_sort_function(const std::string& key); - -struct TrackSorterFunctional -{ - TrackSorterFunctional (const TrackSorter& sorter) - : m_sorter (sorter) {} - bool operator() (const IPxDInfo& a, const IPxDInfo& b) const - { - return m_sorter (a, b); - } - - const TrackSorter& m_sorter; -}; - -} - -// Track variable names, for both the NN inputs and for writing to the -// xAOD EDM. -namespace trkvar { - const std::string D0 = "d0"; - const std::string D0_SIG = "d0sig"; - const std::string Z0 = "z0"; - const std::string Z0_SIG = "z0sig"; - const std::string D0Z0_SIG = "d0z0sig"; - const std::string GRADE = "grade"; - const std::string FROM_V0 = "fromV0"; - const std::string PT = "pt"; - const std::string DPHI = "dPhi"; - const std::string ABS_ETA = "absEta"; - const std::string DETA = "dEta"; - const std::string CHARGE = "charge"; - - const std::string PT_FRAC = "pTFrac"; - const std::string DR = "dR"; - - // hit info - const std::string CHI2 = "chi2"; - const std::string N_INN_HITS = "nInnHits"; - const std::string N_NEXT_TO_INN_HITS = "nNextToInnHits"; - const std::string N_BL_HITS = "nBLHits"; - const std::string N_SHARED_BL_HITS = "nsharedBLHits"; - const std::string N_SPLIT_BL_HITS = "nsplitBLHits"; - const std::string N_PIX_HITS = "nPixHits"; - const std::string N_SHARED_PIX_HITS = "nsharedPixHits"; - const std::string N_SPLIT_PIX_HITS = "nsplitPixHits"; - const std::string N_SCT_HITS = "nSCTHits"; - const std::string N_SHARED_SCT_HITS = "nsharedSCTHits"; - const std::string EXPECT_BL_HIT = "expectInnermostPixelLayerHit"; - const std::string EXPECT_INNERMOST_PIX_HIT = - "expectInnermostPixelLayerHit"; - const std::string EXPECT_NEXT_TO_INNERMOST_PIX_HIT = - "expectNextToInnermostPixelLayerHit"; -} - -namespace Analysis { - struct IPxDInfo { - ElementLink<xAOD::TrackParticleContainer> trk; - double d0; - double d0sig; - double z0; - double z0sig; - double dphi; - double ptfrac; - double dr; - double deta; - TrackGrade grade; - const xAOD::TrackParticle* trkP; - bool fromV0; - } ; - - bool StructPTsorting(const IPxDInfo& objA, const IPxDInfo& objB) { - return (objA.trkP)->pt() > (objB.trkP)->pt(); - } - - bool StructD0Sigsorting(const IPxDInfo& objA, const IPxDInfo& objB) { - return fabs(objA.d0sig) > fabs(objB.d0sig); - } - - bool StructZ0D0Sigsorting(const IPxDInfo& objA, const IPxDInfo& objB) { - double a = pow(objA.d0sig,2)+pow(objA.z0sig,2); - double b = pow(objB.d0sig,2)+pow(objB.z0sig,2); - return a > b; - } - - - /** - @class RNNIPTag - b-jet tagger based on 2D or 3D impact parameter - @author CPPM Marseille - */ - - - RNNIPTag::RNNIPTag(const std::string& t, - const std::string& n, - const IInterface* p) - : base_class(t,n,p), - m_unbiasIPEstimation(true), - m_calibrationDirectory("RNNIP"), - m_secVxFinderName("InDetVKalVxInJetTool"), - m_trackSelectorTool("Analysis::TrackSelector", this), - m_SVForIPTool("Analysis::SVForIPTool", this), - m_trackGradeFactory("Analysis::BasicTrackGradeFactory", this), - m_trackToVertexIPEstimator(this) - { - // global configuration: - declareProperty("xAODBaseName" , m_xAODBaseName); - - declareProperty("flipIPSign" , m_flipIP = false); - declareProperty("flipZIPSign" , m_flipZIP = false); - declareProperty("usePosIP" , m_usePosIP = true); - declareProperty("useNegIP" , m_useNegIP = true); - declareProperty("useZIPSignForPosNeg" , m_useZIPSignForPosNeg = false); - declareProperty("use2DSignForIP3D" , m_use2DSignForIP3D = false); - declareProperty("useD0SignForZ0" , m_useD0SignForZ0 = false); - declareProperty("RejectBadTracks" , m_rejectBadTracks = true); - declareProperty("unbiasIPEstimation" , m_unbiasIPEstimation); - declareProperty("writeInputsToBtagObject", - m_writeInputsToBtagObject = false); - declareProperty("writeTrackLinks", - m_writeTrackLinks = false); - - declareProperty("trackAssociationName" , - m_trackAssociationName = "BTagTrackToJetAssociator"); - declareProperty("originalTPCollectionName", - m_originalTPCollectionName = "InDetTrackParticles"); - declareProperty("ForcedCalibrationName" , m_ForcedCalibName = "AntiKt4EMTopo"); - declareProperty("NetworkConfig" , m_network_cfg); - - declareProperty("trackGradePartitions" , - m_trackGradePartitionsDefinition); - m_trackGradePartitionsDefinition.push_back("Good"); - - declareProperty("SecVxFinderName" ,m_secVxFinderName); - - // tools: - declareProperty("trackSelectorTool" , m_trackSelectorTool ); - declareProperty("SVForIPTool" , m_SVForIPTool ); - declareProperty("trackGradeFactory" , m_trackGradeFactory ); - declareProperty("TrackToVertexIPEstimator" , m_trackToVertexIPEstimator); - declareProperty("calibration_directory", m_calibrationDirectory); - } - - - RNNIPTag::~RNNIPTag() { - for (size_t i = 0; i < m_trackGradePartitions.size(); i++) - delete m_trackGradePartitions[i]; - - // Networks are owned by the structure they are created in - } - - - StatusCode RNNIPTag::initialize() { - - // FF: comment out V0 finding - if (m_SVForIPTool.retrieve().isFailure() ) { - ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_SVForIPTool); - return StatusCode::FAILURE; - } else { - ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_SVForIPTool); - } - if (m_trackToVertexIPEstimator.retrieve().isFailure() ) { - ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << - m_trackToVertexIPEstimator); - return StatusCode::FAILURE; - } else { - ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackToVertexIPEstimator); - } - - - /** creation of TrackSelector: (private instance) */ - if ( m_trackSelectorTool.retrieve().isFailure() ) { - ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_trackSelectorTool); - return StatusCode::FAILURE; - } else { - ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackSelectorTool); - } - - /** retrieving the track grade factory */ - if ( m_trackGradeFactory.retrieve().isFailure() ) { - ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_trackGradeFactory); - return StatusCode::FAILURE; - } else { - ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackGradeFactory); - } - - /** prepare the track partitions: */ - int nbPart = m_trackGradePartitionsDefinition.size(); - ATH_MSG_DEBUG("#BTAG# Defining " << nbPart <<" track partitions: "); - for(int i=0;i<nbPart;i++) { - TrackGradePartition* part = nullptr; - try { - part = new TrackGradePartition(m_trackGradePartitionsDefinition[i], - *m_trackGradeFactory); - } - catch (std::string error) { - ATH_MSG_ERROR("#BTAG# Reported error " << error); - ATH_MSG_ERROR("#BTAG# List of categories provided to IPTag by jO : "); - for (int l=0;l<nbPart;l++) { - ATH_MSG_ERROR( - "#BTAG# string " << m_trackGradePartitionsDefinition[l]); - } - ATH_MSG_ERROR("#BTAG# List of categories provided by the" - " TrackGradeFactory " << m_trackGradeFactory); - - if (msgLvl(MSG::ERROR)) { - const auto& grades = m_trackGradeFactory->getTrackGradesDefinition(); - for (const auto& grade: grades.getList() ) { - ATH_MSG_ERROR("#BTAG# n. " << grade.gradeNumber() << - " string " << grade.gradeString()); - } - } - ATH_MSG_ERROR("#BTAG# Terminating now... "); - return StatusCode::FAILURE; - } - ATH_MSG_DEBUG((*part)); - m_trackGradePartitions.push_back(part); - } - - // prepare readKey for calibration data: - ATH_CHECK(m_readKey.initialize()); - - return StatusCode::SUCCESS; - } - - - StatusCode RNNIPTag::finalize() { - return StatusCode::SUCCESS; - } - - - StatusCode RNNIPTag::tagJet(const xAOD::Vertex& priVtx, - const xAOD::Jet& jetToTag, - xAOD::BTagging& BTag, - const std::string &jetName) const - { - /** author to know which jet algorithm: */ - std::string author = jetName; - if (m_ForcedCalibName.size() > 0) author = m_ForcedCalibName; - ATH_MSG_VERBOSE("#BTAG# Using jet type " << author << " for calibrations"); - - std::vector<GradedTrack> tracksInJet; - int nbPart = m_trackGradePartitionsDefinition.size(); - - std::vector<const xAOD::TrackParticle*> TrkFromV0; - - // bad tracks from V0s, conversions, interactions: - m_SVForIPTool->getTrkFromV0FromSecondaryVertexInfo( - TrkFromV0,//output - &BTag,m_secVxFinderName);//input - - ATH_MSG_VERBOSE("#BTAG# VALERIO TrkFromV0 : number of reconstructed" - " bad tracks: " << TrkFromV0.size()); - if (TrkFromV0.size()!=0) ATH_MSG_DEBUG( - "#BTAG# TrkFromV0 : number of reconstructed bad tracks: " << - TrkFromV0.size()); - - /** extract the TrackParticles from the jet and apply track selection: */ - int nbTrak = 0; - - const auto& associationLinks = BTag.auxdata<TrackLinks>( - m_trackAssociationName); - double sumTrkpT = 0; - if( associationLinks.size() == 0 ) { - ATH_MSG_VERBOSE("#BTAG# Could not find tracks associated with" - " BTagging object as " << m_trackAssociationName); - } else { - - // We loop over the tracks twice: the first time is to compute - // the summed pt of all tracks satisfying the "normal" criteria; - // the second time a possibly tighter pt cut may be applied - for(const auto& trk: associationLinks) { - const xAOD::TrackParticle* aTemp = *trk; - if (m_trackSelectorTool->selectTrack(priVtx.position(), aTemp)) - { - sumTrkpT += aTemp->pt(); - } - } - // m_trackSelectorTool->setSumTrkPt(sumTrkpT); - - for(const auto& trk: associationLinks) { - const xAOD::TrackParticle* aTemp = *trk; - nbTrak++; - if( m_trackSelectorTool->selectTrack(priVtx.position(), aTemp, sumTrkpT) ) { - TrackGrade* theGrade = m_trackGradeFactory->getGrade( - *aTemp, jetToTag.p4() ); - ATH_MSG_VERBOSE("#BTAG# result of selectTrack is OK, grade= " - << theGrade->gradeString() ); - bool tobeUsed = false; - for(int i=0;i<nbPart;i++) { - if( std::find( (m_trackGradePartitions[i]->grades()).begin(), - (m_trackGradePartitions[i]->grades()).end(), - *theGrade ) - != (m_trackGradePartitions[i]->grades()).end() ){ - tobeUsed = true; - } - } - // is it a bad track ? - if( std::find(TrkFromV0.begin(),TrkFromV0.end(),aTemp) - != TrkFromV0.end() ) { - ATH_MSG_VERBOSE("#BTAG# Bad track in jet, pt = " << aTemp->pt() << - " eta = " << aTemp->eta() << " phi = " << - aTemp->phi() ); - if (m_rejectBadTracks) tobeUsed = false; - } - // check required IP sign: - if (tobeUsed) tracksInJet.push_back(GradedTrack(trk, *theGrade)); - delete theGrade; - theGrade=0; - } - } - } - - ATH_MSG_VERBOSE("#BTAG# #tracks = " << nbTrak); - ATH_MSG_VERBOSE("#BTAG# the z of the primary = " << - priVtx.position().z()); - - /** jet direction: */ - Amg::Vector3D jetDirection(jetToTag.px(),jetToTag.py(),jetToTag.pz()); - - /** prepare vectors with all track information: TP links, - * i.p. significances, track grade, etc */ - auto track_info = get_track_info(priVtx, tracksInJet, jetDirection, TrkFromV0); - - // add the tags - add_tags(BTag, author, track_info); - - if (m_writeTrackLinks) { - TrackLinks ip_tracks; - for (const auto& trk: track_info) { - ip_tracks.push_back( trk.trk ); - } - - // specific fast accessors for mainstream instances of IPTag: IP3D, IP2D - //// need to handle to persistify for dynamic values before adding this - BTag.setVariable<TrackLinks> ( - m_xAODBaseName, "TrackParticleLinks", ip_tracks ); - BTag.setDynTPELName( m_xAODBaseName, "TrackParticleLinks"); - } - - return StatusCode::SUCCESS; - } - - // ___________________________________________________________ - // apply tags loop - void RNNIPTag::add_tags(xAOD::BTagging& tag, const std::string& author, - std::vector<IPxDInfo>& track_info) const { - - // first loop is over the different sorting functions - for (const auto& sort_group: get_networks_for(author)) { - const auto& sort_func = sort_group.first; - const auto& networks = sort_group.second; - // This doesn't compile with clang 3.8 and gcc 6.1 - //std::sort( track_info.begin(), track_info.end(), sort_func); - TrackSorterFunctional sorter (sort_func); - std::sort( track_info.begin(), track_info.end(), sorter); - const auto inputs = get_nn_inputs(track_info); - - // inner loop is over the networks that use this sort function - for (const auto& network: networks) { - if (track_info.size() == 0) { - ATH_MSG_DEBUG("no tracks, filling with defaults"); - fill_posteriors(tag, network.name, network.outputs); - continue; - } - try { - lwt::ValueMap out = network.network->reduce(inputs); - fill_posteriors(tag, network.name, network.outputs, out); - if (msgLvl(MSG::DEBUG)) { - std::string op = "output for " + network.name + ": "; - for (const auto& pr: out) { - op.append(pr.first + " = " + std::to_string(pr.second) + ", "); - } - ATH_MSG_DEBUG(op); - } - } catch (lwt::NNEvaluationException& e) { - ATH_MSG_WARNING(e.what() << " tagging with " + network.name - + ", will fill with defaults"); - fill_posteriors(tag, network.name, network.outputs); - } - } // end loop over networks - // for each sorting, store inputs - if (networks.size() > 0) { - if (m_writeInputsToBtagObject) { - fill_inputs(tag, networks.front().name, inputs); - } - } else { - ATH_MSG_ERROR("Found sorting function in RNNIP with no accompanying" - " inputs. This should not happen."); - } - } // end loop over sorting functions - - } - - RNNIPTag::Network::Network(const std::string& net_name, - const lwt::JSONConfig& cf): - name(net_name), - network(new lwt::LightweightRNN(cf.inputs, cf.layers, cf.outputs)), - outputs(cf.outputs) - { - } - - std::string RNNIPTag::get_calib_string(const std::string& author, - const std::string& name) const - { - // if we have an override we ignore the author and just read from - // a text file - if (m_network_cfg.at(name).size() > 0) { - ATH_MSG_DEBUG("Reading from local file"); - std::ifstream file(m_network_cfg.at(name)); - std::stringstream out; - out << file.rdbuf(); - return out.str(); - } else { - ATH_MSG_DEBUG("reading out from DB"); - } - - SG::ReadCondHandle<JetTagCalibCondData> readCdo(m_readKey); - return readCdo->retrieveIPRNN(m_calibrationDirectory , author); - } - - - - const RNNIPTag::SortGroups& - RNNIPTag::get_networks_for(const std::string& author) const { - using std::map; - using std::string; - using std::pair; - using std::vector; - using namespace lwt; - - std::lock_guard<std::mutex> lock (m_networksMutex); - - // TODO: delete networks if they've gone out of the IOV, needs - // some calibration broker code. On the other hand, we've never - // had an IOV end within a job. Will we? - auto it = m_networks.find(author); - if (it != m_networks.end()) { - return it->second; - } - SortGroups& groups = m_networks[author]; - - // order the networks we need to build by the sort function - typedef map<string, vector<pair<string, JSONConfig > > > NWBySort; - NWBySort nw_by_sort_func; - for (const auto& cfg: m_network_cfg) { - const auto& cfg_name = cfg.first; - std::string calstring = get_calib_string(author, cfg_name); - if (calstring.size() == 0) { - ATH_MSG_WARNING("cant load '" + cfg_name + "' for '" + author + "'"); - continue; - } - ATH_MSG_DEBUG("calstring for " + author + ", " + cfg_name + ": " - << calstring.size() << " characters"); - std::stringstream stream(calstring); - try { - lwt::JSONConfig nncfg = lwt::parse_json(stream); - auto sort_name = get_sort_name(nncfg); - nw_by_sort_func[sort_name].emplace_back(cfg_name, nncfg); - } catch (std::exception& e) { - ATH_MSG_WARNING(e.what() << ", will not run '" + cfg_name - + "' for '" + author + "' jets"); - } - } - - // build the groups for this author - for (const auto& sf_nw: nw_by_sort_func) { - // TODO: add more sort func - TrackSorter sort = get_sort_function(sf_nw.first); - groups.emplace_back(sort, Networks()); - for (const auto& name_and_network_conf: sf_nw.second) { - const auto& nw_config = name_and_network_conf.second; - const auto& nw_name = name_and_network_conf.first; - ATH_MSG_DEBUG(nw_name + ": " << nw_config.layers.size() << " layers"); - auto& nw_group = groups.back().second; - try { - nw_group.emplace_back(nw_name, nw_config); - } catch (lwt::NNConfigurationException& e) { - ATH_MSG_WARNING(nw_name + " init failure: " + e.what()); - } - } - } - - return groups; - } - - // ____________________________________________________________ - // Get track info vector - - std::vector<IPxDInfo> RNNIPTag::get_track_info( - const xAOD::Vertex& priVtx, - const std::vector<GradedTrack>& tracksInJet, - const Amg::Vector3D& jetDirection, - const std::vector<const xAOD::TrackParticle*>& TrkFromV0) const { - Amg::Vector3D unit = jetDirection.unit(); - double jet_pt = std::hypot(jetDirection.x(), jetDirection.y()); - - std::vector<IPxDInfo> track_info; - - for (std::vector<GradedTrack>::const_iterator trkItr = tracksInJet.begin(); - trkItr != tracksInJet.end(); ++trkItr) { - - const xAOD::TrackParticle* trk = *(trkItr->track); - const auto& trk4 = trk->p4(); - const Amg::Vector3D trk_momentum(trk4.Px(), trk4.Py(), trk4.Pz()); - - bool isFromV0 = ( - std::find(TrkFromV0.begin(),TrkFromV0.end(),trk) != TrkFromV0.end()); - - /** track parameters defined at the primary vertex: */ - double d0wrtPriVtx(0.); - double z0wrtPriVtx(0.); - double d0ErrwrtPriVtx(1.); - double z0ErrwrtPriVtx(1.); - - /** use new Tool for "unbiased" IP estimation */ - const Trk::ImpactParametersAndSigma* myIPandSigma(0); - if (m_trackToVertexIPEstimator) { - myIPandSigma = m_trackToVertexIPEstimator->estimate( - trk, &priVtx, m_unbiasIPEstimation); - } - if(0==myIPandSigma) { - ATH_MSG_WARNING("#BTAG# IPTAG: trackToVertexIPEstimator failed !"); - } else { - d0wrtPriVtx=myIPandSigma->IPd0; - d0ErrwrtPriVtx=myIPandSigma->sigmad0; - z0wrtPriVtx=myIPandSigma->IPz0SinTheta; - z0ErrwrtPriVtx=myIPandSigma->sigmaz0SinTheta; - delete myIPandSigma; - myIPandSigma=0; - } - - /** sign of the impact parameter */ - double signOfIP(1.); - if ( m_use2DSignForIP3D ) { - signOfIP=m_trackToVertexIPEstimator->get2DLifetimeSignOfTrack( - trk->perigeeParameters(),unit, priVtx); - } else { - signOfIP=m_trackToVertexIPEstimator->get3DLifetimeSignOfTrack( - trk->perigeeParameters(), unit, priVtx); - } - double signOfZIP = m_trackToVertexIPEstimator->getZLifetimeSignOfTrack( - trk->perigeeParameters(), unit, priVtx); - - if (m_useD0SignForZ0) signOfZIP = signOfIP; - - /** option to flip signs for negative tag method */ - if(m_flipIP ) signOfIP = -signOfIP; - if(m_flipZIP ) signOfZIP = -signOfZIP; - - /** select according to sign: skip tracks if not ok */ - if(signOfIP>0 && !m_usePosIP) continue; - if(signOfIP<0 && !m_useNegIP) continue; - if( m_useZIPSignForPosNeg ) { - if(signOfZIP>0 && !m_usePosIP) continue; - if(signOfZIP<0 && !m_useNegIP) continue; - } - - /** significances */ - double sIP = signOfIP*fabs(d0wrtPriVtx); - double significance= signOfIP*fabs(d0wrtPriVtx/d0ErrwrtPriVtx); - double szIP = signOfZIP*fabs(z0wrtPriVtx); - double z0Sig = signOfZIP*fabs(z0wrtPriVtx/z0ErrwrtPriVtx); - - // VD: I know that this is ugly but I want to minimise the - // changes as much as I can - IPxDInfo tmpObj; - tmpObj.trk=trkItr->track; - tmpObj.d0 =sIP; - tmpObj.d0sig=significance; - tmpObj.z0 =szIP; - tmpObj.z0sig=z0Sig; - tmpObj.grade=trkItr->grade; - tmpObj.trkP =trk; - tmpObj.fromV0=isFromV0; - tmpObj.dphi = Amg::deltaPhi(trk_momentum, unit); - tmpObj.dr = Amg::deltaR(trk_momentum, unit); - tmpObj.deta = trk_momentum.eta() - unit.eta(); - tmpObj.ptfrac = trk->pt() / jet_pt; - track_info.push_back(tmpObj); - } - return track_info; - } - -}//end namespace - -namespace { - double val(const xAOD::TrackParticle& tp, const xAOD::SummaryType& prop) { - uint8_t val; - tp.summaryValue(val, prop); - return val; - } - - VectorMap get_nn_inputs(const std::vector<IPxDInfo>& tracks) { - using namespace trkvar; - const std::vector<std::string> inputs{ - D0, D0_SIG, Z0, Z0_SIG, D0Z0_SIG, GRADE, FROM_V0, PT, DPHI, ABS_ETA, - PT_FRAC, DR, DETA, CHARGE, - CHI2, N_INN_HITS, N_NEXT_TO_INN_HITS, N_BL_HITS, N_SHARED_BL_HITS, - N_SPLIT_BL_HITS, N_PIX_HITS, N_SHARED_PIX_HITS, N_SPLIT_PIX_HITS, - N_SCT_HITS, N_SHARED_SCT_HITS, EXPECT_BL_HIT, - EXPECT_INNERMOST_PIX_HIT, EXPECT_NEXT_TO_INNERMOST_PIX_HIT}; - VectorMap out; - for (const auto& input: inputs) { - out.emplace(input, std::vector<double>()); - } - for (const auto& tk: tracks) { - out.at(D0).push_back(tk.d0); - out.at(D0_SIG).push_back(tk.d0sig); - out.at(Z0).push_back(tk.z0); - out.at(Z0_SIG).push_back(tk.z0sig); - out.at(D0Z0_SIG).push_back(std::hypot(tk.z0sig, tk.d0sig)); - out.at(GRADE).push_back(tk.grade); - out.at(FROM_V0).push_back(tk.fromV0); - out.at(PT).push_back(tk.trkP->pt()); - out.at(DPHI).push_back(tk.dphi); - out.at(ABS_ETA).push_back(std::abs(tk.trkP->eta())); - out.at(PT_FRAC).push_back(tk.ptfrac); - out.at(DR).push_back(tk.dr); - out.at(DETA).push_back(tk.deta); - out.at(CHARGE).push_back(tk.trkP->charge()); - - const auto& tp = *tk.trkP; - out.at(CHI2).push_back(tp.chiSquared()); - out.at(N_INN_HITS).push_back( - val(tp,xAOD::numberOfInnermostPixelLayerHits)); - out.at(N_NEXT_TO_INN_HITS).push_back( - val(tp, xAOD::numberOfNextToInnermostPixelLayerHits)); - out.at(N_BL_HITS).push_back( - val(tp, xAOD::numberOfInnermostPixelLayerHits)); - out.at(N_SHARED_BL_HITS).push_back( - val(tp, xAOD::numberOfInnermostPixelLayerSharedHits)); - out.at(N_SPLIT_BL_HITS).push_back( - val(tp, xAOD::numberOfInnermostPixelLayerSplitHits)); - out.at(N_PIX_HITS).push_back( - val(tp, xAOD::numberOfPixelHits)); - out.at(N_SHARED_PIX_HITS).push_back( - val(tp, xAOD::numberOfPixelSharedHits)); - out.at(N_SPLIT_PIX_HITS).push_back( - val(tp, xAOD::numberOfPixelSplitHits)); - out.at(N_SCT_HITS).push_back( - val(tp, xAOD::numberOfSCTHits)); - out.at(N_SHARED_SCT_HITS).push_back( - val(tp, xAOD::numberOfSCTSharedHits)); - out.at(EXPECT_BL_HIT).push_back( - val(tp, xAOD::expectInnermostPixelLayerHit)); - out.at(EXPECT_INNERMOST_PIX_HIT).push_back( - val(tp, xAOD::expectInnermostPixelLayerHit)); - out.at(EXPECT_NEXT_TO_INNERMOST_PIX_HIT).push_back( - val(tp, xAOD::expectNextToInnermostPixelLayerHit)); - } - return out; - } - - size_t fill_posteriors(xAOD::BTagging& tag, - const std::string& author, - const std::vector<std::string>& outputs, - const lwt::ValueMap& vals) { - size_t found = 0; - for (const auto& out: outputs) { - double val = 0; // was NaN, see jira: AFT-194, ATLASRECTS-3897 - bool is_valid = false; - if (vals.count(out)) { - val = vals.at(out); - found++; - is_valid = true; - } - tag.setVariable<double>(author, out, val); - std::string valid_key = out + "IsValid"; - tag.setVariable<char>(author, valid_key, is_valid); - } - return found; - } - void fill_inputs(xAOD::BTagging& tag, - const std::string& author, - const lwt::VectorMap& inputs) { - // cast to float to save space - typedef std::vector<float> OutVector; - for (const auto& in: inputs) { - OutVector outvec(in.second.begin(), in.second.end()); - tag.setVariable<OutVector>(author, in.first, outvec); - } - } - - std::string get_sort_name(const lwt::JSONConfig& cfg) { - if (!cfg.miscellaneous.count(SORT_BY)) { - throw std::logic_error("sort function not given"); - } - return cfg.miscellaneous.at(SORT_BY); - } - - Analysis::TrackSorter get_sort_function(const std::string& key) { - using namespace trkvar; - using namespace Analysis; - if (key == D0_SIG) return StructD0Sigsorting; - if (key == PT) return StructPTsorting; - if (key == D0Z0_SIG) return StructZ0D0Sigsorting; - throw std::logic_error("sort by " + key + " is not defined"); - } - -} diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/SVTag.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/SVTag.cxx index 9e2e6791e1a911496b58f569714ef9bbea3af09f..f4421ab5403725c94c3d13d3bed51f0712ef65a6 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/SVTag.cxx +++ b/PhysicsAnalysis/JetTagging/JetTagTools/src/SVTag.cxx @@ -53,6 +53,7 @@ namespace Analysis declareProperty("UseDRJetPvSv", m_useDRJPVSV = true); declareProperty("UseCHypo", m_useCHypo=true); declareProperty("UseSV2Pt", m_usePtSV2=false); + declareProperty("SaveProbabilities", m_save_probabilities=false); } @@ -446,9 +447,11 @@ namespace Analysis } } + if (m_save_probabilities) { BTag.setVariable<double>(m_xAODBaseName, "pb", probi[0]); BTag.setVariable<double>(m_xAODBaseName, "pu", probi[1]); if (m_useCHypo) BTag.setVariable<double>(m_xAODBaseName, "pc", probi[2]); + } } diff --git a/PhysicsAnalysis/JetTagging/JetTagTools/src/components/JetTagTools_entries.cxx b/PhysicsAnalysis/JetTagging/JetTagTools/src/components/JetTagTools_entries.cxx index 8d6e7c6da50a08c2e1eccee50879657f9489f7e3..d7e16237c41e2b35be95c44c0e9fd051f78891d9 100644 --- a/PhysicsAnalysis/JetTagging/JetTagTools/src/components/JetTagTools_entries.cxx +++ b/PhysicsAnalysis/JetTagging/JetTagTools/src/components/JetTagTools_entries.cxx @@ -1,5 +1,4 @@ #include "JetTagTools/IPTag.h" -#include "JetTagTools/RNNIPTag.h" #include "JetTagTools/SVTag.h" #include "JetTagTools/MultiSVTag.h" @@ -14,7 +13,6 @@ #include "JetTagTools/MSVVariablesFactory.h" #include "JetTagTools/MultivariateTagManager.h" -#include "JetTagTools/DL1Tag.h" #include "JetTagTools/TagNtupleDumper.h" #include "JetTagTools/JetFitterNNTool.h" #include "JetTagTools/JetFitterDummyClassifier.h" @@ -27,11 +25,8 @@ #include "JetTagTools/MV1Tag.h" #include "JetTagTools/MV2Tag.h" -#include "JetTagTools/ExKtbbTagTool.h" - DECLARE_COMPONENT( Analysis::IPTag ) -DECLARE_COMPONENT( Analysis::RNNIPTag ) DECLARE_COMPONENT( Analysis::SVTag ) DECLARE_COMPONENT( Analysis::MultiSVTag ) DECLARE_COMPONENT( Analysis::SoftMuonTag ) @@ -41,7 +36,6 @@ DECLARE_COMPONENT( Analysis::JetFitterTag ) DECLARE_COMPONENT( Analysis::JetFitterNtupleWriter ) DECLARE_COMPONENT( Analysis::JetFitterVariablesFactory ) DECLARE_COMPONENT( Analysis::MSVVariablesFactory ) -DECLARE_COMPONENT( Analysis::DL1Tag ) DECLARE_COMPONENT( Analysis::TagNtupleDumper ) DECLARE_COMPONENT( Analysis::MultivariateTagManager ) DECLARE_COMPONENT( Analysis::JetFitterNNTool ) @@ -52,4 +46,4 @@ DECLARE_COMPONENT( Analysis::BasicTrackGradeFactory ) DECLARE_COMPONENT( Analysis::DetailedTrackGradeFactory ) DECLARE_COMPONENT( Analysis::MV1Tag ) DECLARE_COMPONENT( Analysis::MV2Tag ) -DECLARE_COMPONENT( Analysis::ExKtbbTagTool ) +