Belle II Software
development
087_module.py
1
#!/usr/bin/env python3
2
3
import
basf2
as
b2
4
from
ROOT
import
Belle2
5
6
7
class
AccessingDataStoreModule
(b2.Module):
8
"""An example of a basf2 module in python which accesses things in the datastore."""
9
10
def
initialize
(self):
11
"""Create a member to access event info and the MCParticles
12
StoreArray
13
"""
14
15
self.
eventinfo
=
Belle2.PyStoreObj
(
"EventMetaData"
)
16
17
self.
particles
=
Belle2.PyStoreArray
(
"MCParticles"
)
18
19
def
event
(self):
20
"""Print the number of charged particles and the total charge"""
21
n_charged = 0
22
total_charge = 0
23
for
particle
in
self.
particles
:
24
charge = particle.getCharge()
25
if
charge:
26
n_charged += 1
27
total_charge += charge
28
29
b2.B2INFO(
30
f
"Number of charged particles = {n_charged}, "
31
f
"total charge of event = {total_charge}"
32
)
33
34
35
# create a path
36
main = b2.Path()
37
38
# generate events
39
main.add_module(
"EventInfoSetter"
, evtNumList=[10])
40
41
# generate events with 3 tracks (not all of them are charged tracks)
42
main.add_module(
"ParticleGun"
, nTracks=3)
43
44
# and add our module
45
main.add_module(
AccessingDataStoreModule
())
46
47
# run the path
48
b2.process(main)
087_module.AccessingDataStoreModule
Definition
087_module.py:7
087_module.AccessingDataStoreModule.initialize
initialize(self)
Definition
087_module.py:10
087_module.AccessingDataStoreModule.eventinfo
eventinfo
an example object from the datastore (the metadata collection for the event)
Definition
087_module.py:15
087_module.AccessingDataStoreModule.event
event(self)
Definition
087_module.py:19
087_module.AccessingDataStoreModule.particles
particles
an example array from the datastore (the list of MC particles)
Definition
087_module.py:17
Belle2::PyStoreArray
A (simplified) python wrapper for StoreArray.
Definition
PyStoreArray.h:73
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition
PyStoreObj.h:67
online_book
basf2
steering_files
087_module.py
Generated on Mon Sep 1 2025 02:54:37 for Belle II Software by
1.13.2