/[PAMELA software]/DarthVader/ToFLevel2/src/toftrk.for
ViewVC logotype

Diff of /DarthVader/ToFLevel2/src/toftrk.for

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by mocchiut, Mon Jan 22 10:45:26 2007 UTC revision 1.19 by mocchiut, Mon Nov 23 09:50:51 2009 UTC
# Line 7  C     Changed to use DOTRACK2 Line 7  C     Changed to use DOTRACK2
7  C     Beta calculation: now the flightpath (instead of cos(theta)) is used  C     Beta calculation: now the flightpath (instead of cos(theta)) is used
8  C     Beta calculation: all 4 TDV measurements must be < 4095 (in the old  C     Beta calculation: all 4 TDV measurements must be < 4095 (in the old
9  C     routine it was (t1+t2)<8000  C     routine it was (t1+t2)<8000
10  C      C
11  C     08-12-06 WM:  C     08-12-06 WM:
12  C     adc_c-bug :  The raw ADC value was multiplied with cos(theta)  C     adc_c-bug :  The raw ADC value was multiplied with cos(theta)
13  C     and AFTER that there was an if statement "if tof32(right,i,iadc) < 4095"  C     and AFTER that there was an if statement "if tof32(right,i,iadc) < 4095"
14  C      C
15  C  jan-07 GF: ADC/TDCflags(4,12) inserted to flag artificial ADC/TDC  C  jan-07 GF: ADC/TDCflags(4,12) inserted to flag artificial ADC/TDC
16  C             values  C             values
17  C  jan-07 WM: artificial ADC values created using attenuation calibration  C  jan-07 WM: artificial ADC values created using attenuation calibration
18  C  jan-07 WM: artificial TDC values created using xy_coor calibration  C  jan-07 WM: artificial TDC values created using xy_coor calibration
# Line 20  C  jan-07 WM: modified xtofpos flag "101 Line 20  C  jan-07 WM: modified xtofpos flag "101
20  C             dimension of the paddle +/- 10 cm  C             dimension of the paddle +/- 10 cm
21  C  jan-07 WM: if xtofpos=101 then this paddle is not used for beta  C  jan-07 WM: if xtofpos=101 then this paddle is not used for beta
22  C             calculation  C             calculation
23  C  jan-07 WM: in the xtofpos calculation a check for TDC.ne.4095 was  C  jan-07 WM: in the xtofpos calculation a check for TDC.ne.4095 was
24  C             inserted. In the old code one would still calculate a  C             inserted. In the old code one would still calculate a
25  C             xtofpos-value even if the TDC information was missing  C             xtofpos-value even if the TDC information was missing
26  C  jan-07 WM: flag for PMTs #10 and #35 added, TDC=819 due to bit-shift  C  jan-07 WM: flag for PMTs #10 and #35 added, TDC=819 due to bit-shift
27    C  jan-05 WM: bug fixed: calculation of zenith angles using DOTRACK2
28    C             was incorrect
29    C  jan-07 WM: bug fixed: in some cases tdc_tw was calculated due to a
30    C             leftover "xhelp" value
31    C  apr-07 WM: attenuation fit curve is now a double exponential fit
32    C             conversion from raw ADC to pC using calibration function
33    C             new variables xtr_tof(6) and ytr_tof(6) give track position
34    C             at ToF layers
35    C  aug-07 WM: artificial ADC creation revised: Now an ADC value is created
36    C             only if there is a TDC value (before ADC was created in ANY
37    C             case)
38    C  jan-08 WM: Major Update: Time Walk correction introduced
39    C             Additionally we use the information from the "check_charge"
40    C             function to fill artificial ADC values and make small corrections
41    C             to the k1-parameter (for Z>2)
42    C  feb-08 WM: Calculation of beta(13) changed: First a mean beta is calculated,
43    C             then in a second step we check the residuals of the single
44    C             measurements, reject if > 10 sigma, calculate chi2 and "quality"
45    C             beta is taken as good if chi2<20 and quality>10
46    C             The function "newbeta" is located in "tofl2com.for"
47    C  mar-08 WM: Call to "newbeta" changed, now a flag tells the function if the
48    C             call comes from "tofl2com" or form "toftrack"
49    C  mar-08 WM: Bug found in dEdx if check_charge>1
50    C  apr-08 WM: Bug found in S22 artificial ADC, mismatch found between the track
51    C             length  from DOTRACK2 and "GetLength" method for 4 combinations
52    C  oct-08 WM: New method to create artificial ADC values. Do NOT take the position
53    C             from the tracking, but the position from timing. This method gives a
54    C             better time resolution
55    C  nov-09 WM: the dEdx part ("adc_c") moved to the new dEdx routine from Napoli
56  C  C
57  C****************************************************************************  C****************************************************************************
58        IMPLICIT NONE        IMPLICIT NONE
59  C      C
60        include  'input_tof.txt'        include  'input_tof.txt'
61        include  'output_tof.txt'        include  'output_tof.txt'
62        include  'tofcomm.txt'        include  'tofcomm.txt'
63  C      C
64          
65  c     =======================================  c     =======================================
66  c     variables for tracking routine  c     variables for tracking routine
67  c     =======================================  c     =======================================
# Line 53  c     define TOF Z-coordinates Line 82  c     define TOF Z-coordinates
82    
83    
84        INTEGER IFAIL        INTEGER IFAIL
85  c      REAL dx,dy,dr,xdummy  c      REAL dx,dy,dr
86        REAL ds        REAL ds
87        REAL t1,t2,t3,t4        REAL t1,t2,t3,t4
88        REAL yhelp,xhelp,xhelp1,xhelp2        REAL yhelp,xhelp,xhelp1,xhelp2
89        REAL c1,c2,sw,sxw,w_i        REAL c1,c2
90        REAL dist,dl,F  C     REAL sw,sxw,w_i
91        INTEGER icount,ievent        REAL dist,dl,F
92        REAL xhelp_a,xhelp_t        INTEGER ievent
93    C      INTEGER icount
94        REAL beta_mean  C      REAL beta_mean
95          REAL btemp(12)
96        REAL hepratio        REAL hepratio
97          
98        INTEGER j        INTEGER j,hitvec(6)
99    
100          real atten,pc_adc,check_charge,newbeta
101    
102    
103        REAL theta,phi        REAL theta,phi
104  C--   DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006  C--   DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006
105        REAL tofarm12        REAL tofarm12
106        PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69        PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69
107        REAL tofarm23                REAL tofarm23
108        PARAMETER (tofarm23 = 47.61) ! from 23.69 to -23.92        PARAMETER (tofarm23 = 47.61) ! from 23.69 to -23.92
109        REAL tofarm13        REAL tofarm13
110        PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92        PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92
111    
112          
113    C--- new
114          REAL xtofpre(3),ytofpre(3)
115    
116          REAL y_coor_lin11c(8,2),x_coor_lin12c(6,2)
117          REAL x_coor_lin21c(2,2),y_coor_lin22c(2,2)
118          REAL y_coor_lin31c(3,2),x_coor_lin32c(3,2)
119    
120          DATA y_coor_lin11c(1,1),y_coor_lin11c(1,2) /-20.66,-2.497/
121          DATA y_coor_lin11c(2,1),y_coor_lin11c(2,2) /-9.10, -2.52/
122          DATA y_coor_lin11c(3,1),y_coor_lin11c(3,2) /-24.07,-2.12/
123          DATA y_coor_lin11c(4,1),y_coor_lin11c(4,2) /-13.40,-2.47/
124          DATA y_coor_lin11c(5,1),y_coor_lin11c(5,2) /-31.07,-2.32/
125          DATA y_coor_lin11c(6,1),y_coor_lin11c(6,2) /-21.69,-2.63/
126          DATA y_coor_lin11c(7,1),y_coor_lin11c(7,2) /-12.37,-2.65/
127          DATA y_coor_lin11c(8,1),y_coor_lin11c(8,2) /-10.81,-3.15/
128    
129          DATA x_coor_lin12c(1,1),x_coor_lin12c(1,2) /12.96, -2.65/
130          DATA x_coor_lin12c(2,1),x_coor_lin12c(2,2) /17.12,-2.44/
131          DATA x_coor_lin12c(3,1),x_coor_lin12c(3,2) /7.26, -1.98/
132          DATA x_coor_lin12c(4,1),x_coor_lin12c(4,2) /-22.52,-2.27/
133          DATA x_coor_lin12c(5,1),x_coor_lin12c(5,2) /-18.54,-2.28/
134          DATA x_coor_lin12c(6,1),x_coor_lin12c(6,2) /-7.67,-2.15/
135    
136          DATA x_coor_lin21c(1,1),x_coor_lin21c(1,2) /22.56,-1.56/
137          DATA x_coor_lin21c(2,1),x_coor_lin21c(2,2) /13.94,-1.56/
138    
139          DATA y_coor_lin22c(1,1),y_coor_lin22c(1,2) /-24.24,-2.23/
140          DATA y_coor_lin22c(2,1),y_coor_lin22c(2,2) /-45.99,-1.68/
141    
142          DATA y_coor_lin31c(1,1),y_coor_lin31c(1,2) /-22.99,-3.54/
143          DATA y_coor_lin31c(2,1),y_coor_lin31c(2,2) /-42.28,-4.10/
144          DATA y_coor_lin31c(3,1),y_coor_lin31c(3,2) /-41.29,-3.69/
145    
146          DATA x_coor_lin32c(1,1),x_coor_lin32c(1,2) /0.961, -3.22/
147          DATA x_coor_lin32c(2,1),x_coor_lin32c(2,2) /4.98,-3.48/
148          DATA x_coor_lin32c(3,1),x_coor_lin32c(3,2) /-22.08,-3.37/
149    
150    C---
151    
152        INTEGER ihelp        INTEGER ihelp
153        REAL xkorr,xpos        REAL xkorr,xpos
154    
155          INTEGER IZ
156          REAL k1corrA1,k1corrB1,k1corrC1
157    
158        REAL yl,yh,xl,xh        REAL yl,yh,xl,xh
159  C      C
160        REAL hmemor(9000000)        REAL hmemor(9000000)
161        INTEGER Iquest(100)        INTEGER Iquest(100)
162  C      C
163        DATA ievent / 0 /        DATA ievent / 0 /
164    
165          INTEGER ifst
166          DATA ifst /0/
167    
168        COMMON / pawcd / hmemor        COMMON / pawcd / hmemor
169        save / pawcd /        save / pawcd /
170  C      C
171        Common / QUESTd / Iquest        Common / QUESTd / Iquest
172        save / questd /        save / questd /
173  C      C
174  C     Begin !  C     Begin !
175  C      C
176        TOFTRK = 0        TOFTRK = 0
177    
178  *******************************************************************  *******************************************************************
179    
180        ievent = ievent +1         if (ifst.eq.0) then
181           ifst=1
182    
183  C  ratio helium to proton ca. 4  C  ratio helium to proton ca. 4
184        hepratio = 4.5        hepratio = 4.
185    
186        offset = 1        offset = 1
187        slope = 2        slope = 2
# Line 115  C  ratio helium to proton ca. 4 Line 194  C  ratio helium to proton ca. 4
194        itdc = 1        itdc = 1
195        iadc = 2        iadc = 2
196    
197    
198          k1corrA1 = 0.
199          k1corrB1 = -5.0
200          k1corrC1=  8.0
201    
202          ENDIF   ! ifst
203    
204    *******************************************************************
205    
206          ievent = ievent +1
207    
208        do i=1,13        do i=1,13
209           beta_a(i) = 100.           beta_a(i) = 100.
210        enddo        enddo
# Line 145  C  ratio helium to proton ca. 4 Line 235  C  ratio helium to proton ca. 4
235    
236        pmt_id=0        pmt_id=0
237    
238          do j=1,6
239          THXOUT(j) = 0.
240          THYOUT(j) = 0.
241          enddo
242    
243          do j=1,6
244          xtr_tof(j) = 100.
245          ytr_tof(j) = 100.
246          enddo
247    
248    
249  C----------------------------------------------------------------------  C----------------------------------------------------------------------
250  C-------------------------get ToF data --------------------------------  C-------------------------get ToF data --------------------------------
251  C     we cannot use the tofxx(x,x,x)  data  from tofl2com since it is  C     we cannot use the tofxx(x,x,x)  data  from tofl2com since it is
252  C     manipulated (Time-walk, artificila ADc and TDC values using ToF  C     manipulated (Time-walk, artificila ADc and TDC values using ToF
253  C     standalone information  C     standalone information
254  C----------------------------------------------------------------------  C----------------------------------------------------------------------
 C     put the adc and tdc values from ntuple into tofxx(i,j,k) variables  
255    
256    c     put the adc and tdc values from ntuple into tofxx(i,j,k) variables
257    
258        do j=1,8        do j=1,8
259           tof11(1,j,2) = adc(ch11a(j),hb11a(j))           tof11(1,j,2) = pc_adc(adc(ch11a(j),hb11a(j)))
260           tof11(2,j,2) = adc(ch11b(j),hb11b(j))           tof11(2,j,2) = pc_adc(adc(ch11b(j),hb11b(j)))
261           tof11(1,j,1) = tdc(ch11a(j),hb11a(j))           tof11(1,j,1) = (tdc(ch11a(j),hb11a(j)))
262           tof11(2,j,1) = tdc(ch11b(j),hb11b(j))           tof11(2,j,1) = (tdc(ch11b(j),hb11b(j)))
263        enddo        enddo
264    
265    
266        do j=1,6        do j=1,6
267           tof12(1,j,2) = adc(ch12a(j),hb12a(j))           tof12(1,j,2) = pc_adc(adc(ch12a(j),hb12a(j)))
268           tof12(2,j,2) = adc(ch12b(j),hb12b(j))           tof12(2,j,2) = pc_adc(adc(ch12b(j),hb12b(j)))
269           tof12(1,j,1) = tdc(ch12a(j),hb12a(j))           tof12(1,j,1) = (tdc(ch12a(j),hb12a(j)))
270           tof12(2,j,1) = tdc(ch12b(j),hb12b(j))           tof12(2,j,1) = (tdc(ch12b(j),hb12b(j)))
271        enddo        enddo
272    
273        do j=1,2        do j=1,2
274           tof21(1,j,2) = adc(ch21a(j),hb21a(j))           tof21(1,j,2) = pc_adc(adc(ch21a(j),hb21a(j)))
275           tof21(2,j,2) = adc(ch21b(j),hb21b(j))           tof21(2,j,2) = pc_adc(adc(ch21b(j),hb21b(j)))
276           tof21(1,j,1) = tdc(ch21a(j),hb21a(j))           tof21(1,j,1) = (tdc(ch21a(j),hb21a(j)))
277           tof21(2,j,1) = tdc(ch21b(j),hb21b(j))           tof21(2,j,1) = (tdc(ch21b(j),hb21b(j)))
278        enddo        enddo
279    
280        do j=1,2        do j=1,2
281           tof22(1,j,2) = adc(ch22a(j),hb22a(j))           tof22(1,j,2) = pc_adc(adc(ch22a(j),hb22a(j)))
282           tof22(2,j,2) = adc(ch22b(j),hb22b(j))           tof22(2,j,2) = pc_adc(adc(ch22b(j),hb22b(j)))
283           tof22(1,j,1) = tdc(ch22a(j),hb22a(j))           tof22(1,j,1) = (tdc(ch22a(j),hb22a(j)))
284           tof22(2,j,1) = tdc(ch22b(j),hb22b(j))           tof22(2,j,1) = (tdc(ch22b(j),hb22b(j)))
285        enddo        enddo
286    
287        do j=1,3        do j=1,3
288           tof31(1,j,2) = adc(ch31a(j),hb31a(j))           tof31(1,j,2) = pc_adc(adc(ch31a(j),hb31a(j)))
289           tof31(2,j,2) = adc(ch31b(j),hb31b(j))           tof31(2,j,2) = pc_adc(adc(ch31b(j),hb31b(j)))
290           tof31(1,j,1) = tdc(ch31a(j),hb31a(j))           tof31(1,j,1) = (tdc(ch31a(j),hb31a(j)))
291           tof31(2,j,1) = tdc(ch31b(j),hb31b(j))           tof31(2,j,1) = (tdc(ch31b(j),hb31b(j)))
292        enddo        enddo
293    
294        do j=1,3        do j=1,3
295           tof32(1,j,2) = adc(ch32a(j),hb32a(j))           tof32(1,j,2) = pc_adc(adc(ch32a(j),hb32a(j)))
296           tof32(2,j,2) = adc(ch32b(j),hb32b(j))           tof32(2,j,2) = pc_adc(adc(ch32b(j),hb32b(j)))
297           tof32(1,j,1) = tdc(ch32a(j),hb32a(j))           tof32(1,j,1) = (tdc(ch32a(j),hb32a(j)))
298           tof32(2,j,1) = tdc(ch32b(j),hb32b(j))           tof32(2,j,1) = (tdc(ch32b(j),hb32b(j)))
299        enddo        enddo
300    
301  C----------------------------------------------------------------------  C----------------------------------------------------------------------
# Line 242  C--------------------------------------- Line 343  C---------------------------------------
343           if (abs(tof32(2,i,iadc)).gt.10000.) tof32(2,i,iadc)= 10000.           if (abs(tof32(2,i,iadc)).gt.10000.) tof32(2,i,iadc)= 10000.
344        ENDDO        ENDDO
345    
346  C-------------------------------------------------------------------  C----------------------------------------------------------------------
347    
348  C------read  tracking routine  C------read  tracking routine
349  *     igoodevent = igoodevent+1  *     igoodevent = igoodevent+1
# Line 257  C     COPY THE ALFA VECTOR FROM AL_PP TO Line 358  C     COPY THE ALFA VECTOR FROM AL_PP TO
358           AL_P(i) = al_pp(i)           AL_P(i) = al_pp(i)
359        enddo        enddo
360    
361  c     write(*,*) AL_P  c      write(*,*) AL_P
362    c      write(*,*) 'Rigidity ',(1./AL_P(5))
363    
364        if (al_p(5).eq.0.) THEN        if (al_p(5).eq.0.) THEN
365           PRINT *,' TOF - WARNING F77: track with R = 0, discarded'  c         PRINT *,' TOF - WARNING F77: track with R = 0, discarded'
366           GOTO 969           GOTO 969
367        ENDIF        ENDIF
368  *     -------- *** tracking routine *** --------  *     -------- *** tracking routine *** --------
# Line 268  c     write(*,*) AL_P Line 370  c     write(*,*) AL_P
370  C     call DOTRACK(NPTOF,ZIN,XOUT,YOUT,AL_P,IFAIL)  C     call DOTRACK(NPTOF,ZIN,XOUT,YOUT,AL_P,IFAIL)
371        call DOTRACK2(NPTOF,ZIN,XOUT,YOUT,THXOUT,THYOUT,TLOUT,AL_P,IFAIL)        call DOTRACK2(NPTOF,ZIN,XOUT,YOUT,THXOUT,THYOUT,TLOUT,AL_P,IFAIL)
372    
   
373  C     write(*,*) (TLOUT(i),i=1,6)  C     write(*,*) (TLOUT(i),i=1,6)
374    
375        if(IFAIL.ne.0)then        if(IFAIL.ne.0)then
376           print *,' TOF - WARNING F77: tracking failed '  c         print *,' TOF - WARNING F77: tracking failed '
377           goto 969           goto 969
378        endif        endif
379  *     ------------------------------------------  *     ------------------------------------------
380    
381   969  continue   969  continue
382    
383    C---  Fill xtr_tof  and ytr_tof: positions from tracker at ToF layers
384          do j=1,6
385          xtr_tof(j) = XOUT(j)
386          ytr_tof(j) = YOUT(j)
387    c      write(*,*) XOUT(j),YOUT(j)
388          enddo
389    
390    
391    C---  convert  angles to radian
392          do j=1,6
393          THXOUT(j) = 3.1415927*THXOUT(j)/180.
394          THYOUT(j) = 3.1415927*THYOUT(j)/180.
395          enddo
396    
397          do j=1,6
398    c      write (*,*) j,THXOUT(j),THYOUT(j)
399          enddo
400    
401    
402  C----------------------------------------------------------------------  C----------------------------------------------------------------------
403  C------------------  set ADC & TDC flag = 0    ------------------------  C------------------  set ADC & TDC flag = 0    ------------------------
# Line 348  c     DATA tof21_y/  3.75,-3.75/  ! padd Line 467  c     DATA tof21_y/  3.75,-3.75/  ! padd
467  c     DATA tof22_x/ -4.5,4.5/  c     DATA tof22_x/ -4.5,4.5/
468  c     DATA tof31_x/ -6.0,0.,6.0/  c     DATA tof31_x/ -6.0,0.,6.0/
469  c     DATA tof32_y/ -5.0,0.0,5.0/  c     DATA tof32_y/ -5.0,0.0,5.0/
470  c      c
471  c     S11 8 paddles  33.0 x 5.1 cm  c     S11 8 paddles  33.0 x 5.1 cm
472  c     S12 6 paddles  40.8 x 5.5 cm  c     S12 6 paddles  40.8 x 5.5 cm
473  c     S21 2 paddles  18.0 x 7.5 cm  c     S21 2 paddles  18.0 x 7.5 cm
# Line 356  c     S22 2 paddles  15.0 x 9.0 cm Line 475  c     S22 2 paddles  15.0 x 9.0 cm
475  c     S31 3 paddles  15.0 x 6.0 cm  c     S31 3 paddles  15.0 x 6.0 cm
476  c     S32 3 paddles  18.0 x 5.0 cm  c     S32 3 paddles  18.0 x 5.0 cm
477    
 c     write(*,*) xout(1),xout(2),xout(3),xout(4),xout(5),xout(6)  
 c     write(*,*) yout(1),yout(2),yout(3),yout(4),yout(5),yout(6)  
478    
479  C--------------S11 --------------------------------------  C--------------S11 --------------------------------------
480    
# Line 379  C--------------S11 --------------------- Line 496  C--------------S11 ---------------------
496  C--------------S12 --------------------------------------  C--------------S12 --------------------------------------
497    
498        tof12_i = none_find        tof12_i = none_find
499          
500        xl = -40.8/2.        xl = -40.8/2.
501        xh =  40.8/2.        xh =  40.8/2.
502    
# Line 396  C--------------S12 --------------------- Line 513  C--------------S12 ---------------------
513  C--------------S21 --------------------------------------  C--------------S21 --------------------------------------
514    
515        tof21_i = none_find        tof21_i = none_find
516          
517        xl = -18./2.        xl = -18./2.
518        xh =  18./2.        xh =  18./2.
519    
# Line 413  C--------------S21 --------------------- Line 530  C--------------S21 ---------------------
530  C--------------S22 --------------------------------------  C--------------S22 --------------------------------------
531    
532        tof22_i = none_find        tof22_i = none_find
533          
534        yl = -15./2.        yl = -15./2.
535        yh =  15./2.        yh =  15./2.
536    
# Line 430  C--------------S22 --------------------- Line 547  C--------------S22 ---------------------
547  C--------------S31 --------------------------------------  C--------------S31 --------------------------------------
548    
549        tof31_i = none_find        tof31_i = none_find
550          
551        yl = -15.0/2.        yl = -15.0/2.
552        yh =  15.0/2.        yh =  15.0/2.
553    
# Line 447  C--------------S31 --------------------- Line 564  C--------------S31 ---------------------
564  C--------------S32 --------------------------------------  C--------------S32 --------------------------------------
565    
566        tof32_i = none_find        tof32_i = none_find
567          
568        xl = -18.0/2.        xl = -18.0/2.
569        xh =  18.0/2.        xh =  18.0/2.
570    
# Line 462  C--------------S32 --------------------- Line 579  C--------------S32 ---------------------
579        endif        endif
580    
581    
 C     write(*,*) tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i  
582    
583  C-----------------------------------------------------------------------         hitvec(1)=tof11_i
584  C--------------------Insert Artifical TDC Value  ---------------------         hitvec(2)=tof12_i
585  C     For each Paddle perform check:         hitvec(3)=tof21_i
586  C     if left paddle=4095  and right paddle OK => create TDC value left         hitvec(4)=tof22_i
587  C     if right paddle=4095  and left paddle OK => create TDC value right         hitvec(5)=tof31_i
588  C-----------------------------------------------------------------------         hitvec(6)=tof32_i
589    
 C-----------------------S11 -----------------------------------------  
590    
591        IF (tof11_i.GT.none_find) THEN  C----------------------------------------------------------------------
592           xpos = yout(1)  C--- check charge:
593           i = tof11_i  C--- if Z=2 we should use the attenuation curve for helium to
594           if ((tof11(1,tof11_i,itdc).EQ.4095).AND.  C--- fill the artificail ADC values and NOT divide by "hepratio"
595       &        (tof11(2,tof11_i,itdc).LT.4095)) THEN    C--- if Z>2 we should do a correction to
596    C--- the k1 constants in the beta calculation
597    C----------------------------------------------------------------------
598    
599  c       write(*,*)'11lb4 ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)         theta=0.  
600           dist = ZTOF(1) - ZTOF(5)
601           dl = 0.
602           DO I=1,5
603             dl = dl + TLOUT(i)
604           ENDDO
605           F = dl/dist
606           theta = acos(1/F)
607    
608           iz = int(check_charge(theta,hitvec))
609    c       write(*,*) 'in toftrk',iz
610    
             tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)  
      &           + 2*(y_coor_lin11(tof11_i,offset)  
      &           + xpos*y_coor_lin11(tof11_i,slope))  
611    
612  c       write(*,*)'11laf ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  C-------------------------------  new  ---------------------------
613    C--  calculate track position in paddle using timing difference
614    C--  this calculation is preliminary and uses some standard
615    C--  calibration values, but we need to find a rough position to
616    C--  be able to calculate artificial ADC values (needed for the
617    C--  timewalk...
618    C------------------------------------------------------------------
619    
620              tdcflag(ch11a(i),hb11a(i)) = 1         do i=1,3
621               xtofpre(i)=100.
622          ENDIF           ytofpre(i)=100.
623           if ((tof11(2,tof11_i,itdc).EQ.4095).AND.         enddo
      &        (tof11(1,tof11_i,itdc).LT.4095)) THEN    
624    
625  c       write(*,*)'11rb4 ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  C-----------------------------S1 --------------------------------
626    
627              tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)        IF (tof11_i.GT.none_find) THEN
628       &           - 2*(y_coor_lin11(tof11_i,offset)        IF ((tof11(1,tof11_i,itdc).LT.2000).AND.
629       &           + xpos*y_coor_lin11(tof11_i,slope))       +                             (tof11(2,tof11_i,itdc).LT.2000))
630  c       write(*,*)'11raf ',i,tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)       +    ytofpre(1)  = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
631         +   -y_coor_lin11c(tof11_i,offset))/y_coor_lin11c(tof11_i,slope)
632          endif
633    
634              tdcflag(ch11b(i),hb11b(i)) = 1        IF (tof12_i.GT.none_find) THEN
635           ENDIF            IF ((tof12(1,tof12_i,itdc).LT.2000).AND.
636        ENDIF       +                             (tof12(2,tof12_i,itdc).LT.2000))
637         +    xtofpre(1)  = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
638         +   -x_coor_lin12c(tof12_i,offset))/x_coor_lin12c(tof12_i,slope)
639          endif
640    
 C-----------------------S12 -----------------------------------------  
641    
642        IF (tof12_i.GT.none_find) THEN  C-----------------------------S2 --------------------------------
          xpos = xout(2)  
          i = tof12_i  
          if ((tof12(1,tof12_i,itdc).EQ.4095).AND.  
      &        (tof12(2,tof12_i,itdc).LT.4095)) THEN  
             tof12(1,tof12_i,itdc) = tof12(2,tof12_i,itdc)  
      &           + 2*(x_coor_lin12(tof12_i,offset)  
      &           + xpos*x_coor_lin12(tof12_i,slope))  
             tdcflag(ch12a(i),hb12a(i)) = 1  
          ENDIF  
          if ((tof12(2,tof12_i,itdc).EQ.4095).AND.  
      &        (tof12(1,tof12_i,itdc).LT.4095)) THEN  
             tof12(2,tof12_i,itdc) = tof12(1,tof12_i,itdc)  
      &           - 2*(x_coor_lin12(tof12_i,offset)  
      &           + xpos*x_coor_lin12(tof12_i,slope))  
             tdcflag(ch12b(i),hb12b(i)) = 1  
          ENDIF  
       ENDIF  
         
 C-----------------------S21 -----------------------------------------  
643    
644        IF (tof21_i.GT.none_find) THEN        IF (tof21_i.GT.none_find) THEN
645           xpos = xout(3)        IF ((tof21(1,tof21_i,itdc).LT.2000).AND.
646           i = tof21_i       +                             (tof21(2,tof21_i,itdc).LT.2000))
647           if ((tof21(1,tof21_i,itdc).EQ.4095).AND.       +    xtofpre(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
648       &        (tof21(2,tof21_i,itdc).LT.4095)) THEN       +    -x_coor_lin21c(tof21_i,offset))/x_coor_lin21c(tof21_i,slope)
649              tof21(1,tof21_i,itdc) = tof21(2,tof21_i,itdc)        endif
      &           + 2*(x_coor_lin21(tof21_i,offset)  
      &           + xpos*x_coor_lin21(tof21_i,slope))  
             tdcflag(ch21a(i),hb21a(i)) = 1  
          ENDIF  
          if ((tof21(2,tof21_i,itdc).EQ.4095).AND.  
      &        (tof21(1,tof21_i,itdc).LT.4095)) THEN  
             tof21(2,tof21_i,itdc) = tof21(1,tof21_i,itdc)  
      &           - 2*(x_coor_lin21(tof21_i,offset)  
      &           + xpos*x_coor_lin21(tof21_i,slope))  
             tdcflag(ch21b(i),hb21b(i)) = 1  
          ENDIF  
       ENDIF  
   
 C-----------------------S22 -----------------------------------------  
650    
651        IF (tof22_i.GT.none_find) THEN        IF (tof22_i.GT.none_find) THEN
652           xpos = yout(4)        IF ((tof22(1,tof22_i,itdc).LT.2000).AND.
653           i = tof22_i       +                             (tof22(2,tof22_i,itdc).LT.2000))
654           if ((tof22(1,tof22_i,itdc).EQ.4095).AND.       +    ytofpre(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
655       &        (tof22(2,tof22_i,itdc).LT.4095)) THEN       +    -y_coor_lin22c(tof22_i,offset))/y_coor_lin22c(tof22_i,slope)
656              tof22(1,tof22_i,itdc) = tof22(2,tof22_i,itdc)        endif
      &           + 2*(y_coor_lin22(tof22_i,offset)  
      &           + xpos*y_coor_lin22(tof22_i,slope))  
             tdcflag(ch22a(i),hb22a(i)) = 1  
          ENDIF  
          if ((tof22(2,tof22_i,itdc).EQ.4095).AND.  
      &        (tof22(1,tof22_i,itdc).LT.4095)) THEN  
             tof22(2,tof22_i,itdc) = tof22(1,tof22_i,itdc)  
      &           - 2*(y_coor_lin22(tof22_i,offset)  
      &           + xpos*y_coor_lin22(tof22_i,slope))  
             tdcflag(ch22b(i),hb22b(i)) = 1  
          ENDIF  
       ENDIF  
657    
 C-----------------------S31 -----------------------------------------  
         
       IF (tof31_i.GT.none_find) THEN  
          xpos = yout(5)  
          i = tof31_i  
          if ((tof31(1,tof31_i,itdc).EQ.4095).AND.  
      &        (tof31(2,tof31_i,itdc).LT.4095)) THEN  
             tof31(1,tof31_i,itdc) = tof31(2,tof31_i,itdc)  
      &           + 2*(y_coor_lin31(tof31_i,offset)  
      &           + xpos*y_coor_lin31(tof31_i,slope))  
             tdcflag(ch31a(i),hb31a(i)) = 1  
          ENDIF  
          if ((tof31(2,tof31_i,itdc).EQ.4095).AND.  
      &        (tof31(1,tof31_i,itdc).LT.4095)) THEN  
             tof31(2,tof31_i,itdc) = tof31(1,tof31_i,itdc)  
      &           - 2*(y_coor_lin31(tof31_i,offset)  
      &           + xpos*y_coor_lin31(tof31_i,slope))  
             tdcflag(ch31b(i),hb31b(i)) = 1  
          ENDIF  
       ENDIF  
658    
659  C-----------------------S32 -----------------------------------------  C-----------------------------S3 --------------------------------
660    
661          IF (tof31_i.GT.none_find) THEN
662          IF ((tof31(1,tof31_i,itdc).LT.2000).AND.
663         +                             (tof31(2,tof31_i,itdc).LT.2000))
664         +    ytofpre(3)  = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
665         +    -y_coor_lin31c(tof31_i,offset))/y_coor_lin31c(tof31_i,slope)
666          endif
667    
668        IF (tof32_i.GT.none_find) THEN        IF (tof32_i.GT.none_find) THEN
669           xpos = xout(6)        IF ((tof32(1,tof32_i,itdc).LT.2000).AND.
670           i = tof32_i       +                             (tof32(2,tof32_i,itdc).LT.2000))
671           if ((tof32(1,tof32_i,itdc).EQ.4095).AND.       +    xtofpre(3)  = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
672       &        (tof32(2,tof32_i,itdc).LT.4095)) THEN       +    -x_coor_lin32c(tof32_i,offset))/x_coor_lin32c(tof32_i,slope)
673              tof32(1,tof32_i,itdc) = tof32(2,tof32_i,itdc)        endif
674       &           + 2*(x_coor_lin32(tof32_i,offset)  
675       &           + xpos*x_coor_lin32(tof32_i,slope))  
676              tdcflag(ch32a(i),hb32a(i)) = 1  C--  restrict TDC measurements to physical paddle dimensions +/- 10 cm
677           ENDIF  
678           if ((tof32(2,tof32_i,itdc).EQ.4095).AND.          if (abs(xtofpre(1)).gt.31.)  xtofpre(1)=100.
679       &        (tof32(1,tof32_i,itdc).LT.4095)) THEN          if (abs(xtofpre(2)).gt.19.)  xtofpre(2)=100.
680              tof32(2,tof32_i,itdc) = tof32(1,tof32_i,itdc)          if (abs(xtofpre(3)).gt.19.)  xtofpre(3)=100.
681       &           - 2*(x_coor_lin32(tof32_i,offset)  
682       &           + xpos*x_coor_lin32(tof32_i,slope))          if (abs(ytofpre(1)).gt.26.)  ytofpre(1)=100.
683              tdcflag(ch32b(i),hb32b(i)) = 1          if (abs(ytofpre(2)).gt.18.)  ytofpre(2)=100.
684           ENDIF          if (abs(ytofpre(3)).gt.18.)  ytofpre(3)=100.
       ENDIF  
685    
686  C--------------------------------------------------------------------  C--------------------------------------------------------------------
687  C---- if TDCleft.and.TDCright and NO ADC insert artificial ADC  C---- if paddle hit: if we have TDC value but no ADC, create ADC value
688  C---- values  C---- use the "pre" position if possible, since this gives better time
689    C---- resolution ... october 2008
690  C--------------------------------------------------------------------  C--------------------------------------------------------------------
691  c     middle y (or x) position of the upper and middle ToF-Paddle  c     middle y (or x) position of the upper and middle ToF-Paddle
692  c     DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/  c     DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/
# Line 623  c     DATA tof32_y/ -5.0,0.0,5.0/ Line 698  c     DATA tof32_y/ -5.0,0.0,5.0/
698    
699  C----------------------------S1 -------------------------------------  C----------------------------S1 -------------------------------------
700    
701        yhelp=yout(1)  c     yhelp=yout(1)
702        IF (tof11_i.GT.none_find.AND.abs(yout(1)).lt.100) THEN        yhelp = ytofpre(1)
703          if (yhelp.eq.100) yhelp=yout(1)
704    
705          IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
706           i = tof11_i           i = tof11_i
707           if (tof11(left,i,iadc).eq.4095) then           if ((tdc(ch11a(i),hb11a(i)).lt.4095).AND.
708              phi   = atan(tan(THXOUT(1))/tan(THYOUT(1)))       &       (adc(ch11a(i),hb11a(i)).eq.4095)) then
709  c            theta = atan(tan(THXOUT(1))/cos(phi)              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))
710              theta = atan(tan(THXOUT(1))/cos(phi))              theta = atan(tan(THXOUT(1))/cos(phi))
711              xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))              xkorr = atten(left,11,i,yhelp)
712              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
713              tof11(left,i,iadc)=xkorr/cos(theta)              tof11(left,i,iadc)=xkorr/cos(theta)
714              adcflag(ch11a(i),hb11a(i)) = 1              adcflag(ch11a(i),hb11a(i)) = 1
715           endif           endif
716           if (tof11(right,i,iadc).eq.4095) then           if ((tdc(ch11b(i),hb11b(i)).lt.4095).AND.
717              phi   = atan(tan(THXOUT(1))/tan(THYOUT(1)))       &       (adc(ch11b(i),hb11b(i)).eq.4095)) then
718  c            theta = atan(tan(THXOUT(1))/cos(phi)              phi   = atan(tan(THYOUT(1))/tan(THXOUT(1)))
719              theta = atan(tan(THXOUT(1))/cos(phi))              theta = atan(tan(THXOUT(1))/cos(phi))
720              xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))              xkorr = atten(right,11,i,yhelp)
721              xkorr=xkorr/hepratio                          if (iz.le.1) xkorr=xkorr/hepratio
722              tof11(right,i,iadc)=xkorr/cos(theta)              tof11(right,i,iadc)=xkorr/cos(theta)
723              adcflag(ch11b(i),hb11b(i)) = 1              adcflag(ch11b(i),hb11b(i)) = 1
724           endif           endif
725        ENDIF        ENDIF
726    
727        xhelp=xout(2)  c      xhelp=xout(2)
728        IF (tof12_i.GT.none_find.AND.abs(xout(2)).lt.100) THEN        xhelp = xtofpre(1)
729          if (xhelp.eq.100) xhelp=xout(2)
730    
731          IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
732           i = tof12_i           i = tof12_i
733           if (tof12(left,i,iadc).eq.4095) then           if ((tdc(ch12a(i),hb12a(i)).lt.4095).AND.
734              phi   = atan(tan(THXOUT(2))/tan(THYOUT(2)))       &       (adc(ch12a(i),hb12a(i)).eq.4095)) then
735  c            theta = atan(tan(THXOUT(2))/cos(phi)              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
736              theta = atan(tan(THXOUT(2))/cos(phi))              theta = atan(tan(THXOUT(2))/cos(phi))
737              xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))  c            xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))
738              xkorr=xkorr/hepratio                          xkorr = atten(left,12,i,xhelp)
739                if (iz.le.1) xkorr=xkorr/hepratio
740              tof12(left,i,iadc) = xkorr/cos(theta)              tof12(left,i,iadc) = xkorr/cos(theta)
741              adcflag(ch12a(i),hb12a(i)) = 1              adcflag(ch12a(i),hb12a(i)) = 1
742           endif           endif
743           if (tof12(right,i,iadc).eq.4095) then           if ((tdc(ch12b(i),hb12b(i)).lt.4095).AND.
744              phi   = atan(tan(THXOUT(2))/tan(THYOUT(2)))       &       (adc(ch12b(i),hb12b(i)).eq.4095)) then
745  c            theta = atan(tan(THXOUT(2))/cos(phi)              phi   = atan(tan(THYOUT(2))/tan(THXOUT(2)))
746              theta = atan(tan(THXOUT(2))/cos(phi))              theta = atan(tan(THXOUT(2))/cos(phi))
747              xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))  c            xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))
748              xkorr=xkorr/hepratio                          xkorr = atten(right,12,i,xhelp)
749                if (iz.le.1) xkorr=xkorr/hepratio
750              tof12(right,i,iadc) = xkorr/cos(theta)              tof12(right,i,iadc) = xkorr/cos(theta)
751              adcflag(ch12b(i),hb12b(i)) = 1              adcflag(ch12b(i),hb12b(i)) = 1
752           endif           endif
# Line 671  c            theta = atan(tan(THXOUT(2)) Line 754  c            theta = atan(tan(THXOUT(2))
754    
755  C-----------------------------S2 --------------------------------  C-----------------------------S2 --------------------------------
756    
757        xhelp=xout(3)  c      xhelp=xout(3)
758        IF (tof21_i.GT.none_find.AND.abs(xout(3)).lt.100) THEN        xhelp = xtofpre(2)
759          if (xhelp.eq.100) xhelp=xout(3)
760    
761          IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
762           i = tof21_i           i = tof21_i
763           if (tof21(left,i,iadc).eq.4095) then           if ((tdc(ch21a(i),hb21a(i)).lt.4095).AND.
764              phi   = atan(tan(THXOUT(3))/tan(THYOUT(3)))       &       (adc(ch21a(i),hb21a(i)).eq.4095)) then
765  c            theta = atan(tan(THXOUT(3))/cos(phi)              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
766              theta = atan(tan(THXOUT(3))/cos(phi))              theta = atan(tan(THXOUT(3))/cos(phi))
767              xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))  c            xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))
768              xkorr=xkorr/hepratio                          xkorr = atten(left,21,i,xhelp)
769                if (iz.le.1) xkorr=xkorr/hepratio
770              tof21(left,i,iadc) = xkorr/cos(theta)              tof21(left,i,iadc) = xkorr/cos(theta)
771              adcflag(ch21a(i),hb21a(i)) = 1              adcflag(ch21a(i),hb21a(i)) = 1
772           endif           endif
773           if (tof21(right,i,iadc).eq.4095) then           if ((tdc(ch21b(i),hb21b(i)).lt.4095).AND.
774              phi   = atan(tan(THXOUT(3))/tan(THYOUT(3)))       &       (adc(ch21b(i),hb21b(i)).eq.4095)) then
775  c            theta = atan(tan(THXOUT(3))/cos(phi)              phi   = atan(tan(THYOUT(3))/tan(THXOUT(3)))
776              theta = atan(tan(THXOUT(3))/cos(phi))              theta = atan(tan(THXOUT(3))/cos(phi))
777              xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))  c            xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))
778              xkorr=xkorr/hepratio                          xkorr = atten(right,21,i,xhelp)
779                if (iz.le.1) xkorr=xkorr/hepratio
780              tof21(right,i,iadc) = xkorr/cos(theta)              tof21(right,i,iadc) = xkorr/cos(theta)
781              adcflag(ch21b(i),hb21b(i)) = 1              adcflag(ch21b(i),hb21b(i)) = 1
782           endif           endif
783        ENDIF        ENDIF
784    
785    
786        yhelp=yout(4)  c      yhelp=yout(4)
787        IF (tof22_i.GT.none_find.AND.abs(yout(4)).lt.100) THEN        yhelp = ytofpre(2)
788          if (yhelp.eq.100) yhelp=yout(4)
789    
790          IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
791           i = tof22_i           i = tof22_i
792           if (tof22(left,i,iadc).eq.4095) then           if ((tdc(ch22a(i),hb22a(i)).lt.4095).AND.
793              phi   = atan(tan(THXOUT(4))/tan(THYOUT(4)))       &       (adc(ch22a(i),hb22a(i)).eq.4095)) then
794  c            theta = atan(tan(THXOUT(4))/cos(phi)              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
795              theta = atan(tan(THXOUT(4))/cos(phi))              theta = atan(tan(THXOUT(4))/cos(phi))
796              xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))  c            xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))
797              xkorr=xkorr/hepratio                          xkorr = atten(left,22,i,yhelp)
798                if (iz.le.1) xkorr=xkorr/hepratio
799              tof22(left,i,iadc) = xkorr/cos(theta)              tof22(left,i,iadc) = xkorr/cos(theta)
800              adcflag(ch22a(i),hb22a(i)) = 1              adcflag(ch22a(i),hb22a(i)) = 1
801           endif           endif
802           if (tof22(right,i,iadc).eq.4095) then           if ((tdc(ch22b(i),hb22b(i)).lt.4095).AND.
803              phi   = atan(tan(THXOUT(4))/tan(THYOUT(4)))       &       (adc(ch22b(i),hb22b(i)).eq.4095)) then
804  c            theta = atan(tan(THXOUT(4))/cos(phi)              phi   = atan(tan(THYOUT(4))/tan(THXOUT(4)))
805              theta = atan(tan(THXOUT(4))/cos(phi))              theta = atan(tan(THXOUT(4))/cos(phi))
806              xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))  c            xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))
807              xkorr=xkorr/hepratio                          xkorr = atten(right,22,i,yhelp)
808                if (iz.le.1) xkorr=xkorr/hepratio
809              tof22(right,i,iadc) = xkorr/cos(theta)              tof22(right,i,iadc) = xkorr/cos(theta)
810              adcflag(ch22b(i),hb22b(i)) = 1              adcflag(ch22b(i),hb22b(i)) = 1
811           endif           endif
# Line 720  c            theta = atan(tan(THXOUT(4)) Line 813  c            theta = atan(tan(THXOUT(4))
813    
814  C-----------------------------S3 --------------------------------  C-----------------------------S3 --------------------------------
815    
816        yhelp=yout(5)  c      yhelp=yout(5)
817        IF (tof31_i.GT.none_find.AND.abs(yout(5)).lt.100) THEN        yhelp = ytofpre(3)
818          if (yhelp.eq.100) yhelp=yout(5)
819    
820          IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
821           i = tof31_i           i = tof31_i
822           if (tof31(left,i,iadc).eq.4095) then           if ((tdc(ch31a(i),hb31a(i)).lt.4095).AND.
823              phi   = atan(tan(THXOUT(5))/tan(THYOUT(5)))       &       (adc(ch31a(i),hb31a(i)).eq.4095)) then
824  c            theta = atan(tan(THXOUT(5))/cos(phi)              phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
825              theta = atan(tan(THXOUT(5))/cos(phi))              theta = atan(tan(THXOUT(5))/cos(phi))
826              xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))  c            xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))
827              xkorr=xkorr/hepratio                          xkorr = atten(left,31,i,yhelp)
828                if (iz.le.1) xkorr=xkorr/hepratio
829              tof31(left,i,iadc) = xkorr/cos(theta)              tof31(left,i,iadc) = xkorr/cos(theta)
830              adcflag(ch31a(i),hb31a(i)) = 1              adcflag(ch31a(i),hb31a(i)) = 1
831           endif           endif
832           if (tof31(right,i,iadc).eq.4095) then           if ((tdc(ch31b(i),hb31b(i)).lt.4095).AND.
833              phi   = atan(tan(THXOUT(5))/tan(THYOUT(5)))       &       (adc(ch31b(i),hb31b(i)).eq.4095)) then
834  c            theta = atan(tan(THXOUT(5))/cos(phi)                phi   = atan(tan(THYOUT(5))/tan(THXOUT(5)))
835              theta = atan(tan(THXOUT(5))/cos(phi))              theta = atan(tan(THXOUT(5))/cos(phi))
836              xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))  c            xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))
837              xkorr=xkorr/hepratio                          xkorr = atten(right,31,i,yhelp)
838                if (iz.le.1) xkorr=xkorr/hepratio
839              tof31(right,i,iadc) = xkorr/cos(theta)              tof31(right,i,iadc) = xkorr/cos(theta)
840              adcflag(ch31b(i),hb31b(i)) = 1              adcflag(ch31b(i),hb31b(i)) = 1
841           endif           endif
842        ENDIF        ENDIF
843    
844    
845        xhelp=xout(6)  c      xhelp=xout(6)
846          xhelp = xtofpre(3)
847          if (xhelp.eq.100) xhelp=xout(6)
848    
849        IF (tof32_i.GT.none_find.AND.abs(xout(6)).lt.100) THEN        IF (tof32_i.GT.none_find.AND.abs(xout(6)).lt.100) THEN
850           i = tof32_i           i = tof32_i
851           if (tof32(left,i,iadc).eq.4095) then           if ((tdc(ch32a(i),hb32a(i)).lt.4095).AND.
852              phi   = atan(tan(THXOUT(6))/tan(THYOUT(6)))       &       (adc(ch32a(i),hb32a(i)).eq.4095)) then
853  c            theta = atan(tan(THXOUT(6))/cos(phi)              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
854              theta = atan(tan(THXOUT(6))/cos(phi))              theta = atan(tan(THXOUT(6))/cos(phi))
855              xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))  c            xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))
856              xkorr=xkorr/hepratio                          xkorr = atten(left,32,i,xhelp)
857                if (iz.le.1) xkorr=xkorr/hepratio
858              tof32(left,i,iadc) = xkorr/cos(theta)              tof32(left,i,iadc) = xkorr/cos(theta)
859              adcflag(ch32a(i),hb32a(i)) = 1              adcflag(ch32a(i),hb32a(i)) = 1
860           endif           endif
861           if (tof32(right,i,iadc).eq.4095) then           if ((tdc(ch32b(i),hb32b(i)).lt.4095).AND.
862              phi   = atan(tan(THXOUT(6))/tan(THYOUT(6)))       &       (adc(ch32b(i),hb32b(i)).eq.4095)) then
863  c            theta = atan(tan(THXOUT(6))/cos(phi)              phi   = atan(tan(THYOUT(6))/tan(THXOUT(6)))
864              theta = atan(tan(THXOUT(6))/cos(phi))              theta = atan(tan(THXOUT(6))/cos(phi))
865              xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))  c            xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))
866              xkorr=xkorr/hepratio                          xkorr = atten(right,32,i,xhelp)
867                if (iz.le.1) xkorr=xkorr/hepratio
868              tof32(right,i,iadc) = xkorr/cos(theta)              tof32(right,i,iadc) = xkorr/cos(theta)
869              adcflag(ch32b(i),hb32b(i)) = 1              adcflag(ch32b(i),hb32b(i)) = 1
870           endif           endif
871        ENDIF        ENDIF
872    
873    C-------------------------------------------------------------------
874    C Now there is for each hitted paddle a TDC and ADC value, if the
875    C TDC was < 4095.
876    C There might be also TDC-ADC pairs in paddles not hitted
877    C Let's correct the raw TDC value with the time walk
878    C-------------------------------------------------------------------
879    C--------------------Time walk correction  -------------------------
880    C-------------------------------------------------------------------
881    
882          DO i=1,8
883             if ((tdc(ch11a(i),hb11a(i)).lt.4095).and.
884         &             (tof11(left,i,iadc).lt.3786)) THEN
885             xhelp = tw11(left,i)/(tof11(left,i,iadc)**0.5)
886             tof11(left,i,itdc) = tof11(left,i,itdc) + xhelp
887             tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)
888                                                  ENDIF
889    
890             if ((tdc(ch11b(i),hb11b(i)).lt.4095).and.
891         &             (tof11(right,i,iadc).lt.3786)) THEN
892             xhelp = tw11(right,i)/(tof11(right,i,iadc)**0.5)
893             tof11(right,i,itdc) = tof11(right,i,itdc) + xhelp
894             tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)
895                                                 ENDIF
896          ENDDO
897    
898    
899          DO i=1,6
900             if ((tdc(ch12a(i),hb12a(i)).lt.4095).and.
901         &             (tof12(left,i,iadc).lt.3786)) THEN
902             xhelp = tw12(left,i)/(tof12(left,i,iadc)**0.5)
903             tof12(left,i,itdc) = tof12(left,i,itdc) + xhelp
904             tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)
905                                                  ENDIF
906    
907             if ((tdc(ch12b(i),hb12b(i)).lt.4095).and.
908         &             (tof12(right,i,iadc).lt.3786)) THEN
909             xhelp = tw12(right,i)/(tof12(right,i,iadc)**0.5)
910             tof12(right,i,itdc) = tof12(right,i,itdc) + xhelp
911             tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)
912                                                 ENDIF
913          ENDDO
914    
915    C----
916          DO I=1,2
917             if ((tdc(ch21a(i),hb21a(i)).lt.4095).and.
918         &             (tof21(left,i,iadc).lt.3786)) THEN
919             xhelp = tw21(left,i)/(tof21(left,i,iadc)**0.5)
920             tof21(left,i,itdc) = tof21(left,i,itdc) + xhelp
921             tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)
922                                                  ENDIF
923    
924             if ((tdc(ch21b(i),hb21b(i)).lt.4095).and.
925         &             (tof21(right,i,iadc).lt.3786)) THEN
926             xhelp = tw21(right,i)/(tof21(right,i,iadc)**0.5)
927             tof21(right,i,itdc) = tof21(right,i,itdc) + xhelp
928             tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)
929                                                 ENDIF
930          ENDDO
931    
932          DO I=1,2
933             if ((tdc(ch22a(i),hb22a(i)).lt.4095).and.
934         &             (tof22(left,i,iadc).lt.3786)) THEN
935             xhelp = tw22(left,i)/(tof22(left,i,iadc)**0.5)
936             tof22(left,i,itdc) = tof22(left,i,itdc) + xhelp
937             tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)
938                                                  ENDIF
939    
940             if ((tdc(ch22b(i),hb22b(i)).lt.4095).and.
941         &             (tof22(right,i,iadc).lt.3786)) THEN
942             xhelp = tw22(right,i)/(tof22(right,i,iadc)**0.5)
943             tof22(right,i,itdc) = tof22(right,i,itdc) + xhelp
944             tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)
945                                                 ENDIF
946          ENDDO
947    
948    C----
949          DO I=1,3
950             if ((tdc(ch31a(i),hb31a(i)).lt.4095).and.
951         &             (tof31(left,i,iadc).lt.3786)) THEN
952             xhelp = tw31(left,i)/(tof31(left,i,iadc)**0.5)
953             tof31(left,i,itdc) = tof31(left,i,itdc) + xhelp
954             tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)
955                                                  ENDIF
956    
957             if ((tdc(ch31b(i),hb31b(i)).lt.4095).and.
958         &             (tof31(right,i,iadc).lt.3786)) THEN
959             xhelp = tw31(right,i)/(tof31(right,i,iadc)**0.5)
960             tof31(right,i,itdc) = tof31(right,i,itdc) + xhelp
961             tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)
962                                                 ENDIF
963          ENDDO
964    
965          DO I=1,3
966             if ((tdc(ch32a(i),hb32a(i)).lt.4095).and.
967         &             (tof32(left,i,iadc).lt.3786)) THEN
968             xhelp = tw32(left,i)/(tof32(left,i,iadc)**0.5)
969             tof32(left,i,itdc) = tof32(left,i,itdc) + xhelp
970             tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)
971                                                  ENDIF
972    
973             if ((tdc(ch32b(i),hb32b(i)).lt.4095).and.
974         &             (tof32(right,i,iadc).lt.3786)) THEN
975             xhelp = tw32(right,i)/(tof32(right,i,iadc)**0.5)
976             tof32(right,i,itdc) = tof32(right,i,itdc) + xhelp
977             tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)
978                                                 ENDIF
979          ENDDO
980    
981    
982    C-----------------------------------------------------------------------
983    C--------------------Insert Artifical TDC Value  ---------------------
984    C     For each Paddle perform check:
985    C     if left paddle=4095  and right paddle OK => create TDC value left
986    C     if right paddle=4095  and left paddle OK => create TDC value right
987    C-----------------------------------------------------------------------
988    
989    C-----------------------S11 -----------------------------------------
990    
991          IF (tof11_i.GT.none_find) THEN
992             xpos = yout(1)
993             i = tof11_i
994            if ((tdc(ch11a(i),hb11a(i)).EQ.4095).AND.
995         &          (tdc(ch11b(i),hb11b(i)).LT.4095)) THEN
996              tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)
997         &           + 2*(y_coor_lin11(tof11_i,offset)
998         &           + xpos*y_coor_lin11(tof11_i,slope))
999                tdcflag(ch11a(i),hb11a(i)) = 1
1000            ENDIF
1001    
1002            if ((tdc(ch11b(i),hb11b(i)).EQ.4095).AND.
1003         &          (tdc(ch11a(i),hb11a(i)).LT.4095)) THEN
1004                tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)
1005         &           - 2*(y_coor_lin11(tof11_i,offset)
1006         &           + xpos*y_coor_lin11(tof11_i,slope))
1007                tdcflag(ch11b(i),hb11b(i)) = 1
1008             ENDIF
1009    
1010          ENDIF
1011    
1012    C-----------------------S12 -----------------------------------------
1013    
1014          IF (tof12_i.GT.none_find) THEN
1015             xpos = xout(2)
1016             i = tof12_i
1017            if ((tdc(ch12a(i),hb12a(i)).EQ.4095).AND.
1018         &          (tdc(ch12b(i),hb12b(i)).LT.4095)) THEN
1019                tof12(1,tof12_i,itdc) = tof12(2,tof12_i,itdc)
1020         &           + 2*(x_coor_lin12(tof12_i,offset)
1021         &           + xpos*x_coor_lin12(tof12_i,slope))
1022                tdcflag(ch12a(i),hb12a(i)) = 1
1023             ENDIF
1024    
1025            if ((tdc(ch12b(i),hb12b(i)).EQ.4095).AND.
1026         &          (tdc(ch12a(i),hb12a(i)).LT.4095)) THEN
1027                tof12(2,tof12_i,itdc) = tof12(1,tof12_i,itdc)
1028         &           - 2*(x_coor_lin12(tof12_i,offset)
1029         &           + xpos*x_coor_lin12(tof12_i,slope))
1030                tdcflag(ch12b(i),hb12b(i)) = 1
1031             ENDIF
1032          ENDIF
1033    
1034    C-----------------------S21 -----------------------------------------
1035    
1036          IF (tof21_i.GT.none_find) THEN
1037             xpos = xout(3)
1038             i = tof21_i
1039            if ((tdc(ch21a(i),hb21a(i)).EQ.4095).AND.
1040         &          (tdc(ch21b(i),hb21b(i)).LT.4095)) THEN
1041                tof21(1,tof21_i,itdc) = tof21(2,tof21_i,itdc)
1042         &           + 2*(x_coor_lin21(tof21_i,offset)
1043         &           + xpos*x_coor_lin21(tof21_i,slope))
1044                tdcflag(ch21a(i),hb21a(i)) = 1
1045             ENDIF
1046    
1047            if ((tdc(ch21b(i),hb21b(i)).EQ.4095).AND.
1048         &          (tdc(ch21a(i),hb21a(i)).LT.4095)) THEN
1049                tof21(2,tof21_i,itdc) = tof21(1,tof21_i,itdc)
1050         &           - 2*(x_coor_lin21(tof21_i,offset)
1051         &           + xpos*x_coor_lin21(tof21_i,slope))
1052                tdcflag(ch21b(i),hb21b(i)) = 1
1053             ENDIF
1054          ENDIF
1055    
1056    C-----------------------S22 -----------------------------------------
1057    
1058          IF (tof22_i.GT.none_find) THEN
1059             xpos = yout(4)
1060             i = tof22_i
1061            if ((tdc(ch22a(i),hb22a(i)).EQ.4095).AND.
1062         &          (tdc(ch22b(i),hb22b(i)).LT.4095)) THEN
1063                tof22(1,tof22_i,itdc) = tof22(2,tof22_i,itdc)
1064         &           + 2*(y_coor_lin22(tof22_i,offset)
1065         &           + xpos*y_coor_lin22(tof22_i,slope))
1066                tdcflag(ch22a(i),hb22a(i)) = 1
1067             ENDIF
1068    
1069            if ((tdc(ch22b(i),hb22b(i)).EQ.4095).AND.
1070         &          (tdc(ch22a(i),hb22a(i)).LT.4095)) THEN
1071                tof22(2,tof22_i,itdc) = tof22(1,tof22_i,itdc)
1072         &           - 2*(y_coor_lin22(tof22_i,offset)
1073         &           + xpos*y_coor_lin22(tof22_i,slope))
1074                tdcflag(ch22b(i),hb22b(i)) = 1
1075             ENDIF
1076          ENDIF
1077    
1078    C-----------------------S31 -----------------------------------------
1079    
1080          IF (tof31_i.GT.none_find) THEN
1081             xpos = yout(5)
1082             i = tof31_i
1083            if ((tdc(ch31a(i),hb31a(i)).EQ.4095).AND.
1084         &          (tdc(ch31b(i),hb31b(i)).LT.4095)) THEN
1085                tof31(1,tof31_i,itdc) = tof31(2,tof31_i,itdc)
1086         &           + 2*(y_coor_lin31(tof31_i,offset)
1087         &           + xpos*y_coor_lin31(tof31_i,slope))
1088                tdcflag(ch31a(i),hb31a(i)) = 1
1089             ENDIF
1090    
1091            if ((tdc(ch31b(i),hb31b(i)).EQ.4095).AND.
1092         &          (tdc(ch31a(i),hb31a(i)).LT.4095)) THEN
1093                tof31(2,tof31_i,itdc) = tof31(1,tof31_i,itdc)
1094         &           - 2*(y_coor_lin31(tof31_i,offset)
1095         &           + xpos*y_coor_lin31(tof31_i,slope))
1096                tdcflag(ch31b(i),hb31b(i)) = 1
1097             ENDIF
1098          ENDIF
1099    
1100    C-----------------------S32 -----------------------------------------
1101    
1102          IF (tof32_i.GT.none_find) THEN
1103             xpos = xout(6)
1104             i = tof32_i
1105            if ((tdc(ch32a(i),hb32a(i)).EQ.4095).AND.
1106         &          (tdc(ch32b(i),hb32b(i)).LT.4095)) THEN
1107                tof32(1,tof32_i,itdc) = tof32(2,tof32_i,itdc)
1108         &           + 2*(x_coor_lin32(tof32_i,offset)
1109         &           + xpos*x_coor_lin32(tof32_i,slope))
1110                tdcflag(ch32a(i),hb32a(i)) = 1
1111             ENDIF
1112    
1113            if ((tdc(ch32b(i),hb32b(i)).EQ.4095).AND.
1114         &          (tdc(ch32a(i),hb32a(i)).LT.4095)) THEN
1115                tof32(2,tof32_i,itdc) = tof32(1,tof32_i,itdc)
1116         &           - 2*(x_coor_lin32(tof32_i,offset)
1117         &           + xpos*x_coor_lin32(tof32_i,slope))
1118                tdcflag(ch32b(i),hb32b(i)) = 1
1119             ENDIF
1120          ENDIF
1121    
1122    
1123  C------------------------------------------------------------------  C------------------------------------------------------------------
1124  C---  calculate track position in paddle using timing difference  C---  calculate track position in paddle using timing difference
# Line 775  C--------------------------------------- Line 1127  C---------------------------------------
1127        do i=1,3        do i=1,3
1128           xtofpos(i)=100.           xtofpos(i)=100.
1129           ytofpos(i)=100.           ytofpos(i)=100.
1130        enddo        enddo
1131    
1132  C-----------------------------S1 --------------------------------  C-----------------------------S1 --------------------------------
1133          
1134        IF (tof11_i.GT.none_find) THEN        IF (tof11_i.GT.none_find) THEN
1135           IF ((tof11(1,tof11_i,itdc).NE.4095).AND.           IF ((tof11(1,tof11_i,itdc).NE.4095).AND.
1136       &       (tof11(2,tof11_i,itdc).NE.4095)) THEN       &       (tof11(2,tof11_i,itdc).NE.4095)) THEN
1137           ytofpos(1)  = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.           ytofpos(1)  = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
1138       +        -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)       +        -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)
1139          if (abs(ytofpos(1)).gt.26.)  ytofpos(1)=101.          if (abs(ytofpos(1)).gt.26.)  ytofpos(1)=101.
1140          i=tof11_i
1141        endif        endif
1142        endif        endif
1143    
# Line 793  C-----------------------------S1 ------- Line 1147  C-----------------------------S1 -------
1147           xtofpos(1)  = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.           xtofpos(1)  = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
1148       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)
1149          if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.          if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.
1150          i=tof12_i
1151        endif        endif
1152        endif              endif
1153          
1154  C-----------------------------S2 --------------------------------  C-----------------------------S2 --------------------------------
1155          
1156        IF (tof21_i.GT.none_find) THEN        IF (tof21_i.GT.none_find) THEN
1157           IF ((tof21(1,tof21_i,itdc).NE.4095).AND.           IF ((tof21(1,tof21_i,itdc).NE.4095).AND.
1158       &       (tof21(2,tof21_i,itdc).NE.4095)) THEN       &       (tof21(2,tof21_i,itdc).NE.4095)) THEN
1159           xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.           xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
1160       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)
1161          if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.          if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.
1162          i=tof21_i
1163        endif        endif
1164        endif        endif
1165    
# Line 813  C-----------------------------S2 ------- Line 1169  C-----------------------------S2 -------
1169           ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.           ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
1170       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)
1171          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.
1172          i=tof22_i
1173        endif        endif
1174        endif              endif
1175          
1176  C-----------------------------S3 --------------------------------  C-----------------------------S3 --------------------------------
1177          
1178        IF (tof31_i.GT.none_find) THEN        IF (tof31_i.GT.none_find) THEN
1179           IF ((tof31(1,tof31_i,itdc).NE.4095).AND.           IF ((tof31(1,tof31_i,itdc).NE.4095).AND.
1180       &       (tof31(2,tof31_i,itdc).NE.4095)) THEN       &       (tof31(2,tof31_i,itdc).NE.4095)) THEN
1181           ytofpos(3)  = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.           ytofpos(3)  = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
1182       +        -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)       +        -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)
1183          if (abs(ytofpos(3)).gt.18.)  ytofpos(3)=101.          if (abs(ytofpos(3)).gt.18.)  ytofpos(3)=101.
1184          i=tof31_i
1185        endif        endif
1186        endif        endif
1187    
# Line 833  C-----------------------------S3 ------- Line 1191  C-----------------------------S3 -------
1191           xtofpos(3)  = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.           xtofpos(3)  = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
1192       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)
1193          if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.          if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.
1194          i=tof32_i
1195        endif        endif
1196        endif        endif
1197          
1198  c      do i=1,3  c      do i=1,3
1199  c         if (abs(xtofpos(i)).gt.100.) then  c         if (abs(xtofpos(i)).gt.100.) then
1200  c            xtofpos(i)=101.  c            xtofpos(i)=101.
# Line 843  c         endif Line 1202  c         endif
1202  c         if (abs(ytofpos(i)).gt.100.) then  c         if (abs(ytofpos(i)).gt.100.) then
1203  c            ytofpos(i)=101.  c            ytofpos(i)=101.
1204  c         endif  c         endif
1205  c      enddo  c      enddo
         
1206    
1207    
1208    
1209  C--------------------------------------------------------------------  C--------------------------------------------------------------------
1210  C--------------------Time walk correction  -------------------------  C-------------------Corrections on ADC-data -------------------------
 C--------------------------------------------------------------------  
   
       DO i=1,8  
          xhelp_a = tof11(left,i,iadc)  
          xhelp_t = tof11(left,i,itdc)  
          if(xhelp_a<4095) xhelp = tw11(left,i)/sqrt(xhelp_a)  
          tof11(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)  
          xhelp_a = tof11(right,i,iadc)  
          xhelp_t = tof11(right,i,itdc)  
          if(xhelp_a<4095) xhelp = tw11(right,i)/sqrt(xhelp_a)  
          tof11(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)  
       ENDDO  
   
       DO i=1,6  
          xhelp_a = tof12(left,i,iadc)  
          xhelp_t = tof12(left,i,itdc)  
          if(xhelp_a<4095) xhelp = tw12(left,i)/sqrt(xhelp_a)  
          tof12(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)  
          xhelp_a = tof12(right,i,iadc)  
          xhelp_t = tof12(right,i,itdc)  
          if(xhelp_a<4095) xhelp = tw12(right,i)/sqrt(xhelp_a)  
          tof12(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)  
       ENDDO  
 C----  
       DO i=1,2  
          xhelp_a = tof21(left,i,iadc)  
          xhelp_t = tof21(left,i,itdc)  
          if(xhelp_a<4095) xhelp = tw21(left,i)/sqrt(xhelp_a)  
          tof21(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)  
          xhelp_a = tof21(right,i,iadc)  
          xhelp_t = tof21(right,i,itdc)  
          if(xhelp_a<4095) xhelp = tw21(right,i)/sqrt(xhelp_a)  
          tof21(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)  
       ENDDO  
   
       DO i=1,2  
          xhelp_a = tof22(left,i,iadc)  
          xhelp_t = tof22(left,i,itdc)  
          if(xhelp_a<4095) xhelp = tw22(left,i)/sqrt(xhelp_a)  
          tof22(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)  
          xhelp_a = tof22(right,i,iadc)  
          xhelp_t = tof22(right,i,itdc)  
          if(xhelp_a<4095) xhelp = tw22(right,i)/sqrt(xhelp_a)  
          tof22(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)  
       ENDDO  
 C----  
   
       DO i=1,3  
          xhelp_a = tof31(left,i,iadc)  
          xhelp_t = tof31(left,i,itdc)  
          if(xhelp_a<4095) xhelp = tw31(left,i)/sqrt(xhelp_a)  
          tof31(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)  
          xhelp_a = tof31(right,i,iadc)  
          xhelp_t = tof31(right,i,itdc)  
          if(xhelp_a<4095) xhelp = tw31(right,i)/sqrt(xhelp_a)  
          tof31(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)  
       ENDDO  
   
       DO i=1,3  
          xhelp_a = tof32(left,i,iadc)  
          xhelp_t = tof32(left,i,itdc)  
          if(xhelp_a<4095) xhelp = tw32(left,i)/sqrt(xhelp_a)  
          tof32(left,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)  
          xhelp_a = tof32(right,i,iadc)  
          xhelp_t = tof32(right,i,itdc)  
          if(xhelp_a<4095) xhelp = tw32(right,i)/sqrt(xhelp_a)  
          tof32(right,i,itdc) = xhelp_t  + xhelp  
          tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)  
       ENDDO  
   
   
 C---------------------------------------------------------------------  
 C--------------------Corrections on ADC-data -------------------------  
1211  C-----------------angle and ADC(x) correction -----------------------  C-----------------angle and ADC(x) correction -----------------------
1212    C----------------   moved to the new dEdx routine -------------------
1213    
1214  C-----------------------------S1 -------------------------------------  C--------------------------------------------------------------------
   
       yhelp=yout(1)  
       phi   = atan(tan(THXOUT(1))/tan(THYOUT(1)))  
 c      theta = atan(tan(THXOUT(1))/cos(phi)  
       theta = atan(tan(THXOUT(1))/cos(phi))  
   
       IF (tof11_i.GT.none_find.AND.yhelp.lt.100) THEN  
   
          i = tof11_i  
           
          if (tof11(left,i,iadc).lt.4095) then  
             tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta)  
             xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))  
             xkorr=xkorr/hepratio  
             adc_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr  
          endif  
   
           
          if (tof11(right,i,iadc).lt.4095) then  
             tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta)  
             xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
   
       xhelp=xout(2)  
       phi   = atan(tan(THXOUT(2))/tan(THYOUT(2)))  
 c      theta = atan(tan(THXOUT(2))/cos(phi)  
       theta = atan(tan(THXOUT(2))/cos(phi))  
       IF (tof12_i.GT.none_find.AND.xhelp.lt.100) THEN  
   
          i = tof12_i  
          if (tof12(left,i,iadc).lt.4095) then  
             tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta)  
             xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr  
          endif  
   
          if (tof12(right,i,iadc).lt.4095) then  
             tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta)  
             xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
 C-----------------------------S2 --------------------------------  
   
       xhelp=xout(3)  
       phi   = atan(tan(THXOUT(3))/tan(THYOUT(3)))  
 c      theta = atan(tan(THXOUT(3))/cos(phi)  
       theta = atan(tan(THXOUT(3))/cos(phi))  
       IF (tof21_i.GT.none_find.AND.xhelp.lt.100) THEN  
   
          i = tof21_i  
          if (tof21(left,i,iadc).lt.4095) then  
             tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta)  
             xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr  
          endif  
   
          if (tof21(right,i,iadc).lt.4095) then  
             tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta)  
             xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
       yhelp=yout(4)  
       phi   = atan(tan(THXOUT(4))/tan(THYOUT(4)))  
 c      theta = atan(tan(THXOUT(4))/cos(phi)  
       theta = atan(tan(THXOUT(4))/cos(phi))  
   
       IF (tof22_i.GT.none_find.AND.yhelp.lt.100) THEN  
   
          i = tof22_i  
          if (tof22(left,i,iadc).lt.4095) then  
             tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta)  
             xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr  
          endif  
   
          if (tof22(right,i,iadc).lt.4095) then  
             tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta)  
             xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
 C-----------------------------S3 --------------------------------  
   
       yhelp=yout(5)  
       phi   = atan(tan(THXOUT(5))/tan(THYOUT(5)))  
 c      theta = atan(tan(THXOUT(5))/cos(phi)  
       theta = atan(tan(THXOUT(5))/cos(phi))  
         
       IF (tof31_i.GT.none_find.AND.yhelp.lt.100) THEN  
   
          i = tof31_i  
          if (tof31(left,i,iadc).lt.4095) then  
             tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta)  
             xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr  
          endif  
   
          if (tof31(right,i,iadc).lt.4095) then  
             tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta)  
             xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
       xhelp=xout(6)  
       phi   = atan(tan(THXOUT(6))/tan(THYOUT(6)))  
 c      theta = atan(tan(THXOUT(6))/cos(phi)  
       theta = atan(tan(THXOUT(6))/cos(phi))  
   
       IF (tof32_i.GT.none_find.AND.xhelp.lt.100) THEN  
   
          i = tof32_i  
          if (tof32(left,i,iadc).lt.4095) then  
             tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta)  
             xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr  
          endif  
   
          if (tof32(right,i,iadc).lt.4095) then  
             tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta)  
             xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))  
             xkorr=xkorr/hepratio              
             adc_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
 C-----------------------------------------------------------------------  
1215  C----------------------calculate Beta  ------------------------------  C----------------------calculate Beta  ------------------------------
1216  C-----------------------------------------------------------------------  C--------------------------------------------------------------------
1217  C-------------------difference of sums  ---------------------------  C---------------------difference of sums  ---------------------------
1218  C      C
1219  C     DS = (t1+t2) - t3+t4)  C     DS = (t1+t2) - t3+t4)
1220  C     DS = c1 + c2/beta*cos(theta)  C     DS = c1 + c2/beta*cos(theta)
1221  C     c2 = 2d/c   gives c2 = 2d/(c*TDCresolution)  TDC=50ps/channel  C     c2 = 2d/c   gives c2 = 2d/(c*TDCresolution)  TDC=50ps/channel
1222  C     =>  c2 =  ca.60 for  0.45 m    c2 = ca.109  for 0.81 m  C     =>  c2 =  ca.60 for  0.45 m    c2 = ca.109  for 0.81 m
1223  C     since TDC resolution varies slightly c2 has to be calibrated  C     since TDC resolution varies slightly c2 has to be calibrated
1224  C     instead of cos(theta) use factor F:  C     instead of cos(theta) use factor F:
1225  C     F =  pathlength/d  C     F =  pathlength/d
1226  C     => beta = c2*F/(DS-c1))  C     => beta = c2*F/(DS-c1))
1227    
1228        dist = ZTOF(1) - ZTOF(5)        dist = ZTOF(1) - ZTOF(5)
# Line 1100  C     => beta = c2*F/(DS-c1)) Line 1230  C     => beta = c2*F/(DS-c1))
1230        DO I=1,5        DO I=1,5
1231           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1232        ENDDO        ENDDO
1233        F = dl/dist        F = dl/dist
1234    
1235  C     S11 - S31  C     S11 - S31
1236  C      IF (tof11_i.GT.none_find.AND.tof31_i.GT.none_find) THEN  C      IF (tof11_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
# Line 1110  C      IF (tof11_i.GT.none_find.AND.tof3 Line 1240  C      IF (tof11_i.GT.none_find.AND.tof3
1240           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1241           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1242           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1243           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1244       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1245              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1246              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1247              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1248              ihelp=(tof11_i-1)*3+tof31_i              ihelp=(tof11_i-1)*3+tof31_i
1249              c1 = k_S11S31(1,ihelp)              c1 = k_S11S31(1,ihelp)
1250              c2 = k_S11S31(2,ihelp)                      if (iz.gt.2) c1 = c1 + k1corrA1
1251                c2 = k_S11S31(2,ihelp)
1252              beta_a(1) = c2*F/(ds-c1)              beta_a(1) = c2*F/(ds-c1)
1253  C     write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)  c       write(*,*) 'S11-S31 ',c1,c2,F
1254    c       write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)
1255  C-------ToF Mask - S11 - S31  C-------ToF Mask - S11 - S31
1256    
1257              tofmask(ch11a(tof11_i),hb11a(tof11_i)) =              tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
# Line 1129  C-------ToF Mask - S11 - S31 Line 1261  C-------ToF Mask - S11 - S31
1261    
1262              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1263       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1264              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1265       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1266    
1267           ENDIF           ENDIF
# Line 1140  C-------ToF Mask - S11 - S31 Line 1272  C-------ToF Mask - S11 - S31
1272        DO I=1,6        DO I=1,6
1273           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1274        ENDDO        ENDDO
1275        F = dl/dist        F = dl/dist
1276          
1277  C     S11 - S32  C     S11 - S32
1278  C      IF (tof11_i.GT.none_find.AND.tof32_i.GT.none_find) THEN  C      IF (tof11_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1279         IF ((tof11_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
# Line 1150  C      IF (tof11_i.GT.none_find.AND.tof3 Line 1282  C      IF (tof11_i.GT.none_find.AND.tof3
1282           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1283           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1284           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1285           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1286       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1287              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1288              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1289              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1290              ihelp=(tof11_i-1)*3+tof32_i              ihelp=(tof11_i-1)*3+tof32_i
1291              c1 = k_S11S32(1,ihelp)              c1 = k_S11S32(1,ihelp)
1292              c2 = k_S11S32(2,ihelp)                      if (iz.gt.2) c1 = c1 + k1corrA1
1293                c2 = k_S11S32(2,ihelp)
1294              beta_a(2) = c2*F/(ds-c1)              beta_a(2) = c2*F/(ds-c1)
1295  C     write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)  C     write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)
1296    
# Line 1170  C-------ToF Mask - S11 - S32 Line 1303  C-------ToF Mask - S11 - S32
1303    
1304              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1305       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1306              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1307       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1308    
1309  C-------  C-------
# Line 1184  C     S12 - S31 Line 1317  C     S12 - S31
1317        DO I=2,5        DO I=2,5
1318           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1319        ENDDO        ENDDO
1320        F = dl/dist        F = dl/dist
1321    
1322  C      IF (tof12_i.GT.none_find.AND.tof31_i.GT.none_find) THEN  C      IF (tof12_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1323         IF ((tof12_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
# Line 1193  C      IF (tof12_i.GT.none_find.AND.tof3 Line 1326  C      IF (tof12_i.GT.none_find.AND.tof3
1326           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1327           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1328           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1329           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1330       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1331              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1332              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1333              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1334              ihelp=(tof12_i-1)*3+tof31_i              ihelp=(tof12_i-1)*3+tof31_i
1335              c1 = k_S12S31(1,ihelp)              c1 = k_S12S31(1,ihelp)
1336                if (iz.gt.2) c1 = c1 + k1corrA1
1337              c2 = k_S12S31(2,ihelp)              c2 = k_S12S31(2,ihelp)
1338              beta_a(3) = c2*F/(ds-c1)              beta_a(3) = c2*F/(ds-c1)
1339  C     write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)  C     write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)
# Line 1213  C-------ToF Mask - S12 - S31 Line 1347  C-------ToF Mask - S12 - S31
1347    
1348              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1349       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1350              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1351       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1352    
1353  C-------  C-------
# Line 1228  C     S12 - S32 Line 1362  C     S12 - S32
1362        DO I=2,6        DO I=2,6
1363           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1364        ENDDO        ENDDO
1365        F = dl/dist        F = dl/dist
1366    
1367  C      IF (tof12_i.GT.none_find.AND.tof32_i.GT.none_find) THEN  C      IF (tof12_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1368         IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
# Line 1237  C      IF (tof12_i.GT.none_find.AND.tof3 Line 1371  C      IF (tof12_i.GT.none_find.AND.tof3
1371           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1372           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1373           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1374           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1375       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1376              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1377              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1378              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1379              ihelp=(tof12_i-1)*3+tof32_i              ihelp=(tof12_i-1)*3+tof32_i
1380              c1 = k_S12S32(1,ihelp)              c1 = k_S12S32(1,ihelp)
1381                if (iz.gt.2) c1 = c1 + k1corrA1
1382              c2 = k_S12S32(2,ihelp)              c2 = k_S12S32(2,ihelp)
1383              beta_a(4) = c2*F/(ds-c1)              beta_a(4) = c2*F/(ds-c1)
1384  C     write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)  C     write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)
# Line 1257  C-------ToF Mask - S12 - S32 Line 1392  C-------ToF Mask - S12 - S32
1392    
1393              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1394       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1395              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1396       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1397    
1398  C-------  C-------
# Line 1272  C     S21 - S31 Line 1407  C     S21 - S31
1407        DO I=3,5        DO I=3,5
1408           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1409        ENDDO        ENDDO
1410        F = dl/dist        F = dl/dist
1411    
1412  C      IF (tof21_i.GT.none_find.AND.tof31_i.GT.none_find) THEN  C      IF (tof21_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1413         IF ((tof21_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof21_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
# Line 1281  C      IF (tof21_i.GT.none_find.AND.tof3 Line 1416  C      IF (tof21_i.GT.none_find.AND.tof3
1416           t2 = tof21(2,tof21_i,itdc)           t2 = tof21(2,tof21_i,itdc)
1417           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1418           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1419           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1420       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1421              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1422              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1423              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1424              ihelp=(tof21_i-1)*3+tof31_i              ihelp=(tof21_i-1)*3+tof31_i
1425              c1 = k_S21S31(1,ihelp)              c1 = k_S21S31(1,ihelp)
1426                if (iz.gt.2) c1 = c1 + k1corrB1
1427              c2 = k_S21S31(2,ihelp)              c2 = k_S21S31(2,ihelp)
1428              beta_a(5) = c2*F/(ds-c1)              beta_a(5) = c2*F/(ds-c1)
1429    
# Line 1300  C-------ToF Mask - S21 - S31 Line 1436  C-------ToF Mask - S21 - S31
1436    
1437              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1438       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1439              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1440       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1441    
1442  C-------  C-------
# Line 1315  C     S21 - S32 Line 1451  C     S21 - S32
1451        DO I=3,6        DO I=3,6
1452           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1453        ENDDO        ENDDO
1454        F = dl/dist        F = dl/dist
1455    
1456  C      IF (tof21_i.GT.none_find.AND.tof32_i.GT.none_find) THEN  C      IF (tof21_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1457         IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
# Line 1324  C      IF (tof21_i.GT.none_find.AND.tof3 Line 1460  C      IF (tof21_i.GT.none_find.AND.tof3
1460           t2 = tof21(2,tof21_i,itdc)           t2 = tof21(2,tof21_i,itdc)
1461           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1462           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1463           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1464       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1465              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1466              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1467              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1468              ihelp=(tof21_i-1)*3+tof32_i              ihelp=(tof21_i-1)*3+tof32_i
1469              c1 = k_S21S32(1,ihelp)              c1 = k_S21S32(1,ihelp)
1470                if (iz.gt.2) c1 = c1 + k1corrB1
1471              c2 = k_S21S32(2,ihelp)              c2 = k_S21S32(2,ihelp)
1472              beta_a(6) = c2*F/(ds-c1)              beta_a(6) = c2*F/(ds-c1)
1473    
# Line 1343  C-------ToF Mask - S21 - S32 Line 1480  C-------ToF Mask - S21 - S32
1480    
1481              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1482       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1483              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1484       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1485    
1486  C-------  C-------
# Line 1358  C     S22 - S31 Line 1495  C     S22 - S31
1495        DO I=4,5        DO I=4,5
1496           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1497        ENDDO        ENDDO
1498        F = dl/dist        F = dl/dist
1499          
1500    C WM workaround
1501          dl = dl - 0.06*F
1502          F = dl/dist
1503    
1504  C      IF (tof22_i.GT.none_find.AND.tof31_i.GT.none_find) THEN  C      IF (tof22_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1505         IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
# Line 1367  C      IF (tof22_i.GT.none_find.AND.tof3 Line 1508  C      IF (tof22_i.GT.none_find.AND.tof3
1508           t2 = tof22(2,tof22_i,itdc)           t2 = tof22(2,tof22_i,itdc)
1509           t3 = tof31(1,tof31_i,itdc)           t3 = tof31(1,tof31_i,itdc)
1510           t4 = tof31(2,tof31_i,itdc)           t4 = tof31(2,tof31_i,itdc)
1511           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1512       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1513              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1514              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)              xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1515              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1516              ihelp=(tof22_i-1)*3+tof31_i              ihelp=(tof22_i-1)*3+tof31_i
1517              c1 = k_S22S31(1,ihelp)              c1 = k_S22S31(1,ihelp)
1518                if (iz.gt.2) c1 = c1 + k1corrB1
1519              c2 = k_S22S31(2,ihelp)              c2 = k_S22S31(2,ihelp)
1520              beta_a(7) = c2*F/(ds-c1)              beta_a(7) = c2*F/(ds-c1)
1521    
# Line 1386  C-------ToF Mask - S22 - S31 Line 1528  C-------ToF Mask - S22 - S31
1528    
1529              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =              tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1530       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1       $           tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1531              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =              tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1532       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1       $           tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1533    
1534  C-------  C-------
1535    
1536           ENDIF           ENDIF
1537        ENDIF        ENDIF
1538          
1539  C     S22 - S32  C     S22 - S32
1540    
1541        dist = ZTOF(4) - ZTOF(6)        dist = ZTOF(4) - ZTOF(6)
# Line 1401  C     S22 - S32 Line 1543  C     S22 - S32
1543        DO I=4,6        DO I=4,6
1544           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1545        ENDDO        ENDDO
1546        F = dl/dist        F = dl/dist
1547          
1548    C WM workaround      
1549          dl = dl - 0.06*F
1550          F = dl/dist
1551    
1552    
1553  C      IF (tof22_i.GT.none_find.AND.tof32_i.GT.none_find) THEN  C      IF (tof22_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1554         IF ((tof22_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof22_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
# Line 1410  C      IF (tof22_i.GT.none_find.AND.tof3 Line 1557  C      IF (tof22_i.GT.none_find.AND.tof3
1557           t2 = tof22(2,tof22_i,itdc)           t2 = tof22(2,tof22_i,itdc)
1558           t3 = tof32(1,tof32_i,itdc)           t3 = tof32(1,tof32_i,itdc)
1559           t4 = tof32(2,tof32_i,itdc)           t4 = tof32(2,tof32_i,itdc)
1560           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1561       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1562              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1563              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)              xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1564              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1565              ihelp=(tof22_i-1)*3+tof32_i              ihelp=(tof22_i-1)*3+tof32_i
1566              c1 = k_S22S32(1,ihelp)              c1 = k_S22S32(1,ihelp)
1567                if (iz.gt.2) c1 = c1 + k1corrB1
1568              c2 = k_S22S32(2,ihelp)              c2 = k_S22S32(2,ihelp)
1569              beta_a(8) = c2*F/(ds-c1)              beta_a(8) = c2*F/(ds-c1)
1570    
# Line 1429  C-------ToF Mask - S22 - S32 Line 1577  C-------ToF Mask - S22 - S32
1577    
1578              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =              tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1579       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1       $           tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1580              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =              tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1581       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1       $           tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1582    
1583  C-------  C-------
# Line 1444  C     S11 - S21 Line 1592  C     S11 - S21
1592        DO I=1,3        DO I=1,3
1593           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1594        ENDDO        ENDDO
1595        F = dl/dist        F = dl/dist
1596    
1597    C WM workaround      
1598          dl = dl - 0.442*F
1599          F = dl/dist
1600    
1601  C      IF (tof11_i.GT.none_find.AND.tof21_i.GT.none_find) THEN  C      IF (tof11_i.GT.none_find.AND.tof21_i.GT.none_find) THEN
1602         IF ((tof11_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
# Line 1453  C      IF (tof11_i.GT.none_find.AND.tof2 Line 1605  C      IF (tof11_i.GT.none_find.AND.tof2
1605           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1606           t3 = tof21(1,tof21_i,itdc)           t3 = tof21(1,tof21_i,itdc)
1607           t4 = tof21(2,tof21_i,itdc)           t4 = tof21(2,tof21_i,itdc)
1608           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1609       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1610              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1611              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1612              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1613              ihelp=(tof11_i-1)*2+tof21_i              ihelp=(tof11_i-1)*2+tof21_i
1614              c1 = k_S11S21(1,ihelp)              c1 = k_S11S21(1,ihelp)
1615                if (iz.gt.2) c1 = c1 + k1corrC1
1616              c2 = k_S11S21(2,ihelp)              c2 = k_S11S21(2,ihelp)
1617              beta_a(9) = c2*F/(ds-c1)              beta_a(9) = c2*F/(ds-c1)
1618    
# Line 1472  C-------ToF Mask - S11 - S21 Line 1625  C-------ToF Mask - S11 - S21
1625    
1626              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1627       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1628              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1629       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1630    
1631  C-------  C-------
1632    
1633           ENDIF           ENDIF
1634        ENDIF        ENDIF
1635          
1636  C     S11 - S22  C     S11 - S22
1637    
1638        dist = ZTOF(1) - ZTOF(4)        dist = ZTOF(1) - ZTOF(4)
# Line 1487  C     S11 - S22 Line 1640  C     S11 - S22
1640        DO I=1,4        DO I=1,4
1641           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1642        ENDDO        ENDDO
1643        F = dl/dist        F = dl/dist
1644    
1645  C      IF (tof11_i.GT.none_find.AND.tof22_i.GT.none_find) THEN  C      IF (tof11_i.GT.none_find.AND.tof22_i.GT.none_find) THEN
1646         IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
# Line 1496  C      IF (tof11_i.GT.none_find.AND.tof2 Line 1649  C      IF (tof11_i.GT.none_find.AND.tof2
1649           t2 = tof11(2,tof11_i,itdc)           t2 = tof11(2,tof11_i,itdc)
1650           t3 = tof22(1,tof22_i,itdc)           t3 = tof22(1,tof22_i,itdc)
1651           t4 = tof22(2,tof22_i,itdc)           t4 = tof22(2,tof22_i,itdc)
1652           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1653       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1654              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)              xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1655              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1656              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1657              ihelp=(tof11_i-1)*2+tof22_i              ihelp=(tof11_i-1)*2+tof22_i
1658              c1 = k_S11S22(1,ihelp)              c1 = k_S11S22(1,ihelp)
1659                if (iz.gt.2) c1 = c1 + k1corrC1
1660              c2 = k_S11S22(2,ihelp)              c2 = k_S11S22(2,ihelp)
1661              beta_a(10) = c2*F/(ds-c1)              beta_a(10) = c2*F/(ds-c1)
1662    
# Line 1515  C-------ToF Mask - S11 - S22 Line 1669  C-------ToF Mask - S11 - S22
1669    
1670              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1671       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1672              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1673       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1674    
1675  C-------  C-------
# Line 1530  C     S12 - S21 Line 1684  C     S12 - S21
1684        DO I=2,3        DO I=2,3
1685           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1686        ENDDO        ENDDO
1687        F = dl/dist        F = dl/dist
1688    
1689    C  WM workaround
1690          dl = dl - 0.442*F
1691          F = dl/dist
1692    
1693  C      IF (tof12_i.GT.none_find.AND.tof21_i.GT.none_find) THEN  C      IF (tof12_i.GT.none_find.AND.tof21_i.GT.none_find) THEN
1694         IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
# Line 1539  C      IF (tof12_i.GT.none_find.AND.tof2 Line 1697  C      IF (tof12_i.GT.none_find.AND.tof2
1697           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1698           t3 = tof21(1,tof21_i,itdc)           t3 = tof21(1,tof21_i,itdc)
1699           t4 = tof21(2,tof21_i,itdc)           t4 = tof21(2,tof21_i,itdc)
1700           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1701       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1702              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1703              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)              xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1704              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1705              ihelp=(tof12_i-1)*2+tof21_i              ihelp=(tof12_i-1)*2+tof21_i
1706              c1 = k_S12S21(1,ihelp)              c1 = k_S12S21(1,ihelp)
1707                if (iz.gt.2) c1 = c1 + k1corrC1
1708              c2 = k_S12S21(2,ihelp)              c2 = k_S12S21(2,ihelp)
1709              beta_a(11) = c2*F/(ds-c1)              beta_a(11) = c2*F/(ds-c1)
1710    
# Line 1558  C-------ToF Mask - S12 - S21 Line 1717  C-------ToF Mask - S12 - S21
1717    
1718              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =              tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1719       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1       $           tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1720              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =              tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1721       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1       $           tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1722    
1723  C-------  C-------
# Line 1573  C     S12 - S22 Line 1732  C     S12 - S22
1732        DO I=2,4        DO I=2,4
1733           dl = dl + TLOUT(i)           dl = dl + TLOUT(i)
1734        ENDDO        ENDDO
1735        F = dl/dist        F = dl/dist
1736    
1737  C      IF (tof12_i.GT.none_find.AND.tof22_i.GT.none_find) THEN  C      IF (tof12_i.GT.none_find.AND.tof22_i.GT.none_find) THEN
1738         IF ((tof12_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
# Line 1582  C      IF (tof12_i.GT.none_find.AND.tof2 Line 1741  C      IF (tof12_i.GT.none_find.AND.tof2
1741           t2 = tof12(2,tof12_i,itdc)           t2 = tof12(2,tof12_i,itdc)
1742           t3 = tof22(1,tof22_i,itdc)           t3 = tof22(1,tof22_i,itdc)
1743           t4 = tof22(2,tof22_i,itdc)           t4 = tof22(2,tof22_i,itdc)
1744           IF ((t1.lt.4095).and.(t2.lt.4095).and.           IF ((t1.lt.4095).and.(t2.lt.4095).and.
1745       &        (t3.lt.4095).and.(t4.lt.4095)) THEN       &        (t3.lt.4095).and.(t4.lt.4095)) THEN
1746              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)              xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1747              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)              xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1748              ds = xhelp1-xhelp2              ds = xhelp1-xhelp2
1749              ihelp=(tof12_i-1)*2+tof22_i              ihelp=(tof12_i-1)*2+tof22_i
1750              c1 = k_S12S22(1,ihelp)              c1 = k_S12S22(1,ihelp)
1751                if (iz.gt.2) c1 = c1 + k1corrC1
1752              c2 = k_S12S22(2,ihelp)              c2 = k_S12S22(2,ihelp)
1753              beta_a(12) = c2*F/(ds-c1)              beta_a(12) = c2*F/(ds-c1)
1754    
# Line 1601  C-------ToF Mask - S12 - S22 Line 1761  C-------ToF Mask - S12 - S22
1761    
1762              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =              tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1763       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1       $           tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1764              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =              tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1765       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1       $           tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1766    
1767  C-------  C-------
1768    
1769           ENDIF           ENDIF
1770        ENDIF        ENDIF
1771          
1772  C-------  C-------
1773    C
1774    C      icount=0
1775    C      sw=0.
1776    C      sxw=0.
1777    C      beta_mean=100.
1778    C
1779    C      do i=1,12
1780    C         if ((beta_a(i).gt.-1.5).and.(beta_a(i).lt.1.5)) then
1781    C            icount= icount+1
1782    C            if (i.le.4) w_i=1./(0.13**2.)
1783    C            if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)
1784    C            if (i.ge.9) w_i=1./(0.25**2.) ! to be checked
1785    C            sxw=sxw + beta_a(i)*w_i
1786    C            sw =sw + w_i
1787    C         endif
1788    C      enddo
1789    C
1790    C      if (icount.gt.0) beta_mean=sxw/sw
1791    C      beta_a(13) = beta_mean
1792    C
1793    
1794        icount=0  C-------  New mean beta  calculation
       sw=0.  
       sxw=0.  
       beta_mean=100.  
1795    
1796        do i=1,12         do i=1,12
1797           if ((beta_a(i).gt.-1.5).and.(beta_a(i).lt.1.5)) then           btemp(i) =  beta_a(i)
1798              icount= icount+1         enddo
             if (i.le.4) w_i=1./(0.13**2.)  
             if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)  
             if (i.ge.9) w_i=1./(0.25**2.) ! to be checked  
             sxw=sxw + beta_a(i)*w_i  
             sw =sw + w_i  
          endif  
       enddo  
         
       if (icount.gt.0) beta_mean=sxw/sw  
       beta_a(13) = beta_mean  
1799    
1800           beta_a(13)=newbeta(2,btemp,hitvec,10.,10.,20.)
1801    
1802    C-------
1803    
1804  c       IF (tof11_i.GT.none_find)  
1805    c       IF (tof11_i.GT.none_find)
1806  c     &  write(*,*) '11 ',tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)  c     &  write(*,*) '11 ',tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)
1807  c       IF (tof12_i.GT.none_find)  c       IF (tof12_i.GT.none_find)
1808  c     &  write(*,*) '12 ',tof12(1,tof12_i,itdc),tof12(2,tof12_i,itdc)  c     &  write(*,*) '12 ',tof12(1,tof12_i,itdc),tof12(2,tof12_i,itdc)
1809    
1810  c       IF (tof21_i.GT.none_find)  c       IF (tof21_i.GT.none_find)
1811  c     &  write(*,*) '21 ',tof21(1,tof21_i,itdc),tof21(2,tof21_i,itdc)  c     &  write(*,*) '21 ',tof21(1,tof21_i,itdc),tof21(2,tof21_i,itdc)
1812  c       IF (tof22_i.GT.none_find)  c       IF (tof22_i.GT.none_find)
1813  c     &  write(*,*) '22 ',tof22(1,tof22_i,itdc),tof22(2,tof22_i,itdc)  c     &  write(*,*) '22 ',tof22(1,tof22_i,itdc),tof22(2,tof22_i,itdc)
1814    
1815  c       IF (tof31_i.GT.none_find)  c       IF (tof31_i.GT.none_find)
1816  c     &  write(*,*) '31 ',tof31(1,tof31_i,itdc),tof31(2,tof31_i,itdc)  c     &  write(*,*) '31 ',tof31(1,tof31_i,itdc),tof31(2,tof31_i,itdc)
1817  c       IF (tof32_i.GT.none_find)  c       IF (tof32_i.GT.none_find)
1818  c     &  write(*,*) '32 ',tof32(1,tof32_i,itdc),tof32(2,tof32_i,itdc)  c     &  write(*,*) '32 ',tof32(1,tof32_i,itdc),tof32(2,tof32_i,itdc)
1819    
1820  c      write(*,*) xtofpos  c      write(*,*) xtofpos
1821  c      write(*,*) ytofpos  c      write(*,*) ytofpos
1822  c      write(*,*) beta_a  C      write(*,*)'toftrk beta', beta_a
1823  C      write(*,*) adcflagtof  C      write(*,*) adcflagtof
   
   
1824  C     write(*,*)'TOFTRK ',ievent,beta_a(1),beta_a(2),beta_a(3),beta_a(4)  C     write(*,*)'TOFTRK ',ievent,beta_a(1),beta_a(2),beta_a(3),beta_a(4)
1825    c      write(*,*) 'toftrk'
1826    c      write(*,*) xtofpos
1827    c      write(*,*) ytofpos
1828    c      write(*,*) xtr_tof
1829    c      write(*,*) ytr_tof
1830    
1831    c       write(*,*) '---------  end toftrk ----------'
1832    
1833        RETURN        RETURN
1834        END        END
1835    
1836    
1837    
1838    
1839    C------------------------------------------------------------------
1840    
1841    

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.23