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

Member Data Documentation

◆ onlySystematicsCategories

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

Definition at line 93 of file AsgAnalysisConfig.py.

◆ runSystematics

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

Definition at line 84 of file AsgAnalysisConfig.py.

◆ separateWeightSystematics

python.AsgAnalysisConfig.CommonServicesConfig.separateWeightSystematics

Definition at line 116 of file AsgAnalysisConfig.py.

◆ setupONNX

python.AsgAnalysisConfig.CommonServicesConfig.setupONNX

Definition at line 161 of file AsgAnalysisConfig.py.


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