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