Belle II Software  release-06-01-15
neurotrigger.py
1 
8 
9 import basf2
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 def filterTRG(path):
41  nullpath = basf2.create_path()
42  mfilter = basf2.register_module("CDCTriggerUnpacker", unpackNeuro=True)
43  path.add_module(mfilter)
44  mfilter.if_value('<1', nullpath)
45 
46 
47 class nnt_eventfilter(basf2.Module):
48  def initialize(self):
49  self.tracksegmentsnametracksegmentsname = hwneuroinputsegmenthits,
50  self.twodtracksnametwodtracksname = hwneuroinput2dfindertracks,
51  self.neurotracksnameneurotracksname = hwneurotracks,
52  self.recotracksnamerecotracksname = "RecoTracks"
53  self.nullpathnullpath = basf2.create_path()
54 
55  def event(self):
56  self.return_value(bool(self.neurotrack_allgoodqualityneurotrack_allgoodquality()))
57  self.if_false(self.nullpathnullpath)
58 
59  def hastrginfo(self):
60  return bool(Belle2.PyStoreArray(self.twodtracksnametwodtracksname).getEntries() > 0)
61 
62  def neurotrack_allgoodquality(self):
63  isgoodquality = True
64  for tr in Belle2.PyStoreArray("CDCTriggerNeuroTracks"):
65  if tr.getQualityVector() > 0:
66  isgoodquality = False
67  break
68  return isgoodquality
69 
70 
71 def add_neuro_unpacker(path, debug_level=4, debugout=False, **kwargs):
72  #
73  unpacker = basf2.register_module('CDCTriggerUnpacker')
74  if debugout:
75  unpacker.logging.log_level = basf2.LogLevel.DEBUG
76  unpacker.logging.debug_level = debug_level
77  unpacker.logging.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
78  # size (number of words) of the Belle2Link header
79  unpacker.param('headerSize', 3)
80  # unpack the data from the 2D tracker and save its Bitstream
81  unpacker.param('unpackTracker2D', False)
82  # make CDCTriggerTrack and CDCTriggerSegmentHit objects from the 2D output
83  unpacker.param('decode2DFinderTrack', False)
84  # make CDCTriggerSegmentHit objects from the 2D input
85  unpacker.param('decode2DFinderInput', False)
86  unpacker.param('2DNodeId', [
87  [0x11000001, 0],
88  [0x11000001, 1],
89  [0x11000002, 0],
90  [0x11000002, 1]])
91  unpacker.param('NeuroNodeId', [
92  [0x11000005, 0],
93  [0x11000005, 1],
94  [0x11000006, 0],
95  [0x11000006, 1],
96  ])
97  if 'useDB' in kwargs:
98  unpacker.param('useDB', kwargs['useDB'])
99  else:
100  unpacker.param('useDB', True)
101 
102  if 'sim13dt' in kwargs:
103  unpacker.param('sim13dt', kwargs['sim13dt'])
104  else:
105  unpacker.param('sim13dt', False)
106  unpacker.param('unpackNeuro', True)
107  unpacker.param('decodeNeuro', True)
108  path.add_module(unpacker)
109 
110 
111 def add_neuro_2d_unpackers(path, debug_level=4, debugout=False, **kwargs):
112  #
113  unpacker = basf2.register_module('CDCTriggerUnpacker')
114  if debugout:
115  unpacker.logging.log_level = basf2.LogLevel.DEBUG
116  unpacker.logging.debug_level = debug_level
117  unpacker.logging.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
118  # size (number of words) of the Belle2Link header
119  unpacker.param('headerSize', 3)
120  # unpack the data from the 2D tracker and save its Bitstream
121  unpacker.param('unpackTracker2D', True)
122  # make CDCTriggerTrack and CDCTriggerSegmentHit objects from the 2D output
123  unpacker.param('decode2DFinderTrack', True)
124  # make CDCTriggerSegmentHit objects from the 2D input
125  unpacker.param('decode2DFinderInput', True)
126  unpacker.param('2DNodeId', [
127  [0x11000001, 0],
128  [0x11000001, 1],
129  [0x11000002, 0],
130  [0x11000002, 1],
131  ])
132  unpacker.param('NeuroNodeId', [
133  [0x11000005, 0],
134  [0x11000005, 1],
135  [0x11000006, 0],
136  [0x11000006, 1],
137  ])
138  if 'useDB' in kwargs:
139  unpacker.param('useDB', kwargs['useDB'])
140  else:
141  unpacker.param('useDB', True)
142 
143  if 'sim13dt' in kwargs:
144  unpacker.param('sim13dt', kwargs['sim13dt'])
145  else:
146  unpacker.param('sim13dt', False)
147  unpacker.param('unpackNeuro', True)
148  unpacker.param('decodeNeuro', True)
149  path.add_module(unpacker)
150 
151 
152 def add_neurotrigger_sim(path, nntweightfile=None, debug_level=4, debugout=False, **kwargs):
153  nnt = basf2.register_module('CDCTriggerNeuro')
154  if 'inputCollectionName' in kwargs:
155  nnt.param('inputCollectionName', kwargs['inputCollectionName'])
156  else:
157  nnt.param('inputCollectionName', hwneuroinput2dfindertracks)
158  if 'outputCollectionName' in kwargs:
159  nnt.param('outputCollectionName', kwargs['outputCollectionName'])
160  else:
161  nnt.param('outputCollectionName', hwsimneurotracks)
162  if 'hitCollectionName' in kwargs:
163  nnt.param('hitCollectionName', kwargs['hitCollectionName'])
164  else:
165  nnt.param('hitCollectionName', hwneuroinputsegmenthits)
166  if 'writeMLPinput' in kwargs:
167  nnt.param('writeMLPinput', kwargs['writeMLPinput'])
168  else:
169  nnt.param('writeMLPinput', True)
170  if 'fixedPoint' in kwargs:
171  nnt.param('fixedPoint', kwargs['fixedPoint'])
172  else:
173  nnt.param('fixedPoint', True)
174  if nntweightfile is not None:
175  nnt.param('filename', Belle2.FileSystem.findFile(nntweightfile))
176 
177  if 'et_option' in kwargs:
178  nnt.param('et_option', kwargs['et_option'])
179  if 'EventTimeName' in kwargs:
180  nnt.param('EventTimeName', kwargs['EventTimeName'])
181  if debugout:
182  nnt.logging.log_level = basf2.LogLevel.DEBUG
183  nnt.logging.debug_level = debug_level
184  path.add_module(nnt)
185 
186 
187 def add_neurotrigger_hw(path, nntweightfile=None, debug_level=4, debugout=False, **kwargs):
188  nnt = basf2.register_module('CDCTriggerNeuro')
189  if 'inputCollectionName' in kwargs:
190  nnt.param('inputCollectionName', kwargs['inputCollectionName'])
191  else:
192  nnt.param('inputCollectionName', hwneurotracks)
193  if 'outputCollectionName' in kwargs:
194  nnt.param('outputCollectionName', kwargs['outputCollectionName'])
195  else:
196  nnt.param('outputCollectionName', hwsimneurotracks)
197  if 'hitCollectionName' in kwargs:
198  nnt.param('hitCollectionName', kwargs['hitCollectionName'])
199  else:
200  nnt.param('hitCollectionName', hwneuroinputsegmenthits)
201  if 'writeMLPinput' in kwargs:
202  nnt.param('writeMLPinput', kwargs['writeMLPinput'])
203  else:
204  nnt.param('writeMLPinput', True)
205  if 'fixedPoint' in kwargs:
206  nnt.param('fixedPoint', kwargs['fixedPoint'])
207  else:
208  nnt.param('fixedPoint', True)
209  if 'realinputCollectonName' in kwargs:
210  nnt.param('realinputCollectionName', kwargs['realinputCollectionName'])
211  else:
212  nnt.param('realinputCollectionName', hwneuroinput2dfindertracks)
213 
214  if nntweightfile is not None:
215  nnt.param('filename', Belle2.FileSystem.findFile(nntweightfile))
216  nnt.param('NeuroHWTrackInputMode', True)
217  if 'et_option' in kwargs:
218  nnt.param('et_option', kwargs['et_option'])
219  else:
220  nnt.param('et_option', 'etf_or_fastestpriority')
221 
222  if 'EventTimeName' in kwargs:
223  nnt.param('EventTimeName', kwargs['EventTimeName'])
224  else:
225  nnt.param('EventTimeName', 'CDCTriggerNeuroETFT0')
226  if debugout:
227  nnt.logging.log_level = basf2.LogLevel.DEBUG
228  nnt.logging.debug_level = debug_level
229  path.add_module(nnt)
230 
231 
232 def add_neuro_simulation(path, nntweightfile=None, **kwargs):
233  nnt = basf2.register_module('CDCTriggerNeuro')
234  tsf = basf2.register_module('CDCTriggerTSF')
235  if "InnerTSLUTFile" in kwargs:
236  tsf.param("InnerTSLUTFile", kwargs["InnerTSLUTFile"])
237  else:
238  tsf.param("InnerTSLUTFile", Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_v2.2.coe"))
239  if "OuterTSLUTFile" in kwargs:
240  tsf.param("OuterTSLUTFile", kwargs["OuterTSLUTFile"])
241  else:
242  tsf.param("OuterTSLUTFile", Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_v2.2.coe"))
243  tsf.param("TSHitCollectionName", simsegmenthits)
244  path.add_module(tsf)
245  path.add_module('CDCTrigger2DFinder',
246  minHits=4, minHitsShort=4, minPt=0.3,
247  hitCollectionName=simsegmenthits,
248  outputCollectionName=sim2dtracks_swts)
249  if nntweightfile is not None:
250  nnt.param('filename', Belle2.FileSystem.findFile(nntweightfile))
251  nnt.param('inputCollectionName', sim2dtracks_swts)
252  nnt.param('outputCollectionName', simneurotracks_swtssw2d)
253  nnt.param('hitCollectionName', simsegmenthits)
254  nnt.param('writeMLPinput', True)
255  nnt.param('fixedPoint', True)
256  path.add_module(nnt)
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