Verified Commit 0960912c authored by Tadej Novak's avatar Tadej Novak
Browse files

CP algs: Add ElectronAnalysisHelpers for SF functions

parent 868ef9b4
Pipeline #1279115 passed with stage
in 0 seconds
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
# Framework import(s):
from ROOT import PATCore
# AnaAlgorithm import(s):
from AnaAlgorithm.DualUseConfig import createAlgorithm, addPrivateTool
def addElectronIdentificationSelectionAlg( sequence, identification,
postfix='',
preselection='' ):
"""Add electron identification selection algorithm used to get the
output decoration.
Keyword arguments:
sequence -- Sequence to add to
postfix -- a postfix to apply to decorations and algorithm
names. this is mostly used/needed when using this
sequence with multiple working points to ensure all
names are unique.
preselection -- preselection to apply
identification -- electron identification working point
"""
alg = createAlgorithm( 'CP::AsgSelectionAlg',
'ElectronLikelihoodAlg' + identification + postfix )
alg.preselection = preselection
addPrivateTool( alg, 'selectionTool', 'CP::AsgFlagSelectionTool' )
alg.selectionDecoration = 'identification_' + identification + ',as_char'
alg.selectionTool.selectionFlags = [ 'DFCommonElectronsLH' + identification ]
sequence.append( alg, inputPropName = 'particles',
stageName = 'efficiency' )
def addElectronIsolationSelectionAlg( sequence, isolation,
postfix='',
preselection='' ):
"""Add electron isolation selection algorithm used to get the
output decoration.
Keyword arguments:
sequence -- Sequence to add to
postfix -- a postfix to apply to decorations and algorithm
names. this is mostly used/needed when using this
sequence with multiple working points to ensure all
names are unique.
preselection -- preselection to apply
isolation -- electron isolation working point
"""
alg = createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
'ElectronIsolationSelectionAlg' + isolation + postfix)
alg.preselection = preselection
addPrivateTool( alg, 'selectionTool', 'CP::IsolationSelectionTool' )
alg.selectionDecoration = 'isIsolated_' + isolation + ',as_char'
alg.selectionTool.ElectronWP = isolation
sequence.append( alg, inputPropName = 'egammas',
stageName = 'efficiency' )
def addElectronEfficiencyAlg( sequence, dataType, postfix='',
preselection='',
identification=None,
isolation=None,
triggerWP=None,
triggerEfficiency=False ):
"""Add electron efficiency alg to the sequence
Keyword arguments:
sequence -- Sequence to add to
dataType -- The data type to run on ("data", "mc" or "afii")
postfix -- a postfix to apply to decorations and algorithm
names. this is mostly used/needed when using this
sequence with multiple working points to ensure all
names are unique.
preselection -- preselection to apply
identification -- electron identification working point
isolation -- electron isolation working point
triggerWP -- electron trigger working point
triggerEfficiency -- whether or not to get efficiencies or scale factors
"""
if dataType == 'data':
return
suffix = ''
sysRegex = '(^EL_EFF_Reco.*)'
if identification:
sysRegex = '(^EL_EFF_ID.*)'
suffix = identification
if isolation:
sysRegex = '(^EL_EFF_Iso.*)'
suffix += '_' + isolation
if triggerWP:
suffix += '_' + triggerWP
if triggerEfficiency:
suffix = 'MC_' + suffix
sysRegex = '(^EL_EFF_TriggerEff_.*)'
triggerWP = 'Eff_' + triggerWP
else:
suffix = 'SF_' + suffix
sysRegex = '(^EL_EFF_Trigger_.*)'
elif suffix:
suffix = 'SF_' + suffix
else:
suffix = 'SF'
suffix += postfix
alg = createAlgorithm( 'CP::ElectronEfficiencyCorrectionAlg',
'ElectronEfficiencyCorrectionAlg' + suffix )
alg.preselection = preselection
addPrivateTool( alg, 'efficiencyCorrectionTool',
'AsgElectronEfficiencyCorrectionTool' )
alg.scaleFactorDecoration = 'eff' + suffix + '_%SYS%'
alg.scaleFactorDecorationRegex = sysRegex
alg.efficiencyCorrectionTool.CorrelationModel = 'TOTAL'
if dataType == 'afii':
alg.efficiencyCorrectionTool.ForceDataType = \
PATCore.ParticleDataType.Fast
elif dataType == 'mc':
alg.efficiencyCorrectionTool.ForceDataType = \
PATCore.ParticleDataType.Full
pass
alg.outOfValidity = 2 # silent
alg.outOfValidityDeco = 'bad_eff'
# Set the correct correction
if identification:
alg.efficiencyCorrectionTool.IdKey = identification
if isolation:
alg.efficiencyCorrectionTool.IsoKey = isolation
if triggerWP:
alg.efficiencyCorrectionTool.TriggerKey = triggerWP
if not identification and not isolation and not triggerWP:
alg.efficiencyCorrectionTool.RecoKey = 'Reconstruction'
sequence.append( alg, inputPropName = 'electrons',
affectingSystematics = sysRegex,
stageName = 'efficiency' )
def addElectronChflipEfficiencyAlg(sequence, dataType,
identification,
isolation,
ECIDS_WP=None,
postfix='',
preselection=''):
"""Add electron charge-flip efficiency alg to the sequence
Keyword arguments:
sequence -- Sequence to add to
dataType -- The data type to run on ("data", "mc" or "afii")
postfix -- a postfix to apply to decorations and algorithm
names. this is mostly used/needed when using this
sequence with multiple working points to ensure all
names are unique.
preselection -- preselection to apply
identification -- electron identification working point
isolation -- electron isolation working point
ECIDS_WP -- electron ECIDS working point
"""
suffix = identification + '_' + isolation
if ECIDS_WP:
suffix += '_' + ECIDS_WP
if postfix:
suffix += postfix
sysRegex = '(^EL_CHARGE.*)'
filePath = 'ElectronEfficiencyCorrection/2015_2017/rel21.2/Consolidation_September2018_v1/charge_misID'
fileName = filePath + '/chargeEfficiencySF.'
fileName += identification + 'LLH'
fileName += '_d0z0_v13'
fileName += '_' + isolation
if ECIDS_WP:
fileName += '_' + ECIDS_WP
fileName += '.root'
alg = createAlgorithm( 'CP::ElectronEfficiencyCorrectionAlg',
'ElectronEfficiencyCorrectionAlgChflip' + suffix )
alg.preselection = preselection
addPrivateTool( alg, 'efficiencyCorrectionTool',
'CP::ElectronChargeEfficiencyCorrectionTool' )
alg.scaleFactorDecoration = 'effSF_Chflip_' + suffix + '_%SYS%'
alg.scaleFactorDecorationRegex = sysRegex
alg.efficiencyCorrectionTool.CorrectionFileName = fileName
if dataType == 'afii':
alg.efficiencyCorrectionTool.ForceDataType = \
PATCore.ParticleDataType.Fast
elif dataType == 'mc':
alg.efficiencyCorrectionTool.ForceDataType = \
PATCore.ParticleDataType.Full
pass
alg.outOfValidity = 2 # silent
alg.outOfValidityDeco = 'bad_eff'
sequence.append( alg, inputPropName = 'electrons',
affectingSystematics = sysRegex,
stageName = 'efficiency' )
def addElectronECIDSEfficiencyAlg(sequence, dataType,
identification,
isolation,
ECIDS_WP,
postfix='',
preselection=''):
"""Add electron ECIDS efficiency alg to the sequence
Keyword arguments:
sequence -- Sequence to add to
dataType -- The data type to run on ("data", "mc" or "afii")
postfix -- a postfix to apply to decorations and algorithm
names. this is mostly used/needed when using this
sequence with multiple working points to ensure all
names are unique.
preselection -- preselection to apply
identification -- electron identification working point
isolation -- electron isolation working point
ECIDS_WP -- electron ECIDS working point
"""
suffix = identification + '_' + isolation + '_' + ECIDS_WP
if postfix:
suffix += postfix
sysRegex = '(^EL_CHARGE.*)'
filePath = 'ElectronEfficiencyCorrection/2015_2017/rel21.2/Consolidation_September2018_v2/additional'
fileName = filePath + '/efficiencySF.ChargeID.'
fileName += identification + 'LLH'
fileName += '_d0z0_v13'
fileName += '_' + isolation
fileName += '_' + ECIDS_WP
fileName += '.root'
alg = createAlgorithm( 'CP::ElectronEfficiencyCorrectionAlg',
'ElectronEfficiencyCorrectionAlgECIDS' + suffix )
alg.preselection = preselection
addPrivateTool( alg, 'efficiencyCorrectionTool',
'CP::ElectronChargeEfficiencyCorrectionTool' )
alg.scaleFactorDecoration = 'effSF_ECIDS_' + suffix + '_%SYS%'
alg.scaleFactorDecorationRegex = sysRegex
alg.efficiencyCorrectionTool.CorrectionFileName = fileName
if dataType == 'afii':
alg.efficiencyCorrectionTool.ForceDataType = \
PATCore.ParticleDataType.Fast
elif dataType == 'mc':
alg.efficiencyCorrectionTool.ForceDataType = \
PATCore.ParticleDataType.Full
pass
alg.outOfValidity = 2 # silent
alg.outOfValidityDeco = 'bad_eff'
sequence.append( alg, inputPropName = 'electrons',
affectingSystematics = sysRegex,
stageName = 'efficiency' )
# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
# Framework import(s):
import ROOT
from ROOT import xAOD
# AnaAlgorithm import(s):
from AnaAlgorithm.AnaAlgSequence import AnaAlgSequence
......@@ -38,7 +38,7 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
"""
# Make sure we received a valid data type.
if not dataType in [ 'data', 'mc', 'afii' ]:
if dataType not in [ 'data', 'mc', 'afii' ]:
raise ValueError( 'Invalid data type: %' % dataType )
if postfix != '' :
......@@ -120,7 +120,7 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
alg.preselection = "&&".join (selectionDecorNames)
alg.selectionDecoration = 'goodOQ' + postfix + ',as_bits'
addPrivateTool( alg, 'selectionTool', 'CP::EgammaIsGoodOQSelectionTool' )
alg.selectionTool.Mask = ROOT.xAOD.EgammaParameters.BADCLUSELECTRON
alg.selectionTool.Mask = xAOD.EgammaParameters.BADCLUSELECTRON
seq.append( alg, inputPropName = 'particles',
stageName = 'calibration' )
selectionDecorNames.append( alg.selectionDecoration )
......@@ -244,30 +244,18 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
stageName = 'selection' )
pass
# Set up the electron efficiency correction algorithm:
alg = createAlgorithm( 'CP::ElectronEfficiencyCorrectionAlg',
'ElectronEfficiencyCorrectionAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
addPrivateTool( alg, 'efficiencyCorrectionTool',
'AsgElectronEfficiencyCorrectionTool' )
alg.scaleFactorDecoration = 'effSF' + postfix + '_%SYS%'
alg.scaleFactorDecorationRegex = '(^EL_EFF_Reco.*)'
alg.efficiencyCorrectionTool.RecoKey = "Reconstruction"
alg.efficiencyCorrectionTool.CorrelationModel = "TOTAL"
if dataType == 'afii':
alg.efficiencyCorrectionTool.ForceDataType = \
ROOT.PATCore.ParticleDataType.Fast
elif dataType == 'mc':
alg.efficiencyCorrectionTool.ForceDataType = \
ROOT.PATCore.ParticleDataType.Full
pass
alg.outOfValidity = 2 #silent
alg.outOfValidityDeco = 'bad_eff' + postfix
if dataType != 'data':
seq.append( alg, inputPropName = 'electrons',
affectingSystematics = '(^EL_EFF_Reco.*)',
stageName = 'efficiency' )
pass
from EgammaAnalysisAlgorithms.ElectronAnalysisHelpers import addElectronEfficiencyAlg
# Set up the electron reconstruction efficiency correction algorithm:
addElectronEfficiencyAlg( seq, dataType, postfix, '&&'.join (selectionDecorNames) )
if 'Loose' not in likelihoodWP:
# Set up the electron identification efficiency correction algorithm:
addElectronEfficiencyAlg( seq, dataType, postfix, '&&'.join (selectionDecorNames),
identification=likelihoodWP )
# Set up the electron isolation efficiency correction algorithm:
if isolationWP != 'NonIso':
addElectronEfficiencyAlg( seq, dataType, postfix, '&&'.join (selectionDecorNames),
identification=likelihoodWP,
isolation=isolationWP )
# Set up a final deep copy making algorithm if requested:
if deepCopyOutput:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment