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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations) (download)
Wed Feb 17 11:50:54 2010 UTC (14 years, 9 months ago) by mocchiut
Branch: MAIN
CVS Tags: v9r00, v9r01
Changes since 1.19: +108 -60 lines
New ToF timing for Z>1

1 mocchiut 1.1 *****************************************************************************
2     INTEGER FUNCTION TOFTRK()
3 mocchiut 1.5
4     C****************************************************************************
5 mocchiut 1.8 C 31-08-06 WM
6     C Changed to use DOTRACK2
7     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
9     C routine it was (t1+t2)<8000
10 pam-de 1.12 C
11     C 08-12-06 WM:
12 mocchiut 1.8 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"
14 pam-de 1.12 C
15     C jan-07 GF: ADC/TDCflags(4,12) inserted to flag artificial ADC/TDC
16 mocchiut 1.8 C values
17     C jan-07 WM: artificial ADC values created using attenuation calibration
18     C jan-07 WM: artificial TDC values created using xy_coor calibration
19     C jan-07 WM: modified xtofpos flag "101". xtofpos must be inside physical
20     C dimension of the paddle +/- 10 cm
21     C jan-07 WM: if xtofpos=101 then this paddle is not used for beta
22     C calculation
23 pam-de 1.12 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
25 mocchiut 1.8 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
27 mocchiut 1.10 C jan-05 WM: bug fixed: calculation of zenith angles using DOTRACK2
28 mocchiut 1.9 C was incorrect
29 mocchiut 1.10 C jan-07 WM: bug fixed: in some cases tdc_tw was calculated due to a
30     C leftover "xhelp" value
31 mocchiut 1.11 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 pam-de 1.12 C new variables xtr_tof(6) and ytr_tof(6) give track position
34 mocchiut 1.11 C at ToF layers
35 pam-de 1.12 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 mocchiut 1.15 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 pam-de 1.16 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 mocchiut 1.17 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 pamelats 1.18 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 mocchiut 1.19 C nov-09 WM: the dEdx part ("adc_c") moved to the new dEdx routine from Napoli
56 mocchiut 1.20 C feb-10 WM: k1 values now for Z=1, Z=2, Z>2, k2 values are fix
57     C feb-10 WM: charge calculation with tracker dEdx vs. deflection^2
58 mocchiut 1.19 C
59 mocchiut 1.5 C****************************************************************************
60 mocchiut 1.1 IMPLICIT NONE
61 pam-de 1.12 C
62 mocchiut 1.1 include 'input_tof.txt'
63     include 'output_tof.txt'
64     include 'tofcomm.txt'
65 pam-de 1.12 C
66    
67 mocchiut 1.1 c =======================================
68     c variables for tracking routine
69     c =======================================
70     integer NPOINT_MAX
71     parameter(NPOINT_MAX=100)
72    
73     c define TOF Z-coordinates
74     integer NPTOF
75     parameter (NPTOF=6)
76     DOUBLE PRECISION ZTOF(NPTOF)
77     DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006
78    
79 mocchiut 1.8 integer itof,pmt_id
80 mocchiut 1.1
81     DOUBLE PRECISION al_p(5),
82 mocchiut 1.5 & xout(NPOINT_MAX),yout(NPOINT_MAX),zin(NPTOF),
83     & THXOUT(NPOINT_MAX),THYOUT(NPOINT_MAX),TLOUT(NPOINT_MAX)
84    
85 mocchiut 1.20 DOUBLE PRECISION dedxtrk
86     DOUBLE PRECISION deflection
87 mocchiut 1.1
88     INTEGER IFAIL
89 mocchiut 1.9 c REAL dx,dy,dr
90 mocchiut 1.8 REAL ds
91 mocchiut 1.5 REAL t1,t2,t3,t4
92 mocchiut 1.8 REAL yhelp,xhelp,xhelp1,xhelp2
93 mocchiut 1.20 REAL yhelp1,yhelp2
94 mocchiut 1.15 REAL c1,c2
95     C REAL sw,sxw,w_i
96 pam-de 1.12 REAL dist,dl,F
97 mocchiut 1.15 INTEGER ievent
98     C INTEGER icount
99     C REAL beta_mean
100     REAL btemp(12)
101 mocchiut 1.8 REAL hepratio
102 pam-de 1.12
103 mocchiut 1.15 INTEGER j,hitvec(6)
104 mocchiut 1.1
105 mocchiut 1.20 real atten,pc_adc,newbeta
106     C real check_charge
107 mocchiut 1.11
108    
109 mocchiut 1.8 REAL theta,phi
110 mocchiut 1.1 C-- DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006
111     REAL tofarm12
112     PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69
113 pam-de 1.12 REAL tofarm23
114 mocchiut 1.8 PARAMETER (tofarm23 = 47.61) ! from 23.69 to -23.92
115 mocchiut 1.1 REAL tofarm13
116 mocchiut 1.8 PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92
117 mocchiut 1.1
118 pam-de 1.12
119 pamelats 1.18 C--- new
120     REAL xtofpre(3),ytofpre(3)
121    
122     REAL y_coor_lin11c(8,2),x_coor_lin12c(6,2)
123     REAL x_coor_lin21c(2,2),y_coor_lin22c(2,2)
124     REAL y_coor_lin31c(3,2),x_coor_lin32c(3,2)
125    
126     DATA y_coor_lin11c(1,1),y_coor_lin11c(1,2) /-20.66,-2.497/
127     DATA y_coor_lin11c(2,1),y_coor_lin11c(2,2) /-9.10, -2.52/
128     DATA y_coor_lin11c(3,1),y_coor_lin11c(3,2) /-24.07,-2.12/
129     DATA y_coor_lin11c(4,1),y_coor_lin11c(4,2) /-13.40,-2.47/
130     DATA y_coor_lin11c(5,1),y_coor_lin11c(5,2) /-31.07,-2.32/
131     DATA y_coor_lin11c(6,1),y_coor_lin11c(6,2) /-21.69,-2.63/
132     DATA y_coor_lin11c(7,1),y_coor_lin11c(7,2) /-12.37,-2.65/
133     DATA y_coor_lin11c(8,1),y_coor_lin11c(8,2) /-10.81,-3.15/
134    
135     DATA x_coor_lin12c(1,1),x_coor_lin12c(1,2) /12.96, -2.65/
136     DATA x_coor_lin12c(2,1),x_coor_lin12c(2,2) /17.12,-2.44/
137     DATA x_coor_lin12c(3,1),x_coor_lin12c(3,2) /7.26, -1.98/
138     DATA x_coor_lin12c(4,1),x_coor_lin12c(4,2) /-22.52,-2.27/
139     DATA x_coor_lin12c(5,1),x_coor_lin12c(5,2) /-18.54,-2.28/
140     DATA x_coor_lin12c(6,1),x_coor_lin12c(6,2) /-7.67,-2.15/
141    
142     DATA x_coor_lin21c(1,1),x_coor_lin21c(1,2) /22.56,-1.56/
143     DATA x_coor_lin21c(2,1),x_coor_lin21c(2,2) /13.94,-1.56/
144    
145     DATA y_coor_lin22c(1,1),y_coor_lin22c(1,2) /-24.24,-2.23/
146     DATA y_coor_lin22c(2,1),y_coor_lin22c(2,2) /-45.99,-1.68/
147    
148     DATA y_coor_lin31c(1,1),y_coor_lin31c(1,2) /-22.99,-3.54/
149     DATA y_coor_lin31c(2,1),y_coor_lin31c(2,2) /-42.28,-4.10/
150     DATA y_coor_lin31c(3,1),y_coor_lin31c(3,2) /-41.29,-3.69/
151    
152     DATA x_coor_lin32c(1,1),x_coor_lin32c(1,2) /0.961, -3.22/
153     DATA x_coor_lin32c(2,1),x_coor_lin32c(2,2) /4.98,-3.48/
154     DATA x_coor_lin32c(3,1),x_coor_lin32c(3,2) /-22.08,-3.37/
155    
156     C---
157    
158 mocchiut 1.1 INTEGER ihelp
159 mocchiut 1.8 REAL xkorr,xpos
160 mocchiut 1.1
161 mocchiut 1.15 INTEGER IZ
162    
163 mocchiut 1.1 REAL yl,yh,xl,xh
164 pam-de 1.12 C
165 mocchiut 1.1 REAL hmemor(9000000)
166     INTEGER Iquest(100)
167 pam-de 1.12 C
168 mocchiut 1.5 DATA ievent / 0 /
169    
170 mocchiut 1.15 INTEGER ifst
171     DATA ifst /0/
172    
173 mocchiut 1.1 COMMON / pawcd / hmemor
174     save / pawcd /
175 pam-de 1.12 C
176 mocchiut 1.1 Common / QUESTd / Iquest
177     save / questd /
178 pam-de 1.12 C
179 mocchiut 1.1 C Begin !
180 pam-de 1.12 C
181 mocchiut 1.1 TOFTRK = 0
182    
183     *******************************************************************
184    
185 mocchiut 1.15 if (ifst.eq.0) then
186     ifst=1
187 mocchiut 1.5
188 mocchiut 1.8 C ratio helium to proton ca. 4
189 mocchiut 1.11 hepratio = 4.
190 mocchiut 1.5
191 mocchiut 1.1 offset = 1
192     slope = 2
193     left = 1
194     right = 2
195     none_ev = 0
196     none_find = 0
197     tdc_ev = 1
198     adc_ev = 1
199     itdc = 1
200     iadc = 2
201    
202 mocchiut 1.15 ENDIF ! ifst
203    
204     *******************************************************************
205    
206     ievent = ievent +1
207    
208 mocchiut 1.1 do i=1,13
209     beta_a(i) = 100.
210     enddo
211    
212 mocchiut 1.2 do i=1,4
213     do j=1,12
214     adc_c(i,j) = 1000.
215     enddo
216     enddo
217    
218     do i=1,12
219     do j=1,4
220     tofmask(j,i) = 0
221     enddo
222     enddo
223    
224 mocchiut 1.8 do i=1,4
225     do j=1,12
226     adcflag(i,j) = 0
227     enddo
228     enddo
229    
230     do i=1,4
231     do j=1,12
232     tdcflag(i,j) = 0
233     enddo
234     enddo
235    
236     pmt_id=0
237    
238 mocchiut 1.9 do j=1,6
239     THXOUT(j) = 0.
240     THYOUT(j) = 0.
241     enddo
242    
243 mocchiut 1.11 do j=1,6
244     xtr_tof(j) = 100.
245     ytr_tof(j) = 100.
246     enddo
247    
248 mocchiut 1.15
249 mocchiut 1.8 C----------------------------------------------------------------------
250     C-------------------------get ToF data --------------------------------
251     C we cannot use the tofxx(x,x,x) data from tofl2com since it is
252 pam-de 1.12 C manipulated (Time-walk, artificila ADc and TDC values using ToF
253 mocchiut 1.8 C standalone information
254     C----------------------------------------------------------------------
255    
256 mocchiut 1.11 c put the adc and tdc values from ntuple into tofxx(i,j,k) variables
257 mocchiut 1.8
258     do j=1,8
259 mocchiut 1.11 tof11(1,j,2) = pc_adc(adc(ch11a(j),hb11a(j)))
260     tof11(2,j,2) = pc_adc(adc(ch11b(j),hb11b(j)))
261     tof11(1,j,1) = (tdc(ch11a(j),hb11a(j)))
262     tof11(2,j,1) = (tdc(ch11b(j),hb11b(j)))
263 mocchiut 1.8 enddo
264    
265    
266     do j=1,6
267 mocchiut 1.11 tof12(1,j,2) = pc_adc(adc(ch12a(j),hb12a(j)))
268     tof12(2,j,2) = pc_adc(adc(ch12b(j),hb12b(j)))
269     tof12(1,j,1) = (tdc(ch12a(j),hb12a(j)))
270     tof12(2,j,1) = (tdc(ch12b(j),hb12b(j)))
271 mocchiut 1.8 enddo
272    
273     do j=1,2
274 mocchiut 1.11 tof21(1,j,2) = pc_adc(adc(ch21a(j),hb21a(j)))
275     tof21(2,j,2) = pc_adc(adc(ch21b(j),hb21b(j)))
276     tof21(1,j,1) = (tdc(ch21a(j),hb21a(j)))
277     tof21(2,j,1) = (tdc(ch21b(j),hb21b(j)))
278 mocchiut 1.8 enddo
279 pamelats 1.18
280 mocchiut 1.8 do j=1,2
281 mocchiut 1.11 tof22(1,j,2) = pc_adc(adc(ch22a(j),hb22a(j)))
282     tof22(2,j,2) = pc_adc(adc(ch22b(j),hb22b(j)))
283     tof22(1,j,1) = (tdc(ch22a(j),hb22a(j)))
284     tof22(2,j,1) = (tdc(ch22b(j),hb22b(j)))
285 mocchiut 1.8 enddo
286    
287     do j=1,3
288 mocchiut 1.11 tof31(1,j,2) = pc_adc(adc(ch31a(j),hb31a(j)))
289     tof31(2,j,2) = pc_adc(adc(ch31b(j),hb31b(j)))
290     tof31(1,j,1) = (tdc(ch31a(j),hb31a(j)))
291     tof31(2,j,1) = (tdc(ch31b(j),hb31b(j)))
292 mocchiut 1.8 enddo
293    
294     do j=1,3
295 mocchiut 1.11 tof32(1,j,2) = pc_adc(adc(ch32a(j),hb32a(j)))
296     tof32(2,j,2) = pc_adc(adc(ch32b(j),hb32b(j)))
297     tof32(1,j,1) = (tdc(ch32a(j),hb32a(j)))
298     tof32(2,j,1) = (tdc(ch32b(j),hb32b(j)))
299 mocchiut 1.8 enddo
300    
301     C----------------------------------------------------------------------
302    
303     DO i = 1,8
304     if (abs(tof11(1,i,itdc)).gt.10000.) tof11(1,i,itdc)= 10000.
305     if (abs(tof11(2,i,itdc)).gt.10000.) tof11(2,i,itdc)= 10000.
306     if (abs(tof11(1,i,iadc)).gt.10000.) tof11(1,i,iadc)= 10000.
307     if (abs(tof11(2,i,iadc)).gt.10000.) tof11(2,i,iadc)= 10000.
308     ENDDO
309    
310     DO i = 1,6
311     if (abs(tof12(1,i,itdc)).gt.10000.) tof12(1,i,itdc)= 10000.
312     if (abs(tof12(2,i,itdc)).gt.10000.) tof12(2,i,itdc)= 10000.
313     if (abs(tof12(1,i,iadc)).gt.10000.) tof12(1,i,iadc)= 10000.
314     if (abs(tof12(2,i,iadc)).gt.10000.) tof12(2,i,iadc)= 10000.
315     ENDDO
316    
317    
318     DO i = 1,2
319     if (abs(tof21(1,i,itdc)).gt.10000.) tof21(1,i,itdc)= 10000.
320     if (abs(tof21(2,i,itdc)).gt.10000.) tof21(2,i,itdc)= 10000.
321     if (abs(tof21(1,i,iadc)).gt.10000.) tof21(1,i,iadc)= 10000.
322     if (abs(tof21(2,i,iadc)).gt.10000.) tof21(2,i,iadc)= 10000.
323     ENDDO
324    
325     DO i = 1,2
326     if (abs(tof22(1,i,itdc)).gt.10000.) tof22(1,i,itdc)= 10000.
327     if (abs(tof22(2,i,itdc)).gt.10000.) tof22(2,i,itdc)= 10000.
328     if (abs(tof22(1,i,iadc)).gt.10000.) tof22(1,i,iadc)= 10000.
329     if (abs(tof22(2,i,iadc)).gt.10000.) tof22(2,i,iadc)= 10000.
330     ENDDO
331    
332     DO i = 1,3
333     if (abs(tof31(1,i,itdc)).gt.10000.) tof31(1,i,itdc)= 10000.
334     if (abs(tof31(2,i,itdc)).gt.10000.) tof31(2,i,itdc)= 10000.
335     if (abs(tof31(1,i,iadc)).gt.10000.) tof31(1,i,iadc)= 10000.
336     if (abs(tof31(2,i,iadc)).gt.10000.) tof31(2,i,iadc)= 10000.
337     ENDDO
338    
339     DO i = 1,3
340     if (abs(tof32(1,i,itdc)).gt.10000.) tof32(1,i,itdc)= 10000.
341     if (abs(tof32(2,i,itdc)).gt.10000.) tof32(2,i,itdc)= 10000.
342     if (abs(tof32(1,i,iadc)).gt.10000.) tof32(1,i,iadc)= 10000.
343     if (abs(tof32(2,i,iadc)).gt.10000.) tof32(2,i,iadc)= 10000.
344     ENDDO
345    
346 mocchiut 1.11 C----------------------------------------------------------------------
347 mocchiut 1.8
348     C------read tracking routine
349 mocchiut 1.1 * igoodevent = igoodevent+1
350     * assigned input parameters for track routine
351     * 1) Z-coordinates where the trajectory is evaluated
352     do itof=1,NPTOF
353     ZIN(itof) = ZTOF(itof)
354     enddo
355     * 2) track status vector
356     C COPY THE ALFA VECTOR FROM AL_PP TO AL_P FOR THE TRACK "T"
357     do i=1,5
358     AL_P(i) = al_pp(i)
359     enddo
360 mocchiut 1.20 deflection = AL_P(5)
361     * 3) tracker dEdx
362     dedxtrk = trkmip
363    
364     c write(*,*) AL_P
365     c write(*,*) 'Rig, Def, dEdx ',(1./AL_P(5)),AL_P(5),dedxtrk
366    
367    
368     C-- charge selection with tracker using dedx vs. deflection^2 ----
369    
370     yhelp1 = 3.5 + 4.5*deflection*deflection
371     yhelp2 = 9. + 20.*deflection*deflection
372     c write(*,*) yhelp1,yhelp2
373    
374     iz = 0
375     if (dedxtrk.lt.yhelp1) iz=1
376     if ((dedxtrk.gt.yhelp1).and.(dedxtrk.lt.yhelp2)) iz=2
377     if (dedxtrk.gt.yhelp2) iz=3
378     c write(*,*) 'tracker charge ',iz
379 mocchiut 1.5
380 mocchiut 1.20 C--------------------------------------------------------------------
381 mocchiut 1.5
382 mocchiut 1.1 if (al_p(5).eq.0.) THEN
383 mocchiut 1.14 c PRINT *,' TOF - WARNING F77: track with R = 0, discarded'
384 mocchiut 1.1 GOTO 969
385     ENDIF
386     * -------- *** tracking routine *** --------
387     IFAIL = 0
388 mocchiut 1.8 C call DOTRACK(NPTOF,ZIN,XOUT,YOUT,AL_P,IFAIL)
389 mocchiut 1.5 call DOTRACK2(NPTOF,ZIN,XOUT,YOUT,THXOUT,THYOUT,TLOUT,AL_P,IFAIL)
390    
391 mocchiut 1.8 C write(*,*) (TLOUT(i),i=1,6)
392 mocchiut 1.5
393 mocchiut 1.1 if(IFAIL.ne.0)then
394 mocchiut 1.14 c print *,' TOF - WARNING F77: tracking failed '
395 mocchiut 1.1 goto 969
396     endif
397     * ------------------------------------------
398    
399 mocchiut 1.8 969 continue
400    
401 mocchiut 1.11 C--- Fill xtr_tof and ytr_tof: positions from tracker at ToF layers
402     do j=1,6
403     xtr_tof(j) = XOUT(j)
404 pam-de 1.12 ytr_tof(j) = YOUT(j)
405 pamelats 1.18 c write(*,*) XOUT(j),YOUT(j)
406 mocchiut 1.11 enddo
407    
408    
409 mocchiut 1.9 C--- convert angles to radian
410     do j=1,6
411     THXOUT(j) = 3.1415927*THXOUT(j)/180.
412     THYOUT(j) = 3.1415927*THYOUT(j)/180.
413     enddo
414    
415     do j=1,6
416     c write (*,*) j,THXOUT(j),THYOUT(j)
417     enddo
418    
419 mocchiut 1.8
420     C----------------------------------------------------------------------
421     C------------------ set ADC & TDC flag = 0 ------------------------
422     C----------------------------------------------------------------------
423    
424     do j=1,8
425     if (adc(ch11a(j),hb11a(j)).LT.4096)adcflagtof(ch11a(j),hb11a(j))=0
426     if (adc(ch11b(j),hb11b(j)).LT.4096)adcflagtof(ch11b(j),hb11b(j))=0
427     if (tdc(ch11a(j),hb11a(j)).LT.4096)tdcflagtof(ch11a(j),hb11a(j))=0
428     if (tdc(ch11b(j),hb11b(j)).LT.4096)tdcflagtof(ch11b(j),hb11b(j))=0
429     enddo
430     do j=1,6
431     if (adc(ch12a(j),hb12a(j)).LT.4096)adcflagtof(ch12a(j),hb12a(j))=0
432     if (adc(ch12b(j),hb12b(j)).LT.4096)adcflagtof(ch12b(j),hb12b(j))=0
433     if (tdc(ch12a(j),hb12a(j)).LT.4096)tdcflagtof(ch12a(j),hb12a(j))=0
434     if (tdc(ch12b(j),hb12b(j)).LT.4096)tdcflagtof(ch12b(j),hb12b(j))=0
435     enddo
436     do j=1,2
437     if (adc(ch21a(j),hb21a(j)).LT.4096)adcflagtof(ch21a(j),hb21a(j))=0
438     if (adc(ch21b(j),hb21b(j)).LT.4096)adcflagtof(ch21b(j),hb21b(j))=0
439     if (tdc(ch21a(j),hb21a(j)).LT.4096)tdcflagtof(ch21a(j),hb21a(j))=0
440     if (tdc(ch21b(j),hb21b(j)).LT.4096)tdcflagtof(ch21b(j),hb21b(j))=0
441     enddo
442     do j=1,2
443     if (adc(ch22a(j),hb22a(j)).LT.4096)adcflagtof(ch22a(j),hb22a(j))=0
444     if (adc(ch22b(j),hb22b(j)).LT.4096)adcflagtof(ch22b(j),hb22b(j))=0
445     if (tdc(ch22a(j),hb22a(j)).LT.4096)tdcflagtof(ch22a(j),hb22a(j))=0
446     if (tdc(ch22b(j),hb22b(j)).LT.4096)tdcflagtof(ch22b(j),hb22b(j))=0
447     enddo
448     do j=1,3
449     if (adc(ch31a(j),hb31a(j)).LT.4096)adcflagtof(ch31a(j),hb31a(j))=0
450     if (adc(ch31b(j),hb31b(j)).LT.4096)adcflagtof(ch31b(j),hb31b(j))=0
451     if (tdc(ch31a(j),hb31a(j)).LT.4096)tdcflagtof(ch31a(j),hb31a(j))=0
452     if (tdc(ch31b(j),hb31b(j)).LT.4096)tdcflagtof(ch31b(j),hb31b(j))=0
453     enddo
454     do j=1,3
455     if (adc(ch32a(j),hb32a(j)).LT.4096)adcflagtof(ch32a(j),hb32a(j))=0
456     if (adc(ch32b(j),hb32b(j)).LT.4096)adcflagtof(ch32b(j),hb32b(j))=0
457     if (tdc(ch32a(j),hb32a(j)).LT.4096)tdcflagtof(ch32a(j),hb32a(j))=0
458     if (tdc(ch32b(j),hb32b(j)).LT.4096)tdcflagtof(ch32b(j),hb32b(j))=0
459     enddo
460    
461    
462     C----------------------------------------------------------------
463     C---------- Check PMTs 10 and 35 for strange TDC values----------
464     C----------------------------------------------------------------
465    
466     C---- S116A TDC=819
467     if (tof11(1,6,1).EQ.819) then
468     tof11(1,6,1) = 4095
469     tdcflagtof(ch11a(6),hb11a(6))=2
470     endif
471 pam-de 1.12
472 mocchiut 1.8 C---- S222B TDC=819
473     if (tof22(2,2,1).EQ.819) then
474     tof22(2,2,1) = 4095
475     tdcflagtof(ch22b(2),hb22b(2))=2
476     endif
477 pam-de 1.12
478 mocchiut 1.1 C-------------------------------------------------------------
479 mocchiut 1.8 C-------check which paddle penetrated the track -----------
480 mocchiut 1.1 C-------------------------------------------------------------
481 mocchiut 1.8 c middle y (or x) position of the upper and middle ToF-Paddle
482     c DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/
483     c DATA tof12_y/ -13.75,-8.25,-2.75,2.75,8.25,13.75/
484     c DATA tof21_y/ 3.75,-3.75/ ! paddles in different order
485     c DATA tof22_x/ -4.5,4.5/
486     c DATA tof31_x/ -6.0,0.,6.0/
487     c DATA tof32_y/ -5.0,0.0,5.0/
488 pam-de 1.12 c
489 mocchiut 1.8 c S11 8 paddles 33.0 x 5.1 cm
490     c S12 6 paddles 40.8 x 5.5 cm
491     c S21 2 paddles 18.0 x 7.5 cm
492     c S22 2 paddles 15.0 x 9.0 cm
493     c S31 3 paddles 15.0 x 6.0 cm
494     c S32 3 paddles 18.0 x 5.0 cm
495 mocchiut 1.1
496    
497 mocchiut 1.8 C--------------S11 --------------------------------------
498 mocchiut 1.1
499     tof11_i = none_find
500    
501     yl = -33.0/2.
502     yh = 33.0/2.
503    
504     if ((yout(1).gt.yl).and.(yout(1).lt.yh)) then
505 mocchiut 1.8 do i=1,8
506     xl = tof11_x(i) - 5.1/2.
507     xh = tof11_x(i) + 5.1/2.
508     if ((xout(1).gt.xl).and.(xout(1).le.xh)) then
509     tof11_i=i
510     endif
511     enddo
512 mocchiut 1.1 endif
513    
514 mocchiut 1.8 C--------------S12 --------------------------------------
515 mocchiut 1.1
516     tof12_i = none_find
517 pam-de 1.12
518 mocchiut 1.1 xl = -40.8/2.
519     xh = 40.8/2.
520    
521     if ((xout(2).gt.xl).and.(xout(2).lt.xh)) then
522 mocchiut 1.8 do i=1,6
523     yl = tof12_y(i) - 5.5/2.
524     yh = tof12_y(i) + 5.5/2.
525     if ((yout(2).gt.yl).and.(yout(2).le.yh)) then
526     tof12_i=i
527     endif
528     enddo
529 mocchiut 1.1 endif
530    
531 mocchiut 1.8 C--------------S21 --------------------------------------
532 mocchiut 1.1
533     tof21_i = none_find
534 pam-de 1.12
535 mocchiut 1.1 xl = -18./2.
536     xh = 18./2.
537    
538     if ((xout(3).gt.xl).and.(xout(3).lt.xh)) then
539 mocchiut 1.8 do i=1,2
540     yl = tof21_y(i) - 7.5/2.
541     yh = tof21_y(i) + 7.5/2.
542     if ((yout(3).gt.yl).and.(yout(3).le.yh)) then
543     tof21_i=i
544     endif
545     enddo
546 mocchiut 1.1 endif
547    
548 mocchiut 1.8 C--------------S22 --------------------------------------
549 mocchiut 1.1
550     tof22_i = none_find
551 pam-de 1.12
552 mocchiut 1.1 yl = -15./2.
553     yh = 15./2.
554    
555     if ((yout(4).gt.yl).and.(yout(4).lt.yh)) then
556 mocchiut 1.8 do i=1,2
557     xl = tof22_x(i) - 9.0/2.
558     xh = tof22_x(i) + 9.0/2.
559     if ((xout(4).gt.xl).and.(xout(4).le.xh)) then
560     tof22_i=i
561     endif
562     enddo
563 mocchiut 1.1 endif
564    
565 mocchiut 1.8 C--------------S31 --------------------------------------
566 mocchiut 1.1
567     tof31_i = none_find
568 pam-de 1.12
569 mocchiut 1.1 yl = -15.0/2.
570     yh = 15.0/2.
571    
572     if ((yout(5).gt.yl).and.(yout(5).lt.yh)) then
573 mocchiut 1.8 do i=1,3
574     xl = tof31_x(i) - 6.0/2.
575     xh = tof31_x(i) + 6.0/2.
576     if ((xout(5).gt.xl).and.(xout(5).le.xh)) then
577     tof31_i=i
578     endif
579     enddo
580 mocchiut 1.1 endif
581    
582 mocchiut 1.8 C--------------S32 --------------------------------------
583 mocchiut 1.1
584     tof32_i = none_find
585 pam-de 1.12
586 mocchiut 1.1 xl = -18.0/2.
587     xh = 18.0/2.
588    
589     if ((xout(6).gt.xl).and.(xout(6).lt.xh)) then
590 mocchiut 1.8 do i=1,3
591     yl = tof32_y(i) - 5.0/2.
592     yh = tof32_y(i) + 5.0/2.
593     if ((yout(6).gt.yl).and.(yout(6).le.yh)) then
594     tof32_i=i
595     endif
596     enddo
597 mocchiut 1.1 endif
598    
599 mocchiut 1.5
600 mocchiut 1.8
601 mocchiut 1.15 hitvec(1)=tof11_i
602     hitvec(2)=tof12_i
603     hitvec(3)=tof21_i
604     hitvec(4)=tof22_i
605     hitvec(5)=tof31_i
606     hitvec(6)=tof32_i
607 mocchiut 1.8
608    
609 mocchiut 1.15 C----------------------------------------------------------------------
610     C--- check charge:
611     C--- if Z=2 we should use the attenuation curve for helium to
612     C--- fill the artificail ADC values and NOT divide by "hepratio"
613     C--- if Z>2 we should do a correction to
614     C--- the k1 constants in the beta calculation
615     C----------------------------------------------------------------------
616 mocchiut 1.8
617 mocchiut 1.15 theta=0.
618     dist = ZTOF(1) - ZTOF(5)
619     dl = 0.
620     DO I=1,5
621     dl = dl + TLOUT(i)
622     ENDDO
623     F = dl/dist
624     theta = acos(1/F)
625 mocchiut 1.8
626 mocchiut 1.20 c iz = int(check_charge(theta,hitvec))
627 mocchiut 1.15 c write(*,*) 'in toftrk',iz
628 mocchiut 1.8
629 pamelats 1.18
630     C------------------------------- new ---------------------------
631     C-- calculate track position in paddle using timing difference
632     C-- this calculation is preliminary and uses some standard
633     C-- calibration values, but we need to find a rough position to
634     C-- be able to calculate artificial ADC values (needed for the
635     C-- timewalk...
636     C------------------------------------------------------------------
637    
638     do i=1,3
639     xtofpre(i)=100.
640     ytofpre(i)=100.
641     enddo
642    
643     C-----------------------------S1 --------------------------------
644    
645     IF (tof11_i.GT.none_find) THEN
646     IF ((tof11(1,tof11_i,itdc).LT.2000).AND.
647     + (tof11(2,tof11_i,itdc).LT.2000))
648     + ytofpre(1) = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
649     + -y_coor_lin11c(tof11_i,offset))/y_coor_lin11c(tof11_i,slope)
650     endif
651    
652     IF (tof12_i.GT.none_find) THEN
653     IF ((tof12(1,tof12_i,itdc).LT.2000).AND.
654     + (tof12(2,tof12_i,itdc).LT.2000))
655     + xtofpre(1) = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
656     + -x_coor_lin12c(tof12_i,offset))/x_coor_lin12c(tof12_i,slope)
657     endif
658    
659    
660     C-----------------------------S2 --------------------------------
661    
662     IF (tof21_i.GT.none_find) THEN
663     IF ((tof21(1,tof21_i,itdc).LT.2000).AND.
664     + (tof21(2,tof21_i,itdc).LT.2000))
665     + xtofpre(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
666     + -x_coor_lin21c(tof21_i,offset))/x_coor_lin21c(tof21_i,slope)
667     endif
668    
669     IF (tof22_i.GT.none_find) THEN
670     IF ((tof22(1,tof22_i,itdc).LT.2000).AND.
671     + (tof22(2,tof22_i,itdc).LT.2000))
672     + ytofpre(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
673     + -y_coor_lin22c(tof22_i,offset))/y_coor_lin22c(tof22_i,slope)
674     endif
675    
676    
677     C-----------------------------S3 --------------------------------
678    
679     IF (tof31_i.GT.none_find) THEN
680     IF ((tof31(1,tof31_i,itdc).LT.2000).AND.
681     + (tof31(2,tof31_i,itdc).LT.2000))
682     + ytofpre(3) = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
683     + -y_coor_lin31c(tof31_i,offset))/y_coor_lin31c(tof31_i,slope)
684     endif
685    
686     IF (tof32_i.GT.none_find) THEN
687     IF ((tof32(1,tof32_i,itdc).LT.2000).AND.
688     + (tof32(2,tof32_i,itdc).LT.2000))
689     + xtofpre(3) = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
690     + -x_coor_lin32c(tof32_i,offset))/x_coor_lin32c(tof32_i,slope)
691     endif
692    
693    
694     C-- restrict TDC measurements to physical paddle dimensions +/- 10 cm
695    
696     if (abs(xtofpre(1)).gt.31.) xtofpre(1)=100.
697     if (abs(xtofpre(2)).gt.19.) xtofpre(2)=100.
698     if (abs(xtofpre(3)).gt.19.) xtofpre(3)=100.
699    
700     if (abs(ytofpre(1)).gt.26.) ytofpre(1)=100.
701     if (abs(ytofpre(2)).gt.18.) ytofpre(2)=100.
702     if (abs(ytofpre(3)).gt.18.) ytofpre(3)=100.
703    
704 mocchiut 1.8 C--------------------------------------------------------------------
705 pam-de 1.12 C---- if paddle hit: if we have TDC value but no ADC, create ADC value
706 pamelats 1.18 C---- use the "pre" position if possible, since this gives better time
707     C---- resolution ... october 2008
708 mocchiut 1.8 C--------------------------------------------------------------------
709     c middle y (or x) position of the upper and middle ToF-Paddle
710     c DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/
711     c DATA tof12_y/ -13.75,-8.25,-2.75,2.75,8.25,13.75/
712     c DATA tof21_y/ 3.75,-3.75/ ! paddles in different order
713     c DATA tof22_x/ -4.5,4.5/
714     c DATA tof31_x/ -6.0,0.,6.0/
715     c DATA tof32_y/ -5.0,0.0,5.0/
716    
717     C----------------------------S1 -------------------------------------
718    
719 pamelats 1.18 c yhelp=yout(1)
720     yhelp = ytofpre(1)
721     if (yhelp.eq.100) yhelp=yout(1)
722    
723     IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
724 mocchiut 1.8 i = tof11_i
725 mocchiut 1.15 if ((tdc(ch11a(i),hb11a(i)).lt.4095).AND.
726 pam-de 1.12 & (adc(ch11a(i),hb11a(i)).eq.4095)) then
727 mocchiut 1.9 phi = atan(tan(THYOUT(1))/tan(THXOUT(1)))
728 mocchiut 1.8 theta = atan(tan(THXOUT(1))/cos(phi))
729 mocchiut 1.11 xkorr = atten(left,11,i,yhelp)
730 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
731 mocchiut 1.8 tof11(left,i,iadc)=xkorr/cos(theta)
732     adcflag(ch11a(i),hb11a(i)) = 1
733     endif
734 mocchiut 1.15 if ((tdc(ch11b(i),hb11b(i)).lt.4095).AND.
735 pam-de 1.12 & (adc(ch11b(i),hb11b(i)).eq.4095)) then
736 mocchiut 1.9 phi = atan(tan(THYOUT(1))/tan(THXOUT(1)))
737 mocchiut 1.8 theta = atan(tan(THXOUT(1))/cos(phi))
738 mocchiut 1.11 xkorr = atten(right,11,i,yhelp)
739 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
740 mocchiut 1.8 tof11(right,i,iadc)=xkorr/cos(theta)
741     adcflag(ch11b(i),hb11b(i)) = 1
742     endif
743     ENDIF
744    
745 pamelats 1.18 c xhelp=xout(2)
746     xhelp = xtofpre(1)
747     if (xhelp.eq.100) xhelp=xout(2)
748    
749     IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
750 mocchiut 1.8 i = tof12_i
751 mocchiut 1.15 if ((tdc(ch12a(i),hb12a(i)).lt.4095).AND.
752 pam-de 1.12 & (adc(ch12a(i),hb12a(i)).eq.4095)) then
753 mocchiut 1.9 phi = atan(tan(THYOUT(2))/tan(THXOUT(2)))
754 mocchiut 1.8 theta = atan(tan(THXOUT(2))/cos(phi))
755 mocchiut 1.11 c xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))
756     xkorr = atten(left,12,i,xhelp)
757 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
758 mocchiut 1.8 tof12(left,i,iadc) = xkorr/cos(theta)
759     adcflag(ch12a(i),hb12a(i)) = 1
760     endif
761 mocchiut 1.15 if ((tdc(ch12b(i),hb12b(i)).lt.4095).AND.
762 pam-de 1.12 & (adc(ch12b(i),hb12b(i)).eq.4095)) then
763 mocchiut 1.9 phi = atan(tan(THYOUT(2))/tan(THXOUT(2)))
764 mocchiut 1.8 theta = atan(tan(THXOUT(2))/cos(phi))
765 mocchiut 1.11 c xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))
766     xkorr = atten(right,12,i,xhelp)
767 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
768 mocchiut 1.8 tof12(right,i,iadc) = xkorr/cos(theta)
769     adcflag(ch12b(i),hb12b(i)) = 1
770     endif
771     ENDIF
772    
773     C-----------------------------S2 --------------------------------
774    
775 pamelats 1.18 c xhelp=xout(3)
776     xhelp = xtofpre(2)
777     if (xhelp.eq.100) xhelp=xout(3)
778    
779     IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
780 mocchiut 1.8 i = tof21_i
781 mocchiut 1.15 if ((tdc(ch21a(i),hb21a(i)).lt.4095).AND.
782 pam-de 1.12 & (adc(ch21a(i),hb21a(i)).eq.4095)) then
783 mocchiut 1.9 phi = atan(tan(THYOUT(3))/tan(THXOUT(3)))
784 mocchiut 1.8 theta = atan(tan(THXOUT(3))/cos(phi))
785 mocchiut 1.11 c xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))
786     xkorr = atten(left,21,i,xhelp)
787 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
788 mocchiut 1.8 tof21(left,i,iadc) = xkorr/cos(theta)
789     adcflag(ch21a(i),hb21a(i)) = 1
790     endif
791 mocchiut 1.15 if ((tdc(ch21b(i),hb21b(i)).lt.4095).AND.
792 pam-de 1.12 & (adc(ch21b(i),hb21b(i)).eq.4095)) then
793 mocchiut 1.9 phi = atan(tan(THYOUT(3))/tan(THXOUT(3)))
794 mocchiut 1.8 theta = atan(tan(THXOUT(3))/cos(phi))
795 mocchiut 1.11 c xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))
796     xkorr = atten(right,21,i,xhelp)
797 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
798 mocchiut 1.8 tof21(right,i,iadc) = xkorr/cos(theta)
799     adcflag(ch21b(i),hb21b(i)) = 1
800     endif
801     ENDIF
802    
803    
804 pamelats 1.18 c yhelp=yout(4)
805     yhelp = ytofpre(2)
806     if (yhelp.eq.100) yhelp=yout(4)
807    
808     IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
809 mocchiut 1.8 i = tof22_i
810 mocchiut 1.15 if ((tdc(ch22a(i),hb22a(i)).lt.4095).AND.
811 pam-de 1.12 & (adc(ch22a(i),hb22a(i)).eq.4095)) then
812 mocchiut 1.9 phi = atan(tan(THYOUT(4))/tan(THXOUT(4)))
813 mocchiut 1.8 theta = atan(tan(THXOUT(4))/cos(phi))
814 mocchiut 1.11 c xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))
815     xkorr = atten(left,22,i,yhelp)
816 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
817 mocchiut 1.8 tof22(left,i,iadc) = xkorr/cos(theta)
818     adcflag(ch22a(i),hb22a(i)) = 1
819     endif
820 mocchiut 1.17 if ((tdc(ch22b(i),hb22b(i)).lt.4095).AND.
821 pam-de 1.12 & (adc(ch22b(i),hb22b(i)).eq.4095)) then
822 mocchiut 1.9 phi = atan(tan(THYOUT(4))/tan(THXOUT(4)))
823 mocchiut 1.8 theta = atan(tan(THXOUT(4))/cos(phi))
824 mocchiut 1.11 c xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))
825     xkorr = atten(right,22,i,yhelp)
826 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
827 mocchiut 1.8 tof22(right,i,iadc) = xkorr/cos(theta)
828     adcflag(ch22b(i),hb22b(i)) = 1
829     endif
830     ENDIF
831    
832     C-----------------------------S3 --------------------------------
833    
834 pamelats 1.18 c yhelp=yout(5)
835     yhelp = ytofpre(3)
836     if (yhelp.eq.100) yhelp=yout(5)
837    
838     IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
839 mocchiut 1.8 i = tof31_i
840 mocchiut 1.15 if ((tdc(ch31a(i),hb31a(i)).lt.4095).AND.
841 pam-de 1.12 & (adc(ch31a(i),hb31a(i)).eq.4095)) then
842 mocchiut 1.9 phi = atan(tan(THYOUT(5))/tan(THXOUT(5)))
843 mocchiut 1.8 theta = atan(tan(THXOUT(5))/cos(phi))
844 mocchiut 1.11 c xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))
845     xkorr = atten(left,31,i,yhelp)
846 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
847 mocchiut 1.8 tof31(left,i,iadc) = xkorr/cos(theta)
848     adcflag(ch31a(i),hb31a(i)) = 1
849     endif
850 mocchiut 1.15 if ((tdc(ch31b(i),hb31b(i)).lt.4095).AND.
851 pam-de 1.12 & (adc(ch31b(i),hb31b(i)).eq.4095)) then
852 mocchiut 1.9 phi = atan(tan(THYOUT(5))/tan(THXOUT(5)))
853 mocchiut 1.8 theta = atan(tan(THXOUT(5))/cos(phi))
854 mocchiut 1.11 c xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))
855     xkorr = atten(right,31,i,yhelp)
856 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
857 mocchiut 1.8 tof31(right,i,iadc) = xkorr/cos(theta)
858     adcflag(ch31b(i),hb31b(i)) = 1
859     endif
860     ENDIF
861    
862    
863 pamelats 1.18 c xhelp=xout(6)
864     xhelp = xtofpre(3)
865     if (xhelp.eq.100) xhelp=xout(6)
866    
867 mocchiut 1.8 IF (tof32_i.GT.none_find.AND.abs(xout(6)).lt.100) THEN
868     i = tof32_i
869 mocchiut 1.15 if ((tdc(ch32a(i),hb32a(i)).lt.4095).AND.
870 pam-de 1.12 & (adc(ch32a(i),hb32a(i)).eq.4095)) then
871 mocchiut 1.9 phi = atan(tan(THYOUT(6))/tan(THXOUT(6)))
872 mocchiut 1.8 theta = atan(tan(THXOUT(6))/cos(phi))
873 mocchiut 1.11 c xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))
874     xkorr = atten(left,32,i,xhelp)
875 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
876 mocchiut 1.8 tof32(left,i,iadc) = xkorr/cos(theta)
877     adcflag(ch32a(i),hb32a(i)) = 1
878     endif
879 mocchiut 1.15 if ((tdc(ch32b(i),hb32b(i)).lt.4095).AND.
880 pam-de 1.12 & (adc(ch32b(i),hb32b(i)).eq.4095)) then
881 mocchiut 1.9 phi = atan(tan(THYOUT(6))/tan(THXOUT(6)))
882 mocchiut 1.8 theta = atan(tan(THXOUT(6))/cos(phi))
883 mocchiut 1.11 c xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))
884     xkorr = atten(right,32,i,xhelp)
885 mocchiut 1.15 if (iz.le.1) xkorr=xkorr/hepratio
886 mocchiut 1.8 tof32(right,i,iadc) = xkorr/cos(theta)
887     adcflag(ch32b(i),hb32b(i)) = 1
888     endif
889     ENDIF
890    
891 mocchiut 1.15 C-------------------------------------------------------------------
892     C Now there is for each hitted paddle a TDC and ADC value, if the
893     C TDC was < 4095.
894     C There might be also TDC-ADC pairs in paddles not hitted
895     C Let's correct the raw TDC value with the time walk
896     C-------------------------------------------------------------------
897     C--------------------Time walk correction -------------------------
898     C-------------------------------------------------------------------
899    
900     DO i=1,8
901     if ((tdc(ch11a(i),hb11a(i)).lt.4095).and.
902     & (tof11(left,i,iadc).lt.3786)) THEN
903     xhelp = tw11(left,i)/(tof11(left,i,iadc)**0.5)
904     tof11(left,i,itdc) = tof11(left,i,itdc) + xhelp
905     tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)
906     ENDIF
907    
908     if ((tdc(ch11b(i),hb11b(i)).lt.4095).and.
909     & (tof11(right,i,iadc).lt.3786)) THEN
910     xhelp = tw11(right,i)/(tof11(right,i,iadc)**0.5)
911     tof11(right,i,itdc) = tof11(right,i,itdc) + xhelp
912     tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)
913     ENDIF
914     ENDDO
915    
916    
917     DO i=1,6
918     if ((tdc(ch12a(i),hb12a(i)).lt.4095).and.
919     & (tof12(left,i,iadc).lt.3786)) THEN
920     xhelp = tw12(left,i)/(tof12(left,i,iadc)**0.5)
921     tof12(left,i,itdc) = tof12(left,i,itdc) + xhelp
922     tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)
923     ENDIF
924    
925     if ((tdc(ch12b(i),hb12b(i)).lt.4095).and.
926     & (tof12(right,i,iadc).lt.3786)) THEN
927     xhelp = tw12(right,i)/(tof12(right,i,iadc)**0.5)
928     tof12(right,i,itdc) = tof12(right,i,itdc) + xhelp
929     tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)
930     ENDIF
931     ENDDO
932    
933     C----
934     DO I=1,2
935     if ((tdc(ch21a(i),hb21a(i)).lt.4095).and.
936     & (tof21(left,i,iadc).lt.3786)) THEN
937     xhelp = tw21(left,i)/(tof21(left,i,iadc)**0.5)
938     tof21(left,i,itdc) = tof21(left,i,itdc) + xhelp
939     tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)
940     ENDIF
941    
942     if ((tdc(ch21b(i),hb21b(i)).lt.4095).and.
943     & (tof21(right,i,iadc).lt.3786)) THEN
944     xhelp = tw21(right,i)/(tof21(right,i,iadc)**0.5)
945     tof21(right,i,itdc) = tof21(right,i,itdc) + xhelp
946     tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)
947     ENDIF
948     ENDDO
949    
950     DO I=1,2
951     if ((tdc(ch22a(i),hb22a(i)).lt.4095).and.
952     & (tof22(left,i,iadc).lt.3786)) THEN
953     xhelp = tw22(left,i)/(tof22(left,i,iadc)**0.5)
954     tof22(left,i,itdc) = tof22(left,i,itdc) + xhelp
955     tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)
956     ENDIF
957    
958     if ((tdc(ch22b(i),hb22b(i)).lt.4095).and.
959     & (tof22(right,i,iadc).lt.3786)) THEN
960     xhelp = tw22(right,i)/(tof22(right,i,iadc)**0.5)
961     tof22(right,i,itdc) = tof22(right,i,itdc) + xhelp
962     tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)
963     ENDIF
964     ENDDO
965    
966     C----
967     DO I=1,3
968     if ((tdc(ch31a(i),hb31a(i)).lt.4095).and.
969     & (tof31(left,i,iadc).lt.3786)) THEN
970     xhelp = tw31(left,i)/(tof31(left,i,iadc)**0.5)
971     tof31(left,i,itdc) = tof31(left,i,itdc) + xhelp
972     tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)
973     ENDIF
974    
975     if ((tdc(ch31b(i),hb31b(i)).lt.4095).and.
976     & (tof31(right,i,iadc).lt.3786)) THEN
977     xhelp = tw31(right,i)/(tof31(right,i,iadc)**0.5)
978     tof31(right,i,itdc) = tof31(right,i,itdc) + xhelp
979     tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)
980     ENDIF
981     ENDDO
982    
983     DO I=1,3
984     if ((tdc(ch32a(i),hb32a(i)).lt.4095).and.
985     & (tof32(left,i,iadc).lt.3786)) THEN
986     xhelp = tw32(left,i)/(tof32(left,i,iadc)**0.5)
987     tof32(left,i,itdc) = tof32(left,i,itdc) + xhelp
988     tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)
989     ENDIF
990    
991     if ((tdc(ch32b(i),hb32b(i)).lt.4095).and.
992     & (tof32(right,i,iadc).lt.3786)) THEN
993     xhelp = tw32(right,i)/(tof32(right,i,iadc)**0.5)
994     tof32(right,i,itdc) = tof32(right,i,itdc) + xhelp
995     tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)
996     ENDIF
997     ENDDO
998    
999    
1000     C-----------------------------------------------------------------------
1001     C--------------------Insert Artifical TDC Value ---------------------
1002     C For each Paddle perform check:
1003     C if left paddle=4095 and right paddle OK => create TDC value left
1004     C if right paddle=4095 and left paddle OK => create TDC value right
1005     C-----------------------------------------------------------------------
1006    
1007     C-----------------------S11 -----------------------------------------
1008    
1009     IF (tof11_i.GT.none_find) THEN
1010     xpos = yout(1)
1011     i = tof11_i
1012     if ((tdc(ch11a(i),hb11a(i)).EQ.4095).AND.
1013     & (tdc(ch11b(i),hb11b(i)).LT.4095)) THEN
1014     tof11(1,tof11_i,itdc) = tof11(2,tof11_i,itdc)
1015     & + 2*(y_coor_lin11(tof11_i,offset)
1016     & + xpos*y_coor_lin11(tof11_i,slope))
1017     tdcflag(ch11a(i),hb11a(i)) = 1
1018     ENDIF
1019    
1020     if ((tdc(ch11b(i),hb11b(i)).EQ.4095).AND.
1021     & (tdc(ch11a(i),hb11a(i)).LT.4095)) THEN
1022     tof11(2,tof11_i,itdc) = tof11(1,tof11_i,itdc)
1023     & - 2*(y_coor_lin11(tof11_i,offset)
1024     & + xpos*y_coor_lin11(tof11_i,slope))
1025     tdcflag(ch11b(i),hb11b(i)) = 1
1026     ENDIF
1027    
1028     ENDIF
1029    
1030     C-----------------------S12 -----------------------------------------
1031    
1032     IF (tof12_i.GT.none_find) THEN
1033     xpos = xout(2)
1034     i = tof12_i
1035     if ((tdc(ch12a(i),hb12a(i)).EQ.4095).AND.
1036     & (tdc(ch12b(i),hb12b(i)).LT.4095)) THEN
1037     tof12(1,tof12_i,itdc) = tof12(2,tof12_i,itdc)
1038     & + 2*(x_coor_lin12(tof12_i,offset)
1039     & + xpos*x_coor_lin12(tof12_i,slope))
1040     tdcflag(ch12a(i),hb12a(i)) = 1
1041     ENDIF
1042    
1043     if ((tdc(ch12b(i),hb12b(i)).EQ.4095).AND.
1044     & (tdc(ch12a(i),hb12a(i)).LT.4095)) THEN
1045     tof12(2,tof12_i,itdc) = tof12(1,tof12_i,itdc)
1046     & - 2*(x_coor_lin12(tof12_i,offset)
1047     & + xpos*x_coor_lin12(tof12_i,slope))
1048     tdcflag(ch12b(i),hb12b(i)) = 1
1049     ENDIF
1050     ENDIF
1051    
1052     C-----------------------S21 -----------------------------------------
1053    
1054     IF (tof21_i.GT.none_find) THEN
1055     xpos = xout(3)
1056     i = tof21_i
1057     if ((tdc(ch21a(i),hb21a(i)).EQ.4095).AND.
1058     & (tdc(ch21b(i),hb21b(i)).LT.4095)) THEN
1059     tof21(1,tof21_i,itdc) = tof21(2,tof21_i,itdc)
1060     & + 2*(x_coor_lin21(tof21_i,offset)
1061     & + xpos*x_coor_lin21(tof21_i,slope))
1062     tdcflag(ch21a(i),hb21a(i)) = 1
1063     ENDIF
1064    
1065     if ((tdc(ch21b(i),hb21b(i)).EQ.4095).AND.
1066     & (tdc(ch21a(i),hb21a(i)).LT.4095)) THEN
1067     tof21(2,tof21_i,itdc) = tof21(1,tof21_i,itdc)
1068     & - 2*(x_coor_lin21(tof21_i,offset)
1069     & + xpos*x_coor_lin21(tof21_i,slope))
1070     tdcflag(ch21b(i),hb21b(i)) = 1
1071     ENDIF
1072     ENDIF
1073    
1074     C-----------------------S22 -----------------------------------------
1075    
1076     IF (tof22_i.GT.none_find) THEN
1077     xpos = yout(4)
1078     i = tof22_i
1079     if ((tdc(ch22a(i),hb22a(i)).EQ.4095).AND.
1080     & (tdc(ch22b(i),hb22b(i)).LT.4095)) THEN
1081     tof22(1,tof22_i,itdc) = tof22(2,tof22_i,itdc)
1082     & + 2*(y_coor_lin22(tof22_i,offset)
1083     & + xpos*y_coor_lin22(tof22_i,slope))
1084     tdcflag(ch22a(i),hb22a(i)) = 1
1085     ENDIF
1086    
1087     if ((tdc(ch22b(i),hb22b(i)).EQ.4095).AND.
1088     & (tdc(ch22a(i),hb22a(i)).LT.4095)) THEN
1089     tof22(2,tof22_i,itdc) = tof22(1,tof22_i,itdc)
1090     & - 2*(y_coor_lin22(tof22_i,offset)
1091     & + xpos*y_coor_lin22(tof22_i,slope))
1092     tdcflag(ch22b(i),hb22b(i)) = 1
1093     ENDIF
1094     ENDIF
1095    
1096     C-----------------------S31 -----------------------------------------
1097    
1098     IF (tof31_i.GT.none_find) THEN
1099     xpos = yout(5)
1100     i = tof31_i
1101     if ((tdc(ch31a(i),hb31a(i)).EQ.4095).AND.
1102     & (tdc(ch31b(i),hb31b(i)).LT.4095)) THEN
1103     tof31(1,tof31_i,itdc) = tof31(2,tof31_i,itdc)
1104     & + 2*(y_coor_lin31(tof31_i,offset)
1105     & + xpos*y_coor_lin31(tof31_i,slope))
1106     tdcflag(ch31a(i),hb31a(i)) = 1
1107     ENDIF
1108    
1109     if ((tdc(ch31b(i),hb31b(i)).EQ.4095).AND.
1110     & (tdc(ch31a(i),hb31a(i)).LT.4095)) THEN
1111     tof31(2,tof31_i,itdc) = tof31(1,tof31_i,itdc)
1112     & - 2*(y_coor_lin31(tof31_i,offset)
1113     & + xpos*y_coor_lin31(tof31_i,slope))
1114     tdcflag(ch31b(i),hb31b(i)) = 1
1115     ENDIF
1116     ENDIF
1117    
1118     C-----------------------S32 -----------------------------------------
1119    
1120     IF (tof32_i.GT.none_find) THEN
1121     xpos = xout(6)
1122     i = tof32_i
1123     if ((tdc(ch32a(i),hb32a(i)).EQ.4095).AND.
1124     & (tdc(ch32b(i),hb32b(i)).LT.4095)) THEN
1125     tof32(1,tof32_i,itdc) = tof32(2,tof32_i,itdc)
1126     & + 2*(x_coor_lin32(tof32_i,offset)
1127     & + xpos*x_coor_lin32(tof32_i,slope))
1128     tdcflag(ch32a(i),hb32a(i)) = 1
1129     ENDIF
1130    
1131     if ((tdc(ch32b(i),hb32b(i)).EQ.4095).AND.
1132     & (tdc(ch32a(i),hb32a(i)).LT.4095)) THEN
1133     tof32(2,tof32_i,itdc) = tof32(1,tof32_i,itdc)
1134     & - 2*(x_coor_lin32(tof32_i,offset)
1135     & + xpos*x_coor_lin32(tof32_i,slope))
1136     tdcflag(ch32b(i),hb32b(i)) = 1
1137     ENDIF
1138     ENDIF
1139    
1140 mocchiut 1.5
1141 mocchiut 1.2 C------------------------------------------------------------------
1142     C--- calculate track position in paddle using timing difference
1143     C------------------------------------------------------------------
1144    
1145     do i=1,3
1146     xtofpos(i)=100.
1147     ytofpos(i)=100.
1148 pam-de 1.12 enddo
1149 mocchiut 1.15
1150 mocchiut 1.2 C-----------------------------S1 --------------------------------
1151 pam-de 1.12
1152 mocchiut 1.2 IF (tof11_i.GT.none_find) THEN
1153 mocchiut 1.8 IF ((tof11(1,tof11_i,itdc).NE.4095).AND.
1154     & (tof11(2,tof11_i,itdc).NE.4095)) THEN
1155 mocchiut 1.2 ytofpos(1) = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
1156     + -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)
1157 mocchiut 1.8 if (abs(ytofpos(1)).gt.26.) ytofpos(1)=101.
1158 pamelats 1.18 i=tof11_i
1159 mocchiut 1.8 endif
1160 mocchiut 1.2 endif
1161    
1162     IF (tof12_i.GT.none_find) THEN
1163 mocchiut 1.8 IF ((tof12(1,tof12_i,itdc).NE.4095).AND.
1164     & (tof12(2,tof12_i,itdc).NE.4095)) THEN
1165 mocchiut 1.2 xtofpos(1) = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
1166     + -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)
1167 mocchiut 1.8 if (abs(xtofpos(1)).gt.31.) xtofpos(1)=101.
1168 pamelats 1.18 i=tof12_i
1169 mocchiut 1.2 endif
1170 pam-de 1.12 endif
1171    
1172 mocchiut 1.2 C-----------------------------S2 --------------------------------
1173 pam-de 1.12
1174 mocchiut 1.2 IF (tof21_i.GT.none_find) THEN
1175 mocchiut 1.8 IF ((tof21(1,tof21_i,itdc).NE.4095).AND.
1176     & (tof21(2,tof21_i,itdc).NE.4095)) THEN
1177 mocchiut 1.2 xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
1178     + -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)
1179 pam-de 1.12 if (abs(xtofpos(2)).gt.19.) xtofpos(2)=101.
1180 pamelats 1.18 i=tof21_i
1181 mocchiut 1.8 endif
1182 mocchiut 1.2 endif
1183 mocchiut 1.8
1184 mocchiut 1.2 IF (tof22_i.GT.none_find) THEN
1185 mocchiut 1.8 IF ((tof22(1,tof22_i,itdc).NE.4095).AND.
1186     & (tof22(2,tof22_i,itdc).NE.4095)) THEN
1187 mocchiut 1.2 ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
1188     + -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)
1189 mocchiut 1.8 if (abs(ytofpos(2)).gt.18.) ytofpos(2)=101.
1190 pamelats 1.18 i=tof22_i
1191 mocchiut 1.2 endif
1192 pam-de 1.12 endif
1193    
1194 mocchiut 1.2 C-----------------------------S3 --------------------------------
1195 pam-de 1.12
1196 mocchiut 1.2 IF (tof31_i.GT.none_find) THEN
1197 mocchiut 1.8 IF ((tof31(1,tof31_i,itdc).NE.4095).AND.
1198     & (tof31(2,tof31_i,itdc).NE.4095)) THEN
1199 mocchiut 1.2 ytofpos(3) = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
1200     + -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)
1201 mocchiut 1.8 if (abs(ytofpos(3)).gt.18.) ytofpos(3)=101.
1202 pamelats 1.18 i=tof31_i
1203 mocchiut 1.8 endif
1204 mocchiut 1.2 endif
1205 mocchiut 1.8
1206 mocchiut 1.2 IF (tof32_i.GT.none_find) THEN
1207 mocchiut 1.8 IF ((tof32(1,tof32_i,itdc).NE.4095).AND.
1208     & (tof32(2,tof32_i,itdc).NE.4095)) THEN
1209 mocchiut 1.2 xtofpos(3) = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
1210     + -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)
1211 mocchiut 1.8 if (abs(xtofpos(3)).gt.19.) xtofpos(3)=101.
1212 pamelats 1.18 i=tof32_i
1213 mocchiut 1.2 endif
1214 pam-de 1.12 endif
1215    
1216 mocchiut 1.8 c do i=1,3
1217     c if (abs(xtofpos(i)).gt.100.) then
1218     c xtofpos(i)=101.
1219     c endif
1220     c if (abs(ytofpos(i)).gt.100.) then
1221     c ytofpos(i)=101.
1222     c endif
1223 pam-de 1.12 c enddo
1224    
1225 mocchiut 1.8
1226    
1227 mocchiut 1.19 C--------------------------------------------------------------------
1228     C-------------------Corrections on ADC-data -------------------------
1229 mocchiut 1.8 C-----------------angle and ADC(x) correction -----------------------
1230 mocchiut 1.19 C---------------- moved to the new dEdx routine -------------------
1231 mocchiut 1.1
1232 mocchiut 1.19 C--------------------------------------------------------------------
1233 mocchiut 1.1 C----------------------calculate Beta ------------------------------
1234 mocchiut 1.19 C--------------------------------------------------------------------
1235     C---------------------difference of sums ---------------------------
1236 pam-de 1.12 C
1237 mocchiut 1.1 C DS = (t1+t2) - t3+t4)
1238     C DS = c1 + c2/beta*cos(theta)
1239     C c2 = 2d/c gives c2 = 2d/(c*TDCresolution) TDC=50ps/channel
1240     C => c2 = ca.60 for 0.45 m c2 = ca.109 for 0.81 m
1241     C since TDC resolution varies slightly c2 has to be calibrated
1242 mocchiut 1.5 C instead of cos(theta) use factor F:
1243 pam-de 1.12 C F = pathlength/d
1244 mocchiut 1.5 C => beta = c2*F/(DS-c1))
1245    
1246 mocchiut 1.20 C--------------------- S11 - S31 ------------------------
1247    
1248 mocchiut 1.8 dist = ZTOF(1) - ZTOF(5)
1249     dl = 0.
1250     DO I=1,5
1251     dl = dl + TLOUT(i)
1252     ENDDO
1253 pam-de 1.12 F = dl/dist
1254 mocchiut 1.1
1255 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1256    
1257 mocchiut 1.8 C IF (tof11_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1258     IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1259     & (ytofpos(1).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1260 mocchiut 1.5 t1 = tof11(1,tof11_i,itdc)
1261     t2 = tof11(2,tof11_i,itdc)
1262     t3 = tof31(1,tof31_i,itdc)
1263     t4 = tof31(2,tof31_i,itdc)
1264 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1265     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1266 mocchiut 1.8 xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1267     xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1268     ds = xhelp1-xhelp2
1269     ihelp=(tof11_i-1)*3+tof31_i
1270 mocchiut 1.20 if (iz.le.1) c1 = k_S11S31(1,ihelp)
1271     if (iz.eq.2) c1 = k_S11S31(2,ihelp)
1272     if (iz.gt.2) c1 = k_S11S31(3,ihelp)
1273     c write(*,*)k_S11S31(1,ihelp),k_S11S31(2,ihelp),k_S11S31(3,ihelp)
1274     c write(*,*)iz,c1,c2
1275 mocchiut 1.8 beta_a(1) = c2*F/(ds-c1)
1276 mocchiut 1.13 c write(*,*) 'S11-S31 ',c1,c2,F
1277     c write(*,*) 'S11-S31 ',xhelp1,xhelp2, beta_a(1)
1278 mocchiut 1.8 C-------ToF Mask - S11 - S31
1279    
1280     tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
1281     $ tofmask(ch11a(tof11_i),hb11a(tof11_i)) + 1
1282     tofmask(ch11b(tof11_i),hb11b(tof11_i)) =
1283     $ tofmask(ch11b(tof11_i),hb11b(tof11_i)) + 1
1284    
1285     tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1286     $ tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1287 pam-de 1.12 tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1288 mocchiut 1.8 $ tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1289    
1290     ENDIF
1291     ENDIF
1292    
1293 mocchiut 1.20 C--------------------- S11 - S32 ------------------------
1294    
1295 mocchiut 1.8 dist = ZTOF(1) - ZTOF(6)
1296     dl = 0.
1297     DO I=1,6
1298     dl = dl + TLOUT(i)
1299     ENDDO
1300 pam-de 1.12 F = dl/dist
1301    
1302 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1303    
1304 mocchiut 1.8 C IF (tof11_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1305     IF ((tof11_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1306     & (ytofpos(1).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1307 mocchiut 1.5 t1 = tof11(1,tof11_i,itdc)
1308     t2 = tof11(2,tof11_i,itdc)
1309     t3 = tof32(1,tof32_i,itdc)
1310     t4 = tof32(2,tof32_i,itdc)
1311 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1312     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1313 mocchiut 1.8 xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1314     xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1315     ds = xhelp1-xhelp2
1316     ihelp=(tof11_i-1)*3+tof32_i
1317 mocchiut 1.20 if (iz.le.1) c1 = k_S11S32(1,ihelp)
1318     if (iz.eq.2) c1 = k_S11S32(2,ihelp)
1319     if (iz.gt.2) c1 = k_S11S32(3,ihelp)
1320 mocchiut 1.8 beta_a(2) = c2*F/(ds-c1)
1321     C write(*,*) 'S11-S32 ',xhelp1,xhelp2, beta_a(2)
1322    
1323     C-------ToF Mask - S11 - S32
1324    
1325     tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
1326     $ tofmask(ch11a(tof11_i),hb11a(tof11_i)) + 1
1327     tofmask(ch11b(tof11_i),hb11b(tof11_i)) =
1328     $ tofmask(ch11b(tof11_i),hb11b(tof11_i)) + 1
1329    
1330     tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1331     $ tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1332 pam-de 1.12 tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1333 mocchiut 1.8 $ tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1334 mocchiut 1.2
1335 mocchiut 1.8 C-------
1336 mocchiut 1.2
1337 mocchiut 1.8 ENDIF
1338 mocchiut 1.5 ENDIF
1339 mocchiut 1.1
1340 mocchiut 1.20 C--------------------- S12 - S31 ------------------------
1341    
1342 mocchiut 1.8 dist = ZTOF(2) - ZTOF(5)
1343     dl = 0.
1344     DO I=2,5
1345     dl = dl + TLOUT(i)
1346     ENDDO
1347 pam-de 1.12 F = dl/dist
1348 mocchiut 1.8
1349 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1350    
1351 mocchiut 1.8 C IF (tof12_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1352     IF ((tof12_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1353     & (xtofpos(1).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1354 mocchiut 1.5 t1 = tof12(1,tof12_i,itdc)
1355     t2 = tof12(2,tof12_i,itdc)
1356     t3 = tof31(1,tof31_i,itdc)
1357     t4 = tof31(2,tof31_i,itdc)
1358 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1359     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1360 mocchiut 1.8 xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1361     xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1362     ds = xhelp1-xhelp2
1363     ihelp=(tof12_i-1)*3+tof31_i
1364 mocchiut 1.20 if (iz.le.1) c1 = k_S12S31(1,ihelp)
1365     if (iz.eq.2) c1 = k_S12S31(2,ihelp)
1366     if (iz.gt.2) c1 = k_S12S31(3,ihelp)
1367 mocchiut 1.8 beta_a(3) = c2*F/(ds-c1)
1368     C write(*,*) 'S12-S31 ',xhelp1,xhelp2, beta_a(3)
1369    
1370     C-------ToF Mask - S12 - S31
1371    
1372     tofmask(ch12a(tof12_i),hb12a(tof12_i)) =
1373     $ tofmask(ch12a(tof12_i),hb12a(tof12_i)) + 1
1374     tofmask(ch12b(tof12_i),hb12b(tof12_i)) =
1375     $ tofmask(ch12b(tof12_i),hb12b(tof12_i)) + 1
1376    
1377     tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1378     $ tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1379 pam-de 1.12 tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1380 mocchiut 1.8 $ tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1381 mocchiut 1.2
1382 mocchiut 1.8 C-------
1383 mocchiut 1.2
1384 mocchiut 1.8 ENDIF
1385 mocchiut 1.5 ENDIF
1386 mocchiut 1.1
1387 mocchiut 1.20 C--------------------- S12 - S32 ------------------------
1388 mocchiut 1.5
1389 mocchiut 1.8 dist = ZTOF(2) - ZTOF(6)
1390     dl = 0.
1391     DO I=2,6
1392     dl = dl + TLOUT(i)
1393     ENDDO
1394 pam-de 1.12 F = dl/dist
1395 mocchiut 1.20
1396     c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1397 mocchiut 1.8
1398     C IF (tof12_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1399     IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1400     & (xtofpos(1).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1401 mocchiut 1.5 t1 = tof12(1,tof12_i,itdc)
1402     t2 = tof12(2,tof12_i,itdc)
1403     t3 = tof32(1,tof32_i,itdc)
1404     t4 = tof32(2,tof32_i,itdc)
1405 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1406     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1407 mocchiut 1.8 xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1408     xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1409     ds = xhelp1-xhelp2
1410     ihelp=(tof12_i-1)*3+tof32_i
1411 mocchiut 1.20 if (iz.le.1) c1 = k_S12S32(1,ihelp)
1412     if (iz.eq.2) c1 = k_S12S32(2,ihelp)
1413     if (iz.gt.2) c1 = k_S12S32(3,ihelp)
1414 mocchiut 1.8 beta_a(4) = c2*F/(ds-c1)
1415     C write(*,*) 'S12-S32 ',xhelp1,xhelp2, beta_a(4)
1416    
1417     C-------ToF Mask - S12 - S32
1418    
1419     tofmask(ch12a(tof12_i),hb12a(tof12_i)) =
1420     $ tofmask(ch12a(tof12_i),hb12a(tof12_i)) + 1
1421     tofmask(ch12b(tof12_i),hb12b(tof12_i)) =
1422     $ tofmask(ch12b(tof12_i),hb12b(tof12_i)) + 1
1423    
1424     tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1425     $ tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1426 pam-de 1.12 tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1427 mocchiut 1.8 $ tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1428 mocchiut 1.2
1429 mocchiut 1.8 C-------
1430 mocchiut 1.2
1431 mocchiut 1.8 ENDIF
1432 mocchiut 1.5 ENDIF
1433 mocchiut 1.1
1434 mocchiut 1.20 C--------------------- S21 - S31 ------------------------
1435 mocchiut 1.5
1436 mocchiut 1.8 dist = ZTOF(3) - ZTOF(5)
1437     dl = 0.
1438     DO I=3,5
1439     dl = dl + TLOUT(i)
1440     ENDDO
1441 pam-de 1.12 F = dl/dist
1442 mocchiut 1.8
1443 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1444    
1445 mocchiut 1.8 C IF (tof21_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1446     IF ((tof21_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1447     & (xtofpos(2).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1448 mocchiut 1.5 t1 = tof21(1,tof21_i,itdc)
1449     t2 = tof21(2,tof21_i,itdc)
1450     t3 = tof31(1,tof31_i,itdc)
1451     t4 = tof31(2,tof31_i,itdc)
1452 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1453     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1454 mocchiut 1.8 xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1455     xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1456     ds = xhelp1-xhelp2
1457     ihelp=(tof21_i-1)*3+tof31_i
1458 mocchiut 1.20 if (iz.le.1) c1 = k_S21S31(1,ihelp)
1459     if (iz.eq.2) c1 = k_S21S31(2,ihelp)
1460     if (iz.gt.2) c1 = k_S21S31(3,ihelp)
1461 mocchiut 1.8 beta_a(5) = c2*F/(ds-c1)
1462    
1463     C-------ToF Mask - S21 - S31
1464    
1465     tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1466     $ tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1467     tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1468     $ tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1469    
1470     tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1471     $ tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1472 pam-de 1.12 tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1473 mocchiut 1.8 $ tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1474 mocchiut 1.2
1475 mocchiut 1.8 C-------
1476 mocchiut 1.2
1477 mocchiut 1.8 ENDIF
1478 mocchiut 1.5 ENDIF
1479 mocchiut 1.1
1480 mocchiut 1.20 C--------------------- S21 - S32 ------------------------
1481 mocchiut 1.5
1482 mocchiut 1.8 dist = ZTOF(3) - ZTOF(6)
1483     dl = 0.
1484     DO I=3,6
1485     dl = dl + TLOUT(i)
1486     ENDDO
1487 pam-de 1.12 F = dl/dist
1488 mocchiut 1.8
1489 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1490    
1491 mocchiut 1.8 C IF (tof21_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1492     IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1493     & (xtofpos(2).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1494 mocchiut 1.5 t1 = tof21(1,tof21_i,itdc)
1495     t2 = tof21(2,tof21_i,itdc)
1496     t3 = tof32(1,tof32_i,itdc)
1497     t4 = tof32(2,tof32_i,itdc)
1498 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1499     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1500 mocchiut 1.8 xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1501     xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1502     ds = xhelp1-xhelp2
1503     ihelp=(tof21_i-1)*3+tof32_i
1504 mocchiut 1.20 if (iz.le.1) c1 = k_S21S32(1,ihelp)
1505     if (iz.eq.2) c1 = k_S21S32(2,ihelp)
1506     if (iz.gt.2) c1 = k_S21S32(3,ihelp)
1507 mocchiut 1.8 beta_a(6) = c2*F/(ds-c1)
1508    
1509     C-------ToF Mask - S21 - S32
1510    
1511     tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1512     $ tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1513     tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1514     $ tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1515    
1516     tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1517     $ tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1518 pam-de 1.12 tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1519 mocchiut 1.8 $ tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1520 mocchiut 1.2
1521 mocchiut 1.8 C-------
1522 mocchiut 1.2
1523 mocchiut 1.8 ENDIF
1524 mocchiut 1.5 ENDIF
1525 mocchiut 1.1
1526 mocchiut 1.20 C--------------------- S22 - S31 ------------------------
1527 mocchiut 1.5
1528 mocchiut 1.8 dist = ZTOF(4) - ZTOF(5)
1529     dl = 0.
1530     DO I=4,5
1531     dl = dl + TLOUT(i)
1532     ENDDO
1533 pam-de 1.12 F = dl/dist
1534 mocchiut 1.20
1535     c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1536    
1537 mocchiut 1.17 C WM workaround
1538     dl = dl - 0.06*F
1539     F = dl/dist
1540 mocchiut 1.8
1541     C IF (tof22_i.GT.none_find.AND.tof31_i.GT.none_find) THEN
1542     IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1543     & (ytofpos(2).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1544 mocchiut 1.5 t1 = tof22(1,tof22_i,itdc)
1545     t2 = tof22(2,tof22_i,itdc)
1546     t3 = tof31(1,tof31_i,itdc)
1547     t4 = tof31(2,tof31_i,itdc)
1548 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1549     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1550 mocchiut 1.8 xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1551     xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1552     ds = xhelp1-xhelp2
1553     ihelp=(tof22_i-1)*3+tof31_i
1554 mocchiut 1.20 if (iz.le.1) c1 = k_S22S31(1,ihelp)
1555     if (iz.eq.2) c1 = k_S22S31(2,ihelp)
1556     if (iz.gt.2) c1 = k_S22S31(3,ihelp)
1557 mocchiut 1.8 beta_a(7) = c2*F/(ds-c1)
1558    
1559     C-------ToF Mask - S22 - S31
1560    
1561     tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1562     $ tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1563     tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1564     $ tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1565    
1566     tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1567     $ tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1568 pam-de 1.12 tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1569 mocchiut 1.8 $ tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1570 mocchiut 1.2
1571 mocchiut 1.8 C-------
1572 mocchiut 1.2
1573 mocchiut 1.8 ENDIF
1574 mocchiut 1.5 ENDIF
1575 pam-de 1.12
1576 mocchiut 1.20 C--------------------- S22 - S32 ------------------------
1577    
1578 mocchiut 1.5
1579 mocchiut 1.8 dist = ZTOF(4) - ZTOF(6)
1580     dl = 0.
1581     DO I=4,6
1582     dl = dl + TLOUT(i)
1583     ENDDO
1584 pam-de 1.12 F = dl/dist
1585 mocchiut 1.17
1586 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1587    
1588 mocchiut 1.17 C WM workaround
1589     dl = dl - 0.06*F
1590     F = dl/dist
1591    
1592 mocchiut 1.8
1593     C IF (tof22_i.GT.none_find.AND.tof32_i.GT.none_find) THEN
1594     IF ((tof22_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1595     & (ytofpos(2).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1596 mocchiut 1.5 t1 = tof22(1,tof22_i,itdc)
1597     t2 = tof22(2,tof22_i,itdc)
1598     t3 = tof32(1,tof32_i,itdc)
1599     t4 = tof32(2,tof32_i,itdc)
1600 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1601     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1602 mocchiut 1.8 xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1603     xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1604     ds = xhelp1-xhelp2
1605     ihelp=(tof22_i-1)*3+tof32_i
1606 mocchiut 1.20 if (iz.le.1) c1 = k_S22S32(1,ihelp)
1607     if (iz.eq.2) c1 = k_S22S32(2,ihelp)
1608     if (iz.gt.2) c1 = k_S22S32(3,ihelp)
1609 mocchiut 1.8 beta_a(8) = c2*F/(ds-c1)
1610    
1611     C-------ToF Mask - S22 - S32
1612    
1613     tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1614     $ tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1615     tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1616     $ tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1617    
1618     tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1619     $ tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1620 pam-de 1.12 tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1621 mocchiut 1.8 $ tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1622 mocchiut 1.2
1623 mocchiut 1.8 C-------
1624 mocchiut 1.2
1625 mocchiut 1.8 ENDIF
1626 mocchiut 1.5 ENDIF
1627 mocchiut 1.1
1628 mocchiut 1.20 C--------------------- S11 - S21 ------------------------
1629 mocchiut 1.5
1630 mocchiut 1.8 dist = ZTOF(1) - ZTOF(3)
1631     dl = 0.
1632     DO I=1,3
1633     dl = dl + TLOUT(i)
1634     ENDDO
1635 pam-de 1.12 F = dl/dist
1636 mocchiut 1.8
1637 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1638    
1639 mocchiut 1.17 C WM workaround
1640     dl = dl - 0.442*F
1641     F = dl/dist
1642    
1643 mocchiut 1.8 C IF (tof11_i.GT.none_find.AND.tof21_i.GT.none_find) THEN
1644     IF ((tof11_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
1645     & (ytofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN
1646 mocchiut 1.5 t1 = tof11(1,tof11_i,itdc)
1647     t2 = tof11(2,tof11_i,itdc)
1648     t3 = tof21(1,tof21_i,itdc)
1649     t4 = tof21(2,tof21_i,itdc)
1650 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1651     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1652 mocchiut 1.8 xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1653     xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1654     ds = xhelp1-xhelp2
1655     ihelp=(tof11_i-1)*2+tof21_i
1656 mocchiut 1.20 if (iz.le.1) c1 = k_S11S21(1,ihelp)
1657     if (iz.eq.2) c1 = k_S11S21(2,ihelp)
1658     if (iz.gt.2) c1 = k_S11S21(3,ihelp)
1659 mocchiut 1.8 beta_a(9) = c2*F/(ds-c1)
1660    
1661     C-------ToF Mask - S11 - S21
1662    
1663     tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
1664     $ tofmask(ch11a(tof11_i),hb11a(tof11_i)) + 1
1665     tofmask(ch11b(tof11_i),hb11b(tof11_i)) =
1666     $ tofmask(ch11b(tof11_i),hb11b(tof11_i)) + 1
1667    
1668     tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1669     $ tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1670 pam-de 1.12 tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1671 mocchiut 1.8 $ tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1672 mocchiut 1.2
1673 mocchiut 1.8 C-------
1674 mocchiut 1.2
1675 mocchiut 1.8 ENDIF
1676 mocchiut 1.5 ENDIF
1677 pam-de 1.12
1678 mocchiut 1.20 C--------------------- S11 - S22 ------------------------
1679 mocchiut 1.5
1680 mocchiut 1.8 dist = ZTOF(1) - ZTOF(4)
1681     dl = 0.
1682     DO I=1,4
1683     dl = dl + TLOUT(i)
1684     ENDDO
1685 pam-de 1.12 F = dl/dist
1686 mocchiut 1.8
1687 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1688    
1689 mocchiut 1.8 C IF (tof11_i.GT.none_find.AND.tof22_i.GT.none_find) THEN
1690     IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
1691     & (ytofpos(1).NE.101.).AND.(ytofpos(2).NE.101.)) THEN
1692 mocchiut 1.5 t1 = tof11(1,tof11_i,itdc)
1693     t2 = tof11(2,tof11_i,itdc)
1694     t3 = tof22(1,tof22_i,itdc)
1695     t4 = tof22(2,tof22_i,itdc)
1696 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1697     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1698 mocchiut 1.8 xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1699     xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1700     ds = xhelp1-xhelp2
1701     ihelp=(tof11_i-1)*2+tof22_i
1702 mocchiut 1.20 if (iz.le.1) c1 = k_S11S22(1,ihelp)
1703     if (iz.eq.2) c1 = k_S11S22(2,ihelp)
1704     if (iz.gt.2) c1 = k_S11S22(3,ihelp)
1705 mocchiut 1.8 beta_a(10) = c2*F/(ds-c1)
1706    
1707     C-------ToF Mask - S11 - S22
1708    
1709     tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
1710     $ tofmask(ch11a(tof11_i),hb11a(tof11_i)) + 1
1711     tofmask(ch11b(tof11_i),hb11b(tof11_i)) =
1712     $ tofmask(ch11b(tof11_i),hb11b(tof11_i)) + 1
1713    
1714     tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1715     $ tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1716 pam-de 1.12 tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1717 mocchiut 1.8 $ tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1718 mocchiut 1.2
1719 mocchiut 1.8 C-------
1720 mocchiut 1.2
1721 mocchiut 1.8 ENDIF
1722 mocchiut 1.5 ENDIF
1723 mocchiut 1.1
1724 mocchiut 1.20 C--------------------- S12 - S21 ------------------------
1725 mocchiut 1.5
1726 mocchiut 1.8 dist = ZTOF(2) - ZTOF(3)
1727     dl = 0.
1728     DO I=2,3
1729     dl = dl + TLOUT(i)
1730     ENDDO
1731 pam-de 1.12 F = dl/dist
1732 mocchiut 1.8
1733 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1734    
1735 mocchiut 1.17 C WM workaround
1736     dl = dl - 0.442*F
1737     F = dl/dist
1738    
1739 mocchiut 1.8 C IF (tof12_i.GT.none_find.AND.tof21_i.GT.none_find) THEN
1740     IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
1741     & (xtofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN
1742 mocchiut 1.5 t1 = tof12(1,tof12_i,itdc)
1743     t2 = tof12(2,tof12_i,itdc)
1744     t3 = tof21(1,tof21_i,itdc)
1745     t4 = tof21(2,tof21_i,itdc)
1746 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1747     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1748 mocchiut 1.8 xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1749     xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1750     ds = xhelp1-xhelp2
1751     ihelp=(tof12_i-1)*2+tof21_i
1752 mocchiut 1.20 if (iz.le.1) c1 = k_S12S21(1,ihelp)
1753     if (iz.eq.2) c1 = k_S12S21(2,ihelp)
1754     if (iz.gt.2) c1 = k_S12S21(3,ihelp)
1755 mocchiut 1.8 beta_a(11) = c2*F/(ds-c1)
1756    
1757     C-------ToF Mask - S12 - S21
1758    
1759     tofmask(ch12a(tof12_i),hb12a(tof12_i)) =
1760     $ tofmask(ch12a(tof12_i),hb12a(tof12_i)) + 1
1761     tofmask(ch12b(tof12_i),hb12b(tof12_i)) =
1762     $ tofmask(ch12b(tof12_i),hb12b(tof12_i)) + 1
1763    
1764     tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1765     $ tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1766 pam-de 1.12 tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1767 mocchiut 1.8 $ tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1768 mocchiut 1.2
1769 mocchiut 1.8 C-------
1770 mocchiut 1.2
1771 mocchiut 1.8 ENDIF
1772 mocchiut 1.5 ENDIF
1773 mocchiut 1.1
1774 mocchiut 1.20 C--------------------- S12 - S22 ------------------------
1775 mocchiut 1.5
1776 mocchiut 1.8 dist = ZTOF(2) - ZTOF(4)
1777     dl = 0.
1778     DO I=2,4
1779     dl = dl + TLOUT(i)
1780     ENDDO
1781 pam-de 1.12 F = dl/dist
1782 mocchiut 1.8
1783 mocchiut 1.20 c2 = (2.*0.01*dist)/(3.E08*50.E-12 )
1784    
1785 mocchiut 1.8 C IF (tof12_i.GT.none_find.AND.tof22_i.GT.none_find) THEN
1786     IF ((tof12_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
1787     & (xtofpos(1).NE.101.).AND.(ytofpos(2).NE.101.)) THEN
1788 mocchiut 1.5 t1 = tof12(1,tof12_i,itdc)
1789     t2 = tof12(2,tof12_i,itdc)
1790     t3 = tof22(1,tof22_i,itdc)
1791     t4 = tof22(2,tof22_i,itdc)
1792 pam-de 1.12 IF ((t1.lt.4095).and.(t2.lt.4095).and.
1793     & (t3.lt.4095).and.(t4.lt.4095)) THEN
1794 mocchiut 1.8 xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1795     xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1796     ds = xhelp1-xhelp2
1797 mocchiut 1.20 ihelp=(tof12_i-1)*2+tof22_i
1798     if (iz.le.1) c1 = k_S12S22(1,ihelp)
1799     if (iz.eq.2) c1 = k_S12S22(2,ihelp)
1800     if (iz.gt.2) c1 = k_S12S22(3,ihelp)
1801 mocchiut 1.8 beta_a(12) = c2*F/(ds-c1)
1802    
1803     C-------ToF Mask - S12 - S22
1804    
1805     tofmask(ch12a(tof12_i),hb12a(tof12_i)) =
1806     $ tofmask(ch12a(tof12_i),hb12a(tof12_i)) + 1
1807     tofmask(ch12b(tof12_i),hb12b(tof12_i)) =
1808     $ tofmask(ch12b(tof12_i),hb12b(tof12_i)) + 1
1809    
1810     tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1811     $ tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1812 pam-de 1.12 tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1813 mocchiut 1.8 $ tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1814 mocchiut 1.2
1815 mocchiut 1.8 C-------
1816 mocchiut 1.2
1817 mocchiut 1.8 ENDIF
1818 mocchiut 1.5 ENDIF
1819 pam-de 1.12
1820 mocchiut 1.1 C-------
1821 mocchiut 1.15 C
1822     C icount=0
1823     C sw=0.
1824     C sxw=0.
1825     C beta_mean=100.
1826     C
1827     C do i=1,12
1828     C if ((beta_a(i).gt.-1.5).and.(beta_a(i).lt.1.5)) then
1829     C icount= icount+1
1830     C if (i.le.4) w_i=1./(0.13**2.)
1831     C if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)
1832     C if (i.ge.9) w_i=1./(0.25**2.) ! to be checked
1833     C sxw=sxw + beta_a(i)*w_i
1834     C sw =sw + w_i
1835     C endif
1836     C enddo
1837     C
1838     C if (icount.gt.0) beta_mean=sxw/sw
1839     C beta_a(13) = beta_mean
1840     C
1841 pam-de 1.16
1842 mocchiut 1.15 C------- New mean beta calculation
1843 mocchiut 1.1
1844 mocchiut 1.15 do i=1,12
1845     btemp(i) = beta_a(i)
1846     enddo
1847 mocchiut 1.1
1848 pam-de 1.16 beta_a(13)=newbeta(2,btemp,hitvec,10.,10.,20.)
1849 pam-de 1.12
1850 mocchiut 1.15 C-------
1851 mocchiut 1.1
1852 mocchiut 1.8
1853 pam-de 1.12 c IF (tof11_i.GT.none_find)
1854 mocchiut 1.8 c & write(*,*) '11 ',tof11(1,tof11_i,itdc),tof11(2,tof11_i,itdc)
1855 pam-de 1.12 c IF (tof12_i.GT.none_find)
1856 mocchiut 1.8 c & write(*,*) '12 ',tof12(1,tof12_i,itdc),tof12(2,tof12_i,itdc)
1857    
1858 pam-de 1.12 c IF (tof21_i.GT.none_find)
1859 mocchiut 1.8 c & write(*,*) '21 ',tof21(1,tof21_i,itdc),tof21(2,tof21_i,itdc)
1860 pam-de 1.12 c IF (tof22_i.GT.none_find)
1861 mocchiut 1.8 c & write(*,*) '22 ',tof22(1,tof22_i,itdc),tof22(2,tof22_i,itdc)
1862    
1863 pam-de 1.12 c IF (tof31_i.GT.none_find)
1864 mocchiut 1.8 c & write(*,*) '31 ',tof31(1,tof31_i,itdc),tof31(2,tof31_i,itdc)
1865 pam-de 1.12 c IF (tof32_i.GT.none_find)
1866 mocchiut 1.8 c & write(*,*) '32 ',tof32(1,tof32_i,itdc),tof32(2,tof32_i,itdc)
1867    
1868     c write(*,*) xtofpos
1869     c write(*,*) ytofpos
1870 mocchiut 1.11 C write(*,*)'toftrk beta', beta_a
1871 mocchiut 1.8 C write(*,*) adcflagtof
1872 mocchiut 1.11 C write(*,*)'TOFTRK ',ievent,beta_a(1),beta_a(2),beta_a(3),beta_a(4)
1873     c write(*,*) 'toftrk'
1874     c write(*,*) xtofpos
1875     c write(*,*) ytofpos
1876     c write(*,*) xtr_tof
1877     c write(*,*) ytr_tof
1878 mocchiut 1.8
1879 pamelats 1.18 c write(*,*) '--------- end toftrk ----------'
1880 mocchiut 1.8
1881 mocchiut 1.1 RETURN
1882     END
1883    
1884    
1885 mocchiut 1.8
1886 mocchiut 1.11
1887     C------------------------------------------------------------------
1888 pam-de 1.12
1889 pam-de 1.16

  ViewVC Help
Powered by ViewVC 1.1.23