Belle II Software  release-05-01-25
neurotrigger.py
1 import basf2
2 from ROOT import Belle2
3 
4 
7 
8 # standard name for hardware tracks coming from the unpacker
9 hwneurotracks = 'CDCTriggerNeuroTracks'
10 hwneuroinput2dfindertracks = 'CDCTriggerNNInput2DFinderTracks'
11 hwneuroinputsegmenthits = 'CDCTriggerNNInputSegmentHits'
12 
13 
14 # sofware neurotracks, that were calculated from hardware 2d-inputtracks
15 # and hardware stereo track segments coming over all 48cc within one event
16 # OR
17 # standard name for tracks resulting from the software neurotrigger
18 # module when it is rerun on the hardware tracks
19 hwsimneurotracks = 'TSimNeuroTracks'
20 
21 # software neurotracks, which were all simulated in software starting only
22 # from real CDCHITs. Also simulated track segments and 2dtracks are needed therefore.
23 simneurotracks_swtssw2d = 'TRGCDCNeuroTracks'
24 simsegmenthits = 'SimSegmentHits'
25 sim2dtracks_swts = 'TRGCDC2DFinderTracks'
26 
27 
30 
31 
32 class filterTRG(basf2.Module):
33  def initialize(self, branchname=hwneuroinput2dfindertracks):
34  self.branchname = branchname
35  self.nullpath = basf2.create_path()
36 
37  def event(self):
38  self.return_value(bool(Belle2.PyStoreArray(self.branchname).getEntries() > 0))
39  self.if_false(self.nullpath)
40 
41 
42 def add_neuro_unpacker(path, debug_level=4, debugout=False, **kwargs):
43  #
44  unpacker = basf2.register_module('CDCTriggerUnpacker')
45  if debugout:
46  unpacker.logging.log_level = LogLevel.DEBUG
47  unpacker.logging.debug_level = debug_level
48  unpacker.logging.set_info(LogLevel.DEBUG, LogInfo.LEVEL | LogInfo.MESSAGE)
49  # size (number of words) of the Belle2Link header
50  unpacker.param('headerSize', 3)
51  # unpack the data from the 2D tracker and save its Bitstream
52  unpacker.param('unpackTracker2D', False)
53  # make CDCTriggerTrack and CDCTriggerSegmentHit objects from the 2D output
54  unpacker.param('decode2DFinderTrack', False)
55  # make CDCTriggerSegmentHit objects from the 2D input
56  unpacker.param('decode2DFinderInput', False)
57  unpacker.param('2DNodeId', [
58  [0x11000001, 0],
59  [0x11000001, 1],
60  [0x11000002, 0],
61  [0x11000002, 1]])
62  unpacker.param('NeuroNodeId', [
63  [0x11000005, 0],
64  [0x11000005, 1],
65  [0x11000006, 0],
66  [0x11000006, 1],
67  ])
68  if 'useDB' in kwargs:
69  unpacker.param('useDB', kwargs['useDB'])
70  else:
71  unpacker.param('useDB', True)
72 
73  if 'sim13dt' in kwargs:
74  unpacker.param('sim13dt', kwargs['sim13dt'])
75  else:
76  unpacker.param('sim13dt', False)
77  unpacker.param('unpackNeuro', True)
78  unpacker.param('decodeNeuro', True)
79  path.add_module(unpacker)
80 
81 
82 def add_neuro_2d_unpackers(path, debug_level=4, debugout=False, **kwargs):
83  #
84  unpacker = basf2.register_module('CDCTriggerUnpacker')
85  if debugout:
86  unpacker.logging.log_level = LogLevel.DEBUG
87  unpacker.logging.debug_level = debug_level
88  unpacker.logging.set_info(LogLevel.DEBUG, LogInfo.LEVEL | LogInfo.MESSAGE)
89  # size (number of words) of the Belle2Link header
90  unpacker.param('headerSize', 3)
91  # unpack the data from the 2D tracker and save its Bitstream
92  unpacker.param('unpackTracker2D', True)
93  # make CDCTriggerTrack and CDCTriggerSegmentHit objects from the 2D output
94  unpacker.param('decode2DFinderTrack', True)
95  # make CDCTriggerSegmentHit objects from the 2D input
96  unpacker.param('decode2DFinderInput', True)
97  unpacker.param('2DNodeId', [
98  [0x11000001, 0],
99  [0x11000001, 1],
100  [0x11000002, 0],
101  [0x11000002, 1],
102  ])
103  unpacker.param('NeuroNodeId', [
104  [0x11000005, 0],
105  [0x11000005, 1],
106  [0x11000006, 0],
107  [0x11000006, 1],
108  ])
109  if 'useDB' in kwargs:
110  unpacker.param('useDB', kwargs['useDB'])
111  else:
112  unpacker.param('useDB', True)
113 
114  if 'sim13dt' in kwargs:
115  unpacker.param('sim13dt', kwargs['sim13dt'])
116  else:
117  unpacker.param('sim13dt', False)
118  unpacker.param('unpackNeuro', True)
119  unpacker.param('decodeNeuro', True)
120  path.add_module(unpacker)
121 
122 
123 def add_neurotrigger_sim(path, nntweightfile=None, debug_level=4, debugout=False, **kwargs):
124  nnt = basf2.register_module('CDCTriggerNeuro')
125  if 'inputCollectionName' in kwargs:
126  nnt.param('inputCollectionName', kwargs['inputCollectionName'])
127  else:
128  nnt.param('inputCollectionName', hwneuroinput2dfindertracks)
129  if 'outputCollectionName' in kwargs:
130  nnt.param('outputCollectionName', kwargs['outputCollectionName'])
131  else:
132  nnt.param('outputCollectionName', hwsimneurotracks)
133  if 'hitCollectionName' in kwargs:
134  nnt.param('hitCollectionName', kwargs['hitCollectionName'])
135  else:
136  nnt.param('hitCollectionName', hwneuroinputsegmenthits)
137  if 'writeMLPinput' in kwargs:
138  nnt.param('writeMLPinput', kwargs['writeMLPinput'])
139  else:
140  nnt.param('writeMLPinput', True)
141  if 'fixedPoint' in kwargs:
142  nnt.param('fixedPoint', kwargs['fixedPoint'])
143  else:
144  nnt.param('fixedPoint', True)
145  if nntweightfile is not None:
146  nnt.param('filename', Belle2.FileSystem.findFile(nntweightfile))
147 
148  if 'et_option' in kwargs:
149  nnt.param('et_option', kwargs['et_option'])
150  if debugout:
151  nnt.logging.log_level = LogLevel.DEBUG
152  nnt.logging.debug_level = debug_level
153  path.add_module(nnt)
154 
155 
156 def add_neurotrigger_hw(path, nntweightfile=None, debug_level=4, debugout=False, **kwargs):
157  nnt = basf2.register_module('CDCTriggerNeuro')
158  if 'inputCollectionName' in kwargs:
159  nnt.param('inputCollectionName', kwargs['inputCollectionName'])
160  else:
161  nnt.param('inputCollectionName', hwneurotracks)
162  if 'outputCollectionName' in kwargs:
163  nnt.param('outputCollectionName', kwargs['outputCollectionName'])
164  else:
165  nnt.param('outputCollectionName', hwsimneurotracks)
166  if 'hitCollectionName' in kwargs:
167  nnt.param('hitCollectionName', kwargs['hitCollectionName'])
168  else:
169  nnt.param('hitCollectionName', hwneuroinputsegmenthits)
170  if 'writeMLPinput' in kwargs:
171  nnt.param('writeMLPinput', kwargs['writeMLPinput'])
172  else:
173  nnt.param('writeMLPinput', True)
174  if 'fixedPoint' in kwargs:
175  nnt.param('fixedPoint', kwargs['fixedPoint'])
176  else:
177  nnt.param('fixedPoint', True)
178  if 'realinputCollectonName' in kwargs:
179  nnt.param('realinputCollectionName', kwargs['realinputCollectionName'])
180  else:
181  nnt.param('realinputCollectionName', hwneuroinput2dfindertracks)
182 
183  if nntweightfile is not None:
184  nnt.param('filename', Belle2.FileSystem.findFile(nntweightfile))
185  nnt.param('NeuroHWTrackInputMode', True)
186  if 'et_option' in kwargs:
187  nnt.param('et_option', kwargs['et_option'])
188  if debugout:
189  nnt.logging.log_level = LogLevel.DEBUG
190  nnt.logging.debug_level = debug_level
191  path.add_module(nnt)
192 
193 
194 def add_neuro_simulation(path):
195  path.add_module('CDCTriggerTSF',
196  InnerTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_v2.2.coe"),
197  OuterTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_v2.2.coe"),
198  TSHitCollectionName=simsegmenthits)
199  path.add_module('CDCTrigger2DFinder',
200  minHits=4, minHitsShort=4, minPt=0.3,
201  hitCollectionName=simsegmenthits,
202  outputCollectionName=sim2dtracks_swts)
203  path.add_module('CDCTriggerNeuro',
204  inputCollectionName=sim2dtracks_swts,
205  outputCollectionName=simneurotracks_swtssw2d,
206  hitCollectionName=simsegmenthits,
207  writeMLPinput=True,
208  fixedPoint=True,
209  )
neurotrigger.filterTRG.nullpath
nullpath
Definition: neurotrigger.py:35
neurotrigger.filterTRG.branchname
branchname
Definition: neurotrigger.py:34
neurotrigger.filterTRG
Defining a filter for skipping trigger suppressed events in realdata:
Definition: neurotrigger.py:32
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58
Belle2::FileSystem::findFile
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:147