<?xml version='1.0' encoding='utf-8'?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">

  <define>
    <position name="det_in_world" x="0" y="0" z="0" unit="mm"/>
    <rotation name="ZtoX" x="0" y="90" z="0" unit="deg" />
    <rotation name="stereo_plus" x="0" y="15" z="0" unit="deg" />
    <rotation name="stereo_minus" x="0" y="-15" z="0" unit="deg" />        
  </define>
  
  <materials>
    <material name = "straw_gas" forumla = "50:50 Ar:C2H6" state = "gas">
      <!-- May need to set density -->
      <fraction n = "0.5" ref = "G4_Ar"/>
      <fraction n = "0.5" ref = "G4_ETHANE"/>      
    </material>
  </materials>  
  
  <solids>
    <!-- z is half length -->

    <!-- Straw radii are rough for now and have no anode wire yet -->
    <tube name="straw_outer_wall" rmin="2.45" rmax="2.5" z="5" deltaphi="360" aunit="deg" lunit="mm" />
    <tube name="straw_inner_wall" rmin="2.35" rmax="2.4" z="5" deltaphi="360" aunit="deg" lunit="mm" />       
    <tube name="straw_gas" rmax="2.3" z="5" deltaphi="360" aunit="deg" lunit="mm" />
    
    <box name="world_solid" x="100" y="100" z="1000" lunit="mm"/>
    <box name="layer1_solid" x="384" y="6" z="1000" lunit="mm"/>
    <box name="layer2_solid" x="384" y="6" z="1000" lunit="mm"/>    
    <box name="double_layer_solid" x="386" y="11.196" z="1000" lunit="mm"/>
    <box name="double_layer_total_solid" x="1158" y="11.196" z="1000" lunit="mm"/> 
    <box name="stereo_unit_solid" x="1400" y="300" z="1000" lunit="mm"/>               
  </solids>

  <!-- Construct straw --> 
  <structure>
    <volume name="gas">
      <materialref ref="straw_gas" />
      <solidref ref="straw_gas" />
      <position x="0" y="0" z="0" unit="mm"/>            
    </volume>
    
    <volume name="inner_wall">
      <materialref ref="G4_Al" />
      <solidref ref="straw_inner_wall" />
      <volume>
        <volumeref ref="gas" />
	<position x="0" y="0" z="0" unit="mm"/>            
      </volume>
    </volume>

    <volume name="outer_wall">
      <materialref ref="G4_Al" />
      <solidref ref="straw_outer_wall" />
      <volume>
        <volumeref ref="inner_wall" />
	<position x="0" y="0" z="0" unit="mm"/>      	
      </volume>
    </volume>

    <!-- Construct two layers of 64 --> 
    <volume name = "layer1_array">
      <materialref ref="G4_AIR" />
      <solidref ref = "layer1_solid"/>
      <replicavol number="64">
	<volumeref ref="outer_wall"/>	
	<replicate_along_axis>
	  <direction x="1"/>
          <width value="6" unit="mm"/>
          <offset value="0" unit="mm"/>	 	    
	</replicate_along_axis>
      </replicavol>
    </volume>      

    <volume name = "layer2_array">
      <materialref ref="G4_AIR" />
      <solidref ref = "layer2_solid"/>
      <replicavol number="64">
	<volumeref ref="outer_wall"/>	
	<replicate_along_axis>
	  <direction x="1"/>
          <width value="6" unit="mm"/>
          <offset value="0" unit="mm"/>	 	    
	</replicate_along_axis>
      </replicavol>
    </volume>      
    
    <!-- Combine into double array with hex packing -->
    <volume name = "double_layer_array">
      <materialref ref="G4_AIR" />
      <solidref ref = "double_layer_solid"/>
      <physvol>
        <volumeref ref="layer1_array" />
	<position x="0" y="-2.58" z="0" unit="mm"/>
      </physvol>
      <physvol>
        <volumeref ref="layer2_array" />
	<position x="3" y="2.58" z="0" unit="mm"/>      	
      </physvol>
    </volume> 

    <!-- Combine 3 double arrays into a double layer -->
    <volume name = "double_layer">
      <materialref ref="G4_AIR" />
      <solidref ref = "double_layer_total_solid"/>
      <replicavol number="3">
	<volumeref ref="double_layer_array"/>
	<replicate_along_axis>
	  <direction x="1"/>
          <width value="386" unit="mm"/>
          <offset value="0" unit="mm"/>	 	    
	</replicate_along_axis>
      </replicavol>
    </volume>      


    <!-- Unit of 3 stereo double layers --> 
    <volume name = "stereo_unit">
      <materialref ref="G4_AIR" />
      <solidref ref = "stereo_unit_solid"/>

      <physvol>
        <volumeref ref="double_layer" />
	<position x="0" y="0" z="0" unit="mm"/>
      </physvol>

      <physvol>
        <volumeref ref="double_layer" />
	<position x="0" y="100" z="0" unit="mm"/>
	<rotationref ref="stereo_plus" /> 
      </physvol>

      <physvol>
        <volumeref ref="double_layer" />
	<position x="0" y="-100" z="0" unit="mm"/>
	<rotationref ref="stereo_minus" />
      </physvol>
      
    </volume> 
    
    <!-- Place in world volume -->
    <volume name="lv_world">
      <materialref ref="G4_AIR" />
      <solidref ref="world_solid" />
      <physvol>
        <volumeref ref="stereo_unit" />
        <positionref ref="det_in_world" />
        <rotationref ref="ZtoX" />
      </physvol>
    </volume>    

    
  </structure>
  
  <setup name="Default" version="1.0">
    <world ref="lv_world" />
  </setup>
  
</gdml>
