Belle II Software  release-05-01-25
087_module.py
1 #!/usr/bin/env python3
2 
3 
4 import basf2 as b2
5 from ROOT import Belle2
6 
7 
8 class AccessingDataStoreModule(b2.Module):
9  def initialize(self):
10  """Create a member to access event info and the MCParticles
11  StoreArray
12  """
13  self.eventinfo = Belle2.PyStoreObj("EventMetaData")
14  self.particles = Belle2.PyStoreArray("MCParticles")
15 
16  def event(self):
17  """Print the number of charged particles and the total charge"""
18  n_charged = 0
19  total_charge = 0
20  for particle in self.particles:
21  charge = particle.getCharge()
22  if charge:
23  n_charged += 1
24  total_charge += charge
25 
26  b2.B2INFO(
27  f"Number of charged particles = {n_charged}, "
28  f"total charge of event = {total_charge}"
29  )
30 
31 
32 # create a path
33 main = b2.Path()
34 
35 # generate events
36 main.add_module("EventInfoSetter", evtNumList=[10])
37 
38 # generate events with 3 tracks (not all of them are charged tracks)
39 main.add_module("ParticleGun", nTracks=3)
40 
41 # and add our module
42 main.add_module(AccessingDataStoreModule())
43 
44 # run the path
45 b2.process(main)
087_module.AccessingDataStoreModule.event
def event(self)
Definition: 087_module.py:16
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:69
087_module.AccessingDataStoreModule.eventinfo
eventinfo
Definition: 087_module.py:13
087_module.AccessingDataStoreModule
Definition: 087_module.py:8
087_module.AccessingDataStoreModule.initialize
def initialize(self)
Definition: 087_module.py:9
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58
087_module.AccessingDataStoreModule.particles
particles
Definition: 087_module.py:14