ATLAS Offline Software
EventCleaningConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 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 ('userGRLFiles', [], type=None,
19  info="a list of GRL files (list of strings) to select data from. "
20  "The default is [] (empty list).")
21  self.addOption ('minTracksPerVertex', 2, type=int,
22  info="minimum number (integer) of tracks per vertex. The default is 2.")
23  self.addOption ('selectionFlags', ['DFCommonJets_eventClean_LooseBad'], type=None,
24  info="lags (list of strings) to use for jet cleaning. The default is "
25  "['DFCommonJets_eventClean_LooseBad'].")
26  # This is a vector<bool>, so parsing True/False is not handled
27  # in AnalysisBase, but we can evade this with numerical values
28  self.addOption ('invertFlags', [0], type=None,
29  info="list of booleans determining whether to invert the cut of the "
30  "above selectionFlags. The default is [0].")
31  self.addOption ('GRLDict', {}, type=None)
32  self.addOption ('noFilter', False, type=bool,
33  info="do apply event decoration, but do not filter. The default is False, i.e. 'We decorate events but do not filter' ")
34 
35  def getDefaultGRLs (self, data_year) :
36  """ returns a reasonable set of GRLs that should be suited for most analyses """
37 
38  if data_year == 2015:
39  return ['GoodRunsLists/data15_13TeV/20170619/data15_13TeV.periodAllYear_DetStatus-v89-pro21-02_Unknown_PHYS_StandardGRL_All_Good_25ns.xml']
40  elif data_year == 2016:
41  return ['GoodRunsLists/data16_13TeV/20180129/data16_13TeV.periodAllYear_DetStatus-v89-pro21-01_DQDefects-00-02-04_PHYS_StandardGRL_All_Good_25ns.xml']
42  elif data_year == 2017:
43  return ['GoodRunsLists/data17_13TeV/20180619/data17_13TeV.periodAllYear_DetStatus-v99-pro22-01_Unknown_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.xml']
44  elif data_year == 2018:
45  return ['GoodRunsLists/data18_13TeV/20190318/data18_13TeV.periodAllYear_DetStatus-v102-pro22-04_Unknown_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.xml']
46  elif data_year == 2022:
47  return ['GoodRunsLists/data22_13p6TeV/20230207/data22_13p6TeV.periodAllYear_DetStatus-v109-pro28-04_MERGED_PHYS_StandardGRL_All_Good_25ns.xml']
48  elif data_year == 2023:
49  return ['GoodRunsLists/data23_13p6TeV/20230712/data23_13p6TeV.periodAllYear_DetStatus-v110-pro31-05_MERGED_PHYS_StandardGRL_All_Good_25ns.xml']
50  else:
51  raise ValueError (f"Data year {data_year} is not recognised for automatic GRL retrieval!")
52 
53  def makeAlgs (self, config) :
54 
55  if config.dataType() is DataType.Data:
56  if self.noFilter:
57  """ here we only decorate the PHYSLITE events with a boolean and don't do any cleaning"""
58 
59  # Set up the GRL Decoration
60  for GRLDecoratorName,GRLFile in (self.GRLDict).items():
61  alg = config.createAlgorithm( 'GRLSelectorAlg', GRLDecoratorName )
62  config.addPrivateTool( 'Tool', 'GoodRunsListSelectionTool' )
63  alg.Tool.GoodRunsListVec = GRLFile
64  alg.grlKey = "EventInfo." + GRLDecoratorName
65  # Using WriteDecorHandle thus no need for addOutputVar
66  else:
67  # Set up the GRL selection:
68  alg = config.createAlgorithm( 'GRLSelectorAlg', 'GRLSelectorAlg' )
69  config.addPrivateTool( 'Tool', 'GoodRunsListSelectionTool' )
70  if self.userGRLFiles:
71  alg.Tool.GoodRunsListVec = self.userGRLFiles
72  else:
73  alg.Tool.GoodRunsListVec = self.getDefaultGRLs( config.dataYear() )
74 
75  # Skip events with no primary vertex:
76  if self.runPrimaryVertexSelection:
77  alg = config.createAlgorithm( 'CP::VertexSelectionAlg',
78  'PrimaryVertexSelectorAlg' )
79  alg.VertexContainer = 'PrimaryVertices'
80  alg.MinVertices = 1
81  alg.MinTracks = self.minTracksPerVertex
82 
83  # Set up the event cleaning selection:
84  if self.runEventCleaning:
85  if config.dataType() is DataType.Data:
86  alg = config.createAlgorithm( 'CP::EventStatusSelectionAlg', 'EventStatusSelectionAlg' )
87  alg.FilterKey = 'EventErrorState'
88  alg.FilterDescription = 'selecting events without any error state set'
89 
90  alg = config.createAlgorithm( 'CP::EventFlagSelectionAlg', 'EventFlagSelectionAlg' )
91  alg.FilterKey = 'JetCleaning'
92  alg.selectionFlags = [f'{sel},as_char' for sel in self.selectionFlags]
93  alg.invertFlags = self.invertFlags
94  alg.FilterDescription = f"selecting events passing: {','.join(alg.selectionFlags)}"
95 
96 
97 
98 
100  runPrimaryVertexSelection = None,
101  runEventCleaning = None,
102  userGRLFiles = None,
103  GRLDict = None,
104  noFilter = None,
105  ):
106  """Create a basic event cleaning analysis algorithm sequence
107 
108  Keyword arguments:
109  runPrimaryVertexSelection -- whether to run primary vertex selection
110  runEventCleaning -- wether to run event cleaning
111  userGRLFiles -- a list of GRL files to select data from
112  GRLDict -- a dictionary of GRL files to determine decoration names
113  noFilter -- wether to apply event decoration or not
114  """
115 
116  config = EventCleaningBlock ()
117  config.setOptionValue ('runPrimaryVertexSelection', runPrimaryVertexSelection)
118  config.setOptionValue ('runEventCleaning', runEventCleaning)
119  config.setOptionValue ('userGRLFiles', userGRLFiles)
120  config.setOptionValue ('GRLDict', GRLDict)
121  config.setOptionValue ('noFilter', noFilter)
122  seq.append (config)
python.EventCleaningConfig.EventCleaningBlock.__init__
def __init__(self)
Definition: EventCleaningConfig.py:11
python.EventCleaningConfig.EventCleaningBlock
Definition: EventCleaningConfig.py:8
python.EventCleaningConfig.makeEventCleaningConfig
def makeEventCleaningConfig(seq, runPrimaryVertexSelection=None, runEventCleaning=None, userGRLFiles=None, GRLDict=None, noFilter=None)
Definition: EventCleaningConfig.py:99
python.EventCleaningConfig.EventCleaningBlock.makeAlgs
def makeAlgs(self, config)
Definition: EventCleaningConfig.py:53
python.EventCleaningConfig.EventCleaningBlock.getDefaultGRLs
def getDefaultGRLs(self, data_year)
Definition: EventCleaningConfig.py:35
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79