Belle II Software  release-06-01-15
MCGenTopo.py
1 #!/usr/bin/env python3
2 
3 
10 from variables.utils import create_aliases
11 from variables import variables
12 
13 
14 def mc_gen_topo(n=200):
15  """
16  Gets the list of variables containing the raw topology information of MC generated events.
17  To be specific, the list including the following variables:
18 
19  * ``nMCGen``: number of MC generated particles in a given event,
20  * ``MCGenPDG_i`` (i=0, 1, ... n-2, n-1):
21  PDG code of the :math:`{\\rm i}^{\\rm th}` MC generated particle in a given event,
22  * ``MCGenMothIndex_i`` (i=0, 1, ... n-2, n-1):
23  mother index of the :math:`{\\rm i}^{\\rm th}` MC generated particle in a given event.
24 
25  .. tip::
26 
27  * Internally, ``nMCGen``, ``MCGenPDG_i`` and ``MCGenMothIndex_i`` are just aliases of
28  ``nMCParticles``, ``genParticle(i, varForMCGen(PDG))``
29  and ``genParticle(i, varForMCGen(mcMother(mdstIndex)))``, respectively.
30  * For more details on the variables, please refer to the documentations of
31  :b2:var:`nMCParticles`, :b2:var:`genParticle`, :b2:var:`varForMCGen`,
32  :b2:var:`PDG`, :b2:var:`mcMother`, and :b2:var:`mdstIndex`.
33 
34  Parameters:
35  n (int): number of ``MCGenPDG_i``/``MCGenMothIndex_i`` variables. Its default value is 200.
36 
37  .. note::
38 
39  * To completely examine the topology information of the events in an MC sample,
40  the parameter ``n`` should be greater than or equal to the maximum of ``nMCGen`` in the sample.
41  * Normally, the maximum of ``nMCGen`` in the MC samples at Belle II is less than 200.
42  Hence, if you have no idea about the maximum of ``nMCGen`` in your own MC sample,
43  it is usually a safe choice to use the default parameter value 200.
44  * However, an overlarge parameter value leads to unnecessary waste of disk space and
45  redundant variables with inelegant ``nan`` values.
46  Hence, if you know the maximum of ``nMCGen`` in your own MC sample,
47  it is a better choice to assign the parameter a proper value.
48  """
49  list_of_indexes = [str(i) for i in range(n)]
50  wrapper = 'genParticle({variable}, varForMCGen(PDG))'
51  prefix = 'MCGenPDG'
52  MCGenPDG = create_aliases(list_of_indexes, wrapper, prefix)
53  wrapper = 'genParticle({variable}, varForMCGen(mcMother(mdstIndex)))'
54  prefix = 'MCGenMothIndex'
55  MCGenMothIndex = create_aliases(list_of_indexes, wrapper, prefix)
56  variables.addAlias('nMCGen', 'nMCParticles')
57  list_of_variables = ['nMCGen']
58  for i in range(n):
59  list_of_variables.append(MCGenPDG[i])
60  list_of_variables.append(MCGenMothIndex[i])
61  return list_of_variables