ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.OutputAnalysisConfig.OutputAnalysisConfig Class Reference
Inheritance diagram for python.OutputAnalysisConfig.OutputAnalysisConfig:
Collaboration diagram for python.OutputAnalysisConfig.OutputAnalysisConfig:

Public Member Functions

def __init__ (self)
 
def makeAlgs (self, config)
 
def createSelectionFlagBranches (self, config)
 
def makeSelectionSummaryAlg (self, config, containerName, selectionName)
 

Public Attributes

 vars
 
 varsOnlyForMC
 

Detailed Description

the ConfigBlock for the MET configuration

Definition at line 10 of file OutputAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.OutputAnalysisConfig.OutputAnalysisConfig.__init__ (   self)

Definition at line 13 of file OutputAnalysisConfig.py.

13  def __init__ (self) :
14  super (OutputAnalysisConfig, self).__init__ ()
15  self.addOption ('postfix', '', type=str,
16  info="a postfix to apply to decorations and algorithm names. "
17  "Typically not needed here.")
18  self.addOption ('vars', [], type=None,
19  info="a list of mappings (list of strings) between containers and "
20  "decorations to output branches. The default is [] (empty list).")
21  self.addOption ('varsOnlyForMC', [], type=None,
22  info="same as vars, but for MC-only variables so as to avoid a "
23  "crash when running on data. The default is [] (empty list).")
24  self.addOption ('metVars', [], type=None,
25  info="a list of mappings (list of strings) between containers "
26  "and decorations to output branches. Specficially for MET "
27  "variables, where only the final MET term is retained. "
28  "The default is [] (empty list).")
29  self.addOption ('containers', {}, type=None,
30  info="a dictionary mapping prefixes (key) to container names "
31  "(values) to be used when saving to the output tree. Branches "
32  "are then of the form prefix_decoration.")
33  self.addOption ('containersOnlyForMC', {}, type=None,
34  info="same as containers, but for MC-only containers so as to avoid "
35  "a crash when running on data.")
36  self.addOption ('containersOnlyForDSIDs', {}, type=None,
37  info="specify which DSIDs are allowed to produce a given container. "
38  "This works like 'onlyForDSIDs': pass a list of DSIDs or regexps.")
39  self.addOption ('treeName', 'analysis', type=str,
40  info="name of the output TTree to save. The default is analysis.")
41  self.addOption ('streamName', 'ANALYSIS', type=str,
42  info="name of the output stream to save the tree in. "
43  "The default is ANALYSIS.")
44  self.addOption ('metTermName', 'Final', type=str,
45  info="the name (string) of the MET term to save, turning the MET "
46  "container into a single object. The default is 'Final'.")
47  # TODO: add info strng
48  self.addOption ('storeSelectionFlags', True, type=bool,
49  info="")
50  # TODO: add info strng
51  self.addOption ('selectionFlagPrefix', 'select', type=str,
52  info="")
53  self.addOption ('commands', [], type=None,
54  info="a list of strings containing commands (regexp strings "
55  "prefaced by the keywords enable or disable) to turn on/off the "
56  "writing of branches to the output ntuple. The default is None "
57  "(no modification to the scheduled output branches).")
58  self.addOption ('alwaysAddNosys', False, type=bool,
59  info="If set to True, all branches will be given a systematics suffix, "
60  "even if they have no systematics (beyond the nominal).")
61 
62 

Member Function Documentation

◆ createSelectionFlagBranches()

def python.OutputAnalysisConfig.OutputAnalysisConfig.createSelectionFlagBranches (   self,
  config 
)
For each container and for each selection, create a single pass variable in output NTuple,
which aggregates all the selections flag of the given selection. For example, this can include
pT, eta selections, some object ID selection, overlap removal, etc.
The goal is to have only one flag per object and working point in the output NTuple.

Definition at line 195 of file OutputAnalysisConfig.py.

195  def createSelectionFlagBranches(self, config):
196  """
197  For each container and for each selection, create a single pass variable in output NTuple,
198  which aggregates all the selections flag of the given selection. For example, this can include
199  pT, eta selections, some object ID selection, overlap removal, etc.
200  The goal is to have only one flag per object and working point in the output NTuple.
201  """
202  originalContainersSeen = []
203  for prefix in self.containers.keys() :
204  outputContainerName = self.containers[prefix]
205  containerName = config.getOutputContainerOrigin(outputContainerName)
206  if containerName in originalContainersSeen:
207  continue
208  else:
209  originalContainersSeen.append(containerName)
210 
211  # EventInfo is one obvious example of a container that has no object selections
212  if containerName == 'EventInfo':
213  continue
214 
215  selectionNames = config.getSelectionNames(containerName, excludeFrom={'or'})
216  for selectionName in selectionNames:
217  # skip default selection
218  if selectionName == '':
219  continue
220  self.makeSelectionSummaryAlg(config, containerName, selectionName)
221 

◆ makeAlgs()

def python.OutputAnalysisConfig.OutputAnalysisConfig.makeAlgs (   self,
  config 
)

Definition at line 63 of file OutputAnalysisConfig.py.

63  def makeAlgs (self, config) :
64 
65  log = logging.getLogger('OutputAnalysisConfig')
66 
67  self.vars = set(self.vars)
68  self.varsOnlyForMC = set(self.varsOnlyForMC)
69  # merge the MC-specific branches and containers into the main list/dictionary only if we are not running on data
70  if config.dataType() is not DataType.Data:
71  self.vars |= self.varsOnlyForMC
72 
73  # protect 'containers' against being overwritten
74  # find overlapping keys
75  overlapping_keys = set(self.containers.keys()).intersection(self.containersOnlyForMC.keys())
76  if overlapping_keys:
77  # convert the set of overlapping keys to a list of strings for the message (represents the empty string too!)
78  keys_message = [repr(key) for key in overlapping_keys]
79  raise KeyError(f"containersOnlyForMC would overwrite the following container keys: {', '.join(keys_message)}")
80 
81  # move items in self.containersOnlyForMC to self.containers
82  self.containers.update(self.containersOnlyForMC)
83  # clear the dictionary to avoid overlapping key error during the second pass
84  self.containersOnlyForMC.clear()
85 
86  # now filter the containers depending on DSIDs
87  for container,dsid_filters in self.containersOnlyForDSIDs.items():
88  if container not in self.containers:
89  log.warning(f"Skipping unrecognised container {container} for DSID-filtering in OutputAnalysisConfig...")
90  continue
91  if not filter_dsids (dsid_filters, config):
92  # if current DSID is not allowed for this container, remove it
93  self.containers.pop (container)
94 
95  if self.storeSelectionFlags:
96  self.createSelectionFlagBranches(config)
97 
98  outputConfigs = {}
99  for prefix in self.containers.keys() :
100  containerName = self.containers[prefix]
101  outputDict = config.getOutputVars (containerName)
102  for outputName in outputDict :
103  outputConfig = copy.deepcopy (outputDict[outputName])
104  if containerName == 'EventInfo' :
105  outputConfig.outputContainerName = outputConfig.origContainerName
106  elif outputConfig.outputContainerName != outputConfig.origContainerName :
107  outputConfig.outputContainerName = containerName + '_%SYS%'
108  else :
109  outputConfig.outputContainerName = config.readName (containerName)
110  outputConfigs[prefix + outputName] = outputConfig
111 
112  for command in self.commands :
113  words = command.split (' ')
114  if len (words) == 0 :
115  raise ValueError ('received empty command for "commands" option')
116  if words[0] == 'enable' :
117  if len (words) != 2 :
118  raise ValueError ('enable takes exactly one argument: ' + command)
119  used = False
120  for name in outputConfigs :
121  if re.match (words[1], name) :
122  outputConfigs[name].enabled = True
123  used = True
124  if not used and config.dataType() is not DataType.Data:
125  raise KeyError ('unknown branch pattern for enable: ' + words[1])
126  elif words[0] == 'disable' :
127  if len (words) != 2 :
128  raise ValueError ('disable takes exactly one argument: ' + command)
129  used = False
130  for name in outputConfigs :
131  if re.match (words[1], name) :
132  outputConfigs[name].enabled = False
133  used = True
134  if not used and config.dataType() is not DataType.Data:
135  raise KeyError ('unknown branch pattern for disable: ' + words[1])
136  else :
137  raise KeyError ('unknown command for "commands" option: ' + words[0])
138 
139  autoVars = []
140  autoMetVars = []
141  for outputName in outputConfigs :
142  outputConfig = outputConfigs[outputName]
143  if outputConfig.enabled :
144  if config.isMetContainer (outputConfig.origContainerName) :
145  myVars = autoMetVars
146  else :
147  myVars = autoVars
148  if outputConfig.noSys :
149  outputConfig.outputContainerName = outputConfig.outputContainerName.replace ('%SYS%', 'NOSYS')
150  outputConfig.variableName = outputConfig.variableName.replace ('%SYS%', 'NOSYS')
151  if self.alwaysAddNosys :
152  outputName += "_NOSYS"
153  else :
154  outputName += '_%SYS%'
155  myVars += [outputConfig.outputContainerName + '.' + outputConfig.variableName + ' -> ' + outputName]
156 
157  postfix = self.postfix
158 
159  # Add an ntuple dumper algorithm:
160  treeMaker = config.createAlgorithm( 'CP::TreeMakerAlg', 'TreeMaker' + postfix )
161  treeMaker.TreeName = self.treeName
162  treeMaker.RootStreamName = self.streamName
163  # the auto-flush setting still needs to be figured out
164  #treeMaker.TreeAutoFlush = 0
165 
166  if len (self.vars) + len (autoVars) :
167  ntupleMaker = config.createAlgorithm( 'CP::AsgxAODNTupleMakerAlg', 'NTupleMaker' + postfix )
168  ntupleMaker.TreeName = self.treeName
169  ntupleMaker.RootStreamName = self.streamName
170  branchList = list(self.vars | set(autoVars))
171  branchList.sort()
172  branchList_nosys = [branch for branch in branchList if "%SYS%" not in branch]
173  branchList_sys = [branch for branch in branchList if "%SYS%" in branch]
174  ntupleMaker.Branches = branchList_nosys + branchList_sys
175  # ntupleMaker.OutputLevel = 2 # For output validation
176 
177  if len (self.metVars) + len (autoMetVars) > 0:
178  ntupleMaker = config.createAlgorithm( 'CP::AsgxAODMetNTupleMakerAlg', 'MetNTupleMaker' + postfix )
179  ntupleMaker.TreeName = self.treeName
180  ntupleMaker.RootStreamName = self.streamName
181  branchList = self.metVars + autoMetVars
182  branchList.sort()
183  branchList_nosys = [branch for branch in branchList if "%SYS%" not in branch]
184  branchList_sys = [branch for branch in branchList if "%SYS%" in branch]
185  ntupleMaker.Branches = branchList_nosys + branchList_sys
186  ntupleMaker.termName = self.metTermName
187  #ntupleMaker.OutputLevel = 2 # For output validation
188 
189  treeFiller = config.createAlgorithm( 'CP::TreeFillerAlg', 'TreeFiller' + postfix )
190  treeFiller.TreeName = self.treeName
191  treeFiller.RootStreamName = self.streamName
192 
193 
194 

◆ makeSelectionSummaryAlg()

def python.OutputAnalysisConfig.OutputAnalysisConfig.makeSelectionSummaryAlg (   self,
  config,
  containerName,
  selectionName 
)
Schedule an algorithm to pick up all cut flags for a given selectionName.
The summary selection flag is written to output as selectionFlagPrefix_selectionName.

Definition at line 222 of file OutputAnalysisConfig.py.

222  def makeSelectionSummaryAlg(self, config, containerName, selectionName):
223  """
224  Schedule an algorithm to pick up all cut flags for a given selectionName.
225  The summary selection flag is written to output as selectionFlagPrefix_selectionName.
226  """
227  alg = config.createAlgorithm( 'CP::AsgSelectionAlg',
228  f'ObjectSelectionSummary_{containerName}_{selectionName}')
229  selectionDecoration = f'baselineSelection_{selectionName}_%SYS%'
230  alg.selectionDecoration = f'{selectionDecoration},as_char'
231  alg.particles = config.readName (containerName)
232  alg.preselection = config.getFullSelection (containerName, selectionName)
233  config.addOutputVar (containerName, selectionDecoration, self.selectionFlagPrefix + '_' + selectionName)

Member Data Documentation

◆ vars

python.OutputAnalysisConfig.OutputAnalysisConfig.vars

Definition at line 67 of file OutputAnalysisConfig.py.

◆ varsOnlyForMC

python.OutputAnalysisConfig.OutputAnalysisConfig.varsOnlyForMC

Definition at line 68 of file OutputAnalysisConfig.py.


The documentation for this class was generated from the following file:
intersection
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:25
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
WriteBchToCool.update
update
Definition: WriteBchToCool.py:67