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