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

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

Constructor & Destructor Documentation

◆ __init__()

python.AsgAnalysisConfig.CommonServicesConfig.__init__ ( self)

Definition at line 36 of file AsgAnalysisConfig.py.

36 def __init__ (self) :
37 super (CommonServicesConfig, self).__init__ ()
38 self.addOption ('runSystematics', None, type=bool,
39 info="whether to turn on the computation of systematic variations. "
40 "The default is to run them on MC.")
41 self.addOption ('filterSystematics', None, type=str,
42 info="a regexp string against which the systematics names will be "
43 "matched. Only positive matches are retained and used in the evaluation "
44 "of the various algorithms.")
45 self.addOption ('onlySystematicsCategories', None, type=list,
46 info="a list of strings defining categories of systematics to enable "
47 "(only recommended for studies / partial ntuple productions). Choose amongst: "
48 "jets, electrons, muons, photons, taus, met, tracks, ftag, event. This option is overridden "
49 "by 'filterSystematics'.")
50 self.addOption ('systematicsHistogram', None , type=str,
51 info="the name (string) of the histogram to which a list of executed "
52 "systematics will be printed. The default is None (don't write out "
53 "the histogram).")
54 self.addOption ('separateWeightSystematics', False, type=bool,
55 info="if 'systematicsHistogram' is enabled, whether to create a separate "
56 "histogram holding only the names of weight-based systematics. This is useful "
57 "to help make histogramming frameworks more efficient by knowing in advance which "
58 "systematics need to recompute the observable and which don't.")
59 self.addOption ('metadataHistogram', None , type=str,
60 info="the name (string) of the metadata histogram which contains information about "
61 "data type, campaign, etc. The default is None (don't write out "
62 "the histogram).")
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 "The default is ANALYSIS.")
69

Member Function Documentation

◆ instanceName()

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

Definition at line 70 of file AsgAnalysisConfig.py.

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

◆ makeAlgs()

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

Definition at line 74 of file AsgAnalysisConfig.py.

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

Member Data Documentation

◆ onlySystematicsCategories

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

Definition at line 92 of file AsgAnalysisConfig.py.

◆ runSystematics

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

Definition at line 83 of file AsgAnalysisConfig.py.

◆ separateWeightSystematics

python.AsgAnalysisConfig.CommonServicesConfig.separateWeightSystematics

Definition at line 115 of file AsgAnalysisConfig.py.


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