ATLAS Offline Software
Loading...
Searching...
No Matches
KLFitterConfig.KLFitterBlock Class Reference
Inheritance diagram for KLFitterConfig.KLFitterBlock:
Collaboration diagram for KLFitterConfig.KLFitterBlock:

Public Member Functions

 __init__ (self)
 instanceName (self)
 parseSelectionRegionsConfig (self)
 makeAlgs (self, config)

Public Attributes

 perRegionConfiguration = list()
str likelihoodType
 containerName
 saveAllPermutations

Detailed Description

ConfigBlock for KLFitter algorithms

Definition at line 7 of file KLFitterConfig.py.

Constructor & Destructor Documentation

◆ __init__()

KLFitterConfig.KLFitterBlock.__init__ ( self)

Definition at line 10 of file KLFitterConfig.py.

10 def __init__(self):
11 super(KLFitterBlock, self).__init__()
12 self.addOption ('containerName', '', type=str,
13 noneAction='error',
14 info="the name of the input container.",
15 meta={'role':'container'})
16 self.addOption(
17 "electrons",
18 "",
19 type=str,
20 info="the input electron container, with a possible selection, in the format `container` or `container.selection`.",
21 meta={'role':'containerRef'},
22 )
23 self.addOption(
24 "muons",
25 "",
26 type=str,
27 info="the input muon container, with a possible selection, in the format `container` or `container.selection`.",
28 meta={'role':'containerRef'},
29 )
30 self.addOption(
31 "jets",
32 "",
33 type=str,
34 info="the input jet container, with a possible selection, in the format `container` or `container.selection`.",
35 meta={'role':'containerRef'},
36 )
37 self.addOption(
38 "met",
39 "",
40 type=str,
41 info="the input MET container.",
42 meta={'role':'containerRef'},
43 )
44 self.addOption(
45 "likelihoodType",
46 "",
47 type=str,
48 info="KLFitter likelihood, if only one is needed. See `KLFitterEnums.h` for possible values.",
49 )
50 self.addOption(
51 "leptonType",
52 "",
53 type=str,
54 info="type of lepton to use (only relevant to certain likelihood types), if only one is needed. See `KLFitterEnums.h` for possible values.",
55 )
56 self.addOption(
57 "jetSelectionMode",
58 "",
59 type=str,
60 info="jet selection mode to use, if only one is needed. See `KLFitterEnums.h` for possible values.",
61 )
62 self.addOption(
63 "btaggingMethod",
64 "kNotag",
65 type=str,
66 info="strategy to handle b-jets, if only one is needed. See `KLFitterEnums.h` for possible values.",
67 )
68 self.addOption(
69 "bTagCDIFile",
70 None,
71 type=str,
72 info="CDI file to pass to the b-tagging efficiency tool.",
73 )
74 self.addOption(
75 "btagger",
76 "GN2v01",
77 type=str,
78 info="b-tagging algorithm to use, if only one is needed.",
79 )
80 self.addOption(
81 "btagWP",
82 "",
83 type=str,
84 info="b-tagging efficiency WP to use, if only one is needed.",
85 )
86 self.addOption(
87 "btagIgnoreOutOfValidityRange",
88 False,
89 type=bool,
90 info="whether or not the b-tagger should ignore (and not fail) when a jet is outside the calibration range.",
91 )
92 self.addOption(
93 "selectionRegionsConfig",
94 "",
95 type=str,
96 info="string of the form `selectionName: sel1, optionA: opA, optionB: opB; selectionName: sel2, ...` where options can be `likelihoodType`, `leptonType`, `jetSelectionMode`, `btaggingMethod`, `btagger` or `btagWP`.",
97 )
98 self.addOption(
99 "saveAllPermutations",
100 False,
101 type=bool,
102 info="whether to save all permutations, or just the best one.",
103 )
104 # list of dictionaries for the per-region config options
105 self.perRegionConfiguration = list()
106

Member Function Documentation

◆ instanceName()

KLFitterConfig.KLFitterBlock.instanceName ( self)
Return the instance name for this block

Definition at line 107 of file KLFitterConfig.py.

107 def instanceName (self) :
108 """Return the instance name for this block"""
109 return self.containerName
110

◆ makeAlgs()

KLFitterConfig.KLFitterBlock.makeAlgs ( self,
config )

Definition at line 137 of file KLFitterConfig.py.

137 def makeAlgs(self, config):
138 if not self.likelihoodType:
139 raise ValueError("KLFitterConfig: the likelihoodType option must be set")
140 self.parseSelectionRegionsConfig()
141 for perRegionConfig in self.perRegionConfiguration:
142 selectionName = perRegionConfig["selectionName"]
143 alg = config.createAlgorithm(
144 "EventReco::RunKLFitterAlg",
145 f"RunKLFitterAlg_{selectionName}",
146 )
147 # input objects and their object selections
148 alg.electrons, alg.electronSelection = config.readNameAndSelection(
149 self.electrons
150 )
151 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
152 alg.jets, alg.jetSelection = config.readNameAndSelection(self.jets)
153 alg.met = config.readName(self.met)
154 alg.result = self.containerName + "_%SYS%"
155
156 # global settings, in future expect to expose more options for configuration
157 alg.SaveAllPermutations = self.saveAllPermutations
158
159 # these settings can be defined per-region, but if not, we fallback to global setting
160 alg.selectionDecorationName = selectionName + "_%SYS%,as_char"
161 alg.LHType = self.likelihoodType
162 alg.LeptonType = perRegionConfig.get("leptonType", self.leptonType)
163 alg.JetSelectionMode = perRegionConfig.get(
164 "jetSelectionMode", self.jetSelectionMode
165 )
166 btagAlgo = perRegionConfig.get("btagger", self.btagger)
167 btagWP = perRegionConfig.get("btagWP", self.btagWP)
168 alg.BTaggingDecoration = f"ftag_select_{btagAlgo}_{btagWP}"
169
170 alg.BTaggingMethod = perRegionConfig.get(
171 "btaggingMethod", self.btaggingMethod
172 )
173 if alg.BTaggingMethod == "kWorkingPoint":
174 config.addPrivateTool("btagEffTool", "BTaggingEfficiencyTool")
175 alg.btagEffTool.TaggerName = btagAlgo
176 alg.btagEffTool.OperatingPoint = btagWP
177 jetCollection = config.originalName(self.jets.split(".")[0])
178 alg.btagEffTool.JetAuthor = jetCollection
179 alg.btagEffTool.ScaleFactorFileName = (
180 getRecommendedBTagCalib(config.geometry(), btagWP)
181 if self.bTagCDIFile is None
182 else self.bTagCDIFile
183 )
184 alg.btagEffTool.IgnoreOutOfValidityRange = (
185 self.btagIgnoreOutOfValidityRange
186 )
187 alg.btagEffTool.MinPt = (
188 20e3 # hardcoded to the recommendation for EMPFlow at the moment
189 )
190 # NOTE the efficiency tool is simply set to the default generator,
191 # meaning the results are not correct for alternative showering generators!!
192
193 finalizeAlg = config.createAlgorithm(
194 "EventReco::KLFitterFinalizeOutputAlg",
195 "KLFitterFinalizeOutputAlg",
196 )
197 finalizeAlg.resultContainerToCheck = self.containerName + "_%SYS%"
198 finalizeAlg.resultContainerToWrite = self.containerName + "_%SYS%"
199
200 config.writeName(self.containerName)
201
202 config.addOutputVar(self.containerName, "eventProbability", "eventProbability", auxType="float")
203 config.addOutputVar(self.containerName, "logLikelihood", "logLikelihood", auxType="float")
204 if self.saveAllPermutations:
205 config.addOutputVar(self.containerName, "bestPermutation", "bestPermutation", auxType="unsigned_int")
206
207 if self.likelihoodType != "ttbar_AllHad":
208 config.addOutputVar(
209 self.containerName, "model_bhad_jetIndex", "bhad_jetIndex", auxType="unsigned_int"
210 )
211 config.addOutputVar(
212 self.containerName, "model_blep_jetIndex", "blep_jetIndex", auxType="unsigned_int"
213 )
214 config.addOutputVar(
215 self.containerName, "model_lq1_jetIndex", "lq1_jetIndex", auxType="unsigned_int"
216 )
217 if self.likelihoodType != "ttbar_BoostedLJets":
218 config.addOutputVar(
219 self.containerName, "model_lq2_jetIndex", "lq2_jetIndex", auxType="unsigned_int"
220 )
221 if self.likelihoodType == "ttH":
222 config.addOutputVar(
223 self.containerName, "model_Higgs_b1_jetIndex", "Higgs_b1_jetIndex", auxType="unsigned_int"
224 )
225 config.addOutputVar(
226 self.containerName, "model_Higgs_b2_jetIndex", "Higgs_b2_jetIndex", auxType="unsigned_int"
227 )
228
229 config.addOutputVar(self.containerName, "model_nu_pt", "nu_pt", auxType="float")
230 config.addOutputVar(self.containerName, "model_nu_eta", "nu_eta", auxType="float")
231 config.addOutputVar(self.containerName, "model_nu_phi", "nu_phi", auxType="float")
232 config.addOutputVar(self.containerName, "model_nu_E", "nu_E", auxType="float")
233
234 if self.likelihoodType == "ttZTrilepton":
235 config.addOutputVar(self.containerName, "model_lep_index", "lep_index", auxType="unsigned_int")
236 config.addOutputVar(
237 self.containerName, "model_lepZ1_index", "lepZ1_index", auxType="unsigned_int"
238 )
239 config.addOutputVar(
240 self.containerName, "model_lepZ2_index", "lepZ2_index", auxType="unsigned_int"
241 )
242 else:
243 config.addOutputVar(
244 self.containerName, "model_b_from_top1_jetIndex", "b_from_top1_jetIndex", auxType="unsigned_int"
245 )
246 config.addOutputVar(
247 self.containerName, "model_b_from_top2_jetIndex", "b_from_top2_jetIndex", auxType="unsigned_int"
248 )
249 config.addOutputVar(
250 self.containerName,
251 "model_lj1_from_top1_jetIndex",
252 "lj1_from_top1_jetIndex",
253 auxType="unsigned_int"
254 )
255 config.addOutputVar(
256 self.containerName,
257 "model_lj2_from_top1_jetIndex",
258 "lj2_from_top1_jetIndex",
259 auxType="unsigned_int"
260 )
261 config.addOutputVar(
262 self.containerName,
263 "model_lj1_from_top2_jetIndex",
264 "lj1_from_top2_jetIndex",
265 auxType="unsigned_int"
266 )
267 config.addOutputVar(
268 self.containerName,
269 "model_lj2_from_top2_jetIndex",
270 "lj2_from_top2_jetIndex",
271 auxType="unsigned_int"
272 )
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ parseSelectionRegionsConfig()

KLFitterConfig.KLFitterBlock.parseSelectionRegionsConfig ( self)

Definition at line 111 of file KLFitterConfig.py.

111 def parseSelectionRegionsConfig(self):
112 if not self.selectionRegionsConfig.strip():
113 raise ValueError(
114 "KLFitterConfig: Could not determine any regions in your selectionRegionsConfig (empty string)"
115 )
116 regions = self.selectionRegionsConfig.split(";")
117 for reg in regions:
118 regionopts = {}
119 for option in reg.replace(" ", "").split(","):
120 keyval = option.split(":")
121 if len(keyval) != 2 or not keyval[0] or not keyval[1]:
122 raise ValueError(
123 f"KLFitterConfig: malformed option '{option}' in selectionRegionsConfig region '{reg}', expected 'key: value'"
124 )
125 regionopts[keyval[0]] = keyval[1]
126 if "selectionName" not in regionopts:
127 raise ValueError(
128 f"KLFitterConfig: Could not parse selectionRegionsConfig selectionName for region '{reg}'"
129 )
130 if "likelihoodType" in regionopts:
131 raise ValueError(
132 "KLFitterConfig: likelihoodType cannot be overriden per region. Create a separate instance of KLFitter block with different likelihoodType instead."
133 )
134
135 self.perRegionConfiguration.append(regionopts)
136

Member Data Documentation

◆ containerName

KLFitterConfig.KLFitterBlock.containerName

Definition at line 200 of file KLFitterConfig.py.

◆ likelihoodType

str KLFitterConfig.KLFitterBlock.likelihoodType

Definition at line 138 of file KLFitterConfig.py.

◆ perRegionConfiguration

KLFitterConfig.KLFitterBlock.perRegionConfiguration = list()

Definition at line 105 of file KLFitterConfig.py.

◆ saveAllPermutations

KLFitterConfig.KLFitterBlock.saveAllPermutations

Definition at line 204 of file KLFitterConfig.py.


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