15 This steering file fills an NTuple with the ChargedPidMVA score
16 for charged particle identification. By default, global PID info is stored,
17 meaning one signal hypothesis is tested against all others.
18 Optionally, binary PID can be stored, by testing one (or more) pair of (S,B) mass hypotheses.
22 basf2 -i /PATH/TO/MDST/FILE.root analysis/examples/PostMdstIdentification/ChargedPidMVAModule.py -- [OPTIONS]
31 from modularAnalysis
import getAnalysisGlobaltag
36 parser = argparse.ArgumentParser(description=__doc__,
37 formatter_class=argparse.RawTextHelpFormatter)
41 s, b = map(int, arg.split(
','))
44 raise argparse.ArgumentTypeError(
"Option string must be of the form 'S,B'")
46 parser.add_argument(
"--matchTruth",
49 help=
"Apply truth-matching on particles.")
50 parser.add_argument(
"--testHyposPDGCodePair",
54 help=
"Option required in binary mode.\n"
55 "A list of pdgId pairs of the (S, B) charged stable particle mass hypotheses to test.\n"
56 "Pass a space-separated list of (>= 1) S,B pdgIds, e.g.:\n"
57 "'--testHyposPDGCodePair 11,211 13,211'")
58 parser.add_argument(
"--addECLOnly",
62 help=
"Apply the BDT also for the ECL-only training."
63 "This will result in a separate score branch in the ntuple.")
64 parser.add_argument(
"--chargeIndependent",
67 help=
"Use a BDT trained on a sample of inclusively charged particles.")
68 parser.add_argument(
"--global_tag_append",
71 default=[getAnalysisGlobaltag()],
72 help=
"List of names of conditions DB global tag(s) to append on top of GT replay.\n"
73 "NB: these GTs will have lowest priority.\n"
74 "Pass a space-separated list of names.")
75 parser.add_argument(
"-d",
"--debug",
80 choices=list(range(11, 20)),
81 help=
"Run the ChargedPidMVA module in debug mode. Pass the desired DEBUG level integer.")
86 if __name__ ==
'__main__':
88 args = argparser().parse_args()
91 import modularAnalysis
as ma
92 from ROOT
import Belle2
95 for tag
in args.global_tag_append:
96 basf2.conditions.append_globaltag(tag)
97 print(f
"Appending GTs:\n{args.global_tag_append}")
103 path = basf2.create_path()
109 ma.inputMdst(filename=basf2.find_file(
"mdst13.root",
"validation"),
118 Belle2.Const.electron.getPDGCode(),
119 Belle2.Const.muon.getPDGCode(),
120 Belle2.Const.pion.getPDGCode(),
121 Belle2.Const.kaon.getPDGCode(),
122 Belle2.Const.proton.getPDGCode(),
123 Belle2.Const.deuteron.getPDGCode(),
126 plists = [(f
"{pdg.to_name(pdgId)}:my_{pdg.to_name(pdgId)}",
"")
for pdgId
in std_charged]
127 ma.fillParticleLists(plists, path=path)
134 for plistname, _
in plists:
135 ma.matchMCTruth(plistname, path=path)
136 ma.applyCuts(plistname,
"isSignal == 1", path=path)
142 global_pid = (args.testHyposPDGCodePair == (0, 0))
143 binary_pid =
not global_pid
150 ma.applyChargedPidMVA(particleLists=[plistname
for plistname, _
in plists],
152 trainingMode=Belle2.ChargedPidMVAWeights.ChargedPidMVATrainingMode.c_Multiclass,
153 chargeIndependent=args.chargeIndependent)
154 if args.add_ecl_only:
155 ma.applyChargedPidMVA(particleLists=[plistname
for plistname, _
in plists],
157 trainingMode=Belle2.ChargedPidMVAWeights.ChargedPidMVATrainingMode.c_ECL_Multiclass)
159 for s, b
in args.testHyposPDGCodePair:
160 ma.applyChargedPidMVA(particleLists=[plistname
for plistname, _
in plists],
162 trainingMode=Belle2.ChargedPidMVAWeights.ChargedPidMVATrainingMode.c_Classification,
163 binaryHypoPDGCodes=(s, b),
164 chargeIndependent=args.chargeIndependent)
165 if args.add_ecl_only:
166 ma.applyChargedPidMVA(particleLists=[plistname
for plistname, _
in plists],
168 trainingMode=Belle2.ChargedPidMVAWeights.ChargedPidMVATrainingMode.c_ECL_Classification,
169 binaryHypoPDGCodes=(s, b))
172 for m
in path.modules():
173 if "ChargedPidMVA" in m.name():
174 m.logging.log_level = basf2.LogLevel.DEBUG
175 m.logging.debug_level = args.debug
183 append =
"_vs_".join(map(str, std_charged))
185 variables = [f
"pidChargedBDTScore({pdgId}, ALL)" for pdgId
in std_charged]
186 if args.add_ecl_only:
187 variables += [f
"pidChargedBDTScore({pdgId}, ECL)" for pdgId
in std_charged]
191 append =
"__".join([f
"{s}_vs_{b}" for s, b
in args.testHyposPDGCodePair])
193 variables = [f
"pidPairChargedBDTScore({s}, {b}, ALL)" for s, b
in args.testHyposPDGCodePair]
194 if args.add_ecl_only:
195 variables += [f
"pidPairChargedBDTScore({s}, {b}, ECL)" for s, b
in args.testHyposPDGCodePair]
197 filename = f
"chargedpid_ntuples__{append}.root"
199 for plistname, _
in plists:
202 treename = re.sub(
r"[\W]+",
"", plistname.split(
':')[1])
205 ma.variablesToNtuple(decayString=plistname,
211 ma.variablesToNtuple(decayString=plistname,
221 progress = basf2.register_module(
"Progress")
222 path.add_module(progress)
232 print(basf2.statistics)