SND@LHC Software
Loading...
Searching...
No Matches
SciFiMapping.py
Go to the documentation of this file.
1import ROOT
2# to be run after detector modules are created, simplest way:
3# python -i $SNDBUILD/sndsw/shipLHC/run_simSND.py -n 10 --Ntuple -f /eos/experiment/sndlhc/MonteCarlo/FLUKA/muons_up/version1/unit30_Nm.root --eMin 1.0
4# import SciFiMapping
5
6if __name__ == "__main__":
7 print("open geofile")
8 geoFile = "geofile_full.Ntuple-TGeant4.root"
9 fgeo = ROOT.TFile.Open(geoFile)
10 from ShipGeoConfig import ConfigRegistry
11 from rootpyPickler import Unpickler
12#load geo dictionary
13 upkl = Unpickler(fgeo)
14 snd_geo = upkl.load('ShipGeo')
15
16# -----Create geometry----------------------------------------------
17 import shipLHC_conf as sndDet_conf
18
19 run = ROOT.FairRunSim()
20 run.SetName("TGeant4") # Transport engine
21 run.SetSink(ROOT.FairRootFileSink(ROOT.TMemFile('output', 'recreate'))) # Output file
22 run.SetUserConfig("g4Config_basic.C") # geant4 transport not used
23 rtdb = run.GetRuntimeDb()
24 modules = sndDet_conf.configure(run,snd_geo)
25 sGeo = fgeo.FAIRGeom
26 top = sGeo.GetTopVolume()
27# hierarchy: top<-volTarget<-ScifiVolume<- ScifiHorPlaneVol<-HorMatVolume<-FibreVolume
28# <- ScifiVertPlaneVol<-VertMatVolume<-FibreVolume
29
30# get mapping from C++
32 scifi.SiPMOverlap()
33 scifi.SiPMmapping()
34 F=scifi.GetSiPMmap()
35 fibresSiPM = {}
36 for x in F:
37 fibresSiPM[x.first]={}
38 for z in x.second:
39 fibresSiPM[x.first][z.first]={'weight':z.second[0],'xpos':z.second[1]}
40 return fibresSiPM
41
43 X=scifi.GetFibresMap()
44 siPMFibres = {}
45 for x in X:
46 siPMFibres[x.first]={}
47 for z in x.second:
48 siPMFibres[x.first][z.first]={'weight':z.second[0],'xpos':z.second[1]}
49 return siPMFibres
50
51from array import array
52def localPosition(fibresSiPM):
53 meanPos = {}
54 for N in fibresSiPM:
55 m = 0
56 w = 0
57 for fID in fibresSiPM[N]:
58 m+=fibresSiPM[N][fID]['weight']*fibresSiPM[N][fID]['xpos']
59 w+=fibresSiPM[N][fID]['weight']
60 meanPos[N] = m/w
61 return meanPos
62
63h={}
64import rootUtils as ut
65def overlap(F,Finv):
66 ut.bookHist(h,'W','overlap/fibre',110,0.,1.1)
67 ut.bookHist(h,'C','coverage',50,0.,10.)
68 ut.bookHist(h,'S','fibres/sipm',15,-0.5,14.5)
69 ut.bookHist(h,'Eff','efficiency',110,0.,1.1)
70 for n in F:
71 C=0
72 for fid in F[n]:
73 rc = h['W'].Fill(F[n][fid]['weight'])
74 C+=F[n][fid]['weight']
75 rc = h['C'].Fill(C)
76 for n in Finv:
77 E=0
78 for sipm in Finv[n]:
79 E+=Finv[n][sipm]['weight']
80 rc = h['Eff'].Fill(E)
81 rc = h['S'].Fill(len(Finv[n]))
82
83def test(chan):
84 for x in F['VertMatVolume'][chan]:
85 print('%6i:%5.2F'%(x,F['VertMatVolume'][chan][x]))
86
88 sGeo = ROOT.gGeoManager
89 SiPMmapVol = sGeo.FindVolumeFast("SiPMmapVol")
90 for l1 in SiPMmapVol.GetNodes(): # 3 mats with 4 SiPMs each and 128 channels
91 t1 = l1.GetMatrix().GetTranslation()[1]
92 if l1.GetNumber()%1000==0: print( "%s %5.2F"%(l1.GetName(),(t1)*10.))
93
95 sGeo = ROOT.gGeoManager
96 ScifiHorPlaneVol = sGeo.FindVolumeFast("ScifiHorPlaneVol")
97 for l1 in ScifiHorPlaneVol.GetNodes(): # 3 mats
98 t1 = l1.GetMatrix().GetTranslation()[1]
99 print(l1.GetName(),t1)
100 for l2 in l1.GetVolume().GetNodes():
101 t2 = l2.GetMatrix().GetTranslation()[1]
102 print(" ",l2.GetName(),t2,t1+t2)
104 for mat in range(1,4):
105 for row in range(1,7):
106 for channel in range(1,473):
107 fID = mat*10000+row*1000+channel
108 if not fID in Finv: print('missing fibre:',fID)
109def checkLocalPosition(fibresSiPM):
110 ut.bookHist(h,'delta','central - weighted',100,-20.,20.)
111 L = localPosition(fibresSiPM)
112 sGeo = ROOT.gGeoManager
113 SiPMmapVol = sGeo.FindVolumeFast("SiPMmapVol")
114 for l in SiPMmapVol.GetNodes():
115 n = l.GetNumber()
116 ty = l.GetMatrix().GetTranslation()[1]
117 delta = ty-L[n]
118 rc = h['delta'].Fill(delta*10*1000.)
119def moreChecks(modules):
120 ut.bookHist(h,'dx','dx',100,-0.1,0.1)
121 ut.bookHist(h,'dy','dy',100,-1.,1.)
122 ut.bookHist(h,'dz','dz',100,-0.2,0.2)
123 AS=ROOT.TVector3()
124 BS=ROOT.TVector3()
125 AF=ROOT.TVector3()
126 BF=ROOT.TVector3()
127 scifi = modules['Scifi']
128 F=getFibre2SiPMCPP(modules)
129 for station in range(1,6):
130 for orientation in range(0,2):
131 for channel in F:
132 globChannel = station* 1000000+ orientation*100000 +channel
133 scifi.GetSiPMPosition(globChannel,AS,BS)
134 for fibre in F[channel]:
135 globFibre = station* 1000000+ orientation*100000+fibre
136 scifi.GetPosition(globFibre,AF,BF)
137 if orientation==0:
138 dx = AS[1]-AF[1]
139 dy = AS[0]-AF[0]
140 else:
141 dx = AS[0]-AF[0]
142 dy = AS[1]-AF[1]
143 dz = AS[2]-AF[2]
144 rc = h['dx'].Fill(dx)
145 rc = h['dy'].Fill(dy)
146 rc = h['dz'].Fill(dz)
147def someDrawings(F,channel):
148 AF = ROOT.TVector3()
149 BF = ROOT.TVector3()
150 ut.bookCanvas(h,'c1',' ;x;y',800,800,1,1)
151 s = int(channel/1000000)
152 o = int( (channel-1000000*s)/100000)
153 locChannel = channel%100000
154 fibreVol = sGeo.FindVolumeFast('FiberVolume')
155 R = fibreVol.GetShape().GetDX()
156 sipmVol = sGeo.FindVolumeFast("ChannelVol")
157 DY = sipmVol.GetShape().GetDY()
158 DZ = sipmVol.GetShape().GetDZ()
159 n = 0
160 xmin = 999.
161 xmax = -999.
162 ymin = 999.
163 ymax = -999.
164 for fibre in F[locChannel]:
165 globFibre = int(s*1000000 + o*100000 + fibre)
166 scifi.GetPosition(globFibre,AF,BF)
167 loc = scifi.GetLocalPos(globFibre,AF)
168 h['ellipse'+str(n)]=ROOT.TEllipse(loc[0],loc[2],R,0)
169 n+=1
170 if xmin>loc[0]: xmin = loc[0]
171 if ymin>loc[2]: ymin = loc[2]
172 if xmax<loc[0]: xmax = loc[0]
173 if ymax<loc[2]: ymax = loc[2]
174 print(xmin,xmax,ymin,ymax)
175 D = ymax - ymin+3*R
176 x0 = (xmax+xmin)/2.
177 ut.bookHist(h,'x','',100,x0-D/2,x0+D/2,100,ymin-1.5*R,ymax+1.5*R)
178 h['x'].SetStats(0)
179 h['x'].Draw()
180 for i in range(n):
181 print(fibre,globFibre,loc[0],loc[1],loc[2])
182 el = h['ellipse'+str(i)]
183 el.SetFillColor(6)
184 el.Draw('same')
185 scifi.GetSiPMPosition(channel,AF,BF)
186 loc = scifi.GetLocalPos(globFibre,AF)
187 h['rectang']=ROOT.TBox(loc[0]-DY,loc[2]-DZ,loc[0]+DY,loc[2]+DZ)
188 h['rectang'].SetFillColor(4)
189 h['rectang'].SetFillStyle(3001)
190 h['rectang'].Draw('same')
191
getFibre2SiPMCPP(scifi)
getSiPM2FibreCPP(scifi)
someDrawings(F, channel)
checkLocalPosition(fibresSiPM)
checkFibreCoverage(Finv)
localPosition(fibresSiPM)
overlap(F, Finv)
moreChecks(modules)