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

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.CommonServicesConfig.__init__ ( self)

Definition at line 38 of file AsgAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 71 of file AsgAnalysisConfig.py.

71 def instanceName (self) :
72 """Return the instance name for this block"""
73 return '' # no instance name, this is a singleton
74

◆ makeAlgs()

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

Definition at line 75 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ metadataHistogram

python.AsgAnalysisConfig.CommonServicesConfig.metadataHistogram

Definition at line 129 of file AsgAnalysisConfig.py.

◆ onlySystematicsCategories

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

Definition at line 100 of file AsgAnalysisConfig.py.

◆ runSystematics

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

Definition at line 88 of file AsgAnalysisConfig.py.

◆ separateWeightSystematics

python.AsgAnalysisConfig.CommonServicesConfig.separateWeightSystematics

Definition at line 123 of file AsgAnalysisConfig.py.

◆ setupONNX

python.AsgAnalysisConfig.CommonServicesConfig.setupONNX

Definition at line 169 of file AsgAnalysisConfig.py.


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