12S = {1:[1800,800,2,1],2:[1800,1500,2,3],3:[1800,1800,2,4]}
69 ut.bookCanvas(h,
'xCheckH',
' ',1200,600,1,1)
70 ut.bookCanvas(h,
'xCheckV',
' ',1200,600,1,1)
71 tcolors = [0,ROOT.kRed,ROOT.kRed,ROOT.kBlue,ROOT.kBlue,ROOT.kGreen,ROOT.kGreen,ROOT.kCyan,ROOT.kCyan]
73 for b
in [
'',
'B2noB1']:
76 tc = h[
'mufi-dTcorScifiDS'+b]
79 h[
'meanAndSig'][b] = {}
81 if b==
'B2noB1': xmin,xmax = -20.,-8.
82 for pad
in tc.GetListOfPrimitives():
86 for x
in pad.GetListOfPrimitives():
87 if not x.ClassName().find(
'TH')<0:
88 if j%2==1: tcX = h[
'xCheckH'].cd()
89 else: tcX = h[
'xCheckV'].cd()
91 h[hname] = x.Clone(hname)
92 h[hname+
'B1'] = h[hname].ProjectionX(hname+
'B1')
93 h[hname+
'B1'].SetStats(0)
94 h[hname+
'B1'].SetLineColor(tcolors[j])
95 h[hname+
'B1'].SetMarkerColor(tcolors[j])
96 h[hname+
'B1'].SetMarkerStyle(30+j)
97 rc = h[hname+
'B1'].Fit(
'gaus',
'SQ',
'',xmin,xmax)
99 h[hname+
'B1'].GetFunction(
'gaus').SetLineColor(tcolors[j])
100 h[
'meanAndSig'][b][j] = [fitRes.Parameter(1),fitRes.Parameter(2)]
101 plots = {
'H':[0,2,4],
'V':[1,3,5,6]}
105 txt.SetTextSize(0.04)
107 tcX = h[
'xCheck'+c].cd()
111 if x<2: h[
'mufi-dTcor_3'+str(x)+
'B1'].Draw()
112 else: h[
'mufi-dTcor_3'+str(x)+
'B1'].Draw(
'same')
113 if x==6: m,s = h[
'meanAndSig'][b][x+2]
114 else: m,s = h[
'meanAndSig'][b][x+1]
115 h[
'txt'+str(x)] = txt.DrawLatexNDC(0.15,0.85-j*0.05,
"DS%i%s m=%5.2Fns #sigma=%5.2Fns"%(x//2,c,m,s))
116 h[
'txt'+str(x)].SetTextColor(h[
'mufi-dTcor_3'+str(x)+
'B1'].GetLineColor())
121 h[
'txtB2H'] = txt.DrawLatexNDC(0.15,0.85-j*0.05,
"BW tracks DS0H: %5.2Fns DS1H: %5.2Fns DS2H: %5.2Fns "%(
122 h[
'meanAndSig'][
'B2noB1'][1][0],h[
'meanAndSig'][
'B2noB1'][3][0],h[
'meanAndSig'][
'B2noB1'][5][0]))
123 h[
'txtB2H'].SetTextColor(ROOT.kMagenta)
125 h[
'txtB2V'] = txt.DrawLatexNDC(0.15,0.85-j*0.05,
"BW tracks DS0V: %5.2Fns DS1V: %5.2Fns DS2V: %5.2Fns DS3V: %5.2Fns "%(
126 h[
'meanAndSig'][
'B2noB1'][2][0],h[
'meanAndSig'][
'B2noB1'][4][0],h[
'meanAndSig'][
'B2noB1'][6][0],h[
'meanAndSig'][
'B2noB1'][8][0]))
127 h[
'txtB2V'].SetTextColor(ROOT.kMagenta)
129 h[
'xCheck'+c].Update()
130 h[
'xCheck'+c].Print(
'mufi-dTScifiDS-xCheck'+c+
'.png')
140 if s==1: system =
'Veto'
141 ut.bookCanvas(h,
'c1',
'',640,480,1,1)
143 fitLimits ={1:[-15,-5],11:[-15,-5],3:[-10,-2],13:[-25,-15]}
144 for l
in range(S[s][2]*S[s][3]):
145 if s==3
and l>6:
continue
147 hist = h[detector+
'dT_'+tag]
148 alignTpar[s*10+l] = {}
149 alignTparB2[s*10+l] = {}
150 for i
in range(hist.GetNbinsY()):
151 if s==1
and i > 8*16:
continue
152 tagi = str(i*1000+s*10+l)
153 alignTpar[s*10+l][i] = [100,-100]
154 h[
'tmp'+tagi] = hist.ProjectionX(
'tmp'+tagi,i+1,i+1)
156 rc = tmp.Fit(
'gaus',
'SQ',
'',fitLimits[s][0],fitLimits[s][1])
159 alignTpar[s*10+l][i]=[fitres.Parameter(1),fitres.Parameter(2)]
160 alignTparB2[s*10+l][i] = [100,-100]
162 tmp = h[detector+
'dT_'+tag+
'B2noB1'].ProjectionX(
'tmp',i+1,i+1)
163 rc = tmp.Fit(
'gaus',
'SQ',
'',fitLimits[s+10][0],fitLimits[s+10][1])
166 alignTparB2[s*10+l][i]=[fitres.Parameter(1),fitres.Parameter(2)]
168 nbins = channelsPerPlane[s] * Planes[s]
169 ut.bookHist(h,
'talign',
'time alignment B1;channel;offset [ns]',nbins,-0.5,nbins-0.5)
170 ut.bookHist(h,
'talign2',
'time alignment B2;channel;offset [ns]',nbins,-0.5,nbins-0.5)
171 ut.bookHist(h,
'tres',
'time diff res;channel;sigma [ns]',nbins,-0.5,nbins-0.5)
172 ut.bookHist(h,
't12',
'time diff B1 B2;channel;sigma [ns]',nbins,-0.5,nbins-0.5)
173 for l
in range(S[s][2]*S[s][3]):
174 if s==3
and l>6:
continue
175 for i
in range(hist.GetNbinsY()):
176 k = l*channelsPerPlane[s]
177 rc = h[
'talign'].Fill(k+i,alignTpar[s*10+l][i][0])
178 rc = h[
'talign2'].Fill(k+i,alignTparB2[s*10+l][i][0])
179 rc = h[
'tres'].Fill(k+i,abs(alignTpar[s*10+l][i][1]))
180 if alignTpar[s*10+l][i][0]<99
and alignTparB2[s*10+l][i][0]<99:
181 rc = h[
't12'].Fill(k+i,alignTparB2[s*10+l][i][0]-alignTpar[s*10+l][i][0])
182 else: rc = h[
't12'].Fill(k+i,100)
184 h[
'talign'].SetMinimum(-10)
185 h[
'talign'].SetMaximum(1)
187 h[
'talign'].SetMinimum(-15)
188 h[
'talign'].SetMaximum(-5)
189 h[
'talign2'].SetMinimum(-25)
190 h[
'talign2'].SetMaximum(1)
191 h[
'tres'].SetMinimum(0)
192 h[
'tres'].SetMaximum(2.5)
193 h[
'talign'].SetMarkerStyle(30)
194 h[
'talign'].SetMarkerColor(ROOT.kRed)
195 h[
'talign2'].SetMarkerStyle(32)
196 h[
'talign2'].SetMarkerColor(ROOT.kBlue)
197 h[
'tres'].SetMarkerStyle(31)
198 h[
'tres'].SetMarkerColor(ROOT.kGreen)
199 h[
'tres'].SetStats(0)
200 h[
'talign'].SetStats(0)
201 h[
'talign2'].SetStats(0)
202 ut.bookCanvas(h,
'results',system+
' time alignment',2400,1200,1,2)
203 tc = h[
'results'].cd(1)
204 h[
'talign'].Draw(
'phist')
205 tc = h[
'results'].cd(2)
206 h[
'tres'].Draw(
'phist')
207 h[
'results'].Print(system+
'timeAlign-run'+runN+
'.png')
208 h[
't12'].SetMinimum(-30)
209 h[
't12'].SetMaximum(0)
211 h[
't12'].SetMarkerColor(ROOT.kMagenta)
212 h[
't12'].SetMarkerStyle(53)
214 ut.bookCanvas(h,
'results2',
'time diff between FW and BW tracks',1200,600,1,1)
216 h[
't12'].Draw(
'phist')
217 h[
'results2'].Print(system+
'timeAlignFWBW-run'+runN+
'.png')
220 h[
'talignReorder'+str(k)] = h[
'talign'].Clone(
'talignReorder'+str(k))
221 h[
'talignReorder'+str(k)].Reset()
224 for i
in range(h[
'talign'].GetNbinsX()):
225 if i<120
and i%2==0: p=0
226 elif i<120
and i%2==1: p=1
227 elif i<240
and i%2==0: p=2
228 elif i<360
and i%2==0: p=3
229 elif i<360
and i%2==1: p=4
230 elif i<480
and i%2==0: p=5
231 elif i<600
and i%2==0: p=6
232 elif i<600
and i%2==1: p=7
233 elif i<720
and i%2==0: p=8
234 elif i<840
and i%2==0: p=9
236 if i%2==0: j=(i//2)%60
237 if i%2==1: j=((i-1)//2)%60
238 X = h[
'talign'].GetBinContent(i+1)
239 h[
'talignReorder0'].SetBinContent(j+1+p*60,X)
240 h[
'talignReorder1'].SetBinContent(j+1+p*60,X)
241 channel = (j+1+p*60)%60
242 if channel<30: X+= channel*slope - 15*slope
243 else: X-=(channel-30)*slope - 15*slope
244 h[
'talignReorder2'].SetBinContent(j+1+p*60,X)
247 c =
'talignReorder'+str(l)
248 ut.bookCanvas(h,
'results'+c,system+
' time alignment '+str(l),1200,600,1,1)
249 h[
'results'+c].SetGridy(1)
252 for x
in h[c].GetListOfFunctions(): x.Delete()
265 for p
in range(planes):
278 theFun =
'fun'+str(l*100+p)
279 h[theFun]=ROOT.TF1(theFun,
'[0]+x*[1]')
282 h[theFun].SetParameter(0, -6)
283 if l>0: h[theFun].FixParameter(1, sign*par1)
284 rc = h[c].Fit(h[theFun],
'SQw+',
'',imin+2,imax-2)
287 while res.Chi2() > 1.5:
289 if imax-ix < imin+2: 1/0
290 if h[c].GetFunction(theFun): h[c].GetFunction(theFun).Delete()
291 if p==3: rc = h[c].Fit(h[theFun],
'SQw+',
'',imin+ix,imax-ix)
292 else : rc = h[c].Fit(h[theFun],
'SQw+',
'',imin+2,imax-ix)
294 par0[l][p]=[res.Parameter(0),res.Parameter(1)]
295 print(
"%i slope %5.3F b = %5.2F"%(p,res.Parameter(1),res.Parameter(0)))
296 h[c].GetXaxis().SetRange(1,600)
298 h[
'results'+c].Print(system+
'timeAlignFit'+str(l)+
'-run'+runN+
'.png')
301 ut.bookHist(h,
'resT',
't residuals',100,-3.,3.)
302 for i
in range(h[c].GetNbinsX()):
305 res = h[c.replace(
'3',
'2')].GetBinContent(i+1)-par0[2][p][0]
306 h[c].SetBinContent(i+1,res)
307 rc = h[
'resT'].Fill(res)
308 ut.bookCanvas(h,
'results'+c,system+
' time alignment 3',1200,600,1,1)
309 h[
'results'+c].SetGridy(1)
311 h[c].GetXaxis().SetRange(1,600)
315 h[
'results'+c].Print(system+
'timeAlignFit3'+
'-run'+runN+
'.png')
317 rc = h[
'resT'].Fit(
'gaus',
'S',
'')
319 stats = h[
'resT'].FindObject(
'stats')
321 stats.SetOptStat(1000000000)
322 stats.SetX1NDC(0.595611)
323 stats.SetY1NDC(0.614035)
324 stats.SetX2NDC(0.979624)
325 stats.SetY2NDC(0.936404)
326 h[
'c1'].Print(system+
'timeResiudals'+
'-run'+runN+
'.png')
329 for I
in [ [10.5,89.5],[249.5,328.5],[492.5,571.5] ]:
331 rc = h[
't12'].Fit(
'pol1',
'SQ',
'',I[0],I[1])
333 print(
"%i delta t = %5.2F"%(p,res.Parameter(0)))
336 m+=abs(par0[0][i][1])
337 print(
'average slope = ',m/len(par0[0]))
343 firstScifi_z = 300*u.cm
344 TDC2ns = 1E9/160.316E6
345 ut.bookHist(h,
'evTimeDS',
'cor time of hits;[ns]',100,-20.,20)
346 ut.bookHist(h,
'evTimeScifi',
'cor time of hits blue DS red Scifi;[ns]',100,-20.,20)
347 ut.bookCanvas(h,
'tevTime',
'cor time of hits',1024,768,1,1)
348 h[
'evTimeScifi'].SetLineColor(ROOT.kRed)
349 h[
'evTimeDS'].SetLineColor(ROOT.kBlue)
350 h[
'evTimeScifi'].SetStats(0)
351 h[
'evTimeDS'].SetStats(0)
352 if makeCluster: trackTask.scifiCluster()
354 for siCl
in trackTask.clusScifi:
355 detID = siCl.GetFirst()
357 isVertical = detID%1000000//100000
358 siCl.GetPosition(A,B)
361 L = abs(A[0]-B[0])/2.
364 L = abs(A[1]-B[1])/2.
365 corTime = geo.modules[
'Scifi'].GetCorrectedTime(detID, siCl.GetTime(), L) - (z-firstScifi_z)/u.speedOfLight
366 h[
'evTimeScifi'].Fill(corTime)
367 if debug: print(detID,corTime,pos)
368 for aHit
in eventTree.Digi_MuFilterHits:
369 detID = aHit.GetDetectorID()
370 if not detID//10000==3:
continue
371 if aHit.isVertical(): nmax = 1
373 geo.modules[
'MuFilter'].GetPosition(detID,A,B)
376 L = abs(A[0]-B[0])/2.
379 L = abs(A[1]-B[1])/2.
380 for i
in range(nmax):
381 corTime = geo.modules[
'MuFilter'].GetCorrectedTime(detID, i, aHit.GetTime(i)*TDC2ns, L)- (z-firstScifi_z)/u.speedOfLight
382 h[
'evTimeDS'].Fill(corTime)
383 if debug: print(detID,i,corTime,pos)
385 h[
'evTimeScifi'].Draw()
386 h[
'evTimeDS'].Draw(
'same')