Commit 9ef420f0 authored by Nils Krumnack's avatar Nils Krumnack
Browse files

switch selection accounting to use algorithm meta-configuration

Just to allow easier sequence modification.
parent bc4c7808
......@@ -64,12 +64,12 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
seq = AnaAlgSequence( "ElectronAnalysisSequence" + postfix )
# Variables keeping track of the selections being applied.
selectionDecorNames = []
selectionDecorCount = []
seq.addMetaConfigDefault ("selectionDecorNames", [])
seq.addMetaConfigDefault ("selectionDecorNamesOutput", [])
seq.addMetaConfigDefault ("selectionDecorCount", [])
# Set up the eta-cut on all electrons prior to everything else
alg = createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronEtaCutAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.selectionDecoration = 'selectEta' + postfix + ',as_bits'
addPrivateTool( alg, 'selectionTool', 'CP::AsgPtEtaSelectionTool' )
alg.selectionTool.maxEta = 2.47
......@@ -79,61 +79,61 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
alg.selectionTool.useClusterEta = True
seq.append( alg, inputPropName = 'particles',
outputPropName = 'particlesOut',
stageName = 'calibration' )
selectionDecorNames.append( alg.selectionDecoration )
if crackVeto :
selectionDecorCount.append( 5 )
else :
selectionDecorCount.append( 4 )
stageName = 'calibration',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorNamesOutput' : [alg.selectionDecoration],
'selectionDecorCount' : [5 if crackVeto else 4]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Set up the track selection algorithm:
alg = createAlgorithm( 'CP::AsgLeptonTrackSelectionAlg',
'ElectronTrackSelectionAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.selectionDecoration = 'trackSelection' + postfix + ',as_bits'
alg.maxD0Significance = 5
alg.maxDeltaZ0SinTheta = 0.5
seq.append( alg, inputPropName = 'particles',
stageName = 'selection' )
selectionDecorNames.append( alg.selectionDecoration )
selectionDecorCount.append( 3 )
stageName = 'selection',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorNamesOutput' : [alg.selectionDecoration],
'selectionDecorCount' : [3]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Set up the likelihood ID selection algorithm
# It is safe to do this before calibration, as the cluster E is used
alg = createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.selectionDecoration = 'selectLikelihood' + postfix + ',as_bits'
selectionDecorNames.append( alg.selectionDecoration )
if recomputeLikelihood:
# Rerun the likelihood ID
addPrivateTool( alg, 'selectionTool', 'AsgElectronLikelihoodTool' )
alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
alg.selectionTool.WorkingPoint = likelihoodWP
selectionDecorCount.append( 7 )
else:
# Select from Derivation Framework flags
addPrivateTool( alg, 'selectionTool', 'CP::AsgFlagSelectionTool' )
dfFlag = "DFCommonElectronsLH" + likelihoodWP.split('LH')[0]
alg.selectionTool.selectionFlags = [dfFlag]
selectionDecorCount.append( 1 )
seq.append( alg, inputPropName = 'particles',
stageName = 'selection' )
stageName = 'selection',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorNamesOutput' : [alg.selectionDecoration],
'selectionDecorCount' : [7 if recomputeLikelihood else 1]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Select electrons only with good object quality.
alg = createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronObjectQualityAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.selectionDecoration = 'goodOQ' + postfix + ',as_bits'
addPrivateTool( alg, 'selectionTool', 'CP::EgammaIsGoodOQSelectionTool' )
alg.selectionTool.Mask = ROOT.xAOD.EgammaParameters.BADCLUSELECTRON
seq.append( alg, inputPropName = 'particles',
stageName = 'calibration' )
selectionDecorNames.append( alg.selectionDecoration )
selectionDecorCount.append( 1 )
stageName = 'calibration',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorNamesOutput' : [alg.selectionDecoration],
'selectionDecorCount' : [1]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Set up the calibration and smearing algorithm:
alg = createAlgorithm( 'CP::EgammaCalibrationAndSmearingAlg',
'ElectronCalibrationAndSmearingAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
addPrivateTool( alg, 'calibrationAndSmearingTool',
'CP::EgammaCalibrationAndSmearingTool' )
alg.calibrationAndSmearingTool.ESModel = 'es2018_R21_v0'
......@@ -145,25 +145,25 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
pass
seq.append( alg, inputPropName = 'egammas', outputPropName = 'egammasOut',
affectingSystematics = '(^EG_RESOLUTION_.*)|(^EG_SCALE_.*)',
stageName = 'calibration' )
stageName = 'calibration',
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Set up the the pt selection
ptSelectionDecoration = 'selectPt' + postfix + ',as_bits'
alg = createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronPtCutAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.selectionDecoration = ptSelectionDecoration
alg.selectionDecoration = 'selectPt' + postfix + ',as_bits'
addPrivateTool( alg, 'selectionTool', 'CP::AsgPtEtaSelectionTool' )
alg.selectionTool.minPt = 4.5e3
seq.append( alg, inputPropName = 'particles',
stageName = 'selection' )
selectionDecorNames.append( alg.selectionDecoration )
selectionDecorCount.append( 2 )
stageName = 'selection',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorNamesOutput' : [alg.selectionDecoration] if ptSelectionOutput else [],
'selectionDecorCount' : [2]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Set up the isolation correction algorithm:
if isolationCorrection:
alg = createAlgorithm( 'CP::EgammaIsolationCorrectionAlg',
'ElectronIsolationCorrectionAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
addPrivateTool( alg, 'isolationCorrectionTool',
'CP::IsolationCorrectionTool' )
if dataType == 'data':
......@@ -172,26 +172,27 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
alg.isolationCorrectionTool.IsMC = 1
pass
seq.append( alg, inputPropName = 'egammas', outputPropName = 'egammasOut',
stageName = 'calibration' )
stageName = 'calibration',
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Set up the isolation selection algorithm:
if isolationWP != 'NonIso' :
alg = createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
'ElectronIsolationSelectionAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.selectionDecoration = 'isolated' + postfix + ',as_bits'
addPrivateTool( alg, 'selectionTool', 'CP::IsolationSelectionTool' )
alg.selectionTool.ElectronWP = isolationWP
seq.append( alg, inputPropName = 'egammas',
stageName = 'selection' )
selectionDecorNames.append( alg.selectionDecoration )
selectionDecorCount.append( 1 )
stageName = 'selection',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorNamesOutput' : [alg.selectionDecoration],
'selectionDecorCount' : [1]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Select electrons only if they don't appear to have flipped their charge.
if chargeIDSelection:
alg = createAlgorithm( 'CP::AsgSelectionAlg',
'ElectronChargeIDSelectionAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.selectionDecoration = 'chargeID' + postfix + ',as_bits'
addPrivateTool( alg, 'selectionTool',
'AsgElectronChargeIDSelectorTool' )
......@@ -200,55 +201,50 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
alg.selectionTool.WorkingPoint = 'Loose'
alg.selectionTool.CutOnBDT = -0.337671 # Loose 97%
seq.append( alg, inputPropName = 'particles',
stageName = 'selection' )
selectionDecorNames.append( alg.selectionDecoration )
selectionDecorCount.append( 1 )
stageName = 'selection',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorNamesOutput' : [alg.selectionDecoration],
'selectionDecorCount' : [1]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
pass
# Set up an algorithm used for decorating baseline electron selection:
alg = createAlgorithm( 'CP::AsgSelectionAlg',
'ElectronSelectionSummary' + postfix )
addPrivateTool( alg, 'selectionTool', 'CP::AsgFlagSelectionTool' )
alg.selectionTool.selectionFlags = selectionDecorNames[ : ]
alg.selectionDecoration = 'baselineSelection' + postfix + ',as_char'
seq.append( alg, inputPropName = 'particles',
stageName = 'selection' )
stageName = 'selection',
dynConfig = {'selectionTool.selectionFlags' : lambda meta : meta["selectionDecorNames"] [ : ]} )
# Set up an algorithm used to create electron selection cutflow:
if enableCutflow:
alg = createAlgorithm( 'CP::ObjectCutFlowHistAlg', 'ElectronCutFlowDumperAlg' + postfix )
alg.histPattern = 'electron_cflow_%SYS%' + postfix
alg.selection = selectionDecorNames[ : ]
alg.selectionNCuts = selectionDecorCount[ : ]
seq.append( alg, inputPropName = 'input', stageName = 'selection' )
seq.append( alg, inputPropName = 'input', stageName = 'selection',
dynConfig = {'selection' : lambda meta : meta["selectionDecorNames"][:],
'selectionNCuts' : lambda meta : meta["selectionDecorCount"][:]} )
# Set up an algorithm dumping the kinematic properties of the electrons:
if enableKinematicHistograms:
alg = createAlgorithm( 'CP::KinematicHistAlg', 'ElectronKinematicDumperAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.histPattern = 'electron_%VAR%_%SYS%' + postfix
seq.append( alg, inputPropName = 'input', stageName = 'selection' )
# Set up the output selection
if shallowViewOutput or deepCopyOutput:
selectionDecorNamesOutput = selectionDecorNames[ : ]
if not ptSelectionOutput:
selectionDecorNamesOutput.remove(ptSelectionDecoration)
seq.append( alg, inputPropName = 'input', stageName = 'selection',
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Set up an algorithm that makes a view container using the selections
# performed previously:
if shallowViewOutput:
alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
'ElectronViewFromSelectionAlg' + postfix )
alg.selection = selectionDecorNamesOutput[ : ]
seq.append( alg, inputPropName = 'input', outputPropName = 'output',
stageName = 'selection' )
stageName = 'selection',
dynConfig = {'selection' : lambda meta : meta["selectionDecorNamesOutput"][:]} )
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%'
......@@ -267,17 +263,18 @@ def makeElectronAnalysisSequence( dataType, workingPoint,
if dataType != 'data':
seq.append( alg, inputPropName = 'electrons',
affectingSystematics = '(^EL_EFF_Reco.*)',
stageName = 'efficiency' )
stageName = 'efficiency',
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
pass
# Set up a final deep copy making algorithm if requested:
if deepCopyOutput:
alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
'ElectronDeepCopyMaker' + postfix )
alg.selection = selectionDecorNamesOutput[:]
alg.deepCopy = True
seq.append( alg, inputPropName = 'input', outputPropName = 'output',
stageName = 'selection' )
stageName = 'selection',
dynConfig = {'selection' : lambda meta : meta["selectionDecorNamesOutput"][:]} )
pass
# Return the sequence:
......
......@@ -58,30 +58,30 @@ def makePhotonAnalysisSequence( dataType, workingPoint,
seq = AnaAlgSequence( "PhotonAnalysisSequence" + postfix )
# Variables keeping track of the selections being applied.
selectionDecorNames = []
selectionDecorCount = []
seq.addMetaConfigDefault ("selectionDecorNames", [])
seq.addMetaConfigDefault ("selectionDecorCount", [])
# Set up the photon selection algorithm:
alg = createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonIsEMSelectorAlg' + postfix )
alg.selectionDecoration = 'selectEM'
selectionDecorNames.append( alg.selectionDecoration )
if recomputeIsEM:
# Rerun the cut-based ID
addPrivateTool( alg, 'selectionTool', 'AsgPhotonIsEMSelector' )
alg.selectionTool.isEMMask = quality
alg.selectionTool.ConfigFile = \
'ElectronPhotonSelectorTools/offline/20180116/PhotonIsEMTightSelectorCutDefs.conf'
selectionDecorCount.append( 32 )
else:
# Select from Derivation Framework flags
addPrivateTool( alg, 'selectionTool', 'CP::AsgFlagSelectionTool' )
dfFlag = 'DFCommonPhotonsIsEM' + qualityWP
alg.selectionTool.selectionFlags = [ dfFlag ]
selectionDecorCount.append( 1 )
pass
seq.append( alg, inputPropName = 'particles',
outputPropName = 'particlesOut',
stageName = 'calibration' )
stageName = 'calibration',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorCount' : [32 if recomputeIsEM else 1]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Select electrons only with good object quality.
alg = createAlgorithm( 'CP::AsgSelectionAlg', 'PhotonObjectQualityAlg' + postfix )
......@@ -90,18 +90,19 @@ def makePhotonAnalysisSequence( dataType, workingPoint,
alg.selectionTool.Mask = ROOT.xAOD.EgammaParameters.BADCLUSPHOTON
seq.append( alg, inputPropName = 'particles',
outputPropName = 'particlesOut',
stageName = 'calibration' )
selectionDecorNames.append( alg.selectionDecoration )
selectionDecorCount.append( 1 )
stageName = 'calibration',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorCount' : [1]},
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Only run subsequent processing on the objects passing all of these cuts.
# Since these are independent of the photon calibration, and this speeds
# up the job.
alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
'PhotonPreSelViewFromSelectionAlg' + postfix )
alg.selection = selectionDecorNames[ : ]
seq.append( alg, inputPropName = 'input', outputPropName = 'output',
stageName = 'calibration' )
stageName = 'calibration',
dynConfig = {'selection' : lambda meta : meta["selectionDecorNames"] [:]} )
# Set up the calibration ans smearing algorithm.
alg = createAlgorithm( 'CP::EgammaCalibrationAndSmearingAlg',
......@@ -150,9 +151,9 @@ def makePhotonAnalysisSequence( dataType, workingPoint,
addPrivateTool( alg, 'selectionTool', 'CP::IsolationSelectionTool' )
alg.selectionTool.PhotonWP = isolationWP
seq.append( alg, inputPropName = 'egammas', outputPropName = 'egammasOut',
stageName = 'selection' )
selectionDecorNames.append( alg.selectionDecoration )
selectionDecorCount.append( 1 )
stageName = 'selection',
metaConfig = {'selectionDecorNames' : [alg.selectionDecoration],
'selectionDecorCount' : [1]} )
# Set up the photon efficiency correction algorithm.
alg = createAlgorithm( 'CP::PhotonEfficiencyCorrectionAlg',
......@@ -175,9 +176,9 @@ def makePhotonAnalysisSequence( dataType, workingPoint,
seq.append( alg, inputPropName = 'photons',
outputPropName = 'photonsOut',
affectingSystematics = '(^PH_EFF_.*)',
stageName = 'efficiency' )
selectionDecorNames.append( alg.outOfValidityDeco )
selectionDecorCount.append( 1 )
stageName = 'efficiency',
metaConfig = {'selectionDecorNames' : [alg.outOfValidityDeco],
'selectionDecorCount' : [1]} )
pass
# Set up an algorithm used to create photon selection cutflow:
......@@ -185,26 +186,26 @@ def makePhotonAnalysisSequence( dataType, workingPoint,
alg = createAlgorithm( 'CP::ObjectCutFlowHistAlg',
'PhotonCutFlowDumperAlg' + postfix )
alg.histPattern = 'photon_cflow_%SYS%' + postfix
alg.selection = selectionDecorNames[ : ]
alg.selectionNCuts = selectionDecorCount[ : ]
seq.append( alg, inputPropName = 'input',
stageName = 'selection' )
stageName = 'selection',
dynConfig = {'selection' : lambda meta : meta["selectionDecorNames"][:],
'selectionNCuts' : lambda meta : meta["selectionDecorCount"][:]} )
# Set up an algorithm that makes a view container using the selections
# performed previously:
alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
'PhotonViewFromSelectionAlg' + postfix )
alg.selection = selectionDecorNames[ : ]
seq.append( alg, inputPropName = 'input', outputPropName = 'output',
stageName = 'selection' )
stageName = 'selection',
dynConfig = {'selection' : lambda meta : meta["selectionDecorNames"] [:]} )
# Set up an algorithm dumping the kinematic properties of the photons:
if enableKinematicHistograms:
alg = createAlgorithm( 'CP::KinematicHistAlg', 'PhotonKinematicDumperAlg' + postfix )
alg.preselection = "&&".join (selectionDecorNames)
alg.histPattern = 'photon_%VAR%_%SYS%' + postfix
seq.append( alg, inputPropName = 'input',
stageName = 'selection' )
stageName = 'selection',
dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])} )
# Set up a final deep copy making algorithm if requested:
if deepCopyOutput:
......
Supports Markdown
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