ATLAS Offline Software
Loading...
Searching...
No Matches
python.AsgAnalysisConfig.CommonServicesConfig Class Reference
Inheritance diagram for python.AsgAnalysisConfig.CommonServicesConfig:
Collaboration diagram for python.AsgAnalysisConfig.CommonServicesConfig:

Public Member Functions

 __init__ (self)
 instanceName (self)
 makeAlgs (self, config)

Public Attributes

 runSystematics = not config.noSystematics()
list onlySystematicsCategories = ['JER']
 separateWeightSystematics
 metadataHistogram
 enableExpertMode
 setupONNX

Detailed Description

the ConfigBlock for common services

The idea here is that all algorithms need some common services, and I should
provide configuration blocks for those.  For now there is just a single
block, but in the future I might break out e.g. the systematics service.

Definition at line 36 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.CommonServicesConfig.__init__ ( self)

Definition at line 44 of file AsgAnalysisConfig.py.

44 def __init__ (self) :
45 super().__init__ ()
46 self.addOption ('runSystematics', None, type=bool,
47 info="whether to turn on the computation of systematic variations. "
48 "The default is to run them on MC.")
49 self.addOption ('filterSystematics', None, type=str,
50 info="a regexp string against which the systematics names will be "
51 "matched. Only positive matches are retained and used in the evaluation "
52 "of the various algorithms.")
53 self.addOption ('onlySystematicsCategories', None, type=list,
54 info="a list of strings defining categories of systematics to enable "
55 "(only recommended for studies / partial ntuple productions). Choose amongst: "
56 "`jets`, `JER`, `FTag`, `electrons`, `muons`, `photons`, `taus`, `met`, `tracks`, `generator`, `PRW`, `event`. "
57 "This option is overridden by `filterSystematics`.",
58 meta={'choices':(['jets', 'JER', 'FTag', 'electrons', 'muons', 'photons', 'taus', 'met', 'tracks', 'generator', 'PRW', 'event'], None)})
59 self.addOption ('systematicsHistogram', None , type=str,
60 info="the name of the histogram to which a list of executed "
61 "systematics will be printed. If left empty, the histogram is not written at all.")
62 self.addOption ('separateWeightSystematics', False, type=bool,
63 info="if `systematicsHistogram` is enabled, whether to create a separate "
64 "histogram holding only the names of weight-based systematics. This is useful "
65 "to help make histogramming frameworks more efficient by knowing in advance which "
66 "systematics need to recompute the observable and which don't.")
67 self.addOption ('metadataHistogram', 'metadata' , type=str,
68 info="the name of the metadata histogram which contains information about "
69 "data type, campaign, etc. If left empty, the histogram is not written at all.")
70 self.addOption ('enableExpertMode', False, type=bool,
71 info="allows CP experts and CPAlgorithm devs to use non-recommended configurations. "
72 "DO NOT USE FOR ANALYSIS.")
73 self.addOption ('streamName', None, type=str,
74 info="name of the output stream to save metadata histograms in.")
75 self.addOption ('setupONNX', False, type=bool,
76 info="creates an instance of `AthOnnx::OnnxRuntimeSvc`.")
77

Member Function Documentation

◆ instanceName()

python.AsgAnalysisConfig.CommonServicesConfig.instanceName ( self)
Return the instance name for this block

Definition at line 78 of file AsgAnalysisConfig.py.

78 def instanceName (self) :
79 """Return the instance name for this block"""
80 return '' # no instance name, this is a singleton
81

◆ makeAlgs()

python.AsgAnalysisConfig.CommonServicesConfig.makeAlgs ( self,
config )

Definition at line 82 of file AsgAnalysisConfig.py.

82 def makeAlgs (self, config) :
83
84 sysService = config.createService( 'CP::SystematicsSvc', 'SystematicsSvc' )
85
86 # Setup stream name
87 streamName = self.streamName or config.defaultHistogramStream()
88
89 # Handle all possible configuration options for systematics
90 if self.runSystematics is False:
91 runSystematics = self.runSystematics
92 elif config.noSystematics() is not None:
93 # if option not set:
94 # check to see if set in config accumulator
95 self.runSystematics = not config.noSystematics()
96 runSystematics = self.runSystematics
97 else:
98 runSystematics = True
99
100 # Now update the global configuration
101 config._noSystematics = not runSystematics
102
103 if runSystematics:
104 sysService.sigmaRecommended = 1
105 if config.dataType() is DataType.Data:
106 # Only one type of allowed systematics on data: the JER variations!
107 self.onlySystematicsCategories = ['JER']
108 if self.onlySystematicsCategories is not None:
109 # Convert strings to enums and validate
110 requested_categories = set()
111 for category_str in self.onlySystematicsCategories:
112 try:
113 category_enum = SystematicsCategories[category_str.upper()]
114 requested_categories |= category_enum.value
115 except KeyError:
116 raise ValueError(f"Invalid systematics category passed to option 'onlySystematicsCategories': {category_str}. Must be one of {', '.join(category.name for category in SystematicsCategories)}")
117 # Construct regex pattern as logical-OR of category names
118 if len(requested_categories):
119 sysService.systematicsRegex = "^(?=.*(" + "|".join(sorted(requested_categories)) + ")|$).*"
120 if self.filterSystematics is not None:
121 sysService.systematicsRegex = self.filterSystematics
122 config.createService( 'CP::SelectionNameSvc', 'SelectionNameSvc')
123
124 if self.systematicsHistogram is not None:
125 # print out all systematics
126 allSysDumper = config.createAlgorithm( 'CP::SysListDumperAlg', 'SystematicsPrinter' )
127 allSysDumper.histogramName = self.systematicsHistogram
128 allSysDumper.RootStreamName = streamName
129
130 if self.separateWeightSystematics:
131 # print out only the weight systematics (for more efficient histogramming down the line)
132 weightSysDumper = config.createAlgorithm( 'CP::SysListDumperAlg', 'OnlyWeightSystematicsPrinter' )
133 weightSysDumper.histogramName = f"{self.systematicsHistogram}OnlyWeights"
134 weightSysDumper.systematicsRegex = "^(GEN_|EL_EFF_|MUON_EFF_|PH_EFF_|TAUS_TRUEHADTAU_EFF_|FT_EFF_|JET_.*JvtEfficiency_|PRW_).*"
135 weightSysDumper.RootStreamName = streamName
136
137 if self.metadataHistogram:
138 # add histogram with metadata
139 if not config.flags:
140 raise ValueError ("Writing out the metadata histogram requires to pass config flags")
141 metadataHistAlg = config.createAlgorithm( 'CP::MetadataHistAlg', 'MetadataHistAlg' )
142 metadataHistAlg.histogramName = self.metadataHistogram
143 metadataHistAlg.dataType = str(config.dataType().value)
144 metadataHistAlg.campaign = str(config.dataYear()) if config.dataType() is DataType.Data else str(config.campaign().value)
145 metadataHistAlg.mcChannelNumber = str(config.dsid())
146 metadataHistAlg.RootStreamName = streamName
147 if config.dataType() is DataType.Data:
148 etag = "unavailable"
149 else:
150 from AthenaConfiguration.AutoConfigFlags import GetFileMD
151 metadata = GetFileMD(config.flags.Input.Files)
152 amiTags = metadata.get("AMITag", "not found!")
153 etag = str(amiTags.split("_")[0])
154 metadataHistAlg.etag = etag
155
156 if self.enableExpertMode:
157 # set any expert-mode errors to be ignored instead
158 warnings.simplefilter('ignore', ExpertModeWarning)
159 # just warning users they might be doing something dangerous
160 log = logging.getLogger('CommonServices')
161 bold = "\033[1m"
162 red = "\033[91m"
163 yellow = "\033[93m"
164 reset = "\033[0m"
165 log.warning(red +r"""
166 ________ _______ ______ _____ _______ __ __ ____ _____ ______ ______ _ _ ____ _ ______ _____
167 | ____\ \ / / __ \| ____| __ \__ __| | \/ |/ __ \| __ \| ____| | ____| \ | | /\ | _ \| | | ____| __ \
168 | |__ \ V /| |__) | |__ | |__) | | | | \ / | | | | | | | |__ | |__ | \| | / \ | |_) | | | |__ | | | |
169 | __| > < | ___/| __| | _ / | | | |\/| | | | | | | | __| | __| | . ` | / /\ \ | _ <| | | __| | | | |
170 | |____ / . \| | | |____| | \ \ | | | | | | |__| | |__| | |____ | |____| |\ |/ ____ \| |_) | |____| |____| |__| |
171 |______/_/ \_\_| |______|_| \_\ |_| |_| |_|\____/|_____/|______| |______|_| \_/_/ \_\____/|______|______|_____/
172
173"""
174 +reset)
175 log.warning(f"{bold}{yellow}These settings are not recommended for analysis. Make sure you know what you're doing, or disable them with `enableExpertMode: False` in `CommonServices`.{reset}")
176
177 if self.setupONNX:
178 config.createService('AthOnnx::OnnxRuntimeSvc', 'OnnxRuntimeSvc')
179 config.setContainerMeta ('EventInfo', 'OnnxEnabled', self.setupONNX)
180
181@groupBlocks
STL class.

Member Data Documentation

◆ enableExpertMode

python.AsgAnalysisConfig.CommonServicesConfig.enableExpertMode

Definition at line 156 of file AsgAnalysisConfig.py.

◆ metadataHistogram

python.AsgAnalysisConfig.CommonServicesConfig.metadataHistogram

Definition at line 137 of file AsgAnalysisConfig.py.

◆ onlySystematicsCategories

list python.AsgAnalysisConfig.CommonServicesConfig.onlySystematicsCategories = ['JER']

Definition at line 107 of file AsgAnalysisConfig.py.

◆ runSystematics

python.AsgAnalysisConfig.CommonServicesConfig.runSystematics = not config.noSystematics()

Definition at line 95 of file AsgAnalysisConfig.py.

◆ separateWeightSystematics

python.AsgAnalysisConfig.CommonServicesConfig.separateWeightSystematics

Definition at line 130 of file AsgAnalysisConfig.py.

◆ setupONNX

python.AsgAnalysisConfig.CommonServicesConfig.setupONNX

Definition at line 177 of file AsgAnalysisConfig.py.


The documentation for this class was generated from the following file: