C
C   $Id: keat_geom.F,v 1.7 2001/03/08 21:48:04 godang Exp $
C   $Author: godang $
C
      Subroutine keat_geom

      Implicit none

#include "ckm_media.inc"
#include "ckm_dim.inc"
#include "ckm_pos.inc"

C  02/01/01 RG Update the changing on KEAT!
C  define KTCH for keat wire chamber volume
C  The KEAT chambers are a direct copy of the UMS chambers for now
C  I used the same routine with some obvious modifications.  The
C  wire volume 'WICH' was already defined for the UMS.
C

c-----number of chambers--------------------------------------

      integer ncham, p, k, l, m    
      parameter (ncham=2)

c-----half x,y,z dimensions of each wire chamber

      real hdim_cham1(3),hdim_cham2(3),hdim_cham3(3),hdim_cham4(3),
     +     hdim_cham5(3),hdim_cham6(3)

c-------------------------------------------------------------------
c     01/29/01 We need to make a larger chamber so that it cover
c     all beam size with more wires on each chamber.
c     390 wires in x and 390 wires in x'
c     342 wires in u and 342 wires in u' 
c     342 wires in v and 342 wires in v' 
c     total wires/chamber = (390+342+342) x 2 = 2148 wires/chamber
c     total wires (UMS)   = 6 X 2148 = 12,888 
c-------------------------------------------------------------------

      integer nplane(ncham)
      integer nwires_x, nwires_x1        ! x, x'
      integer nwires_u, nwires_u1        ! u, u'
      integer nwires_v, nwires_v1        ! v, v'

      data nplane    /6,6/               ! x,x',u,u',v,v'
      data nwires_x  /390/
      data nwires_x1 /390/
      data nwires_u  /342/
      data nwires_u1 /342/
      data nwires_v  /342/
      data nwires_v1 /342/
c-----wire dimensions (in cm)---------------------------------------

      real wire_d     /12e-4/     ! sense wire diameter
      real wire_l     /28/        ! the length of wire (large chamber)
      real wire_pitch /.08/       ! pitch between wires
      real plane_sep  /.5/        ! separation between wire planes

c-----offset of each chamber relative to center position
c     chamber 1 = -50 cm
c     chamber 2 = +50 cm
c-------------------------------------------------------------------

      real offset(ncham)    
      data offset /-160.,160./

c-------------------------------------------------------------------

c-----local variables 
c
      integer I,ivolu
      real par(3),xpos,ypos,zpos,xoff,angle,he_length,he_pos

      integer irotx90,irotz60,irotz300
      data irotx90  /3001/
      data irotz60  /3002/
      data irotz300 /3003/

c-----Polyethylene dimension (in cm)--------------------------------

      real poly_r    /2.54e-3/    
      real poly_l    /200/   

c-----define 90 degree rotation around x-axis

      call gsrotm(irotx90,90.,0.,0.,0.,90.,-90.)

c-----define 60,300 degree rotations about the z-axis

      call gsrotm(irotz60,90.,120.,90.,210.,0.,0.)
      call gsrotm(irotz300,90.,-120.,90.,-30.,0.,0.)

c-----use KTCH for KEAT chamber-----------------
c      par(1) = 0.             
c      par(2) = wire_d/2       
c      par(3) = wire_l/2       
c      call gsvolu('KTCH','TUBE',ckmmed_umswire,par,3,ivolu)  

c
c define 6 wire plane volumes for chambers:
c
      par(1) = ((nwires_x+2)*wire_pitch)/2.     ! 2 cm space at each end
      par(2) = wire_l/2.
      par(3) = plane_sep/2.- poly_r/2. 
      call gsvolu('KXX ','BOX ',ckmmed_butcf4,par,3,ivolu)  ! plane x
      call gsdvn('KTXX','KXX ',nwires_x,1)
      call gspos('WICH',1,'KTXX',0.,0.,0.,irotx90,'ONLY')

      par(1) = ((nwires_x1+2)*wire_pitch)/2.
      call gsvolu('KX1 ','BOX ',ckmmed_butcf4,par,3,ivolu)  ! plane x'
      call gsdvn('KTX1','KX1 ',nwires_x1,1)
      call gspos('WICH',1,'KTX1',0.,0.,0.,irotx90,'ONLY')

      par(1) = ((nwires_u+2)*wire_pitch)/2.   
      call gsvolu('KUU ','BOX ',ckmmed_butcf4,par,3,ivolu)  ! plave u
      call gsdvn('KTUU','KUU ',nwires_u,1)
      call gspos('WICH',1,'KTUU',0.,0.,0.,irotx90,'ONLY')

      par(1) = ((nwires_u1+2)*wire_pitch)/2. 
      call gsvolu('KU1 ','BOX ',ckmmed_butcf4,par,3,ivolu)  ! plane u'
      call gsdvn('KTU1','KU1 ',nwires_u1,1)
      call gspos('WICH',1,'KTU1',0.,0.,0.,irotx90,'ONLY')

      par(1) = ((nwires_v+2)*wire_pitch)/2.     
      call gsvolu('KVV ','BOX ',ckmmed_butcf4,par,3,ivolu)  ! plane v
      call gsdvn('KTVV','KVV ',nwires_v,1)
      call gspos('WICH',1,'KTVV',0.,0.,0.,irotx90,'ONLY')

      par(1) = ((nwires_v1+2)*wire_pitch)/2.    
      call gsvolu('KV1 ','BOX ',ckmmed_butcf4,par,3,ivolu)  ! plane v'
      call gsdvn('KTV1','KV1 ',nwires_v1,1)
      call gspos('WICH',1,'KTV1',0.,0.,0.,irotx90,'ONLY')
c
c-----Make a chamber volume of isobutane+cf4 big enough to 
c     contain rotated planes
c         (Make all chambers the same for now - EJR)
c     2/27/01 1.913 -> 1.91 to include all  the mylar planes    
c

      par(1)=1.914*(nwires_u*wire_pitch+4.)/2.
      par(2)=par(1)
      par(3)=(nplane(1)+2)*plane_sep/2.   
      call gsvolu('KEAT','BOX ',ckmmed_butcf4,par,3,ivolu)

c
c-----Material for windows---------------------------------- 
c     Choose mylar for now
c      par(3) = poly_r/2    
c      call gsvolu('POLY','BOX ',ckmmed_mylar,par,3,ivolu)

c-----insert the layers and cathode planes into the chamber

      call gspos('POLY',1,'KEAT',0.,0.,-4.*plane_sep + poly_r/2,0,
     +                                                     'ONLY')
      call gspos('POLY',2,'KEAT',0.,0.,-3.5*plane_sep,0,'ONLY')
      do i=-3,3
       call gspos('POLY',i+6,'KEAT',0.,0.,i*plane_sep,0,'ONLY')
      end do
      call gspos('POLY',10,'KEAT',0.,0.,+3.5*plane_sep,0,'ONLY')
      call gspos('POLY',11,'KEAT',0.,0.,+4.*plane_sep - poly_r/2,0,
     +                                                      'ONLY')

      zpos = -2.5*plane_sep       
      call gspos('KXX ',1,'KEAT',+wire_pitch/4.,0.,zpos,0,'ONLY')

      zpos = -1.5*plane_sep
      call gspos('KX1 ',1,'KEAT',-wire_pitch/4.,0.,zpos,0,'ONLY')

      angle = 60.0*(3.14159/180.0)
      xpos  =  -0.25*wire_pitch*cos(angle)
      ypos  =  +0.25*wire_pitch*sin(angle)
      zpos  = -.5*plane_sep
      call gspos('KUU ',1,'KEAT',xpos,ypos,zpos,irotz60,'ONLY')

      xpos  =  +0.25*wire_pitch*cos(angle)
      ypos  =  -0.25*wire_pitch*sin(angle)
      zpos  =  .5*plane_sep
      zpos  =  .5*plane_sep
      call gspos('KU1 ',1,'KEAT',xpos,ypos,zpos,irotz60,'ONLY')

      xpos  =  -0.25*wire_pitch*cos(angle)
      ypos  =  -0.25*wire_pitch*sin(angle)
      zpos  = 1.5*plane_sep
      call gspos('KVV ',1,'KEAT',xpos,ypos,zpos,irotz300,'ONLY')

      xpos  =  +0.25*wire_pitch*cos(angle)
      ypos  =  +0.25*wire_pitch*sin(angle)
      zpos  = 2.5*plane_sep
      call gspos('KV1 ',1,'KEAT',xpos,ypos,zpos,irotz300,'ONLY')
c
c  Make a volume of helium between chambers
c
      he_length=offset(2)-offset(1)-(nplane(1)+2)*plane_sep
      par(1)=1.914*(nwires_u*wire_pitch+4.)/2.
      par(2) = par(1)
      par(3) = he_length/2.-5

      call gsvolu('HEKT','BOX ',ckmmed_helium,par,3,ivolu) 
      he_pos=keat_z+(offset(1)+offset(2))/2.
      call gspos('HEKT',1,'CKM ',0.,0.,he_pos,0,'ONLY')
c
c-----insert chambers into CKM 
c
      do i=1,ncham
         call gspos('KEAT',i,'CKM ',0.,0.,keat_z+offset(i),0,'ONLY')
      end do
      Return

      End

C
C  $Log: keat_geom.F,v $
C  Revision 1.7  2001/03/08 21:48:04  godang
C  shift the first and last layers of mylar by poly_r/2 by Vladimir & Romulus
C
C  Revision 1.6  2001/03/07 23:37:30  caroline
C       Modifications in positions - Keat moved out from the vacuum system
C
C  Revision 1.5  2001/03/01 18:27:32  godang
C  fixed the sense wire diameter
C
C  Revision 1.4  2001/02/27 23:17:45  godang
C  increase KEAT chamber frame size slightly
C
C  Revision 1.3  2001/02/09 20:51:35  godang
C  added cathode planes into the chamber & calculate wire hit
C
C  Revision 1.2  2000/12/19 22:43:12  jurgen
C  added cvs headers.
C
C

