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