56 self.
tag = monitor.iteration
58 for s
in range(1, nStations+1):
59 ut.bookHist(h,
'CTR_Scifi'+
str(s)+tag,
'CTR '+
str(s)+tag+
'; dt [ns]; ',100,-5.,5.)
60 ut.bookHist(h,
'CTR_Scifi_beam'+
str(s)+tag,
'CTR beam'+
str(s)+tag+
'; dt [ns]; ',100,-5.,5.)
61 ut.bookHist(h,
'dT_posxV'+
str(s)+tag,
'; x [cm]; dt [ns]',100,-50.,-30., 100,-5.,5.)
62 ut.bookHist(h,
'dT_posxH'+
str(s)+tag,
'; x [cm]; dt [ns]',100,-50.,-30., 100,-5.,5.)
63 ut.bookHist(h,
'dT_posyH'+
str(s)+tag,
'; y [cm]; dt [ns]',100,35,55., 100,-5.,5.)
64 ut.bookHist(h,
'dT_posyV'+
str(s)+tag,
'; y [cm]; dt [ns]',100,35,55., 100,-5.,5.)
65 ut.bookHist(h,
'CTR_timeH_posy_Scifi'+
str(s)+tag,
'CTR '+
str(s)+tag+
'; y [cm]; cluster time [ns]; ',100,35,55,100,-5.,15.)
66 ut.bookHist(h,
'CTR_timeV_posy_Scifi'+
str(s)+tag,
'CTR '+
str(s)+tag+
'; y [cm]; cluster time [ns]; ',100,35,55,100,-5.,15.)
68 for matH
in range(nMats):
69 for matV
in range(nMats):
70 ut.bookHist(h,
'CTR_Scifi'+
str(s*100+10*matH+matV)+tag,
'CTR '+
str(s)+tag+
'; dt [ns]; ',100,-5.,5.)
71 ut.bookHist(h,
'CTR_Scifi_beam'+
str(s*100+10*matH+matV)+tag,
'CTR beam'+
str(s)+tag+
'; dt [ns]; ',100,-5.,5.)
74 if s==2
and channelTimeAlignment==1:
75 for arr
in range(nSiPMArrays):
76 for chan
in range(nChannelsPerSiPMArray):
77 detid =
int(s*1e6+0*1e5+matH*1e4+arr*1e3+chan)
78 ut.bookHist(h,
'CTR_ScifiMat'+
str(detid)+tag,
'CTR mat '+
str(detid)+tag+
'; dt [ns]; ',100,-5.,5.)
81 ut.bookHist(h,
'res'+
str(s)+self.
projs[p],
'd; [cm]; ',100,-1.,1.)
82 ut.bookHist(h,
'resX'+
str(s)+self.
projs[p],
'd; [cm]; ',100,-1.,1.)
83 ut.bookHist(h,
'extrap'+
str(s)+self.
projs[p],
'SiPM distance; L [cm]; ',100,0.,50.)
85 for s1
in range(1, nStations):
86 for s2
in range(s1+1, nStations+1):
87 ut.bookHist(h,
'CTR_ScifiStation'+
str(s1*10+s2)+tag,
'CTR station'+
str(s1*10+s2)+
'; dt [ns]; ',100,-5.,5.)
88 ut.bookHist(h,
'CTR_ScifiStation_beam'+
str(s1*10+s2)+tag,
'CTR station beam'+
str(s1*10+s2)+
'; dt [ns]; ',100,-5.,5.)
90 if channelTimeAlignment==1
and tag ==
"v0prime":
92 for s
in range(1, nStations+1):
94 self.
tdcScifiStationCalib[s] = [0,{
'H': [0, {arr: {ch: 0
for ch
in range(nChannelsPerSiPMArray)}
for arr
in range(nSiPMArrays)},],\
95 'V': [0, {arr: {ch: 0
for ch
in range(nChannelsPerSiPMArray)}
for arr
in range(nSiPMArrays)},],},]
98 elif channelTimeAlignment==0
and tag ==
"v0":
100 for s
in range(1, nStations+1):
106 with open(
'ScifiTimeAlignment_'+self.
tag,
'rb')
as fh:
109 self.
V = M.Scifi.GetConfParF(
"Scifi/signalSpeed")
115 for nHit
in range(event.Digi_ScifiHits.GetEntries()):
116 DetID2Key[event.Digi_ScifiHits[nHit].GetDetectorID()] = nHit
118 for aTrack
in self.
M.Reco_MuonTracks:
119 if not aTrack.GetUniqueID()==1:
continue
120 fitStatus = aTrack.getFitStatus()
121 if not fitStatus.isFitConverged():
continue
122 state = aTrack.getFittedState()
124 slopeX = mom.X()/mom.Z()
125 slopeY = mom.Y()/mom.Z()
129 for s
in range(1, nStations+1): sortedClusters[s] = {
'H':[],
'V':[]}
130 for nM
in range(aTrack.getNumPointsWithMeasurement()):
131 state = aTrack.getFittedState(nM)
132 Meas = aTrack.getPointWithMeasurement(nM)
133 W = Meas.getRawMeasurement()
135 aCl = self.
M.trackTask.clusScifi[clkey]
136 aHit = event.Digi_ScifiHits[DetID2Key[aCl.GetFirst()]]
137 detID = aCl.GetFirst()
140 mat = (detID//10000)%10
141 if aHit.isVertical():
142 L = B[1]-state.getPos()[1]
143 sortedClusters[s][
'V'].append( [clkey,L,B[0],state.getPos()[1],mat,(A[2]+B[2])/2.,state.getPos()[0],aCl.GetFirst(),aCl.GetTime()] )
144 rc = h[
'res'+
str(s)+
'V'].Fill( (A[0]+B[0])/2.-state.getPos()[0])
146 L = A[0]-state.getPos()[0]
147 sortedClusters[s][
'H'].append( [clkey,L,A[1],state.getPos()[0],mat,(A[2]+B[2])/2.,state.getPos()[1],aCl.GetFirst(),aCl.GetTime()] )
148 rc = h[
'res'+
str(s)+
'H'].Fill( (A[1]+B[1])/2.-state.getPos()[1])
150 for s
in range(1, nStations+1):
151 if not (len(sortedClusters[s][
'V']) * len(sortedClusters[s][
'H']) ) ==1:
continue
153 for proj
in [
'V',
'H']:
154 clkey = sortedClusters[s][proj][0][0]
155 aCl = self.
M.trackTask.clusScifi[clkey]
156 L = sortedClusters[s][proj][0][1]
157 rc = h[
'extrap'+
str(s)+proj].Fill(abs(L))
160 mat = sortedClusters[s][proj][0][4]
161 sipm_array =
int(sortedClusters[s][proj][0][7]/1000)%10
162 sipm_channel = sortedClusters[s][proj][0][7]%1000
163 if channelTimeAlignment==1
and s==2
and proj==
'H':
167 timeCorr[proj] = time - abs(L)/self.
V
169 dt = timeCorr[
'H'] - timeCorr[
'V']
170 rc = h[
'CTR_Scifi'+
str(s)+tag].Fill(dt)
171 for proj
in [
'V',
'H']:
174 if channelTimeAlignment==1
and s==2
and proj==
'H':
175 rc = h[
'CTR_ScifiMat'+
str(sortedClusters[s][proj][0][7])+tag].Fill(dt)
176 rc=h[
'dT_posxV'+
str(s)+tag].Fill(sortedClusters[s][
'V'][0][6],dt)
177 rc=h[
'dT_posxH'+
str(s)+tag].Fill(sortedClusters[s][
'H'][0][3],dt)
178 rc=h[
'dT_posyH'+
str(s)+tag].Fill(sortedClusters[s][
'H'][0][6], dt)
179 rc=h[
'dT_posyV'+
str(s)+tag].Fill(sortedClusters[s][
'V'][0][3], dt)
180 rc=h[
'CTR_timeH_posy_Scifi'+
str(s)+tag].Fill(sortedClusters[s][
'H'][0][6], sortedClusters[s][proj][0][8])
181 rc=h[
'CTR_timeV_posy_Scifi'+
str(s)+tag].Fill(sortedClusters[s][
'V'][0][3],sortedClusters[s][proj][0][8])
183 matH,matV = sortedClusters[s][
'H'][0][4],sortedClusters[s][
'V'][0][4]
184 rc = h[
'CTR_Scifi'+
str(100*s+10*matH+matV)+tag].Fill(dt)
185 if abs(slopeX)<0.1
and abs(slopeY)<0.1:
186 rc = h[
'CTR_Scifi_beam'+
str(s)+tag].Fill(dt)
187 rc = h[
'CTR_Scifi_beam'+
str(100*s+10*matH+matV)+tag].Fill(dt)
188 dR = sortedClusters[s][
'V'][0][2] - sortedClusters[s][
'H'][0][3]
189 rc = h[
'resX'+
str(s)+
'V'].Fill(dR)
190 dR = sortedClusters[s][
'H'][0][2]-sortedClusters[s][
'V'][0][3]
191 rc = h[
'resX'+
str(s)+
'H'].Fill(dR)
193 if tag!=
'v0' and tag!=
'v0prime':
195 for s
in range(1, nStations+1):
196 if not (len(sortedClusters[s][
'V']) * len(sortedClusters[s][
'H']) ) ==1:
continue
198 for proj
in [
'V',
'H']:
199 clkey = sortedClusters[s][proj][0][0]
200 aCl = self.
M.trackTask.clusScifi[clkey]
201 L = sortedClusters[s][proj][0][1]
204 mat = sortedClusters[s][proj][0][4]
209 stationTimes[s] = [sTime/2.,(sortedClusters[s][
'H'][0][5] + sortedClusters[s][
'V'][0][5])/2.]
210 for s1
in range(1, nStations):
211 if not s1
in stationTimes:
continue
212 for s2
in range(s1+1, nStations+1):
213 if not s2
in stationTimes:
continue
214 dT = stationTimes[s2][0] - stationTimes[s1][0]
216 dZ = stationTimes[s2][1] - stationTimes[s1][1]
217 dL = dZ * ROOT.TMath.Sqrt( slopeX**2+slopeY**2+1 )
218 if slopeY>0.1: dL = -dL
219 dT -= dL / u.speedOfLight
220 rc = h[
'CTR_ScifiStation'+
str(s1*10+s2)+tag].Fill(dT)
221 if abs(slopeX)<0.1
and abs(slopeY)<0.1:
222 rc = h[
'CTR_ScifiStation_beam'+
str(s1*10+s2)+tag].Fill(dT)
387 for s1
in range(1, nStations+1):
388 for s2
in range(s1+1, nStations+1):
390 histo = h[
'CTR_ScifiStation'+b+
str(key)+tag]
391 Fun = histo.GetFunction(
'gaus')
393 for s1
in range(1, nStations+1):
394 for s2
in range(s1+1, nStations+1):
397 h[
'commonBlock'].SetBinContent(key,dt)
399 ierflg = ctypes.c_int(0)
400 vstart = array(
'd',[0]*npar)
401 gMinuit = ROOT.TMinuit(npar)
403 gMinuit.SetErrorDef(1.0)
404 gMinuit.SetMaxIterations(10000)
407 for s
in range(1, nStations+1):
408 name =
"station"+
str(s)
409 gMinuit.mnparm(p, name, vstart[p], err, 0.,0.,ierflg)
411 gMinuit.FixParameter(0)
412 strat = array(
'd',[0])
413 gMinuit.mnexcm(
"SET STR",strat,1,ierflg)
414 gMinuit.mnexcm(
"SIMPLEX",vstart,npar,ierflg)
415 gMinuit.mnexcm(
"MIGRAD",vstart,npar,ierflg)
417 cor = ctypes.c_double(0)
418 ecor = ctypes.c_double(0)
419 for s
in range(1, nStations+1):
420 rc = gMinuit.GetParameter(s-1,cor,ecor)
423 with open(
'ScifiTimeAlignment_v2',
'wb')
as fh: