ATLAS Offline Software
AnalysisObjectSharedSequence.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2 
3 # AnaAlgorithm import(s):
4 from AnaAlgorithm.DualUseConfig import createAlgorithm
5 
7  deepCopyOutput = False,
8  shallowViewOutput = True,
9  postfix = '',
10  enableCutflow = False,
11  enableKinematicHistograms = False,
12  defineSystObjectLinks = False ):
13  """Create an analysis algorithm sequence for shared post-processing of
14  all object types
15 
16  This contains various algorithms for producing view containers (or
17  deep copied containers), as well as debugging output. Typically
18  there has to be one such sequence for each object type and working
19  point. Due to the highly regular format, as well as the number of
20  customizations (and all algorithms being switchable) it may be
21  more practical for the users to write their own version of this
22  for their use case.
23 
24  Keyword arguments:
25  deepCopyOutput -- If set to 'True', the output containers will be
26  standalone, deep copies (slower, but needed for xAOD
27  output writing)
28  shallowViewOutput -- Create a view container if required
29  postfix -- a postfix to apply to decorations and algorithm
30  names. this is required to make multiple such
31  sequences for various object types and working points.
32  enableCutflow -- Whether or not to dump the cutflow
33  enableKinematicHistograms -- Whether or not to dump the kinematic histograms
34 
35  """
36 
37  # Make sure selection options make sense
38  if deepCopyOutput and shallowViewOutput:
39  raise ValueError ("deepCopyOutput and shallowViewOutput can't both be true!")
40 
41  # Build links between nominal and systematic objects
42  # This is useful downstream for constructing the union of all selected objects
43  if defineSystObjectLinks:
44  if deepCopyOutput:
45  raise ValueError ("Systematic object links may not work correctly on deep copy output")
46  alg = createAlgorithm('CP::SystObjectLinkerAlg', 'SystObjLinker'+postfix)
47  seq.append( alg, inputPropName = 'input', stageName = 'selection' )
48 
49  # Set up an algorithm used to create selection cutflow:
50  if enableCutflow:
51  alg = createAlgorithm( 'CP::ObjectCutFlowHistAlg', 'CutFlowDumperAlg' + postfix )
52  alg.histPattern = 'cflow' + postfix + '_%SYS%'
53  seq.append( alg, inputPropName = 'input', stageName = 'selection',
54  dynConfig = {'selections' : lambda meta : meta["selectionDecorNames"][:]} )
55 
56  # Set up an algorithm that makes a view container using the selections
57  # performed previously:
58  if shallowViewOutput:
59  alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
60  'ViewFromSelectionAlg' + postfix )
61  seq.append( alg, inputPropName = 'input', outputPropName = 'output',
62  stageName = 'selection',
63  dynConfig = {'selection' : lambda meta : meta["selectionDecorNamesOutput"][:]} )
64 
65  # Set up an algorithm dumping the kinematic properties of the objects:
66  if enableKinematicHistograms:
67  alg = createAlgorithm( 'CP::KinematicHistAlg', 'KinematicDumperAlg' + postfix )
68  alg.histPattern = '%VAR%' + postfix + '_%SYS%'
69  seq.append( alg, inputPropName = 'input', stageName = 'selection',
70  dynConfig = {'preselection' : lambda meta : "&&".join (meta["selectionDecorNames"])})
71 
72  # Set up a final deep copy making algorithm if requested:
73  if deepCopyOutput:
74  alg = createAlgorithm( 'CP::AsgViewFromSelectionAlg',
75  'DeepCopyMaker' + postfix )
76  alg.deepCopy = True
77  seq.append( alg, inputPropName = 'input', outputPropName = 'output',
78  stageName = 'selection',
79  dynConfig = {'selection' : lambda meta : meta["selectionDecorNamesOutput"][:]} )
80  pass
81 
82  pass
python.DualUseConfig.createAlgorithm
def createAlgorithm(typeName, instanceName)
Definition: DualUseConfig.py:56
python.AnalysisObjectSharedSequence.makeSharedObjectSequence
def makeSharedObjectSequence(seq, deepCopyOutput=False, shallowViewOutput=True, postfix='', enableCutflow=False, enableKinematicHistograms=False, defineSystObjectLinks=False)
Definition: AnalysisObjectSharedSequence.py:6