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(environmentType=
"default",
110 filename=basf2.find_file(
"mdst13.root",
"validation"),
119 Belle2.Const.electron.getPDGCode(),
120 Belle2.Const.muon.getPDGCode(),
121 Belle2.Const.pion.getPDGCode(),
122 Belle2.Const.kaon.getPDGCode(),
123 Belle2.Const.proton.getPDGCode(),
124 Belle2.Const.deuteron.getPDGCode(),
127 plists = [(f
"{pdg.to_name(pdgId)}:my_{pdg.to_name(pdgId)}",
"")
for pdgId
in std_charged]
128 ma.fillParticleLists(plists, path=path)
135 for plistname, _
in plists:
136 ma.matchMCTruth(plistname, path=path)
137 applyCuts(plistname,
"isSignal == 1", path=path)
143 global_pid = (args.testHyposPDGCodePair == (0, 0))
144 binary_pid =
not global_pid
151 ma.applyChargedPidMVA(particleLists=[plistname
for plistname, _
in plists],
153 trainingMode=Belle2.ChargedPidMVAWeights.ChargedPidMVATrainingMode.c_Multiclass,
154 chargeIndependent=args.chargeIndependent)
155 if args.add_ecl_only:
156 ma.applyChargedPidMVA(particleLists=[plistname
for plistname, _
in plists],
158 trainingMode=Belle2.ChargedPidMVAWeights.ChargedPidMVATrainingMode.c_ECL_Multiclass)
160 for s, b
in args.testHyposPDGCodePair:
161 ma.applyChargedPidMVA(particleLists=[plistname
for plistname, _
in plists],
163 trainingMode=Belle2.ChargedPidMVAWeights.ChargedPidMVATrainingMode.c_Classification,
164 binaryHypoPDGCodes=(s, b),
165 chargeIndependent=args.chargeIndependent)
166 if args.add_ecl_only:
167 ma.applyChargedPidMVA(particleLists=[plistname
for plistname, _
in plists],
169 trainingMode=Belle2.ChargedPidMVAWeights.ChargedPidMVATrainingMode.c_ECL_Classification,
170 binaryHypoPDGCodes=(s, b))
173 for m
in path.modules():
174 if "ChargedPidMVA" in m.name():
175 m.logging.log_level = basf2.LogLevel.DEBUG
176 m.logging.debug_level = args.debug
184 append =
"_vs_".join(map(str, std_charged))
186 variables = [f
"pidChargedBDTScore({pdgId}, ALL)" for pdgId
in std_charged]
187 if args.add_ecl_only:
188 variables += [f
"pidChargedBDTScore({pdgId}, ECL)" for pdgId
in std_charged]
192 append =
"__".join([f
"{s}_vs_{b}" for s, b
in args.testHyposPDGCodePair])
194 variables = [f
"pidPairChargedBDTScore({s}, {b}, ALL)" for s, b
in args.testHyposPDGCodePair]
195 if args.add_ecl_only:
196 variables += [f
"pidPairChargedBDTScore({s}, {b}, ECL)" for s, b
in args.testHyposPDGCodePair]
198 filename = f
"chargedpid_ntuples__{append}.root"
200 for plistname, _
in plists:
203 treename = re.sub(
r"[\W]+",
"", plistname.split(
':')[1])
206 ma.variablesToNtuple(decayString=plistname,
212 ma.variablesToNtuple(decayString=plistname,
222 progress = basf2.register_module(
"Progress")
223 path.add_module(progress)
233 print(basf2.statistics)