/[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.22 - (hide annotations) (download)
Thu Jan 16 15:29:37 2014 UTC (10 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: v10RED, v10REDr01, HEAD
Changes since 1.21: +56 -55 lines
Compilation warnings using GCC4.7 fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23