303 if 'simpleDisplay' not in h: ut.bookCanvas(h,key='simpleDisplay',title='simple event display',nx=1200,ny=1600,cx=1,cy=2)
304 h['simpleDisplay'].cd(1)
305 zStart = 250. # TI18 coordinate system
306 if Setup == 'H6': zStart = 60.
307 if Setup == 'TP': zStart = -50. # old coordinate system with origin in middle of target
312 h['xmin'],h['xmax'] = -100.,10.
313 h['ymin'],h['ymax'] = -30.,80.
314 h['zmin'],h['zmax'] = zStart,zStart+350.
315 for d in ['xmin','xmax','ymin','ymax','zmin','zmax']: h['c'+d]=h[d]
316 ut.bookHist(h,'xz','; z [cm]; x [cm]',500,h['czmin'],h['czmax'],100,h['cxmin'],h['cxmax'])
317 ut.bookHist(h,'yz','; z [cm]; y [cm]',500,h['czmin'],h['czmax'],100,h['cymin'],h['cymax'])
319 proj = {1:'xz',2:'yz'}
325 A,B = ROOT.TVector3(),ROOT.TVector3()
326 ptext={0:' Y projection',1:' X projection'}
329 OT = sink.GetOutTree()
330 if withTrack==0 or withHoughTrack==0: OT = eventTree
331 if type(start) == type(1):
333 e = event.GetEntries()
338 if type(start) == type(1): rc = event.GetEvent(N)
339 else: rc = event.GetEvent(start[N])
340 if goodEvents and not goodEvent(event): continue
342 OT.Reco_MuonTracks = ROOT.TObjArray(10)
343 if withHoughTrack > 0:
344 rc = source.GetInTree().GetEvent(N)
345 # Delete SndlhcMuonReco kalman tracks container
346 for ht_task in HT_tasks.values():
347 ht_task.kalman_tracks.Delete()
348 if withHoughTrack==1:
349 HT_tasks['muon_reco_task_Sf'].Exec(0)
350 HT_tasks['muon_reco_task_DS'].Exec(0)
351 elif withHoughTrack==2:
352 HT_tasks['muon_reco_task_Sf'].Exec(0)
353 elif withHoughTrack==3:
354 HT_tasks['muon_reco_task_DS'].Exec(0)
355 elif withHoughTrack==4:
356 HT_tasks['muon_reco_task_nuInt'].Exec(0)
357 # Save the tracks in OT.Reco_MuonTracks object
358 for ht_task in HT_tasks.values():
359 for trk in ht_task.kalman_tracks:
360 OT.Reco_MuonTracks.Add(trk)
361 nHoughtracks = OT.Reco_MuonTracks.GetEntries()
362 if nHoughtracks>0: print('number of tracks by HT:', nHoughtracks)
365 # Delete SndlhcTracking fitted tracks container
366 trackTask.fittedTracks.Delete()
368 trackTask.ExecuteTask("ScifiDS")
370 trackTask.ExecuteTask("Scifi")
372 trackTask.ExecuteTask("DS")
374 for trk in trackTask.fittedTracks:
375 OT.Reco_MuonTracks.Add(trk)
376 ntracks = len(OT.Reco_MuonTracks) - nHoughtracks
377 if ntracks>0: print('number of tracks by ST:', ntracks)
378 nAlltracks = len(OT.Reco_MuonTracks)
379 if nAlltracks<nTracks: continue
382 for aTrack in OT.Reco_MuonTracks:
383 print(aTrack.__repr__())
384 mom = aTrack.getFittedState().getMom()
385 pos = aTrack.getFittedState().getPos()
389 T = event.EventHeader.GetEventTime()
390 runId = eventTree.EventHeader.GetRunId()
391 if Tprev >0: dT = T-Tprev
393 if nAlltracks > 0: print('total number of tracks: ', nAlltracks)
396 if event.FindBranch("Digi_ScifiHits"): digis.append(event.Digi_ScifiHits)
397 if event.FindBranch("Digi_MuFilterHits"): digis.append(event.Digi_MuFilterHits)
398 if event.FindBranch("Digi_MuFilterHit"): digis.append(event.Digi_MuFilterHit)
402 if empty: print( "event -> %i"%N)
405 h['hitCollectionX']= {'Veto':[0,ROOT.TGraphErrors()],'Scifi':[0,ROOT.TGraphErrors()],'DS':[0,ROOT.TGraphErrors()]}
406 h['hitCollectionY']= {'Veto':[0,ROOT.TGraphErrors()],'Scifi':[0,ROOT.TGraphErrors()],'US':[0,ROOT.TGraphErrors()],'DS':[0,ROOT.TGraphErrors()]}
408 h['hitColourX'] = {'Veto': [], 'Scifi': [], 'DS' : []}
409 h['hitColourY'] = {'Veto': [], 'Scifi' : [], 'US' : [], 'DS' : []}
410 h["markerCollection"] = []
412 h['firedChannelsX']= {'Veto':[0,0,0,0],'Scifi':[0,0,0],'DS':[0,0,0]}
413 h['firedChannelsY']= {'Veto':[0,0,0,0],'Scifi':[0,0,0],'US':[0,0,0,0],'DS':[0,0,0,0]}
414 systems = {1:'Veto',2:'US',3:'DS',0:'Scifi'}
415 for collection in ['hitCollectionX','hitCollectionY']:
416 for c in h[collection]:
417 rc=h[collection][c][1].SetName(c)
418 rc=h[collection][c][1].Set(0)
421 h["markerCollection"] = []
423 #Do we still use these lines? Seems no.
424 #And for events having all negative QDCs minT[1] is returned empty and the display crashes.
425 #dTs = "%5.2Fns"%(dT/u.snd_freq*1E9)
426 # find detector which triggered
427 #minT = firstTimeStamp(event)
428 #dTs+= " " + str(minT[1].GetDetectorID())
430 rc = h[ 'simpleDisplay'].cd(p)
437 detID = digi.GetDetectorID()
439 if digi.GetName() == 'MuFilterHit':
440 system = digi.GetSystem()
441 geo.modules['MuFilter'].GetPosition(detID,A,B)
442 sipmMult = len(digi.GetAllSignals(False,False))
443 if sipmMult<minSipmMult and (system==1 or system==2): continue
445 geo.modules['Scifi'].GetSiPMPosition(detID,A,B)
447 curPath = nav.GetPath()
448 tmp = curPath.rfind('/')
449 nav.cd(curPath[:tmp])
452 if not first and not with2Points:
455 globA, locA = array('d', [X[0], X[1], X[2]]), array('d', [X[0], X[1], X[2]])
457 nav.MasterToLocal(globA, locA)
459 if digi.isVertical():
460 collection = 'hitCollectionX'
462 sY = detSize[system][0]
464 collection = 'hitCollectionY'
466 sY = detSize[system][1]
467 c = h[collection][systems[system]]
468 rc = c[1].SetPoint(c[0], Z, Y)
469 rc = c[1].SetPointError(c[0], detSize[system][2], sY)
471 if hitColour == "q" :
474 ns = max(1,digi.GetnSides())
475 for side in range(ns):
476 for m in range(digi.GetnSiPMs()):
477 qdc = digi.GetSignal(m+side*digi.GetnSiPMs())
480 if this_qdc > max_QDC :
482 fillNode(curPath, ROOT.TColor.GetPalette()[int(this_qdc/max_QDC*(len(ROOT.TColor.GetPalette())-1))])
486 if digi.isVertical(): F = 'firedChannelsX'
487 else: F = 'firedChannelsY'
488 ns = max(1,digi.GetnSides())
489 for side in range(ns):
490 for m in range(digi.GetnSiPMs()):
491 qdc = digi.GetSignal(m+side*digi.GetnSiPMs())
492 if qdc < 0 and qdc > -900: h[F][systems[system]][1]+=1
494 h[F][systems[system]][0]+=1
495 if len(h[F][systems[system]]) < 2+side: continue
496 h[F][systems[system]][2+side]+=qdc
497 h['hitCollectionY']['Scifi'][1].SetMarkerColor(ROOT.kBlue+2)
498 h['hitCollectionX']['Scifi'][1].SetMarkerColor(ROOT.kBlue+2)
500 if hitColour == "q" :
501 for orientation in ['X', 'Y']:
503 density = np.clip(0, max_density, getSciFiHitDensity(h['hitCollection'+orientation]['Scifi'][1]))
504 for i in range(h['hitCollection'+orientation]['Scifi'][1].GetN()) :
505 h['hitColour'+orientation]['Scifi'].append(ROOT.TColor.GetPalette()[int(float(density[i])/max_density*(len(ROOT.TColor.GetPalette())-1))])
507 drawLegend(max_density, max_QDC, 5)
513 for collection in ['hitCollectionX','hitCollectionY']:
514 h['simpleDisplay'].cd(k)
515 drawInfo(h['simpleDisplay'], k, runId, N, T)
517 for c in h[collection]:
518 F = collection.replace('hitCollection','firedChannels')
519 pj = collection.split('ion')[1]
520 if pj =="X" or c=="Scifi":
521 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])
523 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])
524 moreEventInfo.append(atext)
526 if h[collection][c][1].GetN()<1: continue
528 if hitColour not in ["q"] :
529 h[collection][c][1].SetMarkerStyle(20)
530 h[collection][c][1].SetMarkerSize(1.5)
531 rc=h[collection][c][1].Draw('sameP')
532 h['display:'+c]=h[collection][c][1]
533 elif hitColour == "q" :
534 drawSciFiHits(h[collection][c][1], h['hitColour'+collection[-1]][c])
536 T0 = eventTree.EventHeader.GetEventTime()
537 if type(start) == type(1): rc = event.GetEvent(N-1)
538 else: rc = event.GetEvent(start[N]-1)
539 delTM1 = eventTree.EventHeader.GetEventTime() - T0
540 if type(start) == type(1): rc = event.GetEvent(N+1)
541 else: rc = event.GetEvent(start[N]+1)
542 delTP1 = eventTree.EventHeader.GetEventTime() - T0
543 atext = "timing info, prev event: %6i cc next event: %6i cc"%(delTM1,delTP1)
544 moreEventInfo.append(atext)
545 if type(start) == type(1): rc = event.GetEvent(N)
546 else: rc = event.GetEvent(start[N])
549 for collection in ['hitCollectionX','hitCollectionY']:
550 h['simpleDisplay'].cd(k)
551 drawInfo(h['simpleDisplay'], k, runId, N, T,moreEventInfo)
554 h['simpleDisplay'].Update()
555 if withTiming: timingOfEvent()
558 if option == "2tracks":
559 rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=0.5)
560 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=0.75)
561 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=1.0)
562 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=1.75)
563 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=2.5)
564 if not rc: rc = twoTrackEvent(sMin=10,dClMin=7,minDistance=0.5,sepDistance=3.0)
566 if verbose>0: dumpChannels()
567 userProcessing(event)
569 if save: h['simpleDisplay'].Print('{:0>2d}-event_{:04d}'.format(runId,N)+'.png')
571 h['simpleDisplay'].Print(options.storePic+str(runId)+'-event_'+str(event.EventHeader.GetEventNumber())+'.png')
573 rc = input("hit return for next event or p for print or q for quit: ")
575 h['simpleDisplay'].Print(options.storePic+str(runId)+'-event_'+str(event.EventHeader.GetEventNumber())+'.png')
579 eventComment[f"{runId}-event_{event.EventHeader.GetEventNumber()}"] = rc
580 if save: os.system("convert -delay 60 -loop 0 event*.png animated.gif")
720 nodes = {'volMuFilter_1/volFeBlockEnd_1':ROOT.kGreen-6}
721 for i in range(mi.NVetoPlanes):
722 nodes['volVeto_1/volVetoPlane_{}_{}'.format(i, i)]=ROOT.kRed
723 for j in range(mi.NVetoBars):
724 if i<2: nodes['volVeto_1/volVetoPlane_{}_{}/volVetoBar_1{}{:0>3d}'.format(i, i, i, j)]=ROOT.kRed
725 if i==2: nodes['volVeto_1/volVetoPlane_{}_{}/volVetoBar_ver_1{}{:0>3d}'.format(i, i, i, j)]=ROOT.kRed
726 if i<2: nodes['volVeto_1/subVetoBox_{}'.format(i)]=ROOT.kGray+1
727 if i==2: nodes['volVeto_1/subVeto3Box_{}'.format(i)]=ROOT.kGray+1
728 for i in range(mi.NDownstreamPlanes):
729 nodes['volMuFilter_1/volMuDownstreamDet_{}_{}'.format(i, i+mi.NVetoPlanes+mi.NUpstreamPlanes)]=ROOT.kBlue+1
730 for j in range(mi.NDownstreamBars):
731 nodes['volMuFilter_1/volMuDownstreamDet_{}_{}/volMuDownstreamBar_ver_3{}{:0>3d}'.format(i, i+mi.NVetoPlanes+mi.NUpstreamPlanes, i, j+mi.NDownstreamBars)]=ROOT.kBlue+1
733 nodes['volMuFilter_1/volMuDownstreamDet_{}_{}/volMuDownstreamBar_hor_3{}{:0>3d}'.format(i, i+mi.NVetoPlanes+mi.NUpstreamPlanes, i, j)]=ROOT.kBlue+1
734 for i in range(mi.NDownstreamPlanes):
735 nodes['volMuFilter_1/subDSBox_{}'.format(i+mi.NVetoPlanes+mi.NUpstreamPlanes)]=ROOT.kGray+1
736 for i in range(mi.NUpstreamPlanes):
737 nodes['volTarget_1/ScifiVolume{}_{}000000'.format(i+1, i+1)]=ROOT.kBlue+1
738 nodes['volTarget_1/volWallborder_{}'.format(i)]=ROOT.kGray
739 nodes['volMuFilter_1/subUSBox_{}'.format(i+mi.NVetoPlanes)]=ROOT.kGray+1
740 nodes['volMuFilter_1/volMuUpstreamDet_{}_{}'.format(i, i+mi.NVetoPlanes)]=ROOT.kBlue+1
741 # iron blocks btw SciFi planes in the testbeam 2023 det layout
742 nodes['volTarget_1/volFeTarget{}_1'.format(i+1)]=ROOT.kGreen-6
743 for j in range(mi.NUpstreamBars):
744 nodes['volMuFilter_1/volMuUpstreamDet_{}_{}/volMuUpstreamBar_2{}00{}'.format(i, i+mi.NVetoPlanes, i, j)]=ROOT.kBlue+1
745 nodes['volMuFilter_1/volFeBlock_{}'.format(i)]=ROOT.kGreen-6
746 for i in range(mi.NVetoPlanes+mi.NUpstreamPlanes,mi.NVetoPlanes+mi.NUpstreamPlanes+mi.NDownstreamPlanes):
747 nodes['volMuFilter_1/volFeBlock_{}'.format(i)]=ROOT.kGreen-6
748 passNodes = {'Block', 'Wall', 'FeTarget'}
749 xNodes = {'UpstreamBar', 'VetoBar', 'hor'}
752 node = '/cave_1/Detector_0/'+node_
754 if node+p in h and any(passNode in node for passNode in passNodes):
757 h['simpleDisplay'].cd(c+1)
761 # check if node exists
762 if not nav.CheckPath(node): continue
764 N = nav.GetCurrentNode()
765 S = N.GetVolume().GetShape()
766 dx,dy,dz = S.GetDX(),S.GetDY(),S.GetDZ()
767 ox,oy,oz = S.GetOrigin()[0],S.GetOrigin()[1],S.GetOrigin()[2]
770 if p=='X' and (not any(xNode in node for xNode in xNodes) or 'VetoBar_ver' in node):
771 P['LeftBottom'] = array('d',[-dx+ox,oy,-dz+oz])
772 P['LeftTop'] = array('d',[dx+ox,oy,-dz+oz])
773 P['RightBottom'] = array('d',[-dx+ox,oy,dz+oz])
774 P['RightTop'] = array('d',[dx+ox,oy,dz+oz])
775 elif p=='Y' and 'ver' not in node:
776 P['LeftBottom'] = array('d',[ox,-dy+oy,-dz+oz])
777 P['LeftTop'] = array('d',[ox,dy+oy,-dz+oz])
778 P['RightBottom'] = array('d',[ox,-dy+oy,dz+oz])
779 P['RightTop'] = array('d',[ox,dy+oy,dz+oz])
782 M[C] = array('d',[0,0,0])
783 nav.LocalToMaster(P[C],M[C])
784 h[node+p] = ROOT.TPolyLine()
787 X.SetPoint(0,M['LeftBottom'][2],M['LeftBottom'][c])
788 X.SetPoint(1,M['LeftTop'][2],M['LeftTop'][c])
789 X.SetPoint(2,M['RightTop'][2],M['RightTop'][c])
790 X.SetPoint(3,M['RightBottom'][2],M['RightBottom'][c])
791 X.SetPoint(4,M['LeftBottom'][2],M['LeftBottom'][c])
792 X.SetLineColor(nodes[node_])
794 h['simpleDisplay'].cd(c+1)
795 if any(passNode in node for passNode in passNodes):
796 X.SetFillColorAlpha(nodes[node_], 0.5)
844def checkOtherTriggers(event,deadTime = 100,debug=False):
845 T0 = event.EventHeader.GetEventTime()
846 N = event.EventHeader.GetEventNumber()
848 rc = event.GetEvent(N-Nprev)
849 dt = T0 - event.EventHeader.GetEventTime()
850 otherFastTrigger = False
851 otherAdvTrigger = False
852 tightNoiseFilter = False
854 otherFastTrigger = False
855 for x in event.EventHeader.GetFastNoiseFilters():
856 if debug: print('fast:', x.first, x.second )
857 if x.second and not x.first == 'Veto_Total': otherFastTrigger = True
858 otherAdvTrigger = False
859 for x in event.EventHeader.GetAdvNoiseFilters():
860 if debug: print('adv:', x.first, x.second )
861 if x.second and not x.first == 'VETO_Planes': otherAdvTrigger = True
862 if debug: print('pre event ',Nprev,dt,otherFastTrigger,otherAdvTrigger)
863 if otherFastTrigger and otherAdvTrigger:
864 rc = event.GetEvent(N)
865 return otherFastTrigger, otherAdvTrigger, tightNoiseFilter, Nprev, dt
867 rc = event.GetEvent(N-Nprev)
868 dt = T0 - event.EventHeader.GetEventTime()
870 rc = event.GetEvent(N-Nprev)
871 dt = T0 - event.EventHeader.GetEventTime()
874 for aHit in event.Digi_MuFilterHits:
875 Minfo = MuFilter_PlaneBars(aHit.GetDetectorID())
876 s,l,bar = Minfo['station'],Minfo['plane'],Minfo['bar']
878 allChannels = aHit.GetAllSignals(False,False)
879 hits[l]+=len(allChannels)
880 noiseFilter0 = (hits[0]+hits[1])>4.5
881 noiseFilter1 = hits[0]>0 and hits[1]>0
882 if debug: print('veto hits:',hits)
883 if noiseFilter0 and noiseFilter1:
884 tightNoiseFilter = True
885 rc = event.GetEvent(N)
886 return otherFastTrigger, otherAdvTrigger, tightNoiseFilter, Nprev-1, dt
888 rc = event.GetEvent(N-Nprev)
889 dt = T0 - event.EventHeader.GetEventTime()
891 rc = event.GetEvent(N-Nprev+1)
892 dt = T0 - event.EventHeader.GetEventTime()
893 rc = event.GetEvent(N)
894 return otherFastTrigger, otherAdvTrigger, tightNoiseFilter, Nprev-1, dt