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 32 of file AsgAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.CommonServicesConfig.__init__ ( self)

Definition at line 40 of file AsgAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 74 of file AsgAnalysisConfig.py.

74 def instanceName (self) :
75 """Return the instance name for this block"""
76 return '' # no instance name, this is a singleton
77

◆ makeAlgs()

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

Definition at line 78 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ enableExpertMode

python.AsgAnalysisConfig.CommonServicesConfig.enableExpertMode

Definition at line 151 of file AsgAnalysisConfig.py.

◆ metadataHistogram

python.AsgAnalysisConfig.CommonServicesConfig.metadataHistogram

Definition at line 132 of file AsgAnalysisConfig.py.

◆ onlySystematicsCategories

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

Definition at line 103 of file AsgAnalysisConfig.py.

◆ runSystematics

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

Definition at line 91 of file AsgAnalysisConfig.py.

◆ separateWeightSystematics

python.AsgAnalysisConfig.CommonServicesConfig.separateWeightSystematics

Definition at line 126 of file AsgAnalysisConfig.py.

◆ setupONNX

python.AsgAnalysisConfig.CommonServicesConfig.setupONNX

Definition at line 172 of file AsgAnalysisConfig.py.


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