Belle II Software development
gdltrigger.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12import modularAnalysis as ma
13
14
15def add_gdl_trigger(path, SimulationMode=1, FilterEvents=False, simulateT0jitter=False, Belle2Phase="Phase2"):
16 """
17 add the gdl module to path
18 @param path module is added to this path
19 @param SimulationMode the simulation mode in TSIM, 1: fast simulation,
20 trigger algorithm simulation only, no firmware simulation
21 2: full simulation, both trigger algorithm and firmware
22 are simulated
23 @param FilterEvents if True only the events that pass the L1 trigger will
24 survive simulation, the other are discarded.
25 Make sure you do need to filter events before you set
26 the value to True.
27 """
28 trggdl = b2.register_module('TRGGDL')
29 trggdl.param('SimulationMode', SimulationMode)
30 trggdl.param('Belle2Phase', Belle2Phase)
31 trggdl.param('simulateT0jitter', simulateT0jitter)
32 path.add_module(trggdl)
33 if FilterEvents:
34 ma.applyEventCuts('L1Trigger == 1', path)
35
36
37class TRGAbortGapFilter(b2.Module):
38 """
39 Reject events whose `coml1rvc` lies inside configured abort gaps.
40 The same nomenclature used in ``TRGGDLDQM`` module is used here for easy comparison of the code/logic.
41 """
42
43 def initialize(self):
44 """Initialize."""
45 import ROOT
46 self.entAry = ROOT.Belle2.PyStoreArray("TRGGDLUnpackerStores")
47 self.entAry.isRequired()
48 self.bevt = ROOT.Belle2.PyStoreObj("EventMetaData")
49 self.bevt.isRequired()
50 self.m_unpacker = ROOT.Belle2.PyDBObj("TRGGDLDBUnpacker")
51 self.abort_gaps = { # {experiment: [(min, max), ...]}
52 37: [
53 (544, 586), # gap 1
54 (1183, 1225) # gap 2
55 ],
56 39: [
57 (316, 358), # gap 1
58 (956, 998) # gap 2
59 ]
60 }
61
62 def beginRun(self):
63 """Begin run."""
64 if not self.bevt.isValid():
65 b2.B2FATAL("No valid EventMetaData object")
66
67 self.exp = self.bevt.getExperiment()
68 self.run = self.bevt.getRun()
69
70 self.run_filter = self.exp in self.abort_gaps
71 if not self.run_filter:
72 return
73
74 if not self.m_unpacker.isValid():
75 b2.B2FATAL("No valid payload for TRGGDLDBUnpacker")
76
77 self._e_coml1rvc = None
78 for i in range(320):
79 if self.m_unpacker.getLeafnames(i) == "coml1rvc":
80 self._e_coml1rvc = i
81 break
82
83 if not self._e_coml1rvc:
84 b2.B2FATAL(
85 "No leaf named `coml1rvc` in TRGGDLDBUnpacker payload "
86 f"in exp={self.exp} and run={self.run}"
87 )
88
89 def event(self):
90 """Event."""
91 self.return_value(1)
92
93 if not self.run_filter:
94 return
95
96 if (self.entAry.getEntries() == 0):
97 return
98
99 store = self.entAry[0]
100 coml1rvc = store.m_unpacker[self._e_coml1rvc]
101
102 for abort_gap_min, abort_gap_max in self.abort_gaps[self.exp]:
103 if abort_gap_min <= coml1rvc < abort_gap_max:
104 self.return_value(0)
105
106
107def filter_trigger_abort_gaps(path):
108 """
109 Add the ``TRGAbortGapFilter`` module and the relevant logic to the ``path`` to filter the events
110 in the trigger abort gaps.
111 """
112
113 empty = b2.Path()
114 abort_gap_filter = path.add_module(TRGAbortGapFilter())
115 abort_gap_filter.if_value('<1', empty)