11 from basf2
import B2INFO, B2FATAL
14 import modularAnalysis
as ma
15 from variables
import utils
16 from ROOT
import Belle2
22 def getBelleOrBelle2():
24 Gets the global ModeCode.
32 def setInteractionWithDatabase(downloadFromDatabaseIfNotFound=False, uploadToDatabaseAfterTraining=False):
34 Sets the interaction with the database: download trained weight files or upload weight files after training.
40 downloadFlag = downloadFromDatabaseIfNotFound
41 uploadFlag = uploadToDatabaseAfterTraining
45 flavor_tagging = [
'FBDT_qrCombined',
'FANN_qrCombined',
'qrMC',
'mcFlavorOfOtherB',
46 'qpElectron',
'hasTrueTargetElectron',
'isRightCategoryElectron',
47 'qpIntermediateElectron',
'hasTrueTargetIntermediateElectron',
'isRightCategoryIntermediateElectron',
48 'qpMuon',
'hasTrueTargetMuon',
'isRightCategoryMuon',
49 'qpIntermediateMuon',
'hasTrueTargetIntermediateMuon',
'isRightCategoryIntermediateMuon',
50 'qpKinLepton',
'hasTrueTargetKinLepton',
'isRightCategoryKinLepton',
51 'qpIntermediateKinLepton',
'hasTrueTargetIntermediateKinLepton',
'isRightCategoryIntermediateKinLepton',
52 'qpKaon',
'hasTrueTargetKaon',
'isRightCategoryKaon',
53 'qpSlowPion',
'hasTrueTargetSlowPion',
'isRightCategorySlowPion',
54 'qpFastHadron',
'hasTrueTargetFastHadron',
'isRightCategoryFastHadron',
55 'qpLambda',
'hasTrueTargetLambda',
'isRightCategoryLambda',
56 'qpFSC',
'hasTrueTargetFSC',
'isRightCategoryFSC',
57 'qpMaximumPstar',
'hasTrueTargetMaximumPstar',
'isRightCategoryMaximumPstar',
58 'qpKaonPion',
'hasTrueTargetKaonPion',
'isRightCategoryKaonPion']
61 def add_default_FlavorTagger_aliases():
63 This function adds the default aliases for flavor tagging variables
64 and defines the collection of flavor tagging variables.
67 utils._variablemanager.addAlias(
'FBDT_qrCombined',
'qrOutput(FBDT)')
68 utils._variablemanager.addAlias(
'FANN_qrCombined',
'qrOutput(FANN)')
69 utils._variablemanager.addAlias(
'qrMC',
'isRelatedRestOfEventB0Flavor')
71 for iCategory
in AvailableCategories:
72 aliasForQp =
'qp' + iCategory
73 aliasForTrueTarget =
'hasTrueTarget' + iCategory
74 aliasForIsRightCategory =
'isRightCategory' + iCategory
75 utils._variablemanager.addAlias(aliasForQp,
'qpCategory(' + iCategory +
')')
76 utils._variablemanager.addAlias(aliasForTrueTarget,
'hasTrueTargets(' + iCategory +
')')
77 utils._variablemanager.addAlias(aliasForIsRightCategory,
'isTrueFTCategory(' + iCategory +
')')
79 utils.add_collection(flavor_tagging,
'flavor_tagging')
82 def set_FlavorTagger_pid_aliases():
84 This function adds the pid aliases needed by the flavor tagger.
86 utils._variablemanager.addAlias(
'eid_TOP',
'ifNANgiveX(pidPairProbabilityExpert(11, 211, TOP), 0.5)')
87 utils._variablemanager.addAlias(
'eid_ARICH',
'ifNANgiveX(pidPairProbabilityExpert(11, 211, ARICH), 0.5)')
88 utils._variablemanager.addAlias(
'eid_ECL',
'ifNANgiveX(pidPairProbabilityExpert(11, 211, ECL), 0.5)')
90 utils._variablemanager.addAlias(
'muid_TOP',
'ifNANgiveX(pidPairProbabilityExpert(13, 211, TOP), 0.5)')
91 utils._variablemanager.addAlias(
'muid_ARICH',
'ifNANgiveX(pidPairProbabilityExpert(13, 211, ARICH), 0.5)')
92 utils._variablemanager.addAlias(
'muid_KLM',
'ifNANgiveX(pidPairProbabilityExpert(13, 211, KLM), 0.5)')
94 utils._variablemanager.addAlias(
'piid_TOP',
'ifNANgiveX(pidPairProbabilityExpert(211, 321, TOP), 0.5)')
95 utils._variablemanager.addAlias(
'piid_ARICH',
'ifNANgiveX(pidPairProbabilityExpert(211, 321, ARICH), 0.5)')
97 utils._variablemanager.addAlias(
'Kid_TOP',
'ifNANgiveX(pidPairProbabilityExpert(321, 211, TOP), 0.5)')
98 utils._variablemanager.addAlias(
'Kid_ARICH',
'ifNANgiveX(pidPairProbabilityExpert(321, 211, ARICH), 0.5)')
100 if getBelleOrBelle2() ==
"Belle":
101 utils._variablemanager.addAlias(
'eid_dEdx',
'ifNANgiveX(pidPairProbabilityExpert(11, 211, CDC, SVD), 0.5)')
102 utils._variablemanager.addAlias(
'muid_dEdx',
'ifNANgiveX(pidPairProbabilityExpert(13, 211, CDC, SVD), 0.5)')
103 utils._variablemanager.addAlias(
'piid_dEdx',
'ifNANgiveX(pidPairProbabilityExpert(211, 321, CDC, SVD), 0.5)')
104 utils._variablemanager.addAlias(
'pi_vs_edEdxid',
'ifNANgiveX(pidPairProbabilityExpert(211, 11, CDC, SVD), 0.5)')
105 utils._variablemanager.addAlias(
'Kid_dEdx',
'ifNANgiveX(pidPairProbabilityExpert(321, 211, CDC, SVD), 0.5)')
108 utils._variablemanager.addAlias(
'eid_dEdx',
'ifNANgiveX(pidPairProbabilityExpert(11, 211, CDC), 0.5)')
109 utils._variablemanager.addAlias(
'muid_dEdx',
'ifNANgiveX(pidPairProbabilityExpert(13, 211, CDC), 0.5)')
110 utils._variablemanager.addAlias(
'piid_dEdx',
'ifNANgiveX(pidPairProbabilityExpert(211, 321, CDC), 0.5)')
111 utils._variablemanager.addAlias(
'pi_vs_edEdxid',
'ifNANgiveX(pidPairProbabilityExpert(211, 11, CDC), 0.5)')
112 utils._variablemanager.addAlias(
'Kid_dEdx',
'ifNANgiveX(pidPairProbabilityExpert(321, 211, CDC), 0.5)')
116 fastBDTCategories = basf2_mva.FastBDTOptions()
117 fastBDTCategories.m_nTrees = 500
118 fastBDTCategories.m_nCuts = 8
119 fastBDTCategories.m_nLevels = 3
120 fastBDTCategories.m_shrinkage = 0.10
121 fastBDTCategories.m_randRatio = 0.5
124 fastBDTCombiner = basf2_mva.FastBDTOptions()
125 fastBDTCombiner.m_nTrees = 500
126 fastBDTCombiner.m_nCuts = 8
127 fastBDTCombiner.m_nLevels = 3
128 fastBDTCombiner.m_shrinkage = 0.10
129 fastBDTCombiner.m_randRatio = 0.5
131 mlpFANNCombiner = basf2_mva.FANNOptions()
132 mlpFANNCombiner.m_max_epochs = 10000
133 mlpFANNCombiner.m_hidden_layers_architecture =
"3*N"
134 mlpFANNCombiner.m_hidden_activiation_function =
"FANN_SIGMOID_SYMMETRIC"
135 mlpFANNCombiner.m_output_activiation_function =
"FANN_SIGMOID_SYMMETRIC"
136 mlpFANNCombiner.m_error_function =
"FANN_ERRORFUNC_LINEAR"
137 mlpFANNCombiner.m_training_method =
"FANN_TRAIN_RPROP"
138 mlpFANNCombiner.m_validation_fraction = 0.5
139 mlpFANNCombiner.m_random_seeds = 10
140 mlpFANNCombiner.m_test_rate = 500
141 mlpFANNCombiner.m_number_of_threads = 8
142 mlpFANNCombiner.m_scale_features =
True
143 mlpFANNCombiner.m_scale_target =
False
157 AvailableCategories = {
162 'QpOf(e+:inRoe, isRightCategory(Electron), isRightCategory(Electron))',
164 'IntermediateElectron': [
166 'IntermediateElectron',
167 'IntermediateElectron',
168 'QpOf(e+:inRoe, isRightCategory(IntermediateElectron), isRightCategory(IntermediateElectron))',
174 'QpOf(mu+:inRoe, isRightCategory(Muon), isRightCategory(Muon))',
176 'IntermediateMuon': [
180 'QpOf(mu+:inRoe, isRightCategory(IntermediateMuon), isRightCategory(IntermediateMuon))',
186 'QpOf(mu+:inRoe, isRightCategory(KinLepton), isRightCategory(KinLepton))',
188 'IntermediateKinLepton': [
190 'IntermediateKinLepton',
191 'IntermediateKinLepton',
192 'QpOf(mu+:inRoe, isRightCategory(IntermediateKinLepton), isRightCategory(IntermediateKinLepton))',
198 'weightedQpOf(K+:inRoe, isRightCategory(Kaon), isRightCategory(Kaon))',
204 'QpOf(pi+:inRoe, isRightCategory(SlowPion), isRightCategory(SlowPion))',
210 'QpOf(pi+:inRoe, isRightCategory(FastHadron), isRightCategory(FastHadron))',
216 'weightedQpOf(Lambda0:inRoe, isRightCategory(Lambda), isRightCategory(Lambda))',
222 'QpOf(pi+:inRoe, isRightCategory(FSC), isRightCategory(SlowPion))',
228 'QpOf(pi+:inRoe, isRightCategory(MaximumPstar), isRightCategory(MaximumPstar))',
234 'QpOf(K+:inRoe, isRightCategory(KaonPion), isRightCategory(Kaon))',
239 trackLevelParticleLists = []
240 eventLevelParticleLists = []
241 variablesCombinerLevel = []
244 def WhichCategories(categories=[
257 Selection of the Categories that are going to be used.
260 if len(categories) > 13
or len(categories) < 2:
261 B2FATAL(
'Flavor Tagger: Invalid amount of categories. At least two are needed. No more than 13 are available'
264 'Flavor Tagger: Possible categories are "Electron", "IntermediateElectron", "Muon", "IntermediateMuon", '
265 '"KinLepton", "IntermediateKinLepton", "Kaon", "SlowPion", "FastHadron",'
266 '"Lambda", "FSC", "MaximumPstar" or "KaonPion" ')
267 categoriesCombination = []
268 for category
in categories:
269 if category
in AvailableCategories:
270 if category !=
'MaximumPstar' and (AvailableCategories[category][0],
271 AvailableCategories[category][1]) \
272 not in trackLevelParticleLists:
273 trackLevelParticleLists.append((AvailableCategories[category][0],
274 AvailableCategories[category][1]))
275 if (AvailableCategories[category][0],
276 AvailableCategories[category][2], AvailableCategories[category][3]) \
277 not in eventLevelParticleLists:
278 eventLevelParticleLists.append((AvailableCategories[category][0],
279 AvailableCategories[category][2], AvailableCategories[category][3]))
280 variablesCombinerLevel.append(AvailableCategories[category][3])
281 categoriesCombination.append(AvailableCategories[category][4])
283 B2FATAL(
'Flavor Tagger: ' + category +
' has been already given')
285 B2FATAL(
'Flavor Tagger: ' + category +
' is not a valid category name given')
286 B2FATAL(
'Flavor Tagger: Available categories are "Electron", "IntermediateElectron", '
287 '"Muon", "IntermediateMuon", "KinLepton", "IntermediateKinLepton", "Kaon", "SlowPion", "FastHadron", '
288 '"Lambda", "FSC", "MaximumPstar" or "KaonPion" ')
289 global categoriesCombinationCode
290 categoriesCombinationCode =
'CatCode'
291 for code
in sorted(categoriesCombination):
292 categoriesCombinationCode = categoriesCombinationCode +
'%02d' % code
297 KId = {
'Belle':
'ifNANgiveX(atcPIDBelle(3,2), 0.5)',
'Belle2':
'kaonID'}
298 muId = {
'Belle':
'muIDBelle',
'Belle2':
'muonID'}
299 eId = {
'Belle':
'eIDBelle',
'Belle2':
'electronID'}
304 Sets the Variables used for Track and Event Levels.
307 variables[
'Electron'] = [
313 eId[getBelleOrBelle2()],
317 'BtagToWBosonVariables(recoilMassSqrd)',
318 'BtagToWBosonVariables(pMissCMS)',
319 'BtagToWBosonVariables(cosThetaMissCMS)',
320 'BtagToWBosonVariables(EW90)',
324 variables[
'IntermediateElectron'] = variables[
'Electron']
325 variables[
'Muon'] = [
331 muId[getBelleOrBelle2()],
335 'BtagToWBosonVariables(recoilMassSqrd)',
336 'BtagToWBosonVariables(pMissCMS)',
337 'BtagToWBosonVariables(cosThetaMissCMS)',
338 'BtagToWBosonVariables(EW90)',
341 variables[
'IntermediateMuon'] = [
347 muId[getBelleOrBelle2()],
351 'BtagToWBosonVariables(recoilMassSqrd)',
352 'BtagToWBosonVariables(pMissCMS)',
353 'BtagToWBosonVariables(cosThetaMissCMS)',
354 'BtagToWBosonVariables(EW90)',
358 variables[
'KinLepton'] = [
364 muId[getBelleOrBelle2()],
368 eId[getBelleOrBelle2()],
372 'BtagToWBosonVariables(recoilMassSqrd)',
373 'BtagToWBosonVariables(pMissCMS)',
374 'BtagToWBosonVariables(cosThetaMissCMS)',
375 'BtagToWBosonVariables(EW90)',
378 variables[
'IntermediateKinLepton'] = [
384 muId[getBelleOrBelle2()],
388 eId[getBelleOrBelle2()],
392 'BtagToWBosonVariables(recoilMassSqrd)',
393 'BtagToWBosonVariables(pMissCMS)',
394 'BtagToWBosonVariables(cosThetaMissCMS)',
395 'BtagToWBosonVariables(EW90)',
399 variables[
'Kaon'] = [
405 KId[getBelleOrBelle2()],
409 'NumberOfKShortsInRoe',
411 'BtagToWBosonVariables(recoilMassSqrd)',
412 'BtagToWBosonVariables(pMissCMS)',
413 'BtagToWBosonVariables(cosThetaMissCMS)',
414 'BtagToWBosonVariables(EW90)',
418 variables[
'SlowPion'] = [
428 KId[getBelleOrBelle2()],
432 'NumberOfKShortsInRoe',
434 eId[getBelleOrBelle2()],
435 'BtagToWBosonVariables(recoilMassSqrd)',
436 'BtagToWBosonVariables(EW90)',
437 'BtagToWBosonVariables(cosThetaMissCMS)',
438 'BtagToWBosonVariables(pMissCMS)',
441 variables[
'FastHadron'] = [
452 KId[getBelleOrBelle2()],
456 'NumberOfKShortsInRoe',
458 eId[getBelleOrBelle2()],
459 'BtagToWBosonVariables(recoilMassSqrd)',
460 'BtagToWBosonVariables(EW90)',
461 'BtagToWBosonVariables(cosThetaMissCMS)',
464 variables[
'Lambda'] = [
466 'NumberOfKShortsInRoe',
468 'cosAngleBetweenMomentumAndVertexVector',
471 'daughter(0,useCMSFrame(p))',
473 'daughter(1,useCMSFrame(p))',
478 variables[
'MaximumPstar'] = [
488 KId[getBelleOrBelle2()],
489 'FSCVariables(pFastCMS)',
490 'FSCVariables(cosSlowFast)',
491 'FSCVariables(cosTPTOFast)',
492 'FSCVariables(SlowFastHaveOpositeCharges)',
496 variables[
'KaonPion'] = [
'extraInfo(isRightCategory(Kaon))',
497 'HighestProbInCat(pi+:inRoe, isRightCategory(SlowPion))',
498 'KaonPionVariables(cosKaonPion)',
'KaonPionVariables(HaveOpositeCharges)', KId[getBelleOrBelle2()]]
501 if getBelleOrBelle2() ==
"Belle2":
502 variables[
'Lambda'].append(
'daughter(1,protonID)')
503 variables[
'Lambda'].append(
'daughter(0,pionID)')
508 variables[
'Electron'].append(
'eid_dEdx')
509 variables[
'Electron'].append(
'ImpactXY')
510 variables[
'Electron'].append(
'distance')
512 variables[
'IntermediateElectron'].append(
'eid_dEdx')
513 variables[
'IntermediateElectron'].append(
'ImpactXY')
514 variables[
'IntermediateElectron'].append(
'distance')
516 variables[
'Muon'].append(
'muid_dEdx')
517 variables[
'Muon'].append(
'ImpactXY')
518 variables[
'Muon'].append(
'distance')
519 variables[
'Muon'].append(
'chiProb')
521 variables[
'IntermediateMuon'].append(
'muid_dEdx')
522 variables[
'IntermediateMuon'].append(
'ImpactXY')
523 variables[
'IntermediateMuon'].append(
'distance')
525 variables[
'KinLepton'].append(
'muid_dEdx')
526 variables[
'KinLepton'].append(
'eid_dEdx')
527 variables[
'KinLepton'].append(
'ImpactXY')
528 variables[
'KinLepton'].append(
'distance')
529 variables[
'KinLepton'].append(
'chiProb')
531 variables[
'IntermediateKinLepton'].append(
'muid_dEdx')
532 variables[
'IntermediateKinLepton'].append(
'eid_dEdx')
533 variables[
'IntermediateKinLepton'].append(
'ImpactXY')
534 variables[
'IntermediateKinLepton'].append(
'distance')
536 variables[
'Kaon'].append(
'ImpactXY')
537 variables[
'Kaon'].append(
'distance')
539 variables[
'SlowPion'].append(
'piid_dEdx')
540 variables[
'SlowPion'].append(
'ImpactXY')
541 variables[
'SlowPion'].append(
'distance')
542 variables[
'SlowPion'].append(
'chiProb')
544 variables[
'FastHadron'].append(
'BtagToWBosonVariables(pMissCMS)')
545 variables[
'FastHadron'].append(
'ImpactXY')
546 variables[
'FastHadron'].append(
'distance')
547 variables[
'FastHadron'].append(
'chiProb')
549 variables[
'Lambda'].append(
'distance')
551 variables[
'MaximumPstar'].append(
'ImpactXY')
552 variables[
'MaximumPstar'].append(
'distance')
555 def FillParticleLists(mode='Expert', maskName='', path=None):
557 Fills the particle Lists for all categories.
560 from vertex
import kFit
561 readyParticleLists = []
563 for (particleList, category)
in trackLevelParticleLists:
565 if particleList
in readyParticleLists:
569 if particleList !=
'Lambda0:inRoe' and particleList !=
'K+:inRoe' and particleList !=
'pi+:inRoe':
572 ma.fillParticleList(particleList,
'isInRestOfEvent > 0.5 and passesROEMask(' + maskName +
') > 0.5 and ' +
573 'isNAN(p) !=1 and isInfinity(p) != 1', path=path)
574 readyParticleLists.append(particleList)
577 if 'pi+:inRoe' not in readyParticleLists:
579 'pi+:inRoe',
'isInRestOfEvent > 0.5 and passesROEMask(' + maskName +
') > 0.5 and ' +
580 'isNAN(p) !=1 and isInfinity(p) != 1', path=path)
581 readyParticleLists.append(
'pi+:inRoe')
583 if 'K_S0:inRoe' not in readyParticleLists:
584 if getBelleOrBelle2() ==
'Belle':
585 ma.cutAndCopyList(
'K_S0:inRoe',
'K_S0:mdst',
'extraInfo(ksnbStandard) == 1 and isInRestOfEvent == 1', path=path)
587 ma.reconstructDecay(
'K_S0:inRoe -> pi+:inRoe pi-:inRoe',
'0.40<=M<=0.60',
False, path=path)
588 kFit(
'K_S0:inRoe', 0.01, path=path)
589 readyParticleLists.append(
'K_S0:inRoe')
591 if particleList ==
'K+:inRoe':
593 particleList,
'isInRestOfEvent > 0.5 and passesROEMask(' + maskName +
') > 0.5 and ' +
594 'isNAN(p) !=1 and isInfinity(p) != 1', path=path)
597 readyParticleLists.append(particleList)
599 if particleList ==
'Lambda0:inRoe':
601 'p+:inRoe',
'isInRestOfEvent > 0.5 and passesROEMask(' + maskName +
') > 0.5 and ' +
602 'isNAN(p) !=1 and isInfinity(p) != 1', path=path)
603 ma.reconstructDecay(particleList +
' -> pi-:inRoe p+:inRoe',
'1.00<=M<=1.23',
False, path=path)
604 kFit(particleList, 0.01, path=path)
606 ma.matchMCTruth(particleList, path=path)
607 readyParticleLists.append(particleList)
612 def eventLevel(mode='Expert', weightFiles='B2JpsiKs_mu', path=None):
614 Samples data for training or tests all categories all categories at event level.
617 from basf2
import create_path
618 from basf2
import register_module
620 B2INFO(
'EVENT LEVEL')
625 identifiersExtraInfosDict = dict()
626 identifiersExtraInfosKaonPion = []
628 for (particleList, category, combinerVariable)
in eventLevelParticleLists:
630 methodPrefixEventLevel =
"FlavorTagger_" + getBelleOrBelle2() +
"_" + weightFiles +
'EventLevel' + category +
'FBDT'
631 identifierEventLevel = methodPrefixEventLevel
632 targetVariable =
'isRightCategory(' + category +
')'
633 extraInfoName = targetVariable
637 if downloadFlag
or useOnlyLocalFlag:
638 identifierEventLevel = filesDirectory +
'/' + methodPrefixEventLevel +
'_1.root'
639 if not os.path.isfile(identifierEventLevel):
641 basf2_mva.download(methodPrefixEventLevel, identifierEventLevel)
642 if not os.path.isfile(identifierEventLevel):
643 B2FATAL(
'Flavor Tagger: Weight file ' + identifierEventLevel +
644 ' was not downloaded from Database. Please check the buildOrRevision name. Stopped')
647 'Flavor Tagger: ' + particleList +
' Eventlevel was not trained. Weight file ' +
648 identifierEventLevel +
' was not found. Stopped')
651 B2INFO(
'flavorTagger: MVAExpert ' + methodPrefixEventLevel +
' ready.')
653 elif mode ==
'Sampler':
655 identifierEventLevel = filesDirectory +
'/' + methodPrefixEventLevel +
'_1.root'
656 if os.path.isfile(identifierEventLevel):
657 B2INFO(
'flavorTagger: MVAExpert ' + methodPrefixEventLevel +
' ready.')
659 if 'KaonPion' in [row[1]
for row
in eventLevelParticleLists]:
660 methodPrefixEventLevelKaonPion =
"FlavorTagger_" + getBelleOrBelle2() + \
661 "_" + weightFiles +
'EventLevelKaonPionFBDT'
662 identifierEventLevelKaonPion = filesDirectory +
'/' + methodPrefixEventLevelKaonPion +
'_1.root'
663 if not os.path.isfile(identifierEventLevelKaonPion):
666 if category !=
"SlowPion" and category !=
"Kaon":
669 if mode ==
'Expert' or (mode ==
'Sampler' and os.path.isfile(identifierEventLevel)):
671 B2INFO(
'flavorTagger: Applying MVAExpert ' + methodPrefixEventLevel +
'.')
673 if particleList
not in identifiersExtraInfosDict
and category !=
'KaonPion':
674 identifiersExtraInfosDict[particleList] = [(extraInfoName, identifierEventLevel)]
675 elif category !=
'KaonPion':
676 identifiersExtraInfosDict[particleList].append((extraInfoName, identifierEventLevel))
678 identifiersExtraInfosKaonPion.append((extraInfoName, identifierEventLevel))
683 for particleList
in identifiersExtraInfosDict:
684 eventLevelPath = create_path()
685 SkipEmptyParticleList = register_module(
"SkimFilter")
686 SkipEmptyParticleList.set_name(
'SkimFilter_EventLevel_' + particleList)
687 SkipEmptyParticleList.param(
'particleLists', particleList)
688 SkipEmptyParticleList.if_true(eventLevelPath, basf2.AfterConditionPath.CONTINUE)
689 path.add_module(SkipEmptyParticleList)
691 mvaMultipleExperts = register_module(
'MVAMultipleExperts')
692 mvaMultipleExperts.set_name(
'MVAMultipleExperts_EventLevel_' + particleList)
693 mvaMultipleExperts.param(
'listNames', [particleList])
694 mvaMultipleExperts.param(
'extraInfoNames', [row[0]
for row
in identifiersExtraInfosDict[particleList]])
695 mvaMultipleExperts.param(
'signalFraction', signalFraction)
696 mvaMultipleExperts.param(
'identifiers', [row[1]
for row
in identifiersExtraInfosDict[particleList]])
697 eventLevelPath.add_module(mvaMultipleExperts)
699 if 'KaonPion' in [row[1]
for row
in eventLevelParticleLists]
and len(identifiersExtraInfosKaonPion) != 0:
700 eventLevelKaonPionPath = create_path()
701 SkipEmptyParticleList = register_module(
"SkimFilter")
702 SkipEmptyParticleList.set_name(
'SkimFilter_' +
'K+:inRoe')
703 SkipEmptyParticleList.param(
'particleLists',
'K+:inRoe')
704 SkipEmptyParticleList.if_true(eventLevelKaonPionPath, basf2.AfterConditionPath.CONTINUE)
705 path.add_module(SkipEmptyParticleList)
707 mvaExpertKaonPion = register_module(
"MVAExpert")
708 mvaExpertKaonPion.set_name(
'MVAExpert_KaonPion_' +
'K+:inRoe')
709 mvaExpertKaonPion.param(
'listNames', [
'K+:inRoe'])
710 mvaExpertKaonPion.param(
'extraInfoName', identifiersExtraInfosKaonPion[0][0])
711 mvaExpertKaonPion.param(
'signalFraction', signalFraction)
712 mvaExpertKaonPion.param(
'identifier', identifiersExtraInfosKaonPion[0][1])
714 eventLevelKaonPionPath.add_module(mvaExpertKaonPion)
716 for (particleList, category, combinerVariable)
in eventLevelParticleLists:
718 methodPrefixEventLevel =
"FlavorTagger_" + getBelleOrBelle2() +
"_" + weightFiles +
'EventLevel' + category +
'FBDT'
719 identifierEventLevel = filesDirectory +
'/' + methodPrefixEventLevel +
'_1.root'
720 targetVariable =
'isRightCategory(' + category +
')'
722 if not os.path.isfile(identifierEventLevel)
and mode ==
'Sampler':
724 if category ==
'KaonPion':
725 methodPrefixEventLevelSlowPion =
"FlavorTagger_" + getBelleOrBelle2() +
"_" + weightFiles +
'EventLevelSlowPionFBDT'
726 identifierEventLevelSlowPion = filesDirectory +
'/' + methodPrefixEventLevelSlowPion +
'_1.root'
727 if not os.path.isfile(identifierEventLevelSlowPion):
728 B2INFO(
"Flavor Tagger: event level weight file for the Slow Pion category is absent." +
729 "It is required to sample the training information for the KaonPion category." +
730 "An additional sampling step will be needed after the following training step.")
734 'flavorTagger: file ' + filesDirectory +
'/' +
735 methodPrefixEventLevel +
"sampled" + fileId +
'.root will be saved.')
737 ma.applyCuts(particleList,
'isRightCategory(mcAssociated) > 0', path)
738 eventLevelpath = create_path()
739 SkipEmptyParticleList = register_module(
"SkimFilter")
740 SkipEmptyParticleList.set_name(
'SkimFilter_EventLevel' + category)
741 SkipEmptyParticleList.param(
'particleLists', particleList)
742 SkipEmptyParticleList.if_true(eventLevelpath, basf2.AfterConditionPath.CONTINUE)
743 path.add_module(SkipEmptyParticleList)
745 ntuple = register_module(
'VariablesToNtuple')
746 ntuple.param(
'fileName', filesDirectory +
'/' + methodPrefixEventLevel +
"sampled" + fileId +
".root")
747 ntuple.param(
'treeName', methodPrefixEventLevel +
"_tree")
748 variablesToBeSaved = variables[category] + [targetVariable,
'ancestorHasWhichFlavor',
749 'isSignal',
'mcPDG',
'mcErrors',
'genMotherPDG',
750 'nMCMatches',
'B0mcErrors']
751 if category !=
'KaonPion' and category !=
'FSC':
752 variablesToBeSaved = variablesToBeSaved + \
753 [
'extraInfo(isRightTrack(' + category +
'))',
754 'hasHighestProbInCat(' + particleList +
', isRightTrack(' + category +
'))']
755 ntuple.param(
'variables', variablesToBeSaved)
756 ntuple.param(
'particleList', particleList)
757 eventLevelpath.add_module(ntuple)
759 if ReadyMethods != len(eventLevelParticleLists):
765 def eventLevelTeacher(weightFiles='B2JpsiKs_mu'):
767 Trains all categories at event level.
770 B2INFO(
'EVENT LEVEL TEACHER')
774 for (particleList, category, combinerVariable)
in eventLevelParticleLists:
776 methodPrefixEventLevel =
"FlavorTagger_" + getBelleOrBelle2() +
"_" + weightFiles +
'EventLevel' + category +
'FBDT'
777 targetVariable =
'isRightCategory(' + category +
')'
778 weightFile = filesDirectory +
'/' + methodPrefixEventLevel +
"_1.root"
780 if not os.path.isfile(weightFile):
782 sampledFilesList = glob.glob(filesDirectory +
'/' + methodPrefixEventLevel +
'sampled*.root')
783 if len(sampledFilesList) == 0:
785 B2INFO(
'flavorTagger: eventLevelTeacher did not find any ' + methodPrefixEventLevel +
786 ".root" +
' file. Please run the flavorTagger in "Sampler" mode afterwards.')
790 B2INFO(
'flavorTagger: MVA Teacher training' + methodPrefixEventLevel +
' .')
791 trainingOptionsEventLevel = basf2_mva.GeneralOptions()
792 trainingOptionsEventLevel.m_datafiles = basf2_mva.vector(*sampledFilesList)
793 trainingOptionsEventLevel.m_treename = methodPrefixEventLevel +
"_tree"
794 trainingOptionsEventLevel.m_identifier = weightFile
795 trainingOptionsEventLevel.m_variables = basf2_mva.vector(*variables[category])
796 trainingOptionsEventLevel.m_target_variable = targetVariable
797 trainingOptionsEventLevel.m_max_events = maxEventsNumber
799 basf2_mva.teacher(trainingOptionsEventLevel, fastBDTCategories)
802 basf2_mva.upload(weightFile, methodPrefixEventLevel)
808 if ReadyMethods != len(eventLevelParticleLists):
814 def combinerLevel(mode='Expert', weightFiles='B2JpsiKs_mu', path=None):
816 Samples the input data or tests the combiner according to the selected categories.
819 B2INFO(
'COMBINER LEVEL')
821 B2INFO(
"Flavor Tagger: Required Combiner for Categories:")
822 for (particleList, category, combinerVariable)
in eventLevelParticleLists:
825 B2INFO(
"Flavor Tagger: which corresponds to a weight file with categories combination code " + categoriesCombinationCode)
827 methodPrefixCombinerLevel =
"FlavorTagger_" + getBelleOrBelle2() +
"_" + weightFiles +
'Combiner' \
828 + categoriesCombinationCode
830 if mode ==
'Sampler':
834 filesDirectory +
'/' + methodPrefixCombinerLevel +
'FBDT' +
'_1.root')
or os.path.isfile(
835 filesDirectory +
'/' + methodPrefixCombinerLevel +
'FANN' +
'_1.root')):
836 B2INFO(
'flavorTagger: Sampling Data on Combiner Level. File' +
837 methodPrefixCombinerLevel +
".root" +
' will be saved')
839 ntuple = basf2.register_module(
'VariablesToNtuple')
840 ntuple.param(
'fileName', filesDirectory +
'/' + methodPrefixCombinerLevel +
"sampled" + fileId +
".root")
841 ntuple.param(
'treeName', methodPrefixCombinerLevel +
'FBDT' +
"_tree")
842 ntuple.param(
'variables', variablesCombinerLevel + [
'qrCombined'])
843 ntuple.param(
'particleList',
"")
844 path.add_module(ntuple)
849 B2FATAL(
'flavorTagger: File' + methodPrefixCombinerLevel +
'FBDT' +
"_1.root" +
' or ' + methodPrefixCombinerLevel +
850 'FANN' +
'_1.root found. Please run the "Expert" mode or delete the file if a new sampling is desired.')
854 if TMVAfbdt
and not FANNmlp:
856 identifier = methodPrefixCombinerLevel +
'FBDT'
858 if downloadFlag
or useOnlyLocalFlag:
860 identifier = filesDirectory +
'/' + methodPrefixCombinerLevel +
'FBDT' +
'_1.root'
861 if not os.path.isfile(identifier):
863 basf2_mva.download(methodPrefixCombinerLevel +
'FBDT', identifier)
864 if not os.path.isfile(identifier):
865 B2FATAL(
'Flavor Tagger: Weight file ' + methodPrefixCombinerLevel +
'FBDT' +
866 '_1.root was not downloaded from Database. Please check the buildOrRevision name. Stopped')
869 'flavorTagger: Combinerlevel FastBDT was not trained with this combination of categories.' +
870 ' Weight file ' + methodPrefixCombinerLevel +
'FBDT' +
'_1.root not found. Stopped')
872 B2INFO(
'flavorTagger: Ready to be used with weightFile ' + methodPrefixCombinerLevel +
'FBDT' +
'_1.root')
874 B2INFO(
'flavorTagger: Apply FBDTMethod ' + methodPrefixCombinerLevel +
'FBDT')
875 path.add_module(
'MVAExpert', listNames=[], extraInfoName=
'qrCombined' +
'FBDT', signalFraction=signalFraction,
876 identifier=identifier)
879 if FANNmlp
and not TMVAfbdt:
881 identifier = methodPrefixCombinerLevel +
'FANN'
883 if downloadFlag
or useOnlyLocalFlag:
884 identifier = filesDirectory +
'/' + methodPrefixCombinerLevel +
'FANN' +
'_1.root'
886 if not os.path.isfile(identifier):
888 basf2_mva.download(methodPrefixCombinerLevel +
'FANN', identifier)
889 if not os.path.isfile(identifier):
890 B2FATAL(
'Flavor Tagger: Weight file ' + methodPrefixCombinerLevel +
'FANN' +
891 '_1.root was not downloaded from Database. Please check the buildOrRevision name. Stopped')
894 'flavorTagger: Combinerlevel FANNMLP was not trained with this combination of categories. ' +
895 ' Weight file ' + methodPrefixCombinerLevel +
'FANN' +
'_1.root not found. Stopped')
897 B2INFO(
'flavorTagger: Ready to be used with weightFile ' + methodPrefixCombinerLevel +
'FANN' +
'_1.root')
899 B2INFO(
'flavorTagger: Apply FANNMethod on combiner level')
900 path.add_module(
'MVAExpert', listNames=[], extraInfoName=
'qrCombined' +
'FANN', signalFraction=signalFraction,
901 identifier=identifier)
904 if FANNmlp
and TMVAfbdt:
906 identifierFBDT = methodPrefixCombinerLevel +
'FBDT'
907 identifierFANN = methodPrefixCombinerLevel +
'FANN'
909 if downloadFlag
or useOnlyLocalFlag:
910 identifierFBDT = filesDirectory +
'/' + methodPrefixCombinerLevel +
'FBDT' +
'_1.root'
911 identifierFANN = filesDirectory +
'/' + methodPrefixCombinerLevel +
'FANN' +
'_1.root'
913 if not os.path.isfile(identifierFBDT):
915 basf2_mva.download(methodPrefixCombinerLevel +
'FBDT', identifierFBDT)
916 if not os.path.isfile(identifierFBDT):
917 B2FATAL(
'Flavor Tagger: Weight file ' + methodPrefixCombinerLevel +
'FBDT' +
918 '_1.root was not downloaded from Database. Please check the buildOrRevision name. Stopped')
921 'flavorTagger: Combinerlevel FastBDT was not trained with this combination of categories. ' +
922 'Weight file ' + methodPrefixCombinerLevel +
'FBDT' +
'_1.root not found. Stopped')
924 if not os.path.isfile(identifierFANN):
926 basf2_mva.download(methodPrefixCombinerLevel +
'FANN', identifierFANN)
927 if not os.path.isfile(identifierFANN):
928 B2FATAL(
'Flavor Tagger: Weight file ' + methodPrefixCombinerLevel +
'FANN' +
929 '_1.root was not downloaded from Database. Please check the buildOrRevision name. Stopped')
932 'flavorTagger: Combinerlevel FANNMLP was not trained with this combination of categories. ' +
933 'Weight file ' + methodPrefixCombinerLevel +
'FANN' +
'_1.root not found. Stopped')
935 if os.path.isfile(identifierFBDT)
and os.path.isfile(identifierFANN):
936 B2INFO(
'flavorTagger: Ready to be used with weightFiles ' + methodPrefixCombinerLevel +
937 'FBDT' +
'_1.root and ' + methodPrefixCombinerLevel +
'FANN' +
'_1.root')
939 B2INFO(
'flavorTagger: Apply FANNMethod and FBDTMethod on combiner level')
941 mvaMultipleExperts = basf2.register_module(
'MVAMultipleExperts')
942 mvaMultipleExperts.set_name(
'MVAMultipleExperts_Combiners')
943 mvaMultipleExperts.param(
'listNames', [])
944 mvaMultipleExperts.param(
'extraInfoNames', [
'qrCombined' +
'FBDT',
'qrCombined' +
'FANN'])
945 mvaMultipleExperts.param(
'signalFraction', signalFraction)
946 mvaMultipleExperts.param(
'identifiers', [identifierFBDT, identifierFANN])
947 path.add_module(mvaMultipleExperts)
952 def combinerLevelTeacher(weightFiles='B2JpsiKs_mu'):
954 Trains the combiner according to the selected categories.
957 B2INFO(
'COMBINER LEVEL TEACHER')
959 methodPrefixCombinerLevel =
"FlavorTagger_" + getBelleOrBelle2() +
"_" + weightFiles +
'Combiner' \
960 + categoriesCombinationCode
962 sampledFilesList = glob.glob(filesDirectory +
'/' + methodPrefixCombinerLevel +
'sampled*.root')
963 if len(sampledFilesList) == 0:
964 B2FATAL(
'FlavorTagger: combinerLevelTeacher did not find any ' +
965 methodPrefixCombinerLevel +
'sampled*.root file. Please run the flavorTagger in "Sampler" mode.')
967 ReadyTMVAfbdt =
False
972 if not os.path.isfile(filesDirectory +
'/' + methodPrefixCombinerLevel +
'FBDT' +
'_1.root'):
974 B2INFO(
'flavorTagger: MVA Teacher training a FastBDT on Combiner Level')
976 trainingOptionsCombinerLevel = basf2_mva.GeneralOptions()
977 trainingOptionsCombinerLevel.m_datafiles = basf2_mva.vector(*sampledFilesList)
978 trainingOptionsCombinerLevel.m_treename = methodPrefixCombinerLevel +
'FBDT' +
"_tree"
979 trainingOptionsCombinerLevel.m_identifier = filesDirectory +
'/' + methodPrefixCombinerLevel +
'FBDT' +
"_1.root"
980 trainingOptionsCombinerLevel.m_variables = basf2_mva.vector(*variablesCombinerLevel)
981 trainingOptionsCombinerLevel.m_target_variable =
'qrCombined'
982 trainingOptionsCombinerLevel.m_max_events = maxEventsNumber
984 basf2_mva.teacher(trainingOptionsCombinerLevel, fastBDTCombiner)
987 basf2_mva.upload(filesDirectory +
'/' + methodPrefixCombinerLevel +
988 'FBDT' +
"_1.root", methodPrefixCombinerLevel +
'FBDT')
990 elif FANNmlp
and not os.path.isfile(filesDirectory +
'/' + methodPrefixCombinerLevel +
'FANN' +
'_1.root'):
992 B2INFO(
'flavorTagger: Combinerlevel FBDT was already trained with this combination of categories. Weight file ' +
993 methodPrefixCombinerLevel +
'FBDT' +
'_1.root has been found.')
996 B2FATAL(
'flavorTagger: Combinerlevel was already trained with this combination of categories. Weight files ' +
997 methodPrefixCombinerLevel +
'FBDT' +
'_1.root and ' +
998 methodPrefixCombinerLevel +
'FANN' +
'_1.root has been found. Please use the "Expert" mode')
1002 if not os.path.isfile(filesDirectory +
'/' + methodPrefixCombinerLevel +
'FANN' +
'_1.root'):
1004 B2INFO(
'flavorTagger: MVA Teacher training a FANN MLP on Combiner Level')
1006 trainingOptionsCombinerLevel = basf2_mva.GeneralOptions()
1007 trainingOptionsCombinerLevel.m_datafiles = basf2_mva.vector(*sampledFilesList)
1008 trainingOptionsCombinerLevel.m_treename = methodPrefixCombinerLevel +
'FBDT' +
"_tree"
1009 trainingOptionsCombinerLevel.m_identifier = filesDirectory +
'/' + methodPrefixCombinerLevel +
'FANN' +
"_1.root"
1010 trainingOptionsCombinerLevel.m_variables = basf2_mva.vector(*variablesCombinerLevel)
1011 trainingOptionsCombinerLevel.m_target_variable =
'qrCombined'
1012 trainingOptionsCombinerLevel.m_max_events = maxEventsNumber
1014 basf2_mva.teacher(trainingOptionsCombinerLevel, mlpFANNCombiner)
1017 basf2_mva.upload(filesDirectory +
'/' + methodPrefixCombinerLevel +
1018 'FANN' +
"_1.root", methodPrefixCombinerLevel +
'FANN')
1020 elif TMVAfbdt
and not os.path.isfile(filesDirectory +
'/' + methodPrefixCombinerLevel +
'FBDT' +
'_1.root'):
1022 B2INFO(
'flavorTagger: Combinerlevel FBDT was already trained with this combination of categories. Weight file ' +
1023 methodPrefixCombinerLevel +
'FANN' +
'_1.config has been found.')
1026 B2FATAL(
'flavorTagger: Combinerlevel was already trained with this combination of categories. Weight files ' +
1027 methodPrefixCombinerLevel +
'FBDT' +
'_1.root and ' +
1028 methodPrefixCombinerLevel +
'FANN' +
'_1.root has been found. Please use the "Expert" mode')
1034 weightFiles='B2nunubarBGx1',
1035 workingDirectory='.',
1036 combinerMethods=['TMVA-FBDT', 'FANN-MLP'],
1039 'IntermediateElectron',
1043 'IntermediateKinLepton',
1052 saveCategoriesInfo=True,
1053 useOnlyLocalWeightFiles=False,
1054 downloadFromDatabaseIfNotFound=False,
1055 uploadToDatabaseAfterTraining=False,
1060 Defines the whole flavor tagging process for each selected Rest of Event (ROE) built in the steering file.
1061 The flavor is predicted by Multivariate Methods trained with Variables and MetaVariables which use
1062 Tracks, ECL- and KLMClusters from the corresponding RestOfEvent dataobject.
1063 This module can be used to sample the training information, to train and/or to test the flavorTagger.
1065 @param particleLists The ROEs for flavor tagging are selected from the given particle lists.
1066 @param mode The available modes are
1067 ``Expert`` (default), ``Sampler``, and ``Teacher``. In the ``Expert`` mode
1068 Flavor Tagging is applied to the analysis,. In the ``Sampler`` mode you save
1069 save the variables for training. In the ``Teacher`` mode the FlavorTagger is
1070 trained, for this step you do not reconstruct any particle or do any analysis,
1071 you just run the flavorTagger alone.
1072 @param weightFiles Weight files name. Default=
1073 ``B2nunubarBGx1`` (official weight files). If the user self
1074 wants to train the FlavorTagger, the weightfiles name should correspond to the
1075 analysed CP channel in order to avoid confusions. The default name
1076 ``B2nunubarBGx1`` corresponds to
1077 :math:`B^0_{\\rm sig}\\to \\nu \\overline{\\nu}`.
1078 and ``B2JpsiKs_muBGx1`` to
1079 :math:`B^0_{\\rm sig}\\to J/\\psi (\\to \\mu^+ \\mu^-) K_s (\\to \\pi^+ \\pi^-)`.
1080 BGx1 stays for events simulated with background.
1081 @param workingDirectory Path to the directory containing the FlavorTagging/ folder.
1082 @param combinerMethods MVAs for the combiner: ``TMVA-FBDT`` or ``FANN-MLP``. Both used by default.
1083 @param categories Categories used for flavor tagging. By default all are used.
1084 @param maskName Gets ROE particles from a specified ROE mask.
1085 @param saveCategoriesInfo Sets to save information of individual categories.
1086 @param useOnlyLocalWeightFiles [Expert] Uses only locally saved weight files.
1087 @param downloadFromDatabaseIfNotFound [Expert] Weight files are downloaded from
1088 the conditions database if not available in workingDirectory.
1089 @param uploadToDatabaseAfterTraining [Expert] For librarians only: uploads weight files to localdb after training.
1090 @param samplerFileId Identifier to paralellize
1091 sampling. Only used in ``Sampler`` mode. If you are training by yourself and
1092 want to parallelize the sampling, you can run several sampling scripts in
1093 parallel. By changing this parameter you will not overwrite an older sample.
1094 @param path Modules are added to this path
1098 if mode !=
'Sampler' and mode !=
'Teacher' and mode !=
'Expert':
1099 B2FATAL(
'flavorTagger: Wrong mode given: The available modes are "Sampler", "Teacher" or "Expert"')
1105 B2FATAL(
'flavorTagger: THE GIVEN WORKING DIRECTORY "' + workingDirectory +
'" DOES NOT EXIST! PLEASE SPECIFY A VALID PATH.')
1107 global filesDirectory
1108 filesDirectory = workingDirectory +
'/FlavorTagging/TrainedMethods'
1110 if mode ==
'Sampler' or (mode ==
'Expert' and downloadFromDatabaseIfNotFound):
1112 os.mkdir(workingDirectory +
'/FlavorTagging')
1113 os.mkdir(workingDirectory +
'/FlavorTagging/TrainedMethods')
1115 os.mkdir(workingDirectory +
'/FlavorTagging/TrainedMethods')
1116 filesDirectory = workingDirectory +
'/FlavorTagging/TrainedMethods'
1118 if len(combinerMethods) < 1
or len(combinerMethods) > 2:
1119 B2FATAL(
'flavorTagger: Invalid list of combinerMethods. The available methods are "TMVA-FBDT" and "FANN-MLP"')
1127 for method
in combinerMethods:
1128 if method ==
'TMVA-FBDT':
1130 elif method ==
'FANN-MLP':
1133 B2FATAL(
'flavorTagger: Invalid list of combinerMethods. The available methods are "TMVA-FBDT" and "FANN-MLP"')
1136 fileId = samplerFileId
1138 global useOnlyLocalFlag
1139 useOnlyLocalFlag = useOnlyLocalWeightFiles
1141 B2INFO(
'*** FLAVOR TAGGING ***')
1143 B2INFO(
' Working directory is: ' + filesDirectory)
1146 setInteractionWithDatabase(downloadFromDatabaseIfNotFound, uploadToDatabaseAfterTraining)
1147 WhichCategories(categories)
1148 set_FlavorTagger_pid_aliases()
1151 roe_path = basf2.create_path()
1152 deadEndPath = basf2.create_path()
1155 if mode ==
'Sampler':
1156 ma.signalSideParticleListsFilter(
1158 'nROE_Charged(' + maskName +
', 0) > 0 and abs(qrCombined) == 1',
1163 if mode ==
'Expert':
1164 ma.signalSideParticleListsFilter(particleLists,
'nROE_Charged(' + maskName +
', 0) > 0', roe_path, deadEndPath)
1166 flavorTaggerInfoBuilder = basf2.register_module(
'FlavorTaggerInfoBuilder')
1167 path.add_module(flavorTaggerInfoBuilder)
1170 if mode ==
'Sampler' or mode ==
'Expert':
1171 if FillParticleLists(mode, maskName, roe_path):
1172 if eventLevel(mode, weightFiles, roe_path):
1173 combinerLevel(mode, weightFiles, roe_path)
1174 if mode ==
'Expert':
1175 flavorTaggerInfoFiller = basf2.register_module(
'FlavorTaggerInfoFiller')
1176 flavorTaggerInfoFiller.param(
'trackLevelParticleLists', trackLevelParticleLists)
1177 flavorTaggerInfoFiller.param(
'eventLevelParticleLists', eventLevelParticleLists)
1178 flavorTaggerInfoFiller.param(
'TMVAfbdt', TMVAfbdt)
1179 flavorTaggerInfoFiller.param(
'FANNmlp', FANNmlp)
1180 flavorTaggerInfoFiller.param(
'qpCategories', saveCategoriesInfo)
1181 flavorTaggerInfoFiller.param(
'istrueCategories', saveCategoriesInfo)
1182 flavorTaggerInfoFiller.param(
'targetProb',
False)
1183 flavorTaggerInfoFiller.param(
'trackPointers',
False)
1184 roe_path.add_module(flavorTaggerInfoFiller)
1185 add_default_FlavorTagger_aliases()
1188 particleListsToRemoveExtraInfo = []
1189 for particleList
in eventLevelParticleLists:
1190 if particleList[0]
not in particleListsToRemoveExtraInfo:
1191 particleListsToRemoveExtraInfo.append(particleList[0])
1193 if mode ==
'Expert':
1194 ma.removeExtraInfo(particleListsToRemoveExtraInfo,
True, roe_path)
1196 elif mode ==
'Sampler':
1197 ma.removeExtraInfo(particleListsToRemoveExtraInfo,
False, roe_path)
1199 path.for_each(
'RestOfEvent',
'RestOfEvents', roe_path)
1201 if mode ==
'Teacher':
1202 if eventLevelTeacher(weightFiles):
1203 combinerLevelTeacher(weightFiles)
1206 if __name__ ==
'__main__':
1210 function = globals()[
"flavorTagger"]
1211 signature = inspect.formatargspec(*inspect.getfullargspec(function))
1212 desc_list.append((function.__name__, signature +
'\n' + function.__doc__))
1214 from terminal_utils
import Pager
1215 from basf2.utils import pretty_print_description_list
1216 with Pager(
'Flavor Tagger function accepts the following arguments:'):
1217 pretty_print_description_list(desc_list)