      subroutine esageom
c
      implicit none

      real pi/3.141592654/
c W target 0.10% x0 = 0.00025
      real rw/5.0/
      real zw, w/0.00025/
c      real xlead/14./, zlead/3389.89/, lead/1.68/
c-- Magnet
c      real xmag(2)/20.0, 30.0/, ymag(2)/20., 30./
      real xmag(2)/20.0, 32.0/, ymag(2)/27.94, 64.0/
      real zmag(2)/50.0, 100.0/ 

      real zpos(3)/50.0, 55.0, 240.0/
c ECAL
      real zcal/120./, xcal/32.0/, ycal/64.0/

c muon
cc      real zmu(4)/250., 270., 290., 310./, xmu1/50./, ymu1/100./
cc      real xmu4/64./, ymu4/140./
      real zmu(4)/250., 270., 290., 310./, xmu1/200./, ymu1/200./
      real xmu4/200./, ymu4/200./
c-- Si layer
c (1.05+9.833)*2=21.766
c 5 sensors=18.97 cm
c 6 sensors=22.754 cm
c 7 sensors=26.538 cm
      real xsi/21.766/, ysi/26.538/, xsi5/22.366/, ysi5/26.538/
      real zsi(9)/5., 6., 25., 26., 45., 46., 65., 66., 85./
c
      integer ivolu, i

      real par(5), x, y, z
c-------------------------------------------------------------------------
c W target
      par(1) = rw / 2.
      par(2) = rw / 2.
      par(3) = w / 2.
      call gsvolu( 'WT  ', 'BOX ', 3, par, 3, ivolu)
      call gspos( 'WT  ', 1,'WRLD', 0., 0.,0.,0,'ONLY')
c                         Bend
c      par(1) = xmag(1) / 2.
c      par(2) = ymag(1) / 2.
c      par(3) = zmag(1) / 2.
c      call gsvolu( 'MAG1', 'BOX ', 22, par, 3, ivolu)
c      call gsvolu( 'MAG1', 'BOX ', 1, par, 3, ivolu)

      par(1) = xmag(2) / 2.
      par(2) = ymag(2) / 2.
      par(3) = zmag(2) / 2.
      call gsvolu( 'MAG2', 'BOX ', 24, par, 3, ivolu)
c      call gsvolu( 'MAG2', 'BOX ', 1, par, 3, ivolu)

c Si
      par(1) = xsi / 2.
      par(2) = ysi / 2.
c      par(3) = 0.015
c      call gsvolu( 'SI  ', 'BOX ', 14, par, 3, ivolu)
c Vacuum
      par(3) = 0.001
      call gsvolu( 'SI  ', 'BOX ', 17, par, 3, ivolu)
      call jbgset(2, ivolu)
c 5th layer
      par(1) = xsi5 / 2.
      par(2) = ysi5 / 2.

c      call gsvolu( 'SI5 ', 'BOX ', 14, par, 3, ivolu)
c vacuum
      call gsvolu( 'SI5 ', 'BOX ', 17, par, 3, ivolu)
      call jbgset(2, ivolu)
c ECAL
      par(1) = xcal / 2.
      par(2) = ycal / 2.
      par(3) = 0.001
      call gsvolu( 'ECAL', 'BOX ', 17, par, 3, ivolu)
      call jbgset(2, ivolu)

c muon
      par(1) = xmu1 / 2.
      par(2) = ymu1 / 2.
      par(3) = 0.001
      call gsvolu( 'MU1 ', 'BOX ', 17, par, 3, ivolu)
      call jbgset(2, ivolu)

      par(1) = xmu4 / 2.
      par(2) = ymu4 / 2.
      par(3) = 0.001
      call gsvolu( 'MU4 ', 'BOX ', 17, par, 3, ivolu)
      call jbgset(2, ivolu)

c Si layers
      call gspos( 'SI  ', 1,'MAG2', 0., 0.,-zmag(2)/2.+zsi(1),0,'ONLY')
      call gspos( 'SI  ', 2,'MAG2', 0., 0.,-zmag(2)/2.+zsi(2),0,'ONLY')
      call gspos( 'SI  ', 3,'MAG2', 0., 0.,-zmag(2)/2.+zsi(3),0,'ONLY')
      call gspos( 'SI  ', 4,'MAG2', 0., 0.,-zmag(2)/2.+zsi(4),0,'ONLY')
      call gspos( 'SI  ', 5,'MAG2', 0., 0.,-zmag(2)/2.+zsi(5),0,'ONLY')
      call gspos( 'SI  ', 6,'MAG2', 0., 0.,-zmag(2)/2.+zsi(6),0,'ONLY')
      call gspos( 'SI  ', 7,'MAG2', 0., 0.,-zmag(2)/2.+zsi(7),0,'ONLY')
      call gspos( 'SI  ', 8,'MAG2', 0., 0.,-zmag(2)/2.+zsi(8),0,'ONLY')

      call gspos( 'SI5 ', 1,'MAG2', 0., 0.,-zmag(2)/2.+zsi(9),0,'ONLY')

c      call gspos( 'SI  ', 1,'MAG2', 0., 0.,-zmag(2)/2.+zsi(1),0,'ONLY')
c      call gspos( 'SI  ', 2,'MAG2', 0., 0.,-zmag(2)/2.+zsi(3),0,'ONLY')
c      call gspos( 'SI  ', 3,'MAG2', 0., 0.,-zmag(2)/2.+zsi(5),0,'ONLY')

cc      call gspos( 'SI  ', 1,'MAG2', 0., 0.,-zmag(2)/2.+zsi(7),0,'ONLY')


c Magnet
      call gspos( 'MAG2', 1,'WRLD', 0., 0., zpos(2), 0,'ONLY')

      call gspos( 'ECAL', 1,'WRLD', 0., 0., zcal, 0, 'ONLY')

         call gspos( 'MU1 ', 1,'WRLD', 0., 0., zmu(1), 0, 'ONLY')
         call gspos( 'MU1 ', 2,'WRLD', 0., 0., zmu(2), 0, 'ONLY')
         call gspos( 'MU4 ', 1,'WRLD', 0., 0., zmu(3), 0, 'ONLY')
         call gspos( 'MU4 ', 2,'WRLD', 0., 0., zmu(4), 0, 'ONLY')

      return
      end












