<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0"
       xmlns:xs="http://www.w3.org/2001/XMLSchema"
       xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd">

  <!-- Some information about detector  -->
  <info name="Central_Barrel_EMCal_Module_example" title="Central Barrel EMCal Module Example"
        author="Chao Peng"
        url="https://eicweb.phy.anl.gov/EIC/NPDet"
        status="development"
        version="v2.0 2020-07-30">
    <comment>A Module of Central Barrel EMCal</comment>
  </info>

  <!-- Use DD4hep elements and materials definitions -->
  <includes>
    <gdmlFile  ref="elements.xml"/>
    <gdmlFile  ref="materials.xml"/>
  </includes>

  <!-- Define the dimensions of the world volume -->
  <define>
    <constant name="world_side" value="50*m"/>
    <constant name="world_x" value="world_side"/>
    <constant name="world_y" value="world_side"/>
    <constant name="world_z" value="world_side"/>

    <constant name="tracker_region_zmax" value="6.0 * m"/>
    <constant name="tracker_region_rmax" value="6.0 * m"/>

    <constant name="cb_ECal_rmin" value="1.3*m" />
    <constant name="cb_ECal_length" value="4.0*m"/>
    <constant name="cb_ECal_mod_length" value="0.5*m"/>
    <constant name="cb_ECal_mod_width" value="0.5*m"/>

    <constant name="cb_ECal_SiliconThickness" value="0.5*mm"/>
    <constant name="cb_ECal_ElectronicsThickness" value="0.15*mm"/>
    <constant name="cb_ECal_CopperThickness" value="0.1*mm"/>
    <constant name="cb_ECal_KaptonThickness" value="0.2*mm"/>
    <constant name="cb_ECal_EpoxyThickness" value="0.1*mm"/>
    <constant name="cb_ECal_CarbonThickness" value="0.5*mm"/>
    <constant name="cb_ECal_CarbonSpacerWidth" value="4*mm"/>
    <constant name="cb_ECal_LayerSpacing" value="5*mm"/>

    <constant name="cb_ECal_AvailThickness" value="40*cm"/>
    <constant name="cb_ECal_ReadoutLayerThickness"
      value="cb_ECal_SiliconThickness+cb_ECal_ElectronicsThickness+cb_ECal_CopperThickness+cb_ECal_KaptonThickness+cb_ECal_EpoxyThickness+cb_ECal_CarbonThickness+cb_ECal_LayerSpacing" />
    <constant name="cb_ECal_ReadoutLayerNumber" value="floor(cb_ECal_AvailThickness/cb_ECal_ReadoutLayerThickness)"/>

  </define>

  <limits>
    <limitset name="cal_limits">
      <limit name="step_length_max" particles="*" value="5.0" unit="mm"/>
    </limitset>
  </limits>

  <regions>
  </regions>

  <!-- Common Generic visualization attributes -->
  <comment>Common Generic visualization attributes</comment>
  <display>
    <vis name="InvisibleNoDaughters"                                    showDaughters="false" visible="false"/>
    <vis name="InvisibleWithDaughters"                                  showDaughters="true"  visible="false"/>
    <vis name="GreenVis"       alpha="0.5"  r= "0.0"  g="1.0"  b="0.0"  showDaughters="true"  visible="true"/>
    <vis name="RedVis"         alpha="0.5"  r= "1.0"  g="0.0"  b="0.0"  showDaughters="true"  visible="true"/>
    <vis name="BlueVis"        alpha="0.5"  r= "0.0"  g="0.0"  b="1.0"  showDaughters="true"  visible="true"/>
    <vis name="OrangeVis"      alpha="0.5"  r= "1.0"  g="0.45" b="0.0"  showDaughters="true"  visible="true"/>
    <vis name="RedGreenVis"    alpha="0.5"  r= "1.0"  g="1.0"  b="0.0"  showDaughters="true"  visible="true"/>
    <vis name="BlueGreenVis"   alpha="0.5"  r= "0.0"  g="1.0"  b="1.0"  showDaughters="true"  visible="true"/>
    <vis name="PurpleVis"      alpha="0.5"  r= "1.0"  g="0.0"  b="1.0"  showDaughters="true"  visible="true"/>
    <vis name="DoubleRedG"     alpha="0.5"  r= "2.0"  g=".10"  b="0.0"  showDaughters="true"  visible="true"/>
    <vis name="RBG015"         alpha="0.5"  r= "0.0"  g=".2"   b="1.0"  showDaughters="true"  visible="true"/>
    <vis name="RBG510"         alpha="0.5"  r= "1.0"  g=".2"   b="0.0"  showDaughters="true"  visible="true"/>
    <vis name="RBG"            alpha="0.5"  r= "1.0"  g="1.0"  b="1.0"  showDaughters="true"  visible="true"/>
    <vis name="GrayVis"        alpha="0.5"  r= "0.75" g="0.75" b="0.75" showDaughters="true"  visible="true"/>
    <vis name="EcalBarrelVis"  alpha="1.0"  r="0.0"   g="0.99" b="0.0"  showDaughters="false" visible="true" />
  </display>

  <!-- Define detector -->
  <detectors>
    <comment>
      ---------------------
      Barrel EM Calorimeter
      ---------------------
      A layered EM calorimeter with tungsten and silicon (or scintillator) strips
    </comment>
    <detector
      id="131"
      name="EcalBarrel"
      type="DD4hep_EcalBarrel"
      readout="EcalBarrelHits"
      calorimeterType="EM_BARREL">
      <dimensions numsides="16" rmin="cb_ECal_rmin" z="cb_ECal_mod_length"/>
      <staves vis="EcalBarrelVis"/>
      <layer repeat="cb_ECal_ReadoutLayerNumber">
        <slice material="Silicon" thickness="cb_ECal_SiliconThickness" sensitive="yes" limits="cal_limits"/>
        <slice material="Silicon" thickness="cb_ECal_ElectronicsThickness"/>
        <slice material="Copper" thickness="cb_ECal_CopperThickness"/>
        <slice material="Kapton" thickness="cb_ECal_KaptonThickness"/>
        <slice material="Epoxy" thickness="cb_ECal_EpoxyThickness"/>
        <slice material="CarbonFiber" thickness="cb_ECal_CarbonThickness"/>
        <slice material="Air" thickness="cb_ECal_LayerSpacing"/>
      </layer>
    </detector>
  </detectors>

  <!--  Definition of the readout segmentation/definition  -->
  <readouts>
    <readout name="EcalBarrelHits">
      <segmentation type="CartesianGridXY" grid_size_x="2.0 * cm" grid_size_y="2.0 * cm"/>
      <id>system:8,barrel:3,module:4,layer:10,slice:5,x:32:-16,y:-16</id>
    </readout>
  </readouts>


  <plugins>
  </plugins>

  <fields>
  </fields>
</lccdd>