Belle II Software development
triggerKLs.py
1#!/usr/bin/env python3
2
3
10
11# Example steering file with a simple 'trigger' to show only a certain
12# type of events. In this case, we only want to see events containing
13# at least one K_L, which is achieved using a python module that sets
14# a return code.
15# If the return code is 0 (no K_L found), execution will continue in an empty
16# path (i.e. nothing is done with the data), otherwise execution continues
17# normally (K_L event is shown).
18# The same thing can also be done using only C++, by calling
19# Module::setReturnValue() in your module's event() function.
20
21import basf2 as b2
22from ROOT import Belle2
23from simulation import add_simulation
24from reconstruction import add_reconstruction
25
26
27class PyTrigger(b2.Module):
28
29 """Returns 1 if current event contains at least one K_L^0, 0 otherwise"""
30
31 def initialize(self):
32 """reimplementation of Module::initialize()."""
33
34 Belle2.PyStoreObj("DisplayData").registerInDataStore()
35
36 def event(self):
37 """reimplementation of Module::event()."""
38
39 self.return_value(0)
40 mcparticles = Belle2.PyStoreArray('MCParticles')
41 for p in mcparticles:
42 if abs(p.getPDG()) == 130:
43 b2.B2INFO('found a K_L!')
44 self.return_value(1)
45
46 # also select the object in the display
47 displayData = Belle2.PyStoreObj("DisplayData")
48 displayData.create()
49 displayData.obj().select(p)
50 break
51
52
53main = b2.create_path()
54eventinfosetter = main.add_module('EventInfoSetter')
55eventinfosetter.param('evtNumList', [2000])
56
57eventinfoprinter = main.add_module('EventInfoPrinter')
58
59evtgeninput = main.add_module('EvtGenInput')
60
61components = ['CDC', 'KLM']
62add_simulation(main, components)
63
64
66kltrigger = PyTrigger()
67main.add_module(kltrigger)
68
69# if PyTrigger returns 0, we'll jump into an empty path
70# (skipping further modules in 'main': digitisation, tracking and display)
71emptypath = b2.create_path()
72kltrigger.if_false(emptypath)
73
74
75add_reconstruction(main, components)
76
77# default parameters
78display = main.add_module('Display')
79
80b2.process(main)
81print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
def initialize(self)
Definition: triggerKLs.py:31