/[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.7 by mocchiut, Mon Mar 3 09:51:03 2008 UTC revision 1.14 by mocchiut, Wed Feb 17 11:50:53 2010 UTC
# Line 26  C  feb-08 WM: Calculation of beta(13) ch Line 26  C  feb-08 WM: Calculation of beta(13) ch
26  C             then in a second step we check the residuals of the single  C             then in a second step we check the residuals of the single
27  C             measurements, reject if > 10 sigma, calculate chi2 and "quality"  C             measurements, reject if > 10 sigma, calculate chi2 and "quality"
28  C             beta is taken as good if chi2<20 and quality>10  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  nov-09 WM: the dEdx part ("adctof_c") moved to the new dEdx routine from Napoli
35    C  feb-10 WM: k1 values now for Z=1, Z=2, Z>2, k2 values are fix
36  C******************************************************************************  C******************************************************************************
37    
38        INTEGER FUNCTION TOFL2COM()        INTEGER FUNCTION TOFL2COM()
# Line 45  C     Line 52  C    
52        INTEGER j,hitvec(6)        INTEGER j,hitvec(6)
53    
54        REAL dx,dy,dr,ds        REAL dx,dy,dr,ds
55        REAL yhelp,xhelp,xhelp1,xhelp2        REAL yhelp,yhelp1,yhelp2,xhelp,xhelp1,xhelp2
56        REAL c1,c2        REAL c1,c2
57          REAL dist
58    
59  C      REAL sw,sxw,w_i  C      REAL sw,sxw,w_i
60  C      INTEGER icount  C      INTEGER icount
# Line 99  c     second index : 1... number of padd Line 107  c     second index : 1... number of padd
107    
108                
109        REAL theta13        REAL theta13
110  C--   DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006  
111          DOUBLE PRECISION ZTOF(6)
112          DATA ZTOF/53.74,53.04,23.94,23.44,-23.49,-24.34/ !Sergio 9.05.2006
113    
114        REAL tofarm12        REAL tofarm12
115        PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69        PARAMETER (tofarm12 = 29.70) ! from 53.39 to 23.69
116        REAL tofarm23                REAL tofarm23        
117        PARAMETER (tofarm23 = 47.61)  ! from 23.69 to -23.92        PARAMETER (tofarm23 = 47.61)  ! from 23.69 to -23.92
118        REAL tofarm13        REAL tofarm13
119        PARAMETER (tofarm13 = 77.31)  ! from 53.39 to -23.92        PARAMETER (tofarm13 = 77.31)  ! from 53.39 to -23.92
# Line 115  C--   DATA ZTOF/53.74,53.04,23.94,23.44, Line 126  C--   DATA ZTOF/53.74,53.04,23.94,23.44,
126        REAL atten,pc_adc,check_charge,newbeta        REAL atten,pc_adc,check_charge,newbeta
127    
128        INTEGER IZ        INTEGER IZ
       REAL k1corrA1,k1corrB1,k1corrC1  
129    
130    
131        INTEGER ifst        INTEGER ifst
# Line 151  C     ratio between helium and proton ca Line 161  C     ratio between helium and proton ca
161         itdc = 1         itdc = 1
162         iadc = 2         iadc = 2
163    
 C--- These are the corrections to the k1-value for Z>2 particles  
        k1corrA1 = 0.  
        k1corrB1 = -5.0  
        k1corrC1=  8.0  
   
   
164          ENDIF          ENDIF
165  C---------------------------------------------------------------------  C---------------------------------------------------------------------
166    
# Line 575  c     check if an other paddle has also Line 579  c     check if an other paddle has also
579         hitvec(5)=tof31_i         hitvec(5)=tof31_i
580         hitvec(6)=tof32_i         hitvec(6)=tof32_i
581    
 c       write(*,*) 'tofl2com',  
 c     &   tof11_i,tof12_i,tof21_i,tof22_i,tof31_i,tof32_i  
582    
583  C------------------------------------------------------------------  C------------------------------------------------------------------
584  C--  calculate track position in paddle using timing difference  C--  calculate track position in paddle using timing difference
# Line 634  C--------------------------------------- Line 636  C---------------------------------------
636  C---------------------  zenith angle theta  ---------------------------  C---------------------  zenith angle theta  ---------------------------
637  C----------------------------------------------------------------------  C----------------------------------------------------------------------
638    
639        dx=0.         xhelp1=0.
640        dy=0.         if (tof11_i.GT.none_find) xhelp1=tof11_x(tof11_i)
641        dr=0.         if (xtofpos(1).lt.100)  xhelp1=xtofpos(1)
642        theta13 = 0.  
643           yhelp1=0.
644           IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find))         if (tof12_i.GT.none_find) yhelp1=tof12_y(tof12_i)
645       &        dx  = xtofpos(1) - xtofpos(3)         if (ytofpos(1).lt.100)  yhelp1=ytofpos(1)
646           IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find))  
647       &        dy  = ytofpos(1) - ytofpos(3)  
648           dr = sqrt(dx*dx+dy*dy)         yhelp2=0.
649           theta13 = atan(dr/tofarm13)         if (tof32_i.GT.none_find) yhelp2=tof32_y(tof32_i)
650           if (ytofpos(3).lt.100)  yhelp2=ytofpos(3)
651    
652           xhelp2=0.
653           if (tof31_i.GT.none_find) xhelp2=tof31_x(tof31_i)
654           if (xtofpos(3).lt.100)  xhelp2=xtofpos(3)
655    
656    
657           dx=0.
658           dy=0.
659           dr=0.
660           theta13 = 0.
661    
662           dx  = xhelp1 - xhelp2
663           dy  = yhelp1 - yhelp2
664           dr = sqrt(dx*dx+dy*dy)
665           theta13 = atan(dr/tofarm13)
666    
667    
668  C----------------------------------------------------------------------  C----------------------------------------------------------------------
# Line 656  C--- the k1 constants in the beta calcul Line 674  C--- the k1 constants in the beta calcul
674  C----------------------------------------------------------------------  C----------------------------------------------------------------------
675    
676           iz = int(check_charge(theta13,hitvec))           iz = int(check_charge(theta13,hitvec))
677  C         write(*,*) 'in tofl2com',iz  C         write(*,*) 'charge in tofl2com',iz
678    
679  C--------------------------------------------------------------------  C--------------------------------------------------------------------
680  C---- if TDCleft.and.TDCright and NO ADC insert artificial ADC  C---- if TDCleft.and.TDCright and NO ADC insert artificial ADC
# Line 673  c       DATA tof32_y/ -5.0,0.0,5.0/ Line 691  c       DATA tof32_y/ -5.0,0.0,5.0/
691    
692  C----------------------------  S1 -------------------------------------  C----------------------------  S1 -------------------------------------
693    
694         yhelp=0.  c       yhelp=0.
695           yhelp=100.  ! WM
696         if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)         if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)
697         if (ytofpos(1).lt.100)  yhelp=ytofpos(1)         if (ytofpos(1).lt.100)  yhelp=ytofpos(1)
698    
# Line 693  C----------------------------  S1 ------ Line 712  C----------------------------  S1 ------
712           endif           endif
713         ENDIF         ENDIF
714    
715         xhelp=0.  c       xhelp=0.
716           xhelp=100.  ! WM
717         if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)         if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)
718         if (xtofpos(1).lt.100)  xhelp=xtofpos(1)         if (xtofpos(1).lt.100)  xhelp=xtofpos(1)
719    
# Line 715  C----------------------------  S1 ------ Line 735  C----------------------------  S1 ------
735    
736  C-----------------------------S2 --------------------------------  C-----------------------------S2 --------------------------------
737    
738         xhelp=0.  c       xhelp=0.
739           xhelp=100.   ! WM
740         if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)         if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)
741         if (xtofpos(2).lt.100)  xhelp=xtofpos(2)         if (xtofpos(2).lt.100)  xhelp=xtofpos(2)
742    
# Line 736  C-----------------------------S2 ------- Line 757  C-----------------------------S2 -------
757         ENDIF         ENDIF
758    
759    
760         yhelp=0.  c       yhelp=0.
761           yhelp=100.   ! WM
762         if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)         if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)
763         if (ytofpos(2).lt.100)  yhelp=ytofpos(2)         if (ytofpos(2).lt.100)  yhelp=ytofpos(2)
764    
# Line 758  C-----------------------------S2 ------- Line 780  C-----------------------------S2 -------
780    
781  C-----------------------------S3 --------------------------------  C-----------------------------S3 --------------------------------
782    
783         yhelp=0.  c       yhelp=0.
784           yhelp=100.  ! WM
785         if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)         if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)
786         if (ytofpos(3).lt.100)  yhelp=ytofpos(3)         if (ytofpos(3).lt.100)  yhelp=ytofpos(3)
787    
# Line 778  C-----------------------------S3 ------- Line 801  C-----------------------------S3 -------
801           endif           endif
802         ENDIF         ENDIF
803    
804         xhelp=0.  c       xhelp=0.
805           xhelp=100.   ! WM
806         if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)         if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)
807         if (xtofpos(3).lt.100)  xhelp=xtofpos(3)         if (xtofpos(3).lt.100)  xhelp=xtofpos(3)
808    
# Line 918  C---- Line 942  C----
942           tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)           tdc_c(ch32b(i),hb32b(i))=tof32(right,i,itdc)
943                                               ENDIF                                               ENDIF
944        ENDDO        ENDDO
945                  
946    
947  C---------------------------------------------------------------  C---------------------------------------------------------------
948  C--- calculate track position in paddle using timing difference  C--- calculate track position in paddle using timing difference
949  C--- now using the time-walk corrected TDC values  C--- now using the time-walk corrected TDC values
# Line 934  C-----------------------------S1 ------- Line 959  C-----------------------------S1 -------
959        IF (tof11_i.GT.none_find) THEN        IF (tof11_i.GT.none_find) THEN
960           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.
961       +        -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)       +        -y_coor_lin11(tof11_i,offset))/y_coor_lin11(tof11_i,slope)
962           i=tof11_i
963        endif        endif
964    
965        IF (tof12_i.GT.none_find) THEN        IF (tof12_i.GT.none_find) THEN
966           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.
967       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)       +        -x_coor_lin12(tof12_i,offset))/x_coor_lin12(tof12_i,slope)
968          i=tof12_i
969        endif        endif
970    
971    
# Line 947  C-----------------------------S2 ------- Line 974  C-----------------------------S2 -------
974        IF (tof21_i.GT.none_find) THEN        IF (tof21_i.GT.none_find) THEN
975           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.
976       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)       +        -x_coor_lin21(tof21_i,offset))/x_coor_lin21(tof21_i,slope)
977          i=tof21_i
978        endif        endif
979    
980        IF (tof22_i.GT.none_find) THEN        IF (tof22_i.GT.none_find) THEN
981           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.
982       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)       +        -y_coor_lin22(tof22_i,offset))/y_coor_lin22(tof22_i,slope)
983          i=tof22_i
984        endif        endif
985                
986    
# Line 960  C-----------------------------S3 ------- Line 989  C-----------------------------S3 -------
989        IF (tof31_i.GT.none_find) THEN        IF (tof31_i.GT.none_find) THEN
990           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.
991       +        -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)       +        -y_coor_lin31(tof31_i,offset))/y_coor_lin31(tof31_i,slope)
992          i=tof31_i
993        endif        endif
994    
995        IF (tof32_i.GT.none_find) THEN        IF (tof32_i.GT.none_find) THEN
996           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.
997       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)       +        -x_coor_lin32(tof32_i,offset))/x_coor_lin32(tof32_i,slope)
998          i=tof32_i
999        endif        endif
1000    
1001    
# Line 977  c            ytofpos(i)=101. Line 1008  c            ytofpos(i)=101.
1008  c         endif  c         endif
1009  c      enddo  c      enddo
1010    
1011    
1012  C--  restrict TDC measurements to physical paddle dimensions +/- 10 cm  C--  restrict TDC measurements to physical paddle dimensions +/- 10 cm
1013  C--  this cut is now stronger than in the old versions  C--  this cut is now stronger than in the old versions
1014    
# Line 988  C--  this cut is now stronger than in th Line 1020  C--  this cut is now stronger than in th
1020          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.          if (abs(ytofpos(2)).gt.18.)  ytofpos(2)=101.
1021          if (abs(ytofpos(3)).gt.18.)  ytofpos(3)=101.          if (abs(ytofpos(3)).gt.18.)  ytofpos(3)=101.
1022    
   
1023  C----------------------------------------------------------------------  C----------------------------------------------------------------------
1024  C---------------------  zenith angle theta  ---------------------------  C---------------------  zenith angle theta  ---------------------------
1025  C----------------------------------------------------------------------  C----------------------------------------------------------------------
1026    C-------------------  improved calculation  ---------------------------
1027    
1028        dx=0.         xhelp1=0.
1029        dy=0.         if (tof11_i.GT.none_find) xhelp1=tof11_x(tof11_i)
1030        dr=0.         if (xtofpos(1).lt.100)  xhelp1=xtofpos(1)
1031        theta13 = 0.  
1032           yhelp1=0.
1033           IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find))         if (tof12_i.GT.none_find) yhelp1=tof12_y(tof12_i)
1034       &        dx  = xtofpos(1) - xtofpos(3)         if (ytofpos(1).lt.100)  yhelp1=ytofpos(1)
1035           IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find))  
1036       &        dy  = ytofpos(1) - ytofpos(3)         yhelp2=0.
1037           dr = sqrt(dx*dx+dy*dy)         if (tof32_i.GT.none_find) yhelp2=tof32_y(tof32_i)
1038           theta13 = atan(dr/tofarm13)         if (ytofpos(3).lt.100)  yhelp2=ytofpos(3)
1039    
1040  C------------------------------------------------------------------         xhelp2=0.
1041  c      dx=0.         if (tof31_i.GT.none_find) xhelp2=tof31_x(tof31_i)
1042  c      dy=0.         if (xtofpos(3).lt.100)  xhelp2=xtofpos(3)
1043  c      dr=0.  
1044  c      theta12 = 0.  
1045  c         dx=0.
1046  c         IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find))         dy=0.
1047  c     &        dx  = xtofpos(1) - xtofpos(2)         dr=0.
1048  c         IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find))         theta13 = 0.
1049  c     &        dy  = ytofpos(1) - ytofpos(2)  
1050  c         dr = sqrt(dx*dx+dy*dy)         dx  = xhelp1 - xhelp2
1051  c         theta12 = atan(dr/tofarm12)         dy  = yhelp1 - yhelp2
1052  c                 dr = sqrt(dx*dx+dy*dy)
1053  c      dx=0.         theta13 = atan(dr/tofarm13)
 c      dy=0.  
 c      dr=0.  
 c      theta23 = 0.  
 c  
 c         IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find))  
 c     &        dx  = xtofpos(2) - xtofpos(3)  
 c         IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find))  
 c     &        dy  = ytofpos(2) - ytofpos(3)  
 c         dr = sqrt(dx*dx+dy*dy)  
 c         theta23 = atan(dr/tofarm23)  
 c          
 C----------------------------------------------------------------------  
 C------------------angle and ADC(x) correction  
 C----------------------------------------------------------------------  
 C-----------------------------S1 --------------------------------  
 c middle y (or x) position of the upper and middle ToF-Paddle  
 c       DATA tof11_x/ -17.85,-12.75,-7.65,-2.55,2.55,7.65,12.75,17.85/  
 c       DATA tof12_y/ -13.75,-8.25,-2.75,2.75,8.25,13.75/  
 c       DATA tof21_y/  3.75,-3.75/     ! paddles in different order  
 c       DATA tof22_x/ -4.5,4.5/  
 c       DATA tof31_x/ -6.0,0.,6.0/  
 c       DATA tof32_y/ -5.0,0.0,5.0/  
   
       yhelp=0.  
       if (tof12_i.GT.none_find) yhelp=tof12_y(tof12_i)  
       if (ytofpos(1).lt.100)  yhelp=ytofpos(1)  
   
       IF (tof11_i.GT.none_find.AND.abs(yhelp).lt.100) THEN  
   
          i = tof11_i  
          if (tof11(left,i,iadc).lt.3786) then  
 c          if (adc(ch11a(i),hb11a(i)).lt.4095) then  
             tof11(left,i,iadc) = tof11(left,i,iadc)*cos(theta13)  
             xkorr = atten(left,11,i,yhelp)  
 c            write(40+i,*) yhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch11a(i),hb11a(i))=tof11(left,i,iadc)/xkorr  
          endif  
   
          if (tof11(right,i,iadc).lt.3786) then  
 c          if (adc(ch11b(i),hb11b(i)).lt.4095) then  
             tof11(right,i,iadc) = tof11(right,i,iadc)*cos(theta13)  
             xkorr = atten(right,11,i,yhelp)  
 c            write(40+i,*) yhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch11b(i),hb11b(i))=tof11(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
       xhelp=0.  
       if (tof11_i.GT.none_find) xhelp=tof11_x(tof11_i)  
       if (xtofpos(1).lt.100)  xhelp=xtofpos(1)  
   
       IF (tof12_i.GT.none_find.AND.abs(xhelp).lt.100) THEN  
   
          i = tof12_i  
          if (tof12(left,i,iadc).lt.3786) then  
 c          if (adc(ch12a(i),hb12a(i)).lt.4095) then  
             tof12(left,i,iadc) = tof12(left,i,iadc)*cos(theta13)  
             xkorr = atten(left,12,i,xhelp)  
 c            write(50+i,*) xhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch12a(i),hb12a(i))=tof12(left,i,iadc)/xkorr  
          endif  
   
          if (tof12(right,i,iadc).lt.3786) then  
 c          if (adc(ch12b(i),hb12b(i)).lt.4095) then  
             tof12(right,i,iadc) = tof12(right,i,iadc)*cos(theta13)  
             xkorr = atten(right,12,i,xhelp)  
 c            write(50+i,*) xhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch12b(i),hb12b(i))=tof12(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
 C-----------------------------S2 --------------------------------  
   
       xhelp=0.  
       if (tof22_i.GT.none_find) xhelp=tof22_x(tof22_i)  
       if (xtofpos(2).lt.100)  xhelp=xtofpos(2)  
   
       IF (tof21_i.GT.none_find.AND.abs(xhelp).lt.100) THEN  
   
          i = tof21_i  
          if (tof21(left,i,iadc).lt.3786) then  
 c          if (adc(ch21a(i),hb21a(i)).lt.4095) then  
             tof21(left,i,iadc) = tof21(left,i,iadc)*cos(theta13)  
             xkorr = atten(left,21,i,xhelp)  
 c            write(60+i,*) xhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch21a(i),hb21a(i))=tof21(left,i,iadc)/xkorr  
          endif  
   
          if (tof21(right,i,iadc).lt.3786) then  
 c          if (adc(ch21b(i),hb21b(i)).lt.4095) then  
             tof21(right,i,iadc) = tof21(right,i,iadc)*cos(theta13)  
             xkorr=adcx21(right,i,1)*exp(xhelp/adcx21(right,i,2))  
             xkorr = atten(right,21,i,xhelp)  
 c            write(60+i,*) xhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch21b(i),hb21b(i))=tof21(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
1054    
       yhelp=0.  
       if (tof21_i.GT.none_find) yhelp=tof21_y(tof21_i)  
       if (ytofpos(2).lt.100)  yhelp=ytofpos(2)  
1055    
1056        IF (tof22_i.GT.none_find.AND.abs(yhelp).lt.100) THEN  C------------------------------------------------------------------
1057    C------------------------------------------------------------------
1058           i = tof22_i  C-------angle and ADC(x) correction: moved to new dEdx routine
1059           if (tof22(left,i,iadc).lt.3786) then  C------------------------------------------------------------------
1060  c          if (adc(ch22a(i),hb22a(i)).lt.4095) then  C------------------------------------------------------------------
             tof22(left,i,iadc) = tof22(left,i,iadc)*cos(theta13)  
             xkorr = atten(left,22,i,yhelp)  
 c            write(70+i,*) yhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch22a(i),hb22a(i))=tof22(left,i,iadc)/xkorr  
          endif  
   
          if (tof22(right,i,iadc).lt.3786) then  
 c          if (adc(ch22b(i),hb22b(i)).lt.4095) then  
             tof22(right,i,iadc) = tof22(right,i,iadc)*cos(theta13)  
             xkorr = atten(right,22,i,yhelp)  
 c            write(70+i,*) yhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch22b(i),hb22b(i))=tof22(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
 C-----------------------------S3 --------------------------------  
   
       yhelp=0.  
       if (tof32_i.GT.none_find) yhelp=tof32_y(tof32_i)  
       if (ytofpos(3).lt.100)  yhelp=ytofpos(3)  
   
       IF (tof31_i.GT.none_find.AND.abs(yhelp).lt.100) THEN  
   
          i = tof31_i  
          if (tof31(left,i,iadc).lt.3786) then  
 c          if (adc(ch31a(i),hb31a(i)).lt.4095) then  
             tof31(left,i,iadc) = tof31(left,i,iadc)*cos(theta13)  
             xkorr = atten(left,31,i,yhelp)  
 c            write(80+i,*) yhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch31a(i),hb31a(i))=tof31(left,i,iadc)/xkorr  
          endif  
   
          if (tof31(right,i,iadc).lt.3786) then  
 c          if (adc(ch31b(i),hb31b(i)).lt.4095) then  
             tof31(right,i,iadc) = tof31(right,i,iadc)*cos(theta13)  
             xkorr = atten(right,31,i,yhelp)  
 c            write(80+i,*) yhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch31b(i),hb31b(i))=tof31(right,i,iadc)/xkorr  
          endif  
       ENDIF  
   
       xhelp=0.  
       if (tof31_i.GT.none_find) xhelp=tof31_x(tof31_i)  
       if (xtofpos(3).lt.100)  xhelp=xtofpos(3)  
   
       IF (tof32_i.GT.none_find.AND.abs(xhelp).lt.100) THEN  
   
          i = tof32_i  
          if (tof32(left,i,iadc).lt.3786) then  
 c          if (adc(ch32a(i),hb32a(i)).lt.4095) then  
             tof32(left,i,iadc) = tof32(left,i,iadc)*cos(theta13)  
             xkorr = atten(left,32,i,xhelp)  
 c            write(90+i,*) xhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch32a(i),hb32a(i))=tof32(left,i,iadc)/xkorr  
          endif  
   
          if (tof32(right,i,iadc).lt.3786) then  
 c          if (adc(ch32b(i),hb32b(i)).lt.4095) then  
             tof32(right,i,iadc) = tof32(right,i,iadc)*cos(theta13)  
             xkorr = atten(right,32,i,xhelp)  
 c            write(90+i,*) xhelp,xkorr  
             if (iz.le.1) xkorr=xkorr/hepratio  
             adctof_c(ch32b(i),hb32b(i))=tof32(right,i,iadc)/xkorr  
          endif  
       ENDIF  
1061    
1062  C--------------------------------------------------------------------  C--------------------------------------------------------------------
1063  C----------------------calculate Beta  ------------------------------  C----------------------calculate Beta  ------------------------------
# Line 1217  C     since TDC resolution varies slight Line 1072  C     since TDC resolution varies slight
1072    
1073  C     S11 - S31  C     S11 - S31
1074    
1075          dist = ZTOF(1) - ZTOF(5)
1076          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1077    
1078         IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1079       &    (ytofpos(1).NE.101.).AND.(ytofpos(3).NE.101.)) THEN       &    (ytofpos(1).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1080           xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)           xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1081           xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)           xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1082           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1083           ihelp=(tof11_i-1)*3+tof31_i           ihelp=(tof11_i-1)*3+tof31_i
1084           c1 = k_S11S31(1,ihelp)           if (iz.le.1) c1 = k_S11S31(1,ihelp)
1085           if (iz.gt.2) c1 = c1 + k1corrA1           if (iz.eq.2) c1 = k_S11S31(2,ihelp)
1086           c2 = k_S11S31(2,ihelp)           if (iz.gt.2) c1 = k_S11S31(3,ihelp)
1087           betatof_a(1) = c2/(cos(theta13)*(ds-c1))           betatof_a(1) = c2/(cos(theta13)*(ds-c1))
1088    
1089  C------- ToF Mask - S11 - S31  C------- ToF Mask - S11 - S31
# Line 1246  C------- Line 1104  C-------
1104                
1105  C     S11 - S32  C     S11 - S32
1106    
1107          dist = ZTOF(1) - ZTOF(6)
1108          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1109    
1110         IF ((tof11_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1111       &    (ytofpos(1).NE.101.).AND.(xtofpos(3).NE.101.)) THEN       &    (ytofpos(1).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1112           xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)           xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1113           xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)           xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1114           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1115           ihelp=(tof11_i-1)*3+tof32_i           ihelp=(tof11_i-1)*3+tof32_i
1116           c1 = k_S11S32(1,ihelp)           if (iz.le.1) c1 = k_S11S32(1,ihelp)
1117           if (iz.gt.2) c1 = c1 + k1corrA1           if (iz.eq.2) c1 = k_S11S32(2,ihelp)
1118           c2 = k_S11S32(2,ihelp)           if (iz.gt.2) c1 = k_S11S32(3,ihelp)
1119           betatof_a(2) = c2/(cos(theta13)*(ds-c1))           betatof_a(2) = c2/(cos(theta13)*(ds-c1))
1120    
1121  C------- ToF Mask - S11 - S32  C------- ToF Mask - S11 - S32
# Line 1275  C------- Line 1136  C-------
1136                
1137  C     S12 - S31  C     S12 - S31
1138    
1139          dist = ZTOF(2) - ZTOF(5)
1140          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1141    
1142         IF ((tof12_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1143       &    (xtofpos(1).NE.101.).AND.(ytofpos(3).NE.101.)) THEN       &    (xtofpos(1).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1144           xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)           xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1145           xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)           xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1146           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1147           ihelp=(tof12_i-1)*3+tof31_i           ihelp=(tof12_i-1)*3+tof31_i
1148           c1 = k_S12S31(1,ihelp)           if (iz.le.1) c1 = k_S12S31(1,ihelp)
1149           if (iz.gt.2) c1 = c1 + k1corrA1           if (iz.eq.2) c1 = k_S12S31(2,ihelp)
1150           c2 = k_S12S31(2,ihelp)           if (iz.gt.2) c1 = k_S12S31(3,ihelp)
1151           betatof_a(3) = c2/(cos(theta13)*(ds-c1))           betatof_a(3) = c2/(cos(theta13)*(ds-c1))
1152    
1153  C------- ToF Mask - S12 - S31  C------- ToF Mask - S12 - S31
# Line 1304  C------- Line 1168  C-------
1168                            
1169  C     S12 - S32  C     S12 - S32
1170    
1171          dist = ZTOF(2) - ZTOF(6)
1172          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1173    
1174         IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1175       &    (xtofpos(1).NE.101.).AND.(xtofpos(3).NE.101.)) THEN       &    (xtofpos(1).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1176           xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)           xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1177           xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)           xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1178           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1179           ihelp=(tof12_i-1)*3+tof32_i           ihelp=(tof12_i-1)*3+tof32_i
1180           c1 = k_S12S32(1,ihelp)           if (iz.le.1) c1 = k_S12S32(1,ihelp)
1181           if (iz.gt.2) c1 = c1 + k1corrA1           if (iz.eq.2) c1 = k_S12S32(2,ihelp)
1182           c2 = k_S12S32(2,ihelp)           if (iz.gt.2) c1 = k_S12S32(3,ihelp)
1183           betatof_a(4) = c2/(cos(theta13)*(ds-c1))           betatof_a(4) = c2/(cos(theta13)*(ds-c1))
1184    
1185  C------- ToF Mask - S12 - S32  C------- ToF Mask - S12 - S32
# Line 1333  C------- Line 1200  C-------
1200    
1201  C     S21 - S31  C     S21 - S31
1202    
1203          dist = ZTOF(3) - ZTOF(5)
1204          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1205    
1206         IF ((tof21_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof21_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1207       &    (xtofpos(2).NE.101.).AND.(ytofpos(3).NE.101.)) THEN       &    (xtofpos(2).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1208           xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)           xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1209           xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)           xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1210           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1211           ihelp=(tof21_i-1)*3+tof31_i           ihelp=(tof21_i-1)*3+tof31_i
1212           c1 = k_S21S31(1,ihelp)           if (iz.le.1) c1 = k_S21S31(1,ihelp)
1213           if (iz.gt.2) c1 = c1 + k1corrB1           if (iz.eq.2) c1 = k_S21S31(2,ihelp)
1214           c2 = k_S21S31(2,ihelp)           if (iz.gt.2) c1 = k_S21S31(3,ihelp)
1215           betatof_a(5) = c2/(cos(theta13)*(ds-c1))           betatof_a(5) = c2/(cos(theta13)*(ds-c1))
1216    
1217  C------- ToF Mask - S21 - S31  C------- ToF Mask - S21 - S31
# Line 1362  C------- Line 1232  C-------
1232    
1233  C     S21 - S32  C     S21 - S32
1234    
1235          dist = ZTOF(3) - ZTOF(6)
1236          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1237    
1238    
1239         IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof21_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1240       &    (xtofpos(2).NE.101.).AND.(xtofpos(3).NE.101.)) THEN       &    (xtofpos(2).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1241           xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)           xhelp1 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1242           xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)           xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1243           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1244           ihelp=(tof21_i-1)*3+tof32_i           ihelp=(tof21_i-1)*3+tof32_i
1245           c1 = k_S21S32(1,ihelp)           if (iz.le.1) c1 = k_S21S32(1,ihelp)
1246           if (iz.gt.2) c1 = c1 + k1corrB1           if (iz.eq.2) c1 = k_S21S32(2,ihelp)
1247           c2 = k_S21S32(2,ihelp)           if (iz.gt.2) c1 = k_S21S32(3,ihelp)
1248           betatof_a(6) = c2/(cos(theta13)*(ds-c1))           betatof_a(6) = c2/(cos(theta13)*(ds-c1))
1249                                        
1250  C------- ToF Mask - S21 - S32  C------- ToF Mask - S21 - S32
# Line 1391  C------- Line 1265  C-------
1265    
1266  C     S22 - S31  C     S22 - S31
1267    
1268          dist = ZTOF(4) - ZTOF(5)
1269          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1270    
1271         IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.         IF ((tof22_i.GT.none_find).AND.(tof31_i.GT.none_find).AND.
1272       &    (ytofpos(2).NE.101.).AND.(ytofpos(3).NE.101.)) THEN       &    (ytofpos(2).NE.101.).AND.(ytofpos(3).NE.101.)) THEN
1273           xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)           xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1274           xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)           xhelp2 = tof31(1,tof31_i,itdc)+tof31(2,tof31_i,itdc)
1275           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1276           ihelp=(tof22_i-1)*3+tof31_i           ihelp=(tof22_i-1)*3+tof31_i
1277           c1 = k_S22S31(1,ihelp)           if (iz.le.1) c1 = k_S22S31(1,ihelp)
1278           if (iz.gt.2) c1 = c1 + k1corrB1           if (iz.eq.2) c1 = k_S22S31(2,ihelp)
1279           c2 = k_S22S31(2,ihelp)           if (iz.gt.2) c1 = k_S22S31(3,ihelp)
1280           betatof_a(7) = c2/(cos(theta13)*(ds-c1))           betatof_a(7) = c2/(cos(theta13)*(ds-c1))
1281    
1282  C------- ToF Mask - S22 - S31  C------- ToF Mask - S22 - S31
# Line 1420  C-------           Line 1297  C-------          
1297                
1298  C     S22 - S32  C     S22 - S32
1299    
1300          dist = ZTOF(4) - ZTOF(6)
1301          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1302    
1303         IF ((tof22_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.         IF ((tof22_i.GT.none_find).AND.(tof32_i.GT.none_find).AND.
1304       &    (ytofpos(2).NE.101.).AND.(xtofpos(3).NE.101.)) THEN       &    (ytofpos(2).NE.101.).AND.(xtofpos(3).NE.101.)) THEN
1305           xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)           xhelp1 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1306           xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)           xhelp2 = tof32(1,tof32_i,itdc)+tof32(2,tof32_i,itdc)
1307           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1308           ihelp=(tof22_i-1)*3+tof32_i           ihelp=(tof22_i-1)*3+tof32_i
1309           c1 = k_S22S32(1,ihelp)           if (iz.le.1) c1 = k_S22S32(1,ihelp)
1310           if (iz.gt.2) c1 = c1 + k1corrB1           if (iz.eq.2) c1 = k_S22S32(2,ihelp)
1311           c2 = k_S22S32(2,ihelp)           if (iz.gt.2) c1 = k_S22S32(3,ihelp)
1312           betatof_a(8) = c2/(cos(theta13)*(ds-c1))           betatof_a(8) = c2/(cos(theta13)*(ds-c1))
1313    
1314  C------- ToF Mask - S22 - S32  C------- ToF Mask - S22 - S32
# Line 1449  C-------   Line 1329  C-------  
1329    
1330  C     S11 - S21  C     S11 - S21
1331    
1332          dist = ZTOF(1) - ZTOF(3)
1333          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1334    
1335         IF ((tof11_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
1336       &    (ytofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN       &    (ytofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN
1337           xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)           xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1338           xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)           xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1339           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1340           ihelp=(tof11_i-1)*2+tof21_i           ihelp=(tof11_i-1)*2+tof21_i
1341           c1 = k_S11S21(1,ihelp)           if (iz.le.1) c1 = k_S11S21(1,ihelp)
1342           if (iz.gt.2) c1 = c1 + k1corrC1           if (iz.eq.2) c1 = k_S11S21(2,ihelp)
1343           c2 = k_S11S21(2,ihelp)           if (iz.gt.2) c1 = k_S11S21(3,ihelp)
1344           betatof_a(9) = c2/(cos(theta13)*(ds-c1))           betatof_a(9) = c2/(cos(theta13)*(ds-c1))
1345    
1346  C------- ToF Mask - S11 - S21  C------- ToF Mask - S11 - S21
# Line 1478  C-------   Line 1361  C-------  
1361                
1362  C     S11 - S22  C     S11 - S22
1363    
1364          dist = ZTOF(1) - ZTOF(4)
1365          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1366    
1367         IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.         IF ((tof11_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
1368       &    (ytofpos(1).NE.101.).AND.(ytofpos(2).NE.101.)) THEN       &    (ytofpos(1).NE.101.).AND.(ytofpos(2).NE.101.)) THEN
1369           xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)           xhelp1 = tof11(1,tof11_i,itdc)+tof11(2,tof11_i,itdc)
1370           xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)           xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1371           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1372           ihelp=(tof11_i-1)*2+tof22_i           ihelp=(tof11_i-1)*2+tof22_i
1373           c1 = k_S11S22(1,ihelp)           if (iz.le.1) c1 = k_S11S22(1,ihelp)
1374           if (iz.gt.2) c1 = c1 + k1corrC1           if (iz.eq.2) c1 = k_S11S22(2,ihelp)
1375           c2 = k_S11S22(2,ihelp)           if (iz.gt.2) c1 = k_S11S22(3,ihelp)
1376           betatof_a(10) = c2/(cos(theta13)*(ds-c1))           betatof_a(10) = c2/(cos(theta13)*(ds-c1))
1377    
1378  C------- ToF Mask - S11 - S22  C------- ToF Mask - S11 - S22
# Line 1507  C-------   Line 1393  C-------  
1393    
1394  C     S12 - S21  C     S12 - S21
1395    
1396          dist = ZTOF(2) - ZTOF(3)
1397          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1398    
1399         IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof21_i.GT.none_find).AND.
1400       &    (xtofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN       &    (xtofpos(1).NE.101.).AND.(xtofpos(2).NE.101.)) THEN
1401           xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)           xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1402           xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)           xhelp2 = tof21(1,tof21_i,itdc)+tof21(2,tof21_i,itdc)
1403           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1404           ihelp=(tof12_i-1)*2+tof21_i           ihelp=(tof12_i-1)*2+tof21_i
1405           c1 = k_S12S21(1,ihelp)           if (iz.le.1) c1 = k_S12S21(1,ihelp)
1406           if (iz.gt.2) c1 = c1 + k1corrC1           if (iz.eq.2) c1 = k_S12S21(2,ihelp)
1407           c2 = k_S12S21(2,ihelp)           if (iz.gt.2) c1 = k_S12S21(3,ihelp)
1408           betatof_a(11) = c2/(cos(theta13)*(ds-c1))           betatof_a(11) = c2/(cos(theta13)*(ds-c1))
1409    
1410  C------- ToF Mask - S12 - S21  C------- ToF Mask - S12 - S21
# Line 1536  C-------   Line 1425  C-------  
1425    
1426  C     S12 - S22  C     S12 - S22
1427    
1428          dist = ZTOF(2) - ZTOF(4)
1429          c2 = (2.*0.01*dist)/(3.E08*50.E-12  )
1430    
1431         IF ((tof12_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.         IF ((tof12_i.GT.none_find).AND.(tof22_i.GT.none_find).AND.
1432       &    (xtofpos(1).NE.101.).AND.(ytofpos(2).NE.101.)) THEN       &    (xtofpos(1).NE.101.).AND.(ytofpos(2).NE.101.)) THEN
1433           xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)           xhelp1 = tof12(1,tof12_i,itdc)+tof12(2,tof12_i,itdc)
1434           xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)           xhelp2 = tof22(1,tof22_i,itdc)+tof22(2,tof22_i,itdc)
1435           ds = xhelp1-xhelp2           ds = xhelp1-xhelp2
1436           ihelp=(tof12_i-1)*2+tof22_i           ihelp=(tof12_i-1)*2+tof22_i
1437           c1 = k_S12S22(1,ihelp)           if (iz.le.1) c1 = k_S12S22(1,ihelp)
1438           if (iz.gt.2) c1 = c1 + k1corrC1           if (iz.eq.2) c1 = k_S12S22(2,ihelp)
1439           c2 = k_S12S22(2,ihelp)           if (iz.gt.2) c1 = k_S12S22(3,ihelp)
1440           betatof_a(12) = c2/(cos(theta13)*(ds-c1))           betatof_a(12) = c2/(cos(theta13)*(ds-c1))
1441    
1442  C------- ToF Mask - S12 - S22  C------- ToF Mask - S12 - S22
# Line 1575  C         if ((betatof_a(i).gt.-1.5).and Line 1467  C         if ((betatof_a(i).gt.-1.5).and
1467  C            icount= icount+1  C            icount= icount+1
1468  C            if (i.le.4) w_i=1./(0.13**2.)  C            if (i.le.4) w_i=1./(0.13**2.)
1469  C            if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)  C            if ((i.ge.5).and.(i.le.8)) w_i=1./(0.16**2.)
1470  C           if (i.ge.9) w_i=1./(0.25**2.)     ! to be checked  C         if (i.ge.9) w_i=1./(0.25**2.)     ! to be checked
1471  C            sxw=sxw + betatof_a(i)*w_i  C            sxw=sxw + betatof_a(i)*w_i
1472  C            sw =sw + w_i  C            sw =sw + w_i
1473  C         endif  C         endif
# Line 1584  C       Line 1476  C      
1476  C      if (icount.gt.0) beta_mean=sxw/sw  C      if (icount.gt.0) beta_mean=sxw/sw
1477  C      betatof_a(13) = beta_mean  C      betatof_a(13) = beta_mean
1478  C  C
1479    
1480  C--------  New mean beta  calculation  -----------------------  C--------  New mean beta  calculation  -----------------------
1481    
1482          do i=1,12          do i=1,12
1483           btemp(i) = betatof_a(i)           btemp(i) = betatof_a(i)
1484          enddo          enddo
1485    
1486         betatof_a(13)=newbeta(btemp,hitvec,10.,10.,20.)          betatof_a(13)=newbeta(1,btemp,hitvec,10.,10.,20.)
1487    
1488  C--------------------------------------------------------------  C--------------------------------------------------------------
1489  C      write(*,*) betatof_a  C      write(*,*) betatof_a
# Line 1604  c      write(*,*) ytofpos Line 1497  c      write(*,*) ytofpos
1497  c      write(*,*) xtr_tof  c      write(*,*) xtr_tof
1498  c      write(*,*) ytr_tof  c      write(*,*) ytr_tof
1499                
1500   100  continue  c 100  continue
1501            continue
1502    
1503  C  C
1504        RETURN        RETURN
# Line 1748  C k2 constant is taken to be the standar Line 1642  C k2 constant is taken to be the standar
1642          REAL  a1,a2          REAL  a1,a2
1643          INTEGER jj          INTEGER jj
1644    
1645    c get rid of warnings EMILIANO
1646            i = 0
1647            slope = 0
1648            offset = 0
1649            none_find = 0
1650            none_ev = 0
1651            adc_ev = 0
1652            tdc_ev = 0
1653            iadc = 0
1654            itdc = 0
1655            right = 0
1656            left = 0
1657            tof12_y(1) = tof12_y(1)
1658            tof11_x(1) = tof11_x(1)
1659            tof21_y(1) = tof21_y(1)
1660            tof22_x(1) = tof22_x(1)
1661            tof32_y(1) = tof32_y(1)
1662            tof31_x(1) = tof31_x(1)
1663    c get rid of warnings
1664    
1665  C-----------------------------------------------------------  C-----------------------------------------------------------
1666  C--- get data  C--- get data
1667  C-----------------------------------------------------------  C-----------------------------------------------------------
# Line 1974  C----  calculate  beta mean, only downwa Line 1888  C----  calculate  beta mean, only downwa
1888    
1889          if (sw.gt.0) beta_mean_tof=sxw/sw;          if (sw.gt.0) beta_mean_tof=sxw/sw;
1890    
1891  c        write(*,*) 'beta_mean_tof ',beta_mean_tof  C        write(*,*) 'beta_mean_tof ',beta_mean_tof
1892    
1893          beta_help = beta_mean_tof  !  pow(beta_mean_tof,1.0) gave best results          beta_help = beta_mean_tof  !  pow(beta_mean_tof,1.0) gave best results
1894    
# Line 2103  C  no beta found? Sum up geometric means Line 2017  C  no beta found? Sum up geometric means
2017    
2018                                    endif  ! beta_mean_tof.eq.100.                                    endif  ! beta_mean_tof.eq.100.
2019    
2020  c        write(*,*) 'in function charge: ',charge  C        write(*,*) 'in function charge: ',beta_mean_tof,charge
2021    
2022          check_charge = charge          check_charge = charge
2023    
2024    
# Line 2113  C*************************************** Line 2028  C***************************************
2028  C****************************************************************************  C****************************************************************************
2029  C****************************************************************************  C****************************************************************************
2030    
2031          function newbeta(b,hitvec,resmax,qualitycut,chi2cut)          function newbeta(iflag,b,hitvec,resmax,qualitycut,chi2cut)
2032    
2033          include  'input_tof.txt'          include  'input_tof.txt'
2034          include  'output_tof.txt'          include  'output_tof.txt'
# Line 2123  C*************************************** Line 2038  C***************************************
2038          REAL resmax,qualitycut,chi2cut          REAL resmax,qualitycut,chi2cut
2039          REAL w_i(12),w_il(6),quality,res,betachi,beta_mean_inv          REAL w_i(12),w_il(6),quality,res,betachi,beta_mean_inv
2040          REAL sw,sxw,b(12),beta_mean,chi2,xhelp          REAL sw,sxw,b(12),beta_mean,chi2,xhelp
2041            REAL tdcfl(4,12)
2042    
2043          INTEGER icount,hitvec(6)          INTEGER iflag,icount,hitvec(6)
2044    
2045          INTEGER itop(12),ibot(12)          INTEGER itop(12),ibot(12)
2046          DATA itop /1,1,2,2,3,3,4,4,1,1,2,2/          DATA itop /1,1,2,2,3,3,4,4,1,1,2,2/
2047          DATA ibot /5,6,5,6,5,6,5,6,3,4,3,4/          DATA ibot /5,6,5,6,5,6,5,6,3,4,3,4/
2048    
2049    
2050    c get rid of warnings EMILIANO
2051            slope = 0
2052            offset = 0
2053            none_find = 0
2054            none_ev = 0
2055            adc_ev = 0
2056            tdc_ev = 0
2057            iadc = 0
2058            itdc = 0
2059            right = 0
2060            left = 0
2061            tof12_y(1) = tof12_y(1)
2062            tof11_x(1) = tof11_x(1)
2063            tof21_y(1) = tof21_y(1)
2064            tof22_x(1) = tof22_x(1)
2065            tof32_y(1) = tof32_y(1)
2066            tof31_x(1) = tof31_x(1)
2067    c get rid of warnings
2068    
2069  C====================================================================  C====================================================================
2070    
2071          tof11_i = hitvec(1)          tof11_i = hitvec(1)
# Line 2139  C======================================= Line 2075  C=======================================
2075          tof31_i = hitvec(5)          tof31_i = hitvec(5)
2076          tof32_i = hitvec(6)          tof32_i = hitvec(6)
2077    
2078  c        write(*,*) '------------ In NEWBETA  ----------------'           if (iflag.eq.1) then   ! call from tofl2com
2079  c        write(*,*) hitvec           do i=1,4
2080  c        write(*,*) b           do j=1,12
2081              tdcfl(i,j) =  tdcflagtof(i,j)
2082             enddo
2083             enddo
2084                            endif
2085    
2086             if (iflag.eq.2) then   ! call from toftrk
2087             do i=1,4
2088             do j=1,12
2089              tdcfl(i,j) =  tdcflag(i,j)
2090             enddo
2091             enddo
2092                            endif
2093    
2094    
2095  C---  Find out ToF layers with artificial TDC values    -------------  C---  Find out ToF layers with artificial TDC values    -------------
2096    
# Line 2149  C---  Find out ToF layers with artificia Line 2098  C---  Find out ToF layers with artificia
2098          w_il(jj) = 1000.          w_il(jj) = 1000.
2099          enddo          enddo
2100    
 C        write(*,*) tdcflagtof  
2101    
2102          if (tof11_i.gt.0) then          if (tof11_i.gt.0) then
2103          if ((tofmask(ch11a(tof11_i),hb11a(tof11_i)).gt.0).or.          if ((tofmask(ch11a(tof11_i),hb11a(tof11_i)).gt.0).or.
2104       &   (tofmask(ch11b(tof11_i),hb11b(tof11_i)).gt.0)) then       &   (tofmask(ch11b(tof11_i),hb11b(tof11_i)).gt.0)) then
2105          w_il(1)=0          w_il(1)=0
2106          i1=tdcflagtof(ch11a(tof11_i),hb11a(tof11_i))          i1=tdcfl(ch11a(tof11_i),hb11a(tof11_i))
2107          i2=tdcflagtof(ch11b(tof11_i),hb11b(tof11_i))          i2=tdcfl(ch11b(tof11_i),hb11b(tof11_i))
 c               write(*,*) '11 ',i1,i2  
2108          if ((i1.eq.1).or.(i2.eq.1)) w_il(1) = 1  ! tdcflag          if ((i1.eq.1).or.(i2.eq.1)) w_il(1) = 1  ! tdcflag
2109                                                        endif                                                        endif
2110                             endif                             endif
# Line 2166  c              write(*,*) '11 ',i1,i2 Line 2113  c              write(*,*) '11 ',i1,i2
2113          if ((tofmask(ch12a(tof12_i),hb12a(tof12_i)).gt.0).or.          if ((tofmask(ch12a(tof12_i),hb12a(tof12_i)).gt.0).or.
2114       &   (tofmask(ch12b(tof12_i),hb12b(tof12_i)).gt.0)) then       &   (tofmask(ch12b(tof12_i),hb12b(tof12_i)).gt.0)) then
2115          w_il(2)=0          w_il(2)=0
2116          i1=tdcflagtof(ch12a(tof12_i),hb12a(tof12_i))          i1=tdcfl(ch12a(tof12_i),hb12a(tof12_i))
2117          i2=tdcflagtof(ch12b(tof12_i),hb12b(tof12_i))          i2=tdcfl(ch12b(tof12_i),hb12b(tof12_i))
 c               write(*,*) '12 ',i1,i2  
2118          if ((i1.eq.1).or.(i2.eq.1)) w_il(2) = 1  ! tdcflag          if ((i1.eq.1).or.(i2.eq.1)) w_il(2) = 1  ! tdcflag
2119                                                        endif                                                        endif
2120                             endif                             endif
# Line 2177  c              write(*,*) '12 ',i1,i2 Line 2123  c              write(*,*) '12 ',i1,i2
2123          if ((tofmask(ch21a(tof21_i),hb21a(tof21_i)).gt.0).or.          if ((tofmask(ch21a(tof21_i),hb21a(tof21_i)).gt.0).or.
2124       &   (tofmask(ch21b(tof21_i),hb21b(tof21_i)).gt.0)) then       &   (tofmask(ch21b(tof21_i),hb21b(tof21_i)).gt.0)) then
2125          w_il(3)=0          w_il(3)=0
2126          i1=tdcflagtof(ch21a(tof21_i),hb21a(tof21_i))          i1=tdcfl(ch21a(tof21_i),hb21a(tof21_i))
2127          i2=tdcflagtof(ch21b(tof21_i),hb21b(tof21_i))          i2=tdcfl(ch21b(tof21_i),hb21b(tof21_i))
 c               write(*,*) '21 ',i1,i2  
2128          if ((i1.eq.1).or.(i2.eq.1)) w_il(3) = 1  ! tdcflag          if ((i1.eq.1).or.(i2.eq.1)) w_il(3) = 1  ! tdcflag
2129                                                        endif                                                        endif
2130                             endif                             endif
# Line 2188  c              write(*,*) '21 ',i1,i2 Line 2133  c              write(*,*) '21 ',i1,i2
2133          if ((tofmask(ch22a(tof22_i),hb22a(tof22_i)).gt.0).or.          if ((tofmask(ch22a(tof22_i),hb22a(tof22_i)).gt.0).or.
2134       &   (tofmask(ch22b(tof22_i),hb22b(tof22_i)).gt.0)) then       &   (tofmask(ch22b(tof22_i),hb22b(tof22_i)).gt.0)) then
2135          w_il(4)=0          w_il(4)=0
2136          i1=tdcflagtof(ch22a(tof22_i),hb22a(tof22_i))          i1=tdcfl(ch22a(tof22_i),hb22a(tof22_i))
2137          i2=tdcflagtof(ch22b(tof22_i),hb22b(tof22_i))          i2=tdcfl(ch22b(tof22_i),hb22b(tof22_i))
 c               write(*,*) '22 ',i1,i2  
2138          if ((i1.eq.1).or.(i2.eq.1)) w_il(4) = 1  ! tdcflag          if ((i1.eq.1).or.(i2.eq.1)) w_il(4) = 1  ! tdcflag
2139                                                        endif                                                        endif
2140                             endif                             endif
# Line 2199  c              write(*,*) '22 ',i1,i2 Line 2143  c              write(*,*) '22 ',i1,i2
2143          if ((tofmask(ch31a(tof31_i),hb11a(tof31_i)).gt.0).or.          if ((tofmask(ch31a(tof31_i),hb11a(tof31_i)).gt.0).or.
2144       &   (tofmask(ch31b(tof31_i),hb31b(tof31_i)).gt.0)) then       &   (tofmask(ch31b(tof31_i),hb31b(tof31_i)).gt.0)) then
2145          w_il(5)=0          w_il(5)=0
2146          i1=tdcflagtof(ch31a(tof31_i),hb31a(tof31_i))          i1=tdcfl(ch31a(tof31_i),hb31a(tof31_i))
2147          i2=tdcflagtof(ch31b(tof31_i),hb31b(tof31_i))          i2=tdcfl(ch31b(tof31_i),hb31b(tof31_i))
 c               write(*,*) '31 ',i1,i2  
2148          if ((i1.eq.1).or.(i2.eq.1)) w_il(5) = 1  ! tdcflag          if ((i1.eq.1).or.(i2.eq.1)) w_il(5) = 1  ! tdcflag
2149                                                        endif                                                        endif
2150                             endif                             endif
# Line 2210  c              write(*,*) '31 ',i1,i2 Line 2153  c              write(*,*) '31 ',i1,i2
2153          if ((tofmask(ch32a(tof32_i),hb32a(tof32_i)).gt.0).or.          if ((tofmask(ch32a(tof32_i),hb32a(tof32_i)).gt.0).or.
2154       &   (tofmask(ch32b(tof32_i),hb32b(tof32_i)).gt.0)) then       &   (tofmask(ch32b(tof32_i),hb32b(tof32_i)).gt.0)) then
2155          w_il(6)=0          w_il(6)=0
2156          i1=tdcflagtof(ch32a(tof32_i),hb32a(tof32_i))          i1=tdcfl(ch32a(tof32_i),hb32a(tof32_i))
2157          i2=tdcflagtof(ch32b(tof32_i),hb32b(tof32_i))          i2=tdcfl(ch32b(tof32_i),hb32b(tof32_i))
 c               write(*,*) '32 ',i1,i2  
2158          if ((i1.eq.1).or.(i2.eq.1)) w_il(6) = 1  ! tdcflag          if ((i1.eq.1).or.(i2.eq.1)) w_il(6) = 1  ! tdcflag
2159                                                        endif                                                        endif
2160                             endif                             endif
2161    
 c        write(*,*) w_il  
2162  C------------------------------------------------------------------------  C------------------------------------------------------------------------
2163  C---  Set weights for the 12 measurements using information for top and bottom:  C---  Set weights for the 12 measurements using information for top and bottom:
2164  C---  if no measurements: weight = set to very high value=> not used  C---  if no measurements: weight = set to very high value=> not used
# Line 2237  C---  top and bottom artificial: weight* Line 2178  C---  top and bottom artificial: weight*
2178         w_i(jj) = 1./xhelp         w_i(jj) = 1./xhelp
2179         ENDDO         ENDDO
2180    
 c       write(*,*) w_i  
   
2181  C========================================================================  C========================================================================
2182  C--- Calculate mean beta for the first time -----------------------------  C--- Calculate mean beta for the first time -----------------------------
2183  C--- We are using "1/beta" since its error is gaussian ------------------  C--- We are using "1/beta" since its error is gaussian ------------------
# Line 2259  C--- We are using "1/beta" since its err Line 2198  C--- We are using "1/beta" since its err
2198          if (icount.gt.0) beta_mean=1./(sxw/sw)          if (icount.gt.0) beta_mean=1./(sxw/sw)
2199          beta_mean_inv = 1./beta_mean          beta_mean_inv = 1./beta_mean
2200    
 c        write(*,*) icount,beta_mean  
2201        
2202  C--- Calculate beta for the second time, use residuals of the single  C--- Calculate beta for the second time, use residuals of the single
2203  C--- measurements to get a chi2 value  C--- measurements to get a chi2 value
# Line 2275  C--- measurements to get a chi2 value Line 2213  C--- measurements to get a chi2 value
2213          IF ((abs(1./b(jj)).gt.0.1).and.(abs(1./b(jj)).lt.15.)          IF ((abs(1./b(jj)).gt.0.1).and.(abs(1./b(jj)).lt.15.)
2214       &                                .and.(w_i(jj).GT.0.01)) THEN       &                                .and.(w_i(jj).GT.0.01)) THEN
2215              res    = beta_mean_inv - (1./b(jj)) ;              res    = beta_mean_inv - (1./b(jj)) ;
 C            write(*,*) jj,abs(res*w_i(jj))  
2216              if (abs(res*w_i(jj)).lt.resmax) THEN              if (abs(res*w_i(jj)).lt.resmax) THEN
2217              chi2   = chi2 + (res*w_i(jj))**2.              chi2   = chi2 + (res*w_i(jj))**2.
2218              icount = icount+1              icount = icount+1
# Line 2296  c        quality = sw Line 2233  c        quality = sw
2233          beta_mean=100.          beta_mean=100.
2234          if ((chi2.lt.chi2cut).and.(quality.gt.qualitycut))          if ((chi2.lt.chi2cut).and.(quality.gt.qualitycut))
2235       &  beta_mean = betachi       &  beta_mean = betachi
 c        write(*,*) icount,chi2,quality,beta_mean  
2236          newbeta = beta_mean          newbeta = beta_mean
2237    
2238          END          END
2239    
2240  C****************************************************************************  C****************************************************************************
2241    
   
         

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.23