26 |
C then in a second step we check the residuals of the single |
C then in a second step we check the residuals of the single |
27 |
C measurements, reject if > 10 sigma, calculate chi2 and "quality" |
C measurements, reject if > 10 sigma, calculate chi2 and "quality" |
28 |
C beta is taken as good if chi2<20 and quality>10 |
C beta is taken as good if chi2<20 and quality>10 |
29 |
|
C mar-08 WM: Call to "newbeta" changed, now a flag tells the function if the |
30 |
|
C call comes from "tofl2com" or form "toftrack" |
31 |
|
C mar-08 WM: Bug found in dEdx if check_charge>1 |
32 |
C****************************************************************************** |
C****************************************************************************** |
33 |
|
|
34 |
INTEGER FUNCTION TOFL2COM() |
INTEGER FUNCTION TOFL2COM() |
1057 |
tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta13) |
tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta13) |
1058 |
xkorr = atten(left,11,i,yhelp) |
xkorr = atten(left,11,i,yhelp) |
1059 |
c write(40+i,*) yhelp,xkorr |
c write(40+i,*) yhelp,xkorr |
1060 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1061 |
adctof_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr |
adctof_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr |
1062 |
endif |
endif |
1063 |
|
|
1066 |
tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta13) |
tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta13) |
1067 |
xkorr = atten(right,11,i,yhelp) |
xkorr = atten(right,11,i,yhelp) |
1068 |
c write(40+i,*) yhelp,xkorr |
c write(40+i,*) yhelp,xkorr |
1069 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1070 |
adctof_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr |
adctof_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr |
1071 |
endif |
endif |
1072 |
ENDIF |
ENDIF |
1083 |
tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta13) |
tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta13) |
1084 |
xkorr = atten(left,12,i,xhelp) |
xkorr = atten(left,12,i,xhelp) |
1085 |
c write(50+i,*) xhelp,xkorr |
c write(50+i,*) xhelp,xkorr |
1086 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1087 |
adctof_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr |
adctof_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr |
1088 |
endif |
endif |
1089 |
|
|
1092 |
tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta13) |
tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta13) |
1093 |
xkorr = atten(right,12,i,xhelp) |
xkorr = atten(right,12,i,xhelp) |
1094 |
c write(50+i,*) xhelp,xkorr |
c write(50+i,*) xhelp,xkorr |
1095 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1096 |
adctof_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr |
adctof_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr |
1097 |
endif |
endif |
1098 |
ENDIF |
ENDIF |
1111 |
tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta13) |
tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta13) |
1112 |
xkorr = atten(left,21,i,xhelp) |
xkorr = atten(left,21,i,xhelp) |
1113 |
c write(60+i,*) xhelp,xkorr |
c write(60+i,*) xhelp,xkorr |
1114 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1115 |
adctof_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr |
adctof_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr |
1116 |
endif |
endif |
1117 |
|
|
1121 |
xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2)) |
xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2)) |
1122 |
xkorr = atten(right,21,i,xhelp) |
xkorr = atten(right,21,i,xhelp) |
1123 |
c write(60+i,*) xhelp,xkorr |
c write(60+i,*) xhelp,xkorr |
1124 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1125 |
adctof_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr |
adctof_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr |
1126 |
endif |
endif |
1127 |
ENDIF |
ENDIF |
1139 |
tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta13) |
tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta13) |
1140 |
xkorr = atten(left,22,i,yhelp) |
xkorr = atten(left,22,i,yhelp) |
1141 |
c write(70+i,*) yhelp,xkorr |
c write(70+i,*) yhelp,xkorr |
1142 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1143 |
adctof_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr |
adctof_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr |
1144 |
endif |
endif |
1145 |
|
|
1148 |
tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta13) |
tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta13) |
1149 |
xkorr = atten(right,22,i,yhelp) |
xkorr = atten(right,22,i,yhelp) |
1150 |
c write(70+i,*) yhelp,xkorr |
c write(70+i,*) yhelp,xkorr |
1151 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1152 |
adctof_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr |
adctof_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr |
1153 |
endif |
endif |
1154 |
ENDIF |
ENDIF |
1167 |
tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta13) |
tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta13) |
1168 |
xkorr = atten(left,31,i,yhelp) |
xkorr = atten(left,31,i,yhelp) |
1169 |
c write(80+i,*) yhelp,xkorr |
c write(80+i,*) yhelp,xkorr |
1170 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1171 |
adctof_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr |
adctof_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr |
1172 |
endif |
endif |
1173 |
|
|
1176 |
tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta13) |
tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta13) |
1177 |
xkorr = atten(right,31,i,yhelp) |
xkorr = atten(right,31,i,yhelp) |
1178 |
c write(80+i,*) yhelp,xkorr |
c write(80+i,*) yhelp,xkorr |
1179 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1180 |
adctof_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr |
adctof_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr |
1181 |
endif |
endif |
1182 |
ENDIF |
ENDIF |
1193 |
tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta13) |
tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta13) |
1194 |
xkorr = atten(left,32,i,xhelp) |
xkorr = atten(left,32,i,xhelp) |
1195 |
c write(90+i,*) xhelp,xkorr |
c write(90+i,*) xhelp,xkorr |
1196 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1197 |
adctof_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr |
adctof_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr |
1198 |
endif |
endif |
1199 |
|
|
1202 |
tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta13) |
tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta13) |
1203 |
xkorr = atten(right,32,i,xhelp) |
xkorr = atten(right,32,i,xhelp) |
1204 |
c write(90+i,*) xhelp,xkorr |
c write(90+i,*) xhelp,xkorr |
1205 |
if (iz.le.1) xkorr=xkorr/hepratio |
xkorr=xkorr/hepratio |
1206 |
adctof_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr |
adctof_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr |
1207 |
endif |
endif |
1208 |
ENDIF |
ENDIF |
1587 |
C if (icount.gt.0) beta_mean=sxw/sw |
C if (icount.gt.0) beta_mean=sxw/sw |
1588 |
C betatof_a(13) = beta_mean |
C betatof_a(13) = beta_mean |
1589 |
C |
C |
1590 |
|
|
1591 |
C-------- New mean beta calculation ----------------------- |
C-------- New mean beta calculation ----------------------- |
1592 |
|
|
1593 |
do i=1,12 |
do i=1,12 |
1594 |
btemp(i) = betatof_a(i) |
btemp(i) = betatof_a(i) |
1595 |
enddo |
enddo |
1596 |
|
|
1597 |
betatof_a(13)=newbeta(btemp,hitvec,10.,10.,20.) |
betatof_a(13)=newbeta(1,btemp,hitvec,10.,10.,20.) |
1598 |
|
|
1599 |
C-------------------------------------------------------------- |
C-------------------------------------------------------------- |
1600 |
C write(*,*) betatof_a |
C write(*,*) betatof_a |
2117 |
C**************************************************************************** |
C**************************************************************************** |
2118 |
C**************************************************************************** |
C**************************************************************************** |
2119 |
|
|
2120 |
function newbeta(b,hitvec,resmax,qualitycut,chi2cut) |
function newbeta(iflag,b,hitvec,resmax,qualitycut,chi2cut) |
2121 |
|
|
2122 |
include 'input_tof.txt' |
include 'input_tof.txt' |
2123 |
include 'output_tof.txt' |
include 'output_tof.txt' |
2127 |
REAL resmax,qualitycut,chi2cut |
REAL resmax,qualitycut,chi2cut |
2128 |
REAL w_i(12),w_il(6),quality,res,betachi,beta_mean_inv |
REAL w_i(12),w_il(6),quality,res,betachi,beta_mean_inv |
2129 |
REAL sw,sxw,b(12),beta_mean,chi2,xhelp |
REAL sw,sxw,b(12),beta_mean,chi2,xhelp |
2130 |
|
REAL tdcfl(4,12) |
2131 |
|
|
2132 |
INTEGER icount,hitvec(6) |
INTEGER iflag,icount,hitvec(6) |
2133 |
|
|
2134 |
INTEGER itop(12),ibot(12) |
INTEGER itop(12),ibot(12) |
2135 |
DATA itop /1,1,2,2,3,3,4,4,1,1,2,2/ |
DATA itop /1,1,2,2,3,3,4,4,1,1,2,2/ |
2144 |
tof31_i = hitvec(5) |
tof31_i = hitvec(5) |
2145 |
tof32_i = hitvec(6) |
tof32_i = hitvec(6) |
2146 |
|
|
2147 |
c write(*,*) '------------ In NEWBETA ----------------' |
if (iflag.eq.1) then ! call from tofl2com |
2148 |
c write(*,*) hitvec |
do i=1,4 |
2149 |
c write(*,*) b |
do j=1,12 |
2150 |
|
tdcfl(i,j) = tdcflagtof(i,j) |
2151 |
|
enddo |
2152 |
|
enddo |
2153 |
|
endif |
2154 |
|
|
2155 |
|
if (iflag.eq.2) then ! call from toftrk |
2156 |
|
do i=1,4 |
2157 |
|
do j=1,12 |
2158 |
|
tdcfl(i,j) = tdcflag(i,j) |
2159 |
|
enddo |
2160 |
|
enddo |
2161 |
|
endif |
2162 |
|
|
2163 |
|
|
2164 |
C--- Find out ToF layers with artificial TDC values ------------- |
C--- Find out ToF layers with artificial TDC values ------------- |
2165 |
|
|
2167 |
w_il(jj) = 1000. |
w_il(jj) = 1000. |
2168 |
enddo |
enddo |
2169 |
|
|
|
C write(*,*) tdcflagtof |
|
2170 |
|
|
2171 |
if (tof11_i.gt.0) then |
if (tof11_i.gt.0) then |
2172 |
if ((tofmask(ch11a(tof11_i),hb11a(tof11_i)).gt.0).or. |
if ((tofmask(ch11a(tof11_i),hb11a(tof11_i)).gt.0).or. |
2173 |
& (tofmask(ch11b(tof11_i),hb11b(tof11_i)).gt.0)) then |
& (tofmask(ch11b(tof11_i),hb11b(tof11_i)).gt.0)) then |
2174 |
w_il(1)=0 |
w_il(1)=0 |
2175 |
i1=tdcflagtof(ch11a(tof11_i),hb11a(tof11_i)) |
i1=tdcfl(ch11a(tof11_i),hb11a(tof11_i)) |
2176 |
i2=tdcflagtof(ch11b(tof11_i),hb11b(tof11_i)) |
i2=tdcfl(ch11b(tof11_i),hb11b(tof11_i)) |
|
c write(*,*) '11 ',i1,i2 |
|
2177 |
if ((i1.eq.1).or.(i2.eq.1)) w_il(1) = 1 ! tdcflag |
if ((i1.eq.1).or.(i2.eq.1)) w_il(1) = 1 ! tdcflag |
2178 |
endif |
endif |
2179 |
endif |
endif |
2182 |
if ((tofmask(ch12a(tof12_i),hb12a(tof12_i)).gt.0).or. |
if ((tofmask(ch12a(tof12_i),hb12a(tof12_i)).gt.0).or. |
2183 |
& (tofmask(ch12b(tof12_i),hb12b(tof12_i)).gt.0)) then |
& (tofmask(ch12b(tof12_i),hb12b(tof12_i)).gt.0)) then |
2184 |
w_il(2)=0 |
w_il(2)=0 |
2185 |
i1=tdcflagtof(ch12a(tof12_i),hb12a(tof12_i)) |
i1=tdcfl(ch12a(tof12_i),hb12a(tof12_i)) |
2186 |
i2=tdcflagtof(ch12b(tof12_i),hb12b(tof12_i)) |
i2=tdcfl(ch12b(tof12_i),hb12b(tof12_i)) |
|
c write(*,*) '12 ',i1,i2 |
|
2187 |
if ((i1.eq.1).or.(i2.eq.1)) w_il(2) = 1 ! tdcflag |
if ((i1.eq.1).or.(i2.eq.1)) w_il(2) = 1 ! tdcflag |
2188 |
endif |
endif |
2189 |
endif |
endif |
2192 |
if ((tofmask(ch21a(tof21_i),hb21a(tof21_i)).gt.0).or. |
if ((tofmask(ch21a(tof21_i),hb21a(tof21_i)).gt.0).or. |
2193 |
& (tofmask(ch21b(tof21_i),hb21b(tof21_i)).gt.0)) then |
& (tofmask(ch21b(tof21_i),hb21b(tof21_i)).gt.0)) then |
2194 |
w_il(3)=0 |
w_il(3)=0 |
2195 |
i1=tdcflagtof(ch21a(tof21_i),hb21a(tof21_i)) |
i1=tdcfl(ch21a(tof21_i),hb21a(tof21_i)) |
2196 |
i2=tdcflagtof(ch21b(tof21_i),hb21b(tof21_i)) |
i2=tdcfl(ch21b(tof21_i),hb21b(tof21_i)) |
|
c write(*,*) '21 ',i1,i2 |
|
2197 |
if ((i1.eq.1).or.(i2.eq.1)) w_il(3) = 1 ! tdcflag |
if ((i1.eq.1).or.(i2.eq.1)) w_il(3) = 1 ! tdcflag |
2198 |
endif |
endif |
2199 |
endif |
endif |
2202 |
if ((tofmask(ch22a(tof22_i),hb22a(tof22_i)).gt.0).or. |
if ((tofmask(ch22a(tof22_i),hb22a(tof22_i)).gt.0).or. |
2203 |
& (tofmask(ch22b(tof22_i),hb22b(tof22_i)).gt.0)) then |
& (tofmask(ch22b(tof22_i),hb22b(tof22_i)).gt.0)) then |
2204 |
w_il(4)=0 |
w_il(4)=0 |
2205 |
i1=tdcflagtof(ch22a(tof22_i),hb22a(tof22_i)) |
i1=tdcfl(ch22a(tof22_i),hb22a(tof22_i)) |
2206 |
i2=tdcflagtof(ch22b(tof22_i),hb22b(tof22_i)) |
i2=tdcfl(ch22b(tof22_i),hb22b(tof22_i)) |
|
c write(*,*) '22 ',i1,i2 |
|
2207 |
if ((i1.eq.1).or.(i2.eq.1)) w_il(4) = 1 ! tdcflag |
if ((i1.eq.1).or.(i2.eq.1)) w_il(4) = 1 ! tdcflag |
2208 |
endif |
endif |
2209 |
endif |
endif |
2212 |
if ((tofmask(ch31a(tof31_i),hb11a(tof31_i)).gt.0).or. |
if ((tofmask(ch31a(tof31_i),hb11a(tof31_i)).gt.0).or. |
2213 |
& (tofmask(ch31b(tof31_i),hb31b(tof31_i)).gt.0)) then |
& (tofmask(ch31b(tof31_i),hb31b(tof31_i)).gt.0)) then |
2214 |
w_il(5)=0 |
w_il(5)=0 |
2215 |
i1=tdcflagtof(ch31a(tof31_i),hb31a(tof31_i)) |
i1=tdcfl(ch31a(tof31_i),hb31a(tof31_i)) |
2216 |
i2=tdcflagtof(ch31b(tof31_i),hb31b(tof31_i)) |
i2=tdcfl(ch31b(tof31_i),hb31b(tof31_i)) |
|
c write(*,*) '31 ',i1,i2 |
|
2217 |
if ((i1.eq.1).or.(i2.eq.1)) w_il(5) = 1 ! tdcflag |
if ((i1.eq.1).or.(i2.eq.1)) w_il(5) = 1 ! tdcflag |
2218 |
endif |
endif |
2219 |
endif |
endif |
2222 |
if ((tofmask(ch32a(tof32_i),hb32a(tof32_i)).gt.0).or. |
if ((tofmask(ch32a(tof32_i),hb32a(tof32_i)).gt.0).or. |
2223 |
& (tofmask(ch32b(tof32_i),hb32b(tof32_i)).gt.0)) then |
& (tofmask(ch32b(tof32_i),hb32b(tof32_i)).gt.0)) then |
2224 |
w_il(6)=0 |
w_il(6)=0 |
2225 |
i1=tdcflagtof(ch32a(tof32_i),hb32a(tof32_i)) |
i1=tdcfl(ch32a(tof32_i),hb32a(tof32_i)) |
2226 |
i2=tdcflagtof(ch32b(tof32_i),hb32b(tof32_i)) |
i2=tdcfl(ch32b(tof32_i),hb32b(tof32_i)) |
|
c write(*,*) '32 ',i1,i2 |
|
2227 |
if ((i1.eq.1).or.(i2.eq.1)) w_il(6) = 1 ! tdcflag |
if ((i1.eq.1).or.(i2.eq.1)) w_il(6) = 1 ! tdcflag |
2228 |
endif |
endif |
2229 |
endif |
endif |
2230 |
|
|
|
c write(*,*) w_il |
|
2231 |
C------------------------------------------------------------------------ |
C------------------------------------------------------------------------ |
2232 |
C--- Set weights for the 12 measurements using information for top and bottom: |
C--- Set weights for the 12 measurements using information for top and bottom: |
2233 |
C--- if no measurements: weight = set to very high value=> not used |
C--- if no measurements: weight = set to very high value=> not used |
2247 |
w_i(jj) = 1./xhelp |
w_i(jj) = 1./xhelp |
2248 |
ENDDO |
ENDDO |
2249 |
|
|
|
c write(*,*) w_i |
|
|
|
|
2250 |
C======================================================================== |
C======================================================================== |
2251 |
C--- Calculate mean beta for the first time ----------------------------- |
C--- Calculate mean beta for the first time ----------------------------- |
2252 |
C--- We are using "1/beta" since its error is gaussian ------------------ |
C--- We are using "1/beta" since its error is gaussian ------------------ |
2267 |
if (icount.gt.0) beta_mean=1./(sxw/sw) |
if (icount.gt.0) beta_mean=1./(sxw/sw) |
2268 |
beta_mean_inv = 1./beta_mean |
beta_mean_inv = 1./beta_mean |
2269 |
|
|
|
c write(*,*) icount,beta_mean |
|
2270 |
|
|
2271 |
C--- Calculate beta for the second time, use residuals of the single |
C--- Calculate beta for the second time, use residuals of the single |
2272 |
C--- measurements to get a chi2 value |
C--- measurements to get a chi2 value |
2282 |
IF ((abs(1./b(jj)).gt.0.1).and.(abs(1./b(jj)).lt.15.) |
IF ((abs(1./b(jj)).gt.0.1).and.(abs(1./b(jj)).lt.15.) |
2283 |
& .and.(w_i(jj).GT.0.01)) THEN |
& .and.(w_i(jj).GT.0.01)) THEN |
2284 |
res = beta_mean_inv - (1./b(jj)) ; |
res = beta_mean_inv - (1./b(jj)) ; |
|
C write(*,*) jj,abs(res*w_i(jj)) |
|
2285 |
if (abs(res*w_i(jj)).lt.resmax) THEN |
if (abs(res*w_i(jj)).lt.resmax) THEN |
2286 |
chi2 = chi2 + (res*w_i(jj))**2. |
chi2 = chi2 + (res*w_i(jj))**2. |
2287 |
icount = icount+1 |
icount = icount+1 |
2302 |
beta_mean=100. |
beta_mean=100. |
2303 |
if ((chi2.lt.chi2cut).and.(quality.gt.qualitycut)) |
if ((chi2.lt.chi2cut).and.(quality.gt.qualitycut)) |
2304 |
& beta_mean = betachi |
& beta_mean = betachi |
|
c write(*,*) icount,chi2,quality,beta_mean |
|
2305 |
newbeta = beta_mean |
newbeta = beta_mean |
2306 |
|
|
2307 |
END |
END |
2309 |
C**************************************************************************** |
C**************************************************************************** |
2310 |
|
|
2311 |
|
|
|
|
|