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