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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Thu Nov 27 13:47:54 2008 UTC (16 years ago) by pamelats
Branch: MAIN
Changes since 1.8: +100 -70 lines
Calculation of zenith angle debugged

1 mocchiut 1.6
2 mocchiut 1.7 C******************************************************************************
3     C
4     C 08-12-06 WM: adc_c-bug : The raw ADc value was multiplied with cos(theta)
5     C and AFTER that there was an if statement "if tof32(right,i,iadc) < 4095"
6     C
7     C jan-07 GF: ADCflags(4,12) inserted to flag artificial ADC values
8     C jan-07 WM: artificial ADC values created using attenuation calibration
9     C jan-07 WM: modified xtofpos flag "101". xtofpos must be inside physical
10     C dimension of the paddle +/- 10 cm
11     C jan-07 WM: if xtofpos=101 then this paddle is not used for beta
12     C calculation
13     C jan-07 WM: the definition for a "hit" is changed: Now we must have a
14     C valid TDC signal on both sides
15     C jan-07 WM: flag for PMTs #10 and #35 added, TDC=819 due to bit-shift
16     C jan-07 WM: bug removed: in some cases tdc_tw was calculated due to a
17     C leftover "xhelp" value
18     C apr-07 WM: attenuation fit curve is now a double exponential fit
19     C conversion from raw ADC to pC using calibration function
20     C variables xtr_tof and ytr_tof inserted (filled with default)
21     C jan-08 WM: Major Update: Time Walk correction introduced
22     C Additionalyl we use the information from the "check_charge"
23     C function to fill artificial ADC values and make small corrections
24     C to the k1-parameter (for Z>2)
25     C feb-08 WM: Calculation of beta(13) changed: First a mean beta is calculated,
26     C then in a second step we check the residuals of the single
27     C measurements, reject if > 10 sigma, calculate chi2 and "quality"
28     C beta is taken as good if chi2<20 and quality>10
29 pam-de 1.8 C mar-08 WM: Call to "newbeta" changed, now a flag tells the function if the
30     C call comes from "tofl2com" or form "toftrack"
31     C mar-08 WM: Bug found in dEdx if check_charge>1
32 pamelats 1.9 C oct-08 WM: Calculation of zenith angle debugged, sometimes strange values
33     C were possible
34 mocchiut 1.7 C******************************************************************************
35 mocchiut 1.4
36 mocchiut 1.1 INTEGER FUNCTION TOFL2COM()
37     c
38     IMPLICIT NONE
39     C
40     include 'input_tof.txt'
41     include 'output_tof.txt'
42     include 'tofcomm.txt'
43    
44     INTEGER icounter
45     DATA icounter / 0/
46    
47     LOGICAL check
48     REAL secure
49    
50 mocchiut 1.7 INTEGER j,hitvec(6)
51 mocchiut 1.1
52     REAL dx,dy,dr,ds
53 pamelats 1.9 REAL yhelp,yhelp1,yhelp2,xhelp,xhelp1,xhelp2
54 mocchiut 1.7 REAL c1,c2
55 mocchiut 1.1
56 mocchiut 1.7 C REAL sw,sxw,w_i
57     C INTEGER icount
58     C REAL beta_mean
59 mocchiut 1.4
60 mocchiut 1.1 INTEGER tof11_j,tof21_j,tof31_j
61     INTEGER tof12_j,tof22_j,tof32_j
62    
63     c value for status of each PM-data
64     c first index : 1 = left, 2 = right
65     c second index : 1... number of paddle
66     INTEGER tof11_event(2,8),tof12_event(2,6)
67     INTEGER tof21_event(2,2),tof22_event(2,2)
68     INTEGER tof31_event(2,3),tof32_event(2,3)
69    
70 mocchiut 1.7
71     REAL y_coor_lin11c(8,2),x_coor_lin12c(6,2)
72     REAL x_coor_lin21c(2,2),y_coor_lin22c(2,2)
73     REAL y_coor_lin31c(3,2),x_coor_lin32c(3,2)
74    
75     DATA y_coor_lin11c(1,1),y_coor_lin11c(1,2) /-20.66,-2.497/
76     DATA y_coor_lin11c(2,1),y_coor_lin11c(2,2) /-9.10, -2.52/
77     DATA y_coor_lin11c(3,1),y_coor_lin11c(3,2) /-24.07,-2.12/
78     DATA y_coor_lin11c(4,1),y_coor_lin11c(4,2) /-13.40,-2.47/
79     DATA y_coor_lin11c(5,1),y_coor_lin11c(5,2) /-31.07,-2.32/
80     DATA y_coor_lin11c(6,1),y_coor_lin11c(6,2) /-21.69,-2.63/
81     DATA y_coor_lin11c(7,1),y_coor_lin11c(7,2) /-12.37,-2.65/
82     DATA y_coor_lin11c(8,1),y_coor_lin11c(8,2) /-10.81,-3.15/
83    
84     DATA x_coor_lin12c(1,1),x_coor_lin12c(1,2) /12.96, -2.65/
85     DATA x_coor_lin12c(2,1),x_coor_lin12c(2,2) /17.12,-2.44/
86     DATA x_coor_lin12c(3,1),x_coor_lin12c(3,2) /7.26, -1.98/
87     DATA x_coor_lin12c(4,1),x_coor_lin12c(4,2) /-22.52,-2.27/
88     DATA x_coor_lin12c(5,1),x_coor_lin12c(5,2) /-18.54,-2.28/
89     DATA x_coor_lin12c(6,1),x_coor_lin12c(6,2) /-7.67,-2.15/
90    
91     DATA x_coor_lin21c(1,1),x_coor_lin21c(1,2) /22.56,-1.56/
92     DATA x_coor_lin21c(2,1),x_coor_lin21c(2,2) /13.94,-1.56/
93    
94     DATA y_coor_lin22c(1,1),y_coor_lin22c(1,2) /-24.24,-2.23/
95     DATA y_coor_lin22c(2,1),y_coor_lin22c(2,2) /-45.99,-1.68/
96    
97     DATA y_coor_lin31c(1,1),y_coor_lin31c(1,2) /-22.99,-3.54/
98     DATA y_coor_lin31c(2,1),y_coor_lin31c(2,2) /-42.28,-4.10/
99     DATA y_coor_lin31c(3,1),y_coor_lin31c(3,2) /-41.29,-3.69/
100    
101     DATA x_coor_lin32c(1,1),x_coor_lin32c(1,2) /0.961, -3.22/
102     DATA x_coor_lin32c(2,1),x_coor_lin32c(2,2) /4.98,-3.48/
103     DATA x_coor_lin32c(3,1),x_coor_lin32c(3,2) /-22.08,-3.37/
104    
105 mocchiut 1.1
106 mocchiut 1.4 REAL theta13
107 mocchiut 1.1 C-- DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006
108     REAL tofarm12
109     PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69
110     REAL tofarm23
111     PARAMETER (tofarm23 = 47.61) ! from 23.69 to -23.92
112     REAL tofarm13
113     PARAMETER (tofarm13 = 77.31) ! from 53.39 to -23.92
114 mocchiut 1.4
115     REAL hepratio
116 mocchiut 1.1
117     INTEGER ihelp
118 mocchiut 1.7 REAL xkorr,btemp(12)
119    
120     REAL atten,pc_adc,check_charge,newbeta
121    
122     INTEGER IZ
123     REAL k1corrA1,k1corrB1,k1corrC1
124    
125 mocchiut 1.1
126 mocchiut 1.7 INTEGER ifst
127     DATA ifst /0/
128 mocchiut 1.6
129 mocchiut 1.1 C---------------------------------------
130     C
131     C Begin !
132     C
133     TOFL2COM = 0
134     C
135     C CALCULATE COMMON VARIABLES
136     C
137 mocchiut 1.7 C-------------------------------------------------------------------
138 mocchiut 1.1
139 mocchiut 1.7 if (ifst.eq.0) then
140    
141     ifst=1
142 mocchiut 1.1
143 mocchiut 1.7 C amplitude has to be 'secure' higher than pedestal for an adc event
144     secure = 2.
145 mocchiut 1.1
146 mocchiut 1.4 C ratio between helium and proton ca. 4
147 mocchiut 1.7 hepratio = 4. !
148     offset = 1
149     slope = 2
150     left = 1
151     right = 2
152     none_ev = 0
153     none_find = 0
154     tdc_ev = 1
155     adc_ev = 1
156     itdc = 1
157     iadc = 2
158    
159     C--- These are the corrections to the k1-value for Z>2 particles
160     k1corrA1 = 0.
161     k1corrB1 = -5.0
162     k1corrC1= 8.0
163    
164    
165     ENDIF
166     C---------------------------------------------------------------------
167    
168     icounter = icounter + 1
169    
170 mocchiut 1.1
171     do i=1,13
172     betatof_a(i) = 100. ! As in "troftrk.for"
173     enddo
174    
175 mocchiut 1.7 do i=1,6
176     hitvec(i) = -1
177     enddo
178    
179 mocchiut 1.1 do i=1,4
180     do j=1,12
181     adctof_c(i,j) = 1000.
182     enddo
183     enddo
184    
185    
186     do i=1,4
187     do j=1,12
188     tdc_c(i,j) = 4095.
189     enddo
190     enddo
191    
192    
193 mocchiut 1.2 do i=1,12
194     do j=1,4
195     tofmask(j,i) = 0
196     enddo
197     enddo
198    
199    
200 mocchiut 1.4 c gf adc falg:
201     do i=1,4
202     do j=1,12
203     adcflagtof(i,j) = 0
204     enddo
205     enddo
206    
207     c gf tdc falg:
208     do i=1,4
209     do j=1,12
210     tdcflagtof(i,j) = 0
211     enddo
212     enddo
213    
214 mocchiut 1.6
215     C--- Fill xtr_tof and ytr_tof: positions from tracker at ToF layers
216     C--- since this is standalone ToF fill with default values
217     do j=1,6
218     xtr_tof(j) = 101.
219     ytr_tof(j) = 101.
220     enddo
221    
222 mocchiut 1.1 c the calibration files are read in the main program from xxx_tofcalib.rz
223    
224     c-------------------------get ToF data --------------------------------
225    
226     c put the adc and tdc values from ntuple into tofxx(i,j,k) variables
227 mocchiut 1.6 c adc valueas are then pC
228 mocchiut 1.1
229     do j=1,8
230 mocchiut 1.6 tof11(1,j,2) = pc_adc(adc(ch11a(j),hb11a(j)))
231     tof11(2,j,2) = pc_adc(adc(ch11b(j),hb11b(j)))
232     tof11(1,j,1) = (tdc(ch11a(j),hb11a(j)))
233     tof11(2,j,1) = (tdc(ch11b(j),hb11b(j)))
234 mocchiut 1.1 enddo
235    
236    
237     do j=1,6
238 mocchiut 1.6 tof12(1,j,2) = pc_adc(adc(ch12a(j),hb12a(j)))
239     tof12(2,j,2) = pc_adc(adc(ch12b(j),hb12b(j)))
240     tof12(1,j,1) = (tdc(ch12a(j),hb12a(j)))
241     tof12(2,j,1) = (tdc(ch12b(j),hb12b(j)))
242 mocchiut 1.1 enddo
243    
244     do j=1,2
245 mocchiut 1.6 tof21(1,j,2) = pc_adc(adc(ch21a(j),hb21a(j)))
246     tof21(2,j,2) = pc_adc(adc(ch21b(j),hb21b(j)))
247     tof21(1,j,1) = (tdc(ch21a(j),hb21a(j)))
248     tof21(2,j,1) = (tdc(ch21b(j),hb21b(j)))
249 mocchiut 1.1 enddo
250    
251     do j=1,2
252 mocchiut 1.6 tof22(1,j,2) = pc_adc(adc(ch22a(j),hb22a(j)))
253     tof22(2,j,2) = pc_adc(adc(ch22b(j),hb22b(j)))
254     tof22(1,j,1) = (tdc(ch22a(j),hb22a(j)))
255     tof22(2,j,1) = (tdc(ch22b(j),hb22b(j)))
256 mocchiut 1.1 enddo
257    
258     do j=1,3
259 mocchiut 1.6 tof31(1,j,2) = pc_adc(adc(ch31a(j),hb31a(j)))
260     tof31(2,j,2) = pc_adc(adc(ch31b(j),hb31b(j)))
261     tof31(1,j,1) = (tdc(ch31a(j),hb31a(j)))
262     tof31(2,j,1) = (tdc(ch31b(j),hb31b(j)))
263 mocchiut 1.1 enddo
264    
265     do j=1,3
266 mocchiut 1.6 tof32(1,j,2) = pc_adc(adc(ch32a(j),hb32a(j)))
267     tof32(2,j,2) = pc_adc(adc(ch32b(j),hb32b(j)))
268     tof32(1,j,1) = (tdc(ch32a(j),hb32a(j)))
269     tof32(2,j,1) = (tdc(ch32b(j),hb32b(j)))
270 mocchiut 1.1 enddo
271    
272     C----------------------------------------------------------------------
273    
274     DO i = 1,8
275     if (abs(tof11(1,i,itdc)).gt.10000.) tof11(1,i,itdc)= 10000.
276     if (abs(tof11(2,i,itdc)).gt.10000.) tof11(2,i,itdc)= 10000.
277     if (abs(tof11(1,i,iadc)).gt.10000.) tof11(1,i,iadc)= 10000.
278     if (abs(tof11(2,i,iadc)).gt.10000.) tof11(2,i,iadc)= 10000.
279     ENDDO
280    
281     DO i = 1,6
282     if (abs(tof12(1,i,itdc)).gt.10000.) tof12(1,i,itdc)= 10000.
283     if (abs(tof12(2,i,itdc)).gt.10000.) tof12(2,i,itdc)= 10000.
284     if (abs(tof12(1,i,iadc)).gt.10000.) tof12(1,i,iadc)= 10000.
285     if (abs(tof12(2,i,iadc)).gt.10000.) tof12(2,i,iadc)= 10000.
286     ENDDO
287    
288    
289     DO i = 1,2
290     if (abs(tof21(1,i,itdc)).gt.10000.) tof21(1,i,itdc)= 10000.
291     if (abs(tof21(2,i,itdc)).gt.10000.) tof21(2,i,itdc)= 10000.
292     if (abs(tof21(1,i,iadc)).gt.10000.) tof21(1,i,iadc)= 10000.
293     if (abs(tof21(2,i,iadc)).gt.10000.) tof21(2,i,iadc)= 10000.
294     ENDDO
295    
296     DO i = 1,2
297     if (abs(tof22(1,i,itdc)).gt.10000.) tof22(1,i,itdc)= 10000.
298     if (abs(tof22(2,i,itdc)).gt.10000.) tof22(2,i,itdc)= 10000.
299     if (abs(tof22(1,i,iadc)).gt.10000.) tof22(1,i,iadc)= 10000.
300     if (abs(tof22(2,i,iadc)).gt.10000.) tof22(2,i,iadc)= 10000.
301     ENDDO
302    
303     DO i = 1,3
304     if (abs(tof31(1,i,itdc)).gt.10000.) tof31(1,i,itdc)= 10000.
305     if (abs(tof31(2,i,itdc)).gt.10000.) tof31(2,i,itdc)= 10000.
306     if (abs(tof31(1,i,iadc)).gt.10000.) tof31(1,i,iadc)= 10000.
307     if (abs(tof31(2,i,iadc)).gt.10000.) tof31(2,i,iadc)= 10000.
308     ENDDO
309    
310     DO i = 1,3
311     if (abs(tof32(1,i,itdc)).gt.10000.) tof32(1,i,itdc)= 10000.
312     if (abs(tof32(2,i,itdc)).gt.10000.) tof32(2,i,itdc)= 10000.
313     if (abs(tof32(1,i,iadc)).gt.10000.) tof32(1,i,iadc)= 10000.
314     if (abs(tof32(2,i,iadc)).gt.10000.) tof32(2,i,iadc)= 10000.
315     ENDDO
316    
317 mocchiut 1.4 C----------------------------------------------------------------------
318     C------------------ set ADC & TDC flag = 0 ------------------------
319     C----------------------------------------------------------------------
320    
321     do j=1,8
322     if (adc(ch11a(j),hb11a(j)).LT.4096)adcflagtof(ch11a(j),hb11a(j))=0
323     if (adc(ch11b(j),hb11b(j)).LT.4096)adcflagtof(ch11b(j),hb11b(j))=0
324     if (tdc(ch11a(j),hb11a(j)).LT.4096)tdcflagtof(ch11a(j),hb11a(j))=0
325     if (tdc(ch11b(j),hb11b(j)).LT.4096)tdcflagtof(ch11b(j),hb11b(j))=0
326     enddo
327     do j=1,6
328     if (adc(ch12a(j),hb12a(j)).LT.4096)adcflagtof(ch12a(j),hb12a(j))=0
329     if (adc(ch12b(j),hb12b(j)).LT.4096)adcflagtof(ch12b(j),hb12b(j))=0
330     if (tdc(ch12a(j),hb12a(j)).LT.4096)tdcflagtof(ch12a(j),hb12a(j))=0
331     if (tdc(ch12b(j),hb12b(j)).LT.4096)tdcflagtof(ch12b(j),hb12b(j))=0
332     enddo
333     do j=1,2
334     if (adc(ch21a(j),hb21a(j)).LT.4096)adcflagtof(ch21a(j),hb21a(j))=0
335     if (adc(ch21b(j),hb21b(j)).LT.4096)adcflagtof(ch21b(j),hb21b(j))=0
336     if (tdc(ch21a(j),hb21a(j)).LT.4096)tdcflagtof(ch21a(j),hb21a(j))=0
337     if (tdc(ch21b(j),hb21b(j)).LT.4096)tdcflagtof(ch21b(j),hb21b(j))=0
338     enddo
339     do j=1,2
340     if (adc(ch22a(j),hb22a(j)).LT.4096)adcflagtof(ch22a(j),hb22a(j))=0
341     if (adc(ch22b(j),hb22b(j)).LT.4096)adcflagtof(ch22b(j),hb22b(j))=0
342     if (tdc(ch22a(j),hb22a(j)).LT.4096)tdcflagtof(ch22a(j),hb22a(j))=0
343     if (tdc(ch22b(j),hb22b(j)).LT.4096)tdcflagtof(ch22b(j),hb22b(j))=0
344     enddo
345     do j=1,3
346     if (adc(ch31a(j),hb31a(j)).LT.4096)adcflagtof(ch31a(j),hb31a(j))=0
347     if (adc(ch31b(j),hb31b(j)).LT.4096)adcflagtof(ch31b(j),hb31b(j))=0
348     if (tdc(ch31a(j),hb31a(j)).LT.4096)tdcflagtof(ch31a(j),hb31a(j))=0
349     if (tdc(ch31b(j),hb31b(j)).LT.4096)tdcflagtof(ch31b(j),hb31b(j))=0
350     enddo
351     do j=1,3
352     if (adc(ch32a(j),hb32a(j)).LT.4096)adcflagtof(ch32a(j),hb32a(j))=0
353     if (adc(ch32b(j),hb32b(j)).LT.4096)adcflagtof(ch32b(j),hb32b(j))=0
354     if (tdc(ch32a(j),hb32a(j)).LT.4096)tdcflagtof(ch32a(j),hb32a(j))=0
355     if (tdc(ch32b(j),hb32b(j)).LT.4096)tdcflagtof(ch32b(j),hb32b(j))=0
356     enddo
357    
358 mocchiut 1.1 C----------------------------------------------------------------
359 mocchiut 1.4 C---------- Check PMTs 10 and 35 for strange TDC values----------
360     C----------------------------------------------------------------
361    
362     C---- S116A TDC=819
363     if (tof11(1,6,1).EQ.819) then
364     tof11(1,6,1) = 4095
365     tdcflagtof(ch11a(6),hb11a(6))=2
366     endif
367    
368     C---- S222B TDC=819
369     if (tof22(2,2,1).EQ.819) then
370     tof22(2,2,1) = 4095
371     tdcflagtof(ch22b(2),hb22b(2))=2
372     endif
373    
374     C----------------------------------------------------------------
375     C------------ Check Paddles for hits -----------------------
376     C------ a "hit" means TDC values<4095 on both sides ------------
377 mocchiut 1.1 C----------------------------------------------------------------
378    
379     C upper tof S11
380     DO i = 1,8
381    
382     DO j = 1,2
383     tof11_event(j,i) = none_ev
384     IF ((tof11(j,i,itdc).LT.2000).AND.(tof11(j,i,itdc).GT.100))
385     + tof11_event(j,i) = tof11_event(j,i) + tdc_ev
386     ENDDO
387     ENDDO
388    
389     c find single paddle in upper tof with tdc and adc signal
390     tof11_i = none_find
391     tof11_j = none_find
392     check = .TRUE.
393     DO i = 1, 8
394     IF ((tof11_event(left,i).GE.1).AND.(tof11_event(right,i).GE.1))
395     + THEN
396     c check if an other paddle has also an event - then set flag
397     tof11_j = tof11_j + 2**(i-1)
398     IF (check.EQV..TRUE.) THEN
399     IF (tof11_i.EQ.none_find) THEN
400     tof11_i = i
401     ELSE
402     tof11_i = -1
403     check = .FALSE.
404     ENDIF
405     ENDIF
406     ENDIF
407     ENDDO
408    
409    
410     C upper tof S12
411     DO i = 1,6
412     DO j = 1,2
413     tof12_event(j,i) = none_ev
414     IF ((tof12(j,i,itdc).LT.2000).AND.(tof12(j,i,itdc).GT.100))
415     + tof12_event(j,i) = tof12_event(j,i) + tdc_ev
416     ENDDO
417     ENDDO
418    
419     c find single paddle in upper tof with tdc and adc signal
420     tof12_i = none_find
421     tof12_j = none_find
422     check = .TRUE.
423     DO i = 1, 6
424     IF ((tof12_event(left,i).GE.1).AND.(tof12_event(right,i).GE.1))
425     + THEN
426     c check if an other paddle has also an event - then set flag
427     tof12_j = tof12_j + 2**(i-1)
428     IF (check.EQV..TRUE.) THEN
429     IF (tof12_i.EQ.none_find) THEN
430     tof12_i = i
431     ELSE
432     tof12_i = -1
433     check = .FALSE.
434     ENDIF
435     ENDIF
436     ENDIF
437     ENDDO
438    
439    
440     C middle tof S21
441     DO i = 1,2
442     DO j = 1,2
443     tof21_event(j,i) = none_ev
444     IF ((tof21(j,i,itdc).LT.2000).AND.(tof21(j,i,itdc).GT.100))
445     + tof21_event(j,i) = tof21_event(j,i) + tdc_ev
446     ENDDO
447     ENDDO
448    
449     c find single paddle in upper tof with tdc and adc signal
450     tof21_i = none_find
451     tof21_j = none_find
452     check = .TRUE.
453     DO i = 1, 2
454     IF ((tof21_event(left,i).GE.1).AND.(tof21_event(right,i).GE.1))
455     + THEN
456     c check if an other paddle has also an event - then set flag
457     tof21_j = tof21_j + 2**(i-1)
458     IF (check.EQV..TRUE.) THEN
459     IF (tof21_i.EQ.none_find) THEN
460     tof21_i = i
461     ELSE
462     tof21_i = -1
463     check = .FALSE.
464     ENDIF
465     ENDIF
466     ENDIF
467     ENDDO
468    
469     C middle tof S22
470     DO i = 1,2
471     DO j = 1,2
472     tof22_event(j,i) = none_ev
473     IF ((tof22(j,i,itdc).LT.2000).AND.(tof22(j,i,itdc).GT.100))
474     + tof22_event(j,i) = tof22_event(j,i) + tdc_ev
475     ENDDO
476     ENDDO
477    
478     c find single paddle in upper tof with tdc and adc signal
479     tof22_i = none_find
480     tof22_j = none_find
481     check = .TRUE.
482     DO i = 1, 2
483     IF ((tof22_event(left,i).GE.1).AND.(tof22_event(right,i).GE.1))
484     + THEN
485     c check if an other paddle has also an event - then set flag
486     tof22_j = tof22_j + 2**(i-1)
487     IF (check.EQV..TRUE.) THEN
488     IF (tof22_i.EQ.none_find) THEN
489     tof22_i = i
490     ELSE
491     tof22_i = -1
492     check = .FALSE.
493     ENDIF
494     ENDIF
495     ENDIF
496     ENDDO
497    
498    
499     C bottom tof S31
500     DO i = 1,3
501     DO j = 1,2
502     tof31_event(j,i) = none_ev
503     IF ((tof31(j,i,itdc).LT.2000).AND.(tof31(j,i,itdc).GT.100))
504     + tof31_event(j,i) = tof31_event(j,i) + tdc_ev
505     ENDDO
506     ENDDO
507    
508     c find single paddle in upper tof with tdc and adc signal
509     tof31_i = none_find
510     tof31_j = none_find
511     check = .TRUE.
512     DO i = 1, 3
513     IF ((tof31_event(left,i).GE.1).AND.(tof31_event(right,i).GE.1))
514     + THEN
515     c check if an other paddle has also an event - then set flag
516     tof31_j = tof31_j + 2**(i-1)
517     IF (check.EQV..TRUE.) THEN
518     IF (tof31_i.EQ.none_find) THEN
519     tof31_i = i
520     ELSE
521     tof31_i = -1
522     check = .FALSE.
523     ENDIF
524     ENDIF
525     ENDIF
526     ENDDO
527    
528     C bottom tof S32
529     DO i = 1,3
530     DO j = 1,2
531     tof32_event(j,i) = none_ev
532     IF ((tof32(j,i,itdc).LT.2000).AND.(tof32(j,i,itdc).GT.100))
533     + tof32_event(j,i) = tof32_event(j,i) + tdc_ev
534     ENDDO
535     ENDDO
536    
537     c find single paddle in upper tof with tdc and adc signal
538     tof32_i = none_find
539     tof32_j = none_find
540     check = .TRUE.
541     DO i = 1, 3
542     IF ((tof32_event(left,i).GE.1).AND.(tof32_event(right,i).GE.1))
543     + THEN
544     c check if an other paddle has also an event - then set flag
545     tof32_j = tof32_j + 2**(i-1)
546     IF (check.EQV..TRUE.) THEN
547     IF (tof32_i.EQ.none_find) THEN
548     tof32_i = i
549     ELSE
550     tof32_i = -1
551     check = .FALSE.
552     ENDIF
553     ENDIF
554     ENDIF
555 mocchiut 1.7 ENDDO
556 mocchiut 1.1
557 mocchiut 1.7 do i=1,6
558 mocchiut 1.1 tof_i_flag(i)=0
559     tof_j_flag(i)=0
560 mocchiut 1.7 enddo
561    
562     tof_i_flag(1)=tof11_i
563     tof_i_flag(2)=tof12_i
564     tof_i_flag(3)=tof21_i
565     tof_i_flag(4)=tof22_i
566     tof_i_flag(5)=tof31_i
567     tof_i_flag(6)=tof32_i
568    
569     tof_j_flag(1)=tof11_j
570     tof_j_flag(2)=tof12_j
571     tof_j_flag(3)=tof21_j
572     tof_j_flag(4)=tof22_j
573     tof_j_flag(5)=tof31_j
574     tof_j_flag(6)=tof32_j
575    
576     hitvec(1)=tof11_i
577     hitvec(2)=tof12_i
578     hitvec(3)=tof21_i
579     hitvec(4)=tof22_i
580     hitvec(5)=tof31_i
581     hitvec(6)=tof32_i
582 mocchiut 1.1
583    
584 mocchiut 1.4 C------------------------------------------------------------------
585 mocchiut 1.7 C-- calculate track position in paddle using timing difference
586     C-- this calculation is preliminary and uses some standard
587     C-- calibration values, but we need to find a rough position to
588     C-- be able to calculate artificial ADC values (needed for the
589     C-- timewalk...
590 mocchiut 1.4 C------------------------------------------------------------------
591    
592 mocchiut 1.7 do i=1,3
593 mocchiut 1.4 xtofpos(i)=100.
594     ytofpos(i)=100.
595 mocchiut 1.7 enddo
596    
597 mocchiut 1.4 C-----------------------------S1 --------------------------------
598    
599     IF (tof11_i.GT.none_find) THEN
600     ytofpos(1) = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
601 mocchiut 1.7 + -y_coor_lin11c(tof11_i,offset))/y_coor_lin11c(tof11_i,slope)
602 mocchiut 1.4 endif
603    
604     IF (tof12_i.GT.none_find) THEN
605     xtofpos(1) = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
606 mocchiut 1.7 + -x_coor_lin12c(tof12_i,offset))/x_coor_lin12c(tof12_i,slope)
607 mocchiut 1.4 endif
608    
609    
610     C-----------------------------S2 --------------------------------
611    
612     IF (tof21_i.GT.none_find) THEN
613     xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
614 mocchiut 1.7 + -x_coor_lin21c(tof21_i,offset))/x_coor_lin21c(tof21_i,slope)
615 mocchiut 1.4 endif
616    
617     IF (tof22_i.GT.none_find) THEN
618     ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
619 mocchiut 1.7 + -y_coor_lin22c(tof22_i,offset))/y_coor_lin22c(tof22_i,slope)
620 mocchiut 1.4 endif
621    
622    
623     C-----------------------------S3 --------------------------------
624    
625     IF (tof31_i.GT.none_find) THEN
626     ytofpos(3) = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
627 mocchiut 1.7 + -y_coor_lin31c(tof31_i,offset))/y_coor_lin31c(tof31_i,slope)
628 mocchiut 1.4 endif
629    
630     IF (tof32_i.GT.none_find) THEN
631     xtofpos(3) = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
632 mocchiut 1.7 + -x_coor_lin32c(tof32_i,offset))/x_coor_lin32c(tof32_i,slope)
633 mocchiut 1.4 endif
634    
635    
636     C----------------------------------------------------------------------
637     C--------------------- zenith angle theta ---------------------------
638     C----------------------------------------------------------------------
639 pamelats 1.9 C----------------------------- old ----------------------------------
640     c dx=0.
641     c dy=0.
642     c dr=0.
643     c theta13 = 0.
644     c
645     c IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find))
646     c & dx = xtofpos(1) - xtofpos(3)
647     c IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find))
648     c & dy = ytofpos(1) - ytofpos(3)
649     c dr = sqrt(dx*dx+dy*dy)
650     c theta13 = atan(dr/tofarm13)
651     c
652     c
653     C----------------------------- new ------------------------------
654    
655     xhelp1=0.
656     if (tof11_i.GT.none_find) xhelp1=tof11_x(tof11_i)
657     if (xtofpos(1).lt.100) xhelp1=xtofpos(1)
658 mocchiut 1.4
659 pamelats 1.9 yhelp1=0.
660     if (tof12_i.GT.none_find) yhelp1=tof12_y(tof12_i)
661     if (ytofpos(1).lt.100) yhelp1=ytofpos(1)
662    
663    
664     yhelp2=0.
665     if (tof32_i.GT.none_find) yhelp2=tof32_y(tof32_i)
666     if (ytofpos(3).lt.100) yhelp2=ytofpos(3)
667    
668     xhelp2=0.
669     if (tof31_i.GT.none_find) xhelp2=tof31_x(tof31_i)
670     if (xtofpos(3).lt.100) xhelp2=xtofpos(3)
671    
672    
673     dx=0.
674     dy=0.
675     dr=0.
676     theta13 = 0.
677    
678     dx = xhelp1 - xhelp2
679     dy = yhelp1 - yhelp2
680     dr = sqrt(dx*dx+dy*dy)
681     theta13 = atan(dr/tofarm13)
682 mocchiut 1.4
683    
684 mocchiut 1.7 C----------------------------------------------------------------------
685     C--- check charge:
686     C--- if Z=2 we should use the attenuation curve for helium to
687     C--- fill the artificail ADC values and NOT divide by "hepratio"
688     C--- if Z>2 we should do a correction to
689     C--- the k1 constants in the beta calculation
690     C----------------------------------------------------------------------
691    
692     iz = int(check_charge(theta13,hitvec))
693 pamelats 1.9 c write(*,*) 'charge in tofl2com',iz
694 mocchiut 1.4
695     C--------------------------------------------------------------------
696     C---- if TDCleft.and.TDCright and NO ADC insert artificial ADC
697     C---- values
698     C--------------------------------------------------------------------
699     c middle y (or x) position of the upper and middle ToF-Paddle
700     c DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/
701     c DATA tof12_y/ -13.75,-8.25,-2.75,2.75,8.25,13.75/
702     c DATA tof21_y/ 3.75,-3.75/ ! paddles in different order
703     c DATA tof22_x/ -4.5,4.5/
704     c DATA tof31_x/ -6.0,0.,6.0/
705     c DATA tof32_y/ -5.0,0.0,5.0/
706    
707    
708     C---------------------------- S1 -------------------------------------
709    
710 pamelats 1.9 c yhelp=0.
711     yhelp=100. ! WM
712 mocchiut 1.4 if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)
713     if (ytofpos(1).lt.100) yhelp=ytofpos(1)
714    
715     IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
716     i = tof11_i
717 mocchiut 1.6 if (adc(ch11a(i),hb11a(i)).eq.4095) then
718     xkorr = atten(left,11,i,yhelp)
719 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
720 mocchiut 1.4 tof11(left,i,iadc)=xkorr/cos(theta13)
721     adcflagtof(ch11a(i),hb11a(i)) = 1
722     endif
723 mocchiut 1.6 if (adc(ch11b(i),hb11b(i)).eq.4095) then
724     xkorr = atten(right,11,i,yhelp)
725 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
726 mocchiut 1.4 tof11(right,i,iadc)=xkorr/cos(theta13)
727     adcflagtof(ch11b(i),hb11b(i)) = 1
728     endif
729     ENDIF
730    
731 pamelats 1.9 c xhelp=0.
732     xhelp=100. ! WM
733 mocchiut 1.4 if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)
734     if (xtofpos(1).lt.100) xhelp=xtofpos(1)
735    
736     IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
737     i = tof12_i
738 mocchiut 1.6 if (adc(ch12a(i),hb12a(i)).eq.4095) then
739     xkorr = atten(left,12,i,xhelp)
740 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
741 mocchiut 1.4 tof12(left,i,iadc) = xkorr/cos(theta13)
742     adcflagtof(ch12a(i),hb12a(i)) = 1
743     endif
744 mocchiut 1.6 if (adc(ch12b(i),hb12b(i)).eq.4095) then
745     xkorr = atten(right,12,i,xhelp)
746 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
747 mocchiut 1.4 tof12(right,i,iadc) = xkorr/cos(theta13)
748     adcflagtof(ch12b(i),hb12b(i)) = 1
749     endif
750     ENDIF
751    
752     C-----------------------------S2 --------------------------------
753    
754 pamelats 1.9 c xhelp=0.
755     xhelp=100. ! WM
756 mocchiut 1.4 if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)
757     if (xtofpos(2).lt.100) xhelp=xtofpos(2)
758    
759     IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
760     i = tof21_i
761 mocchiut 1.6 if (adc(ch21a(i),hb21a(i)).eq.4095) then
762     xkorr = atten(left,21,i,xhelp)
763 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
764 mocchiut 1.4 tof21(left,i,iadc) = xkorr/cos(theta13)
765     adcflagtof(ch21a(i),hb21a(i)) = 1
766     endif
767 mocchiut 1.6 if (adc(ch21b(i),hb21b(i)).eq.4095) then
768     xkorr = atten(right,21,i,xhelp)
769 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
770 mocchiut 1.4 tof21(right,i,iadc) = xkorr/cos(theta13)
771     adcflagtof(ch21b(i),hb21b(i)) = 1
772     endif
773     ENDIF
774    
775    
776 pamelats 1.9 c yhelp=0.
777     yhelp=100. ! WM
778 mocchiut 1.4 if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)
779     if (ytofpos(2).lt.100) yhelp=ytofpos(2)
780    
781     IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
782     i = tof22_i
783 mocchiut 1.6 if (adc(ch22a(i),hb22a(i)).eq.4095) then
784     xkorr = atten(left,22,i,yhelp)
785 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
786 mocchiut 1.4 tof22(left,i,iadc) = xkorr/cos(theta13)
787     adcflagtof(ch22a(i),hb22a(i)) = 1
788     endif
789 mocchiut 1.6 if (adc(ch22b(i),hb22b(i)).eq.4095) then
790     xkorr = atten(right,22,i,yhelp)
791 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
792 mocchiut 1.4 tof22(right,i,iadc) = xkorr/cos(theta13)
793     adcflagtof(ch22b(i),hb22b(i)) = 1
794     endif
795     ENDIF
796    
797     C-----------------------------S3 --------------------------------
798    
799 pamelats 1.9 c yhelp=0.
800     yhelp=100. ! WM
801 mocchiut 1.4 if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)
802     if (ytofpos(3).lt.100) yhelp=ytofpos(3)
803    
804     IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
805     i = tof31_i
806 mocchiut 1.6 if (adc(ch31a(i),hb31a(i)).eq.4095) then
807     xkorr = atten(left,31,i,yhelp)
808 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
809 mocchiut 1.4 tof31(left,i,iadc) = xkorr/cos(theta13)
810     adcflagtof(ch31a(i),hb31a(i)) = 1
811     endif
812 mocchiut 1.6 if (adc(ch31b(i),hb31b(i)).eq.4095) then
813     xkorr = atten(right,31,i,yhelp)
814 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
815 mocchiut 1.4 tof31(right,i,iadc) = xkorr/cos(theta13)
816     adcflagtof(ch31b(i),hb31b(i)) = 1
817     endif
818     ENDIF
819    
820 pamelats 1.9 c xhelp=0.
821     xhelp=100. ! WM
822 mocchiut 1.4 if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)
823     if (xtofpos(3).lt.100) xhelp=xtofpos(3)
824    
825     IF (tof32_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
826     i = tof32_i
827 mocchiut 1.6 if (adc(ch32a(i),hb32a(i)).eq.4095) then
828     xkorr = atten(left,32,i,xhelp)
829 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
830 mocchiut 1.4 tof32(left,i,iadc) = xkorr/cos(theta13)
831     adcflagtof(ch32a(i),hb32a(i)) = 1
832     endif
833 mocchiut 1.6 if (adc(ch32b(i),hb32b(i)).eq.4095) then
834     xkorr = atten(right,32,i,xhelp)
835 mocchiut 1.7 if (iz.le.1) xkorr=xkorr/hepratio
836 mocchiut 1.4 tof32(right,i,iadc) = xkorr/cos(theta13)
837     adcflagtof(ch32b(i),hb32b(i)) = 1
838     endif
839     ENDIF
840    
841 mocchiut 1.1
842 mocchiut 1.7 C-------------------------------------------------------------------
843 mocchiut 1.1 C--------------------Time walk correction -------------------------
844 mocchiut 1.7 C-------------------------------------------------------------------
845     C-------------------------------------------------------------------
846     C Now there is for each hitted paddle a TDC and ADC value, if the
847     C TDC was < 4095.
848     C There might be also TDC-ADC pairs in paddles not hitted
849    
850     C-------------------------------------------------------------------
851     C If we have multiple paddles hit, so that no artificial ADC value
852     C is created, we set the raw TDC value as "tdc_c"
853     C-------------------------------------------------------------------
854     c
855     c do i=1,4
856     c do j=1,12
857     c tdc_c(i,j) = tdc(i,j)
858     c enddo
859     c enddo
860     c
861     C---- Let's correct the raw TDC value with the time walk ---------
862 mocchiut 1.1
863     DO i=1,8
864 mocchiut 1.7 if ((tdc(ch11a(i),hb11a(i)).lt.4095).and.
865     & (tof11(left,i,iadc).lt.3786)) THEN
866     xhelp = tw11(left,i)/(tof11(left,i,iadc)**0.5)
867     tof11(left,i,itdc) = tof11(left,i,itdc) + xhelp
868     tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)
869     ENDIF
870    
871     if ((tdc(ch11b(i),hb11b(i)).lt.4095).and.
872     & (tof11(right,i,iadc).lt.3786)) THEN
873     xhelp = tw11(right,i)/(tof11(right,i,iadc)**0.5)
874     tof11(right,i,itdc) = tof11(right,i,itdc) + xhelp
875     tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)
876     ENDIF
877 mocchiut 1.1 ENDDO
878    
879 mocchiut 1.7
880 mocchiut 1.1 DO i=1,6
881 mocchiut 1.7 if ((tdc(ch12a(i),hb12a(i)).lt.4095).and.
882     & (tof12(left,i,iadc).lt.3786)) THEN
883     xhelp = tw12(left,i)/(tof12(left,i,iadc)**0.5)
884     tof12(left,i,itdc) = tof12(left,i,itdc) + xhelp
885     tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)
886     ENDIF
887    
888     if ((tdc(ch12b(i),hb12b(i)).lt.4095).and.
889     & (tof12(right,i,iadc).lt.3786)) THEN
890     xhelp = tw12(right,i)/(tof12(right,i,iadc)**0.5)
891     tof12(right,i,itdc) = tof12(right,i,itdc) + xhelp
892     tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)
893     ENDIF
894 mocchiut 1.1 ENDDO
895 mocchiut 1.7
896 mocchiut 1.1 C----
897 mocchiut 1.7 DO I=1,2
898     if ((tdc(ch21a(i),hb21a(i)).lt.4095).and.
899     & (tof21(left,i,iadc).lt.3786)) THEN
900     xhelp = tw21(left,i)/(tof21(left,i,iadc)**0.5)
901     tof21(left,i,itdc) = tof21(left,i,itdc) + xhelp
902     tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)
903     ENDIF
904    
905     if ((tdc(ch21b(i),hb21b(i)).lt.4095).and.
906     & (tof21(right,i,iadc).lt.3786)) THEN
907     xhelp = tw21(right,i)/(tof21(right,i,iadc)**0.5)
908     tof21(right,i,itdc) = tof21(right,i,itdc) + xhelp
909     tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)
910     ENDIF
911     ENDDO
912    
913     DO I=1,2
914     if ((tdc(ch22a(i),hb22a(i)).lt.4095).and.
915     & (tof22(left,i,iadc).lt.3786)) THEN
916     xhelp = tw22(left,i)/(tof22(left,i,iadc)**0.5)
917     tof22(left,i,itdc) = tof22(left,i,itdc) + xhelp
918     tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)
919     ENDIF
920    
921     if ((tdc(ch22b(i),hb22b(i)).lt.4095).and.
922     & (tof22(right,i,iadc).lt.3786)) THEN
923     xhelp = tw22(right,i)/(tof22(right,i,iadc)**0.5)
924     tof22(right,i,itdc) = tof22(right,i,itdc) + xhelp
925     tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)
926     ENDIF
927 mocchiut 1.1 ENDDO
928 mocchiut 1.7
929 mocchiut 1.1 C----
930 mocchiut 1.7 DO I=1,3
931     if ((tdc(ch31a(i),hb31a(i)).lt.4095).and.
932     & (tof31(left,i,iadc).lt.3786)) THEN
933     xhelp = tw31(left,i)/(tof31(left,i,iadc)**0.5)
934     tof31(left,i,itdc) = tof31(left,i,itdc) + xhelp
935     tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)
936     ENDIF
937    
938     if ((tdc(ch31b(i),hb31b(i)).lt.4095).and.
939     & (tof31(right,i,iadc).lt.3786)) THEN
940     xhelp = tw31(right,i)/(tof31(right,i,iadc)**0.5)
941     tof31(right,i,itdc) = tof31(right,i,itdc) + xhelp
942     tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)
943     ENDIF
944     ENDDO
945    
946     DO I=1,3
947     if ((tdc(ch32a(i),hb32a(i)).lt.4095).and.
948     & (tof32(left,i,iadc).lt.3786)) THEN
949     xhelp = tw32(left,i)/(tof32(left,i,iadc)**0.5)
950     tof32(left,i,itdc) = tof32(left,i,itdc) + xhelp
951     tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)
952     ENDIF
953    
954     if ((tdc(ch32b(i),hb32b(i)).lt.4095).and.
955     & (tof32(right,i,iadc).lt.3786)) THEN
956     xhelp = tw32(right,i)/(tof32(right,i,iadc)**0.5)
957     tof32(right,i,itdc) = tof32(right,i,itdc) + xhelp
958     tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)
959     ENDIF
960     ENDDO
961    
962 pamelats 1.9
963 mocchiut 1.7 C---------------------------------------------------------------
964     C--- calculate track position in paddle using timing difference
965     C--- now using the time-walk corrected TDC values
966     C---------------------------------------------------------------
967    
968     do i=1,3
969     xtofpos(i)=100.
970     ytofpos(i)=100.
971     enddo
972    
973     C-----------------------------S1 --------------------------------
974    
975     IF (tof11_i.GT.none_find) THEN
976     ytofpos(1) = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
977     + -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)
978 pamelats 1.9 i=tof11_i
979 mocchiut 1.7 endif
980    
981     IF (tof12_i.GT.none_find) THEN
982     xtofpos(1) = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
983     + -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)
984 pamelats 1.9 i=tof12_i
985 mocchiut 1.7 endif
986    
987    
988     C-----------------------------S2 --------------------------------
989    
990     IF (tof21_i.GT.none_find) THEN
991     xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
992     + -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)
993 pamelats 1.9 i=tof21_i
994 mocchiut 1.7 endif
995    
996     IF (tof22_i.GT.none_find) THEN
997     ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
998     + -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)
999 pamelats 1.9 i=tof22_i
1000 mocchiut 1.7 endif
1001    
1002    
1003     C-----------------------------S3 --------------------------------
1004    
1005     IF (tof31_i.GT.none_find) THEN
1006     ytofpos(3) = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
1007     + -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)
1008 pamelats 1.9 i=tof31_i
1009 mocchiut 1.7 endif
1010    
1011     IF (tof32_i.GT.none_find) THEN
1012     xtofpos(3) = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
1013     + -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)
1014 pamelats 1.9 i=tof32_i
1015 mocchiut 1.7 endif
1016    
1017    
1018     c do i=1,3
1019     c if (abs(xtofpos(i)).gt.100.) then
1020     c xtofpos(i)=101.
1021     c endif
1022     c if (abs(ytofpos(i)).gt.100.) then
1023     c ytofpos(i)=101.
1024     c endif
1025     c enddo
1026    
1027 pamelats 1.9
1028 mocchiut 1.7 C-- restrict TDC measurements to physical paddle dimensions +/- 10 cm
1029     C-- this cut is now stronger than in the old versions
1030 mocchiut 1.1
1031 mocchiut 1.7 if (abs(xtofpos(1)).gt.31.) xtofpos(1)=101.
1032     if (abs(xtofpos(2)).gt.19.) xtofpos(2)=101.
1033     if (abs(xtofpos(3)).gt.19.) xtofpos(3)=101.
1034    
1035     if (abs(ytofpos(1)).gt.26.) ytofpos(1)=101.
1036     if (abs(ytofpos(2)).gt.18.) ytofpos(2)=101.
1037     if (abs(ytofpos(3)).gt.18.) ytofpos(3)=101.
1038    
1039     C----------------------------------------------------------------------
1040     C--------------------- zenith angle theta ---------------------------
1041     C----------------------------------------------------------------------
1042 pamelats 1.9 C------------------- improved calculation ---------------------------
1043    
1044     xhelp1=0.
1045     if (tof11_i.GT.none_find) xhelp1=tof11_x(tof11_i)
1046     if (xtofpos(1).lt.100) xhelp1=xtofpos(1)
1047    
1048     yhelp1=0.
1049     if (tof12_i.GT.none_find) yhelp1=tof12_y(tof12_i)
1050     if (ytofpos(1).lt.100) yhelp1=ytofpos(1)
1051    
1052     yhelp2=0.
1053     if (tof32_i.GT.none_find) yhelp2=tof32_y(tof32_i)
1054     if (ytofpos(3).lt.100) yhelp2=ytofpos(3)
1055    
1056     xhelp2=0.
1057     if (tof31_i.GT.none_find) xhelp2=tof31_x(tof31_i)
1058     if (xtofpos(3).lt.100) xhelp2=xtofpos(3)
1059    
1060    
1061     dx=0.
1062     dy=0.
1063     dr=0.
1064     theta13 = 0.
1065    
1066     dx = xhelp1 - xhelp2
1067     dy = yhelp1 - yhelp2
1068     dr = sqrt(dx*dx+dy*dy)
1069     theta13 = atan(dr/tofarm13)
1070 mocchiut 1.7
1071 mocchiut 1.1
1072 mocchiut 1.7 C------------------------------------------------------------------
1073 mocchiut 1.1 C----------------------------------------------------------------------
1074     C------------------angle and ADC(x) correction
1075     C----------------------------------------------------------------------
1076     C-----------------------------S1 --------------------------------
1077     c middle y (or x) position of the upper and middle ToF-Paddle
1078     c DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/
1079     c DATA tof12_y/ -13.75,-8.25,-2.75,2.75,8.25,13.75/
1080 mocchiut 1.4 c DATA tof21_y/ 3.75,-3.75/ ! paddles in different order
1081 mocchiut 1.1 c DATA tof22_x/ -4.5,4.5/
1082     c DATA tof31_x/ -6.0,0.,6.0/
1083     c DATA tof32_y/ -5.0,0.0,5.0/
1084    
1085     yhelp=0.
1086 pamelats 1.9 c yhelp=100.
1087 mocchiut 1.1 if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)
1088     if (ytofpos(1).lt.100) yhelp=ytofpos(1)
1089    
1090     IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
1091    
1092     i = tof11_i
1093 mocchiut 1.6 if (tof11(left,i,iadc).lt.3786) then
1094     c if (adc(ch11a(i),hb11a(i)).lt.4095) then
1095 mocchiut 1.4 tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta13)
1096 mocchiut 1.6 xkorr = atten(left,11,i,yhelp)
1097 pam-de 1.8 xkorr=xkorr/hepratio
1098 mocchiut 1.1 adctof_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr
1099     endif
1100    
1101 mocchiut 1.6 if (tof11(right,i,iadc).lt.3786) then
1102     c if (adc(ch11b(i),hb11b(i)).lt.4095) then
1103 mocchiut 1.4 tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta13)
1104 mocchiut 1.6 xkorr = atten(right,11,i,yhelp)
1105 pam-de 1.8 xkorr=xkorr/hepratio
1106 mocchiut 1.1 adctof_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr
1107     endif
1108     ENDIF
1109    
1110     xhelp=0.
1111 pamelats 1.9 c xhelp=100.
1112 mocchiut 1.1 if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)
1113     if (xtofpos(1).lt.100) xhelp=xtofpos(1)
1114    
1115     IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
1116    
1117     i = tof12_i
1118 mocchiut 1.6 if (tof12(left,i,iadc).lt.3786) then
1119     c if (adc(ch12a(i),hb12a(i)).lt.4095) then
1120 mocchiut 1.4 tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta13)
1121 mocchiut 1.6 xkorr = atten(left,12,i,xhelp)
1122 pam-de 1.8 xkorr=xkorr/hepratio
1123 mocchiut 1.1 adctof_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr
1124     endif
1125    
1126 mocchiut 1.6 if (tof12(right,i,iadc).lt.3786) then
1127     c if (adc(ch12b(i),hb12b(i)).lt.4095) then
1128 mocchiut 1.4 tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta13)
1129 mocchiut 1.6 xkorr = atten(right,12,i,xhelp)
1130 pam-de 1.8 xkorr=xkorr/hepratio
1131 mocchiut 1.1 adctof_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr
1132     endif
1133     ENDIF
1134    
1135     C-----------------------------S2 --------------------------------
1136    
1137     xhelp=0.
1138 pamelats 1.9 c xhelp=100.
1139 mocchiut 1.1 if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)
1140     if (xtofpos(2).lt.100) xhelp=xtofpos(2)
1141    
1142     IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
1143    
1144     i = tof21_i
1145 mocchiut 1.6 if (tof21(left,i,iadc).lt.3786) then
1146     c if (adc(ch21a(i),hb21a(i)).lt.4095) then
1147 mocchiut 1.4 tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta13)
1148 mocchiut 1.6 xkorr = atten(left,21,i,xhelp)
1149 pam-de 1.8 xkorr=xkorr/hepratio
1150 mocchiut 1.1 adctof_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr
1151     endif
1152    
1153 mocchiut 1.6 if (tof21(right,i,iadc).lt.3786) then
1154     c if (adc(ch21b(i),hb21b(i)).lt.4095) then
1155 mocchiut 1.4 tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta13)
1156 mocchiut 1.1 xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))
1157 mocchiut 1.6 xkorr = atten(right,21,i,xhelp)
1158 pam-de 1.8 xkorr=xkorr/hepratio
1159 mocchiut 1.1 adctof_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr
1160     endif
1161     ENDIF
1162    
1163    
1164     yhelp=0.
1165 pamelats 1.9 c yhelp=100.
1166 mocchiut 1.1 if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)
1167     if (ytofpos(2).lt.100) yhelp=ytofpos(2)
1168    
1169     IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
1170    
1171     i = tof22_i
1172 mocchiut 1.6 if (tof22(left,i,iadc).lt.3786) then
1173     c if (adc(ch22a(i),hb22a(i)).lt.4095) then
1174 mocchiut 1.4 tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta13)
1175 mocchiut 1.6 xkorr = atten(left,22,i,yhelp)
1176 pam-de 1.8 xkorr=xkorr/hepratio
1177 mocchiut 1.1 adctof_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr
1178     endif
1179    
1180 mocchiut 1.6 if (tof22(right,i,iadc).lt.3786) then
1181     c if (adc(ch22b(i),hb22b(i)).lt.4095) then
1182 mocchiut 1.4 tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta13)
1183 mocchiut 1.6 xkorr = atten(right,22,i,yhelp)
1184 pam-de 1.8 xkorr=xkorr/hepratio
1185 mocchiut 1.1 adctof_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr
1186     endif
1187     ENDIF
1188    
1189     C-----------------------------S3 --------------------------------
1190    
1191     yhelp=0.
1192 pamelats 1.9 c yhelp=100.
1193 mocchiut 1.1 if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)
1194     if (ytofpos(3).lt.100) yhelp=ytofpos(3)
1195    
1196     IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
1197    
1198     i = tof31_i
1199 mocchiut 1.6 if (tof31(left,i,iadc).lt.3786) then
1200     c if (adc(ch31a(i),hb31a(i)).lt.4095) then
1201 mocchiut 1.4 tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta13)
1202 mocchiut 1.6 xkorr = atten(left,31,i,yhelp)
1203 pam-de 1.8 xkorr=xkorr/hepratio
1204 mocchiut 1.1 adctof_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr
1205     endif
1206    
1207 mocchiut 1.6 if (tof31(right,i,iadc).lt.3786) then
1208     c if (adc(ch31b(i),hb31b(i)).lt.4095) then
1209 mocchiut 1.4 tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta13)
1210 mocchiut 1.6 xkorr = atten(right,31,i,yhelp)
1211 pam-de 1.8 xkorr=xkorr/hepratio
1212 mocchiut 1.1 adctof_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr
1213     endif
1214     ENDIF
1215    
1216     xhelp=0.
1217 pamelats 1.9 c xhelp=100.
1218 mocchiut 1.1 if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)
1219     if (xtofpos(3).lt.100) xhelp=xtofpos(3)
1220    
1221     IF (tof32_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
1222    
1223     i = tof32_i
1224 mocchiut 1.6 if (tof32(left,i,iadc).lt.3786) then
1225     c if (adc(ch32a(i),hb32a(i)).lt.4095) then
1226 mocchiut 1.4 tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta13)
1227 mocchiut 1.6 xkorr = atten(left,32,i,xhelp)
1228 pam-de 1.8 xkorr=xkorr/hepratio
1229 mocchiut 1.1 adctof_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr
1230     endif
1231    
1232 mocchiut 1.6 if (tof32(right,i,iadc).lt.3786) then
1233     c if (adc(ch32b(i),hb32b(i)).lt.4095) then
1234 mocchiut 1.4 tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta13)
1235 mocchiut 1.6 xkorr = atten(right,32,i,xhelp)
1236 pam-de 1.8 xkorr=xkorr/hepratio
1237 mocchiut 1.1 adctof_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr
1238     endif
1239     ENDIF
1240    
1241 mocchiut 1.4 C--------------------------------------------------------------------
1242 mocchiut 1.1 C----------------------calculate Beta ------------------------------
1243 mocchiut 1.4 C--------------------------------------------------------------------
1244     C-------------------difference of sums -----------------------------
1245 mocchiut 1.1 C
1246     C DS = (t1+t2) - t3+t4)
1247     C DS = c1 + c2/beta*cos(theta)
1248     C c2 = 2d/c gives c2 = 2d/(c*TDCresolution) TDC=50ps/channel
1249     C => c2 = ca.60 for 0.45 m c2 = ca.109 for 0.81 m
1250     C since TDC resolution varies slightly c2 has to be calibrated
1251    
1252     C S11 - S31
1253 mocchiut 1.4
1254     IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1255     & (ytofpos(1).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1256 mocchiut 1.1 xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1257     xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1258     ds = xhelp1-xhelp2
1259     ihelp=(tof11_i-1)*3+tof31_i
1260     c1 = k_S11S31(1,ihelp)
1261 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrA1
1262 mocchiut 1.1 c2 = k_S11S31(2,ihelp)
1263     betatof_a(1) = c2/(cos(theta13)*(ds-c1))
1264 mocchiut 1.2
1265     C------- ToF Mask - S11 - S31
1266    
1267     tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
1268     $ tofmask(ch11a(tof11_i),hb11a(tof11_i)) + 1
1269     tofmask(ch11b(tof11_i),hb11b(tof11_i)) =
1270     $ tofmask(ch11b(tof11_i),hb11b(tof11_i)) + 1
1271    
1272     tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1273     $ tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1274     tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1275     $ tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1276    
1277     C-------
1278    
1279 mocchiut 1.1 ENDIF
1280    
1281     C S11 - S32
1282 mocchiut 1.4
1283     IF ((tof11_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1284     & (ytofpos(1).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1285 mocchiut 1.1 xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1286     xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1287     ds = xhelp1-xhelp2
1288     ihelp=(tof11_i-1)*3+tof32_i
1289     c1 = k_S11S32(1,ihelp)
1290 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrA1
1291 mocchiut 1.1 c2 = k_S11S32(2,ihelp)
1292     betatof_a(2) = c2/(cos(theta13)*(ds-c1))
1293 mocchiut 1.2
1294     C------- ToF Mask - S11 - S32
1295    
1296     tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
1297     $ tofmask(ch11a(tof11_i),hb11a(tof11_i)) + 1
1298     tofmask(ch11b(tof11_i),hb11b(tof11_i)) =
1299     $ tofmask(ch11b(tof11_i),hb11b(tof11_i)) + 1
1300    
1301     tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1302     $ tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1303     tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1304     $ tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1305    
1306     C-------
1307    
1308 mocchiut 1.1 ENDIF
1309 mocchiut 1.2
1310 mocchiut 1.1 C S12 - S31
1311 mocchiut 1.4
1312     IF ((tof12_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1313     & (xtofpos(1).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1314 mocchiut 1.1 xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1315     xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1316     ds = xhelp1-xhelp2
1317     ihelp=(tof12_i-1)*3+tof31_i
1318     c1 = k_S12S31(1,ihelp)
1319 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrA1
1320 mocchiut 1.1 c2 = k_S12S31(2,ihelp)
1321     betatof_a(3) = c2/(cos(theta13)*(ds-c1))
1322 mocchiut 1.2
1323     C------- ToF Mask - S12 - S31
1324    
1325     tofmask(ch12a(tof12_i),hb12a(tof12_i)) =
1326     $ tofmask(ch12a(tof12_i),hb12a(tof12_i)) + 1
1327     tofmask(ch12b(tof12_i),hb12b(tof12_i)) =
1328     $ tofmask(ch12b(tof12_i),hb12b(tof12_i)) + 1
1329    
1330     tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1331     $ tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1332     tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1333     $ tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1334    
1335     C-------
1336    
1337 mocchiut 1.1 ENDIF
1338 mocchiut 1.2
1339 mocchiut 1.1 C S12 - S32
1340 mocchiut 1.4
1341     IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1342     & (xtofpos(1).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1343 mocchiut 1.1 xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1344     xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1345     ds = xhelp1-xhelp2
1346     ihelp=(tof12_i-1)*3+tof32_i
1347     c1 = k_S12S32(1,ihelp)
1348 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrA1
1349 mocchiut 1.1 c2 = k_S12S32(2,ihelp)
1350     betatof_a(4) = c2/(cos(theta13)*(ds-c1))
1351 mocchiut 1.2
1352     C------- ToF Mask - S12 - S32
1353    
1354     tofmask(ch12a(tof12_i),hb12a(tof12_i)) =
1355     $ tofmask(ch12a(tof12_i),hb12a(tof12_i)) + 1
1356     tofmask(ch12b(tof12_i),hb12b(tof12_i)) =
1357     $ tofmask(ch12b(tof12_i),hb12b(tof12_i)) + 1
1358    
1359     tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1360     $ tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1361     tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1362     $ tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1363    
1364     C-------
1365    
1366 mocchiut 1.1 ENDIF
1367    
1368     C S21 - S31
1369 mocchiut 1.4
1370     IF ((tof21_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1371     & (xtofpos(2).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1372 mocchiut 1.1 xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1373     xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1374     ds = xhelp1-xhelp2
1375     ihelp=(tof21_i-1)*3+tof31_i
1376     c1 = k_S21S31(1,ihelp)
1377 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrB1
1378 mocchiut 1.1 c2 = k_S21S31(2,ihelp)
1379 mocchiut 1.4 betatof_a(5) = c2/(cos(theta13)*(ds-c1))
1380 mocchiut 1.2
1381     C------- ToF Mask - S21 - S31
1382    
1383     tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1384     $ tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1385     tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1386     $ tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1387    
1388     tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1389     $ tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1390     tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1391     $ tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1392    
1393     C-------
1394    
1395 mocchiut 1.1 ENDIF
1396    
1397     C S21 - S32
1398 mocchiut 1.4
1399     IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1400     & (xtofpos(2).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1401 mocchiut 1.1 xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1402     xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1403     ds = xhelp1-xhelp2
1404     ihelp=(tof21_i-1)*3+tof32_i
1405     c1 = k_S21S32(1,ihelp)
1406 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrB1
1407 mocchiut 1.1 c2 = k_S21S32(2,ihelp)
1408 mocchiut 1.4 betatof_a(6) = c2/(cos(theta13)*(ds-c1))
1409 mocchiut 1.2
1410     C------- ToF Mask - S21 - S32
1411    
1412     tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1413     $ tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1414     tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1415     $ tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1416    
1417     tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1418     $ tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1419     tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1420     $ tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1421    
1422     C-------
1423    
1424 mocchiut 1.1 ENDIF
1425    
1426     C S22 - S31
1427 mocchiut 1.4
1428     IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1429     & (ytofpos(2).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1430 mocchiut 1.1 xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1431     xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1432     ds = xhelp1-xhelp2
1433     ihelp=(tof22_i-1)*3+tof31_i
1434     c1 = k_S22S31(1,ihelp)
1435 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrB1
1436 mocchiut 1.1 c2 = k_S22S31(2,ihelp)
1437     betatof_a(7) = c2/(cos(theta13)*(ds-c1))
1438 mocchiut 1.2
1439     C------- ToF Mask - S22 - S31
1440    
1441     tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1442     $ tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1443     tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1444     $ tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1445    
1446     tofmask(ch31a(tof31_i),hb31a(tof31_i)) =
1447     $ tofmask(ch31a(tof31_i),hb31a(tof31_i)) + 1
1448     tofmask(ch31b(tof31_i),hb31b(tof31_i)) =
1449     $ tofmask(ch31b(tof31_i),hb31b(tof31_i)) + 1
1450    
1451     C-------
1452    
1453 mocchiut 1.1 ENDIF
1454    
1455     C S22 - S32
1456 mocchiut 1.4
1457     IF ((tof22_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1458     & (ytofpos(2).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1459 mocchiut 1.1 xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1460     xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1461     ds = xhelp1-xhelp2
1462     ihelp=(tof22_i-1)*3+tof32_i
1463     c1 = k_S22S32(1,ihelp)
1464 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrB1
1465 mocchiut 1.1 c2 = k_S22S32(2,ihelp)
1466     betatof_a(8) = c2/(cos(theta13)*(ds-c1))
1467 mocchiut 1.2
1468     C------- ToF Mask - S22 - S32
1469    
1470     tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1471     $ tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1472     tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1473     $ tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1474    
1475     tofmask(ch32a(tof32_i),hb32a(tof32_i)) =
1476     $ tofmask(ch32a(tof32_i),hb32a(tof32_i)) + 1
1477     tofmask(ch32b(tof32_i),hb32b(tof32_i)) =
1478     $ tofmask(ch32b(tof32_i),hb32b(tof32_i)) + 1
1479    
1480     C-------
1481    
1482 mocchiut 1.1 ENDIF
1483    
1484     C S11 - S21
1485 mocchiut 1.4
1486     IF ((tof11_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
1487     & (ytofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN
1488 mocchiut 1.1 xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1489     xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1490     ds = xhelp1-xhelp2
1491     ihelp=(tof11_i-1)*2+tof21_i
1492     c1 = k_S11S21(1,ihelp)
1493 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrC1
1494 mocchiut 1.1 c2 = k_S11S21(2,ihelp)
1495     betatof_a(9) = c2/(cos(theta13)*(ds-c1))
1496 mocchiut 1.2
1497     C------- ToF Mask - S11 - S21
1498    
1499     tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
1500     $ tofmask(ch11a(tof11_i),hb11a(tof11_i)) + 1
1501     tofmask(ch11b(tof11_i),hb11b(tof11_i)) =
1502     $ tofmask(ch11b(tof11_i),hb11b(tof11_i)) + 1
1503    
1504     tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1505     $ tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1506     tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1507     $ tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1508    
1509     C-------
1510    
1511 mocchiut 1.1 ENDIF
1512    
1513     C S11 - S22
1514 mocchiut 1.4
1515     IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
1516     & (ytofpos(1).NE.101.).AND.(ytofpos(2).NE.101.)) THEN
1517 mocchiut 1.1 xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1518     xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1519     ds = xhelp1-xhelp2
1520     ihelp=(tof11_i-1)*2+tof22_i
1521     c1 = k_S11S22(1,ihelp)
1522 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrC1
1523 mocchiut 1.1 c2 = k_S11S22(2,ihelp)
1524     betatof_a(10) = c2/(cos(theta13)*(ds-c1))
1525 mocchiut 1.2
1526     C------- ToF Mask - S11 - S22
1527    
1528     tofmask(ch11a(tof11_i),hb11a(tof11_i)) =
1529     $ tofmask(ch11a(tof11_i),hb11a(tof11_i)) + 1
1530     tofmask(ch11b(tof11_i),hb11b(tof11_i)) =
1531     $ tofmask(ch11b(tof11_i),hb11b(tof11_i)) + 1
1532    
1533     tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1534     $ tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1535     tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1536     $ tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1537    
1538     C-------
1539    
1540 mocchiut 1.1 ENDIF
1541    
1542     C S12 - S21
1543 mocchiut 1.4
1544     IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
1545     & (xtofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN
1546 mocchiut 1.1 xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1547     xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1548     ds = xhelp1-xhelp2
1549     ihelp=(tof12_i-1)*2+tof21_i
1550     c1 = k_S12S21(1,ihelp)
1551 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrC1
1552 mocchiut 1.1 c2 = k_S12S21(2,ihelp)
1553     betatof_a(11) = c2/(cos(theta13)*(ds-c1))
1554 mocchiut 1.2
1555     C------- ToF Mask - S12 - S21
1556    
1557     tofmask(ch12a(tof12_i),hb12a(tof12_i)) =
1558     $ tofmask(ch12a(tof12_i),hb12a(tof12_i)) + 1
1559     tofmask(ch12b(tof12_i),hb12b(tof12_i)) =
1560     $ tofmask(ch12b(tof12_i),hb12b(tof12_i)) + 1
1561    
1562     tofmask(ch21a(tof21_i),hb21a(tof21_i)) =
1563     $ tofmask(ch21a(tof21_i),hb21a(tof21_i)) + 1
1564     tofmask(ch21b(tof21_i),hb21b(tof21_i)) =
1565     $ tofmask(ch21b(tof21_i),hb21b(tof21_i)) + 1
1566    
1567     C-------
1568    
1569 mocchiut 1.1 ENDIF
1570    
1571     C S12 - S22
1572 mocchiut 1.4
1573     IF ((tof12_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
1574     & (xtofpos(1).NE.101.).AND.(ytofpos(2).NE.101.)) THEN
1575 mocchiut 1.1 xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1576     xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1577     ds = xhelp1-xhelp2
1578     ihelp=(tof12_i-1)*2+tof22_i
1579     c1 = k_S12S22(1,ihelp)
1580 mocchiut 1.7 if (iz.gt.2) c1 = c1 + k1corrC1
1581 mocchiut 1.1 c2 = k_S12S22(2,ihelp)
1582     betatof_a(12) = c2/(cos(theta13)*(ds-c1))
1583 mocchiut 1.2
1584     C------- ToF Mask - S12 - S22
1585    
1586     tofmask(ch12a(tof12_i),hb12a(tof12_i)) =
1587     $ tofmask(ch12a(tof12_i),hb12a(tof12_i)) + 1
1588     tofmask(ch12b(tof12_i),hb12b(tof12_i)) =
1589     $ tofmask(ch12b(tof12_i),hb12b(tof12_i)) + 1
1590    
1591     tofmask(ch22a(tof22_i),hb22a(tof22_i)) =
1592     $ tofmask(ch22a(tof22_i),hb22a(tof22_i)) + 1
1593     tofmask(ch22b(tof22_i),hb22b(tof22_i)) =
1594     $ tofmask(ch22b(tof22_i),hb22b(tof22_i)) + 1
1595    
1596     C-------
1597    
1598 mocchiut 1.1 ENDIF
1599 mocchiut 1.2
1600     C---------------------------------------------------------
1601 mocchiut 1.7 C
1602     C icount=0
1603     C sw=0.
1604     C sxw=0.
1605     C beta_mean=100.
1606     C
1607     C do i=1,12
1608     C if ((betatof_a(i).gt.-1.5).and.(betatof_a(i).lt.1.5)) then
1609     C icount= icount+1
1610     C if (i.le.4) w_i=1./(0.13**2.)
1611     C if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)
1612     C if (i.ge.9) w_i=1./(0.25**2.) ! to be checked
1613     C sxw=sxw + betatof_a(i)*w_i
1614     C sw =sw + w_i
1615     C endif
1616     C enddo
1617     C
1618     C if (icount.gt.0) beta_mean=sxw/sw
1619     C betatof_a(13) = beta_mean
1620     C
1621 pam-de 1.8
1622 mocchiut 1.7 C-------- New mean beta calculation -----------------------
1623 mocchiut 1.1
1624 mocchiut 1.7 do i=1,12
1625     btemp(i) = betatof_a(i)
1626     enddo
1627 mocchiut 1.1
1628 pam-de 1.8 betatof_a(13)=newbeta(1,btemp,hitvec,10.,10.,20.)
1629 mocchiut 1.1
1630 mocchiut 1.7 C--------------------------------------------------------------
1631     C write(*,*) betatof_a
1632 mocchiut 1.4 c write(*,*) xtofpos
1633     c write(*,*) ytofpos
1634 mocchiut 1.6 c write(*,*)'tofl2com beta', betatof_a
1635 mocchiut 1.4 C write(*,*) adcflagtof
1636 mocchiut 1.6 c write(*,*) 'tofl2com'
1637     c write(*,*) xtofpos
1638     c write(*,*) ytofpos
1639     c write(*,*) xtr_tof
1640     c write(*,*) ytr_tof
1641    
1642 mocchiut 1.1 100 continue
1643    
1644     C
1645     RETURN
1646     END
1647 mocchiut 1.4
1648 mocchiut 1.6
1649     C------------------------------------------------------------------
1650     C------------------------------------------------------------------
1651    
1652     function atten(is,ilay,ipad,x)
1653     include 'input_tof.txt'
1654     real atten
1655     real x
1656     real xmin,xmax
1657     integer ilay,ipad
1658    
1659     * S11 8 paddles 33.0 x 5.1 cm
1660     * S12 6 paddles 40.8 x 5.5 cm
1661     * S21 2 paddles 18.0 x 7.5 cm
1662     * S22 2 paddles 15.0 x 9.0 cm
1663     * S31 3 paddles 15.0 x 6.0 cm
1664     * S32 3 paddles 18.0 x 5.0 cm
1665    
1666    
1667     c if (ilay.eq.11) write(*,*) 'start ',ipad,is,adcx11(is,ipad,1),
1668     c & adcx11(is,ipad,2),adcx11(is,ipad,3),adcx11(is,ipad,4)
1669     c if (ilay.eq.12) write(*,*) 'start ',ipad,is,adcx12(is,ipad,1),
1670     c & adcx12(is,ipad,2),adcx12(is,ipad,3),adcx12(is,ipad,4)
1671    
1672    
1673     if (ilay.eq.11) xmin=-33.0/2.
1674     if (ilay.eq.11) xmax= 33.0/2.
1675     if (ilay.eq.12) xmin=-40.8/2.
1676     if (ilay.eq.12) xmax= 40.8/2.
1677    
1678     if (ilay.eq.21) xmin=-18.0/2.
1679     if (ilay.eq.21) xmax= 18.0/2.
1680     if (ilay.eq.22) xmin=-15.0/2.
1681     if (ilay.eq.22) xmax= 15.0/2.
1682    
1683     if (ilay.eq.31) xmin=-15.0/2.
1684     if (ilay.eq.31) xmax= 15.0/2.
1685     if (ilay.eq.32) xmin=-18.0/2.
1686     if (ilay.eq.32) xmax= 18.0/2.
1687    
1688     if (x .lt. xmin) x=xmin
1689     if (x .gt. xmax) x=xmax
1690    
1691    
1692     if (ilay.eq.11) atten=
1693     & adcx11(is,ipad,1)*exp(x*adcx11(is,ipad,2))
1694     & + adcx11(is,ipad,3)*exp(x*adcx11(is,ipad,4))
1695    
1696     if (ilay.eq.12) atten=
1697     & adcx12(is,ipad,1)*exp(x*adcx12(is,ipad,2))
1698     & + adcx12(is,ipad,3)*exp(x*adcx12(is,ipad,4))
1699    
1700     if (ilay.eq.21) atten=
1701     & adcx21(is,ipad,1)*exp(x*adcx21(is,ipad,2))
1702     & + adcx21(is,ipad,3)*exp(x*adcx21(is,ipad,4))
1703    
1704     if (ilay.eq.22) atten=
1705     & adcx22(is,ipad,1)*exp(x*adcx22(is,ipad,2))
1706     & + adcx22(is,ipad,3)*exp(x*adcx22(is,ipad,4))
1707    
1708     if (ilay.eq.31) atten=
1709     & adcx31(is,ipad,1)*exp(x*adcx31(is,ipad,2))
1710     & + adcx31(is,ipad,3)*exp(x*adcx31(is,ipad,4))
1711    
1712     if (ilay.eq.32) atten=
1713     & adcx32(is,ipad,1)*exp(x*adcx32(is,ipad,2))
1714     & + adcx32(is,ipad,3)*exp(x*adcx32(is,ipad,4))
1715    
1716     if (atten.gt.10000) atten=10000.
1717    
1718     end
1719    
1720     C------------------------------------------------------------------
1721     C------------------------------------------------------------------
1722    
1723     function pc_adc(ix)
1724     include 'input_tof.txt'
1725     real pc_adc
1726     integer ix
1727    
1728     pc_adc=28.0407 + 0.628929*ix
1729     & - 5.80901e-05*ix*ix + 3.14092e-08*ix*ix*ix
1730     c write(*,*) ix,pc_adc
1731     end
1732    
1733     C------------------------------------------------------------------
1734 mocchiut 1.7 C------------------------------------------------------------------
1735    
1736     function check_charge(theta,hitvec)
1737    
1738     include 'input_tof.txt'
1739     include 'tofcomm.txt'
1740    
1741     real check_charge
1742     integer hitvec(6)
1743     REAL CHARGE, theta
1744    
1745     C upper and lower limits for the helium selection
1746     REAL A_l(24),A_h(24)
1747     DATA A_l /200,190,300,210,220,200,210,60,60,120,220,
1748     & 120,160,50,300,200,120,250,350,300,350,250,280,300/
1749     DATA A_h /550,490,800,600,650,600,600,260,200,380,
1750     & 620,380,550,200,850,560,400,750,900,800,880,800,750,800/
1751    
1752     C The k1 constants for the beta calculation, only for S1-S3
1753     C k2 constant is taken to be the standard 2D/c
1754     REAL k1(84)
1755     DATA k1 /50,59.3296,28.4328,-26.0818,5.91253,-19.588,
1756     & -9.26316,24.7544,2.32465,-50.5058,-15.3195,-39.1443,
1757     & -91.2546,-58.6243,-84.5641,-63.1516,-32.2091,-58.3358,
1758     & 13.8084,45.5322,33.2416,-11.5313,51.3271,75,-14.1141,
1759     & 42.8466,15.1794,-63.6672,-6.07739,-32.164,-41.771,10.5274,
1760     & -9.46096,-81.7404,-28.783,-52.7167,-127.394,-69.6166,
1761     & -93.4655,-98.9543,-42.863,-67.8244,-19.3238,31.1221,8.7319,
1762     & -43.1627,5.55573,-14.4078,-83.4466,-47.4647,-77.8379,
1763     & -108.222,-75.986,-101.297,-96.0205,-63.1881,-90.1372,
1764     & -22.7347,8.31409,-19.6912,-7.49008,23.6979,-1.66677,
1765     & 1.81556,34.4668,6.23693,-100,-59.5861,-90.9159,-141.639,
1766     & -89.2521,-112.881,-130.199,-77.0357,-98.4632,-60.2086,
1767     & -4.82097,-29.3705,-43.6469,10.5884,-9.31304,-35.3329,
1768     & 25.2514,25.6/
1769    
1770    
1771    
1772     REAL zin(6)
1773     DATA zin /53.74, 53.04, 23.94, 23.44, -23.49, -24.34/
1774    
1775     REAL c1,c2,xhelp,xhelp1,xhelp2,ds,dist,F
1776     REAL sw,sxw,beta_mean_tof,w_i
1777     INTEGER ihelp
1778     INTEGER ipmt(4)
1779     REAL time(4),beta1(4)
1780    
1781     REAL adca(48), tdca(48)
1782    
1783     REAL a1,a2
1784     INTEGER jj
1785    
1786     C-----------------------------------------------------------
1787     C--- get data
1788     C-----------------------------------------------------------
1789    
1790     do j=1,8
1791     ih = 1 + 0 +((j-1)*2)
1792     adca(ih) = adc(ch11a(j),hb11a(j))
1793     adca(ih+1) = adc(ch11b(j),hb11b(j))
1794     tdca(ih) = tdc(ch11a(j),hb11a(j))
1795     tdca(ih+1) = tdc(ch11b(j),hb11b(j))
1796     enddo
1797    
1798     do j=1,6
1799     ih = 1 + 16+((j-1)*2)
1800     adca(ih) = adc(ch12a(j),hb12a(j))
1801     adca(ih+1) = adc(ch12b(j),hb12b(j))
1802     tdca(ih) = tdc(ch12a(j),hb12a(j))
1803     tdca(ih+1) = tdc(ch12b(j),hb12b(j))
1804     enddo
1805    
1806     do j=1,2
1807     ih = 1 + 28+((j-1)*2)
1808     adca(ih) = adc(ch21a(j),hb21a(j))
1809     adca(ih+1) = adc(ch21b(j),hb21b(j))
1810     tdca(ih) = tdc(ch21a(j),hb21a(j))
1811     tdca(ih+1) = tdc(ch21b(j),hb21b(j))
1812     enddo
1813    
1814     do j=1,2
1815     ih = 1 + 32+((j-1)*2)
1816     adca(ih) = adc(ch22a(j),hb22a(j))
1817     adca(ih+1) = adc(ch22b(j),hb22b(j))
1818     tdca(ih) = tdc(ch22a(j),hb22a(j))
1819     tdca(ih+1) = tdc(ch22b(j),hb22b(j))
1820     enddo
1821    
1822     do j=1,3
1823     ih = 1 + 36+((j-1)*2)
1824     adca(ih) = adc(ch31a(j),hb31a(j))
1825     adca(ih+1) = adc(ch31b(j),hb31b(j))
1826     tdca(ih) = tdc(ch31a(j),hb31a(j))
1827     tdca(ih+1) = tdc(ch31b(j),hb31b(j))
1828     enddo
1829    
1830     do j=1,3
1831     ih = 1 + 42+((j-1)*2)
1832     adca(ih) = adc(ch32a(j),hb32a(j))
1833     adca(ih+1) = adc(ch32b(j),hb32b(j))
1834     tdca(ih) = tdc(ch32a(j),hb32a(j))
1835     tdca(ih+1) = tdc(ch32b(j),hb32b(j))
1836     enddo
1837    
1838    
1839     c write(*,*) adca
1840     c write(*,*) tdca
1841    
1842    
1843     C============ calculate beta and select charge > Z=1 ===============
1844    
1845     ICHARGE=1
1846    
1847     C find hitted paddle by looking for ADC values on both sides
1848     C since we looking for Z>1 this gives decent results
1849    
1850     tof11_i = hitvec(1)-1
1851     tof12_i = hitvec(2)-1
1852     tof21_i = hitvec(3)-1
1853     tof22_i = hitvec(4)-1
1854     tof31_i = hitvec(5)-1
1855     tof32_i = hitvec(6)-1
1856    
1857     c write(*,*) ' in charge check'
1858     c write(*,*) theta,tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i
1859    
1860     C----------------------------------------------------------------
1861    
1862     beta_help=100.
1863     beta_mean_tof=100.
1864    
1865     do jj=1,4
1866     beta1(jj) = 100.
1867     enddo
1868    
1869     C----------------------------------------------------------------
1870     C--------- S1 - S3 ---------------------------------------------
1871     C----------------------------------------------------------------
1872    
1873     C--------- S11 - S31 -------------------------------------------
1874    
1875     if ((tof11_i.gt.-1).and.(tof31_i.gt.-1)) then
1876    
1877     dist = zin(1) - zin(5)
1878     c2 = (2.*0.01*dist)/(3.E08*50.E-12)
1879     F = 1./cos(theta)
1880    
1881     ipmt(1) = (tof11_i)*2+1
1882     ipmt(2) = (tof11_i)*2+2
1883     ipmt(3) = 36+(tof31_i)*2+1
1884     ipmt(4) = 36+(tof31_i)*2+2
1885    
1886     c write(*,*) ipmt
1887    
1888     do jj=1,4
1889     time(jj) = tdca(ipmt(jj))
1890     enddo
1891    
1892     c write(*,*) time
1893    
1894     if ((time(1).lt.4095).and.(time(2).lt.4095).and.
1895     & (time(3).lt.4095).and.(time(4).lt.4095)) then
1896     xhelp1 = time(1) + time(2)
1897     xhelp2 = time(3) + time(4)
1898     ds = xhelp1-xhelp2
1899     ihelp=0+(tof11_i)*3+tof31_i
1900     c1 = k1(ihelp+1)
1901     beta1(1) = c2*F/(ds-c1);
1902     endif
1903     c write(*,*) beta1(1)
1904     endif ! tof_....
1905    
1906    
1907     C--------- S11 - S32 -------------------------------------------
1908    
1909     if ((tof11_i.gt.-1).and.(tof32_i.gt.-1)) then
1910    
1911     dist = zin(1) - zin(6)
1912     c2 = (2.*0.01*dist)/(3.E08*50.E-12)
1913     F = 1./cos(theta)
1914    
1915     ipmt(1) = (tof11_i)*2+1
1916     ipmt(2) = (tof11_i)*2+2
1917     ipmt(3) = 42+(tof32_i)*2+1
1918     ipmt(4) = 42+(tof32_i)*2+2
1919    
1920     do jj=1,4
1921     time(jj) = tdca(ipmt(jj))
1922     enddo
1923    
1924     if ((time(1).lt.4095).and.(time(2).lt.4095).and.
1925     & (time(3).lt.4095).and.(time(4).lt.4095)) then
1926     xhelp1 = time(1) + time(2)
1927     xhelp2 = time(3) + time(4)
1928     ds = xhelp1-xhelp2
1929     ihelp=24+(tof11_i)*3+tof32_i
1930     c1 = k1(ihelp+1)
1931     beta1(2) = c2*F/(ds-c1);
1932     endif
1933     endif ! tof_....
1934    
1935    
1936     C--------- S12 - S31 -------------------------------------------
1937    
1938     if ((tof12_i.gt.-1).and.(tof31_i.gt.-1)) then
1939    
1940     dist = zin(2) - zin(5)
1941     c2 = (2.*0.01*dist)/(3.E08*50.E-12)
1942     F = 1./cos(theta)
1943    
1944     ipmt(1) = 16+(tof12_i)*2+1
1945     ipmt(2) = 16+(tof12_i)*2+2
1946     ipmt(3) = 36+(tof31_i)*2+1
1947     ipmt(4) = 36+(tof31_i)*2+2
1948    
1949     do jj=1,4
1950     time(jj) = tdca(ipmt(jj))
1951     enddo
1952    
1953     if ((time(1).lt.4095).and.(time(2).lt.4095).and.
1954     & (time(3).lt.4095).and.(time(4).lt.4095)) then
1955     xhelp1 = time(1) + time(2)
1956     xhelp2 = time(3) + time(4)
1957     ds = xhelp1-xhelp2
1958     ihelp=48+(tof12_i)*3+tof31_i
1959     c1 = k1(ihelp+1)
1960     beta1(3) = c2*F/(ds-c1);
1961     endif
1962     endif ! tof_....
1963    
1964    
1965     C--------- S12 - S32 -------------------------------------------
1966    
1967     if ((tof12_i.gt.-1).and.(tof32_i.gt.-1)) then
1968    
1969     dist = zin(2) - zin(6)
1970     c2 = (2.*0.01*dist)/(3.E08*50.E-12)
1971     F = 1./cos(theta)
1972    
1973     ipmt(1) = 16+(tof12_i)*2+1
1974     ipmt(2) = 16+(tof12_i)*2+2
1975     ipmt(3) = 42+(tof32_i)*2+1
1976     ipmt(4) = 42+(tof32_i)*2+2
1977    
1978     do jj=1,4
1979     time(jj) = tdca(ipmt(jj))
1980     enddo
1981    
1982     if ((time(1).lt.4095).and.(time(2).lt.4095).and.
1983     & (time(3).lt.4095).and.(time(4).lt.4095)) then
1984     xhelp1 = time(1) + time(2)
1985     xhelp2 = time(3) + time(4)
1986     ds = xhelp1-xhelp2
1987     ihelp=56+(tof12_i)*3+tof32_i
1988     c1 = k1(ihelp+1)
1989     beta1(4) = c2*F/(ds-c1);
1990     endif
1991    
1992     endif ! tof_....
1993    
1994     c write(*,*) beta1
1995    
1996     C---- calculate beta mean, only downward going particles are interesting ----
1997    
1998     sw=0.
1999     sxw=0.
2000     beta_mean_tof=100.
2001    
2002     do jj=1,4
2003     if ((beta1(jj).gt.0.1).and.(beta1(jj).lt.2.0)) then
2004     w_i=1./(0.13*0.13)
2005     sxw=sxw + beta1(jj)*w_i
2006     sw =sw + w_i ;
2007     endif
2008     enddo
2009    
2010     if (sw.gt.0) beta_mean_tof=sxw/sw;
2011    
2012     c write(*,*) 'beta_mean_tof ',beta_mean_tof
2013    
2014     beta_help = beta_mean_tof ! pow(beta_mean_tof,1.0) gave best results
2015    
2016     CCCCC endif ! if tof11_i > -1 && ...... beta calculation
2017    
2018     C----------------------- Select charge --------------------------
2019    
2020     charge=0
2021    
2022     if ((beta_mean_tof.gt.0.2).and.(beta_mean_tof.lt.2.0)) then
2023    
2024     icount1=0
2025     icount2=0
2026     icount3=0
2027    
2028     do jj=0,23
2029     a1 = adca(2*jj+1)
2030     a2 = adca(2*jj+2)
2031     if ((a1.lt.4095).and.(a2.lt.4095)) then
2032     a1 = adca(2*jj+1)*cos(theta)
2033     a2 = adca(2*jj+2)*cos(theta)
2034     xhelp = 100000.
2035     xhelp1 = 100000.
2036     xhelp = sqrt(a1*a2) ! geometric mean
2037     xhelp1 = beta_help*xhelp
2038     C if geometric mean multiplied by beta_help is inside/outside helium
2039     C limits, increase counter
2040     if (xhelp1.lt.A_l(jj+1)) icount1=icount1+1
2041     if ((xhelp1.gt.A_l(jj+1)).and.(xhelp1.lt.A_h(jj+1)))
2042     & icount2=icount2+1
2043     if (xhelp1.gt.A_h(jj+1)) icount3=icount3+1
2044     endif
2045     enddo
2046    
2047    
2048     C if more than three paddles see the same...
2049    
2050     if (icount1 .gt. 3) charge=1
2051     if (icount2 .gt. 3) charge=2
2052     if (icount3 .gt. 3) charge=3
2053    
2054     endif ! 0.2<beta<2.0
2055    
2056     C no beta found? Sum up geometric means of paddles and derive the mean...
2057    
2058     if (beta_mean_tof.eq.100.) then
2059    
2060     xhelp = 0.
2061     icount = 0
2062    
2063     if (tof11_i.gt.-1) then
2064     jj=tof11_i
2065     a1 = adca(0+2*jj+1)
2066     a2 = adca(0+2*jj+2)
2067     if ((a1.lt.4095).and.(a2.lt.4095)) then
2068     a1 = a1*cos(theta)
2069     a2 = a2*cos(theta)
2070     xhelp = xhelp + sqrt(a1*a2)
2071     icount=icount+1
2072     endif
2073     endif
2074    
2075     if (tof12_i.gt.-1) then
2076     jj=tof12_i
2077     a1 = adca(16+2*jj+1)
2078     a2 = adca(16+2*jj+2)
2079     if ((a1.lt.4095).and.(a2.lt.4095)) then
2080     a1 = a1*cos(theta)
2081     a2 = a2*cos(theta)
2082     xhelp = xhelp + sqrt(a1*a2)
2083     icount=icount+1
2084     endif
2085     endif
2086    
2087     if (tof21_i.gt.-1) then
2088     jj=tof21_i
2089     a1 = adca(28+2*jj+1)
2090     a2 = adca(28+2*jj+2)
2091     if ((a1.lt.4095).and.(a2.lt.4095)) then
2092     a1 = a1*cos(theta)
2093     a2 = a2*cos(theta)
2094     xhelp = xhelp + sqrt(a1*a2)
2095     icount=icount+1
2096     endif
2097     endif
2098    
2099     if (tof22_i.gt.-1) then
2100     jj=tof22_i
2101     a1 = adca(32+2*jj+1)
2102     a2 = adca(32+2*jj+2)
2103     if ((a1.lt.4095).and.(a2.lt.4095)) then
2104     a1 = a1*cos(theta)
2105     a2 = a2*cos(theta)
2106     xhelp = xhelp + sqrt(a1*a2)
2107     icount=icount+1
2108     endif
2109     endif
2110    
2111     if (tof31_i.gt.-1) then
2112     jj=tof31_i
2113     a1 = adca(36+2*jj+1)
2114     a2 = adca(36+2*jj+2)
2115     if ((a1.lt.4095).and.(a2.lt.4095)) then
2116     a1 = a1*cos(theta)
2117     a2 = a2*cos(theta)
2118     xhelp = xhelp + sqrt(a1*a2)
2119     icount=icount+1
2120     endif
2121     endif
2122    
2123     if (tof32_i.gt.-1) then
2124     jj=tof32_i
2125     a1 = adca(42+2*jj+1)
2126     a2 = adca(42+2*jj+2)
2127     if ((a1.lt.4095).and.(a2.lt.4095)) then
2128     a1 = a1*cos(theta)
2129     a2 = a2*cos(theta)
2130     xhelp = xhelp + sqrt(a1*a2)
2131     icount=icount+1
2132     endif
2133     endif
2134    
2135    
2136     if (icount.gt.0) xhelp=xhelp/icount
2137     if ((icount.gt.2).and.(xhelp.gt.1500.)) charge=3
2138    
2139     endif ! beta_mean_tof.eq.100.
2140    
2141     c write(*,*) 'in function charge: ',charge
2142     check_charge = charge
2143    
2144    
2145     END
2146    
2147     C****************************************************************************
2148     C****************************************************************************
2149     C****************************************************************************
2150    
2151 pam-de 1.8 function newbeta(iflag,b,hitvec,resmax,qualitycut,chi2cut)
2152 mocchiut 1.7
2153     include 'input_tof.txt'
2154     include 'output_tof.txt'
2155     include 'tofcomm.txt'
2156    
2157     REAL newbeta
2158     REAL resmax,qualitycut,chi2cut
2159     REAL w_i(12),w_il(6),quality,res,betachi,beta_mean_inv
2160     REAL sw,sxw,b(12),beta_mean,chi2,xhelp
2161 pam-de 1.8 REAL tdcfl(4,12)
2162 mocchiut 1.7
2163 pam-de 1.8 INTEGER iflag,icount,hitvec(6)
2164 mocchiut 1.7
2165     INTEGER itop(12),ibot(12)
2166     DATA itop /1,1,2,2,3,3,4,4,1,1,2,2/
2167     DATA ibot /5,6,5,6,5,6,5,6,3,4,3,4/
2168    
2169     C====================================================================
2170    
2171     tof11_i = hitvec(1)
2172     tof12_i = hitvec(2)
2173     tof21_i = hitvec(3)
2174     tof22_i = hitvec(4)
2175     tof31_i = hitvec(5)
2176     tof32_i = hitvec(6)
2177    
2178 pam-de 1.8 if (iflag.eq.1) then ! call from tofl2com
2179     do i=1,4
2180     do j=1,12
2181     tdcfl(i,j) = tdcflagtof(i,j)
2182     enddo
2183     enddo
2184     endif
2185    
2186     if (iflag.eq.2) then ! call from toftrk
2187     do i=1,4
2188     do j=1,12
2189     tdcfl(i,j) = tdcflag(i,j)
2190     enddo
2191     enddo
2192     endif
2193    
2194 mocchiut 1.7
2195     C--- Find out ToF layers with artificial TDC values -------------
2196    
2197     do jj=1,6
2198     w_il(jj) = 1000.
2199     enddo
2200    
2201    
2202     if (tof11_i.gt.0) then
2203     if ((tofmask(ch11a(tof11_i),hb11a(tof11_i)).gt.0).or.
2204     & (tofmask(ch11b(tof11_i),hb11b(tof11_i)).gt.0)) then
2205     w_il(1)=0
2206 pam-de 1.8 i1=tdcfl(ch11a(tof11_i),hb11a(tof11_i))
2207     i2=tdcfl(ch11b(tof11_i),hb11b(tof11_i))
2208 mocchiut 1.7 if ((i1.eq.1).or.(i2.eq.1)) w_il(1) = 1 ! tdcflag
2209     endif
2210     endif
2211    
2212     if (tof12_i.gt.0) then
2213     if ((tofmask(ch12a(tof12_i),hb12a(tof12_i)).gt.0).or.
2214     & (tofmask(ch12b(tof12_i),hb12b(tof12_i)).gt.0)) then
2215     w_il(2)=0
2216 pam-de 1.8 i1=tdcfl(ch12a(tof12_i),hb12a(tof12_i))
2217     i2=tdcfl(ch12b(tof12_i),hb12b(tof12_i))
2218 mocchiut 1.7 if ((i1.eq.1).or.(i2.eq.1)) w_il(2) = 1 ! tdcflag
2219     endif
2220     endif
2221    
2222     if (tof21_i.gt.0) then
2223     if ((tofmask(ch21a(tof21_i),hb21a(tof21_i)).gt.0).or.
2224     & (tofmask(ch21b(tof21_i),hb21b(tof21_i)).gt.0)) then
2225     w_il(3)=0
2226 pam-de 1.8 i1=tdcfl(ch21a(tof21_i),hb21a(tof21_i))
2227     i2=tdcfl(ch21b(tof21_i),hb21b(tof21_i))
2228 mocchiut 1.7 if ((i1.eq.1).or.(i2.eq.1)) w_il(3) = 1 ! tdcflag
2229     endif
2230     endif
2231    
2232     if (tof22_i.gt.0) then
2233     if ((tofmask(ch22a(tof22_i),hb22a(tof22_i)).gt.0).or.
2234     & (tofmask(ch22b(tof22_i),hb22b(tof22_i)).gt.0)) then
2235     w_il(4)=0
2236 pam-de 1.8 i1=tdcfl(ch22a(tof22_i),hb22a(tof22_i))
2237     i2=tdcfl(ch22b(tof22_i),hb22b(tof22_i))
2238 mocchiut 1.7 if ((i1.eq.1).or.(i2.eq.1)) w_il(4) = 1 ! tdcflag
2239     endif
2240     endif
2241    
2242     if (tof31_i.gt.0) then
2243     if ((tofmask(ch31a(tof31_i),hb11a(tof31_i)).gt.0).or.
2244     & (tofmask(ch31b(tof31_i),hb31b(tof31_i)).gt.0)) then
2245     w_il(5)=0
2246 pam-de 1.8 i1=tdcfl(ch31a(tof31_i),hb31a(tof31_i))
2247     i2=tdcfl(ch31b(tof31_i),hb31b(tof31_i))
2248 mocchiut 1.7 if ((i1.eq.1).or.(i2.eq.1)) w_il(5) = 1 ! tdcflag
2249     endif
2250     endif
2251    
2252     if (tof32_i.gt.0) then
2253     if ((tofmask(ch32a(tof32_i),hb32a(tof32_i)).gt.0).or.
2254     & (tofmask(ch32b(tof32_i),hb32b(tof32_i)).gt.0)) then
2255     w_il(6)=0
2256 pam-de 1.8 i1=tdcfl(ch32a(tof32_i),hb32a(tof32_i))
2257     i2=tdcfl(ch32b(tof32_i),hb32b(tof32_i))
2258 mocchiut 1.7 if ((i1.eq.1).or.(i2.eq.1)) w_il(6) = 1 ! tdcflag
2259     endif
2260     endif
2261    
2262     C------------------------------------------------------------------------
2263     C--- Set weights for the 12 measurements using information for top and bottom:
2264     C--- if no measurements: weight = set to very high value=> not used
2265     C--- top or bottom artificial: weight*sqrt(2)
2266     C--- top and bottom artificial: weight*sqrt(2)*sqrt(2)
2267    
2268     DO jj=1,12
2269     if (jj.le.4) xhelp = 0.11 ! S1-S3
2270     if ((jj.gt.4).and.(jj.le.8)) xhelp = 0.18 ! S2-S3
2271     if (jj.gt.8) xhelp = 0.28 ! S1-S2
2272     if ((w_il(itop(jj)).eq.1000.).and.(w_il(ibot(jj)).eq.1000.))
2273     & xhelp = 1.E09
2274     if ((w_il(itop(jj)).eq.1).or.(w_il(ibot(jj)).eq.1.))
2275     & xhelp = xhelp*1.414
2276     if ((w_il(itop(jj)).eq.1).and.(w_il(ibot(jj)).eq.1.))
2277     & xhelp = xhelp*2.
2278     w_i(jj) = 1./xhelp
2279     ENDDO
2280    
2281     C========================================================================
2282     C--- Calculate mean beta for the first time -----------------------------
2283     C--- We are using "1/beta" since its error is gaussian ------------------
2284    
2285     icount=0
2286     sw=0.
2287     sxw=0.
2288     beta_mean=100.
2289    
2290     DO jj=1,12
2291     IF ((abs(1./b(jj)).gt.0.1).and.(abs(1./b(jj)).lt.15.)) THEN
2292     icount = icount+1
2293     sxw = sxw + (1./b(jj))*w_i(jj)*w_i(jj)
2294     sw = sw + w_i(jj)*w_i(jj)
2295     ENDIF
2296     ENDDO
2297    
2298     if (icount.gt.0) beta_mean=1./(sxw/sw)
2299     beta_mean_inv = 1./beta_mean
2300    
2301    
2302     C--- Calculate beta for the second time, use residuals of the single
2303     C--- measurements to get a chi2 value
2304    
2305     icount = 0
2306     sw = 0.
2307     sxw = 0.
2308     betachi = 100.
2309     chi2 = 0.
2310     quality = 0.
2311    
2312     DO jj=1,12
2313     IF ((abs(1./b(jj)).gt.0.1).and.(abs(1./b(jj)).lt.15.)
2314     & .and.(w_i(jj).GT.0.01)) THEN
2315     res = beta_mean_inv - (1./b(jj)) ;
2316     if (abs(res*w_i(jj)).lt.resmax) THEN
2317     chi2 = chi2 + (res*w_i(jj))**2.
2318     icount = icount+1
2319     sxw = sxw + (1./b(jj))*w_i(jj)*w_i(jj)
2320     sw = sw + w_i(jj)*w_i(jj)
2321     ENDIF
2322     ENDIF
2323     ENDDO
2324    
2325     c quality = sw
2326     quality = sqrt(sw)
2327    
2328     if (icount.eq.0) chi2 = 1000.
2329     if (icount.gt.0) chi2 = chi2/(icount)
2330    
2331     if (icount.gt.0) betachi=1./(sxw/sw);
2332    
2333     beta_mean=100.
2334     if ((chi2.lt.chi2cut).and.(quality.gt.qualitycut))
2335     & beta_mean = betachi
2336     newbeta = beta_mean
2337    
2338     END
2339    
2340     C****************************************************************************
2341    

  ViewVC Help
Powered by ViewVC 1.1.23