Belle II Software development
MultiplicitiesEventShapeMixed.py
1#!/usr/bin/env python3
2
3
10
11
19
20"""
21<header>
22 <input>../mixed.cdst.root</input>
23 <output>MCvalidationMixed.root</output>
24 <description>Determining multiplicities of different particles on generator level</description>
25</header>
26"""
27
28import basf2 as b2
29import modularAnalysis as ma
30from variables import variables as v
31from variables import collections as vc
32from SplitMultiplicities import SplitMultiplicities
33import argparse
34
35path = b2.create_path()
36
37
38def get_argument_parser():
39 """
40 Parses the command line options and returns the corresponding arguments.
41 """
42
43 parser = argparse.ArgumentParser(
44 description=__doc__.split("--examples--")[0],
45 # epilog=__doc__.split("--examples--")[1],
46 formatter_class=argparse.RawDescriptionHelpFormatter,
47 # usage="%(prog)s [optional arguments] [--] program [program arguments]"
48 )
49
50 parser.add_argument('--input', type=str, default='../mixed.cdst.root', help='The name of the input root file')
51 parser.add_argument('--output', type=str, default='MCvalidationMixed.root', help='The name of the output root file')
52
53 return parser
54
55
56def define_ups_aliases():
57 '''Define aliases to write out multiplicities'''
58 alias_dict = {}
59 alias_dict['nPIp'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(211))'
60 alias_dict['nPI0'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(111))'
61 alias_dict['nETA'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(221))'
62 alias_dict['nETAprim'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(331))'
63 alias_dict['nPHI'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(333))'
64 alias_dict['nRHOp'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(213))'
65 alias_dict['nRHO0'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(113))'
66 alias_dict['nKp'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(321))'
67 alias_dict['nKL0'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(130))'
68 alias_dict['nKS0'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(310))'
69 alias_dict['nKstar0'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(313))'
70 alias_dict['nKstarp'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(323))'
71 alias_dict['nDp'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(411))'
72 alias_dict['nD0'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(421))'
73 alias_dict['nBp'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(521))'
74 alias_dict['nB0'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(511))'
75 alias_dict['nJPSI'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(443))'
76 alias_dict['nELECTRON'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(11))'
77 alias_dict['nENEUTRINO'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(12))'
78 alias_dict['nMUON'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(13))'
79 alias_dict['nMNEUTRINO'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(14))'
80 alias_dict['nTAUON'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(15))'
81 alias_dict['nTNEUTRINO'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(16))'
82 alias_dict['nPHOTON'] = 'genUpsilon4S(NumberOfMCParticlesInEvent(22))'
83 alias_dict['GenUp4S_nTracks'] = 'genUpsilon4S(nTracks)'
84 return(alias_dict)
85
86
87def define_split_aliases():
88 '''Define aliases for extraInfo resulting from SplitMultiplicities module'''
89 alias_dict = {}
90 alias_dict['gen_Kp'] = 'eventExtraInfo(nGen_321)'
91 alias_dict['gen_Kp_Bp'] = 'eventExtraInfo(nGen_321_Bp)'
92 alias_dict['gen_Kp_Bm'] = 'eventExtraInfo(nGen_321_Bm)'
93 alias_dict['gen_Kp_B0'] = 'eventExtraInfo(nGen_321_B0)'
94 alias_dict['gen_Kp_antiB0'] = 'eventExtraInfo(nGen_321_antiB0)'
95 alias_dict['gen_Km'] = 'eventExtraInfo(nGen_-321)'
96 alias_dict['gen_Km_Bp'] = 'eventExtraInfo(nGen_-321_Bp)'
97 alias_dict['gen_Km_Bm'] = 'eventExtraInfo(nGen_-321_Bm)'
98 alias_dict['gen_Km_B0'] = 'eventExtraInfo(nGen_-321_B0)'
99 alias_dict['gen_Km_antiB0'] = 'eventExtraInfo(nGen_-321_antiB0)'
100 alias_dict['gen_K0'] = 'eventExtraInfo(nGen_311)'
101 alias_dict['gen_K0_Bp'] = 'eventExtraInfo(nGen_311_Bp)'
102 alias_dict['gen_K0_Bm'] = 'eventExtraInfo(nGen_311_Bm)'
103 alias_dict['gen_K0_B0'] = 'eventExtraInfo(nGen_311_B0)'
104 alias_dict['gen_K0_antiB0'] = 'eventExtraInfo(nGen_311_antiB0)'
105 alias_dict['gen_antiK0'] = 'eventExtraInfo(nGen_-311)'
106 alias_dict['gen_antiK0_Bp'] = 'eventExtraInfo(nGen_-311_Bp)'
107 alias_dict['gen_antiK0_Bm'] = 'eventExtraInfo(nGen_-311_Bm)'
108 alias_dict['gen_antiK0_B0'] = 'eventExtraInfo(nGen_-311_B0)'
109 alias_dict['gen_antiK0_antiB0'] = 'eventExtraInfo(nGen_-311_antiB0)'
110 return(alias_dict)
111
112
113def add_aliases(alias_dict={}):
114 '''Here we add the aliases defined in define_{split/ups}_aliases'''
115 for key, value in alias_dict.items():
116 v.addAlias(key, value)
117
118
119parser = get_argument_parser()
120args = parser.parse_args()
121
122# read input file
123ma.inputMdstList(args.input, path)
124
125path.add_module(SplitMultiplicities(321)) # K+
126path.add_module(SplitMultiplicities(-321)) # K-
127path.add_module(SplitMultiplicities(311)) # K0
128path.add_module(SplitMultiplicities(-311)) # anti_K0
129
130# fill other generated particle lists needed for event shape
131pions = ("pi+:MC", '')
132kaons = ("K+:MC", '')
133muons = ("mu+:MC", '')
134electrons = ("e+:MC", '')
135protons = ("p+:MC", '')
136photons = ("gamma:MC", '')
137klongs = ("K_L0:MC", '')
138ma.fillParticleListsFromMC([pions, kaons, muons, electrons, protons, klongs, photons], path=path)
139
140# build event shape
141ma.buildEventShape(['pi+:MC', "K+:MC", "mu+:MC", "e+:MC", "p+:MC", "K_L0:MC", "gamma:MC"], path=path)
142
143# create a dictionary of multiplicity variable aliases
144Multi_aliasDict = define_ups_aliases()
145Split_aliasDict = define_split_aliases()
146
147# add the multiplicity aliases into variables
148add_aliases(Multi_aliasDict)
149add_aliases(Split_aliasDict)
150multi_variables = list(Multi_aliasDict.keys())
151split_variables = list(Split_aliasDict.keys())
152
153# add event shape variables to a list
154eventshape_variables = vc.event_shape
155
156# write out the trees containing the multiplicities, split multiplicities for kaons and the event shape variables
157ma.variablesToNtuple(
158 '',
159 treename="Multiplicities",
160 variables=multi_variables,
161 filename=args.output,
162 path=path)
163ma.variablesToNtuple('', treename="Split", variables=split_variables, filename=args.output, path=path)
164ma.variablesToNtuple(
165 '',
166 treename="EventShape",
167 variables=eventshape_variables,
168 filename=args.output,
169 path=path)
170
171progress = ma.register_module('Progress')
172path.add_module(progress)
173b2.process(path)
174print(b2.statistics)