Belle II Software  release-08-01-10
SplitMultiplicities.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
20 
21 """
22 <header>
23  <noexecute>Definition of helper class</noexecute>
24 </header>
25 """
26 
27 from ROOT import Belle2
28 import basf2
29 
30 
31 class SplitMultiplicities(basf2.Module):
32  """
33  Module to determine the multiplicities of a particle of a certain pdg code
34  """
35 
36  def __init__(self, pdgcode):
37  """
38  Initialise the class.
39  :param pdgcode: pdg code to be studied
40  """
41  super().__init__()
42 
43  self.pdgcodepdgcode = pdgcode
44 
45  self.eventExtraInfoeventExtraInfo = Belle2.PyStoreObj("EventExtraInfo")
46 
47  def event(self):
48  """ Event function """
49 
50  # set counters to 0
51  gen_counter = 0
52  Bp_counter = 0
53  Bm_counter = 0
54  B0_counter = 0
55  antiB0_counter = 0
56 
57  # get generator particles and loop over them until reaching a B+/B-/B0/antiB0 mother
58  mcParticles = Belle2.PyStoreArray('MCParticles')
59  for mcparticle in mcParticles:
60  if (mcparticle.isPrimaryParticle()) and (mcparticle.getPDG() == self.pdgcodepdgcode):
61  gen_counter += 1
62  mcMother = mcparticle.getMother()
63  while mcMother:
64  pdg = mcMother.getPDG()
65  if pdg == 521: # B+
66  Bp_counter += 1
67  break
68  elif pdg == -521: # B-
69  Bm_counter += 1
70  break
71  elif pdg == 511: # B0
72  B0_counter += 1
73  break
74  elif pdg == -511: # antiB0
75  antiB0_counter += 1
76  break
77  else:
78  mcMother = mcMother.getMother()
79 
80  # create the extra info names and save the corresponding multiplicities
81  extraInfoName = 'nGen_{}'.format(self.pdgcodepdgcode)
82  extraInfoName_Bp = 'nGen_{}_Bp'.format(self.pdgcodepdgcode)
83  extraInfoName_Bm = 'nGen_{}_Bm'.format(self.pdgcodepdgcode)
84  extraInfoName_B0 = 'nGen_{}_B0'.format(self.pdgcodepdgcode)
85  extraInfoName_antiB0 = 'nGen_{}_antiB0'.format(self.pdgcodepdgcode)
86 
87  self.eventExtraInfoeventExtraInfo.create()
88  self.eventExtraInfoeventExtraInfo.setExtraInfo(extraInfoName, gen_counter)
89  self.eventExtraInfoeventExtraInfo.setExtraInfo(extraInfoName_Bp, Bp_counter)
90  self.eventExtraInfoeventExtraInfo.setExtraInfo(extraInfoName_Bm, Bm_counter)
91  self.eventExtraInfoeventExtraInfo.setExtraInfo(extraInfoName_B0, B0_counter)
92  self.eventExtraInfoeventExtraInfo.setExtraInfo(extraInfoName_antiB0, antiB0_counter)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67