ATLAS Offline Software
Public Member Functions | Static 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 createOutputAlgs (self, config, name, vars, isMet=False)
 
def makeAlgs (self, config)
 
def createSelectionFlagBranches (self, config)
 
def makeSelectionSummaryAlg (self, config, containerName, selectionName)
 

Static Public Member Functions

def branchSortOrder (rule)
 

Public Attributes

 vars
 
 varsOnlyForMC
 
 metVars
 
 truthMetVars
 

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 ('truthMetVars', [], type=None,
30  info="a list of mappings (list of strings) between containers "
31  "and decorations to output branches for truth MET. "
32  "The default is [] (empty list).")
33  self.addOption ('containers', {}, type=None,
34  info="a dictionary mapping prefixes (key) to container names "
35  "(values) to be used when saving to the output tree. Branches "
36  "are then of the form prefix_decoration.")
37  self.addOption ('containersOnlyForMC', {}, type=None,
38  info="same as containers, but for MC-only containers so as to avoid "
39  "a crash when running on data.")
40  self.addOption ('containersOnlyForDSIDs', {}, type=None,
41  info="specify which DSIDs are allowed to produce a given container. "
42  "This works like 'onlyForDSIDs': pass a list of DSIDs or regexps.")
43  self.addOption ('treeName', 'analysis', type=str,
44  info="name of the output TTree to save. The default is analysis.")
45  self.addOption ('streamName', 'ANALYSIS', type=str,
46  info="name of the output stream to save the tree in. "
47  "The default is ANALYSIS.")
48  self.addOption ('metTermName', 'Final', type=str,
49  info="the name (string) of the MET term to save, turning the MET "
50  "container into a single object. The default is 'Final'.")
51  self.addOption ('truthMetTermName', 'NonInt', type=str,
52  info="the name (string) of the truth MET term to save, turning the MET "
53  "container into a single object. The default is 'NonInt'.")
54  # TODO: add info strng
55  self.addOption ('storeSelectionFlags', True, type=bool,
56  info="")
57  # TODO: add info strng
58  self.addOption ('selectionFlagPrefix', 'select', type=str,
59  info="")
60  self.addOption ('commands', [], type=None,
61  info="a list of strings containing commands (regexp strings "
62  "prefaced by the keywords enable or disable) to turn on/off the "
63  "writing of branches to the output ntuple. The default is None "
64  "(no modification to the scheduled output branches).")
65  self.addOption ('alwaysAddNosys', False, type=bool,
66  info="If set to True, all branches will be given a systematics suffix, "
67  "even if they have no systematics (beyond the nominal).")
68 

Member Function Documentation

◆ branchSortOrder()

def python.OutputAnalysisConfig.OutputAnalysisConfig.branchSortOrder (   rule)
static

Definition at line 70 of file OutputAnalysisConfig.py.

70  def branchSortOrder (rule):
71  return rule.split('->')[1].strip()
72 

◆ createOutputAlgs()

def python.OutputAnalysisConfig.OutputAnalysisConfig.createOutputAlgs (   self,
  config,
  name,
  vars,
  isMet = False 
)
A helper function to create output algorithm

Definition at line 73 of file OutputAnalysisConfig.py.

73  def createOutputAlgs (self, config, name, vars, isMet=False):
74  """A helper function to create output algorithm"""
75  alg = config.createAlgorithm('CP::AsgxAODMetNTupleMakerAlg' if isMet else 'CP::AsgxAODNTupleMakerAlg', name)
76  alg.TreeName = self.treeName
77  alg.RootStreamName = self.streamName
78  branchList = list(vars)
79  branchList.sort(key=self.branchSortOrder)
80  branchList_nosys = [branch for branch in branchList if "%SYS%" not in branch]
81  branchList_sys = [branch for branch in branchList if "%SYS%" in branch]
82  alg.Branches = branchList_nosys + branchList_sys
83  return alg
84 

◆ 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 215 of file OutputAnalysisConfig.py.

215  def createSelectionFlagBranches(self, config):
216  """
217  For each container and for each selection, create a single pass variable in output NTuple,
218  which aggregates all the selections flag of the given selection. For example, this can include
219  pT, eta selections, some object ID selection, overlap removal, etc.
220  The goal is to have only one flag per object and working point in the output NTuple.
221  """
222  originalContainersSeen = []
223  for prefix in self.containers.keys() :
224  outputContainerName = self.containers[prefix]
225  containerName = config.getOutputContainerOrigin(outputContainerName)
226  if containerName in originalContainersSeen:
227  continue
228  else:
229  originalContainersSeen.append(containerName)
230 
231  # EventInfo is one obvious example of a container that has no object selections
232  if containerName == 'EventInfo':
233  continue
234 
235  selectionNames = config.getSelectionNames(containerName)
236  for selectionName in selectionNames:
237  # skip default selection
238  if selectionName == '':
239  continue
240  self.makeSelectionSummaryAlg(config, containerName, selectionName)
241 

◆ makeAlgs()

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

Definition at line 85 of file OutputAnalysisConfig.py.

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

◆ 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 242 of file OutputAnalysisConfig.py.

242  def makeSelectionSummaryAlg(self, config, containerName, selectionName):
243  """
244  Schedule an algorithm to pick up all cut flags for a given selectionName.
245  The summary selection flag is written to output as selectionFlagPrefix_selectionName.
246  """
247  alg = config.createAlgorithm( 'CP::AsgSelectionAlg',
248  f'ObjectSelectionSummary_{containerName}_{selectionName}')
249  selectionDecoration = f'baselineSelection_{selectionName}_%SYS%'
250  alg.selectionDecoration = f'{selectionDecoration},as_char'
251  alg.particles = config.readName (containerName)
252  alg.preselection = config.getFullSelection (containerName, selectionName)
253  config.addOutputVar (containerName, selectionDecoration, self.selectionFlagPrefix + '_' + selectionName)

Member Data Documentation

◆ metVars

python.OutputAnalysisConfig.OutputAnalysisConfig.metVars

Definition at line 91 of file OutputAnalysisConfig.py.

◆ truthMetVars

python.OutputAnalysisConfig.OutputAnalysisConfig.truthMetVars

Definition at line 92 of file OutputAnalysisConfig.py.

◆ vars

python.OutputAnalysisConfig.OutputAnalysisConfig.vars

Definition at line 89 of file OutputAnalysisConfig.py.

◆ varsOnlyForMC

python.OutputAnalysisConfig.OutputAnalysisConfig.varsOnlyForMC

Definition at line 90 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