10from ROOT
import Belle2
18hwneurotracks =
'CDCTriggerNeuroTracks'
19hwneuroinput2dfindertracks =
'CDCTriggerNNInput2DFinderTracks'
20hwneuroinputsegmenthits =
'CDCTriggerNNInputSegmentHits'
28hwsimneurotracks =
'TSimNeuroTracks'
32simneurotracks_swtssw2d =
'TRGCDCNeuroTracks'
33simsegmenthits =
'SimSegmentHits'
34sim2dtracks_swts =
'TRGCDC2DFinderTracks'
42 nullpath = basf2.create_path()
43 mfilter = basf2.register_module(
"CDCTriggerUnpacker", unpackNeuro=
True)
44 path.add_module(mfilter)
45 mfilter.if_value(
'<1', nullpath)
54 def param(self, params):
55 for key, value
in params.items():
56 setattr(self, key, value)
61 self.return_value(lower
and higher)
65lt2reco.param({
"filterarrayname":
"RecoTracks",
"lowerthan": 2})
68lt4reco.param({
"filterarrayname":
"RecoTracks",
"lowerthan": 4})
86 def neurotrack_allgoodquality(self):
89 if tr.getQualityVector() > 0:
111 print(
"some kind of error")
115def add_nnta_gzip_test_output(
121 excludeBranchNames=[],
126 outpaths.append([
".random_"+str(x), basf2.create_path()])
133 rm.if_value(
'==0', outpaths[0][1])
134 rm.if_value(
'==1', outpaths[1][1])
135 rm.if_value(
'==2', outpaths[2][1])
136 rm.if_value(
'==3', outpaths[3][1])
138 nnta = basf2.register_module(
nntd.nntd())
139 nnta.param({
"filename": baseAnaFileName+p[0]+
".pkl",
"netname":
"hardware"})
140 p[1].add_module(nnta)
141 p[1].add_module(
'CDCTriggerNeuroData',
143 NeuroTrackInputMode=
False,
144 inputCollectionName=hwneuroinput2dfindertracks,
147 hitCollectionName=hwneuroinputsegmenthits,
148 EventTimeName=
"CDCTriggerNeuroETFT0",
149 targetCollectionName=
'RecoTracks',
150 trainOnRecoTracks=
True,
151 gzipFilename=baseGzipFileName+p[0]+
".gz",
152 configFileName=configFileName,
153 writeconfigFileName=baseGzipFileName.split(
"/gzip")[0]+
"/"+configFileName.split(
'/')[-1],
155 if p[0] ==
".random_3":
156 p[1].add_module(
"RootOutput", outputFileName=baseOutputFileName +
157 p[0]+
".root", excludeBranchNames=excludeBranchNames, branchNames=branchNames)
160def add_nnta_gzip_output(path, baseAnaFileName, configFileName, baseGzipFileName):
164 outpaths.append([
".random_"+str(x), basf2.create_path()])
171 rm.if_value(
'==0', outpaths[0][1])
172 rm.if_value(
'==1', outpaths[1][1])
173 rm.if_value(
'==2', outpaths[2][1])
174 rm.if_value(
'==3', outpaths[3][1])
176 nnta = basf2.register_module(
nntd.nntd())
177 nnta.param({
"filename": baseAnaFileName+p[0]+
".pkl",
"netname":
"hardware"})
178 p[1].add_module(nnta)
179 p[1].add_module(
'CDCTriggerNeuroData',
181 NeuroTrackInputMode=
False,
182 inputCollectionName=hwneuroinput2dfindertracks,
185 hitCollectionName=hwneuroinputsegmenthits,
186 EventTimeName=
"CDCTriggerNeuroETFT0",
187 targetCollectionName=
'RecoTracks',
188 trainOnRecoTracks=
True,
189 gzipFilename=baseGzipFileName+p[0]+
".gz",
190 configFileName=configFileName,
191 writeconfigFileName=baseGzipFileName.split(
"/gzip")[0]+
"/"+configFileName.split(
'/')[-1],
201 excludeBranchNames=[],
206 outpaths.append([
".random_"+str(x), basf2.create_path()])
213 rm.if_value(
'==0', outpaths[0][1])
214 rm.if_value(
'==1', outpaths[1][1])
215 rm.if_value(
'==2', outpaths[2][1])
216 rm.if_value(
'==3', outpaths[3][1])
218 nnta = basf2.register_module(
nntd.nntd())
219 nnta.param({
"filename": baseAnaFileName+p[0]+
".pkl",
"netname":
"hardware"})
220 p[1].add_module(
"RootOutput", outputFileName=baseOutputFileName +
221 p[0]+
".root", excludeBranchNames=excludeBranchNames, branchNames=branchNames)
222 p[1].add_module(nnta)
223 p[1].add_module(
'CDCTriggerNeuroData',
225 NeuroTrackInputMode=
False,
226 inputCollectionName=hwneuroinput2dfindertracks,
229 hitCollectionName=hwneuroinputsegmenthits,
230 EventTimeName=
"CDCTriggerNeuroETFT0",
231 targetCollectionName=
'RecoTracks',
232 trainOnRecoTracks=
True,
233 gzipFilename=baseGzipFileName+p[0]+
".gz",
234 configFileName=configFileName,
235 writeconfigFileName=baseGzipFileName.split(
"/gzip")[0]+
"/"+configFileName.split(
'/')[-1],
239def add_nnta_root_output(path, baseOutputFileName, baseAnaFileName, excludeBranchNames=[], branchNames=[]):
243 outpaths.append([
".random_"+str(x), basf2.create_path()])
250 rm.if_value(
'==0', outpaths[0][1])
251 rm.if_value(
'==1', outpaths[1][1])
252 rm.if_value(
'==2', outpaths[2][1])
253 rm.if_value(
'==3', outpaths[3][1])
255 nnta = basf2.register_module(
nntd.nntd())
256 nnta.param({
"filename": baseAnaFileName+p[0]+
".pkl",
"netname":
"hardware"})
257 p[1].add_module(
"RootOutput", outputFileName=baseOutputFileName +
258 p[0]+
".root", excludeBranchNames=excludeBranchNames, branchNames=branchNames)
259 p[1].add_module(nnta)
262def add_neuro_unpacker(path, debug_level=4, debugout=False, **kwargs):
264 unpacker = basf2.register_module(
'CDCTriggerUnpacker')
266 unpacker.logging.log_level = basf2.LogLevel.DEBUG
267 unpacker.logging.debug_level = debug_level
268 unpacker.logging.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
270 unpacker.param(
'headerSize', 3)
272 unpacker.param(
'unpackTracker2D',
False)
274 unpacker.param(
'decode2DFinderTrack',
False)
276 unpacker.param(
'decode2DFinderInput',
False)
277 unpacker.param(
'2DNodeId', [
282 unpacker.param(
'NeuroNodeId', [
288 if 'useDB' in kwargs:
289 unpacker.param(
'useDB', kwargs[
'useDB'])
291 unpacker.param(
'useDB',
True)
293 if 'sim13dt' in kwargs:
294 unpacker.param(
'sim13dt', kwargs[
'sim13dt'])
296 unpacker.param(
'sim13dt',
False)
297 unpacker.param(
'unpackNeuro',
True)
298 unpacker.param(
'decodeNeuro',
True)
299 path.add_module(unpacker)
302def add_neuro_2d_unpackers(path, debug_level=4, debugout=False, **kwargs):
304 unpacker = basf2.register_module(
'CDCTriggerUnpacker')
306 unpacker.logging.log_level = basf2.LogLevel.DEBUG
307 unpacker.logging.debug_level = debug_level
308 unpacker.logging.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
310 unpacker.param(
'headerSize', 3)
312 unpacker.param(
'unpackTracker2D',
True)
314 unpacker.param(
'decode2DFinderTrack',
True)
316 unpacker.param(
'decode2DFinderInput',
True)
317 unpacker.param(
'2DNodeId', [
323 unpacker.param(
'NeuroNodeId', [
329 if 'useDB' in kwargs:
330 unpacker.param(
'useDB', kwargs[
'useDB'])
332 unpacker.param(
'useDB',
True)
334 if 'sim13dt' in kwargs:
335 unpacker.param(
'sim13dt', kwargs[
'sim13dt'])
337 unpacker.param(
'sim13dt',
False)
338 unpacker.param(
'unpackNeuro',
True)
339 unpacker.param(
'decodeNeuro',
True)
340 path.add_module(unpacker)
343def add_neurotrigger_sim(path, nntweightfile=None, debug_level=4, debugout=False, **kwargs):
344 nnt = basf2.register_module(
'CDCTriggerNeuro')
345 if 'inputCollectionName' in kwargs:
346 nnt.param(
'inputCollectionName', kwargs[
'inputCollectionName'])
348 nnt.param(
'inputCollectionName', hwneuroinput2dfindertracks)
349 if 'outputCollectionName' in kwargs:
350 nnt.param(
'outputCollectionName', kwargs[
'outputCollectionName'])
352 nnt.param(
'outputCollectionName', hwsimneurotracks)
353 if 'hitCollectionName' in kwargs:
354 nnt.param(
'hitCollectionName', kwargs[
'hitCollectionName'])
356 nnt.param(
'hitCollectionName', hwneuroinputsegmenthits)
357 if 'writeMLPinput' in kwargs:
358 nnt.param(
'writeMLPinput', kwargs[
'writeMLPinput'])
360 nnt.param(
'writeMLPinput',
True)
361 if 'fixedPoint' in kwargs:
362 nnt.param(
'fixedPoint', kwargs[
'fixedPoint'])
364 nnt.param(
'fixedPoint',
True)
365 if nntweightfile
is not None:
368 if 'et_option' in kwargs:
369 nnt.param(
'et_option', kwargs[
'et_option'])
370 if 'EventTimeName' in kwargs:
371 nnt.param(
'EventTimeName', kwargs[
'EventTimeName'])
373 nnt.logging.log_level = basf2.LogLevel.DEBUG
374 nnt.logging.debug_level = debug_level
378def add_neurotrigger_hw(path, nntweightfile=None, debug_level=4, debugout=False, **kwargs):
379 nnt = basf2.register_module(
'CDCTriggerNeuro')
380 if 'inputCollectionName' in kwargs:
381 nnt.param(
'inputCollectionName', kwargs[
'inputCollectionName'])
383 nnt.param(
'inputCollectionName', hwneurotracks)
384 if 'outputCollectionName' in kwargs:
385 nnt.param(
'outputCollectionName', kwargs[
'outputCollectionName'])
387 nnt.param(
'outputCollectionName', hwsimneurotracks)
388 if 'hitCollectionName' in kwargs:
389 nnt.param(
'hitCollectionName', kwargs[
'hitCollectionName'])
391 nnt.param(
'hitCollectionName', hwneuroinputsegmenthits)
392 if 'writeMLPinput' in kwargs:
393 nnt.param(
'writeMLPinput', kwargs[
'writeMLPinput'])
395 nnt.param(
'writeMLPinput',
True)
396 if 'fixedPoint' in kwargs:
397 nnt.param(
'fixedPoint', kwargs[
'fixedPoint'])
399 nnt.param(
'fixedPoint',
True)
400 if 'realinputCollectonName' in kwargs:
401 nnt.param(
'realinputCollectionName', kwargs[
'realinputCollectionName'])
403 nnt.param(
'realinputCollectionName', hwneuroinput2dfindertracks)
405 if nntweightfile
is not None:
407 nnt.param(
'NeuroHWTrackInputMode',
True)
408 if 'et_option' in kwargs:
409 nnt.param(
'et_option', kwargs[
'et_option'])
411 nnt.param(
'et_option',
'etfhwin')
413 if 'EventTimeName' in kwargs:
414 nnt.param(
'EventTimeName', kwargs[
'EventTimeName'])
416 nnt.param(
'EventTimeName',
'CDCTriggerNeuroETFT0')
418 nnt.logging.log_level = basf2.LogLevel.DEBUG
419 nnt.logging.debug_level = debug_level
423def add_neuro_simulation(path, nntweightfile=None, **kwargs):
424 nnt = basf2.register_module(
'CDCTriggerNeuro')
425 tsf = basf2.register_module(
'CDCTriggerTSF')
426 if "InnerTSLUTFile" in kwargs:
427 tsf.param(
"InnerTSLUTFile", kwargs[
"InnerTSLUTFile"])
430 if "OuterTSLUTFile" in kwargs:
431 tsf.param(
"OuterTSLUTFile", kwargs[
"OuterTSLUTFile"])
434 tsf.param(
"TSHitCollectionName", simsegmenthits)
435 tsf.param(
"CDCHitCollectionName",
"CDCHits")
436 if "relateAllHits" in kwargs:
437 tsf.param(
"relateAllHits", kwargs[
"relateAllHits"])
438 if "makeRecoLRTable" in kwargs:
439 tsf.param(
"makeRecoLRTable", kwargs[
"makeRecoLRTable"])
440 if "outerRecoLRTableFilename" in kwargs:
441 tsf.param(
"outerRecoLRTableFilename", kwargs[
"outerRecoLRTableFilename"])
442 if "innerRecoLRTableFilename" in kwargs:
443 tsf.param(
"innerRecoLRTableFilename", kwargs[
"innerRecoLRTableFilename"])
444 if "makeTrueLRTable" in kwargs:
445 tsf.param(
"makeTrueLRTable", kwargs[
"makeTrueLRTable"])
447 path.add_module(
'CDCTrigger2DFinder',
448 minHits=4, minHitsShort=4, minPt=0.3,
449 hitCollectionName=simsegmenthits,
450 outputCollectionName=sim2dtracks_swts)
451 if nntweightfile
is not None:
453 if 'et_option' in kwargs:
454 nnt.param(
'et_option', kwargs[
'et_option'])
455 nnt.param(
'inputCollectionName', sim2dtracks_swts)
456 nnt.param(
'outputCollectionName', simneurotracks_swtssw2d)
457 nnt.param(
'hitCollectionName', simsegmenthits)
458 nnt.param(
'writeMLPinput',
True)
459 nnt.param(
'fixedPoint',
False)
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...
A (simplified) python wrapper for StoreArray.
def neurotrack_allgoodquality(self)