215 recomputeLikelihood = False,
216 chargeIDSelection = False,
217 forceFullSimConfig = False ):
218 """Create electron analysis algorithms for a single working point
221 dataType -- The data type to run on ("data", "mc" or "afii")
222 workingPoint -- The working point to use
223 postfix -- a postfix to apply to decorations and algorithm
224 names. this is mostly used/needed when using this
225 sequence with multiple working points to ensure all
227 recomputeLikelihood -- Whether to rerun the LH. If not, use derivation flags
228 chargeIDSelection -- Whether or not to perform charge ID/flip selection
232 if dataType
not in [
'data',
'mc',
'afii' ]:
233 raise ValueError(
'Invalid data type: %s' % dataType )
235 if forceFullSimConfig:
236 print(
"WARNING! You are running makeElectronWorkingPointSequence forcing full sim config")
237 print(
"WARNING! This is only intended to be used for testing purposes")
239 splitWP = workingPoint.split (
'.')
240 if len (splitWP) != 2 :
241 raise ValueError (
'working point should be of format "likelihood.isolation", not ' + workingPoint)
243 likelihoodWP = splitWP[0]
244 isolationWP = splitWP[1]
246 if 'LH' in likelihoodWP:
249 alg =
createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronLikelihoodAlg' + postfix )
250 alg.selectionDecoration =
'selectLikelihood' + postfix +
',as_bits'
251 if 'SiHits' in likelihoodWP:
253 addPrivateTool( alg,
'selectionTool',
'CP::AsgMaskSelectionTool' )
254 dfVar =
"DFCommonElectronsLHLooseBLIsEMValue"
255 alg.selectionTool.selectionVars = [dfVar]
256 mask =
int( 0 | 0x1 << 1 | 0x1 << 2)
257 alg.selectionTool.selectionMasks = [mask]
260 if recomputeLikelihood:
262 addPrivateTool( alg,
'selectionTool',
'AsgElectronLikelihoodTool' )
263 alg.selectionTool.primaryVertexContainer =
'PrimaryVertices'
264 alg.selectionTool.WorkingPoint = likelihoodWP
268 addPrivateTool( alg,
'selectionTool',
'CP::AsgFlagSelectionTool' )
269 dfFlag =
"DFCommonElectronsLH" + likelihoodWP.split(
'LH')[0]
270 dfFlag = dfFlag.replace(
"BLayer",
"BL")
271 alg.selectionTool.selectionFlags = [dfFlag]
275 alg =
createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronDNNAlg' + postfix )
276 alg.selectionDecoration =
'selectDNN' + postfix +
',as_bits'
277 if recomputeLikelihood:
280 alg.selectionTool.WorkingPoint = likelihoodWP
284 raise ValueError (
"DNN working points are not available in derivations yet.")
285 seq.append( alg, inputPropName =
'particles',
286 stageName =
'selection',
287 metaConfig = {
'selectionDecorNames' : [alg.selectionDecoration],
288 'selectionDecorNamesOutput' : [alg.selectionDecoration],
289 'selectionDecorCount' : [algDecorCount]},
290 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])} )
293 if isolationWP !=
'NonIso' :
295 'ElectronIsolationSelectionAlg' + postfix )
296 alg.selectionDecoration =
'isolated' + postfix +
',as_bits'
297 addPrivateTool( alg,
'selectionTool',
'CP::IsolationSelectionTool' )
298 alg.selectionTool.ElectronWP = isolationWP
299 seq.append( alg, inputPropName =
'egammas',
300 stageName =
'selection',
301 metaConfig = {
'selectionDecorNames' : [alg.selectionDecoration],
302 'selectionDecorNamesOutput' : [alg.selectionDecoration],
303 'selectionDecorCount' : [1]},
304 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])} )
307 if chargeIDSelection:
309 'ElectronChargeIDSelectionAlg' + postfix )
310 alg.selectionDecoration =
'chargeID' + postfix +
',as_bits'
312 'AsgElectronChargeIDSelectorTool' )
313 alg.selectionTool.TrainingFile = \
314 'ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root'
315 alg.selectionTool.WorkingPoint =
'Loose'
316 alg.selectionTool.CutOnBDT = -0.337671
317 seq.append( alg, inputPropName =
'particles',
318 stageName =
'selection',
319 metaConfig = {
'selectionDecorNames' : [alg.selectionDecoration],
320 'selectionDecorNamesOutput' : [alg.selectionDecoration],
321 'selectionDecorCount' : [1]},
322 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])} )
327 'ElectronEfficiencyCorrectionAlg' + postfix )
329 'AsgElectronEfficiencyCorrectionTool' )
330 alg.scaleFactorDecoration =
'effSF' + postfix +
'_%SYS%'
331 alg.efficiencyCorrectionTool.RecoKey =
"Reconstruction"
332 alg.efficiencyCorrectionTool.CorrelationModel =
"TOTAL"
333 if dataType ==
'afii':
334 alg.efficiencyCorrectionTool.ForceDataType = (
335 PATCore.ParticleDataType.Full
if forceFullSimConfig
336 else PATCore.ParticleDataType.Fast)
337 elif dataType ==
'mc':
338 alg.efficiencyCorrectionTool.ForceDataType = \
339 PATCore.ParticleDataType.Full
341 alg.outOfValidity = 2
342 alg.outOfValidityDeco =
'bad_eff' + postfix
343 if dataType !=
'data':
344 seq.append( alg, inputPropName =
'electrons',
345 stageName =
'efficiency',
346 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNamesOutput"])} )
351 'ElectronSelectionSummary' + postfix )
352 alg.selectionDecoration =
'baselineSelection' + postfix +
',as_char'
353 seq.append( alg, inputPropName =
'particles',
354 stageName =
'selection',
355 dynConfig = {
'preselection' :
lambda meta :
"&&".join (meta[
"selectionDecorNames"])} )