304 if 'simpleDisplay' not in h: ut.bookCanvas(h,key='simpleDisplay',title='simple event display',nx=1200,ny=1600,cx=1,cy=2)
305 h['simpleDisplay'].cd(1)
306 # TI18 coordinate system
311 if Setup == 'H6': zStart = 60.
312 if Setup == 'TP': zStart = -50. # old coordinate system with origin in middle of target
322 h['xmin'],h['xmax'] = xStart,xStart+110.
323 h['ymin'],h['ymax'] = yStart,yStart+110.
324 h['zmin'],h['zmax'] = zStart,zEnd
325 for d in ['xmin','xmax','ymin','ymax','zmin','zmax']: h['c'+d]=h[d]
326 ut.bookHist(h,'xz','; z [cm]; x [cm]',500,h['czmin'],h['czmax'],100,h['cxmin'],h['cxmax'])
327 ut.bookHist(h,'yz','; z [cm]; y [cm]',500,h['czmin'],h['czmax'],100,h['cymin'],h['cymax'])
329 proj = {1:'xz',2:'yz'}
335 A,B = ROOT.TVector3(),ROOT.TVector3()
336 ptext={0:' Y projection',1:' X projection'}
339 OT = sink.GetOutTree()
340 if withTrack==0 or withHoughTrack==0: OT = eventTree
341 if type(start) == type(1):
343 e = event.GetEntries()
348 if type(start) == type(1): rc = event.GetEvent(N)
349 else: rc = event.GetEvent(start[N])
350 if goodEvents and not goodEvent(event): continue
352 OT.Reco_MuonTracks = ROOT.TObjArray(10)
353 if withHoughTrack > 0:
354 rc = source.GetInTree().GetEvent(N)
355 # Delete SndlhcMuonReco kalman tracks container
356 for ht_task in HT_tasks.values():
357 ht_task.kalman_tracks.Delete()
358 if withHoughTrack==1:
359 HT_tasks['muon_reco_task_Sf'].Exec(0)
360 HT_tasks['muon_reco_task_DS'].Exec(0)
361 elif withHoughTrack==2:
362 HT_tasks['muon_reco_task_Sf'].Exec(0)
363 elif withHoughTrack==3:
364 HT_tasks['muon_reco_task_DS'].Exec(0)
365 elif withHoughTrack==4:
366 HT_tasks['muon_reco_task_nuInt'].Exec(0)
367 # Save the tracks in OT.Reco_MuonTracks object
368 for ht_task in HT_tasks.values():
369 for trk in ht_task.kalman_tracks:
370 OT.Reco_MuonTracks.Add(trk)
371 nHoughtracks = OT.Reco_MuonTracks.GetEntries()
372 if nHoughtracks>0: print('number of tracks by HT:', nHoughtracks)
375 # Delete SndlhcTracking fitted tracks container
376 trackTask.fittedTracks.Delete()
378 trackTask.ExecuteTask("ScifiDS")
380 trackTask.ExecuteTask("Scifi")
382 trackTask.ExecuteTask("DS")
384 for trk in trackTask.fittedTracks:
385 OT.Reco_MuonTracks.Add(trk)
386 ntracks = len(OT.Reco_MuonTracks) - nHoughtracks
387 if ntracks>0: print('number of tracks by ST:', ntracks)
388 nAlltracks = len(OT.Reco_MuonTracks)
389 if nAlltracks<nTracks: continue
392 for aTrack in OT.Reco_MuonTracks:
393 print(aTrack.__repr__())
394 mom = aTrack.getFittedState().getMom()
395 pos = aTrack.getFittedState().getPos()
399 T = event.EventHeader.GetEventTime()
400 runId = eventTree.EventHeader.GetRunId()
401 if Tprev >0: dT = T-Tprev
403 if nAlltracks > 0: print('total number of tracks: ', nAlltracks)
406 if event.FindBranch("Digi_ScifiHits"): digis.append(event.Digi_ScifiHits)
407 if event.FindBranch("Digi_MuFilterHits"): digis.append(event.Digi_MuFilterHits)
408 if event.FindBranch("Digi_MuFilterHit"): digis.append(event.Digi_MuFilterHit)
412 if empty: print( "event -> %i"%N)
415 h['hitCollectionX']= {'Veto':[0,ROOT.TGraphErrors()],'Scifi':[0,ROOT.TGraphErrors()],'DS':[0,ROOT.TGraphErrors()]}
416 h['hitCollectionY']= {'Veto':[0,ROOT.TGraphErrors()],'Scifi':[0,ROOT.TGraphErrors()],'US':[0,ROOT.TGraphErrors()],'DS':[0,ROOT.TGraphErrors()]}
418 h['hitColourX'] = {'Veto': [], 'Scifi': [], 'DS' : []}
419 h['hitColourY'] = {'Veto': [], 'Scifi' : [], 'US' : [], 'DS' : []}
420 h["markerCollection"] = []
422 h['firedChannelsX']= {'Veto':[0,0,0,0],'Scifi':[0,0,0],'DS':[0,0,0]}
423 h['firedChannelsY']= {'Veto':[0,0,0,0],'Scifi':[0,0,0],'US':[0,0,0,0],'DS':[0,0,0,0]}
424 systems = {1:'Veto',2:'US',3:'DS',0:'Scifi'}
425 for collection in ['hitCollectionX','hitCollectionY']:
426 for c in h[collection]:
427 rc=h[collection][c][1].SetName(c)
428 rc=h[collection][c][1].Set(0)
431 h["markerCollection"] = []
433 #Do we still use these lines? Seems no.
434 #And for events having all negative QDCs minT[1] is returned empty and the display crashes.
435 #dTs = "%5.2Fns"%(dT/u.snd_freq*1E9)
436 # find detector which triggered
437 #minT = firstTimeStamp(event)
438 #dTs+= " " + str(minT[1].GetDetectorID())
440 rc = h[ 'simpleDisplay'].cd(p)
447 detID = digi.GetDetectorID()
449 if digi.GetName() == 'MuFilterHit':
450 system = digi.GetSystem()
451 geo.modules['MuFilter'].GetPosition(detID,A,B)
452 sipmMult = len(digi.GetAllSignals(False,False))
453 if sipmMult<minSipmMult and (system==1 or system==2): continue
455 geo.modules['Scifi'].GetSiPMPosition(detID,A,B)
457 curPath = nav.GetPath()
458 tmp = curPath.rfind('/')
459 nav.cd(curPath[:tmp])
462 if not first and not with2Points:
465 globA, locA = array('d', [X[0], X[1], X[2]]), array('d', [X[0], X[1], X[2]])
467 nav.MasterToLocal(globA, locA)
469 if digi.isVertical():
470 collection = 'hitCollectionX'
472 sY = detSize[system][0]
474 collection = 'hitCollectionY'
476 sY = detSize[system][1]
477 c = h[collection][systems[system]]
478 rc = c[1].SetPoint(c[0], Z, Y)
479 rc = c[1].SetPointError(c[0], detSize[system][2], sY)
481 if hitColour == "q" :
484 ns = max(1,digi.GetnSides())
485 for side in range(ns):
486 for m in range(digi.GetnSiPMs()):
487 qdc = digi.GetSignal(m+side*digi.GetnSiPMs())
490 if this_qdc > max_QDC :
492 fillNode(curPath, ROOT.TColor.GetPalette()[int(this_qdc/max_QDC*(len(ROOT.TColor.GetPalette())-1))])
496 if digi.isVertical(): F = 'firedChannelsX'
497 else: F = 'firedChannelsY'
498 ns = max(1,digi.GetnSides())
499 for side in range(ns):
500 for m in range(digi.GetnSiPMs()):
501 qdc = digi.GetSignal(m+side*digi.GetnSiPMs())
502 if qdc < 0 and qdc > -900: h[F][systems[system]][1]+=1
504 h[F][systems[system]][0]+=1
505 if len(h[F][systems[system]]) < 2+side: continue
506 h[F][systems[system]][2+side]+=qdc
507 h['hitCollectionY']['Scifi'][1].SetMarkerColor(ROOT.kBlue+2)
508 h['hitCollectionX']['Scifi'][1].SetMarkerColor(ROOT.kBlue+2)
510 if hitColour == "q" :
511 for orientation in ['X', 'Y']:
513 density = np.clip(0, max_density, getSciFiHitDensity(h['hitCollection'+orientation]['Scifi'][1]))
514 for i in range(h['hitCollection'+orientation]['Scifi'][1].GetN()) :
515 h['hitColour'+orientation]['Scifi'].append(ROOT.TColor.GetPalette()[int(float(density[i])/max_density*(len(ROOT.TColor.GetPalette())-1))])
517 drawLegend(max_density, max_QDC, 5)
523 for collection in ['hitCollectionX','hitCollectionY']:
524 h['simpleDisplay'].cd(k)
525 drawInfo(h['simpleDisplay'], k, runId, N, T)
527 for c in h[collection]:
528 F = collection.replace('hitCollection','firedChannels')
529 pj = collection.split('ion')[1]
530 if pj =="X" or c=="Scifi":
531 atext = "%1s %5s %3i +:%3i -:%3i qdc :%5.1F"%(pj,c,h[collection][c][1].GetN(),h[F][c][0],h[F][c][1],h[F][c][2])
533 atext = "%1s %5s %3i +:%3i -:%3i qdcL:%5.1F qdcR:%5.1F"%(pj,c,h[collection][c][1].GetN(),h[F][c][0],h[F][c][1],h[F][c][2],h[F][c][3])
534 moreEventInfo.append(atext)
536 if h[collection][c][1].GetN()<1: continue
538 if hitColour not in ["q"] :
539 h[collection][c][1].SetMarkerStyle(20)
540 h[collection][c][1].SetMarkerSize(1.5)
541 rc=h[collection][c][1].Draw('sameP')
542 h['display:'+c]=h[collection][c][1]
543 elif hitColour == "q" :
544 drawSciFiHits(h[collection][c][1], h['hitColour'+collection[-1]][c])
546 T0 = eventTree.EventHeader.GetEventTime()
547 if type(start) == type(1): rc = event.GetEvent(N-1)
548 else: rc = event.GetEvent(start[N]-1)
549 delTM1 = eventTree.EventHeader.GetEventTime() - T0
550 if type(start) == type(1): rc = event.GetEvent(N+1)
551 else: rc = event.GetEvent(start[N]+1)
552 delTP1 = eventTree.EventHeader.GetEventTime() - T0
553 atext = "timing info, prev event: %6i cc next event: %6i cc"%(delTM1,delTP1)
554 moreEventInfo.append(atext)
555 if type(start) == type(1): rc = event.GetEvent(N)
556 else: rc = event.GetEvent(start[N])
559 for collection in ['hitCollectionX','hitCollectionY']:
560 h['simpleDisplay'].cd(k)
561 drawInfo(h['simpleDisplay'], k, runId, N, T,moreEventInfo)
564 h['simpleDisplay'].Update()
565 if withTiming: timingOfEvent()
568 if option == "2tracks":
569 rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=0.5)
570 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=0.75)
571 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=1.0)
572 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=1.75)
573 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=2.5)
574 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=3.0)
576 if verbose>0: dumpChannels()
577 userProcessing(event)
579 if save: h['simpleDisplay'].Print('{:0>2d}-event_{:04d}'.format(runId,N)+'.png')
581 h['simpleDisplay'].Print(options.storePic+str(runId)+'-event_'+str(event.EventHeader.GetEventNumber())+'.png')
583 rc = input("hit return for next event or p for print or q for quit: ")
585 h['simpleDisplay'].Print(options.storePic+str(runId)+'-event_'+str(event.EventHeader.GetEventNumber())+'.png')
589 eventComment[f"{runId}-event_{event.EventHeader.GetEventNumber()}"] = rc
590 if save: os.system("convert -delay 60 -loop 0 event*.png animated.gif")
730 nodes = {'volMuFilter_1/volFeBlockEnd_1':ROOT.kGreen-6}
731 for i in range(mi.NVetoPlanes):
732 nodes['volVeto_1/volVetoPlane_{}_{}'.format(i, i)]=ROOT.kRed
733 for j in range(mi.NVetoBars):
734 if i<2: nodes['volVeto_1/volVetoPlane_{}_{}/volVetoBar_1{}{:0>3d}'.format(i, i, i, j)]=ROOT.kRed
735 if i==2: nodes['volVeto_1/volVetoPlane_{}_{}/volVetoBar_ver_1{}{:0>3d}'.format(i, i, i, j)]=ROOT.kRed
736 if i<2: nodes['volVeto_1/subVetoBox_{}'.format(i)]=ROOT.kGray+1
737 if i==2: nodes['volVeto_1/subVeto3Box_{}'.format(i)]=ROOT.kGray+1
738 for i in range(si.nscifi): # number of scifi stations
739 nodes['volTarget_1/ScifiVolume{}_{}000000'.format(i+1, i+1)]=ROOT.kBlue+1
740 # iron blocks btw SciFi planes in the testbeam 2023-2024 det layout
741 nodes['volTarget_1/volFeTarget{}_1'.format(i+1)]=ROOT.kGreen-6
742 for i in range(em.wall): # number of target walls
743 nodes['volTarget_1/volWallborder_{}'.format(i)]=ROOT.kGray
744 for i in range(mi.NDownstreamPlanes):
745 nodes['volMuFilter_1/volMuDownstreamDet_{}_{}'.format(i, i+mi.NVetoPlanes+mi.NUpstreamPlanes)]=ROOT.kBlue+1
746 for j in range(mi.NDownstreamBars):
747 nodes['volMuFilter_1/volMuDownstreamDet_{}_{}/volMuDownstreamBar_ver_3{}{:0>3d}'.format(i, i+mi.NVetoPlanes+mi.NUpstreamPlanes, i, j+mi.NDownstreamBars)]=ROOT.kBlue+1
749 nodes['volMuFilter_1/volMuDownstreamDet_{}_{}/volMuDownstreamBar_hor_3{}{:0>3d}'.format(i, i+mi.NVetoPlanes+mi.NUpstreamPlanes, i, j)]=ROOT.kBlue+1
750 for i in range(mi.NDownstreamPlanes):
751 nodes['volMuFilter_1/subDSBox_{}'.format(i+mi.NVetoPlanes+mi.NUpstreamPlanes)]=ROOT.kGray+1
752 for i in range(mi.NUpstreamPlanes):
753 nodes['volMuFilter_1/subUSBox_{}'.format(i+mi.NVetoPlanes)]=ROOT.kGray+1
754 nodes['volMuFilter_1/volMuUpstreamDet_{}_{}'.format(i, i+mi.NVetoPlanes)]=ROOT.kBlue+1
755 for j in range(mi.NUpstreamBars):
756 nodes['volMuFilter_1/volMuUpstreamDet_{}_{}/volMuUpstreamBar_2{}00{}'.format(i, i+mi.NVetoPlanes, i, j)]=ROOT.kBlue+1
757 nodes['volMuFilter_1/volFeBlock_{}'.format(i)]=ROOT.kGreen-6
758 for i in range(mi.NVetoPlanes+mi.NUpstreamPlanes,mi.NVetoPlanes+mi.NUpstreamPlanes+mi.NDownstreamPlanes):
759 nodes['volMuFilter_1/volFeBlock_{}'.format(i)]=ROOT.kGreen-6
760 passNodes = {'Block', 'Wall', 'FeTarget'}
761 xNodes = {'UpstreamBar', 'VetoBar', 'hor'}
764 node = '/cave_1/Detector_0/'+node_
766 if node+p in h and any(passNode in node for passNode in passNodes):
769 h['simpleDisplay'].cd(c+1)
773 # check if node exists
774 if not nav.CheckPath(node): continue
776 N = nav.GetCurrentNode()
777 S = N.GetVolume().GetShape()
778 dx,dy,dz = S.GetDX(),S.GetDY(),S.GetDZ()
779 ox,oy,oz = S.GetOrigin()[0],S.GetOrigin()[1],S.GetOrigin()[2]
782 if p=='X' and (not any(xNode in node for xNode in xNodes) or 'VetoBar_ver' in node):
783 P['LeftBottom'] = array('d',[-dx+ox,oy,-dz+oz])
784 P['LeftTop'] = array('d',[dx+ox,oy,-dz+oz])
785 P['RightBottom'] = array('d',[-dx+ox,oy,dz+oz])
786 P['RightTop'] = array('d',[dx+ox,oy,dz+oz])
787 elif p=='Y' and 'ver' not in node:
788 P['LeftBottom'] = array('d',[ox,-dy+oy,-dz+oz])
789 P['LeftTop'] = array('d',[ox,dy+oy,-dz+oz])
790 P['RightBottom'] = array('d',[ox,-dy+oy,dz+oz])
791 P['RightTop'] = array('d',[ox,dy+oy,dz+oz])
794 M[C] = array('d',[0,0,0])
795 nav.LocalToMaster(P[C],M[C])
796 h[node+p] = ROOT.TPolyLine()
799 X.SetPoint(0,M['LeftBottom'][2],M['LeftBottom'][c])
800 X.SetPoint(1,M['LeftTop'][2],M['LeftTop'][c])
801 X.SetPoint(2,M['RightTop'][2],M['RightTop'][c])
802 X.SetPoint(3,M['RightBottom'][2],M['RightBottom'][c])
803 X.SetPoint(4,M['LeftBottom'][2],M['LeftBottom'][c])
804 X.SetLineColor(nodes[node_])
806 h['simpleDisplay'].cd(c+1)
807 if any(passNode in node for passNode in passNodes):
808 X.SetFillColorAlpha(nodes[node_], 0.5)
856def checkOtherTriggers(event,deadTime = 100,debug=False):
857 T0 = event.EventHeader.GetEventTime()
858 N = event.EventHeader.GetEventNumber()
860 rc = event.GetEvent(N-Nprev)
861 dt = T0 - event.EventHeader.GetEventTime()
862 otherFastTrigger = False
863 otherAdvTrigger = False
864 tightNoiseFilter = False
866 otherFastTrigger = False
867 for x in event.EventHeader.GetFastNoiseFilters():
868 if debug: print('fast:', x.first, x.second )
869 if x.second and not x.first == 'Veto_Total': otherFastTrigger = True
870 otherAdvTrigger = False
871 for x in event.EventHeader.GetAdvNoiseFilters():
872 if debug: print('adv:', x.first, x.second )
873 if x.second and not x.first == 'VETO_Planes': otherAdvTrigger = True
874 if debug: print('pre event ',Nprev,dt,otherFastTrigger,otherAdvTrigger)
875 if otherFastTrigger and otherAdvTrigger:
876 rc = event.GetEvent(N)
877 return otherFastTrigger, otherAdvTrigger, tightNoiseFilter, Nprev, dt
879 rc = event.GetEvent(N-Nprev)
880 dt = T0 - event.EventHeader.GetEventTime()
882 rc = event.GetEvent(N-Nprev)
883 dt = T0 - event.EventHeader.GetEventTime()
886 for aHit in event.Digi_MuFilterHits:
887 Minfo = MuFilter_PlaneBars(aHit.GetDetectorID())
888 s,l,bar = Minfo['station'],Minfo['plane'],Minfo['bar']
890 allChannels = aHit.GetAllSignals(False,False)
891 hits[l]+=len(allChannels)
892 noiseFilter0 = (hits[0]+hits[1])>4.5
893 noiseFilter1 = hits[0]>0 and hits[1]>0
894 if debug: print('veto hits:',hits)
895 if noiseFilter0 and noiseFilter1:
896 tightNoiseFilter = True
897 rc = event.GetEvent(N)
898 return otherFastTrigger, otherAdvTrigger, tightNoiseFilter, Nprev-1, dt
900 rc = event.GetEvent(N-Nprev)
901 dt = T0 - event.EventHeader.GetEventTime()
903 rc = event.GetEvent(N-Nprev+1)
904 dt = T0 - event.EventHeader.GetEventTime()
905 rc = event.GetEvent(N)
906 return otherFastTrigger, otherAdvTrigger, tightNoiseFilter, Nprev-1, dt