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