15Example script to calculate isolation variables per particle.
17For each particle in the input charged stable particle list,
18calculate the distance to the closest candidate in the reference list at a given detector layer surface.
19The calculation of the distance is based on the particles' track helices extrapolation.
30 import stdCharged
as stdc
31 from modularAnalysis
import getAnalysisGlobaltag
33 parser = argparse.ArgumentParser(description=__doc__,
34 formatter_class=argparse.RawTextHelpFormatter)
36 parser.add_argument(
"--std_charged_ref",
38 choices=stdc._chargednames,
40 help=
"The base name of the reference standard charged particle list\n"
41 "that will be considered for the distance calculation.\n"
42 "Default: %(default)s.")
43 parser.add_argument(
"--detectors",
46 default=[
"CDC",
"TOP",
"ARICH",
"ECL",
"KLM"],
47 choices=[
"CDC",
"TOP",
"ARICH",
"ECL",
"KLM"],
48 help=
"List of detectors at whose entry surface the isolation variables will be calculated.\n"
49 "Pass a space-separated list of names.\n"
50 "Default: %(default)s.")
51 parser.add_argument(
"--use_pid_det_weights",
54 help=
"Include the PID detector weights (taken from the CDB) in the isolation score calculation.\n"
55 "Default: %(default)s.")
56 parser.add_argument(
"--global_tag_append",
59 default=[getAnalysisGlobaltag()],
60 help=
"List of names of conditions DB global tag(s) to append on top of GT replay.\n"
61 "NB: these GTs will have lowest priority over GT replay.\n"
62 "The order of the sequence passed determines the priority of the GTs, w/ the highest coming first.\n"
63 "Pass a space-separated list of names.\n"
64 "Default: %(default)s.")
65 parser.add_argument(
"--global_tag_prepend",
69 help=
"List of names of conditions DB global tag(s) to prepend to GT replay.\n"
70 "NB: these GTs will have highest priority over GT replay.\n"
71 "The order of the sequence passed determines the priority of the GTs, w/ the highest coming first.\n"
72 "Pass a space-separated list of names.")
73 parser.add_argument(
"-d",
"--debug",
77 choices=list(range(11, 20)),
78 help=
"Run the TrackIsoCalculator module in debug mode. Pass the desired DEBUG level integer.")
83if __name__ ==
"__main__":
88 args = argparser().parse_args()
91 import modularAnalysis
as ma
92 import stdV0s
as stdv0
93 from variables
import variables
as vm
97 from ROOT
import Belle2
100 for tag
in args.global_tag_append:
101 b2.conditions.append_globaltag(tag)
102 print(f
"Appending GTs:\n{args.global_tag_append}")
104 if args.global_tag_prepend:
105 for tag
in reversed(args.global_tag_prepend):
106 b2.conditions.prepend_globaltag(tag)
107 print(f
"Prepending GTs:\n{args.global_tag_prepend}")
110 path = b2.create_path()
113 ma.inputMdst(filename=b2.find_file(
"mdst14.root",
"validation"), path=path)
122 base_trk_selection =
"[dr < 3] and [abs(dz) < 5] and [thetaInCDCAcceptance] and [pt > 0.1]"
123 ma.fillParticleList(
"mu+:muons", f
"{base_trk_selection} and [muonID > 0.5]", path=path)
126 jpsimumu =
"J/psi:mumu -> mu+:muons mu-:muons"
129 "[daughterSumOf(charge) == 0]",
131 jpsi_cut =
" and ".join(jpsi_cuts)
133 ma.reconstructDecay(jpsimumu, jpsi_cut, path=path)
137 ref = f
"{args.std_charged_ref}+:ref"
139 ma.fillParticleList(ref, f
"{base_trk_selection}", path=path)
146 trackiso_vars_mu = ma.calculateTrackIsolation(
"J/psi:mumu -> ^mu+ ^mu-",
149 vars_for_nearest_part=vc.mc_variables,
151 reference_list_name=ref,
153 exclude_pid_det_weights=
not args.use_pid_det_weights)
156 variables_jpsi = vc.kinematics + [
"daughterDiffOfPhi(0, 1)"]
157 variables_jpsi += vu.create_aliases(variables_jpsi,
"useCMSFrame({variable})",
"CMS")
158 variables_jpsi += vc.inv_mass
159 aliases_jpsi = vu.create_aliases_for_selected(variables_jpsi,
160 "^J/psi:mumu -> mu+ mu-",
165 variables_mu = vc.kinematics + [
"theta",
"phi",
"clusterE",
"nCDCHits"] + trackiso_vars_mu[ref_pdg]
166 aliases_mu = vu.create_aliases_for_selected(variables_mu,
167 "J/psi:mumu -> ^mu+ ^mu-",
171 vm.addAlias(
"nReferenceTracks", f
"nCleanedTracks({base_trk_selection})")
172 aliases_event = [
"nReferenceTracks"]
175 ma.variablesToNtuple(decayString=
"J/psi:mumu",
176 variables=aliases_event+aliases_jpsi+aliases_mu,
178 filename=
"TrackIsolationVariables.root",
186 stdv0.stdLambdas(path=path)
195 trackiso_vars_p_pi = ma.calculateTrackIsolation(
"Lambda0:merged -> ^p+ ^pi-",
198 vars_for_nearest_part=vc.mc_variables,
200 highest_prob_mass_for_ext=
False,
201 exclude_pid_det_weights=
not args.use_pid_det_weights)
204 variables_lambda0 = vc.kinematics + [
"daughterDiffOfPhi(0, 1)"]
205 variables_lambda0 += vu.create_aliases(variables_lambda0,
"useCMSFrame({variable})",
"CMS")
206 variables_lambda0 += vc.inv_mass
207 aliases_lambda0 = vu.create_aliases_for_selected(variables_lambda0,
208 "^Lambda0:merged -> p+ pi-",
213 variables_p = vc.kinematics + \
214 [
"theta",
"phi",
"clusterE",
"nCDCHits"] + \
215 trackiso_vars_p_pi[Const.proton.getPDGCode()]
216 aliases_p = vu.create_aliases_for_selected(variables_p,
217 "Lambda0:merged -> ^p+ pi-",
220 variables_pi = vc.kinematics + \
221 [
"theta",
"phi",
"clusterE",
"nCDCHits"] + \
222 trackiso_vars_p_pi[Const.pion.getPDGCode()]
223 aliases_pi = vu.create_aliases_for_selected(variables_pi,
224 "Lambda0:merged -> p+ ^pi-",
228 ma.variablesToNtuple(decayString=
"Lambda0:merged",
229 variables=aliases_lambda0+aliases_p+aliases_pi,
230 treename=
"lambda0ppi",
231 filename=
"TrackIsolationVariables.root",
240 for m
in path.modules():
241 if "TrackIsoCalculator" in m.name():
242 m.set_log_level(b2.LogLevel.DEBUG)
243 m.set_debug_level(args.debug)
245 path.add_module(
"Progress")
This class provides a set of constants for the framework.