Belle II Software development
085_module.py
1#!/usr/bin/env python3
2
3import basf2 as b2
4from ROOT import Belle2
5
6
7class 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 event number and the PDG code of the MCParticle"""
21 for particle in self.particles:
22 b2.B2INFO(
23 f"We're in event {self.eventinfo.getEvent()} "
24 f"and have a particle with PDG code {particle.getPDG()}"
25 )
26
27
28# create a path
29main = b2.Path()
30
31# generate events
32main.add_module("EventInfoSetter", evtNumList=[10])
33
34# the ParticleGun generates simple tracks
35main.add_module("ParticleGun")
36
37# and add our module
38main.add_module(AccessingDataStoreModule())
39
40# run the path
41b2.process(main)
eventinfo
an example object from the datastore (the metadata collection for the event)
Definition: 085_module.py:15
particles
an example array from the datastore (the list of MC particles)
Definition: 085_module.py:17
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67