3 from AnalysisAlgorithmsConfig.ConfigBlock
import ConfigBlock
4 from FTagAnalysisAlgorithms.FTagHelpers
import getRecommendedBTagCalib
8 """ConfigBlock for KLFitter algorithms"""
11 super(KLFitterBlock, self).
__init__()
12 self.addOption (
'containerName',
'', type=str,
14 info=
"the name of the input container.")
19 info=
"the input electron container, with a possible selection, in the format container or container.selection. The default is '' (empty string).",
25 info=
"the input muon container, with a possible selection, in the format container or container.selection. The default is '' (empty string).",
31 info=
"the input jet container, with a possible selection, in the format container or container.selection. The default is '' (empty string).",
37 info=
"the input MET container. The default is '' (empty string).",
43 info=
"KLFitter likelihood, if only one is needed. See KLFitterEnums.h for possible values. The default is '' (empty string).",
49 info=
"type of lepton to use (only relevant to certain likelihood types), if only one is needed. See KLFitterEnums.h for possible values. The default is '' (empty string).",
55 info=
"jet selection mode to use, if only one is needed. See KLFitterEnums.h for possible values. The default is '' (empty string).",
61 info=
"strategy to handle b-jets, if only one is needed. See KLFitterEnums.h for possible values. The default is '' (empty string).",
67 info=
"CDI file to pass to the b-tagging efficiency tool",
73 info=
"b-tagging algorithm to use, if only one is needed. The default is 'GN2v01'.",
79 info=
"b-tagging efficiency WP to use, if only one is needed.",
82 "btagIgnoreOutOfValidityRange",
85 info=
"whether or not the b-tagger should ignore (and not fail) when a jet is outside the calibration range. The default is False.",
88 "selectionRegionsConfig",
91 info=
"string of the form 'selectionName: sel1, optionA: opA, optionB: opB; selectionName: sel2, ...' where options can be likelihoodType, leptonType, jetSelectionMode, btaggingMethod, btagger or btagWP. The default is '' (empty string).",
94 "saveAllPermutations",
97 info=
"whether to save all permutations, or just the best one. The default is False (only save the best one).",
103 """Return the instance name for this block"""
104 return self.containerName
107 regions = self.selectionRegionsConfig.
split(
";")
108 if len(regions) == 0:
110 "KLFitterConfig: Could not determine any regions in your SelectionRegionsConfig"
113 regstrip = reg.replace(
" ",
"")
115 tuple(option.split(
":"))
for option
in regstrip.split(
",")
117 if "selectionName" not in regionopts:
119 "KLFitterConfig: Could not parse SelectionRegionsConfig selectionName for region ",
122 if "likelihoodType" in regionopts:
124 "KLFitterConfig: likelihoodType cannot be overriden per region. Create a separate instance of KLFitter block with different likelihoodType instead."
132 selectionName = perRegionConfig[
"selectionName"]
133 alg = config.createAlgorithm(
134 "EventReco::RunKLFitterAlg",
135 f
"RunKLFitterAlg_{selectionName}",
138 alg.electrons, alg.electronSelection = config.readNameAndSelection(
141 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
142 alg.jets, alg.jetSelection = config.readNameAndSelection(self.jets)
143 alg.met = config.readName(self.met)
144 alg.result = self.containerName +
"_%SYS%"
147 alg.SaveAllPermutations = self.saveAllPermutations
150 alg.selectionDecorationName = selectionName +
"_%SYS%,as_char"
152 alg.LeptonType = perRegionConfig.get(
"leptonType", self.leptonType)
153 alg.JetSelectionMode = perRegionConfig.get(
154 "jetSelectionMode", self.jetSelectionMode
156 btagAlgo = perRegionConfig.get(
"btagger", self.btagger)
157 btagWP = perRegionConfig.get(
"btagWP", self.btagWP)
158 alg.BTaggingDecoration = f
"ftag_select_{btagAlgo}_{btagWP}"
160 alg.BTaggingMethod = perRegionConfig.get(
161 "btaggingMethod", self.btaggingMethod
163 if alg.BTaggingMethod ==
"kWorkingPoint":
164 config.addPrivateTool(
"btagEffTool",
"BTaggingEfficiencyTool")
165 alg.btagEffTool.TaggerName = self.btagger
166 alg.btagEffTool.OperatingPoint = self.btagWP
167 jetCollection = config.originalName(self.jets.
split(
".")[0])
168 alg.btagEffTool.JetAuthor = jetCollection
169 alg.btagEffTool.ScaleFactorFileName = (
171 if self.bTagCDIFile
is None
172 else self.bTagCDIFile
174 alg.btagEffTool.IgnoreOutOfValidityRange = (
175 self.btagIgnoreOutOfValidityRange
177 alg.btagEffTool.MinPt = (
183 finalizeAlg = config.createAlgorithm(
184 "EventReco::KLFitterFinalizeOutputAlg",
185 "KLFitterFinalizeOutputAlg",
187 finalizeAlg.resultContainerToCheck = self.containerName +
"_%SYS%"
188 finalizeAlg.resultContainerToWrite = self.containerName +
"_%SYS%"
190 config.setSourceName(self.containerName, self.containerName)
191 config.addOutputContainer(self.containerName, self.containerName +
"_%SYS%")
193 config.addOutputVar(self.containerName,
"eventProbability",
"eventProbability")
194 config.addOutputVar(self.containerName,
"logLikelihood",
"logLikelihood")
195 if self.saveAllPermutations:
196 config.addOutputVar(self.containerName,
"selected",
"selected")
200 self.containerName,
"model_bhad_jetIndex",
"bhad_jetIndex"
203 self.containerName,
"model_blep_jetIndex",
"blep_jetIndex"
206 self.containerName,
"model_lq1_jetIndex",
"lq1_jetIndex"
210 self.containerName,
"model_lq2_jetIndex",
"lq2_jetIndex"
214 self.containerName,
"model_Higgs_b1_jetIndex",
"Higgs_b1_jetIndex"
217 self.containerName,
"model_Higgs_b2_jetIndex",
"Higgs_b2_jetIndex"
220 config.addOutputVar(self.containerName,
"model_nu_pt",
"nu_pt")
221 config.addOutputVar(self.containerName,
"model_nu_eta",
"nu_eta")
222 config.addOutputVar(self.containerName,
"model_nu_phi",
"nu_phi")
223 config.addOutputVar(self.containerName,
"model_nu_E",
"nu_E")
226 config.addOutputVar(self.containerName,
"model_lep_index",
"lep_index")
228 self.containerName,
"model_lepZ1_index",
"lepZ1_index"
231 self.containerName,
"model_lepZ2_index",
"lepZ2_index"
235 self.containerName,
"model_b_from_top1_jetIndex",
"b_from_top1_jetIndex"
238 self.containerName,
"model_b_from_top2_jetIndex",
"b_from_top2_jetIndex"
242 "model_lj1_from_top1_jetIndex",
243 "lj1_from_top1_jetIndex",
247 "model_lj2_from_top1_jetIndex",
248 "lj2_from_top1_jetIndex",
252 "model_lj1_from_top2_jetIndex",
253 "lj1_from_top2_jetIndex",
257 "model_lj2_from_top2_jetIndex",
258 "lj2_from_top2_jetIndex",