307 for eventNumber
in range(options.nStart,nEvent):
309 rc = event.GetEvent(eventNumber)
311 if eventNumber%options.heartBeat==0:
313 print(
'run ',options.runNumber,
' event',eventNumber,
" ",tt)
319 board_id =
int(board.split(
'_')[1])
321 rc = bt.GetEvent(eventNumber)
322 if bt.n_hits < 1:
continue
323 if bt.n_hits > maxHits:
327 for boardx
in boards:
328 boardx_id =
int(boardx.split(
'_')[1])
332 if newT<0
or dt==0:
continue
334 if options.debug: print(
"found",eventNumber)
336 if key < 0 :
continue
338 if not board_id
in otherEvents:
339 otherEvents[board_id]={}
340 otherEvents[board_id][boardx_id]=[newT,theMap[newT]]
342 if found
and options.debug: print(
"+++",otherEvents)
344 if len(otherEvents)>1:
345 print(
"Houston we have a problem, more than one board match with other events",eventNumber,otherEvents)
346 for b
in otherEvents:
347 rc = boards[
"board_"+str(b)].GetEvent(eventNumber)
348 txt =
"mult "+str( boards[
"board_"+str(b)].n_hits )
349 for bx
in otherEvents[b]:
350 rc = boards[
"board_"+str(bx)].GetEvent(otherEvents[b][bx][1])
351 txt+=
" " +str( boards[
"board_"+str(bx)].n_hits )
355 if len(otherEvents)==0:
356 if maxHits>mufi_hitThreshold:
357 otherEvents[maxBoard]={}
358 otherEvents[maxBoard][maxBoard] = [T,eventNumber]
361 thisBoard = list(otherEvents.keys())[0]
362 otherEvents[thisBoard][thisBoard] = [T,eventNumber]
364 for x
in otherEvents:
365 for b
in otherEvents[x]:
366 tmp = otherEvents[x][b]
367 listOfBoards[b]=tmp[1]
370 if options.debug: print(
"---",listOfBoards)
372 header.SetEventTime(event.timestamp)
373 header.SetRunId(options.runNumber)
374 if options.debug: print(
'event:',eventNumber,event.timestamp)
379 digiMuFilter.Delete()
380 digiMuFilterStore = {}
382 for board_id
in listOfBoards:
383 board =
"board_"+str(board_id)
385 if board
in boardMaps[
'Scifi']:
386 station,mat = boardMaps[
'Scifi'][board]
387 elif board
in boardMaps[
'MuFilter']:
390 print(board+
' not known. Serious error, stop')
393 rc = bt.GetEvent(listOfBoards[board_id])
394 for n
in range(bt.n_hits):
397 print(scifi,board_id,bt.tofpet_id[n],bt.tofpet_channel[n],bt.tac[n],bt.t_coarse[n],bt.t_fine[n],bt.v_coarse[n],bt.v_fine[n])
398 tofpet_id = bt.tofpet_id[n]
399 tofpet_channel = bt.tofpet_channel[n]
401 TDC,QDC,Chi2ndof,satur =
comb_calibration(board_id,tofpet_id,tofpet_channel,tac,bt.v_coarse[n],bt.v_fine[n],bt.t_coarse[n],bt.t_fine[n])
402 if Chi2ndof > chi2Max:
403 if QDC>1E20: QDC = 997.
404 if QDC != QDC: QDC = 998.
407 elif satur > saturationLimit
or QDC>1E20
or QDC != QDC:
408 if QDC>1E20: QDC = 987.
410 print(
'inf',board_id,bt.tofpet_id[n],bt.tofpet_channel[n],bt.tac[n],bt.v_coarse[n],bt.v_fine[n],TDC-bt.t_coarse[n],eventNumber,Chi2ndof)
411 if QDC != QDC: QDC = 988.
413 print(
'nan',board_id,bt.tofpet_id[n],bt.tofpet_channel[n],bt.tac[n],bt.v_coarse[n],bt.v_fine[n],\
414 TDC-bt.t_coarse[n],TDC,bt.t_coarse[n],eventNumber,Chi2ndof)
415 A =
int(min( QDC,1000))
416 B = min(satur,999)/1000.
419 elif Chi2ndof > chi2Max:
423 print(
'calibrated: tdc = ',TDC,
' qdc = ',QDC)
427 slot = bt.tofpet_id[n]
428 tmp = boardMaps[
'MuFilter'][board][slots[slot]]
429 system = tmp.split(
'_')[0]
430 key = (slot%2)*1000 + bt.tofpet_channel[n]
431 if options.debug: print(system,key,board,bt.tofpet_id[n],bt.tofpet_id[n]%2,bt.tofpet_channel[n])
433 if not key
in TofpetMap[system]:
434 print(
'key does not exist',key)
435 print(system, key, TofpetMap[system])
437 sipmChannel = TofpetMap[system][key]-1
438 nSiPMs = abs(offMap[tmp][1])
439 nSides = abs(offMap[tmp][2])
440 direction =
int(offMap[tmp][1]/nSiPMs)
441 detID = offMap[tmp][0] + direction*(sipmChannel//(nSiPMs))
442 sipm_number = sipmChannel%(nSiPMs)
443 if tmp.find(
'Right')>0:
444 sipm_number += nSiPMs
445 if not detID
in digiMuFilterStore:
446 digiMuFilterStore[detID] = ROOT.MuFilterHit(detID,nSiPMs,nSides)
447 test = digiMuFilterStore[detID].GetSignal(sipm_number)
448 digiMuFilterStore[detID].SetDigi(QDC,TDC,sipm_number)
449 if mask: digiMuFilterStore[detID].SetMasked(sipm_number)
453 print(
'create mu hit: ',detID,tmp,system,slot,offMap[tmp],sipmChannel,nSiPMs,nSides,test,slot)
454 print(
' ',detID,sipm_number,QDC,TDC)
455 if test>0
or detID%1000>200
or sipm_number>15:
456 print(
'what goes wrong?',detID,sipm_number,system,key,board,bt.tofpet_id[n],bt.tofpet_channel[n],test)
459 chan =
channel(bt.tofpet_id[n],bt.tofpet_channel[n],mat)
461 if station[2]==
"Y": orientation = 0
462 sipmLocal = (chan - mat*512)
463 sipmID = 1000000*
int(station[1]) + 100000*orientation + 10000*mat + 1000*(sipmLocal//128) + chan%128
464 if not sipmID
in digiSciFiStore: digiSciFiStore[sipmID] = ROOT.sndScifiHit(sipmID)
465 digiSciFiStore[sipmID].SetDigi(QDC,TDC)
466 if mask: digiSciFiStore[sipmID].setInvalid()
468 print(
'create scifi hit: tdc = ',board,sipmID,QDC,TDC)
469 print(
'tofpet:', bt.tofpet_id[n],bt.tofpet_channel[n],mat,chan)
470 print(station[1],station[2],mat,chan,
int(chan/128)%4,chan%128)
472 for sipmID
in digiSciFiStore:
473 if digiSciFi.GetSize() == indexSciFi: digiSciFi.Expand(indexSciFi+100)
474 digiSciFi[indexSciFi]=digiSciFiStore[sipmID]
476 for detID
in digiMuFilterStore:
477 if digiMuFilter.GetSize() == indexMuFilter: digiMuFilter.Expand(indexMuFilter+100)
478 digiMuFilter[indexMuFilter]=digiMuFilterStore[detID]
484 for k
in range(digiSciFi.GetEntries()):
486 if not d.isValid():
continue
487 hitDict[d.GetDetectorID()] = k
488 hitList = list(hitDict.keys())
494 last = len(hitList)-1
495 hitlist = ROOT.std.vector(
"sndScifiHit*")()
496 for i
in range(len(hitList)):
497 if i==0
and len(hitList)>1:
continue
501 if (c-cprev)!=1
or c==hitList[last]:
506 hitlist.push_back( digiSciFi[hitDict[aHit]])
507 print(aHit,hitDict[aHit],digiSciFi[hitDict[aHit]].GetDetectorID())
508 print(hitlist.size())
509 aCluster = ROOT.sndCluster(first,N,hitlist,scifiDet)
510 print(
"cluster created")
511 if clusScifi.GetSize() == index: clusScifi.Expand(index+10)
512 clusScifi[index]=aCluster
521 print(
'====> number of created hits',ncreated)
523 print(
'number of events processed',sTree.GetEntries(),f0.event.GetEntries())