Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
EventCleaningConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 # AnaAlgorithm import(s):
4 from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock
5 from AnalysisAlgorithmsConfig.ConfigAccumulator import DataType
6 
7 
8 class EventCleaningBlock (ConfigBlock):
9  """the ConfigBlock for event cleaning"""
10 
11  def __init__ (self) :
12  super (EventCleaningBlock, self).__init__ ()
13  self.addOption ('runPrimaryVertexSelection', True, type=bool,
14  info="whether to run primary vertex selection. The default is True.")
15  self.addOption ('runEventCleaning', False, type=bool,
16  info="whether to run event cleaning (sets up an instance of "
17  "CP::EventFlagSelectionAlg). The default is False.")
18  self.addOption ('runGRL', True, type=bool,
19  info="whether to run GRL decoration/selection. The default is True.")
20  self.addOption ('userGRLFiles', [], type=None,
21  info="a list of GRL files (list of strings) to select data from. "
22  "The default is [] (empty list).")
23  self.addOption ('minTracksPerVertex', 2, type=int,
24  info="minimum number (integer) of tracks per vertex. The default is 2.")
25  self.addOption ('selectionFlags', ['DFCommonJets_eventClean_LooseBad'], type=None,
26  info="lags (list of strings) to use for jet cleaning. The default is "
27  "['DFCommonJets_eventClean_LooseBad'].")
28  # This is a vector<bool>, so parsing True/False is not handled
29  # in AnalysisBase, but we can evade this with numerical values
30  self.addOption ('invertFlags', [0], type=None,
31  info="list of booleans determining whether to invert the cut of the "
32  "above selectionFlags. The default is [0].")
33  self.addOption ('GRLDict', {}, type=None)
34  self.addOption ('noFilter', False, type=bool,
35  info="do apply event decoration, but do not filter. The default is False, i.e. 'We decorate events but do not filter' ")
36  self.addOption ('useRandomRunNumber', False, type=bool,
37  info="use RandomRunNumber to compute GRL info. Only supported for MC. The default is False")
38 
39  if self.runGRL and self.userGRLFiles:
40  raise ValueError("No userGRLFiles should be specified if runGRL=False")
41 
42  def getDefaultGRLs (self, data_year) :
43  """ returns a reasonable set of GRLs that should be suited for most analyses """
44  from GoodRunsLists.GoodRunsListsDictionary import getGoodRunsLists
45  GRLDict = getGoodRunsLists()
46 
47  if data_year == 2015:
48  return GRLDict['GRL2015']
49  elif data_year == 2016:
50  return GRLDict['GRL2016']
51  elif data_year == 2017:
52  return GRLDict['GRL2017_Triggerno17e33prim']
53  elif data_year == 2018:
54  return GRLDict['GRL2018_Triggerno17e33prim']
55  elif data_year == 2022:
56  return GRLDict['GRL2022']
57  elif data_year == 2023:
58  return GRLDict['GRL2023']
59  else:
60  raise ValueError (f"Data year {data_year} is not recognised for automatic GRL retrieval!")
61 
62  def makeAlgs (self, config) :
63 
64  # Apply GRL
65  if self.runGRL and (config.dataType() is DataType.Data or self.useRandomRunNumber):
66  if config.dataType() is DataType.Data and self.useRandomRunNumber:
67  raise ValueError ("UseRandomRunNumber is only supported for MC!")
68 
69  if self.noFilter:
70  # here we only decorate the PHYSLITE events with a boolean and don't do any cleaning
71  # Set up the GRL Decoration
72  if not self.GRLDict:
73  raise ValueError ("No GRLDict specified for GRL decoration, please specify a GRLDict")
74 
75  for GRLDecoratorName, GRLFileList in self.GRLDict.items():
76  if isinstance(GRLFileList, str):
77  GRLFileList = [GRLFileList]
78 
79  alg = config.createAlgorithm("GRLSelectorAlg", GRLDecoratorName)
80  config.addPrivateTool("Tool", "GoodRunsListSelectionTool")
81  alg.Tool.UseRandomRunNumber = self.useRandomRunNumber
82  alg.Tool.GoodRunsListVec = GRLFileList
83  alg.noFilter = True
84  alg.grlKey = f"EventInfo.{GRLDecoratorName}"
85 
86  config.addOutputVar("EventInfo", GRLDecoratorName, GRLDecoratorName, noSys=True)
87  else:
88  # Set up the GRL selection:
89  alg = config.createAlgorithm( 'GRLSelectorAlg', 'GRLSelectorAlg' )
90  config.addPrivateTool( 'Tool', 'GoodRunsListSelectionTool' )
91  alg.Tool.UseRandomRunNumber = self.useRandomRunNumber
92  if self.userGRLFiles:
93  alg.Tool.GoodRunsListVec = self.userGRLFiles
94  else:
95  alg.Tool.GoodRunsListVec = self.getDefaultGRLs( config.dataYear() )
96 
97  # Skip events with no primary vertex:
98  if self.runPrimaryVertexSelection:
99  alg = config.createAlgorithm( 'CP::VertexSelectionAlg',
100  'PrimaryVertexSelectorAlg',
101  reentrant=True )
102  alg.VertexContainer = 'PrimaryVertices'
103  alg.MinVertices = 1
104  alg.MinTracks = self.minTracksPerVertex
105 
106  # Set up the event cleaning selection:
107  if self.runEventCleaning:
108  if config.dataType() is DataType.Data:
109  alg = config.createAlgorithm( 'CP::EventStatusSelectionAlg', 'EventStatusSelectionAlg' )
110  alg.FilterKey = 'EventErrorState'
111  alg.FilterDescription = 'selecting events without any error state set'
112 
113  alg = config.createAlgorithm( 'CP::EventFlagSelectionAlg', 'EventFlagSelectionAlg' )
114  alg.FilterKey = 'JetCleaning'
115  alg.selectionFlags = [f'{sel},as_char' for sel in self.selectionFlags]
116  alg.invertFlags = self.invertFlags
117  alg.FilterDescription = f"selecting events passing: {','.join(alg.selectionFlags)}"
118 
119 
120 
python.EventCleaningConfig.EventCleaningBlock.__init__
def __init__(self)
Definition: EventCleaningConfig.py:11
python.GoodRunsListsDictionary.getGoodRunsLists
def getGoodRunsLists()
Definition: GoodRunsListsDictionary.py:3
python.EventCleaningConfig.EventCleaningBlock
Definition: EventCleaningConfig.py:8
python.EventCleaningConfig.EventCleaningBlock.makeAlgs
def makeAlgs(self, config)
Definition: EventCleaningConfig.py:62
python.EventCleaningConfig.EventCleaningBlock.getDefaultGRLs
def getDefaultGRLs(self, data_year)
Definition: EventCleaningConfig.py:42
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71