SND@LHC Software
Loading...
Searching...
No Matches
2dMuEventBuilderDisplay.py
Go to the documentation of this file.
1import ROOT,os
2import rootUtils as ut
3from array import array
4import shipunit as u
5
6h={}
7from argparse import ArgumentParser
8parser = ArgumentParser()
9parser.add_argument("-r", "--runNumber", dest="runNumber", help="run number", type=int,required=False)
10parser.add_argument("-f", "--inputFile", dest="inputFile", help="input file MC",default="",required=False)
11parser.add_argument("-g", "--geoFile", dest="geoFile", help="geofile", required=True)
12options = parser.parse_args()
13trans2local = False
14
15fgeo = ROOT.TFile.Open(options.geoFile)
16from ShipGeoConfig import ConfigRegistry
17from rootpyPickler import Unpickler
18#load geo dictionary
19upkl = Unpickler(fgeo)
20snd_geo = upkl.load('ShipGeo')
21
22# -----Create geometry----------------------------------------------
23import shipLHC_conf as sndDet_conf
24
25run = ROOT.FairRunSim()
26modules = sndDet_conf.configure(run,snd_geo)
27sGeo = fgeo.FAIRGeom
28modules['Scifi'].SiPMmapping()
29lsOfGlobals = ROOT.gROOT.GetListOfGlobals()
30lsOfGlobals.Add(modules['Scifi'])
31lsOfGlobals.Add(modules['MuFilter'])
32
33mc = False
34if options.inputFile=="":
35 f=ROOT.TFile('sndsw_raw_'+str(options.runNumber).zfill(6)+'.root')
36 eventTree = f.rawConv
37else:
38 f=ROOT.TFile.Open(options.inputFile)
39 if f.FindKey('cbmsim'):
40 eventTree = f.cbmsim
41 mc = True
42 else: eventTree = f.rawConv
43
44nav = ROOT.gGeoManager.GetCurrentNavigator()
45for p in [0,1]:
46 h['aLine'+str(p)] = ROOT.TGraph()
47
48def loopEvents(start=0,save=False,selection=4):
49 if 'simpleDisplay' not in h: ut.bookCanvas(h,key='simpleDisplay',title='simple event display',nx=1200,ny=1600,cx=1,cy=2)
50 h['simpleDisplay'].cd(1)
51 zStart = -40. # old coordinate system with origin in middle of target
52 ut.bookHist(h,'xz','x vs z',500,zStart,zStart+250.,100,-100.,10.)
53 ut.bookHist(h,'yz','y vs z',500,zStart,zStart+250.,100,0.,80.)
54 proj = {1:'xz',2:'yz'}
55 h['xz'].SetStats(0)
56 h['yz'].SetStats(0)
57
58 N = -1
59 Tprev = -1
60 A,B = ROOT.TVector3(),ROOT.TVector3()
61 ptext={0:' Y projection',1:' X projection'}
62 text = ROOT.TLatex()
63
64 Nev = eventTree.GetEntries()
65 eventTree.GetEvent(start)
66 T = eventTree.EventHeader.GetEventTime()
67 Nstart = start
68 while Nstart+1 < Nev:
69 bigContainer = []
70 for N in range(Nstart,Nev):
71 rc = eventTree.GetEvent(N)
72 if eventTree.EventHeader.GetEventTime() != T: break
73 for aHit in eventTree.Digi_MuFilterHit:
74 bigContainer.append( aHit.Clone() )
75 T = eventTree.EventHeader.GetEventTime()
76 Nstart = N
77 if len(bigContainer)==0: continue
78 stations = {}
79 for d in bigContainer:
80 plane = 100*(d.GetDetectorID()//1000)
81 stations[plane] = 1
82 if len(stations) <selection: continue
83
84 h['hitCollectionX']= {'Scifi':[0,ROOT.TGraph()],'US':[0,ROOT.TGraph()],'DS':[0,ROOT.TGraph()]}
85 h['hitCollectionY']= {'Veto':[0,ROOT.TGraph()],'Scifi':[0,ROOT.TGraph()],'US':[0,ROOT.TGraph()],'DS':[0,ROOT.TGraph()]}
86 systems = {1:'Veto',2:'US',3:'DS'}
87 for collection in ['hitCollectionX','hitCollectionY']:
88 for c in h[collection]:
89 rc=h[collection][c][1].SetName(c)
90 rc=h[collection][c][1].Set(0)
91 for p in proj:
92 rc = h[ 'simpleDisplay'].cd(p)
93 h[proj[p]].SetStats(0)
94 h[proj[p]].Draw('b')
95
96 for digi in bigContainer:
97 detID = digi.GetDetectorID()
98 if digi.GetName() == 'MuFilterHit':
99 system = digi.GetSystem()
100 modules['MuFilter'].GetPosition(detID,A,B)
101 globA,locA = array('d',[A[0],A[1],A[2]]),array('d',[A[0],A[1],A[2]])
102 if trans2local: nav.MasterToLocal(globA,locA)
103 Z = A[2]
104 if digi.isVertical():
105 collection = 'hitCollectionX'
106 Y = locA[0]
107 else:
108 collection = 'hitCollectionY'
109 Y = locA[1]
110 c = h[collection][systems[system]]
111 rc = c[1].SetPoint(c[0],Z,Y)
112 c[0]+=1
113 h['hitCollectionY']['Veto'][1].SetMarkerColor(ROOT.kRed)
114 h['hitCollectionY']['Scifi'][1].SetMarkerColor(ROOT.kBlue)
115 h['hitCollectionX']['Scifi'][1].SetMarkerColor(ROOT.kBlue)
116 h['hitCollectionY']['US'][1].SetMarkerColor(ROOT.kGreen)
117 h['hitCollectionY']['DS'][1].SetMarkerColor(ROOT.kCyan)
118 h['hitCollectionX']['DS'][1].SetMarkerColor(ROOT.kCyan)
119 k = 1
120 for collection in ['hitCollectionX','hitCollectionY']:
121 h[ 'simpleDisplay'].cd(k)
122 k+=1
123 for c in h[collection]:
124 print(collection.split('ion')[1],c, h[collection][c][1].GetN())
125 if h[collection][c][1].GetN()<1: continue
126 h[collection][c][1].SetMarkerStyle(29+k)
127 rc=h[collection][c][1].Draw('sameP')
128 h['display:'+c]=h[collection][c][1]
129 h[ 'simpleDisplay'].Update()
130 if save: h['simpleDisplay'].Print('event_'+"{:04d}".format(N)+'.png')
131 rc = input("hit return for next event or q for quit: ")
132 if rc=='q': break
133 if save: os.system("convert -delay 60 -loop 0 *.png animated.gif")
loopEvents(start=0, save=False, selection=4)