94 for nHit
in range(event.Digi_ScifiHits.GetEntries()):
95 DetID2Key[event.Digi_ScifiHits[nHit].GetDetectorID()] = nHit
97 for aTrack
in self.
M.Reco_MuonTracks:
98 if not aTrack.GetUniqueID()==1:
continue
99 fitStatus = aTrack.getFitStatus()
100 if not fitStatus.isFitConverged():
continue
101 state = aTrack.getFittedState()
103 slopeX = mom.X()/mom.Z()
104 slopeY = mom.Y()/mom.Z()
108 for s
in range(1, nStations+1): sortedClusters[s] = {
'H':[],
'V':[]}
109 for nM
in range(aTrack.getNumPointsWithMeasurement()):
110 state = aTrack.getFittedState(nM)
111 Meas = aTrack.getPointWithMeasurement(nM)
112 W = Meas.getRawMeasurement()
114 aCl = self.
M.trackTask.clusScifi[clkey]
115 aHit = event.Digi_ScifiHits[DetID2Key[aCl.GetFirst()]]
116 s = aCl.GetFirst()//1000000
118 mat = (aCl.GetFirst()//10000)%10
119 if aHit.isVertical():
120 L = B[1]-state.getPos()[1]
121 sortedClusters[s][
'V'].append( [clkey,L,B[0],state.getPos()[1],mat,(A[2]+B[2])/2.] )
122 rc = h[
'res'+
str(s)+
'V'].Fill( (A[0]+B[0])/2.-state.getPos()[0])
124 L = A[0]-state.getPos()[0]
125 sortedClusters[s][
'H'].append( [clkey,L,A[1],state.getPos()[0],mat,(A[2]+B[2])/2.] )
126 rc = h[
'res'+
str(s)+
'H'].Fill( (A[1]+B[1])/2.-state.getPos()[1])
128 for s
in range(1, nStations+1):
129 if not (len(sortedClusters[s][
'V']) * len(sortedClusters[s][
'H']) ) ==1:
continue
131 for proj
in [
'V',
'H']:
132 clkey = sortedClusters[s][proj][0][0]
133 aCl = self.
M.trackTask.clusScifi[clkey]
134 L = sortedClusters[s][proj][0][1]
135 rc = h[
'extrap'+
str(s)+proj].Fill(abs(L))
138 mat = sortedClusters[s][proj][0][4]
141 timeCorr[proj] = time - abs(L)/self.
V
143 dt = timeCorr[
'H'] - timeCorr[
'V']
144 rc = h[
'CTR_Scifi'+
str(s)+tag].Fill(dt)
145 matH,matV = sortedClusters[s][
'H'][0][4],sortedClusters[s][
'V'][0][4]
146 rc = h[
'CTR_Scifi'+
str(100*s+10*matH+matV)+tag].Fill(dt)
147 if abs(slopeX)<0.1
and abs(slopeY)<0.1:
148 rc = h[
'CTR_Scifi_beam'+
str(s)+tag].Fill(dt)
149 rc = h[
'CTR_Scifi_beam'+
str(100*s+10*matH+matV)+tag].Fill(dt)
150 dR = sortedClusters[s][
'V'][0][2] - sortedClusters[s][
'H'][0][3]
151 rc = h[
'resX'+
str(s)+
'V'].Fill(dR)
152 dR = sortedClusters[s][
'H'][0][2]-sortedClusters[s][
'V'][0][3]
153 rc = h[
'resX'+
str(s)+
'H'].Fill(dR)
157 for s
in range(1, nStations+1):
158 if not (len(sortedClusters[s][
'V']) * len(sortedClusters[s][
'H']) ) ==1:
continue
160 for proj
in [
'V',
'H']:
161 clkey = sortedClusters[s][proj][0][0]
162 aCl = self.
M.trackTask.clusScifi[clkey]
163 L = sortedClusters[s][proj][0][1]
166 mat = sortedClusters[s][proj][0][4]
171 stationTimes[s] = [sTime/2.,(sortedClusters[s][
'H'][0][5] + sortedClusters[s][
'V'][0][5])/2.]
172 for s1
in range(1, nStations):
173 if not s1
in stationTimes:
continue
174 for s2
in range(s1+1, nStations+1):
175 if not s2
in stationTimes:
continue
176 dT = stationTimes[s2][0] - stationTimes[s1][0]
178 dZ = stationTimes[s2][1] - stationTimes[s1][1]
179 dL = dZ * ROOT.TMath.Sqrt( slopeX**2+slopeY**2+1 )
180 if slopeY>0.1: dL = -dL
181 dT -= dL / u.speedOfLight
182 rc = h[
'CTR_ScifiStation'+
str(s1*10+s2)+tag].Fill(dT)
183 if abs(slopeX)<0.1
and abs(slopeY)<0.1:
184 rc = h[
'CTR_ScifiStation_beam'+
str(s1*10+s2)+tag].Fill(dT)
257 def minimize(self,b=""):
260 ut.bookHist(h,
'commonBlock',
'',100,0.,100.)
262 for s
in range(1, nStations+1):
263 for matH
in range(nMats):
264 for matV
in range(nMats):
265 key = 100*s+10*matH+matV
267 h[
'commonBlock'].SetBinContent(matH*10+matV,dt)
269 ierflg = ctypes.c_int(0)
270 vstart = array(
'd',[0]*npar)
271 gMinuit = ROOT.TMinuit(npar)
273 gMinuit.SetErrorDef(1.0)
274 gMinuit.SetMaxIterations(10000)
277 for proj
in [
'H',
'V']:
278 for m
in range(nMats):
279 name =
"s"+
str(s)+proj+
str(m)
280 gMinuit.mnparm(p, name, vstart[p], err, 0.,0.,ierflg)
282 gMinuit.FixParameter(0)
283 strat = array(
'd',[0])
284 gMinuit.mnexcm(
"SET STR",strat,1,ierflg)
285 gMinuit.mnexcm(
"SIMPLEX",vstart,npar,ierflg)
286 gMinuit.mnexcm(
"MIGRAD",vstart,npar,ierflg)
288 cor = ctypes.c_double(0)
289 ecor = ctypes.c_double(0)
291 for proj
in [
'H',
'V']:
292 for m
in range(nMats):
293 rc = gMinuit.GetParameter(p,cor,ecor)
297 with open(
'ScifiTimeAlignment_v1',
'wb')
as fh:
305 for s1
in range(1, nStations+1):
306 for s2
in range(s1+1, nStations+1):
308 histo = h[
'CTR_ScifiStation'+b+
str(key)+tag]
309 Fun = histo.GetFunction(
'gaus')
311 for s1
in range(1, nStations+1):
312 for s2
in range(s1+1, nStations+1):
315 h[
'commonBlock'].SetBinContent(key,dt)
317 ierflg = ctypes.c_int(0)
318 vstart = array(
'd',[0,-0.3365,-0.975,0.11,0.239])
319 gMinuit = ROOT.TMinuit(npar)
321 gMinuit.SetErrorDef(1.0)
322 gMinuit.SetMaxIterations(10000)
325 for s
in range(1, nStations+1):
326 name =
"station"+
str(s)
327 gMinuit.mnparm(p, name, vstart[p], err, 0.,0.,ierflg)
329 gMinuit.FixParameter(0)
330 strat = array(
'd',[0])
331 gMinuit.mnexcm(
"SET STR",strat,1,ierflg)
332 gMinuit.mnexcm(
"SIMPLEX",vstart,npar,ierflg)
333 gMinuit.mnexcm(
"MIGRAD",vstart,npar,ierflg)
335 cor = ctypes.c_double(0)
336 ecor = ctypes.c_double(0)
337 for s
in range(1, nStations+1):
338 rc = gMinuit.GetParameter(s-1,cor,ecor)
341 with open(
'ScifiTimeAlignment_v2',
'wb')
as fh: