8 """Compares two ConfigSequences"""
10 blocks2 = seq2._blocks
11 print(
"Block order for each config sequence")
12 print(
"\033[4m{0:<30} {1:<30}\033[0m".
format(
"Sequence1",
"Sequence2"))
13 for i
in range(
max(len(blocks1), len(blocks2))):
16 name1 = blocks1[i].__class__.__name__
18 name2 = blocks2[i].__class__.__name__
19 print(f
"{name1:<30} {name2}")
21 print(
"Sorting blocks by name (will not sort blocks with same name)")
22 blocks1.sort(key=
lambda x: x.__class__.__name__)
23 blocks2.sort(key=
lambda x: x.__class__.__name__)
24 if len(blocks1) != len(blocks2):
25 raise Exception(
"Number of blocks are different")
26 for i
in range(len(blocks1)):
29 name1 = block1.__class__.__name__
30 name2 = block2.__class__.__name__
32 raise Exception(f
"In position {i} "
33 f
"the first sequence results in {name1} "
34 f
"and the second sequence results in {name2}")
35 for name
in block1.getOptions():
36 if name ==
'groupName':
38 value1 = block1.getOptionValue(name)
39 value2 = block2.getOptionValue(name)
41 raise Exception(f
"For block {name1}, the block "
42 f
"option {name} the first sequence results in {value1} "
43 f
"and the second sequence results in {value2}")
48 Create a configSequence using provided YAML file and a
49 configSequence using ConfigText python commands and compare.
51 Will raise an exception if configSequences differ
54 from AnalysisAlgorithmsConfig.ConfigText
import TextConfig
58 config.addBlock(
'CommonServices')
59 config.setOptions(systematicsHistogram=
'systematicsList')
62 config.addBlock(
'PileupReweighting')
65 config.addBlock(
'EventCleaning')
66 config.setOptions (runEventCleaning=
True)
69 config.addBlock(
'Jets')
70 config.setOptions (containerName=
'AnaJets')
71 config.setOptions (jetCollection=
'AntiKt4EMPFlowJets')
72 config.setOptions (runJvtUpdate=
False)
73 config.setOptions (runNNJvtUpdate=
True)
74 config.setOptions (recalibratePhyslite=
False)
76 config.addBlock(
'Jets.FlavourTagging')
77 config.setOptions (containerName=
'AnaJets')
78 config.setOptions (selectionName=
'ftag')
79 config.setOptions (btagger=
'GN2v01')
80 config.setOptions (btagWP=
'FixedCutBEff_65')
81 config.setOptions (saveScores=
'All')
83 config.addBlock(
'Jets.FlavourTaggingEventSF')
84 config.setOptions (containerName=
'AnaJets.baselineJvt')
85 config.setOptions (btagger=
'GN2v01')
87 config.addBlock(
'Jets.JVT', containerName=
'AnaJets')
90 config.addBlock(
'Jets')
91 config.setOptions (containerName=
'AnaLargeRJets')
92 config.setOptions (jetCollection=
'AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets')
93 config.setOptions (recalibratePhyslite=
False)
96 config.addBlock (
'Electrons')
97 config.setOptions (containerName=
'AnaElectrons')
98 config.setOptions (forceFullSimConfig=
True)
99 config.setOptions (recalibratePhyslite=
False)
100 config.setOptions (decorateTruth=
True)
102 config.addBlock (
'Electrons.WorkingPoint')
103 config.setOptions (containerName=
'AnaElectrons')
104 config.setOptions (selectionName=
'loose')
105 config.setOptions (forceFullSimConfig=
True)
106 config.setOptions (noEffSF=
True)
107 config.setOptions (identificationWP=
'LooseBLayerLH')
108 config.setOptions (isolationWP=
'Loose_VarRad')
109 config.setOptions (writeTrackD0Z0=
True)
111 config.addBlock (
'Electrons.PtEtaSelection')
112 config.setOptions (containerName=
'AnaElectrons')
113 config.setOptions (minPt=10000.0)
115 config.addBlock (
'Electrons.IFFClassification')
116 config.setOptions (containerName=
'AnaElectrons')
118 config.addBlock (
'Electrons.MCTCClassification')
119 config.setOptions (containerName=
'AnaElectrons')
120 config.setOptions (prefix=
'truth_')
123 config.addBlock (
'Photons', containerName=
'AnaPhotons')
124 config.setOptions (forceFullSimConfig=
True)
125 config.setOptions (recomputeIsEM=
False)
126 config.setOptions (recalibratePhyslite=
False)
127 config.setOptions (decorateTruth=
True)
129 config.addBlock (
'Photons.WorkingPoint')
130 config.setOptions (containerName=
'AnaPhotons')
131 config.setOptions (selectionName=
'tight')
132 config.setOptions (forceFullSimConfig=
True)
133 config.setOptions (qualityWP=
'Tight')
134 config.setOptions (isolationWP=
'FixedCutTight')
135 config.setOptions (recomputeIsEM=
False)
137 config.addBlock (
'Photons.PtEtaSelection')
138 config.setOptions (containerName=
'AnaPhotons')
139 config.setOptions (minPt=10000.0)
142 config.addBlock (
'Muons', containerName=
'AnaMuons')
143 config.setOptions (recalibratePhyslite=
False)
144 config.setOptions (decorateTruth=
True)
146 config.addBlock (
'Muons.WorkingPoint')
147 config.setOptions (containerName=
'AnaMuons')
148 config.setOptions (selectionName=
'medium')
149 config.setOptions (quality=
'Medium')
150 config.setOptions (isolation=
'Loose_VarRad')
151 config.setOptions (writeTrackD0Z0=
True)
153 config.addBlock (
'Muons.IFFClassification')
154 config.setOptions (containerName=
'AnaMuons')
156 config.addBlock (
'Muons.MCTCClassification')
157 config.setOptions (containerName=
'AnaMuons')
158 config.setOptions (prefix=
'truth_')
161 config.addBlock (
'TauJets', containerName=
'AnaTauJets')
162 config.setOptions (decorateTruth=
True)
164 config.addBlock (
'TauJets.WorkingPoint')
165 config.setOptions (containerName=
'AnaTauJets')
166 config.setOptions (selectionName=
'tight')
167 config.setOptions (quality=
'Tight')
169 tauTriggerChainsSF = {
170 2015: [
'HLT_tau25_medium1_tracktwo',
'HLT_tau35_medium1_tracktwo'],
171 2016: [
'HLT_tau25_medium1_tracktwo',
'HLT_tau35_medium1_tracktwo'],
172 2017: [
'HLT_tau25_medium1_tracktwo',
'HLT_tau35_medium1_tracktwo'],
173 2018: [
'HLT_tau25_medium1_tracktwoEF_OR_mediumRNN_tracktwoMVA',
'HLT_tau35_medium1_tracktwoEF_OR_mediumRNN_tracktwoMVA'],
175 config.addBlock (
'TauJets.TriggerSF')
176 config.setOptions (containerName=
'AnaTauJets')
177 config.setOptions (tauID=
'Tight')
178 config.setOptions (triggerChainsPerYear=tauTriggerChainsSF)
180 config.addBlock (
'TauJets.MCTCClassification')
181 config.setOptions (containerName=
'AnaTauJets')
182 config.setOptions (prefix=
'truth_')
184 config.addBlock (
'SystObjectLink')
185 config.setOptions (containerName=
'AnaJets')
186 config.addBlock (
'SystObjectLink')
187 config.setOptions (containerName=
'AnaLargeRJets')
188 config.addBlock (
'SystObjectLink')
189 config.setOptions (containerName=
'AnaElectrons')
190 config.addBlock (
'SystObjectLink')
191 config.setOptions (containerName=
'AnaPhotons')
192 config.addBlock (
'SystObjectLink')
193 config.setOptions (containerName=
'AnaMuons')
194 config.addBlock (
'SystObjectLink')
195 config.setOptions (containerName=
'AnaTauJets')
197 config.addBlock (
'ObjectCutFlow')
198 config.setOptions (containerName=
'AnaJets')
199 config.setOptions (selectionName=
'jvt')
200 config.addBlock (
'ObjectCutFlow')
201 config.setOptions (containerName=
'AnaElectrons')
202 config.setOptions (selectionName=
'loose')
203 config.addBlock (
'ObjectCutFlow')
204 config.setOptions (containerName=
'AnaPhotons')
205 config.setOptions (selectionName=
'tight')
206 config.addBlock (
'ObjectCutFlow')
207 config.setOptions (containerName=
'AnaMuons')
208 config.setOptions (selectionName=
'medium')
209 config.addBlock (
'ObjectCutFlow')
210 config.setOptions (containerName=
'AnaTauJets')
211 config.setOptions (selectionName=
'tight')
214 config.addBlock(
'GeneratorLevelAnalysis')
217 config.addBlock (
'MissingET')
218 config.setOptions (containerName=
'AnaMET')
219 config.setOptions (jets=
'AnaJets')
220 config.setOptions (taus=
'AnaTauJets.tight')
221 config.setOptions (electrons=
'AnaElectrons.loose')
222 config.setOptions (photons=
'AnaPhotons.tight')
223 config.setOptions (muons=
'AnaMuons.medium')
226 config.addBlock(
'OverlapRemoval' )
227 config.setOptions (inputLabel=
'preselectOR')
228 config.setOptions (outputLabel=
'passesOR' )
229 config.setOptions (jets=
'AnaJets.baselineJvt')
230 config.setOptions (taus=
'AnaTauJets.tight')
231 config.setOptions (electrons=
'AnaElectrons.loose')
232 config.setOptions (photons=
'AnaPhotons.tight')
233 config.setOptions (muons=
'AnaMuons.medium')
236 config.addBlock (
'PL_Electrons')
237 config.setOptions (containerName=
'TruthElectrons')
238 config.addBlock (
'PL_Electrons.PtEtaSelection')
239 config.setOptions (containerName=
'TruthElectrons')
240 config.setOptions (skipOnData=
True)
241 config.setOptions (useDressedProperties=
True)
242 config.setOptions (minPt=20e3)
243 config.addBlock (
'PL_Electrons.MCTCClassification')
244 config.setOptions (containerName=
'TruthElectrons')
245 config.setOptions (prefix=
'')
247 config.addBlock (
'PL_Photons')
248 config.setOptions (containerName=
'TruthPhotons')
249 config.addBlock (
'PL_Photons.PtEtaSelection')
250 config.setOptions (containerName=
'TruthPhotons')
251 config.setOptions (skipOnData=
True)
252 config.setOptions (minPt=20e3)
254 config.addBlock (
'PL_Muons')
255 config.setOptions (containerName=
'TruthMuons')
256 config.addBlock (
'PL_Muons.PtEtaSelection')
257 config.setOptions (containerName=
'TruthMuons')
258 config.setOptions (skipOnData=
True)
259 config.setOptions (useDressedProperties=
True)
260 config.setOptions (minPt=20e3)
261 config.addBlock (
'PL_Muons.MCTCClassification')
262 config.setOptions (containerName=
'TruthMuons')
263 config.setOptions (prefix=
'')
265 config.addBlock (
'PL_Taus')
266 config.setOptions (containerName=
'TruthTaus')
267 config.addBlock (
'PL_Taus.PtEtaSelection')
268 config.setOptions (containerName=
'TruthTaus')
269 config.setOptions (skipOnData=
True)
270 config.setOptions (minPt=20e3)
271 config.addBlock (
'PL_Taus.MCTCClassification')
272 config.setOptions (containerName=
'TruthTaus')
273 config.setOptions (prefix=
'')
275 config.addBlock (
'PL_Jets')
276 config.setOptions (containerName=
'AntiKt4TruthDressedWZJets')
277 config.addBlock (
'PL_Jets.PtEtaSelection')
278 config.setOptions (containerName=
'AntiKt4TruthDressedWZJets')
279 config.setOptions (skipOnData=
True)
280 config.setOptions (minPt=20e3)
282 config.addBlock (
'PL_Neutrinos')
283 config.setOptions (skipOnData=
True)
284 config.addBlock (
'PL_MissingET')
285 config.setOptions (skipOnData=
True)
287 config.addBlock (
'PL_OverlapRemoval')
288 config.setOptions (skipOnData=
True)
289 config.setOptions (electrons=
'TruthElectrons')
290 config.setOptions (muons=
'TruthMuons')
291 config.setOptions (photons=
'TruthPhotons')
292 config.setOptions (jets=
'AntiKt4TruthDressedWZJets')
293 config.setOptions (useRapidityForDeltaR=
False)
296 config.addBlock (
'Thinning')
297 config.setOptions (containerName=
'AnaElectrons')
298 config.setOptions (selectionName=
'loose')
299 config.setOptions (outputName=
'OutElectrons')
300 config.addBlock (
'Thinning')
301 config.setOptions (containerName=
'AnaPhotons')
302 config.setOptions (selectionName=
'tight')
303 config.setOptions (outputName=
'OutPhotons')
304 config.addBlock (
'Thinning')
305 config.setOptions (containerName=
'AnaMuons')
306 config.setOptions (selectionName=
'medium')
307 config.setOptions (outputName=
'OutMuons')
308 config.addBlock (
'Thinning')
309 config.setOptions (containerName=
'AnaTauJets')
310 config.setOptions (selectionName=
'tight')
311 config.setOptions (outputName=
'OutTauJets')
312 config.addBlock (
'Thinning')
313 config.setOptions (containerName=
'AnaJets')
314 config.setOptions (outputName=
'OutJets')
315 config.addBlock (
'Thinning')
316 config.setOptions (containerName=
'AnaLargeRJets')
317 config.setOptions (outputName=
'OutLargeRJets')
318 config.addBlock (
'Thinning')
319 config.setOptions (containerName=
'TruthElectrons')
320 config.setOptions (skipOnData=
True)
321 config.setOptions (outputName=
'OutTruthElectrons')
322 config.addBlock (
'Thinning')
323 config.setOptions (containerName=
'TruthPhotons')
324 config.setOptions (skipOnData=
True)
325 config.setOptions (outputName=
'OutTruthPhotons')
326 config.addBlock (
'Thinning')
327 config.setOptions (containerName=
'TruthMuons')
328 config.setOptions (skipOnData=
True)
329 config.setOptions (outputName=
'OutTruthMuons')
330 config.addBlock (
'Thinning')
331 config.setOptions (containerName=
'TruthTaus')
332 config.setOptions (skipOnData=
True)
333 config.setOptions (outputName=
'OutTruthTaus')
334 config.addBlock (
'Thinning')
335 config.setOptions (containerName=
'AntiKt4TruthDressedWZJets')
336 config.setOptions (outputName=
'OutTruthJets')
337 config.setOptions (skipOnData=
True)
340 triggerChainsPerYear = {
341 2015: [
'HLT_e24_lhmedium_L1EM20VH || HLT_e60_lhmedium || HLT_e120_lhloose',
'HLT_mu20_iloose_L1MU15 || HLT_mu40',
'HLT_2g20_tight'],
342 2016: [
'HLT_e26_lhtight_nod0_ivarloose || HLT_e60_lhmedium_nod0 || HLT_e140_lhloose_nod0',
'HLT_mu26_ivarmedium || HLT_mu50',
'HLT_g35_loose_g25_loose'],
343 2017: [
'HLT_e26_lhtight_nod0_ivarloose || HLT_e60_lhmedium_nod0 || HLT_e140_lhloose_nod0',
'HLT_2g22_tight_L12EM15VHI',
'HLT_mu50'],
344 2018: [
'HLT_e26_lhtight_nod0_ivarloose || HLT_e60_lhmedium_nod0 || HLT_e140_lhloose_nod0',
'HLT_g35_medium_g25_medium_L12EM20VH',
'HLT_mu26_ivarmedium',
'HLT_2mu14'],
346 config.addBlock (
'Trigger')
347 config.setOptions (triggerChainsPerYear=triggerChainsPerYear)
348 config.setOptions (noFilter=
True)
349 config.setOptions (electrons=
'AnaElectrons.loose')
350 config.setOptions (photons=
'AnaPhotons.tight')
351 config.setOptions (muons=
'AnaMuons.medium')
352 config.setOptions (taus=
'AnaTauJets.tight')
353 config.setOptions (electronID=
'Tight')
354 config.setOptions (electronIsol=
'Tight_VarRad')
355 config.setOptions (photonIsol=
'TightCaloOnly')
356 config.setOptions (muonID=
'Tight')
357 config.setOptions (triggerMatchingChainsPerYear=triggerChainsPerYear)
361 exampleSelectionCuts = {
362 'SUBcommon':
"""JET_N_BTAG >= 2
367 'ejets':
"""IMPORT SUBcommon
374 'mujets':
"""IMPORT SUBcommon
376 MU_N medium 25000 > 0
380 config.addBlock (
'EventSelection')
381 config.setOptions (electrons=
'AnaElectrons.loose')
382 config.setOptions (muons=
'AnaMuons.medium')
383 config.setOptions (jets=
'AnaJets.baselineJvt')
384 config.setOptions (met=
'AnaMET')
385 config.setOptions (btagDecoration=
'ftag_select_ftag')
386 config.setOptions (noFilter=
True)
387 config.setOptions (cutFlowHistograms=
True)
388 config.setOptions (selectionCutsDict=exampleSelectionCuts)
391 config.addBlock (
'Bootstraps')
392 config.setOptions (nReplicas=2000)
393 config.setOptions (skipOnMC=
False)
396 config.addBlock (
'LeptonSF')
397 config.setOptions (muons=
'AnaMuons.medium')
398 config.setOptions (photons=
'AnaPhotons.tight')
399 config.setOptions (lepton_postfix=
'nominal')
404 'el_':
'OutElectrons',
405 'ph_' :
'OutPhotons',
406 'tau_':
'OutTauJets',
408 'larger_jet_':
'OutLargeRJets',
411 outputContainersForMC = {
'truth_mu_' :
'OutTruthMuons',
412 'truth_el_' :
'OutTruthElectrons',
413 'truth_ph_' :
'OutTruthPhotons',
414 'truth_tau_':
'OutTruthTaus',
415 'truth_jet_':
'OutTruthJets',
416 'truth_met_':
'TruthMET'}
417 config.addBlock (
'Output')
418 config.setOptions (treeName=
'analysis')
419 config.setOptions (vars=[
420 'EventInfo.actualInteractionsPerCrossing -> actualMuScaled',
422 config.setOptions (metVars=[
423 'AnaMET_%SYS%.met -> met_%SYS%',
425 config.setOptions (truthMetVars=[
426 'TruthMET_NOSYS.met -> truth_met',
428 config.setOptions (containers=outputContainers)
429 config.setOptions (containersOnlyForMC=outputContainersForMC)
430 config.setOptions (commands=[
431 "disable actualInteractionsPerCrossing",
435 configSeq = config.configure()
438 textConfig = TextConfig(yamlPath)
439 textConfigSeq = textConfig.configure()
447 Create a configSequence using provided YAML file and a
448 configSequence using the block configuration and compare.
450 Will raise an exception if configSequences differ
452 from AthenaConfiguration.Enums
import LHCPeriod
454 from AnalysisAlgorithmsConfig.FullCPAlgorithmsTest
import makeTestSequenceBlocks
456 geometry=LHCPeriod.Run2,
457 isPhyslite=
False, forceEGammaFullSimConfig=
True,
458 returnConfigSeq=
True)
461 from AnalysisAlgorithmsConfig.ConfigText
import TextConfig
462 textConfig = TextConfig(yamlPath)
463 textConfigSeq = textConfig.configure()
469 if __name__ ==
'__main__':
472 parser = optparse.OptionParser()
473 parser.add_option(
'--text-config', dest=
'text_config',
474 default=
'', action=
'store',
475 help=
'YAML file used in unit test')
476 parser.add_option(
'--compare-block', dest=
'compare_block',
477 default=
False, action=
'store_true',
478 help=
'Compare config sequence from YAML and block configuration')
479 parser.add_option(
'--compare-builder', dest=
'compare_builder',
480 default=
False, action=
'store_true',
481 help=
'Compare config sequence from YAML and python configuration')
482 parser.add_option(
'--check-order', dest=
'check_order',
483 default=
False, action=
'store_true',
484 help=
'Require blocks to be in the same order')
485 (options, args) = parser.parse_args()
486 textConfig = options.text_config
487 compareBlock = options.compare_block
488 compareBuilder = options.compare_builder
489 checkOrder = options.check_order
491 from PathResolver
import PathResolver
494 if not os.path.isfile(textConfig):
495 raise FileNotFoundError(f
"{textConfig} is not a file")
499 print(
"Comparing config sequences from the block and text"
500 "configuration methods")
504 print(
"Comparing config sequences from the block and block"
505 "configuration methods")