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 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 self.addOption ('systematicsHistogram', None , type=str,
55 info="the name of the histogram to which a list of executed "
56 "systematics will be printed. If left empty, the histogram is not written at all.")
57 self.addOption ('separateWeightSystematics', False, type=bool,
58 info="if `systematicsHistogram` is enabled, whether to create a separate "
59 "histogram holding only the names of weight-based systematics. This is useful "
60 "to help make histogramming frameworks more efficient by knowing in advance which "
61 "systematics need to recompute the observable and which don't.")
62 self.addOption ('metadataHistogram', 'metadata' , type=str,
63 info="the name of the metadata histogram which contains information about "
64 "data type, campaign, etc. If left empty, the histogram is not written at all.")
65 self.addOption ('enableExpertMode', False, type=bool,
66 info="allows CP experts and CPAlgorithm devs to use non-recommended configurations. "
67 "DO NOT USE FOR ANALYSIS.")
68 self.addOption ('streamName', None, type=str,
69 info="name of the output stream to save metadata histograms in.")
70 self.addOption ('setupONNX', False, type=bool,
71 info="creates an instance of `AthOnnx::OnnxRuntimeSvc`.")
72

Member Function Documentation

◆ instanceName()

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

Definition at line 73 of file AsgAnalysisConfig.py.

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

◆ makeAlgs()

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

Definition at line 77 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ metadataHistogram

python.AsgAnalysisConfig.CommonServicesConfig.metadataHistogram

Definition at line 131 of file AsgAnalysisConfig.py.

◆ onlySystematicsCategories

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

Definition at line 102 of file AsgAnalysisConfig.py.

◆ runSystematics

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

Definition at line 90 of file AsgAnalysisConfig.py.

◆ separateWeightSystematics

python.AsgAnalysisConfig.CommonServicesConfig.separateWeightSystematics

Definition at line 125 of file AsgAnalysisConfig.py.

◆ setupONNX

python.AsgAnalysisConfig.CommonServicesConfig.setupONNX

Definition at line 171 of file AsgAnalysisConfig.py.


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