12Example script to calculate isolation variables per particle.
14For each particle in the input charged stable particle list,
15calculate the distance to the closest candidate in the reference list at a given detector layer surface.
16The calculation of the distance is based on the particles' track helices extrapolation.
27 import stdCharged
as stdc
28 from modularAnalysis
import getAnalysisGlobaltag
30 parser = argparse.ArgumentParser(description=__doc__,
31 formatter_class=argparse.RawTextHelpFormatter)
33 parser.add_argument(
"--std_charged_ref",
35 choices=stdc._chargednames,
37 help=
"The base name of the reference standard charged particle list\n"
38 "that will be considered for the distance calculation.\n"
39 "Default: %(default)s.")
40 parser.add_argument(
"--detectors",
43 default=[
"CDC",
"TOP",
"ARICH",
"ECL",
"KLM"],
44 choices=[
"CDC",
"TOP",
"ARICH",
"ECL",
"KLM"],
45 help=
"List of detectors at whose entry surface the isolation variables will be calculated.\n"
46 "Pass a space-separated list of names.\n"
47 "Default: %(default)s.")
48 parser.add_argument(
"--use_pid_det_weights",
51 help=
"Include the PID detector weights (taken from the CDB) in the isolation score calculation.\n"
52 "Default: %(default)s.")
53 parser.add_argument(
"--global_tag_append",
56 default=[getAnalysisGlobaltag()],
57 help=
"List of names of conditions DB global tag(s) to append on top of GT replay.\n"
58 "NB: these GTs will have lowest priority over GT replay.\n"
59 "The order of the sequence passed determines the priority of the GTs, w/ the highest coming first.\n"
60 "Pass a space-separated list of names.\n"
61 "Default: %(default)s.")
62 parser.add_argument(
"--global_tag_prepend",
66 help=
"List of names of conditions DB global tag(s) to prepend to GT replay.\n"
67 "NB: these GTs will have highest priority over GT replay.\n"
68 "The order of the sequence passed determines the priority of the GTs, w/ the highest coming first.\n"
69 "Pass a space-separated list of names.")
70 parser.add_argument(
"-d",
"--debug",
74 choices=list(range(11, 20)),
75 help=
"Run the TrackIsoCalculator module in debug mode. Pass the desired DEBUG level integer.")
80if __name__ ==
"__main__":
85 args = argparser().parse_args()
88 import modularAnalysis
as ma
89 import stdV0s
as stdv0
90 from variables
import variables
as vm
94 from ROOT
import Belle2
97 for tag
in args.global_tag_append:
98 b2.conditions.append_globaltag(tag)
99 print(f
"Appending GTs:\n{args.global_tag_append}")
101 if args.global_tag_prepend:
102 for tag
in reversed(args.global_tag_prepend):
103 b2.conditions.prepend_globaltag(tag)
104 print(f
"Prepending GTs:\n{args.global_tag_prepend}")
107 path = b2.create_path()
110 ma.inputMdst(filename=b2.find_file(
"mdst16.root",
"validation"), path=path)
119 base_trk_selection =
"[dr < 3] and [abs(dz) < 5] and [thetaInCDCAcceptance] and [pt > 0.1]"
120 ma.fillParticleList(
"mu+:muons", f
"{base_trk_selection} and [muonID > 0.5]", path=path)
123 jpsimumu =
"J/psi:mumu -> mu+:muons mu-:muons"
126 "[daughterSumOf(charge) == 0]",
128 jpsi_cut =
" and ".join(jpsi_cuts)
130 ma.reconstructDecay(jpsimumu, jpsi_cut, path=path)
134 ref = f
"{args.std_charged_ref}+:ref"
136 ma.fillParticleList(ref, f
"{base_trk_selection}", path=path)
143 trackiso_vars_mu = ma.calculateTrackIsolation(
"J/psi:mumu -> ^mu+ ^mu-",
146 vars_for_nearest_part=vc.mc_variables,
148 reference_list_name=ref,
150 exclude_pid_det_weights=
not args.use_pid_det_weights)
153 variables_jpsi = vc.kinematics + [
"daughterDiffOf(0, 1, phi)"]
154 variables_jpsi += vu.create_aliases(variables_jpsi,
"useCMSFrame({variable})",
"CMS")
155 variables_jpsi += vc.inv_mass
156 aliases_jpsi = vu.create_aliases_for_selected(variables_jpsi,
157 "^J/psi:mumu -> mu+ mu-",
162 variables_mu = vc.kinematics + [
"theta",
"phi",
"clusterE",
"nCDCHits"] + trackiso_vars_mu[ref_pdg]
163 aliases_mu = vu.create_aliases_for_selected(variables_mu,
164 "J/psi:mumu -> ^mu+ ^mu-",
168 vm.addAlias(
"nReferenceTracks", f
"nCleanedTracks({base_trk_selection})")
169 aliases_event = [
"nReferenceTracks"]
172 ma.variablesToNtuple(decayString=
"J/psi:mumu",
173 variables=aliases_event+aliases_jpsi+aliases_mu,
175 filename=
"TrackIsolationVariables.root",
183 stdv0.stdLambdas(path=path)
192 trackiso_vars_p_pi = ma.calculateTrackIsolation(
"Lambda0:merged -> ^p+ ^pi-",
195 vars_for_nearest_part=vc.mc_variables,
197 highest_prob_mass_for_ext=
False,
198 exclude_pid_det_weights=
not args.use_pid_det_weights)
201 variables_lambda0 = vc.kinematics + [
"daughterDiffOf(0, 1, phi)"]
202 variables_lambda0 += vu.create_aliases(variables_lambda0,
"useCMSFrame({variable})",
"CMS")
203 variables_lambda0 += vc.inv_mass
204 aliases_lambda0 = vu.create_aliases_for_selected(variables_lambda0,
205 "^Lambda0:merged -> p+ pi-",
210 variables_p = vc.kinematics + \
211 [
"theta",
"phi",
"clusterE",
"nCDCHits"] + \
212 trackiso_vars_p_pi[Const.proton.getPDGCode()]
213 aliases_p = vu.create_aliases_for_selected(variables_p,
214 "Lambda0:merged -> ^p+ pi-",
217 variables_pi = vc.kinematics + \
218 [
"theta",
"phi",
"clusterE",
"nCDCHits"] + \
219 trackiso_vars_p_pi[Const.pion.getPDGCode()]
220 aliases_pi = vu.create_aliases_for_selected(variables_pi,
221 "Lambda0:merged -> p+ ^pi-",
225 ma.variablesToNtuple(decayString=
"Lambda0:merged",
226 variables=aliases_lambda0+aliases_p+aliases_pi,
227 treename=
"lambda0ppi",
228 filename=
"TrackIsolationVariables.root",
237 for m
in path.modules():
238 if "TrackIsoCalculator" in m.name():
239 m.set_log_level(b2.LogLevel.DEBUG)
240 m.set_debug_level(args.debug)
242 path.add_module(
"Progress")
This class provides a set of constants for the framework.