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

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

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

revision 1.4 by mocchiut, Mon Jan 22 10:45:25 2007 UTC revision 1.10 by mocchiut, Fri Nov 28 14:44:22 2008 UTC
# Line 1  Line 1 
1  ******************************************************************************  
2  *  C******************************************************************************
3  *  08-12-06 WM: adc_c-bug :  The raw ADc value was multiplied with cos(theta)  C
4  *  and AFTER that there was an if statement "if tof32(right,i,iadc) < 4095"  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  *  jan-07 GF: ADCflags(4,12) inserted to flag artificial ADC values  C
7  *  jan-07 WM: artificial ADC values created using attenuation calibration  C  jan-07 GF: ADCflags(4,12) inserted to flag artificial ADC values
8  *  jan-07 WM: modified xtofpos flag "101". xtofpos must be inside physical  C  jan-07 WM: artificial ADC values created using attenuation calibration
9  *             dimension of the paddle +/- 10 cm  C  jan-07 WM: modified xtofpos flag "101". xtofpos must be inside physical
10  *  jan-07 WM: if xtofpos=101 then this paddle is not used for beta  C             dimension of the paddle +/- 10 cm
11  *             calculation  C  jan-07 WM: if xtofpos=101 then this paddle is not used for beta
12  *  jan-07 WM: the definition for a "hit" is changed: Now we must have a  C             calculation
13  *             valid TDC signal on both sides  C  jan-07 WM: the definition for a "hit" is changed: Now we must have a
14  *  jan-07 WM: flag for PMTs #10 and #35 added, TDC=819 due to bit-shift  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    C  mar-08 WM: Call to "newbeta" changed, now a flag tells the function if the
30    C             call comes from "tofl2com" or form "toftrack"
31    C  mar-08 WM: Bug found in dEdx if check_charge>1
32    C  oct-08 WM: Calculation of zenith angle debugged, sometimes strange values
33    C             were possible
34    C******************************************************************************
35    
36        INTEGER FUNCTION TOFL2COM()        INTEGER FUNCTION TOFL2COM()
37  c      c    
# Line 28  C     Line 47  C    
47        LOGICAL check        LOGICAL check
48        REAL secure        REAL secure
49    
50        INTEGER j        INTEGER j,hitvec(6)
       REAL xhelp_a,xhelp_t  
51    
52        REAL dx,dy,dr,ds        REAL dx,dy,dr,ds
53        REAL yhelp,xhelp,xhelp1,xhelp2        REAL yhelp,yhelp1,yhelp2,xhelp,xhelp1,xhelp2
54        REAL c1,c2,sw,sxw,w_i        REAL c1,c2
       INTEGER icount  
55    
56  c      REAL xdummy  C      REAL sw,sxw,w_i
57    C      INTEGER icount
58    C      REAL beta_mean
59    
60        INTEGER tof11_j,tof21_j,tof31_j        INTEGER tof11_j,tof21_j,tof31_j
61        INTEGER tof12_j,tof22_j,tof32_j        INTEGER tof12_j,tof22_j,tof32_j
62    
   
       REAL beta_mean  
   
   
63  c     value for status of each PM-data  c     value for status of each PM-data
64  c     first index  : 1 = left, 2 = right  c     first index  : 1 = left, 2 = right
65  c     second index : 1... number of paddle  c     second index : 1... number of paddle
# Line 52  c     second index : 1... number of padd Line 67  c     second index : 1... number of padd
67        INTEGER tof21_event(2,2),tof22_event(2,2)        INTEGER tof21_event(2,2),tof22_event(2,2)
68        INTEGER tof31_event(2,3),tof32_event(2,3)        INTEGER tof31_event(2,3),tof32_event(2,3)
69    
70    
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                
106        REAL theta13        REAL theta13
107  C--   DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006  C--   DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006
# Line 65  C--   DATA ZTOF/53.74,53.04,23.94,23.44, Line 115  C--   DATA ZTOF/53.74,53.04,23.94,23.44,
115        REAL hepratio              REAL hepratio      
116    
117        INTEGER ihelp        INTEGER ihelp
118        REAL xkorr        REAL xkorr,btemp(12)
119    
120          REAL atten,pc_adc,check_charge,newbeta
121    
122          INTEGER IZ
123          REAL k1corrA1,k1corrB1,k1corrC1
124    
125    
126          INTEGER ifst
127          DATA  ifst /0/
128    
129  C---------------------------------------  C---------------------------------------
130  C      C    
# Line 75  C     Line 134  C    
134  C      C    
135  C     CALCULATE COMMON VARIABLES  C     CALCULATE COMMON VARIABLES
136  C      C    
137    C-------------------------------------------------------------------
138    
139  *******************************************************************          if (ifst.eq.0) then
       icounter = icounter + 1  
140    
141  *     amplitude has to be 'secure' higher than pedestal for an adc event          ifst=1
142        secure = 2.  
143    C     amplitude has to be 'secure' higher than pedestal for an adc event
144           secure = 2.
145    
146  C     ratio between helium and proton ca. 4  C     ratio between helium and proton ca. 4
147        hepratio = 4.5  !         hepratio = 4.  !
148        offset = 1         offset = 1
149        slope = 2         slope = 2
150        left = 1         left = 1
151        right = 2         right = 2
152        none_ev = 0         none_ev = 0
153        none_find = 0         none_find = 0
154        tdc_ev = 1         tdc_ev = 1
155        adc_ev = 1         adc_ev = 1
156        itdc = 1         itdc = 1
157        iadc = 2         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    
171        do i=1,13        do i=1,13
172           betatof_a(i) = 100.          ! As in "troftrk.for"           betatof_a(i) = 100.          ! As in "troftrk.for"
173        enddo        enddo
174    
175          do i=1,6
176             hitvec(i) = -1
177          enddo
178    
179        do i=1,4        do i=1,4
180           do j=1,12           do j=1,12
181              adctof_c(i,j) = 1000.              adctof_c(i,j) = 1000.
# Line 134  c gf tdc falg: Line 211  c gf tdc falg:
211           enddo           enddo
212        enddo        enddo
213    
 c the calibration files are read in the main program from xxx_tofcalib.rz  
214    
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    c the calibration files are read in the main program from xxx_tofcalib.rz
223    
224  c-------------------------get ToF data --------------------------------  c-------------------------get ToF data --------------------------------
225    
226  c     put the adc and tdc values from ntuple into tofxx(i,j,k) variables  c     put the adc and tdc values from ntuple into tofxx(i,j,k) variables
227    c     adc valueas are then pC
228    
229        do j=1,8        do j=1,8
230           tof11(1,j,2) = adc(ch11a(j),hb11a(j))           tof11(1,j,2) = pc_adc(adc(ch11a(j),hb11a(j)))
231           tof11(2,j,2) = adc(ch11b(j),hb11b(j))           tof11(2,j,2) = pc_adc(adc(ch11b(j),hb11b(j)))
232           tof11(1,j,1) = tdc(ch11a(j),hb11a(j))           tof11(1,j,1) = (tdc(ch11a(j),hb11a(j)))
233           tof11(2,j,1) = tdc(ch11b(j),hb11b(j))           tof11(2,j,1) = (tdc(ch11b(j),hb11b(j)))
234        enddo        enddo
235    
236    
237        do j=1,6        do j=1,6
238           tof12(1,j,2) = adc(ch12a(j),hb12a(j))           tof12(1,j,2) = pc_adc(adc(ch12a(j),hb12a(j)))
239           tof12(2,j,2) = adc(ch12b(j),hb12b(j))           tof12(2,j,2) = pc_adc(adc(ch12b(j),hb12b(j)))
240           tof12(1,j,1) = tdc(ch12a(j),hb12a(j))           tof12(1,j,1) = (tdc(ch12a(j),hb12a(j)))
241           tof12(2,j,1) = tdc(ch12b(j),hb12b(j))           tof12(2,j,1) = (tdc(ch12b(j),hb12b(j)))
242        enddo        enddo
243    
244        do j=1,2        do j=1,2
245           tof21(1,j,2) = adc(ch21a(j),hb21a(j))           tof21(1,j,2) = pc_adc(adc(ch21a(j),hb21a(j)))
246           tof21(2,j,2) = adc(ch21b(j),hb21b(j))           tof21(2,j,2) = pc_adc(adc(ch21b(j),hb21b(j)))
247           tof21(1,j,1) = tdc(ch21a(j),hb21a(j))           tof21(1,j,1) = (tdc(ch21a(j),hb21a(j)))
248           tof21(2,j,1) = tdc(ch21b(j),hb21b(j))           tof21(2,j,1) = (tdc(ch21b(j),hb21b(j)))
249        enddo        enddo
250    
251        do j=1,2        do j=1,2
252           tof22(1,j,2) = adc(ch22a(j),hb22a(j))           tof22(1,j,2) = pc_adc(adc(ch22a(j),hb22a(j)))
253           tof22(2,j,2) = adc(ch22b(j),hb22b(j))           tof22(2,j,2) = pc_adc(adc(ch22b(j),hb22b(j)))
254           tof22(1,j,1) = tdc(ch22a(j),hb22a(j))           tof22(1,j,1) = (tdc(ch22a(j),hb22a(j)))
255           tof22(2,j,1) = tdc(ch22b(j),hb22b(j))           tof22(2,j,1) = (tdc(ch22b(j),hb22b(j)))
256        enddo        enddo
257    
258        do j=1,3        do j=1,3
259           tof31(1,j,2) = adc(ch31a(j),hb31a(j))           tof31(1,j,2) = pc_adc(adc(ch31a(j),hb31a(j)))
260           tof31(2,j,2) = adc(ch31b(j),hb31b(j))           tof31(2,j,2) = pc_adc(adc(ch31b(j),hb31b(j)))
261           tof31(1,j,1) = tdc(ch31a(j),hb31a(j))           tof31(1,j,1) = (tdc(ch31a(j),hb31a(j)))
262           tof31(2,j,1) = tdc(ch31b(j),hb31b(j))           tof31(2,j,1) = (tdc(ch31b(j),hb31b(j)))
263        enddo        enddo
264    
265        do j=1,3        do j=1,3
266           tof32(1,j,2) = adc(ch32a(j),hb32a(j))           tof32(1,j,2) = pc_adc(adc(ch32a(j),hb32a(j)))
267           tof32(2,j,2) = adc(ch32b(j),hb32b(j))           tof32(2,j,2) = pc_adc(adc(ch32b(j),hb32b(j)))
268           tof32(1,j,1) = tdc(ch32a(j),hb32a(j))           tof32(1,j,1) = (tdc(ch32a(j),hb32a(j)))
269           tof32(2,j,1) = tdc(ch32b(j),hb32b(j))           tof32(2,j,1) = (tdc(ch32b(j),hb32b(j)))
270        enddo        enddo
271    
272  C----------------------------------------------------------------------  C----------------------------------------------------------------------
# Line 287  C---- S222B TDC=819 Line 371  C---- S222B TDC=819
371               tdcflagtof(ch22b(2),hb22b(2))=2               tdcflagtof(ch22b(2),hb22b(2))=2
372         endif         endif
373    
   
374  C----------------------------------------------------------------  C----------------------------------------------------------------
375  C------------   Check Paddles for hits    -----------------------  C------------   Check Paddles for hits    -----------------------
376  C------  a "hit" means TDC values<4095 on both sides ------------  C------  a "hit" means TDC values<4095 on both sides ------------
# Line 469  c     check if an other paddle has also Line 552  c     check if an other paddle has also
552                 ENDIF                 ENDIF
553              ENDIF              ENDIF
554           ENDIF           ENDIF
555        ENDDO         ENDDO
556    
557        do i=1,6         do i=1,6
558           tof_i_flag(i)=0           tof_i_flag(i)=0
559           tof_j_flag(i)=0           tof_j_flag(i)=0
560        enddo         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    
       tof_i_flag(1)=tof11_i  
       tof_i_flag(2)=tof12_i  
       tof_i_flag(3)=tof21_i  
       tof_i_flag(4)=tof22_i  
       tof_i_flag(5)=tof31_i  
       tof_i_flag(6)=tof32_i  
   
       tof_j_flag(1)=tof11_j  
       tof_j_flag(2)=tof12_j  
       tof_j_flag(3)=tof21_j  
       tof_j_flag(4)=tof22_j  
       tof_j_flag(5)=tof31_j  
       tof_j_flag(6)=tof32_j  
583    
           
584  C------------------------------------------------------------------  C------------------------------------------------------------------
585  C---  calculate track position in paddle using timing difference  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  C------------------------------------------------------------------  C------------------------------------------------------------------
591    
592        do i=1,3         do i=1,3
593           xtofpos(i)=100.           xtofpos(i)=100.
594           ytofpos(i)=100.           ytofpos(i)=100.
595        enddo         enddo
596    
597  C-----------------------------S1 --------------------------------  C-----------------------------S1 --------------------------------
598    
599        IF (tof11_i.GT.none_find) THEN        IF (tof11_i.GT.none_find) THEN
600           ytofpos(1)  = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.           ytofpos(1)  = ((tof11(1,tof11_i,itdc)-tof11(2,tof11_i,itdc))/2.
601       +        -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)       +   -y_coor_lin11c(tof11_i,offset))/y_coor_lin11c(tof11_i,slope)
602        endif        endif
603    
604        IF (tof12_i.GT.none_find) THEN        IF (tof12_i.GT.none_find) THEN
605           xtofpos(1)  = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.           xtofpos(1)  = ((tof12(1,tof12_i,itdc)-tof12(2,tof12_i,itdc))/2.
606       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)       +   -x_coor_lin12c(tof12_i,offset))/x_coor_lin12c(tof12_i,slope)
607        endif        endif
608    
609    
# Line 516  C-----------------------------S2 ------- Line 611  C-----------------------------S2 -------
611    
612        IF (tof21_i.GT.none_find) THEN        IF (tof21_i.GT.none_find) THEN
613           xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.           xtofpos(2) = ((tof21(1,tof21_i,itdc)-tof21(2,tof21_i,itdc))/2.
614       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)       +    -x_coor_lin21c(tof21_i,offset))/x_coor_lin21c(tof21_i,slope)
615        endif        endif
616    
617        IF (tof22_i.GT.none_find) THEN        IF (tof22_i.GT.none_find) THEN
618           ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.           ytofpos(2) = ((tof22(1,tof22_i,itdc)-tof22(2,tof22_i,itdc))/2.
619       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)       +    -y_coor_lin22c(tof22_i,offset))/y_coor_lin22c(tof22_i,slope)
620        endif        endif
621                
622    
# Line 529  C-----------------------------S3 ------- Line 624  C-----------------------------S3 -------
624    
625        IF (tof31_i.GT.none_find) THEN        IF (tof31_i.GT.none_find) THEN
626           ytofpos(3)  = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.           ytofpos(3)  = ((tof31(1,tof31_i,itdc)-tof31(2,tof31_i,itdc))/2.
627       +        -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)       +    -y_coor_lin31c(tof31_i,offset))/y_coor_lin31c(tof31_i,slope)
628        endif        endif
629    
630        IF (tof32_i.GT.none_find) THEN        IF (tof32_i.GT.none_find) THEN
631           xtofpos(3)  = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.           xtofpos(3)  = ((tof32(1,tof32_i,itdc)-tof32(2,tof32_i,itdc))/2.
632       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)       +    -x_coor_lin32c(tof32_i,offset))/x_coor_lin32c(tof32_i,slope)
633        endif        endif
634    
635    
 c      do i=1,3  
 c         if (abs(xtofpos(i)).gt.100.) then  
 c            xtofpos(i)=101.  
 c         endif  
 c         if (abs(ytofpos(i)).gt.100.) then  
 c            ytofpos(i)=101.  
 c         endif  
 c      enddo  
   
 C--  restrict TDC measurements to physical paddle dimensions +/- 10 cm  
 C--  this cut is now stronger than in the old versions  
   
         if (abs(xtofpos(1)).gt.31.)  xtofpos(1)=101.  
         if (abs(xtofpos(2)).gt.19.)  xtofpos(2)=101.  
         if (abs(xtofpos(3)).gt.19.)  xtofpos(3)=101.  
   
         if (abs(ytofpos(1)).gt.26.)  ytofpos(1)=101.  
         if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.  
         if (abs(ytofpos(3)).gt.18.)  ytofpos(3)=101.  
   
   
636  C----------------------------------------------------------------------  C----------------------------------------------------------------------
637  C---------------------  zenith angle theta  ---------------------------  C---------------------  zenith angle theta  ---------------------------
638  C----------------------------------------------------------------------  C----------------------------------------------------------------------
639    C-----------------------------  old  ----------------------------------
       dx=0.  
       dy=0.  
       dr=0.  
       theta13 = 0.  
   
          IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find))  
      &        dx  = xtofpos(1) - xtofpos(3)  
          IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find))  
      &        dy  = ytofpos(1) - ytofpos(3)  
          dr = sqrt(dx*dx+dy*dy)  
          theta13 = atan(dr/tofarm13)  
   
 C------------------------------------------------------------------  
640  c      dx=0.  c      dx=0.
641  c      dy=0.  c      dy=0.
642  c      dr=0.  c      dr=0.
643  c      theta12 = 0.  c      theta13 = 0.
644  c  c
645  c         IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find))  c         IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find))
646  c     &        dx  = xtofpos(1) - xtofpos(2)  c     &        dx  = xtofpos(1) - xtofpos(3)
647  c         IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find))  c         IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find))
648  c     &        dy  = ytofpos(1) - ytofpos(2)  c     &        dy  = ytofpos(1) - ytofpos(3)
649  c         dr = sqrt(dx*dx+dy*dy)  c         dr = sqrt(dx*dx+dy*dy)
650  c         theta12 = atan(dr/tofarm12)  c         theta13 = atan(dr/tofarm13)
 c          
 c      dx=0.  
 c      dy=0.  
 c      dr=0.  
 c      theta23 = 0.  
651  c  c
652  c         IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find))  c
653  c     &        dx  = xtofpos(2) - xtofpos(3)  C-----------------------------  new  ------------------------------
654  c         IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find))  
655  c     &        dy  = ytofpos(2) - ytofpos(3)         xhelp1=0.
656  c         dr = sqrt(dx*dx+dy*dy)         if (tof11_i.GT.none_find) xhelp1=tof11_x(tof11_i)
657  c         theta23 = atan(dr/tofarm23)         if (xtofpos(1).lt.100)  xhelp1=xtofpos(1)
658  c          
659  C---------------------------------------------------------------------         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    
683    
684    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    c         write(*,*) 'charge in tofl2com',iz
694    
695  C--------------------------------------------------------------------  C--------------------------------------------------------------------
696  C---- if TDCleft.and.TDCright and NO ADC insert artificial ADC  C---- if TDCleft.and.TDCright and NO ADC insert artificial ADC
# Line 618  c       DATA tof32_y/ -5.0,0.0,5.0/ Line 707  c       DATA tof32_y/ -5.0,0.0,5.0/
707    
708  C----------------------------  S1 -------------------------------------  C----------------------------  S1 -------------------------------------
709    
710         yhelp=0.  c       yhelp=0.
711           yhelp=100.  ! WM
712         if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)         if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)
713         if (ytofpos(1).lt.100)  yhelp=ytofpos(1)         if (ytofpos(1).lt.100)  yhelp=ytofpos(1)
714    
715         IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN         IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
716           i = tof11_i           i = tof11_i
717           if (tof11(left,i,iadc).eq.4095) then           if (adc(ch11a(i),hb11a(i)).eq.4095) then
718              xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))              xkorr = atten(left,11,i,yhelp)
719              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
720              tof11(left,i,iadc)=xkorr/cos(theta13)              tof11(left,i,iadc)=xkorr/cos(theta13)
 c            write(*,*) 'tofl2 left ',i, tof11(left,i,iadc)  
721              adcflagtof(ch11a(i),hb11a(i)) = 1              adcflagtof(ch11a(i),hb11a(i)) = 1
722           endif           endif
723           if (tof11(right,i,iadc).eq.4095) then           if (adc(ch11b(i),hb11b(i)).eq.4095) then
724              xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))              xkorr = atten(right,11,i,yhelp)
725              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
726              tof11(right,i,iadc)=xkorr/cos(theta13)              tof11(right,i,iadc)=xkorr/cos(theta13)
 c            write(*,*) 'tofl2 right ',i, tof11(right,i,iadc)  
727              adcflagtof(ch11b(i),hb11b(i)) = 1              adcflagtof(ch11b(i),hb11b(i)) = 1
728           endif           endif
729         ENDIF         ENDIF
730    
731         xhelp=0.  c       xhelp=0.
732           xhelp=100.  ! WM
733         if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)         if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)
734         if (xtofpos(1).lt.100)  xhelp=xtofpos(1)         if (xtofpos(1).lt.100)  xhelp=xtofpos(1)
735    
736         IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN         IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
737           i = tof12_i           i = tof12_i
738           if (tof12(left,i,iadc).eq.4095) then           if (adc(ch12a(i),hb12a(i)).eq.4095) then
739              xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))              xkorr = atten(left,12,i,xhelp)
740              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
741              tof12(left,i,iadc) = xkorr/cos(theta13)              tof12(left,i,iadc) = xkorr/cos(theta13)
742              adcflagtof(ch12a(i),hb12a(i)) = 1              adcflagtof(ch12a(i),hb12a(i)) = 1
743           endif           endif
744           if (tof12(right,i,iadc).eq.4095) then           if (adc(ch12b(i),hb12b(i)).eq.4095) then
745              xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))              xkorr = atten(right,12,i,xhelp)
746              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
747              tof12(right,i,iadc) = xkorr/cos(theta13)              tof12(right,i,iadc) = xkorr/cos(theta13)
748              adcflagtof(ch12b(i),hb12b(i)) = 1              adcflagtof(ch12b(i),hb12b(i)) = 1
749           endif           endif
# Line 662  c            write(*,*) 'tofl2 right ',i Line 751  c            write(*,*) 'tofl2 right ',i
751    
752  C-----------------------------S2 --------------------------------  C-----------------------------S2 --------------------------------
753    
754         xhelp=0.  c       xhelp=0.
755           xhelp=100.   ! WM
756         if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)         if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)
757         if (xtofpos(2).lt.100)  xhelp=xtofpos(2)         if (xtofpos(2).lt.100)  xhelp=xtofpos(2)
758    
759         IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN         IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
760           i = tof21_i           i = tof21_i
761           if (tof21(left,i,iadc).eq.4095) then           if (adc(ch21a(i),hb21a(i)).eq.4095) then
762              xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))              xkorr = atten(left,21,i,xhelp)
763              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
764              tof21(left,i,iadc) = xkorr/cos(theta13)              tof21(left,i,iadc) = xkorr/cos(theta13)
765              adcflagtof(ch21a(i),hb21a(i)) = 1              adcflagtof(ch21a(i),hb21a(i)) = 1
766           endif           endif
767           if (tof21(right,i,iadc).eq.4095) then           if (adc(ch21b(i),hb21b(i)).eq.4095) then
768              xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))              xkorr = atten(right,21,i,xhelp)
769              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
770              tof21(right,i,iadc) = xkorr/cos(theta13)              tof21(right,i,iadc) = xkorr/cos(theta13)
771              adcflagtof(ch21b(i),hb21b(i)) = 1              adcflagtof(ch21b(i),hb21b(i)) = 1
772           endif           endif
773         ENDIF         ENDIF
774    
775    
776         yhelp=0.  c       yhelp=0.
777           yhelp=100.   ! WM
778         if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)         if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)
779         if (ytofpos(2).lt.100)  yhelp=ytofpos(2)         if (ytofpos(2).lt.100)  yhelp=ytofpos(2)
780    
781         IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN         IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
782           i = tof22_i           i = tof22_i
783           if (tof22(left,i,iadc).eq.4095) then           if (adc(ch22a(i),hb22a(i)).eq.4095) then
784              xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))              xkorr = atten(left,22,i,yhelp)
785              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
786              tof22(left,i,iadc) = xkorr/cos(theta13)              tof22(left,i,iadc) = xkorr/cos(theta13)
787              adcflagtof(ch22a(i),hb22a(i)) = 1              adcflagtof(ch22a(i),hb22a(i)) = 1
788           endif           endif
789           if (tof22(right,i,iadc).eq.4095) then           if (adc(ch22b(i),hb22b(i)).eq.4095) then
790              xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))              xkorr = atten(right,22,i,yhelp)
791              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
792              tof22(right,i,iadc) = xkorr/cos(theta13)              tof22(right,i,iadc) = xkorr/cos(theta13)
793              adcflagtof(ch22b(i),hb22b(i)) = 1              adcflagtof(ch22b(i),hb22b(i)) = 1
794           endif           endif
# Line 705  C-----------------------------S2 ------- Line 796  C-----------------------------S2 -------
796    
797  C-----------------------------S3 --------------------------------  C-----------------------------S3 --------------------------------
798    
799         yhelp=0.  c       yhelp=0.
800           yhelp=100.  ! WM
801         if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)         if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)
802         if (ytofpos(3).lt.100)  yhelp=ytofpos(3)         if (ytofpos(3).lt.100)  yhelp=ytofpos(3)
803    
804         IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN         IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
805           i = tof31_i           i = tof31_i
806           if (tof31(left,i,iadc).eq.4095) then           if (adc(ch31a(i),hb31a(i)).eq.4095) then
807              xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))              xkorr = atten(left,31,i,yhelp)
808              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
809              tof31(left,i,iadc) = xkorr/cos(theta13)              tof31(left,i,iadc) = xkorr/cos(theta13)
810              adcflagtof(ch31a(i),hb31a(i)) = 1              adcflagtof(ch31a(i),hb31a(i)) = 1
811           endif           endif
812           if (tof31(right,i,iadc).eq.4095) then           if (adc(ch31b(i),hb31b(i)).eq.4095) then
813              xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))              xkorr = atten(right,31,i,yhelp)
814              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
815              tof31(right,i,iadc) = xkorr/cos(theta13)              tof31(right,i,iadc) = xkorr/cos(theta13)
816              adcflagtof(ch31b(i),hb31b(i)) = 1              adcflagtof(ch31b(i),hb31b(i)) = 1
817           endif           endif
818         ENDIF         ENDIF
819    
820         xhelp=0.  c       xhelp=0.
821           xhelp=100.   ! WM
822         if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)         if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)
823         if (xtofpos(3).lt.100)  xhelp=xtofpos(3)         if (xtofpos(3).lt.100)  xhelp=xtofpos(3)
824    
825         IF (tof32_i.GT.none_find.AND.abs(xhelp).lt.100) THEN         IF (tof32_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
826           i = tof32_i           i = tof32_i
827           if (tof32(left,i,iadc).eq.4095) then           if (adc(ch32a(i),hb32a(i)).eq.4095) then
828              xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))              xkorr = atten(left,32,i,xhelp)
829              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
830              tof32(left,i,iadc) = xkorr/cos(theta13)              tof32(left,i,iadc) = xkorr/cos(theta13)
831              adcflagtof(ch32a(i),hb32a(i)) = 1              adcflagtof(ch32a(i),hb32a(i)) = 1
832           endif           endif
833           if (tof32(right,i,iadc).eq.4095) then           if (adc(ch32b(i),hb32b(i)).eq.4095) then
834              xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))              xkorr = atten(right,32,i,xhelp)
835              xkorr=xkorr/hepratio              if (iz.le.1) xkorr=xkorr/hepratio
836              tof32(right,i,iadc) = xkorr/cos(theta13)              tof32(right,i,iadc) = xkorr/cos(theta13)
837              adcflagtof(ch32b(i),hb32b(i)) = 1              adcflagtof(ch32b(i),hb32b(i)) = 1
838           endif           endif
839         ENDIF         ENDIF
840    
841    
842  C--------------------------------------------------------------------  C-------------------------------------------------------------------
843  C--------------------Time walk correction  -------------------------  C--------------------Time walk correction  -------------------------
844  C--------------------------------------------------------------------  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    
863        DO i=1,8        DO i=1,8
864         xhelp_a = tof11(left,i,iadc)           if ((tdc(ch11a(i),hb11a(i)).lt.4095).and.
865         xhelp_t = tof11(left,i,itdc)       &             (tof11(left,i,iadc).lt.3786)) THEN
866         if(xhelp_a<4095) xhelp = tw11(left,i)/sqrt(xhelp_a)           xhelp = tw11(left,i)/(tof11(left,i,iadc)**0.5)
867         tof11(left,i,itdc) = xhelp_t  + xhelp           tof11(left,i,itdc) = tof11(left,i,itdc) + xhelp
868         tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)           tdc_c(ch11a(i),hb11a(i))=tof11(left,i,itdc)
869         xhelp_a = tof11(right,i,iadc)                                                ENDIF
870         xhelp_t = tof11(right,i,itdc)  
871         if(xhelp_a<4095) xhelp = tw11(right,i)/sqrt(xhelp_a)           if ((tdc(ch11b(i),hb11b(i)).lt.4095).and.
872         tof11(right,i,itdc) = xhelp_t  + xhelp       &             (tof11(right,i,iadc).lt.3786)) THEN
873         tdc_c(ch11b(i),hb11b(i))=tof11(right,i,itdc)           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        ENDDO        ENDDO
878    
879    
880        DO i=1,6        DO i=1,6
881         xhelp_a = tof12(left,i,iadc)           if ((tdc(ch12a(i),hb12a(i)).lt.4095).and.
882         xhelp_t = tof12(left,i,itdc)       &             (tof12(left,i,iadc).lt.3786)) THEN
883         if(xhelp_a<4095) xhelp = tw12(left,i)/sqrt(xhelp_a)           xhelp = tw12(left,i)/(tof12(left,i,iadc)**0.5)
884         tof12(left,i,itdc) = xhelp_t  + xhelp           tof12(left,i,itdc) = tof12(left,i,itdc) + xhelp
885         tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)           tdc_c(ch12a(i),hb12a(i))=tof12(left,i,itdc)
886         xhelp_a = tof12(right,i,iadc)                                                ENDIF
887         xhelp_t = tof12(right,i,itdc)  
888         if(xhelp_a<4095) xhelp = tw12(right,i)/sqrt(xhelp_a)           if ((tdc(ch12b(i),hb12b(i)).lt.4095).and.
889         tof12(right,i,itdc) = xhelp_t  + xhelp       &             (tof12(right,i,iadc).lt.3786)) THEN
890         tdc_c(ch12b(i),hb12b(i))=tof12(right,i,itdc)           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        ENDDO        ENDDO
895    
896  C----  C----
897        DO i=1,2        DO I=1,2
898         xhelp_a = tof21(left,i,iadc)           if ((tdc(ch21a(i),hb21a(i)).lt.4095).and.
899         xhelp_t = tof21(left,i,itdc)       &             (tof21(left,i,iadc).lt.3786)) THEN
900         if(xhelp_a<4095) xhelp = tw21(left,i)/sqrt(xhelp_a)           xhelp = tw21(left,i)/(tof21(left,i,iadc)**0.5)
901         tof21(left,i,itdc) = xhelp_t  + xhelp           tof21(left,i,itdc) = tof21(left,i,itdc) + xhelp
902         tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)           tdc_c(ch21a(i),hb21a(i))=tof21(left,i,itdc)
903         xhelp_a = tof21(right,i,iadc)                                                ENDIF
904         xhelp_t = tof21(right,i,itdc)  
905         if(xhelp_a<4095) xhelp = tw21(right,i)/sqrt(xhelp_a)           if ((tdc(ch21b(i),hb21b(i)).lt.4095).and.
906         tof21(right,i,itdc) = xhelp_t  + xhelp       &             (tof21(right,i,iadc).lt.3786)) THEN
907         tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)           xhelp = tw21(right,i)/(tof21(right,i,iadc)**0.5)
908        ENDDO           tof21(right,i,itdc) = tof21(right,i,itdc) + xhelp
909             tdc_c(ch21b(i),hb21b(i))=tof21(right,i,itdc)
910        DO i=1,2                                               ENDIF
911         xhelp_a = tof22(left,i,iadc)        ENDDO
912         xhelp_t = tof22(left,i,itdc)  
913         if(xhelp_a<4095) xhelp = tw22(left,i)/sqrt(xhelp_a)        DO I=1,2
914         tof22(left,i,itdc) = xhelp_t  + xhelp           if ((tdc(ch22a(i),hb22a(i)).lt.4095).and.
915         tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)       &             (tof22(left,i,iadc).lt.3786)) THEN
916         xhelp_a = tof22(right,i,iadc)           xhelp = tw22(left,i)/(tof22(left,i,iadc)**0.5)
917         xhelp_t = tof22(right,i,itdc)           tof22(left,i,itdc) = tof22(left,i,itdc) + xhelp
918         if(xhelp_a<4095) xhelp = tw22(right,i)/sqrt(xhelp_a)           tdc_c(ch22a(i),hb22a(i))=tof22(left,i,itdc)
919         tof22(right,i,itdc) = xhelp_t  + xhelp                                                ENDIF
920         tdc_c(ch22b(i),hb22b(i))=tof22(right,i,itdc)  
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        ENDDO        ENDDO
 C----  
928    
929        DO i=1,3  C----
930         xhelp_a = tof31(left,i,iadc)        DO I=1,3
931         xhelp_t = tof31(left,i,itdc)           if ((tdc(ch31a(i),hb31a(i)).lt.4095).and.
932         if(xhelp_a<4095) xhelp = tw31(left,i)/sqrt(xhelp_a)       &             (tof31(left,i,iadc).lt.3786)) THEN
933         tof31(left,i,itdc) = xhelp_t  + xhelp           xhelp = tw31(left,i)/(tof31(left,i,iadc)**0.5)
934         tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)           tof31(left,i,itdc) = tof31(left,i,itdc) + xhelp
935         xhelp_a = tof31(right,i,iadc)           tdc_c(ch31a(i),hb31a(i))=tof31(left,i,itdc)
936         xhelp_t = tof31(right,i,itdc)                                                ENDIF
937         if(xhelp_a<4095) xhelp = tw31(right,i)/sqrt(xhelp_a)  
938         tof31(right,i,itdc) = xhelp_t  + xhelp           if ((tdc(ch31b(i),hb31b(i)).lt.4095).and.
939         tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)       &             (tof31(right,i,iadc).lt.3786)) THEN
940        ENDDO           xhelp = tw31(right,i)/(tof31(right,i,iadc)**0.5)
941             tof31(right,i,itdc) = tof31(right,i,itdc) + xhelp
942        DO i=1,3           tdc_c(ch31b(i),hb31b(i))=tof31(right,i,itdc)
943         xhelp_a = tof32(left,i,iadc)                                               ENDIF
944         xhelp_t = tof32(left,i,itdc)        ENDDO
945         if(xhelp_a<4095) xhelp = tw32(left,i)/sqrt(xhelp_a)  
946         tof32(left,i,itdc) = xhelp_t  + xhelp        DO I=1,3
947         tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)           if ((tdc(ch32a(i),hb32a(i)).lt.4095).and.
948         xhelp_a = tof32(right,i,iadc)       &             (tof32(left,i,iadc).lt.3786)) THEN
949         xhelp_t = tof32(right,i,itdc)           xhelp = tw32(left,i)/(tof32(left,i,iadc)**0.5)
950         if(xhelp_a<4095) xhelp = tw32(right,i)/sqrt(xhelp_a)           tof32(left,i,itdc) = tof32(left,i,itdc) + xhelp
951         tof32(right,i,itdc) = xhelp_t  + xhelp           tdc_c(ch32a(i),hb32a(i))=tof32(left,i,itdc)
952         tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)                                                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        ENDDO
961            
962    
963    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           i=tof11_i
979          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          i=tof12_i
985          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          i=tof21_i
994          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          i=tof22_i
1000          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          i=tof31_i
1009          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          i=tof32_i
1015          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    
1028    C--  restrict TDC measurements to physical paddle dimensions +/- 10 cm
1029    C--  this cut is now stronger than in the old versions
1030    
1031            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    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    
1071    
1072    C------------------------------------------------------------------
1073  C----------------------------------------------------------------------  C----------------------------------------------------------------------
1074  C------------------angle and ADC(x) correction  C------------------angle and ADC(x) correction
1075  C----------------------------------------------------------------------  C----------------------------------------------------------------------
# Line 842  c       DATA tof31_x/ -6.0,0.,6.0/ Line 1083  c       DATA tof31_x/ -6.0,0.,6.0/
1083  c       DATA tof32_y/ -5.0,0.0,5.0/  c       DATA tof32_y/ -5.0,0.0,5.0/
1084    
1085        yhelp=0.        yhelp=0.
1086    c      yhelp=100.
1087        if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)        if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)
1088        if (ytofpos(1).lt.100)  yhelp=ytofpos(1)        if (ytofpos(1).lt.100)  yhelp=ytofpos(1)
1089    
1090        IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN        IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
1091    
1092           i = tof11_i           i = tof11_i
1093           if (tof11(left,i,iadc).lt.4095) then           if (tof11(left,i,iadc).lt.3786) then
1094    c          if (adc(ch11a(i),hb11a(i)).lt.4095) then
1095              tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta13)              tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta13)
1096              xkorr=adcx11(left,i,1)*exp(-yhelp/adcx11(left,i,2))              xkorr = atten(left,11,i,yhelp)
1097              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1098              adctof_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr              adctof_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr
1099           endif           endif
1100    
1101           if (tof11(right,i,iadc).lt.4095) then           if (tof11(right,i,iadc).lt.3786) then
1102    c          if (adc(ch11b(i),hb11b(i)).lt.4095) then
1103              tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta13)              tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta13)
1104              xkorr=adcx11(right,i,1)*exp(yhelp/adcx11(right,i,2))              xkorr = atten(right,11,i,yhelp)
1105              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1106              adctof_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr              adctof_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr
1107           endif           endif
1108        ENDIF        ENDIF
1109    
1110        xhelp=0.        xhelp=0.
1111    c      xhelp=100.
1112        if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)        if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)
1113        if (xtofpos(1).lt.100)  xhelp=xtofpos(1)        if (xtofpos(1).lt.100)  xhelp=xtofpos(1)
1114    
1115        IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN        IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
1116    
1117           i = tof12_i           i = tof12_i
1118           if (tof12(left,i,iadc).lt.4095) then           if (tof12(left,i,iadc).lt.3786) then
1119    c          if (adc(ch12a(i),hb12a(i)).lt.4095) then
1120              tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta13)              tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta13)
1121              xkorr=adcx12(left,i,1)*exp(-xhelp/adcx12(left,i,2))              xkorr = atten(left,12,i,xhelp)
1122              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1123              adctof_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr              adctof_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr
1124           endif           endif
1125    
1126           if (tof12(right,i,iadc).lt.4095) then           if (tof12(right,i,iadc).lt.3786) then
1127    c          if (adc(ch12b(i),hb12b(i)).lt.4095) then
1128              tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta13)              tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta13)
1129              xkorr=adcx12(right,i,1)*exp(xhelp/adcx12(right,i,2))              xkorr = atten(right,12,i,xhelp)
1130              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1131              adctof_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr              adctof_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr
1132           endif           endif
# Line 888  c       DATA tof32_y/ -5.0,0.0,5.0/ Line 1135  c       DATA tof32_y/ -5.0,0.0,5.0/
1135  C-----------------------------S2 --------------------------------  C-----------------------------S2 --------------------------------
1136    
1137        xhelp=0.        xhelp=0.
1138    c      xhelp=100.
1139        if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)        if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)
1140        if (xtofpos(2).lt.100)  xhelp=xtofpos(2)        if (xtofpos(2).lt.100)  xhelp=xtofpos(2)
1141    
1142        IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN        IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
1143    
1144           i = tof21_i           i = tof21_i
1145           if (tof21(left,i,iadc).lt.4095) then           if (tof21(left,i,iadc).lt.3786) then
1146    c          if (adc(ch21a(i),hb21a(i)).lt.4095) then
1147              tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta13)              tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta13)
1148              xkorr=adcx21(left,i,1)*exp(-xhelp/adcx21(left,i,2))              xkorr = atten(left,21,i,xhelp)
1149              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1150              adctof_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr              adctof_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr
1151           endif           endif
1152    
1153           if (tof21(right,i,iadc).lt.4095) then           if (tof21(right,i,iadc).lt.3786) then
1154    c          if (adc(ch21b(i),hb21b(i)).lt.4095) then
1155              tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta13)              tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta13)
1156              xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))              xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))
1157                xkorr = atten(right,21,i,xhelp)
1158              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1159              adctof_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr              adctof_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr
1160           endif           endif
# Line 911  C-----------------------------S2 ------- Line 1162  C-----------------------------S2 -------
1162    
1163    
1164        yhelp=0.        yhelp=0.
1165    c      yhelp=100.
1166        if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)        if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)
1167        if (ytofpos(2).lt.100)  yhelp=ytofpos(2)        if (ytofpos(2).lt.100)  yhelp=ytofpos(2)
1168    
1169        IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN        IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
1170    
1171           i = tof22_i           i = tof22_i
1172           if (tof22(left,i,iadc).lt.4095) then           if (tof22(left,i,iadc).lt.3786) then
1173    c          if (adc(ch22a(i),hb22a(i)).lt.4095) then
1174              tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta13)              tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta13)
1175              xkorr=adcx22(left,i,1)*exp(-yhelp/adcx22(left,i,2))              xkorr = atten(left,22,i,yhelp)
1176              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1177              adctof_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr              adctof_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr
1178           endif           endif
1179    
1180           if (tof22(right,i,iadc).lt.4095) then           if (tof22(right,i,iadc).lt.3786) then
1181    c          if (adc(ch22b(i),hb22b(i)).lt.4095) then
1182              tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta13)              tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta13)
1183              xkorr=adcx22(right,i,1)*exp(yhelp/adcx22(right,i,2))              xkorr = atten(right,22,i,yhelp)
1184              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1185              adctof_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr              adctof_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr
1186           endif           endif
# Line 935  C-----------------------------S2 ------- Line 1189  C-----------------------------S2 -------
1189  C-----------------------------S3 --------------------------------  C-----------------------------S3 --------------------------------
1190    
1191        yhelp=0.        yhelp=0.
1192    c      yhelp=100.
1193        if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)        if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)
1194        if (ytofpos(3).lt.100)  yhelp=ytofpos(3)        if (ytofpos(3).lt.100)  yhelp=ytofpos(3)
1195    
1196        IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN        IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN
1197    
1198           i = tof31_i           i = tof31_i
1199           if (tof31(left,i,iadc).lt.4095) then           if (tof31(left,i,iadc).lt.3786) then
1200    c          if (adc(ch31a(i),hb31a(i)).lt.4095) then
1201              tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta13)              tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta13)
1202              xkorr=adcx31(left,i,1)*exp(-yhelp/adcx31(left,i,2))              xkorr = atten(left,31,i,yhelp)
1203              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1204              adctof_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr              adctof_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr
1205           endif           endif
1206    
1207           if (tof31(right,i,iadc).lt.4095) then           if (tof31(right,i,iadc).lt.3786) then
1208    c          if (adc(ch31b(i),hb31b(i)).lt.4095) then
1209              tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta13)              tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta13)
1210              xkorr=adcx31(right,i,1)*exp(yhelp/adcx31(right,i,2))              xkorr = atten(right,31,i,yhelp)
1211              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1212              adctof_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr              adctof_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr
1213           endif           endif
1214        ENDIF        ENDIF
1215    
1216        xhelp=0.        xhelp=0.
1217    c      xhelp=100.
1218        if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)        if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)
1219        if (xtofpos(3).lt.100)  xhelp=xtofpos(3)        if (xtofpos(3).lt.100)  xhelp=xtofpos(3)
1220    
1221        IF (tof32_i.GT.none_find.AND.abs(xhelp).lt.100) THEN        IF (tof32_i.GT.none_find.AND.abs(xhelp).lt.100) THEN
1222    
1223           i = tof32_i           i = tof32_i
1224           if (tof32(left,i,iadc).lt.4095) then           if (tof32(left,i,iadc).lt.3786) then
1225    c          if (adc(ch32a(i),hb32a(i)).lt.4095) then
1226              tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta13)              tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta13)
1227              xkorr=adcx32(left,i,1)*exp(-xhelp/adcx32(left,i,2))              xkorr = atten(left,32,i,xhelp)
1228              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1229              adctof_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr              adctof_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr
1230           endif           endif
1231    
1232           if (tof32(right,i,iadc).lt.4095) then           if (tof32(right,i,iadc).lt.3786) then
1233    c          if (adc(ch32b(i),hb32b(i)).lt.4095) then
1234              tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta13)              tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta13)
1235              xkorr=adcx32(right,i,1)*exp(xhelp/adcx32(right,i,2))              xkorr = atten(right,32,i,xhelp)
1236              xkorr=xkorr/hepratio              xkorr=xkorr/hepratio
1237              adctof_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr              adctof_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr
1238           endif           endif
1239        ENDIF        ENDIF
1240    
   
1241  C--------------------------------------------------------------------  C--------------------------------------------------------------------
1242  C----------------------calculate Beta  ------------------------------  C----------------------calculate Beta  ------------------------------
1243  C--------------------------------------------------------------------  C--------------------------------------------------------------------
# Line 999  C     S11 - S31 Line 1258  C     S11 - S31
1258           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1259           ihelp=(tof11_i-1)*3+tof31_i           ihelp=(tof11_i-1)*3+tof31_i
1260           c1 = k_S11S31(1,ihelp)           c1 = k_S11S31(1,ihelp)
1261             if (iz.gt.2) c1 = c1 + k1corrA1
1262           c2 = k_S11S31(2,ihelp)           c2 = k_S11S31(2,ihelp)
1263           betatof_a(1) = c2/(cos(theta13)*(ds-c1))           betatof_a(1) = c2/(cos(theta13)*(ds-c1))
1264    
# Line 1027  C     S11 - S32 Line 1287  C     S11 - S32
1287           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1288           ihelp=(tof11_i-1)*3+tof32_i           ihelp=(tof11_i-1)*3+tof32_i
1289           c1 = k_S11S32(1,ihelp)           c1 = k_S11S32(1,ihelp)
1290             if (iz.gt.2) c1 = c1 + k1corrA1
1291           c2 = k_S11S32(2,ihelp)           c2 = k_S11S32(2,ihelp)
1292           betatof_a(2) = c2/(cos(theta13)*(ds-c1))           betatof_a(2) = c2/(cos(theta13)*(ds-c1))
1293    
# Line 1055  C     S12 - S31 Line 1316  C     S12 - S31
1316           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1317           ihelp=(tof12_i-1)*3+tof31_i           ihelp=(tof12_i-1)*3+tof31_i
1318           c1 = k_S12S31(1,ihelp)           c1 = k_S12S31(1,ihelp)
1319             if (iz.gt.2) c1 = c1 + k1corrA1
1320           c2 = k_S12S31(2,ihelp)           c2 = k_S12S31(2,ihelp)
1321           betatof_a(3) = c2/(cos(theta13)*(ds-c1))           betatof_a(3) = c2/(cos(theta13)*(ds-c1))
1322    
# Line 1083  C     S12 - S32 Line 1345  C     S12 - S32
1345           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1346           ihelp=(tof12_i-1)*3+tof32_i           ihelp=(tof12_i-1)*3+tof32_i
1347           c1 = k_S12S32(1,ihelp)           c1 = k_S12S32(1,ihelp)
1348             if (iz.gt.2) c1 = c1 + k1corrA1
1349           c2 = k_S12S32(2,ihelp)           c2 = k_S12S32(2,ihelp)
1350           betatof_a(4) = c2/(cos(theta13)*(ds-c1))           betatof_a(4) = c2/(cos(theta13)*(ds-c1))
1351    
# Line 1111  C     S21 - S31 Line 1374  C     S21 - S31
1374           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1375           ihelp=(tof21_i-1)*3+tof31_i           ihelp=(tof21_i-1)*3+tof31_i
1376           c1 = k_S21S31(1,ihelp)           c1 = k_S21S31(1,ihelp)
1377             if (iz.gt.2) c1 = c1 + k1corrB1
1378           c2 = k_S21S31(2,ihelp)           c2 = k_S21S31(2,ihelp)
1379           betatof_a(5) = c2/(cos(theta13)*(ds-c1))           betatof_a(5) = c2/(cos(theta13)*(ds-c1))
1380    
# Line 1139  C     S21 - S32 Line 1403  C     S21 - S32
1403           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1404           ihelp=(tof21_i-1)*3+tof32_i           ihelp=(tof21_i-1)*3+tof32_i
1405           c1 = k_S21S32(1,ihelp)           c1 = k_S21S32(1,ihelp)
1406             if (iz.gt.2) c1 = c1 + k1corrB1
1407           c2 = k_S21S32(2,ihelp)           c2 = k_S21S32(2,ihelp)
1408           betatof_a(6) = c2/(cos(theta13)*(ds-c1))           betatof_a(6) = c2/(cos(theta13)*(ds-c1))
1409                                        
# Line 1167  C     S22 - S31 Line 1432  C     S22 - S31
1432           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1433           ihelp=(tof22_i-1)*3+tof31_i           ihelp=(tof22_i-1)*3+tof31_i
1434           c1 = k_S22S31(1,ihelp)           c1 = k_S22S31(1,ihelp)
1435             if (iz.gt.2) c1 = c1 + k1corrB1
1436           c2 = k_S22S31(2,ihelp)           c2 = k_S22S31(2,ihelp)
1437           betatof_a(7) = c2/(cos(theta13)*(ds-c1))           betatof_a(7) = c2/(cos(theta13)*(ds-c1))
1438    
# Line 1195  C     S22 - S32 Line 1461  C     S22 - S32
1461           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1462           ihelp=(tof22_i-1)*3+tof32_i           ihelp=(tof22_i-1)*3+tof32_i
1463           c1 = k_S22S32(1,ihelp)           c1 = k_S22S32(1,ihelp)
1464             if (iz.gt.2) c1 = c1 + k1corrB1
1465           c2 = k_S22S32(2,ihelp)           c2 = k_S22S32(2,ihelp)
1466           betatof_a(8) = c2/(cos(theta13)*(ds-c1))           betatof_a(8) = c2/(cos(theta13)*(ds-c1))
1467    
# Line 1223  C     S11 - S21 Line 1490  C     S11 - S21
1490           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1491           ihelp=(tof11_i-1)*2+tof21_i           ihelp=(tof11_i-1)*2+tof21_i
1492           c1 = k_S11S21(1,ihelp)           c1 = k_S11S21(1,ihelp)
1493             if (iz.gt.2) c1 = c1 + k1corrC1
1494           c2 = k_S11S21(2,ihelp)           c2 = k_S11S21(2,ihelp)
1495           betatof_a(9) = c2/(cos(theta13)*(ds-c1))           betatof_a(9) = c2/(cos(theta13)*(ds-c1))
1496    
# Line 1251  C     S11 - S22 Line 1519  C     S11 - S22
1519           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1520           ihelp=(tof11_i-1)*2+tof22_i           ihelp=(tof11_i-1)*2+tof22_i
1521           c1 = k_S11S22(1,ihelp)           c1 = k_S11S22(1,ihelp)
1522             if (iz.gt.2) c1 = c1 + k1corrC1
1523           c2 = k_S11S22(2,ihelp)           c2 = k_S11S22(2,ihelp)
1524           betatof_a(10) = c2/(cos(theta13)*(ds-c1))           betatof_a(10) = c2/(cos(theta13)*(ds-c1))
1525    
# Line 1279  C     S12 - S21 Line 1548  C     S12 - S21
1548           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1549           ihelp=(tof12_i-1)*2+tof21_i           ihelp=(tof12_i-1)*2+tof21_i
1550           c1 = k_S12S21(1,ihelp)           c1 = k_S12S21(1,ihelp)
1551             if (iz.gt.2) c1 = c1 + k1corrC1
1552           c2 = k_S12S21(2,ihelp)           c2 = k_S12S21(2,ihelp)
1553           betatof_a(11) = c2/(cos(theta13)*(ds-c1))           betatof_a(11) = c2/(cos(theta13)*(ds-c1))
1554    
# Line 1307  C     S12 - S22 Line 1577  C     S12 - S22
1577           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1578           ihelp=(tof12_i-1)*2+tof22_i           ihelp=(tof12_i-1)*2+tof22_i
1579           c1 = k_S12S22(1,ihelp)           c1 = k_S12S22(1,ihelp)
1580             if (iz.gt.2) c1 = c1 + k1corrC1
1581           c2 = k_S12S22(2,ihelp)           c2 = k_S12S22(2,ihelp)
1582           betatof_a(12) = c2/(cos(theta13)*(ds-c1))           betatof_a(12) = c2/(cos(theta13)*(ds-c1))
1583    
# Line 1327  C-------   Line 1598  C-------  
1598        ENDIF        ENDIF
1599    
1600  C---------------------------------------------------------  C---------------------------------------------------------
1601    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    
1622        icount=0  C--------  New mean beta  calculation  -----------------------
       sw=0.  
       sxw=0.  
       beta_mean=100.  
1623    
1624        do i=1,12          do i=1,12
1625           if ((betatof_a(i).gt.-1.5).and.(betatof_a(i).lt.1.5)) then           btemp(i) = betatof_a(i)
1626              icount= icount+1          enddo
             if (i.le.4) w_i=1./(0.13**2.)  
             if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)  
             if (i.ge.9) w_i=1./(0.25**2.)     ! to be checked  
             sxw=sxw + betatof_a(i)*w_i  
             sw =sw + w_i  
          endif  
       enddo  
         
       if (icount.gt.0) beta_mean=sxw/sw  
       betatof_a(13) = beta_mean  
1627    
1628            betatof_a(13)=newbeta(1,btemp,hitvec,10.,10.,20.)
1629    
1630    C--------------------------------------------------------------
1631    C      write(*,*) betatof_a
1632  c      write(*,*) xtofpos  c      write(*,*) xtofpos
1633  c      write(*,*) ytofpos  c      write(*,*) ytofpos
1634  c      write(*,*) betatof_a  c      write(*,*)'tofl2com beta', betatof_a
1635  C      write(*,*) adcflagtof  C      write(*,*) adcflagtof
1636    c      write(*,*) 'tofl2com'
1637    c      write(*,*) xtofpos
1638    c      write(*,*) ytofpos
1639    c      write(*,*) xtr_tof
1640    c      write(*,*) ytr_tof
1641          
1642   100  continue   100  continue
1643    
1644  C  C
1645        RETURN        RETURN
1646        END        END
1647    
1648    
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    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 get rid of warnings EMILIANO
1787            i = 0
1788            slope = 0
1789            offset = 0
1790            none_find = 0
1791            none_ev = 0
1792            adc_ev = 0
1793            tdc_ev = 0
1794            iadc = 0
1795            itdc = 0
1796            right = 0
1797            left = 0
1798            tof12_y(1) = tof12_y(1)
1799            tof11_x(1) = tof11_x(1)
1800            tof21_y(1) = tof21_y(1)
1801            tof22_x(1) = tof22_x(1)
1802            tof32_y(1) = tof32_y(1)
1803            tof31_x(1) = tof31_x(1)
1804    c get rid of warnings
1805    
1806    C-----------------------------------------------------------
1807    C--- get data
1808    C-----------------------------------------------------------
1809    
1810             do j=1,8
1811             ih = 1 + 0 +((j-1)*2)
1812             adca(ih)   = adc(ch11a(j),hb11a(j))
1813             adca(ih+1) = adc(ch11b(j),hb11b(j))
1814             tdca(ih)   = tdc(ch11a(j),hb11a(j))
1815             tdca(ih+1) = tdc(ch11b(j),hb11b(j))
1816             enddo
1817    
1818             do j=1,6
1819             ih = 1 + 16+((j-1)*2)
1820             adca(ih)   = adc(ch12a(j),hb12a(j))
1821             adca(ih+1) = adc(ch12b(j),hb12b(j))
1822             tdca(ih)   = tdc(ch12a(j),hb12a(j))
1823             tdca(ih+1) = tdc(ch12b(j),hb12b(j))
1824             enddo
1825    
1826             do j=1,2
1827             ih = 1 + 28+((j-1)*2)
1828             adca(ih)   = adc(ch21a(j),hb21a(j))
1829             adca(ih+1) = adc(ch21b(j),hb21b(j))
1830             tdca(ih)   = tdc(ch21a(j),hb21a(j))
1831             tdca(ih+1) = tdc(ch21b(j),hb21b(j))
1832             enddo
1833    
1834             do j=1,2
1835             ih = 1 + 32+((j-1)*2)
1836             adca(ih)   = adc(ch22a(j),hb22a(j))
1837             adca(ih+1) = adc(ch22b(j),hb22b(j))
1838             tdca(ih)   = tdc(ch22a(j),hb22a(j))
1839             tdca(ih+1) = tdc(ch22b(j),hb22b(j))
1840             enddo
1841    
1842             do j=1,3
1843             ih = 1 + 36+((j-1)*2)
1844             adca(ih)   = adc(ch31a(j),hb31a(j))
1845             adca(ih+1) = adc(ch31b(j),hb31b(j))
1846             tdca(ih)   = tdc(ch31a(j),hb31a(j))
1847             tdca(ih+1) = tdc(ch31b(j),hb31b(j))
1848             enddo
1849    
1850             do j=1,3
1851             ih = 1 + 42+((j-1)*2)
1852             adca(ih)   = adc(ch32a(j),hb32a(j))
1853             adca(ih+1) = adc(ch32b(j),hb32b(j))
1854             tdca(ih)   = tdc(ch32a(j),hb32a(j))
1855             tdca(ih+1) = tdc(ch32b(j),hb32b(j))
1856             enddo
1857    
1858    
1859    c         write(*,*) adca
1860    c         write(*,*) tdca
1861    
1862    
1863    C============   calculate beta and select charge > Z=1   ===============
1864    
1865            ICHARGE=1
1866    
1867    C find hitted paddle by looking for ADC values on both sides
1868    C since we looking for Z>1 this gives decent results
1869    
1870            tof11_i = hitvec(1)-1
1871            tof12_i = hitvec(2)-1
1872            tof21_i = hitvec(3)-1
1873            tof22_i = hitvec(4)-1
1874            tof31_i = hitvec(5)-1
1875            tof32_i = hitvec(6)-1
1876    
1877    c        write(*,*) ' in charge check'
1878    c        write(*,*) theta,tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i
1879    
1880    C----------------------------------------------------------------
1881    
1882            beta_help=100.
1883            beta_mean_tof=100.
1884    
1885            do jj=1,4
1886              beta1(jj) = 100.
1887            enddo
1888    
1889    C----------------------------------------------------------------
1890    C---------  S1 - S3 ---------------------------------------------
1891    C----------------------------------------------------------------
1892    
1893    C---------  S11 - S31 -------------------------------------------
1894    
1895            if ((tof11_i.gt.-1).and.(tof31_i.gt.-1)) then
1896    
1897            dist = zin(1) - zin(5)
1898            c2 = (2.*0.01*dist)/(3.E08*50.E-12)
1899            F = 1./cos(theta)
1900    
1901            ipmt(1)   = (tof11_i)*2+1
1902            ipmt(2)   = (tof11_i)*2+2
1903            ipmt(3)   = 36+(tof31_i)*2+1
1904            ipmt(4)   = 36+(tof31_i)*2+2
1905    
1906    c        write(*,*) ipmt
1907    
1908            do jj=1,4
1909               time(jj) = tdca(ipmt(jj))
1910            enddo
1911    
1912    c        write(*,*) time
1913    
1914            if ((time(1).lt.4095).and.(time(2).lt.4095).and.
1915         &     (time(3).lt.4095).and.(time(4).lt.4095)) then
1916             xhelp1 = time(1) + time(2)
1917             xhelp2 = time(3) + time(4)
1918             ds = xhelp1-xhelp2
1919             ihelp=0+(tof11_i)*3+tof31_i
1920             c1 = k1(ihelp+1)
1921             beta1(1) = c2*F/(ds-c1);
1922                                                     endif
1923    c         write(*,*) beta1(1)
1924             endif  ! tof_....
1925    
1926    
1927    C---------  S11 - S32 -------------------------------------------
1928    
1929            if ((tof11_i.gt.-1).and.(tof32_i.gt.-1)) then
1930    
1931            dist = zin(1) - zin(6)
1932            c2 = (2.*0.01*dist)/(3.E08*50.E-12)
1933            F = 1./cos(theta)
1934    
1935            ipmt(1)   = (tof11_i)*2+1
1936            ipmt(2)   = (tof11_i)*2+2
1937            ipmt(3)   = 42+(tof32_i)*2+1
1938            ipmt(4)   = 42+(tof32_i)*2+2
1939    
1940            do jj=1,4
1941               time(jj) = tdca(ipmt(jj))
1942            enddo
1943    
1944            if ((time(1).lt.4095).and.(time(2).lt.4095).and.
1945         &     (time(3).lt.4095).and.(time(4).lt.4095)) then
1946             xhelp1 = time(1) + time(2)
1947             xhelp2 = time(3) + time(4)
1948             ds = xhelp1-xhelp2
1949             ihelp=24+(tof11_i)*3+tof32_i
1950             c1 = k1(ihelp+1)
1951             beta1(2) = c2*F/(ds-c1);
1952                                                     endif
1953             endif  ! tof_....
1954    
1955    
1956    C---------  S12 - S31 -------------------------------------------
1957    
1958            if ((tof12_i.gt.-1).and.(tof31_i.gt.-1)) then
1959    
1960            dist = zin(2) - zin(5)
1961            c2 = (2.*0.01*dist)/(3.E08*50.E-12)
1962            F = 1./cos(theta)
1963    
1964            ipmt(1)   = 16+(tof12_i)*2+1
1965            ipmt(2)   = 16+(tof12_i)*2+2
1966            ipmt(3)   = 36+(tof31_i)*2+1
1967            ipmt(4)   = 36+(tof31_i)*2+2
1968    
1969            do jj=1,4
1970               time(jj) = tdca(ipmt(jj))
1971            enddo
1972    
1973            if ((time(1).lt.4095).and.(time(2).lt.4095).and.
1974         &     (time(3).lt.4095).and.(time(4).lt.4095)) then
1975             xhelp1 = time(1) + time(2)
1976             xhelp2 = time(3) + time(4)
1977             ds = xhelp1-xhelp2
1978             ihelp=48+(tof12_i)*3+tof31_i
1979             c1 = k1(ihelp+1)
1980             beta1(3) = c2*F/(ds-c1);
1981                                                     endif
1982             endif  ! tof_....
1983    
1984    
1985    C---------  S12 - S32 -------------------------------------------
1986    
1987            if ((tof12_i.gt.-1).and.(tof32_i.gt.-1)) then
1988    
1989            dist = zin(2) - zin(6)
1990            c2 = (2.*0.01*dist)/(3.E08*50.E-12)
1991            F = 1./cos(theta)
1992    
1993            ipmt(1)   = 16+(tof12_i)*2+1
1994            ipmt(2)   = 16+(tof12_i)*2+2
1995            ipmt(3)   = 42+(tof32_i)*2+1
1996            ipmt(4)   = 42+(tof32_i)*2+2
1997    
1998            do jj=1,4
1999               time(jj) = tdca(ipmt(jj))
2000            enddo
2001    
2002            if ((time(1).lt.4095).and.(time(2).lt.4095).and.
2003         &     (time(3).lt.4095).and.(time(4).lt.4095)) then
2004             xhelp1 = time(1) + time(2)
2005             xhelp2 = time(3) + time(4)
2006             ds = xhelp1-xhelp2
2007             ihelp=56+(tof12_i)*3+tof32_i
2008             c1 = k1(ihelp+1)
2009             beta1(4) = c2*F/(ds-c1);
2010                                                     endif
2011    
2012             endif  ! tof_....
2013    
2014    c         write(*,*) beta1
2015      
2016    C----  calculate  beta mean, only downward going particles are interesting ----
2017    
2018             sw=0.
2019             sxw=0.
2020             beta_mean_tof=100.
2021    
2022            do jj=1,4
2023            if ((beta1(jj).gt.0.1).and.(beta1(jj).lt.2.0)) then
2024                w_i=1./(0.13*0.13)
2025                sxw=sxw + beta1(jj)*w_i
2026                sw =sw + w_i ;
2027                                                          endif
2028            enddo
2029    
2030            if (sw.gt.0) beta_mean_tof=sxw/sw;
2031    
2032    c        write(*,*) 'beta_mean_tof ',beta_mean_tof
2033    
2034            beta_help = beta_mean_tof  !  pow(beta_mean_tof,1.0) gave best results
2035    
2036    CCCCC        endif  !  if tof11_i > -1 && ...... beta calculation
2037    
2038    C-----------------------  Select charge   --------------------------
2039    
2040           charge=0
2041    
2042           if ((beta_mean_tof.gt.0.2).and.(beta_mean_tof.lt.2.0)) then
2043    
2044            icount1=0
2045            icount2=0
2046            icount3=0
2047    
2048            do jj=0,23
2049            a1 = adca(2*jj+1)
2050            a2 = adca(2*jj+2)
2051            if ((a1.lt.4095).and.(a2.lt.4095)) then
2052            a1 = adca(2*jj+1)*cos(theta)
2053            a2 = adca(2*jj+2)*cos(theta)
2054            xhelp  = 100000.
2055            xhelp1 = 100000.
2056            xhelp = sqrt(a1*a2)  ! geometric mean
2057            xhelp1 = beta_help*xhelp
2058    C if geometric mean multiplied by beta_help is inside/outside helium
2059    C limits, increase counter
2060           if (xhelp1.lt.A_l(jj+1))  icount1=icount1+1
2061           if ((xhelp1.gt.A_l(jj+1)).and.(xhelp1.lt.A_h(jj+1)))
2062         &                           icount2=icount2+1
2063           if (xhelp1.gt.A_h(jj+1))  icount3=icount3+1
2064                                                endif
2065            enddo
2066    
2067    
2068    C  if more than three paddles see the same...
2069    
2070            if (icount1 .gt. 3) charge=1
2071            if (icount2 .gt. 3) charge=2
2072            if (icount3 .gt. 3) charge=3
2073    
2074                                                        endif  ! 0.2<beta<2.0
2075    
2076    C  no beta found? Sum up geometric means of paddles and derive the mean...
2077    
2078           if (beta_mean_tof.eq.100.) then
2079    
2080           xhelp  = 0.
2081           icount = 0
2082    
2083           if (tof11_i.gt.-1) then
2084           jj=tof11_i
2085           a1 = adca(0+2*jj+1)
2086           a2 = adca(0+2*jj+2)
2087           if ((a1.lt.4095).and.(a2.lt.4095)) then
2088           a1 = a1*cos(theta)
2089           a2 = a2*cos(theta)
2090           xhelp = xhelp + sqrt(a1*a2)
2091           icount=icount+1
2092                        endif
2093                        endif
2094    
2095           if (tof12_i.gt.-1) then
2096           jj=tof12_i
2097           a1 = adca(16+2*jj+1)
2098           a2 = adca(16+2*jj+2)
2099           if ((a1.lt.4095).and.(a2.lt.4095)) then
2100           a1 = a1*cos(theta)
2101           a2 = a2*cos(theta)
2102           xhelp = xhelp + sqrt(a1*a2)
2103           icount=icount+1
2104                        endif
2105                        endif
2106    
2107           if (tof21_i.gt.-1) then
2108           jj=tof21_i
2109           a1 = adca(28+2*jj+1)
2110           a2 = adca(28+2*jj+2)
2111           if ((a1.lt.4095).and.(a2.lt.4095)) then
2112           a1 = a1*cos(theta)
2113           a2 = a2*cos(theta)
2114           xhelp = xhelp + sqrt(a1*a2)
2115           icount=icount+1
2116                        endif
2117                        endif
2118    
2119           if (tof22_i.gt.-1) then
2120           jj=tof22_i
2121           a1 = adca(32+2*jj+1)
2122           a2 = adca(32+2*jj+2)
2123           if ((a1.lt.4095).and.(a2.lt.4095)) then
2124           a1 = a1*cos(theta)
2125           a2 = a2*cos(theta)
2126           xhelp = xhelp + sqrt(a1*a2)
2127           icount=icount+1
2128                        endif
2129                        endif
2130    
2131           if (tof31_i.gt.-1) then
2132           jj=tof31_i
2133           a1 = adca(36+2*jj+1)
2134           a2 = adca(36+2*jj+2)
2135           if ((a1.lt.4095).and.(a2.lt.4095)) then
2136           a1 = a1*cos(theta)
2137           a2 = a2*cos(theta)
2138           xhelp = xhelp + sqrt(a1*a2)
2139           icount=icount+1
2140                        endif
2141                        endif
2142    
2143           if (tof32_i.gt.-1) then
2144           jj=tof32_i
2145           a1 = adca(42+2*jj+1)
2146           a2 = adca(42+2*jj+2)
2147           if ((a1.lt.4095).and.(a2.lt.4095)) then
2148           a1 = a1*cos(theta)
2149           a2 = a2*cos(theta)
2150           xhelp = xhelp + sqrt(a1*a2)
2151           icount=icount+1
2152                        endif
2153                        endif
2154    
2155    
2156           if (icount.gt.0) xhelp=xhelp/icount
2157           if ((icount.gt.2).and.(xhelp.gt.1500.)) charge=3
2158    
2159                                      endif  ! beta_mean_tof.eq.100.
2160    
2161    c        write(*,*) 'in function charge: ',charge
2162            check_charge = charge
2163    
2164    
2165            END
2166    
2167    C****************************************************************************
2168    C****************************************************************************
2169    C****************************************************************************
2170    
2171            function newbeta(iflag,b,hitvec,resmax,qualitycut,chi2cut)
2172    
2173            include  'input_tof.txt'
2174            include  'output_tof.txt'
2175            include  'tofcomm.txt'
2176    
2177            REAL newbeta
2178            REAL resmax,qualitycut,chi2cut
2179            REAL w_i(12),w_il(6),quality,res,betachi,beta_mean_inv
2180            REAL sw,sxw,b(12),beta_mean,chi2,xhelp
2181            REAL tdcfl(4,12)
2182    
2183            INTEGER iflag,icount,hitvec(6)
2184    
2185            INTEGER itop(12),ibot(12)
2186            DATA itop /1,1,2,2,3,3,4,4,1,1,2,2/
2187            DATA ibot /5,6,5,6,5,6,5,6,3,4,3,4/
2188    
2189    
2190    c get rid of warnings EMILIANO
2191            slope = 0
2192            offset = 0
2193            none_find = 0
2194            none_ev = 0
2195            adc_ev = 0
2196            tdc_ev = 0
2197            iadc = 0
2198            itdc = 0
2199            right = 0
2200            left = 0
2201            tof12_y(1) = tof12_y(1)
2202            tof11_x(1) = tof11_x(1)
2203            tof21_y(1) = tof21_y(1)
2204            tof22_x(1) = tof22_x(1)
2205            tof32_y(1) = tof32_y(1)
2206            tof31_x(1) = tof31_x(1)
2207    c get rid of warnings
2208    
2209    C====================================================================
2210    
2211            tof11_i = hitvec(1)
2212            tof12_i = hitvec(2)
2213            tof21_i = hitvec(3)
2214            tof22_i = hitvec(4)
2215            tof31_i = hitvec(5)
2216            tof32_i = hitvec(6)
2217    
2218             if (iflag.eq.1) then   ! call from tofl2com
2219             do i=1,4
2220             do j=1,12
2221              tdcfl(i,j) =  tdcflagtof(i,j)
2222             enddo
2223             enddo
2224                            endif
2225    
2226             if (iflag.eq.2) then   ! call from toftrk
2227             do i=1,4
2228             do j=1,12
2229              tdcfl(i,j) =  tdcflag(i,j)
2230             enddo
2231             enddo
2232                            endif
2233    
2234    
2235    C---  Find out ToF layers with artificial TDC values    -------------
2236    
2237            do jj=1,6
2238            w_il(jj) = 1000.
2239            enddo
2240    
2241    
2242            if (tof11_i.gt.0) then
2243            if ((tofmask(ch11a(tof11_i),hb11a(tof11_i)).gt.0).or.
2244         &   (tofmask(ch11b(tof11_i),hb11b(tof11_i)).gt.0)) then
2245            w_il(1)=0
2246            i1=tdcfl(ch11a(tof11_i),hb11a(tof11_i))
2247            i2=tdcfl(ch11b(tof11_i),hb11b(tof11_i))
2248            if ((i1.eq.1).or.(i2.eq.1)) w_il(1) = 1  ! tdcflag
2249                                                          endif
2250                               endif
2251    
2252            if (tof12_i.gt.0) then
2253            if ((tofmask(ch12a(tof12_i),hb12a(tof12_i)).gt.0).or.
2254         &   (tofmask(ch12b(tof12_i),hb12b(tof12_i)).gt.0)) then
2255            w_il(2)=0
2256            i1=tdcfl(ch12a(tof12_i),hb12a(tof12_i))
2257            i2=tdcfl(ch12b(tof12_i),hb12b(tof12_i))
2258            if ((i1.eq.1).or.(i2.eq.1)) w_il(2) = 1  ! tdcflag
2259                                                          endif
2260                               endif
2261    
2262            if (tof21_i.gt.0) then
2263            if ((tofmask(ch21a(tof21_i),hb21a(tof21_i)).gt.0).or.
2264         &   (tofmask(ch21b(tof21_i),hb21b(tof21_i)).gt.0)) then
2265            w_il(3)=0
2266            i1=tdcfl(ch21a(tof21_i),hb21a(tof21_i))
2267            i2=tdcfl(ch21b(tof21_i),hb21b(tof21_i))
2268            if ((i1.eq.1).or.(i2.eq.1)) w_il(3) = 1  ! tdcflag
2269                                                          endif
2270                               endif
2271    
2272            if (tof22_i.gt.0) then
2273            if ((tofmask(ch22a(tof22_i),hb22a(tof22_i)).gt.0).or.
2274         &   (tofmask(ch22b(tof22_i),hb22b(tof22_i)).gt.0)) then
2275            w_il(4)=0
2276            i1=tdcfl(ch22a(tof22_i),hb22a(tof22_i))
2277            i2=tdcfl(ch22b(tof22_i),hb22b(tof22_i))
2278            if ((i1.eq.1).or.(i2.eq.1)) w_il(4) = 1  ! tdcflag
2279                                                          endif
2280                               endif
2281    
2282            if (tof31_i.gt.0) then
2283            if ((tofmask(ch31a(tof31_i),hb11a(tof31_i)).gt.0).or.
2284         &   (tofmask(ch31b(tof31_i),hb31b(tof31_i)).gt.0)) then
2285            w_il(5)=0
2286            i1=tdcfl(ch31a(tof31_i),hb31a(tof31_i))
2287            i2=tdcfl(ch31b(tof31_i),hb31b(tof31_i))
2288            if ((i1.eq.1).or.(i2.eq.1)) w_il(5) = 1  ! tdcflag
2289                                                          endif
2290                               endif
2291    
2292            if (tof32_i.gt.0) then
2293            if ((tofmask(ch32a(tof32_i),hb32a(tof32_i)).gt.0).or.
2294         &   (tofmask(ch32b(tof32_i),hb32b(tof32_i)).gt.0)) then
2295            w_il(6)=0
2296            i1=tdcfl(ch32a(tof32_i),hb32a(tof32_i))
2297            i2=tdcfl(ch32b(tof32_i),hb32b(tof32_i))
2298            if ((i1.eq.1).or.(i2.eq.1)) w_il(6) = 1  ! tdcflag
2299                                                          endif
2300                               endif
2301    
2302    C------------------------------------------------------------------------
2303    C---  Set weights for the 12 measurements using information for top and bottom:
2304    C---  if no measurements: weight = set to very high value=> not used
2305    C---  top or bottom artificial: weight*sqrt(2)
2306    C---  top and bottom artificial: weight*sqrt(2)*sqrt(2)
2307    
2308           DO jj=1,12
2309           if (jj.le.4)           xhelp = 0.11            ! S1-S3
2310           if ((jj.gt.4).and.(jj.le.8)) xhelp = 0.18      ! S2-S3
2311           if (jj.gt.8)           xhelp = 0.28            ! S1-S2
2312           if ((w_il(itop(jj)).eq.1000.).and.(w_il(ibot(jj)).eq.1000.))
2313         &   xhelp = 1.E09
2314           if ((w_il(itop(jj)).eq.1).or.(w_il(ibot(jj)).eq.1.))
2315         &   xhelp = xhelp*1.414
2316           if ((w_il(itop(jj)).eq.1).and.(w_il(ibot(jj)).eq.1.))
2317         &   xhelp = xhelp*2.
2318           w_i(jj) = 1./xhelp
2319           ENDDO
2320    
2321    C========================================================================
2322    C--- Calculate mean beta for the first time -----------------------------
2323    C--- We are using "1/beta" since its error is gaussian ------------------
2324    
2325            icount=0
2326            sw=0.
2327            sxw=0.
2328            beta_mean=100.
2329    
2330            DO jj=1,12
2331            IF ((abs(1./b(jj)).gt.0.1).and.(abs(1./b(jj)).lt.15.)) THEN
2332                icount = icount+1
2333                sxw    = sxw + (1./b(jj))*w_i(jj)*w_i(jj)
2334                sw     = sw + w_i(jj)*w_i(jj)
2335            ENDIF
2336            ENDDO
2337    
2338            if (icount.gt.0) beta_mean=1./(sxw/sw)
2339            beta_mean_inv = 1./beta_mean
2340    
2341      
2342    C--- Calculate beta for the second time, use residuals of the single
2343    C--- measurements to get a chi2 value
2344    
2345            icount  = 0
2346            sw      = 0.
2347            sxw     = 0.
2348            betachi = 100.
2349            chi2    = 0.
2350            quality = 0.
2351    
2352            DO jj=1,12
2353            IF ((abs(1./b(jj)).gt.0.1).and.(abs(1./b(jj)).lt.15.)
2354         &                                .and.(w_i(jj).GT.0.01)) THEN
2355                res    = beta_mean_inv - (1./b(jj)) ;
2356                if (abs(res*w_i(jj)).lt.resmax) THEN
2357                chi2   = chi2 + (res*w_i(jj))**2.
2358                icount = icount+1
2359                sxw    = sxw + (1./b(jj))*w_i(jj)*w_i(jj)
2360                sw     = sw + w_i(jj)*w_i(jj)
2361                                                ENDIF
2362            ENDIF
2363            ENDDO
2364    
2365    c        quality = sw
2366            quality = sqrt(sw)
2367    
2368            if (icount.eq.0) chi2 = 1000.
2369            if (icount.gt.0) chi2 = chi2/(icount)
2370    
2371            if (icount.gt.0) betachi=1./(sxw/sw);
2372    
2373            beta_mean=100.
2374            if ((chi2.lt.chi2cut).and.(quality.gt.qualitycut))
2375         &  beta_mean = betachi
2376            newbeta = beta_mean
2377    
2378            END
2379    
2380    C****************************************************************************
2381    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.23