diff --git a/Detector/DetCRD/CMakeLists.txt b/Detector/DetCRD/CMakeLists.txt
index 4b8246557f4999ac71889017ec7b6e6723c5a8f3..f4092924d8d53c31575634b0dcc1612e96cb5c0d 100644
--- a/Detector/DetCRD/CMakeLists.txt
+++ b/Detector/DetCRD/CMakeLists.txt
@@ -6,9 +6,11 @@
 gaudi_add_module(DetCRD
                  SOURCES src/Calorimeter/CRDEcal_v01.cpp
                          src/Calorimeter/LongCrystalBarBarrelCalorimeter32Polygon_v01.cpp
+                         src/Calorimeter/LongCrystalBarBarrelCalorimeter32Polygon_v02.cpp
                          src/Calorimeter/LongCrystalBarEndcapCalorimeter_v01.cpp
                          src/Calorimeter/LongCrystalBarEndcapCalorimeter_v02.cpp
                          src/Calorimeter/LongCrystalBarEndcapCalorimeter_v03.cpp
+                         src/Calorimeter/LongCrystalBarEndcapCalorimeter_v04.cpp
                          src/Calorimeter/CRDEcal_Short_v02.cpp
                          src/Calorimeter/CRDEcal_Endcap_Short_v01.cpp
                          src/Calorimeter/RotatedPolyhedraBarrelCalorimeter_v01_geo.cpp
diff --git a/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Barrel_v02_01.xml b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Barrel_v02_01.xml
new file mode 100755
index 0000000000000000000000000000000000000000..1d460a02e81fcabde539e92be27f10398f3de8ee
--- /dev/null
+++ b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Barrel_v02_01.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<lccdd> 
+  <define>
+    <constant name="ecalbarrel_inner_radius"        value="Ecal_barrel_inner_radius"/>
+    <constant name="ecalbarrel_outer_radius"        value="Ecal_barrel_outer_radius"/>
+    <constant name="ecalbarrel_zlength"             value="Ecal_barrel_half_length*2"/>
+
+    <constant name="ecalbarrel_layer"               value="18" />
+    <constant name="ecalbarrel_phimodule_number"    value="32" /> 
+    <constant name="ecalbarrel_Zmodule_number"      value="15"/>  
+    <constant name="ecalbarrel_module_ratation"     value="12.*degree" />
+    <constant name="ecalbarrel_width_crystal"    value="15.2*mm"/>
+
+    <constant name="ecalbarrel_crystal_wrapping"    value="0.1*mm"/>
+    <constant name="ecalbarrel_length_photoelectronic"    value="0.7*mm"/> 
+    <constant name="ecalbarrel_width_photoelectronic"    value="3*mm"/> 
+
+    <constant name="ecalbarrel_length_carbon"    value="5.*mm"/> 
+    <constant name="ecalbarrel_length_cable"    value="0.*mm"/> 
+    <constant name="ecalbarrel_length_cooling"    value="1.*mm"/> 
+    <constant name="ecalbarrel_length_pcb"    value="1.2*mm"/> 
+    <constant name="ecalbarrel_length_asic"    value="1.*mm"/>
+    <constant name="ecalbarrel_length_back"    value="10.*mm"/>
+
+  </define> 
+
+  <regions>
+    <region name="EcalBarrelRegion">
+    </region>
+  </regions>
+
+  <detectors>
+    <detector id="DetID_ECAL" name="EcalBarrel" type="LongCrystalBarBarrelCalorimeter32Polygon_v01" readout="EcalBarrelCollection" vis="Invisible" sensitive="true" region="EcalBarrelRegion">
+      <!-- Use cm as unit if you want to use Pandora for reconstruction -->
+    </detector>
+  </detectors>
+  
+  <readouts>
+    <readout name="EcalBarrelCollection">
+      <segmentation type="NoSegmentation"/>
+      <!--segmentation type="CartesianGridXYZ"
+                    grid_size_x="1*cm"
+                    grid_size_y="1*cm"
+                    grid_size_z="1*cm"/-->
+      <id>system:5,module:5,stave:4,dlayer:5,slayer:6,bar:15</id>
+    </readout>
+  </readouts>
+
+</lccdd>
diff --git a/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Barrel_v02_02.xml b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Barrel_v02_02.xml
new file mode 100755
index 0000000000000000000000000000000000000000..48f4d5d0db5ea47b003943a46425ea608474983c
--- /dev/null
+++ b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Barrel_v02_02.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<lccdd> 
+  <define>
+    <constant name="ecalbarrel_inner_radius"        value="Ecal_barrel_inner_radius"/>
+    <constant name="ecalbarrel_outer_radius"        value="Ecal_barrel_outer_radius"/>
+    <constant name="ecalbarrel_zlength"             value="Ecal_barrel_half_length*2"/>
+
+    <constant name="ecalbarrel_24X0"             value="268.8*mm"/>
+
+    <constant name="ecalbarrel_layer"               value="18" />
+    <constant name="ecalbarrel_phimodule_number"    value="32" /> 
+    <constant name="ecalbarrel_phimodule_number_display"    value="32" /> 
+    <constant name="ecalbarrel_Zmodule_number"      value="15"/> 
+    <constant name="ecalbarrel_Zmodule_number_display"      value="15"/> 
+    <constant name="ecalbarrel_module_ratation"     value="12.*degree" />
+    <constant name="ecalbarrel_width_crystal"    value="15.2*mm"/>
+    <constant name="ecalbarrel_width_crystal_n"    value="15.8*mm"/>
+    <constant name="ecalbarrel_size_crystal"    value="15.2*mm"/>
+
+    <constant name="ecalbarrel_crystal_wrapping"    value="0.1*mm"/>
+    <constant name="ecalbarrel_crystal_supportting"    value="0.000001*mm"/>
+    <constant name="ecalbarrel_length_photoelectronic"    value="0.699999*mm"/> 
+    <constant name="ecalbarrel_width_photoelectronic"    value="3*mm"/> 
+
+    <constant name="ecalbarrel_length_carbon"    value="2.5*mm"/> 
+    <constant name="ecalbarrel_length_carbon_z"    value="2.5*mm"/> 
+    <constant name="ecalbarrel_length_cable"    value="0.*mm"/>  
+    <constant name="ecalbarrel_length_cooling"    value="1.*mm"/> 
+    <constant name="ecalbarrel_length_pcb"    value="2*mm"/> 
+    <constant name="ecalbarrel_length_asic"    value="2*mm"/>
+    <constant name="ecalbarrel_length_back"    value="12*mm"/>
+
+  </define> 
+
+  <regions>
+    <region name="EcalBarrelRegion">
+    </region>
+  </regions>
+
+  <detectors>
+    <detector id="DetID_ECAL" name="CaloDetector" type="LongCrystalBarBarrelCalorimeter32Polygon_v02" readout="EcalBarrelCollection" vis="Invisible" sensitive="true" region="EcalBarrelRegion">
+      <!-- Use cm as unit if you want to use Pandora for reconstruction -->
+    </detector>
+  </detectors>
+  
+  <readouts>
+    <readout name="EcalBarrelCollection">
+      <segmentation type="NoSegmentation"/>
+      <!--segmentation type="CartesianGridXYZ"
+                    grid_size_x="1*cm"
+                    grid_size_y="1*cm"
+                    grid_size_z="1*cm"/-->
+      <id>system:5,module:5,stave:4,dlayer:5,slayer:6,bar:15</id>
+    </readout>
+  </readouts>
+
+</lccdd>
diff --git a/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v02_01.xml b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v02_01.xml
new file mode 100755
index 0000000000000000000000000000000000000000..0966fcf28ea55394a439d6a931694170e8405556
--- /dev/null
+++ b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v02_01.xml
@@ -0,0 +1,81 @@
+<lccdd>
+  <define>
+    <constant name="Ecal_endcap_nlayers" value="18"/> 
+    <constant name="Ecal_scintillator_thickness" value="15*mm"/>
+    <constant name="Ecal_deadarea_thickness" value="8.5*mm"/>
+  </define>
+
+  <detectors>
+    <detector id="DetID_ECAL_ENDCAP" name="EcalEndcap" type="LongCrystalBarEndcapCalorimeter_v03" readout="EcalEndcapsCollection"  vis="CyanVis" calorimeterType="EMC_ENDCAP">
+      <comment>Electromagnetic Calorimeter Endcap</comment>
+
+      <envelope vis="SeeThrough">
+        <shape type="BooleanShape" operation="Subtraction" material="Air">
+          <shape type="BooleanShape" operation="Subtraction" material="Air">
+            <!-- <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_outer_radius - env_safety" dz="Ecal_endcap_zmax"/>  -->
+            <!--there is a thin plane in envolop -->
+            <!-- <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_outer_radius + env_safety" dz="Ecal_endcap_zmin"/> -->
+            <shape type="PolyhedraRegular" numsides="256" rmin="0.0" rmax="Hcal_barrel_inner_radius - 5*mm" dz="Ecal_endcap_zmax*2"/>
+            <shape type="PolyhedraRegular" numsides="256" rmin="0.0" rmax="Hcal_barrel_inner_radius - 5*mm" dz="Ecal_endcap_zmin*2"/>
+          </shape>
+        <!-- <shape type="Box" dx="Ecal_endcap_inner_radius" dy="Ecal_endcap_inner_radius" dz="Ecal_endcap_zmax + env_safety"/>  -->
+        <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_inner_radius" dz="Ecal_endcap_zmax + env_safety"/>
+        </shape>
+        <rotation x="0" y="0" z="0"/>
+      </envelope>
+
+      <type_flags type=" DetType_CALORIMETER + DetType_ENDCAP + DetType_EMC " />
+
+      <material name="CarbonFiber"/> 
+ 
+      <dimensions numsides="Ecal_x_module" > <!-- 0:cube 1:isosceles trapezoid 2:right trapezoid -->
+        <dimensions id="0"  module_type="0" module_number="3" x_offset="768*mm" y_offset="768*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="326*mm" dim_y="326*mm" dim_z="300*mm"/>
+        <dimensions id="1"  module_type="0" module_number="2" x_offset="1069*mm" y_offset="1069*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="276*mm" dim_y="276*mm" dim_z="300*mm"/>
+        <dimensions id="2"  module_type="0" module_number="1" x_offset="1305.5*mm" y_offset="1305.5*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="197*mm" dim_y="197*mm" dim_z="300*mm"/>
+        <dimensions id="0"  module_type="20" module_number="3" x_offset="768*mm" y_offset="768*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="326*mm" dim_y="326*mm" dim_z="300*mm"/>
+        <dimensions id="1"  module_type="20" module_number="2" x_offset="1069*mm" y_offset="1069*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="276*mm" dim_y="276*mm" dim_z="300*mm"/>
+        <dimensions id="2"  module_type="20" module_number="1" x_offset="1305.5*mm" y_offset="1305.5*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="197*mm" dim_y="197*mm" dim_z="300*mm"/>
+
+        <dimensions id="3"  module_type="1" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" />
+        <dimensions id="4"  module_type="2" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" />
+        <dimensions id="3"  module_type="21" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" />
+        <dimensions id="4"  module_type="22" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" />
+
+        <dimensions id="5"  module_type="3" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="6"  module_type="4" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="7"  module_type="5" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="8"  module_type="6" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="9"  module_type="7" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="10"  module_type="8" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="11"  module_type="9" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="12"  module_type="10" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+
+        <dimensions id="13"  module_type="11" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="14"  module_type="12" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="15"  module_type="13" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="16"  module_type="14" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="17"  module_type="15" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="18"  module_type="16" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="19"  module_type="17" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="20"  module_type="18" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        
+      </dimensions>
+
+      <layer repeat="Ecal_endcap_nlayers" vis="CyanVis" material="G4_BGO" thickness = "Ecal_scintillator_thickness">
+        <slice material="G4_BGO" thickness = "Ecal_scintillator_thickness" sensitive = "yes"   limits="cal_limits"  vis="CyanVis"   />
+      </layer>
+    </detector>
+  </detectors>
+
+  <readouts>
+    <readout name="EcalEndcapsCollection">
+      <segmentation type="NoSegmentation"/>
+      <id>system:5,module:1,part:7,stave:7,type:4,dlayer:4,slayer:1,bar:7</id>
+    </readout>
+  </readouts>
+
+</lccdd>
+
+
+
+
diff --git a/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v02_02.xml b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v02_02.xml
new file mode 100755
index 0000000000000000000000000000000000000000..f84ab8c5b44055e6afd065b56af9d19fb7403100
--- /dev/null
+++ b/Detector/DetCRD/compact/CRD_common_v01/Ecal_Crystal_Endcap_v02_02.xml
@@ -0,0 +1,86 @@
+<lccdd>
+  <define>
+    <constant name="Ecal_endcap_nlayers" value="18"/> 
+    <constant name="Ecal_scintillator_thickness" value="15.2*mm"/>
+    <constant name="Ecal_endcap_carbonfiber_thickness" value="2.5*mm"/>
+    <constant name="Ecal_endcap_cu_thickness" value="1*mm"/>
+    <constant name="Ecal_endcap_electronics_thickness" value="4*mm"/>
+    <constant name="Ecal_endcap_sipm_thickness" value="0.8*mm"/>
+    <constant name="Ecal_endcap_sipm_width" value="3*mm"/>
+    <constant name="Ecal_endcap_esr_thickness" value="0.1*mm"/>
+  </define>
+
+  <detectors>
+    <detector id="DetID_ECAL_ENDCAP" name="EcalEndcap" type="LongCrystalBarEndcapCalorimeter_v04" readout="EcalEndcapsCollection"  vis="CyanVis" calorimeterType="EMC_ENDCAP">
+      <comment>Electromagnetic Calorimeter Endcap</comment>
+
+      <envelope vis="SeeThrough">
+        <shape type="BooleanShape" operation="Subtraction" material="Air">
+          <shape type="BooleanShape" operation="Subtraction" material="Air">
+            <!-- <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_outer_radius - env_safety" dz="Ecal_endcap_zmax"/>  -->
+            <!--there is a thin plane in envolop -->
+            <!-- <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_outer_radius + env_safety" dz="Ecal_endcap_zmin"/> -->
+            <shape type="PolyhedraRegular" numsides="256" rmin="0.0" rmax="Hcal_barrel_inner_radius - 5*mm" dz="Ecal_endcap_zmax*2"/>
+            <shape type="PolyhedraRegular" numsides="256" rmin="0.0" rmax="Hcal_barrel_inner_radius - 5*mm" dz="Ecal_endcap_zmin*2"/>
+          </shape>
+        <!-- <shape type="Box" dx="Ecal_endcap_inner_radius" dy="Ecal_endcap_inner_radius" dz="Ecal_endcap_zmax + env_safety"/>  -->
+        <shape type="Tube" rmin="0.0" rmax="Ecal_endcap_inner_radius" dz="Ecal_endcap_zmax + env_safety"/>
+        </shape>
+        <rotation x="0" y="0" z="0"/>
+      </envelope>
+
+      <type_flags type=" DetType_CALORIMETER + DetType_ENDCAP + DetType_EMC " />
+
+      <material name="CarbonFiber"/> 
+ 
+      <dimensions numsides="Ecal_x_module" > <!-- 0:cube 1:isosceles trapezoid 2:right trapezoid -->
+        <dimensions id="0"  module_type="0" module_number="3" x_offset="768*mm" y_offset="768*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="326*mm" dim_y="326*mm" dim_z="300*mm"/>
+        <dimensions id="1"  module_type="0" module_number="2" x_offset="1069*mm" y_offset="1069*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="276*mm" dim_y="276*mm" dim_z="300*mm"/>
+        <dimensions id="2"  module_type="0" module_number="1" x_offset="1305.5*mm" y_offset="1305.5*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="197*mm" dim_y="197*mm" dim_z="300*mm"/>
+        <dimensions id="0"  module_type="20" module_number="3" x_offset="768*mm" y_offset="768*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="326*mm" dim_y="326*mm" dim_z="300*mm"/>
+        <dimensions id="1"  module_type="20" module_number="2" x_offset="1069*mm" y_offset="1069*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="276*mm" dim_y="276*mm" dim_z="300*mm"/>
+        <dimensions id="2"  module_type="20" module_number="1" x_offset="1305.5*mm" y_offset="1305.5*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="197*mm" dim_y="197*mm" dim_z="300*mm"/>
+
+        <dimensions id="3"  module_type="1" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" />
+        <dimensions id="4"  module_type="2" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" />
+        <dimensions id="3"  module_type="21" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" />
+        <dimensions id="4"  module_type="22" module_number="4" x_offset="570.5*mm" y_offset="0*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="574*mm" dim_x2="495*mm" dim_y1="441*mm" dim_y2="441*mm" dim_z="300*mm" />
+
+        <dimensions id="5"  module_type="3" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="6"  module_type="4" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="7"  module_type="5" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="8"  module_type="6" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="9"  module_type="7" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="10"  module_type="8" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="11"  module_type="9" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+        <dimensions id="12"  module_type="10" module_number="4" x_offset="426.25*mm" y_offset="436.125*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x1="318*mm" dim_x2="357.5*mm" dim_y1="357.5*mm" dim_y2="357.5*mm" dim_z="300*mm"/>
+
+        <dimensions id="13"  module_type="11" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="14"  module_type="12" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="15"  module_type="13" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="16"  module_type="14" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="17"  module_type="15" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="18"  module_type="16" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="19"  module_type="17" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        <dimensions id="20"  module_type="18" module_number="1" x_offset="426.25*mm" y_offset="426.25*mm" z_offset="Ecal_endcap_zmin+Ecal_endcap_thickness/2" dim_x="178.75*mm" dim_y="139.25*mm" dim_z="300*mm"/>
+        
+      </dimensions>
+
+      <layer repeat="Ecal_endcap_nlayers" vis="CyanVis" material="G4_BGO" thickness = "Ecal_scintillator_thickness">
+        <slice material="G4_BGO" thickness = "Ecal_scintillator_thickness" sensitive = "yes"   limits="cal_limits"  vis="CyanVis"   />
+      </layer>
+    </detector>
+  </detectors>
+
+  <readouts>
+    <readout name="EcalEndcapsCollection">
+      <segmentation type="NoSegmentation"/>
+      <id>system:5,module:1,part:7,stave:7,type:4,dlayer:4,slayer:1,bar:7</id>
+    </readout>
+  </readouts>
+
+</lccdd>
+
+
+
+
diff --git a/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml
index eb449954dc9c77467d22c6659383df79c5811e4c..0fcfdacdab2f57b816d04e3672051a515f21510b 100644
--- a/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml
+++ b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml
@@ -42,8 +42,8 @@
   <include ref="../CRD_common_v01/OTKBarrel_v01_01.xml"/>
   <!--include ref="../CRD_common_v01/OTKEndcap_v01_01.xml"/-->
 
-  <include ref="../CRD_common_v01/Ecal_Crystal_Barrel_v01_02.xml"/>
-  <include ref="../CRD_common_v01/Ecal_Crystal_Endcap_v01_03.xml"/>
+  <include ref="../CRD_common_v01/Ecal_Crystal_Barrel_v02_02.xml"/>
+  <include ref="../CRD_common_v01/Ecal_Crystal_Endcap_v02_01.xml"/>
   <include ref="../CRD_common_v01/SHcalGlass_Barrel_v05.xml"/>
   <include ref="../CRD_common_v01/SHcalGlass_Endcaps_v01.xml"/>
 
diff --git a/Detector/DetCRD/src/Calorimeter/LongCrystalBarBarrelCalorimeter32Polygon_v02.cpp b/Detector/DetCRD/src/Calorimeter/LongCrystalBarBarrelCalorimeter32Polygon_v02.cpp
new file mode 100755
index 0000000000000000000000000000000000000000..ad31d99540673f42a7a94fa3fe57df68a2026e6e
--- /dev/null
+++ b/Detector/DetCRD/src/Calorimeter/LongCrystalBarBarrelCalorimeter32Polygon_v02.cpp
@@ -0,0 +1,1391 @@
+//==========================================================================
+// LongCrystalBarBarrelCalorimeter32Polygon_v02 implementation 
+//--------------------------------------------------------------------------
+// Author: Song Weizheng, IHEP
+//--------------------------------------------------------------------------
+// Data: 2024.7.1
+//==========================================================================
+
+#include "DD4hep/DetFactoryHelper.h" 
+#include "XML/Layering.h"
+#include "XML/Utilities.h"
+#include "DDRec/DetectorData.h"
+#include "DDSegmentation/Segmentation.h"
+
+#define MYDEBUG(x) std::cout << __FILE__ << ":" << __LINE__ << ": " << x << std::endl;
+#define MYDEBUGVAL(x) std::cout << __FILE__ << ":" << __LINE__ << ": " << #x << ": " << x << std::endl;
+
+using dd4hep::rec::LayeredCalorimeterData;
+using namespace dd4hep;
+using namespace std;
+
+static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
+                                     xml_h e,
+                                     dd4hep::SensitiveDetector sens) {
+
+    xml_det_t x_det = e;
+    std::string det_name = x_det.nameStr();
+    std::string det_type = x_det.typeStr();
+    MYDEBUGVAL(det_name);
+    MYDEBUGVAL(det_type);
+    int detid = x_det.id();
+
+    // ######################################
+    // ### detector description parameter ###
+    // ######################################
+
+    double radius_inner = theDetector.constant<double>("ecalbarrel_inner_radius");
+    double radius_outer = theDetector.constant<double>("ecalbarrel_outer_radius");
+    double length_z = theDetector.constant<double>("ecalbarrel_zlength");
+
+    double X024 = theDetector.constant<double>("ecalbarrel_24X0");
+
+    int Nlayers = theDetector.constant<double>("ecalbarrel_layer");
+    int n_module = theDetector.constant<double>("ecalbarrel_phimodule_number");
+    int Nblock_z = theDetector.constant<double>("ecalbarrel_Zmodule_number");
+    int n_module_display = theDetector.constant<double>("ecalbarrel_phimodule_number_display");
+    int Nblock_z_display = theDetector.constant<double>("ecalbarrel_Zmodule_number_display");
+    double rotation_angle = theDetector.constant<double>("ecalbarrel_module_ratation"); 
+
+    double width_crystal = theDetector.constant<double>("ecalbarrel_width_crystal");
+    double width_crystal_n = theDetector.constant<double>("ecalbarrel_width_crystal_n");
+    double size_crystal1 = theDetector.constant<double>("ecalbarrel_size_crystal");
+    double crystal_wrapping = theDetector.constant<double>("ecalbarrel_crystal_wrapping");
+    double crystal_supportting = theDetector.constant<double>("ecalbarrel_crystal_supportting");
+    double photoelectronic = theDetector.constant<double>("ecalbarrel_length_photoelectronic");
+    double photoelectronic_width = theDetector.constant<double>("ecalbarrel_width_photoelectronic");
+
+    double dead_material = theDetector.constant<double>("ecalbarrel_length_carbon");
+    double dead_material_zz = theDetector.constant<double>("ecalbarrel_length_carbon_z");
+    double cable = theDetector.constant<double>("ecalbarrel_length_cable");
+    double pcb = theDetector.constant<double>("ecalbarrel_length_pcb");
+    double asic = theDetector.constant<double>("ecalbarrel_length_asic");
+    double cooling = theDetector.constant<double>("ecalbarrel_length_cooling");
+    double back_plate = theDetector.constant<double>("ecalbarrel_length_back");
+    
+    // ###########################
+    // ### general measurement ###
+    // ###########################
+
+    // Z direction
+    double pZ = length_z/Nblock_z; // length of module in z
+    double length_crystal_z = pZ - 2*dead_material_zz - 2*cable - 2*pcb - 2*asic - 2*cooling; // length of crystal wrap sipm in z
+    
+
+    // R - phi direction
+    double angle = 360./n_module*degree;
+
+    double trap_depth = radius_outer*cos(angle/2.) - radius_inner;
+    double trap_line = trap_depth/cos(angle/2.);
+    double alice_angle = 0.5*angle + rotation_angle; // angle of "|/" in inner<outer trapozoid
+    double alice_1 = 0.5*trap_depth/tan(90*degree-alice_angle);
+    double alice_2 = 0.5*trap_line*sin(angle/2.);
+    double deviation_positive = alice_1 - alice_2; 
+    double bob_angle = 90*degree - angle; 
+    double deviation_bob = tan(bob_angle)/(tan(alice_angle)+tan(bob_angle))*deviation_positive;
+    double deviation_negative = deviation_bob/cos(angle); 
+    double height_layer1 = deviation_bob*tan(angle); 
+    double deviation_layer1 = height_layer1*tan(alice_angle); 
+    double copper_angle = 180*degree - alice_angle - bob_angle; // angle of "/_" in inner>outer trapozoid
+    
+    //Half-length of the trapezoid
+    double dim_x1 = radius_inner*tan(angle/2.)-deviation_positive+deviation_layer1;
+    double dim_x3 = radius_inner*tan(angle/2.)+deviation_negative;
+
+    // Thickness of the trapezoid
+    double depth_longitudinal_p = Nlayers*width_crystal + back_plate;
+    // double trap_line_p = depth_longitudinal_p/cos(alice_angle);
+    // double depth_longitudinal_n = trap_line_p*sin(copper_angle);
+    double depth_longitudinal_n = Nlayers*width_crystal_n + back_plate;
+
+    double plus = depth_longitudinal_p*tan(alice_angle);
+    double minus = depth_longitudinal_n/tan(copper_angle);
+    double dim_x2 = dim_x1+plus;
+    double dim_x4 = dim_x3-minus;
+
+    double dim_z_p = depth_longitudinal_p/2.;	
+    double dim_z_n = depth_longitudinal_n/2.;	
+
+    double size_crystal = (depth_longitudinal_n-back_plate)/Nlayers; 
+    double size_posi_crystal = (depth_longitudinal_p-back_plate)/Nlayers; //Crystal thickness in positive trapezoid
+
+    width_crystal = size_crystal1; // width of crystal in phi
+    width_crystal_n = size_crystal1; // width of crystal in phi
+    
+    int Nbar_phi = floor(length_crystal_z/width_crystal); // number of crystal in phi
+    // ####################
+    // ### World Volume ###
+    // ####################
+
+    dd4hep::DetElement ECAL(det_name, detid);
+    dd4hep::Volume motherVol = theDetector.pickMotherVolume(ECAL);
+
+    dd4hep::PolyhedraRegular envelope(n_module, angle/2., radius_inner, radius_outer, length_z);
+    dd4hep::Material	air(theDetector.material("Air"));
+    dd4hep::Material	vacuum(theDetector.material("Vacuum"));
+    dd4hep::Volume	   envelopeVol(det_name, envelope, air);
+    dd4hep::PlacedVolume	envelopePlv = motherVol.placeVolume(envelopeVol, Position(0,0,0));
+    envelopePlv.addPhysVolID("system",x_det.id());
+    envelopeVol.setVisAttributes(theDetector, "SeeThrough" );
+    ECAL.setPlacement(envelopePlv);   
+    
+    dd4hep::Material mat_BGO(theDetector.material("G4_BGO")); 
+    dd4hep::Material mat_CF(theDetector.material("CarbonFiber"));
+    dd4hep::Material mat_Cu(theDetector.material("G4_Cu"));
+    dd4hep::Material mat_ESR(theDetector.material("G4_ESR"));
+    dd4hep::Material mat_Si(theDetector.material("G4_Si"));
+    dd4hep::Material mat_PCB(theDetector.material("PCB"));
+
+    dd4hep::Trapezoid trap_positive(dim_x1, dim_x2, length_z/2, length_z/2, dim_z_p);
+    dd4hep::Volume trap_positive_vol("trap_positive_vol", trap_positive, air);
+    trap_positive_vol.setVisAttributes(theDetector, "BlueVis");
+
+    dd4hep::Trapezoid trap_negative(dim_x3, dim_x4, length_z/2, length_z/2, dim_z_n);
+    dd4hep::Volume trap_negative_vol("trap_negative_vol", trap_negative, air);
+    trap_negative_vol.setVisAttributes(theDetector, "BlueVis");
+
+    dd4hep::Trapezoid subtrap_positive(dim_x1, dim_x2, length_z/2/Nblock_z, length_z/2/Nblock_z, dim_z_p);
+    dd4hep::Volume subtrap_positive_vol("subtrap_positive_vol", subtrap_positive, air);
+    subtrap_positive_vol.setVisAttributes(theDetector, "SeeThrough"); 
+
+    dd4hep::Trapezoid subtrap_negative(dim_x3, dim_x4, length_z/2/Nblock_z, length_z/2/Nblock_z, dim_z_n);
+    dd4hep::Volume subtrap_negative_vol("subtrap_negative_vol", subtrap_negative, air);
+    subtrap_negative_vol.setVisAttributes(theDetector, "SeeThrough");
+
+    dd4hep::DetElement stavedet(ECAL, "trap",detid);
+    
+    // ##################################
+    // ### SiPM PCB ASIC Cable Carbon ###
+    // ##################################
+
+    double electronics = cable + pcb + asic + cooling; // + photoelectronic 
+
+    double dead_material_p = dead_material/cos(alice_angle);
+    double dead_material_n = dead_material/sin(copper_angle);
+    
+    double dead_material_l = dead_material_p + electronics;
+    double dead_material_r = dead_material_n + electronics;
+    double dead_material_z = dead_material_zz + electronics;
+
+    dd4hep::Trap left_trap(pZ, size_posi_crystal, dead_material_p + size_posi_crystal*tan(alice_angle), (dead_material_p));
+    dd4hep::Volume left("left_vol", left_trap, mat_CF);
+    left.setVisAttributes(theDetector, "GrayVis");
+
+    dd4hep::Trap right_trap(pZ, size_crystal, (dead_material_n + size_crystal/tan(copper_angle)), dead_material_n); //Dead material in each layer in positive trapezoid
+    dd4hep::Volume right("right_vol", right_trap, mat_CF);
+    right.setVisAttributes(theDetector, "GrayVis");
+
+    // ####################
+    // ### Print Volume ###
+    // ####################
+
+    std::cout << "dim_x1" << " : " << dim_x1*2 << std::endl;
+    std::cout << "dim_x2" << " : " << dim_x2*2 << std::endl;
+    std::cout << "dim_x3" << " : " << dim_x3*2 << std::endl;
+    std::cout << "dim_x4" << " : " << dim_x4*2 << std::endl;
+    std::cout << "depth_longitudinal_p" << " : " << depth_longitudinal_p << std::endl;
+    std::cout << "depth_longitudinal_n" << " : " << depth_longitudinal_n << std::endl;
+
+    std::cout << "radius outer" << " : " << sqrt((radius_inner+depth_longitudinal_n)*(radius_inner+depth_longitudinal_n)+dim_x4*dim_x4) << std::endl;
+    std::cout << "radius outer" << " : " << sqrt((radius_inner+height_layer1+depth_longitudinal_p)*(radius_inner+height_layer1+depth_longitudinal_p)+dim_x2*dim_x2) << std::endl;
+
+    std::cout << "size_crystal" << " : " << size_crystal << std::endl;
+    std::cout << "size_posi_crystal" << " : " << size_posi_crystal << std::endl;
+
+    std::cout << "pZ" << " : " << pZ << std::endl;
+    std::cout << "Nbar_phi" << " : " << Nbar_phi << std::endl;
+
+    std::cout << "area_1" << " : " << dead_material_p*2*size_posi_crystal << std::endl;
+    std::cout << "area_2" << " : " << (dead_material_p+dead_material_p+size_posi_crystal*tan(alice_angle))*size_posi_crystal << std::endl;
+    std::cout << "area_3" << " : " << (dead_material_p+dead_material_p+2*size_posi_crystal*tan(alice_angle))*size_posi_crystal << std::endl;
+
+    std::cout << "area_4" << " : " << dead_material_n*2*size_crystal << std::endl;
+    std::cout << "area_5" << " : " << (dead_material_n+dead_material_n+size_crystal/tan(copper_angle))*size_crystal << std::endl;
+    std::cout << "area_6" << " : " << (dead_material_n+dead_material_n+2*size_crystal/tan(copper_angle))*size_crystal << std::endl;
+    
+    std::cout << "total volume" << " : " << 
+    ( dim_x1*2 + (dim_x1+Nlayers*size_crystal*tan(alice_angle))*2 ) * Nlayers*size_crystal /2 * pZ + 
+    ( dim_x3*2 + (dim_x3-Nlayers*size_posi_crystal/tan(copper_angle))*2 ) * Nlayers*size_posi_crystal /2 * pZ
+    << std::endl;
+
+    // ####################################
+    // ### placement of all the volumes ###
+    // ####################################
+
+    double length_posi; // bottom lenght
+    double length_nega; // 
+    
+    int Nbar_z;
+    double last_bar; // 
+    double last_bar_z;
+
+    double positive_volume = 0;
+    double negative_volume = 0;
+    double volume_bar_s0 = 0;
+    double volume_bar_s1 = 0;
+
+    // ##########################
+    // ### positive trapezoid ###
+    // ##########################
+
+    dd4hep::Volume backPlate("back_plate", dd4hep::Box(back_plate*13, back_plate*13, back_plate/2), mat_PCB);
+    backPlate.setVisAttributes(theDetector, "GrayVis");
+    std::string blockname = "back_plate_positive";
+    dd4hep::DetElement sd(stavedet, blockname, detid);
+    dd4hep::PlacedVolume plv = subtrap_positive_vol.placeVolume(backPlate, Position(0, 0, dim_z_p-back_plate/2));
+    sd.setPlacement(plv);
+    // maybe posi and nega bakplate height is different!!!
+
+    for(int ilayer=0; ilayer<Nlayers; ilayer=ilayer+1){
+
+        length_posi = dim_x1  - dead_material_l + ilayer*size_posi_crystal*tan(alice_angle);
+        cout<< "layer: "<< ilayer+1 << endl;
+        cout<< "   length_posi: "<< length_posi*2 << endl;
+        
+        //Trapezoid in layer
+        dd4hep::Volume block("block", dd4hep::Trapezoid( dim_x1+ilayer*size_posi_crystal*tan(alice_angle), dim_x1+(ilayer+1)*size_posi_crystal*tan(alice_angle), pZ/2, pZ/2, size_posi_crystal/2), air);
+        block.setVisAttributes(theDetector, "SeeThrough");
+        std::string blockname = "Block_positive_"+std::to_string(ilayer+1);
+        dd4hep::DetElement sd(stavedet, blockname, detid);
+
+        // Carbon fiber supporting
+        dd4hep::Volume CarbonFiber0("CarbonFiber0", dd4hep::Box(length_posi+electronics, dead_material_zz/2, size_posi_crystal/2), mat_CF); //phi
+        CarbonFiber0.setVisAttributes(theDetector, "GrayVis");
+
+        dd4hep::PlacedVolume plv_cf0 = block.placeVolume(CarbonFiber0, Position(0, pZ/2-dead_material_zz/2, 0));
+        std::string cfname0 = "Deadzone_s4_"+std::to_string(ilayer+1);	
+        dd4hep::DetElement cfdet0(sd, cfname0, detid);
+        cfdet0.setPlacement(plv_cf0);
+
+        dd4hep::PlacedVolume plv_cf1 = block.placeVolume(CarbonFiber0, Position(0, -pZ/2+dead_material_zz/2, 0));
+        std::string cfname1 = "Deadzone_s5_"+std::to_string(ilayer+1);	
+        dd4hep::DetElement cfdet1(sd, cfname1, detid);
+        cfdet1.setPlacement(plv_cf1);
+
+        dd4hep::Transform3D transform(dd4hep::RotationZ(180*degree)*dd4hep::RotationX(-90*degree),  dd4hep::Position(-length_posi-electronics-(dead_material_p)/2-(((dead_material_p) + size_posi_crystal*tan(alice_angle))/2-(dead_material_p)/2)/2, 0., 0.)); 
+        dd4hep::PlacedVolume plv_bar2 = block.placeVolume(left, transform);
+        std::string barname2 = "Deadzone_s2_"+std::to_string(ilayer+1);
+        dd4hep::DetElement bardet2(sd, barname2, detid);
+        bardet2.setPlacement(plv_bar2);
+
+        dd4hep::Transform3D transform2(dd4hep::RotationX(-90*degree),  dd4hep::Position(length_posi+electronics+(dead_material_p)/2+(((dead_material_p) + size_posi_crystal*tan(alice_angle))/2-(dead_material_p)/2)/2, 0., 0.)); 
+        dd4hep::PlacedVolume plv_bar3= block.placeVolume(left, transform2);
+        std::string barname3 = "Deadzone_s3_"+std::to_string(ilayer+1);
+        dd4hep::DetElement bardet3(sd, barname3, detid);
+        bardet3.setPlacement(plv_bar3);
+
+        // Electronics
+
+        dd4hep::Volume electronics_phi0("electronics_phi0", dd4hep::Box(length_posi+electronics, (electronics-cooling)/2, size_posi_crystal/2), mat_PCB); //phi
+        electronics_phi0.setVisAttributes(theDetector, "YellowVis");
+
+        dd4hep::PlacedVolume plv_elec0 = block.placeVolume(electronics_phi0, Position(0, -length_crystal_z/2-(electronics-cooling)/2, 0));
+        std::string elecname0 = "electronics_positive_phi_u_"+std::to_string(ilayer+1);	
+        dd4hep::DetElement elecdet0(sd, elecname0, detid);
+        elecdet0.setPlacement(plv_elec0);
+
+        dd4hep::PlacedVolume plv_elec1 = block.placeVolume(electronics_phi0, Position(0, length_crystal_z/2+(electronics-cooling)/2, 0));
+        std::string elecname1 = "electronics_positive_phi_d_"+std::to_string(ilayer+1);
+        dd4hep::DetElement elecdet1(sd, elecname1, detid);
+        elecdet1.setPlacement(plv_elec1);
+
+        dd4hep::Volume electronics_phi_l("electronics_phi_l", dd4hep::Box((electronics-cooling)/2, length_crystal_z/2, size_posi_crystal/2), mat_PCB); //phi
+        electronics_phi_l.setVisAttributes(theDetector, "YellowVis");
+
+        dd4hep::PlacedVolume plv_elec2 = block.placeVolume(electronics_phi_l, Position(-length_posi-(electronics-cooling)/2, 0, 0));
+        std::string elecname2 = "electronics_positive_phi_l_"+std::to_string(ilayer+1);
+        dd4hep::DetElement elecdet2(sd, elecname2, detid);
+        elecdet2.setPlacement(plv_elec2);
+
+        dd4hep::PlacedVolume plv_elec3 = block.placeVolume(electronics_phi_l, Position(length_posi+(electronics-cooling)/2, 0, 0));
+        std::string elecname3 = "electronics_positive_phi_r_"+std::to_string(ilayer+1);
+        dd4hep::DetElement elecdet3(sd, elecname3, detid);
+        elecdet3.setPlacement(plv_elec3);
+
+        //Cooling copper
+
+        dd4hep::Volume copper_phi0("copper_phi0", dd4hep::Box(length_posi+electronics, cooling/2, size_posi_crystal/2), mat_Cu); //phi
+        copper_phi0.setVisAttributes(theDetector, "RedVis");
+
+        dd4hep::PlacedVolume plv_copper0 = block.placeVolume(copper_phi0, Position(0, -length_crystal_z/2-electronics+cooling/2, 0));
+        std::string coppername0 = "copper_positive_phi_u_"+std::to_string(ilayer+1);
+        dd4hep::DetElement copperdet0(sd, coppername0, detid);
+        copperdet0.setPlacement(plv_copper0);
+
+        dd4hep::PlacedVolume plv_copper1 = block.placeVolume(copper_phi0, Position(0, length_crystal_z/2+electronics-cooling/2, 0));
+        std::string coppername1 = "copper_positive_phi_d_"+std::to_string(ilayer+1);
+        dd4hep::DetElement copperdet1(sd, coppername1, detid);
+        copperdet1.setPlacement(plv_copper1);
+
+        dd4hep::Volume copper_phi_l("copper_phi_l", dd4hep::Box(cooling/2, length_crystal_z/2, size_posi_crystal/2), mat_Cu); //phi
+        copper_phi_l.setVisAttributes(theDetector, "RedVis");
+
+        dd4hep::PlacedVolume plv_copper2 = block.placeVolume(copper_phi_l, Position(-length_posi-electronics+cooling/2, 0, 0));
+        std::string coppername2 = "copper_positive_phi_l_"+std::to_string(ilayer+1);
+        dd4hep::DetElement copperdet2(sd, coppername2, detid);
+        copperdet2.setPlacement(plv_copper2);
+
+        dd4hep::PlacedVolume plv_copper3 = block.placeVolume(copper_phi_l, Position(length_posi+electronics-cooling/2, 0, 0));
+        std::string coppername3 = "copper_positive_phi_r_"+std::to_string(ilayer+1);
+        dd4hep::DetElement copperdet3(sd, coppername3, detid);
+        copperdet3.setPlacement(plv_copper3);
+
+        // ###################################
+        // ####### Phi direction place #######
+        // ###################################
+
+        if(ilayer%2==0){
+            cout<< "   Nbar_phi: " << Nbar_phi << endl;
+
+            dd4hep::Volume sipm_s0("sipm_s0", dd4hep::Box(photoelectronic/2, photoelectronic_width/2, photoelectronic_width/2), mat_Si); 
+            sipm_s0.setVisAttributes(theDetector, "BlueVis");
+
+            dd4hep::Volume sipm_s1("sipm_s1", dd4hep::Box(crystal_wrapping/2, photoelectronic_width/2, photoelectronic_width/2), mat_Si); 
+            sipm_s1.setVisAttributes(theDetector, "BlueVis");
+
+            last_bar_z = length_crystal_z - (Nbar_phi-1)*width_crystal;
+
+            dd4hep::Volume bar_s0("bar_s0", dd4hep::Box(length_posi-photoelectronic-crystal_wrapping-crystal_supportting, width_crystal/2-crystal_wrapping-crystal_supportting, size_posi_crystal/2-crystal_wrapping-crystal_supportting), mat_BGO); 
+            bar_s0.setVisAttributes(theDetector, "EcalBarrelVis");
+            bar_s0.setSensitiveDetector(sens);
+            
+            volume_bar_s0 = (length_posi-photoelectronic-crystal_wrapping-crystal_supportting)*(width_crystal/2-crystal_wrapping-crystal_supportting)*(size_posi_crystal/2-crystal_wrapping-crystal_supportting)*8;
+
+            dd4hep::Volume bar_s1("bar_s1", dd4hep::Box(length_posi-photoelectronic-crystal_wrapping-crystal_supportting, last_bar_z/2-crystal_wrapping-crystal_supportting, size_posi_crystal/2-crystal_wrapping-crystal_supportting), mat_BGO); 
+            bar_s1.setVisAttributes(theDetector, "EcalBarrelVis");
+            bar_s1.setSensitiveDetector(sens);
+            
+            volume_bar_s1 = (length_posi-photoelectronic-crystal_wrapping-crystal_supportting)*(last_bar_z/2-crystal_wrapping-crystal_supportting)*(size_posi_crystal/2-crystal_wrapping-crystal_supportting)*8;
+
+            positive_volume = positive_volume + volume_bar_s0*(Nbar_phi-1) + volume_bar_s1;
+
+            for(int ibar0=0;ibar0<Nbar_phi;ibar0++){
+                if(ibar0 == Nbar_phi-1){
+
+                    dd4hep::Volume hardware_s1("hardware_s1", dd4hep::Box(length_posi, last_bar_z/2, size_posi_crystal/2), air); 
+                    hardware_s1.setVisAttributes(theDetector, "SeeThrough");
+
+                    dd4hep::Volume carbonbox_s1("carbonbox_s1", dd4hep::Box(length_posi-photoelectronic, last_bar_z/2, size_posi_crystal/2), mat_CF); 
+                    carbonbox_s1.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::Volume crystal_s1("crystal_s1", dd4hep::Box(length_posi-photoelectronic-crystal_supportting, last_bar_z/2-crystal_supportting, size_posi_crystal/2-crystal_supportting), mat_ESR); 
+                    crystal_s1.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::PlacedVolume plv_bar0 = crystal_s1.placeVolume(bar_s1, Position(0, 0, 0));
+                    std::string barname0 = "CrystalBar_positive_s0_"+std::to_string(ibar0);	
+                    dd4hep::DetElement bardet0(sd, barname0, detid);
+                    bardet0.setPlacement(plv_bar0);
+
+                    // dd4hep::PlacedVolume plv_sipm8 = carbonbox_s1.placeVolume(sipm_s1, Position(-length_posi+photoelectronic+crystal_supportting+photoelectronic/2, 0, -photoelectronic_width/2));
+                    // std::string sipmname8 = "SiPM_positive_s8_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet8(sd, sipmname8, detid);
+                    // sipmdet8.setPlacement(plv_sipm8);
+
+                    // dd4hep::PlacedVolume plv_sipm9 = carbonbox_s1.placeVolume(sipm_s1, Position(length_posi-photoelectronic-crystal_supportting-photoelectronic/2, 0, photoelectronic_width/2));
+                    // std::string sipmname9 = "SiPM_positive_s9_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet9(sd, sipmname9, detid);
+                    // sipmdet9.setPlacement(plv_sipm9);
+
+                    // dd4hep::PlacedVolume plv_sipm10 = carbonbox_s1.placeVolume(sipm_s1, Position(-length_posi+photoelectronic+crystal_supportting+photoelectronic/2, 0, photoelectronic_width/2));
+                    // std::string sipmname10 = "SiPM_positive_s10_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet10(sd, sipmname10, detid);
+                    // sipmdet10.setPlacement(plv_sipm10);
+
+                    // dd4hep::PlacedVolume plv_sipm11 = carbonbox_s1.placeVolume(sipm_s1, Position(length_posi-photoelectronic-crystal_supportting-photoelectronic/2, 0, -photoelectronic_width/2));
+                    // std::string sipmname11 = "SiPM_positive_s11_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet11(sd, sipmname11, detid);
+                    // sipmdet11.setPlacement(plv_sipm11);
+
+                    dd4hep::PlacedVolume plv_sipm4 = crystal_s1.placeVolume(sipm_s1, Position(-length_posi+photoelectronic+crystal_supportting+crystal_wrapping/2, 0, -photoelectronic_width/2));
+                    std::string sipmname4 = "SiPM_positive_s4_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet4(sd, sipmname4, detid);
+                    sipmdet4.setPlacement(plv_sipm4);
+
+                    dd4hep::PlacedVolume plv_sipm5 = crystal_s1.placeVolume(sipm_s1, Position(length_posi-photoelectronic-crystal_supportting-crystal_wrapping/2, 0, photoelectronic_width/2));
+                    std::string sipmname5 = "SiPM_positive_s5_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet5(sd, sipmname5, detid);
+                    sipmdet5.setPlacement(plv_sipm5);
+
+                    dd4hep::PlacedVolume plv_sipm6 = crystal_s1.placeVolume(sipm_s1, Position(-length_posi+photoelectronic+crystal_supportting+crystal_wrapping/2, 0, photoelectronic_width/2));
+                    std::string sipmname6 = "SiPM_positive_s6_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet6(sd, sipmname6, detid);
+                    sipmdet6.setPlacement(plv_sipm6);
+
+                    dd4hep::PlacedVolume plv_sipm7 = crystal_s1.placeVolume(sipm_s1, Position(length_posi-photoelectronic-crystal_supportting-crystal_wrapping/2, 0, -photoelectronic_width/2));
+                    std::string sipmname7 = "SiPM_positive_s7_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet7(sd, sipmname7, detid);
+                    sipmdet7.setPlacement(plv_sipm7);
+
+                    dd4hep::PlacedVolume plv_sipm0 = hardware_s1.placeVolume(sipm_s0, Position(-length_posi+photoelectronic/2, 0, -photoelectronic_width/2));
+                    std::string sipmname0 = "SiPM_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet0(sd, sipmname0, detid);
+                    sipmdet0.setPlacement(plv_sipm0);
+
+                    dd4hep::PlacedVolume plv_sipm1 = hardware_s1.placeVolume(sipm_s0, Position(length_posi-photoelectronic/2, 0, photoelectronic_width/2));
+                    std::string sipmname1 = "SiPM_positive_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet1(sd, sipmname1, detid);
+                    sipmdet1.setPlacement(plv_sipm1);
+
+                    dd4hep::PlacedVolume plv_sipm2 = hardware_s1.placeVolume(sipm_s0, Position(-length_posi+photoelectronic/2, 0, photoelectronic_width/2));
+                    std::string sipmname2 = "SiPM_positive_s2_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet2(sd, sipmname2, detid);
+                    sipmdet2.setPlacement(plv_sipm2);
+
+                    dd4hep::PlacedVolume plv_sipm3 = hardware_s1.placeVolume(sipm_s0, Position(length_posi-photoelectronic/2, 0, -photoelectronic_width/2));
+                    std::string sipmname3 = "SiPM_positive_s3_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet3(sd, sipmname3, detid);
+                    sipmdet3.setPlacement(plv_sipm3);
+
+                    dd4hep::PlacedVolume plv_cry0 = carbonbox_s1.placeVolume(crystal_s1, Position(0, 0, 0));
+                    std::string cryname0 = "Crystal_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement crydet0(sd, cryname0, detid);
+                    crydet0.setPlacement(plv_cry0);
+
+                    dd4hep::PlacedVolume plv_cfb0 = hardware_s1.placeVolume(carbonbox_s1, Position(0, 0, 0));
+                    std::string cfbname0 = "cfbstal_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement cfbdet0(sd, cfbname0, detid);
+                    cfbdet0.setPlacement(plv_cfb0);
+
+                    dd4hep::PlacedVolume plv_hard0 = block.placeVolume(hardware_s1, Position(0, -length_crystal_z/2+last_bar_z/2, 0));
+                    plv_hard0.addPhysVolID("slayer",0).addPhysVolID("bar",ibar0);
+                    std::string hardname0 = "Hardware_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement harddet0(sd, hardname0, detid);
+                    harddet0.setPlacement(plv_hard0);
+                }
+                else{
+
+                    dd4hep::Volume hardware_s0("hardware_s0", dd4hep::Box(length_posi, width_crystal/2, size_posi_crystal/2), air); 
+                    hardware_s0.setVisAttributes(theDetector, "SeeThrough");
+
+                    dd4hep::Volume carbonbox_s0("carbonbox_s0", dd4hep::Box(length_posi-photoelectronic, width_crystal/2, size_posi_crystal/2), mat_CF); 
+                    carbonbox_s0.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::Volume crystal_s0("crystal_s0", dd4hep::Box(length_posi-photoelectronic-crystal_supportting, width_crystal/2-crystal_supportting, size_posi_crystal/2-crystal_supportting), mat_ESR); 
+                    crystal_s0.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::PlacedVolume plv_bar0 = crystal_s0.placeVolume(bar_s0, Position(0, 0, 0));
+                    std::string barname0 = "CrystalBar_positive_s0_"+std::to_string(ibar0);	
+                    dd4hep::DetElement bardet0(sd, barname0, detid);
+                    bardet0.setPlacement(plv_bar0);
+
+                    // dd4hep::PlacedVolume plv_sipm8 = carbonbox_s0.placeVolume(sipm_s1, Position(-length_posi+photoelectronic+crystal_supportting+photoelectronic/2, 0, -photoelectronic_width/2));
+                    // std::string sipmname8 = "SiPM_positive_s8_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet8(sd, sipmname8, detid);
+                    // sipmdet8.setPlacement(plv_sipm8);
+
+                    // dd4hep::PlacedVolume plv_sipm9 = carbonbox_s0.placeVolume(sipm_s1, Position(length_posi-photoelectronic-crystal_supportting-photoelectronic/2, 0, photoelectronic_width/2));
+                    // std::string sipmname9 = "SiPM_positive_s9_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet9(sd, sipmname9, detid);
+                    // sipmdet9.setPlacement(plv_sipm9);
+
+                    // dd4hep::PlacedVolume plv_sipm10 = carbonbox_s0.placeVolume(sipm_s1, Position(-length_posi+photoelectronic+crystal_supportting+photoelectronic/2, 0, photoelectronic_width/2));
+                    // std::string sipmname10 = "SiPM_positive_s10_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet10(sd, sipmname10, detid);
+                    // sipmdet10.setPlacement(plv_sipm10);
+
+                    // dd4hep::PlacedVolume plv_sipm11 = carbonbox_s0.placeVolume(sipm_s1, Position(length_posi-photoelectronic-crystal_supportting-photoelectronic/2, 0, -photoelectronic_width/2));
+                    // std::string sipmname11 = "SiPM_positive_s11_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet11(sd, sipmname11, detid);
+                    // sipmdet11.setPlacement(plv_sipm11);
+
+                    dd4hep::PlacedVolume plv_sipm4 = crystal_s0.placeVolume(sipm_s1, Position(-length_posi+photoelectronic+crystal_supportting+crystal_wrapping/2, 0, -photoelectronic_width/2));
+                    std::string sipmname4 = "SiPM_positive_s4_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet4(sd, sipmname4, detid);
+                    sipmdet4.setPlacement(plv_sipm4);
+
+                    dd4hep::PlacedVolume plv_sipm5 = crystal_s0.placeVolume(sipm_s1, Position(length_posi-photoelectronic-crystal_supportting-crystal_wrapping/2, 0, photoelectronic_width/2));
+                    std::string sipmname5 = "SiPM_positive_s5_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet5(sd, sipmname5, detid);
+                    sipmdet5.setPlacement(plv_sipm5);
+
+                    dd4hep::PlacedVolume plv_sipm6 = crystal_s0.placeVolume(sipm_s1, Position(-length_posi+photoelectronic+crystal_supportting+crystal_wrapping/2, 0, photoelectronic_width/2));
+                    std::string sipmname6 = "SiPM_positive_s6_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet6(sd, sipmname6, detid);
+                    sipmdet6.setPlacement(plv_sipm6);
+
+                    dd4hep::PlacedVolume plv_sipm7 = crystal_s0.placeVolume(sipm_s1, Position(length_posi-photoelectronic-crystal_supportting-crystal_wrapping/2, 0, -photoelectronic_width/2));
+                    std::string sipmname7 = "SiPM_positive_s7_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet7(sd, sipmname7, detid);
+                    sipmdet7.setPlacement(plv_sipm7);
+
+                    dd4hep::PlacedVolume plv_sipm0 = hardware_s0.placeVolume(sipm_s0, Position(-length_posi+photoelectronic/2, 0, -photoelectronic_width/2));
+                    std::string sipmname0 = "SiPM_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet0(sd, sipmname0, detid);
+                    sipmdet0.setPlacement(plv_sipm0);
+
+                    dd4hep::PlacedVolume plv_sipm1 = hardware_s0.placeVolume(sipm_s0, Position(length_posi-photoelectronic/2, 0, photoelectronic_width/2));
+                    std::string sipmname1 = "SiPM_positive_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet1(sd, sipmname1, detid);
+                    sipmdet1.setPlacement(plv_sipm1);
+
+                    dd4hep::PlacedVolume plv_sipm2 = hardware_s0.placeVolume(sipm_s0, Position(-length_posi+photoelectronic/2, 0, photoelectronic_width/2));
+                    std::string sipmname2 = "SiPM_positive_s2_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet2(sd, sipmname2, detid);
+                    sipmdet2.setPlacement(plv_sipm2);
+
+                    dd4hep::PlacedVolume plv_sipm3 = hardware_s0.placeVolume(sipm_s0, Position(length_posi-photoelectronic/2, 0, -photoelectronic_width/2));
+                    std::string sipmname3 = "SiPM_positive_s3_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet3(sd, sipmname3, detid);
+                    sipmdet3.setPlacement(plv_sipm3);
+
+                    dd4hep::PlacedVolume plv_cry0 = carbonbox_s0.placeVolume(crystal_s0, Position(0, 0, 0));
+                    std::string cryname0 = "Crystal_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement crydet0(sd, cryname0, detid);
+                    crydet0.setPlacement(plv_cry0);
+
+                    dd4hep::PlacedVolume plv_cfb0 = hardware_s0.placeVolume(carbonbox_s0, Position(0, 0, 0));
+                    std::string cfbname0 = "cfbstal_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement cfbdet0(sd, cfbname0, detid);
+                    cfbdet0.setPlacement(plv_cfb0);
+
+                    dd4hep::PlacedVolume plv_hard0 = block.placeVolume(hardware_s0, Position(0, length_crystal_z/2-(2*ibar0+1)*width_crystal/2, 0));
+                    std::string hardname0 = "Hardware_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement harddet0(sd, hardname0, detid);
+                    plv_hard0.addPhysVolID("slayer",0).addPhysVolID("bar",ibar0);
+                    harddet0.setPlacement(plv_hard0);
+                }
+            }
+        }
+
+        // #################################
+        // ####### Z direction place #######
+        // #################################
+
+        else{
+            
+            Nbar_z = int((length_posi-0.5*width_crystal)/width_crystal);
+            last_bar = length_posi-0.5*width_crystal - (Nbar_z-1)*width_crystal;
+
+            cout<< "   Nbar_z: " << 2*Nbar_z+1 << endl;
+
+            dd4hep::Volume sipm_s0("sipm_s0", dd4hep::Box(photoelectronic_width/2, photoelectronic/2, photoelectronic_width/2), mat_Si); 
+            sipm_s0.setVisAttributes(theDetector, "BlueVis");
+
+            dd4hep::Volume sipm_s1("sipm_s1", dd4hep::Box(photoelectronic_width/2, crystal_wrapping/2, photoelectronic_width/2), mat_Si);
+            sipm_s1.setVisAttributes(theDetector, "BlueVis");
+
+            dd4hep::Volume bar_s0("bar_s0", dd4hep::Box(width_crystal/2-crystal_wrapping-crystal_supportting, length_crystal_z/2-photoelectronic-crystal_wrapping-crystal_supportting, size_posi_crystal/2-crystal_wrapping-crystal_supportting), mat_BGO); 
+            bar_s0.setVisAttributes(theDetector, "EcalBarrelVis");
+            bar_s0.setSensitiveDetector(sens);
+
+            volume_bar_s0 = (width_crystal/2-crystal_wrapping-crystal_supportting)*(length_crystal_z/2-photoelectronic-crystal_wrapping-crystal_supportting)*(size_posi_crystal/2-crystal_wrapping-crystal_supportting)*8;
+
+            dd4hep::Volume bar_s1("bar_s1", dd4hep::Box(last_bar/2-crystal_wrapping-crystal_supportting, length_crystal_z/2-photoelectronic-crystal_wrapping-crystal_supportting, size_posi_crystal/2-crystal_wrapping-crystal_supportting), mat_BGO); 
+            bar_s1.setVisAttributes(theDetector, "EcalBarrelVis");
+            bar_s1.setSensitiveDetector(sens);
+
+            volume_bar_s1 = (last_bar/2-crystal_wrapping-crystal_supportting)*(length_crystal_z/2-photoelectronic-crystal_wrapping-crystal_supportting)*(size_posi_crystal/2-crystal_wrapping-crystal_supportting)*8;
+            
+            positive_volume = positive_volume + volume_bar_s0*(2*Nbar_z-1) + volume_bar_s1*2;
+
+            for(int ibar0=0;ibar0<2*Nbar_z+1;ibar0++){
+                if( (ibar0 == 0) || (ibar0 == 2*Nbar_z)){
+                    dd4hep::Volume hardware_s1("hardware_s1", dd4hep::Box(last_bar/2, length_crystal_z/2, size_posi_crystal/2), air); 
+                    hardware_s1.setVisAttributes(theDetector, "SeeThrough");
+
+                    dd4hep::Volume carbonbox_s1("carbonbox_s1", dd4hep::Box(last_bar/2, length_crystal_z/2-photoelectronic, size_posi_crystal/2), mat_CF);
+                    carbonbox_s1.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::Volume crystal_s1("crystal_s1", dd4hep::Box(last_bar/2-crystal_supportting, length_crystal_z/2-photoelectronic-crystal_supportting, size_posi_crystal/2-crystal_supportting), mat_ESR); 
+                    crystal_s1.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::PlacedVolume plv_bar0 = crystal_s1.placeVolume(bar_s1, Position(0, 0, 0));
+                    std::string barname0 = "CrystalBar_positive_s1_"+std::to_string(ibar0);	
+                    dd4hep::DetElement bardet0(sd, barname0, detid);
+                    bardet0.setPlacement(plv_bar0);
+
+                    // dd4hep::PlacedVolume plv_sipm8 = carbonbox_s1.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+photoelectronic/2, -photoelectronic_width/2));
+                    // std::string sipmname8 = "SiPM_positive_s8_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet8(sd, sipmname8, detid);
+                    // sipmdet8.setPlacement(plv_sipm8);
+
+                    // dd4hep::PlacedVolume plv_sipm9 = carbonbox_s1.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-photoelectronic/2, photoelectronic_width/2));
+                    // std::string sipmname9 = "SiPM_positive_s9_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet9(sd, sipmname9, detid);
+                    // sipmdet9.setPlacement(plv_sipm9);
+
+                    // dd4hep::PlacedVolume plv_sipm10 = carbonbox_s1.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+photoelectronic/2, photoelectronic_width/2));
+                    // std::string sipmname10 = "SiPM_positive_s10_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet10(sd, sipmname10, detid);
+                    // sipmdet10.setPlacement(plv_sipm10);
+
+                    // dd4hep::PlacedVolume plv_sipm11 = carbonbox_s1.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-photoelectronic/2, -photoelectronic_width/2));
+                    // std::string sipmname11 = "SiPM_positive_s11_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet11(sd, sipmname11, detid);
+                    // sipmdet11.setPlacement(plv_sipm11);
+
+                    dd4hep::PlacedVolume plv_sipm4 = crystal_s1.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+crystal_wrapping/2, -photoelectronic_width/2));
+                    std::string sipmname4 = "SiPM_positive_s4_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet4(sd, sipmname4, detid);
+                    sipmdet4.setPlacement(plv_sipm4);
+
+                    dd4hep::PlacedVolume plv_sipm5 = crystal_s1.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-crystal_wrapping/2, photoelectronic_width/2));
+                    std::string sipmname5 = "SiPM_positive_s5_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet5(sd, sipmname5, detid);
+                    sipmdet5.setPlacement(plv_sipm5);
+
+                    dd4hep::PlacedVolume plv_sipm6 = crystal_s1.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+crystal_wrapping/2, photoelectronic_width/2));
+                    std::string sipmname6 = "SiPM_positive_s6_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet6(sd, sipmname6, detid);
+                    sipmdet6.setPlacement(plv_sipm6);
+
+                    dd4hep::PlacedVolume plv_sipm7 = crystal_s1.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-crystal_wrapping/2, -photoelectronic_width/2));
+                    std::string sipmname7 = "SiPM_positive_s7_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet7(sd, sipmname7, detid);
+                    sipmdet7.setPlacement(plv_sipm7);
+
+                    dd4hep::PlacedVolume plv_sipm0 = hardware_s1.placeVolume(sipm_s0, Position(0, -length_crystal_z/2+photoelectronic/2, -photoelectronic_width/2));
+                    std::string sipmname0 = "SiPM_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet0(sd, sipmname0, detid);
+                    sipmdet0.setPlacement(plv_sipm0);
+
+                    dd4hep::PlacedVolume plv_sipm1 = hardware_s1.placeVolume(sipm_s0, Position(0, length_crystal_z/2-photoelectronic/2, photoelectronic_width/2));
+                    std::string sipmname1 = "SiPM_positive_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet1(sd, sipmname1, detid);
+                    sipmdet1.setPlacement(plv_sipm1);
+
+                    dd4hep::PlacedVolume plv_sipm2 = hardware_s1.placeVolume(sipm_s0, Position(0, -length_crystal_z/2+photoelectronic/2, photoelectronic_width/2));
+                    std::string sipmname2 = "SiPM_positive_s2_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet2(sd, sipmname2, detid);
+                    sipmdet2.setPlacement(plv_sipm2);
+
+                    dd4hep::PlacedVolume plv_sipm3 = hardware_s1.placeVolume(sipm_s0, Position(0, length_crystal_z/2-photoelectronic/2, -photoelectronic_width/2));
+                    std::string sipmname3 = "SiPM_positive_s3_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet3(sd, sipmname3, detid);
+                    sipmdet3.setPlacement(plv_sipm3);
+
+                    dd4hep::PlacedVolume plv_cry0 = carbonbox_s1.placeVolume(crystal_s1, Position(0, 0, 0));
+                    std::string cryname0 = "Crystal_positive_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement crydet0(sd, cryname0, detid);
+                    crydet0.setPlacement(plv_cry0);
+
+                    dd4hep::PlacedVolume plv_cfb0 = hardware_s1.placeVolume(carbonbox_s1, Position(0, 0, 0));
+                    std::string cfbname0 = "cfbstal_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement cfbdet0(sd, cfbname0, detid);
+                    cfbdet0.setPlacement(plv_cfb0);
+
+                    dd4hep::PlacedVolume plv_hard0;
+                    if(ibar0==0){
+                        plv_hard0 = block.placeVolume(hardware_s1, Position(0.5*width_crystal + (Nbar_z-1)*width_crystal + 0.5*last_bar, 0, 0));
+                    } 
+                    else{
+                        plv_hard0 = block.placeVolume(hardware_s1, Position(-0.5*width_crystal - (Nbar_z-1)*width_crystal - 0.5*last_bar, 0, 0));
+                    }
+                    plv_hard0.addPhysVolID("slayer",1).addPhysVolID("bar",ibar0);
+                    std::string hardname0 = "Hardware_positive_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement harddet0(sd, hardname0, detid);
+                    harddet0.setPlacement(plv_hard0);
+                }
+                else{
+                    dd4hep::Volume hardware_s0("hardware_s0", dd4hep::Box(width_crystal/2, length_crystal_z/2, size_posi_crystal/2), air); 
+                    hardware_s0.setVisAttributes(theDetector, "SeeThrough");
+
+                    dd4hep::Volume carbonbox_s0("carbonbox_s0", dd4hep::Box(width_crystal/2, length_crystal_z/2-photoelectronic, size_posi_crystal/2), mat_CF);
+                    carbonbox_s0.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::Volume crystal_s0("crystal_s0", dd4hep::Box(width_crystal/2-crystal_supportting, length_crystal_z/2-photoelectronic-crystal_supportting, size_posi_crystal/2-crystal_supportting), mat_ESR);   
+                    crystal_s0.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::PlacedVolume plv_bar0 = crystal_s0.placeVolume(bar_s0, Position(0, 0, 0));
+                    std::string barname0 = "CrystalBar_positive_s1_"+std::to_string(ibar0);	
+                    dd4hep::DetElement bardet0(sd, barname0, detid);
+                    bardet0.setPlacement(plv_bar0);
+
+                    // dd4hep::PlacedVolume plv_sipm8 = carbonbox_s0.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+photoelectronic/2, -photoelectronic_width/2));
+                    // std::string sipmname8 = "SiPM_positive_s8_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet8(sd, sipmname8, detid);
+                    // sipmdet8.setPlacement(plv_sipm8);
+
+                    // dd4hep::PlacedVolume plv_sipm9 = carbonbox_s0.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-photoelectronic/2, photoelectronic_width/2));
+                    // std::string sipmname9 = "SiPM_positive_s9_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet9(sd, sipmname9, detid);
+                    // sipmdet9.setPlacement(plv_sipm9);
+
+                    // dd4hep::PlacedVolume plv_sipm10 = carbonbox_s0.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+photoelectronic/2, photoelectronic_width/2));
+                    // std::string sipmname10 = "SiPM_positive_s10_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet10(sd, sipmname10, detid);
+                    // sipmdet10.setPlacement(plv_sipm10);
+
+                    // dd4hep::PlacedVolume plv_sipm11 = carbonbox_s0.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-photoelectronic/2, -photoelectronic_width/2));
+                    // std::string sipmname11 = "SiPM_positive_s11_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet11(sd, sipmname11, detid);
+                    // sipmdet11.setPlacement(plv_sipm11);
+
+                    dd4hep::PlacedVolume plv_sipm4 = crystal_s0.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_wrapping/2, -photoelectronic_width/2));
+                    std::string sipmname4 = "SiPM_positive_s12_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet4(sd, sipmname4, detid);
+                    sipmdet4.setPlacement(plv_sipm4);
+
+                    dd4hep::PlacedVolume plv_sipm5 = crystal_s0.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_wrapping/2, photoelectronic_width/2));
+                    std::string sipmname5 = "SiPM_positive_s13_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet5(sd, sipmname5, detid);
+                    sipmdet5.setPlacement(plv_sipm5);
+
+                    dd4hep::PlacedVolume plv_sipm6 = crystal_s0.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_wrapping/2, photoelectronic_width/2));
+                    std::string sipmname6 = "SiPM_positive_s14_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet6(sd, sipmname6, detid);
+                    sipmdet6.setPlacement(plv_sipm6);
+
+                    dd4hep::PlacedVolume plv_sipm7 = crystal_s0.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_wrapping/2, -photoelectronic_width/2));
+                    std::string sipmname7 = "SiPM_positive_s15_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet7(sd, sipmname7, detid);
+                    sipmdet7.setPlacement(plv_sipm7);
+
+                    dd4hep::PlacedVolume plv_sipm0 = hardware_s0.placeVolume(sipm_s0, Position(0, -length_crystal_z/2+photoelectronic/2, -photoelectronic_width/2));
+                    std::string sipmname0 = "SiPM_positive_s4_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet0(sd, sipmname0, detid);
+                    sipmdet0.setPlacement(plv_sipm0);
+
+                    dd4hep::PlacedVolume plv_sipm1 = hardware_s0.placeVolume(sipm_s0, Position(0, length_crystal_z/2-photoelectronic/2, photoelectronic_width/2));
+                    std::string sipmname1 = "SiPM_positive_s5_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet1(sd, sipmname1, detid);
+                    sipmdet1.setPlacement(plv_sipm1);
+
+                    dd4hep::PlacedVolume plv_sipm2 = hardware_s0.placeVolume(sipm_s0, Position(0, -length_crystal_z/2+photoelectronic/2, photoelectronic_width/2));
+                    std::string sipmname2 = "SiPM_positive_s6_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet2(sd, sipmname2, detid);
+                    sipmdet2.setPlacement(plv_sipm2);
+
+                    dd4hep::PlacedVolume plv_sipm3 = hardware_s0.placeVolume(sipm_s0, Position(0, length_crystal_z/2-photoelectronic/2, -photoelectronic_width/2));
+                    std::string sipmname3 = "SiPM_positive_s7_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet3(sd, sipmname3, detid);
+                    sipmdet3.setPlacement(plv_sipm3);
+
+                    dd4hep::PlacedVolume plv_cry0 = carbonbox_s0.placeVolume(crystal_s0, Position(0, 0, 0));
+                    std::string cryname0 = "Crystal_positive_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement crydet0(sd, cryname0, detid);
+                    crydet0.setPlacement(plv_cry0);
+
+                    dd4hep::PlacedVolume plv_cfb0 = hardware_s0.placeVolume(carbonbox_s0, Position(0, 0, 0));
+                    std::string cfbname0 = "cfbstal_positive_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement cfbdet0(sd, cfbname0, detid);
+                    cfbdet0.setPlacement(plv_cfb0);
+
+                    dd4hep::PlacedVolume plv_hard0 = block.placeVolume(hardware_s0, Position(length_posi - last_bar - (ibar0-1)*width_crystal - width_crystal/2, 0, 0));
+                    std::string hardname0 = "Hardware_positive_s1_"+std::to_string(ibar0);
+                    plv_hard0.addPhysVolID("slayer",1).addPhysVolID("bar",ibar0);
+                    dd4hep::DetElement harddet0(sd, hardname0, detid);
+                    harddet0.setPlacement(plv_hard0);
+                }
+            }
+        }
+
+        dd4hep::PlacedVolume plv = subtrap_positive_vol.placeVolume(block, Position(0, 0, 0.5*size_posi_crystal+ilayer*size_posi_crystal-dim_z_p));
+        plv.addPhysVolID("dlayer", floor(ilayer/2+1));
+        // cout<<"*****layer: "<<floor(ilayer/2+1)<<endl;
+        sd.setPlacement(plv);              
+    }
+
+    // ##########################
+    // ### negative trapezoid ###
+    // ##########################
+
+    dd4hep::Volume backPlate1("back_plate_negative", dd4hep::Box(back_plate*13, back_plate*13, back_plate/2), mat_PCB);
+    backPlate1.setVisAttributes(theDetector, "GrayVis");
+    std::string blockname1 = "back_plate_negative";
+    dd4hep::DetElement sd1(stavedet, blockname1, detid);
+    dd4hep::PlacedVolume plv1 = subtrap_negative_vol.placeVolume(backPlate1, Position(0, 0, dim_z_n-back_plate/2));
+    sd1.setPlacement(plv1);
+
+
+    for(int ilayer=0; ilayer<Nlayers; ilayer=ilayer+1){
+        
+        length_nega = dim_x3 - dead_material_r - (ilayer+1)*size_crystal/tan(copper_angle);
+        
+        cout << "layer: " << ilayer+1 << endl;
+        cout << "   length_nega: " << length_nega*2 << endl;
+
+
+        //Trapezoid in layer
+        dd4hep::Volume block("block", dd4hep::Trapezoid( dim_x3-ilayer*size_crystal/tan(copper_angle), dim_x3-(ilayer+1)*size_crystal/tan(copper_angle), pZ/2, pZ/2, size_crystal/2), air);
+        block.setVisAttributes(theDetector, "SeeThrough");
+        std::string blockname = "Block_nagative_"+std::to_string(ilayer+1);
+        dd4hep::DetElement sd(stavedet, blockname, detid);
+
+        //Carbon fiber supporting
+        dd4hep::Volume CarbonFiber0("CarbonFiber0", dd4hep::Box(length_nega+electronics, dead_material_zz/2, size_crystal/2), mat_CF); //phi
+        CarbonFiber0.setVisAttributes(theDetector, "GrayVis");
+
+        dd4hep::PlacedVolume plv_cf0 = block.placeVolume(CarbonFiber0, Position(0, pZ/2-dead_material_zz/2, 0));
+        std::string cfname0 = "Deadzone_s4_"+std::to_string(ilayer+1);	
+        dd4hep::DetElement cfdet0(sd, cfname0, detid);
+        cfdet0.setPlacement(plv_cf0);
+
+        dd4hep::PlacedVolume plv_cf1 = block.placeVolume(CarbonFiber0, Position(0, -pZ/2+dead_material_zz/2, 0));
+        std::string cfname1 = "Deadzone_s5_"+std::to_string(ilayer+1);	
+        dd4hep::DetElement cfdet1(sd, cfname1, detid);
+        cfdet1.setPlacement(plv_cf1);
+
+        dd4hep::Transform3D transform(dd4hep::RotationX(-90*degree)*dd4hep::RotationZ(180*degree), dd4hep::Position(-length_nega-electronics-dead_material_n/2-((dead_material_n + size_crystal/tan(copper_angle))/2-dead_material_n/2)/2, 0., 0.)  ); 
+        dd4hep::PlacedVolume plv_bar2 = block.placeVolume(right, transform);
+        std::string barname2 = "Deadzone_s2_"+std::to_string(ilayer+1);
+        dd4hep::DetElement bardet2(sd, barname2, detid);
+        bardet2.setPlacement(plv_bar2);
+
+        dd4hep::Transform3D transform2(dd4hep::RotationX(90*degree),  dd4hep::Position(length_nega+electronics+dead_material_n/2+((dead_material_n + size_crystal/tan(copper_angle))/2-dead_material_n/2)/2, 0., 0.)  ); 
+        dd4hep::PlacedVolume plv_bar3= block.placeVolume(right, transform2);
+        std::string barname3 = "Deadzone_s3_"+std::to_string(ilayer+1);
+        dd4hep::DetElement bardet3(sd, barname3, detid);
+        bardet3.setPlacement(plv_bar3);
+     
+        //Electronics
+        dd4hep::Volume electronics_phi0("electronics_phi0", dd4hep::Box(length_nega+electronics, (electronics-cooling)/2, size_crystal/2), mat_PCB); //phi
+        electronics_phi0.setVisAttributes(theDetector, "YellowVis");
+
+        dd4hep::PlacedVolume plv_elec0 = block.placeVolume(electronics_phi0, Position(0, -length_crystal_z/2-(electronics-cooling)/2, 0));
+        std::string elecname0 = "electronics_nega_phi_u_"+std::to_string(ilayer+1);	
+        dd4hep::DetElement elecdet0(sd, elecname0, detid);
+        elecdet0.setPlacement(plv_elec0);
+
+        dd4hep::PlacedVolume plv_elec1 = block.placeVolume(electronics_phi0, Position(0, length_crystal_z/2+(electronics-cooling)/2, 0));
+        std::string elecname1 = "electronics_nega_phi_d_"+std::to_string(ilayer+1);
+        dd4hep::DetElement elecdet1(sd, elecname1, detid);
+        elecdet1.setPlacement(plv_elec1);
+
+        dd4hep::Volume electronics_phi_l("electronics_phi_l", dd4hep::Box((electronics-cooling)/2, length_crystal_z/2, size_crystal/2), mat_PCB); //phi
+        electronics_phi_l.setVisAttributes(theDetector, "YellowVis");
+
+        dd4hep::PlacedVolume plv_elec2 = block.placeVolume(electronics_phi_l, Position(-length_nega-(electronics-cooling)/2, 0, 0));
+        std::string elecname2 = "electronics_nega_phi_l_"+std::to_string(ilayer+1);
+        dd4hep::DetElement elecdet2(sd, elecname2, detid);
+        elecdet2.setPlacement(plv_elec2);
+
+        dd4hep::PlacedVolume plv_elec3 = block.placeVolume(electronics_phi_l, Position(length_nega+(electronics-cooling)/2, 0, 0));
+        std::string elecname3 = "electronics_nega_phi_r_"+std::to_string(ilayer+1);
+        dd4hep::DetElement elecdet3(sd, elecname3, detid);
+        elecdet3.setPlacement(plv_elec3);
+
+        //Cooling copper
+
+        dd4hep::Volume copper_phi0("copper_phi0", dd4hep::Box(length_nega+electronics, cooling/2, size_crystal/2), mat_Cu); //phi
+        copper_phi0.setVisAttributes(theDetector, "RedVis");
+
+        dd4hep::PlacedVolume plv_copper0 = block.placeVolume(copper_phi0, Position(0, -length_crystal_z/2-electronics+cooling/2, 0));
+        std::string coppername0 = "cooling_nega_phi_u_"+std::to_string(ilayer+1);
+        dd4hep::DetElement copperdet0(sd, coppername0, detid);
+        copperdet0.setPlacement(plv_copper0);
+
+        dd4hep::PlacedVolume plv_copper1 = block.placeVolume(copper_phi0, Position(0, length_crystal_z/2+electronics-cooling/2, 0));
+        std::string coppername1 = "cooling_nega_phi_d_"+std::to_string(ilayer+1);
+        dd4hep::DetElement copperdet1(sd, coppername1, detid);
+        copperdet1.setPlacement(plv_copper1);
+
+        dd4hep::Volume copper_phi_l("copper_phi_l", dd4hep::Box(cooling/2, length_crystal_z/2, size_crystal/2), mat_Cu); //phi
+        copper_phi_l.setVisAttributes(theDetector, "RedVis");
+
+        dd4hep::PlacedVolume plv_copper2 = block.placeVolume(copper_phi_l, Position(-length_nega-electronics+cooling/2, 0, 0));
+        std::string coppername2 = "cooling_nega_phi_l_"+std::to_string(ilayer+1);
+        dd4hep::DetElement copperdet2(sd, coppername2, detid);
+        copperdet2.setPlacement(plv_copper2);
+
+        dd4hep::PlacedVolume plv_copper3 = block.placeVolume(copper_phi_l, Position(length_nega+electronics-cooling/2, 0, 0));
+        std::string coppername3 = "cooling_nega_phi_r_"+std::to_string(ilayer+1);
+        dd4hep::DetElement copperdet3(sd, coppername3, detid);
+        copperdet3.setPlacement(plv_copper3);
+        
+        // ###################################
+        // ####### Phi direction place #######
+        // ###################################
+
+        if(ilayer%2==0){
+
+            cout<< "   Nbar_phi: " << Nbar_phi << endl;
+
+            dd4hep::Volume sipm_s0("sipm_s0", dd4hep::Box(photoelectronic/2, photoelectronic_width/2, photoelectronic_width/2), mat_Si); 
+            sipm_s0.setVisAttributes(theDetector, "BlueVis");
+
+            dd4hep::Volume sipm_s1("sipm_s1", dd4hep::Box(crystal_wrapping/2, photoelectronic_width/2, photoelectronic_width/2), mat_Si);
+            sipm_s1.setVisAttributes(theDetector, "BlueVis");
+
+            last_bar_z = length_crystal_z - (Nbar_phi-1)*width_crystal;
+
+            dd4hep::Volume bar_s0("bar_s0", dd4hep::Box(length_nega-photoelectronic-crystal_wrapping-crystal_supportting, width_crystal/2-crystal_wrapping-crystal_supportting, size_crystal/2-crystal_wrapping-crystal_supportting), mat_BGO); 
+            bar_s0.setVisAttributes(theDetector, "EcalBarrelVis");
+            bar_s0.setSensitiveDetector(sens);
+
+            volume_bar_s0 = (length_nega-photoelectronic-crystal_wrapping-crystal_supportting)*(width_crystal/2-crystal_wrapping-crystal_supportting)*(size_crystal/2-crystal_wrapping-crystal_supportting)*8;
+
+            dd4hep::Volume bar_s1("bar_s1", dd4hep::Box(length_nega-photoelectronic-crystal_wrapping-crystal_supportting, last_bar_z/2-crystal_wrapping-crystal_supportting, size_crystal/2-crystal_wrapping-crystal_supportting), mat_BGO); 
+            bar_s1.setVisAttributes(theDetector, "EcalBarrelVis");
+            bar_s1.setSensitiveDetector(sens);
+
+            volume_bar_s1 = (length_nega-photoelectronic-crystal_wrapping-crystal_supportting)*(last_bar_z/2-crystal_wrapping-crystal_supportting)*(size_crystal/2-crystal_wrapping-crystal_supportting)*8;
+            
+            negative_volume = negative_volume + volume_bar_s0*(Nbar_phi-1) + volume_bar_s1;
+
+            for(int ibar0=0;ibar0<Nbar_phi;ibar0++){
+                if(ibar0 == (Nbar_phi-1)){
+                    
+                    dd4hep::Volume hardware_s1("hardware_s1", dd4hep::Box(length_nega, last_bar_z/2, size_crystal/2), air); 
+                    hardware_s1.setVisAttributes(theDetector, "SeeThrough");
+
+                    dd4hep::Volume carbonbox_s1("carbonbox_s1", dd4hep::Box(length_nega-photoelectronic, last_bar_z/2, size_crystal/2), mat_CF);
+                    carbonbox_s1.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::Volume crystal_s1("crystal_s1", dd4hep::Box(length_nega-photoelectronic-crystal_supportting, last_bar_z/2-crystal_supportting, size_crystal/2-crystal_supportting), mat_ESR); 
+                    crystal_s1.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::PlacedVolume plv_bar0 = crystal_s1.placeVolume(bar_s1, Position(0, 0, 0));
+                    std::string barname0 = "CrystalBar_negative_s0_"+std::to_string(ibar0);	
+                    dd4hep::DetElement bardet0(sd, barname0, detid);
+                    bardet0.setPlacement(plv_bar0);
+
+                    // dd4hep::PlacedVolume plv_sipm8 = carbonbox_s1.placeVolume(sipm_s1, Position(-length_nega+photoelectronic+crystal_supportting+photoelectronic/2, 0, -photoelectronic_width/2));
+                    // std::string sipmname8 = "SiPM_negative_s8_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet8(sd, sipmname8, detid);
+                    // sipmdet8.setPlacement(plv_sipm8);
+
+                    // dd4hep::PlacedVolume plv_sipm9 = carbonbox_s1.placeVolume(sipm_s1, Position(length_nega-photoelectronic-crystal_supportting-photoelectronic/2, 0, photoelectronic_width/2));
+                    // std::string sipmname9 = "SiPM_negative_s9_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet9(sd, sipmname9, detid);
+                    // sipmdet9.setPlacement(plv_sipm9);
+
+                    // dd4hep::PlacedVolume plv_sipm10 = carbonbox_s1.placeVolume(sipm_s1, Position(-length_nega+photoelectronic+crystal_supportting+photoelectronic/2, 0, photoelectronic_width/2));
+                    // std::string sipmname10 = "SiPM_negative_s10_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet10(sd, sipmname10, detid);
+                    // sipmdet10.setPlacement(plv_sipm10);
+
+                    // dd4hep::PlacedVolume plv_sipm11 = carbonbox_s1.placeVolume(sipm_s1, Position(length_nega-photoelectronic-crystal_supportting-photoelectronic/2, 0, -photoelectronic_width/2));
+                    // std::string sipmname11 = "SiPM_negative_s11_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet11(sd, sipmname11, detid);
+                    // sipmdet11.setPlacement(plv_sipm11);
+
+                    dd4hep::PlacedVolume plv_sipm4 = crystal_s1.placeVolume(sipm_s1, Position(-length_nega+photoelectronic+crystal_supportting+crystal_wrapping/2, 0, -photoelectronic_width/2));
+                    std::string sipmname4 = "SiPM_negative_s4_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet4(sd, sipmname4, detid);
+                    sipmdet4.setPlacement(plv_sipm4);
+
+                    dd4hep::PlacedVolume plv_sipm5 = crystal_s1.placeVolume(sipm_s1, Position(length_nega-photoelectronic-crystal_supportting-crystal_wrapping/2, 0, photoelectronic_width/2));
+                    std::string sipmname5 = "SiPM_negative_s5_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet5(sd, sipmname5, detid);
+                    sipmdet5.setPlacement(plv_sipm5);
+
+                    dd4hep::PlacedVolume plv_sipm6 = crystal_s1.placeVolume(sipm_s1, Position(-length_nega+photoelectronic+crystal_supportting+crystal_wrapping/2, 0, photoelectronic_width/2));
+                    std::string sipmname6 = "SiPM_negative_s6_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet6(sd, sipmname6, detid);
+                    sipmdet6.setPlacement(plv_sipm6);
+
+                    dd4hep::PlacedVolume plv_sipm7 = crystal_s1.placeVolume(sipm_s1, Position(length_nega-photoelectronic-crystal_supportting-crystal_wrapping/2, 0, -photoelectronic_width/2));
+                    std::string sipmname7 = "SiPM_negative_s7_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet7(sd, sipmname7, detid);
+                    sipmdet7.setPlacement(plv_sipm7);
+
+                    dd4hep::PlacedVolume plv_sipm0 = hardware_s1.placeVolume(sipm_s0, Position(-length_nega+photoelectronic/2, 0, -photoelectronic_width/2));
+                    std::string sipmname0 = "SiPM_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet0(sd, sipmname0, detid);
+                    sipmdet0.setPlacement(plv_sipm0);
+
+                    dd4hep::PlacedVolume plv_sipm1 = hardware_s1.placeVolume(sipm_s0, Position(length_nega-photoelectronic/2, 0, photoelectronic_width/2));
+                    std::string sipmname1 = "SiPM_negative_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet1(sd, sipmname1, detid);
+                    sipmdet1.setPlacement(plv_sipm1);
+
+                    dd4hep::PlacedVolume plv_sipm2 = hardware_s1.placeVolume(sipm_s0, Position(-length_nega+photoelectronic/2, 0, photoelectronic_width/2));
+                    std::string sipmname2 = "SiPM_negative_s2_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet2(sd, sipmname2, detid);
+                    sipmdet2.setPlacement(plv_sipm2);
+
+                    dd4hep::PlacedVolume plv_sipm3 = hardware_s1.placeVolume(sipm_s0, Position(length_nega-photoelectronic/2, 0, -photoelectronic_width/2));
+                    std::string sipmname3 = "SiPM_negative_s3_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet3(sd, sipmname3, detid);
+                    sipmdet3.setPlacement(plv_sipm3);
+
+                    dd4hep::PlacedVolume plv_cry0 = carbonbox_s1.placeVolume(crystal_s1, Position(0, 0, 0));
+                    std::string cryname0 = "Crystal_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement crydet0(sd, cryname0, detid);
+                    crydet0.setPlacement(plv_cry0);
+
+                    dd4hep::PlacedVolume plv_cfb0 = hardware_s1.placeVolume(carbonbox_s1, Position(0, 0, 0));
+                    std::string cfbname0 = "cfbstal_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement cfbdet0(sd, cfbname0, detid);
+                    cfbdet0.setPlacement(plv_cfb0);
+
+                    dd4hep::PlacedVolume plv_hard0 = block.placeVolume(hardware_s1, Position(0, -length_crystal_z/2+last_bar_z/2, 0));
+                    plv_hard0.addPhysVolID("slayer",0).addPhysVolID("bar",ibar0);
+                    std::string hardname0 = "Hardware_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement harddet0(sd, hardname0, detid);
+                    harddet0.setPlacement(plv_hard0);
+                }
+                else{
+                    dd4hep::Volume hardware_s0("hardware_s0", dd4hep::Box(length_nega, width_crystal/2, size_crystal/2), air); 
+                    hardware_s0.setVisAttributes(theDetector, "SeeThrough");
+
+                    dd4hep::Volume carbonbox_s0("carbonbox_s0", dd4hep::Box(length_nega-photoelectronic, width_crystal/2, size_crystal/2), mat_CF);
+                    carbonbox_s0.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::Volume crystal_s0("crystal_s0", dd4hep::Box(length_nega-photoelectronic-crystal_supportting, width_crystal/2-crystal_supportting, size_crystal/2-crystal_supportting), mat_ESR); 
+                    crystal_s0.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::PlacedVolume plv_bar0 = crystal_s0.placeVolume(bar_s0, Position(0, 0, 0));
+                    std::string barname0 = "CrystalBar_negative_s0_"+std::to_string(ibar0);	
+                    dd4hep::DetElement bardet0(sd, barname0, detid);
+                    bardet0.setPlacement(plv_bar0);
+
+                    // dd4hep::PlacedVolume plv_sipm8 = carbonbox_s0.placeVolume(sipm_s1, Position(-length_nega+photoelectronic+crystal_supportting+photoelectronic/2, 0, -photoelectronic_width/2));
+                    // std::string sipmname8 = "SiPM_negative_s8_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet8(sd, sipmname8, detid);
+                    // sipmdet8.setPlacement(plv_sipm8);
+
+                    // dd4hep::PlacedVolume plv_sipm9 = carbonbox_s0.placeVolume(sipm_s1, Position(length_nega-photoelectronic-crystal_supportting-photoelectronic/2, 0, photoelectronic_width/2));
+                    // std::string sipmname9 = "SiPM_negative_s9_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet9(sd, sipmname9, detid);
+                    // sipmdet9.setPlacement(plv_sipm9);
+
+                    // dd4hep::PlacedVolume plv_sipm10 = carbonbox_s0.placeVolume(sipm_s1, Position(-length_nega+photoelectronic+crystal_supportting+photoelectronic/2, 0, photoelectronic_width/2));
+                    // std::string sipmname10 = "SiPM_negative_s10_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet10(sd, sipmname10, detid);
+                    // sipmdet10.setPlacement(plv_sipm10);
+
+                    // dd4hep::PlacedVolume plv_sipm11 = carbonbox_s0.placeVolume(sipm_s1, Position(length_nega-photoelectronic-crystal_supportting-photoelectronic/2, 0, -photoelectronic_width/2));
+                    // std::string sipmname11 = "SiPM_negative_s11_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet11(sd, sipmname11, detid);
+                    // sipmdet11.setPlacement(plv_sipm11);
+
+                    dd4hep::PlacedVolume plv_sipm4 = crystal_s0.placeVolume(sipm_s1, Position(-length_nega+photoelectronic+crystal_supportting+crystal_wrapping/2, 0, -photoelectronic_width/2));
+                    std::string sipmname4 = "SiPM_negative_s4_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet4(sd, sipmname4, detid);
+                    sipmdet4.setPlacement(plv_sipm4);
+
+                    dd4hep::PlacedVolume plv_sipm5 = crystal_s0.placeVolume(sipm_s1, Position(length_nega-photoelectronic-crystal_supportting-crystal_wrapping/2, 0, photoelectronic_width/2));
+                    std::string sipmname5 = "SiPM_negative_s5_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet5(sd, sipmname5, detid);
+                    sipmdet5.setPlacement(plv_sipm5);
+
+                    dd4hep::PlacedVolume plv_sipm6 = crystal_s0.placeVolume(sipm_s1, Position(-length_nega+photoelectronic+crystal_supportting+crystal_wrapping/2, 0, photoelectronic_width/2));
+                    std::string sipmname6 = "SiPM_negative_s6_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet6(sd, sipmname6, detid);
+                    sipmdet6.setPlacement(plv_sipm6);
+
+                    dd4hep::PlacedVolume plv_sipm7 = crystal_s0.placeVolume(sipm_s1, Position(length_nega-photoelectronic-crystal_supportting-crystal_wrapping/2, 0, -photoelectronic_width/2));
+                    std::string sipmname7 = "SiPM_negative_s7_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet7(sd, sipmname7, detid);
+                    sipmdet7.setPlacement(plv_sipm7);
+
+                    dd4hep::PlacedVolume plv_sipm0 = hardware_s0.placeVolume(sipm_s0, Position(-length_nega+photoelectronic/2, 0, -photoelectronic_width/2));
+                    std::string sipmname0 = "SiPM_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet0(sd, sipmname0, detid);
+                    sipmdet0.setPlacement(plv_sipm0);
+
+                    dd4hep::PlacedVolume plv_sipm1 = hardware_s0.placeVolume(sipm_s0, Position(length_nega-photoelectronic/2, 0, photoelectronic_width/2));
+                    std::string sipmname1 = "SiPM_negative_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet1(sd, sipmname1, detid);
+                    sipmdet1.setPlacement(plv_sipm1);
+
+                    dd4hep::PlacedVolume plv_sipm2 = hardware_s0.placeVolume(sipm_s0, Position(-length_nega+photoelectronic/2, 0, photoelectronic_width/2));
+                    std::string sipmname2 = "SiPM_negative_s2_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet2(sd, sipmname2, detid);
+                    sipmdet2.setPlacement(plv_sipm2);
+
+                    dd4hep::PlacedVolume plv_sipm3 = hardware_s0.placeVolume(sipm_s0, Position(length_nega-photoelectronic/2, 0, -photoelectronic_width/2));
+                    std::string sipmname3 = "SiPM_negative_s3_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet3(sd, sipmname3, detid);
+                    sipmdet3.setPlacement(plv_sipm3);
+
+                    dd4hep::PlacedVolume plv_cry0 = carbonbox_s0.placeVolume(crystal_s0, Position(0, 0, 0));
+                    std::string cryname0 = "Crystal_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement crydet0(sd, cryname0, detid);
+                    crydet0.setPlacement(plv_cry0);
+
+                    dd4hep::PlacedVolume plv_cfb0 = hardware_s0.placeVolume(carbonbox_s0, Position(0, 0, 0));
+                    std::string cfbname0 = "cfbstal_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement cfbdet0(sd, cfbname0, detid);
+                    cfbdet0.setPlacement(plv_cfb0); 
+
+                    dd4hep::PlacedVolume plv_hard0 = block.placeVolume(hardware_s0, Position(0, length_crystal_z/2-(2*ibar0+1)*width_crystal/2, 0));
+                    plv_hard0.addPhysVolID("slayer",0).addPhysVolID("bar",ibar0);
+                    std::string hardname0 = "Hardware_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement harddet0(sd, hardname0, detid);
+                    harddet0.setPlacement(plv_hard0);
+                }
+            }
+        }
+
+        // #################################
+        // ####### Z direction place #######
+        // #################################
+
+        else{
+        
+            Nbar_z = int((length_nega-0.5*width_crystal)/width_crystal);
+            last_bar = length_nega-0.5*width_crystal - (Nbar_z-1)*width_crystal;
+
+            cout << "   Nbar_z: " << 2*Nbar_z+1 << endl;
+
+            dd4hep::Volume sipm_s0("sipm_s0", dd4hep::Box(photoelectronic_width/2, photoelectronic/2, photoelectronic_width/2), mat_Si); 
+            sipm_s0.setVisAttributes(theDetector, "BlueVis");
+
+            dd4hep::Volume sipm_s1("sipm_s1", dd4hep::Box(photoelectronic_width/2, crystal_wrapping/2, photoelectronic_width/2), mat_Si);
+            sipm_s1.setVisAttributes(theDetector, "BlueVis");
+
+            dd4hep::Volume bar_s0("bar_s0", dd4hep::Box(width_crystal/2-crystal_wrapping-crystal_supportting, length_crystal_z/2-photoelectronic-crystal_wrapping-crystal_supportting, size_crystal/2-crystal_wrapping-crystal_supportting), mat_BGO); 
+            bar_s0.setVisAttributes(theDetector, "EcalBarrelVis");
+            bar_s0.setSensitiveDetector(sens);
+
+            volume_bar_s0 = (width_crystal/2-crystal_wrapping-crystal_supportting)*(length_crystal_z/2-photoelectronic-crystal_wrapping-crystal_supportting)*(size_crystal/2-crystal_wrapping-crystal_supportting)*8;
+
+            dd4hep::Volume bar_s1("bar_s1", dd4hep::Box(last_bar/2-crystal_wrapping-crystal_supportting, length_crystal_z/2-photoelectronic-crystal_wrapping-crystal_supportting, size_crystal/2-crystal_wrapping-crystal_supportting), mat_BGO);
+            bar_s1.setVisAttributes(theDetector, "EcalBarrelVis");
+            bar_s1.setSensitiveDetector(sens);
+
+            volume_bar_s1 = (last_bar/2-crystal_wrapping-crystal_supportting)*(length_crystal_z/2-photoelectronic-crystal_wrapping-crystal_supportting)*(size_crystal/2-crystal_wrapping-crystal_supportting)*8;
+
+            negative_volume = negative_volume + volume_bar_s0*(2*Nbar_z-1) + volume_bar_s1*2;
+
+            for(int ibar0=0;ibar0<2*Nbar_z+1;ibar0++){
+                if( (ibar0 == 0) || (ibar0 == 2*Nbar_z)){
+                
+                    dd4hep::Volume hardware_s1("hardware_s1", dd4hep::Box(last_bar/2, length_crystal_z/2, size_crystal/2), air); 
+                    hardware_s1.setVisAttributes(theDetector, "SeeThrough");
+
+                    dd4hep::Volume carbonbox_s1("carbonbox_s1", dd4hep::Box(last_bar/2, length_crystal_z/2-photoelectronic, size_crystal/2), mat_CF);
+                    carbonbox_s1.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::Volume crystal_s1("crystal_s1", dd4hep::Box(last_bar/2-crystal_supportting, length_crystal_z/2-photoelectronic-crystal_supportting, size_crystal/2-crystal_supportting), mat_ESR); 
+                    crystal_s1.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::PlacedVolume plv_bar0 = crystal_s1.placeVolume(bar_s1, Position(0, 0, 0));
+                    std::string barname0 = "CrystalBar_negative_s1_"+std::to_string(ibar0);	
+                    dd4hep::DetElement bardet0(sd, barname0, detid);
+                    bardet0.setPlacement(plv_bar0);
+
+                    // dd4hep::PlacedVolume plv_sipm8 = carbonbox_s1.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+photoelectronic/2, -photoelectronic_width/2));
+                    // std::string sipmname8 = "SiPM_negative_s8_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet8(sd, sipmname8, detid);
+                    // sipmdet8.setPlacement(plv_sipm8);
+
+                    // dd4hep::PlacedVolume plv_sipm9 = carbonbox_s1.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-photoelectronic/2, photoelectronic_width/2));
+                    // std::string sipmname9 = "SiPM_negative_s9_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet9(sd, sipmname9, detid);
+                    // sipmdet9.setPlacement(plv_sipm9);
+
+                    // dd4hep::PlacedVolume plv_sipm10 = carbonbox_s1.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+photoelectronic/2, photoelectronic_width/2));
+                    // std::string sipmname10 = "SiPM_negative_s10_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet10(sd, sipmname10, detid);
+                    // sipmdet10.setPlacement(plv_sipm10);
+
+                    // dd4hep::PlacedVolume plv_sipm11 = carbonbox_s1.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-photoelectronic/2, -photoelectronic_width/2));
+                    // std::string sipmname11 = "SiPM_negative_s11_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet11(sd, sipmname11, detid);
+                    // sipmdet11.setPlacement(plv_sipm11);
+
+                    dd4hep::PlacedVolume plv_sipm4 = crystal_s1.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+crystal_wrapping/2, -photoelectronic_width/2));
+                    std::string sipmname4 = "SiPM_negative_s4_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet4(sd, sipmname4, detid);
+                    sipmdet4.setPlacement(plv_sipm4);
+
+                    dd4hep::PlacedVolume plv_sipm5 = crystal_s1.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-crystal_wrapping/2, photoelectronic_width/2));
+                    std::string sipmname5 = "SiPM_negative_s5_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet5(sd, sipmname5, detid);
+                    sipmdet5.setPlacement(plv_sipm5);
+
+                    dd4hep::PlacedVolume plv_sipm6 = crystal_s1.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+crystal_wrapping/2, photoelectronic_width/2));
+                    std::string sipmname6 = "SiPM_negative_s6_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet6(sd, sipmname6, detid);
+                    sipmdet6.setPlacement(plv_sipm6);
+
+                    dd4hep::PlacedVolume plv_sipm7 = crystal_s1.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-crystal_wrapping/2, -photoelectronic_width/2));
+                    std::string sipmname7 = "SiPM_negative_s7_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet7(sd, sipmname7, detid);
+                    sipmdet7.setPlacement(plv_sipm7);
+
+                    dd4hep::PlacedVolume plv_sipm0 = hardware_s1.placeVolume(sipm_s0, Position(0, -length_crystal_z/2+photoelectronic/2, -photoelectronic_width/2));
+                    std::string sipmname0 = "SiPM_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet0(sd, sipmname0, detid);
+                    sipmdet0.setPlacement(plv_sipm0);
+
+                    dd4hep::PlacedVolume plv_sipm1 = hardware_s1.placeVolume(sipm_s0, Position(0, length_crystal_z/2-photoelectronic/2, photoelectronic_width/2));
+                    std::string sipmname1 = "SiPM_negative_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet1(sd, sipmname1, detid);
+                    sipmdet1.setPlacement(plv_sipm1);
+
+                    dd4hep::PlacedVolume plv_sipm2 = hardware_s1.placeVolume(sipm_s0, Position(0, -length_crystal_z/2+photoelectronic/2, photoelectronic_width/2));
+                    std::string sipmname2 = "SiPM_negative_s2_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet2(sd, sipmname2, detid);
+                    sipmdet2.setPlacement(plv_sipm2);
+
+                    dd4hep::PlacedVolume plv_sipm3 = hardware_s1.placeVolume(sipm_s0, Position(0, length_crystal_z/2-photoelectronic/2, -photoelectronic_width/2));
+                    std::string sipmname3 = "SiPM_negative_s3_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet3(sd, sipmname3, detid);
+                    sipmdet3.setPlacement(plv_sipm3);
+
+                    dd4hep::PlacedVolume plv_cry0 = carbonbox_s1.placeVolume(crystal_s1, Position(0, 0, 0));
+                    std::string cryname0 = "Crystal_negative_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement crydet0(sd, cryname0, detid);
+                    crydet0.setPlacement(plv_cry0);
+
+                    dd4hep::PlacedVolume plv_cfb0 = hardware_s1.placeVolume(carbonbox_s1, Position(0, 0, 0));
+                    std::string cfbname0 = "cfbstal_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement cfbdet0(sd, cfbname0, detid);
+                    cfbdet0.setPlacement(plv_cfb0); 
+
+                    dd4hep::PlacedVolume plv_hard0;
+                    if(ibar0==0){
+                        plv_hard0 = block.placeVolume(hardware_s1, Position(length_nega - 0.5*last_bar, 0, 0));
+                    } 
+                    else{
+                        plv_hard0 = block.placeVolume(hardware_s1, Position(-length_nega + 0.5*last_bar, 0, 0));
+                    }
+                    plv_hard0.addPhysVolID("slayer",1).addPhysVolID("bar",ibar0);
+                    std::string hardname0 = "Hardware_negative_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement harddet0(sd, hardname0, detid);
+                    harddet0.setPlacement(plv_hard0);
+                }
+                else{
+                    
+                    dd4hep::Volume hardware_s0("hardware_s0", dd4hep::Box(width_crystal/2, length_crystal_z/2, size_crystal/2), air); 
+                    hardware_s0.setVisAttributes(theDetector, "SeeThrough");
+
+                    dd4hep::Volume carbonbox_s0("carbonbox_s0", dd4hep::Box(width_crystal/2, length_crystal_z/2-photoelectronic, size_crystal/2), mat_CF);
+                    carbonbox_s0.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::Volume crystal_s0("crystal_s0", dd4hep::Box(width_crystal/2-crystal_supportting, length_crystal_z/2-photoelectronic-crystal_supportting, size_crystal/2-crystal_supportting), mat_ESR); 
+                    crystal_s0.setVisAttributes(theDetector, "CyanVis");
+
+                    dd4hep::PlacedVolume plv_bar0 = crystal_s0.placeVolume(bar_s0, Position(0, 0, 0));
+                    std::string barname0 = "CrystalBar_negative_s1_"+std::to_string(ibar0);	
+                    dd4hep::DetElement bardet0(sd, barname0, detid);
+                    bardet0.setPlacement(plv_bar0);
+
+                    // dd4hep::PlacedVolume plv_sipm8 = carbonbox_s0.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+photoelectronic/2, -photoelectronic_width/2));
+                    // std::string sipmname8 = "SiPM_negative_s8_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet8(sd, sipmname8, detid);
+                    // sipmdet8.setPlacement(plv_sipm8);
+
+                    // dd4hep::PlacedVolume plv_sipm9 = carbonbox_s0.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-photoelectronic/2, photoelectronic_width/2));
+                    // std::string sipmname9 = "SiPM_negative_s9_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet9(sd, sipmname9, detid);
+                    // sipmdet9.setPlacement(plv_sipm9);
+
+                    // dd4hep::PlacedVolume plv_sipm10 = carbonbox_s0.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+photoelectronic/2, photoelectronic_width/2));
+                    // std::string sipmname10 = "SiPM_negative_s10_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet10(sd, sipmname10, detid);
+                    // sipmdet10.setPlacement(plv_sipm10);
+
+                    // dd4hep::PlacedVolume plv_sipm11 = carbonbox_s0.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-photoelectronic/2, -photoelectronic_width/2));
+                    // std::string sipmname11 = "SiPM_negative_s11_"+std::to_string(ibar0);
+                    // dd4hep::DetElement sipmdet11(sd, sipmname11, detid);
+                    // sipmdet11.setPlacement(plv_sipm11);
+
+                    dd4hep::PlacedVolume plv_sipm4 = crystal_s0.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+crystal_wrapping/2, -photoelectronic_width/2));
+                    std::string sipmname4 = "SiPM_negative_s4_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet4(sd, sipmname4, detid);
+                    sipmdet4.setPlacement(plv_sipm4);
+
+                    dd4hep::PlacedVolume plv_sipm5 = crystal_s0.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-crystal_wrapping/2, photoelectronic_width/2));
+                    std::string sipmname5 = "SiPM_negative_s5_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet5(sd, sipmname5, detid);
+                    sipmdet5.setPlacement(plv_sipm5);
+
+                    dd4hep::PlacedVolume plv_sipm6 = crystal_s0.placeVolume(sipm_s1, Position(0, -length_crystal_z/2+photoelectronic+crystal_supportting+crystal_wrapping/2, photoelectronic_width/2));
+                    std::string sipmname6 = "SiPM_negative_s6_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet6(sd, sipmname6, detid);
+                    sipmdet6.setPlacement(plv_sipm6);
+
+                    dd4hep::PlacedVolume plv_sipm7 = crystal_s0.placeVolume(sipm_s1, Position(0, length_crystal_z/2-photoelectronic-crystal_supportting-crystal_wrapping/2, -photoelectronic_width/2));
+                    std::string sipmname7 = "SiPM_negative_s7_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet7(sd, sipmname7, detid);
+                    sipmdet7.setPlacement(plv_sipm7);
+
+                    dd4hep::PlacedVolume plv_sipm0 = hardware_s0.placeVolume(sipm_s0, Position(0, -length_crystal_z/2+photoelectronic/2, -photoelectronic_width/2));
+                    std::string sipmname0 = "SiPM_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet0(sd, sipmname0, detid);
+                    sipmdet0.setPlacement(plv_sipm0);
+
+                    dd4hep::PlacedVolume plv_sipm1 = hardware_s0.placeVolume(sipm_s0, Position(0, length_crystal_z/2-photoelectronic/2, photoelectronic_width/2));
+                    std::string sipmname1 = "SiPM_negative_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet1(sd, sipmname1, detid);
+                    sipmdet1.setPlacement(plv_sipm1);
+
+                    dd4hep::PlacedVolume plv_sipm2 = hardware_s0.placeVolume(sipm_s0, Position(0, -length_crystal_z/2+photoelectronic/2, photoelectronic_width/2));
+                    std::string sipmname2 = "SiPM_negative_s2_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet2(sd, sipmname2, detid);
+                    sipmdet2.setPlacement(plv_sipm2);
+
+                    dd4hep::PlacedVolume plv_sipm3 = hardware_s0.placeVolume(sipm_s0, Position(0, length_crystal_z/2-photoelectronic/2, -photoelectronic_width/2));
+                    std::string sipmname3 = "SiPM_negative_s3_"+std::to_string(ibar0);
+                    dd4hep::DetElement sipmdet3(sd, sipmname3, detid);
+                    sipmdet3.setPlacement(plv_sipm3);
+
+                    dd4hep::PlacedVolume plv_cry0 = carbonbox_s0.placeVolume(crystal_s0, Position(0, 0, 0));
+                    std::string cryname0 = "Crystal_negative_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement crydet0(sd, cryname0, detid);
+                    crydet0.setPlacement(plv_cry0);
+
+                    dd4hep::PlacedVolume plv_cfb0 = hardware_s0.placeVolume(carbonbox_s0, Position(0, 0, 0));
+                    std::string cfbname0 = "cfbstal_negative_s0_"+std::to_string(ibar0);
+                    dd4hep::DetElement cfbdet0(sd, cfbname0, detid);
+                    cfbdet0.setPlacement(plv_cfb0);
+
+
+                    dd4hep::PlacedVolume plv_hard0 = block.placeVolume(hardware_s0, Position(length_nega - last_bar - (ibar0-1)*width_crystal - width_crystal/2, 0, 0));
+                    plv_hard0.addPhysVolID("slayer",1).addPhysVolID("bar",ibar0);
+                    std::string hardname0 = "Hardware_negative_s1_"+std::to_string(ibar0);
+                    dd4hep::DetElement harddet0(sd, hardname0, detid);
+                    harddet0.setPlacement(plv_hard0);
+                }
+            }
+        }
+
+        dd4hep::PlacedVolume plv = subtrap_negative_vol.placeVolume(block, Position(0, 0, 0.5*size_crystal+ilayer*size_crystal-dim_z_n));
+        plv.addPhysVolID("dlayer", floor(ilayer/2+1));
+        // cout<<"*****layer: "<<floor(ilayer/2+1)<<endl;
+        sd.setPlacement(plv); 
+    }
+
+    cout<<"positive volume "<< positive_volume<<endl;
+    cout<<"negative volume "<< negative_volume<<endl;
+
+    // ###########################
+    // ### Z modules placement ###
+    // ###########################
+
+    for(int iz=0; iz<Nblock_z_display; iz=iz+1){  //1 Nblock_z
+        dd4hep::PlacedVolume plv = trap_positive_vol.placeVolume(subtrap_positive_vol, Position(0, 0.5*length_z-(2*iz+1)*pZ/2,0) );
+        plv.addPhysVolID("stave", iz);
+        DetElement sd(stavedet, _toString(iz,"stave_posi_%3d"), detid);
+        sd.setPlacement(plv);    
+    }
+
+    for(int iz=0; iz<Nblock_z_display; iz=iz+1){
+        dd4hep::PlacedVolume plv = trap_negative_vol.placeVolume(subtrap_negative_vol, Position(0, 0.5*length_z-(2*iz+1)*pZ/2,0) );
+        plv.addPhysVolID("stave", iz);
+        DetElement sd(stavedet, _toString(iz,"stave_nega_%3d"), detid);
+        sd.setPlacement(plv);    
+    }  
+
+    // #############################
+    // ### phi modules placement ###
+    // #############################
+
+    double r0 = radius_inner + height_layer1 + depth_longitudinal_p/2;  //Phi-module rotation
+    double r1 = radius_inner + depth_longitudinal_n/2; 
+
+    for(int i=0;i<n_module_display;i=i+2){ //n_module
+        double m_rot = angle*i;
+        double posx = -r0*sin(m_rot);
+        double posy = r0*cos(m_rot);
+        dd4hep::Transform3D transform(dd4hep::RotationZ(m_rot)*dd4hep::RotationX(-90*degree),  dd4hep::Position(posx, posy, 0.)); 
+        dd4hep::PlacedVolume plv = envelopeVol.placeVolume(trap_positive_vol, transform);
+        plv.addPhysVolID("module", i);
+        DetElement sd(ECAL, _toString(i,"trap_posi_%3d"), detid);
+        sd.setPlacement(plv);
+    }
+
+    for(int i=1;i<n_module_display;i=i+2){
+        double m_rot = angle*i;
+        double posx = -r1*sin(m_rot);
+        double posy = r1*cos(m_rot);
+        dd4hep::Transform3D transform(dd4hep::RotationZ(m_rot)*dd4hep::RotationX(-90*degree),  dd4hep::Position(posx, posy, 0.)); 
+        dd4hep::PlacedVolume plv = envelopeVol.placeVolume(trap_negative_vol, transform);
+        plv.addPhysVolID("module", i);
+        DetElement sd(ECAL, _toString(i,"trap_nega_%3d"), detid);
+        sd.setPlacement(plv);
+    }
+
+    sens.setType("calorimeter");
+
+    MYDEBUG("create_detector DONE. ");
+    return ECAL;
+} 
+
+DECLARE_DETELEMENT(LongCrystalBarBarrelCalorimeter32Polygon_v02, create_detector)
diff --git a/Detector/DetCRD/src/Calorimeter/LongCrystalBarEndcapCalorimeter_v04.cpp b/Detector/DetCRD/src/Calorimeter/LongCrystalBarEndcapCalorimeter_v04.cpp
new file mode 100755
index 0000000000000000000000000000000000000000..dadb7cfbad30910f1a714b1f1da4ce53d5641cb5
--- /dev/null
+++ b/Detector/DetCRD/src/Calorimeter/LongCrystalBarEndcapCalorimeter_v04.cpp
@@ -0,0 +1,855 @@
+#include "DD4hep/DetFactoryHelper.h"
+#include "DD4hep/DetType.h"
+#include "XML/Layering.h"
+#include "XML/Utilities.h"
+#include "DDRec/DetectorData.h"
+#include "DDSegmentation/BitField64.h"
+#include "DDSegmentation/Segmentation.h"
+#include "DDSegmentation/MultiSegmentation.h"
+#include "DetIdentifier/CEPCDetectorData.h"
+// #include "LcgeoExceptions.h"
+
+using namespace std;
+
+using dd4hep::BUILD_ENVELOPE;
+using dd4hep::BitField64;
+using dd4hep::Box;
+using dd4hep::Trapezoid;
+using dd4hep::Trap;
+using dd4hep::EightPointSolid;
+using dd4hep::DetElement;
+using dd4hep::DetType;
+using dd4hep::Detector;
+using dd4hep::Layering;
+using dd4hep::Material;
+using dd4hep::PlacedVolume;
+using dd4hep::Position;
+using dd4hep::Readout;
+using dd4hep::Ref_t;
+using dd4hep::RotationX;
+using dd4hep::RotationY;
+using dd4hep::RotationZ;
+using dd4hep::RotationZYX;
+using dd4hep::Segmentation;
+using dd4hep::SensitiveDetector;
+using dd4hep::Transform3D;
+using dd4hep::Translation3D;
+using dd4hep::Volume;
+using dd4hep::_toString;
+
+using dd4hep::rec::LayeredCalorimeterData;
+
+static Ref_t create_detector(Detector& theDetector, xml_h element, SensitiveDetector sens)  {
+  xml_det_t   x_det     = element;
+  Layering    layering(x_det);
+//   xml_dim_t   dim         = x_det.dimensions();
+  string      det_name    = x_det.nameStr();
+
+//   Material    air         = theDetector.air();
+  Material    stavesMaterial    = theDetector.material(x_det.materialStr());
+//   int         numSides    = dim.numsides();
+
+  int           det_id    = x_det.id();
+
+  DetElement   sdet(det_name,det_id);
+
+  PlacedVolume pVol;
+
+  // --- create an envelope volume and position it into the world ---------------------
+
+  Volume envelope = dd4hep::xml::createPlacedEnvelope( theDetector,  element , sdet ) ;
+  // envelopePlv.addPhysVolID("system",x_det.id());
+//   sdet.setTypeFlag( DetType::CALORIMETER |  DetType::ENDCAP  | DetType::HADRONIC ) ;
+
+//   if( theDetector.buildType() == BUILD_ENVELOPE ) return sdet ;
+  //-----------------------------------------------------------------------------------
+  
+  sens.setType("calorimeter");
+
+  dd4hep::rec::ECALSystemInfoData* ecalSystemInfoData = new dd4hep::rec::ECALSystemInfoData;
+  ecalSystemInfoData->systemNumber = det_id;
+
+  DetElement    stave_det("module0stave0part0",det_id);
+
+  double      EcalEndcap_inner_radius          = theDetector.constant<double>("Ecal_endcap_inner_radius");
+  double      EcalEndcap_outer_radius          = theDetector.constant<double>("Ecal_endcap_outer_radius");
+  double      EcalEndcap_min_z                 = theDetector.constant<double>("Ecal_endcap_zmin");
+  double      EcalEndcap_max_z                 = theDetector.constant<double>("Ecal_endcap_zmax");
+
+  double      EcalEndcap_carbonfiber_thickness    = theDetector.constant<double>("Ecal_endcap_carbonfiber_thickness");
+  double      EcalEndcap_cu_thickness             = theDetector.constant<double>("Ecal_endcap_cu_thickness");
+  double      EcalEndcap_electronics_thickness    = theDetector.constant<double>("Ecal_endcap_electronics_thickness");
+  double      EcalEndcap_sipm_thickness           = theDetector.constant<double>("Ecal_endcap_sipm_thickness");
+  double      EcalEndcap_sipm_width               = theDetector.constant<double>("Ecal_endcap_sipm_width");
+  double      EcalEndcap_esr_thickness            = theDetector.constant<double>("Ecal_endcap_esr_thickness");
+
+  dd4hep::Material mat_BGO(theDetector.material("G4_BGO")); 
+  dd4hep::Material mat_CF(theDetector.material("CarbonFiber"));
+  dd4hep::Material mat_Cu(theDetector.material("G4_Cu"));
+  dd4hep::Material mat_ESR(theDetector.material("G4_ESR"));
+  dd4hep::Material mat_Si(theDetector.material("G4_Si"));
+  dd4hep::Material mat_PCB(theDetector.material("PCB"));
+  dd4hep::Material mat_Air(theDetector.material("Air"));
+
+  int endcapID = 0;
+
+  double dim_x = 0.001;
+  double dim_x1 = 0.001;
+  double dim_x2 = 0.001;
+  double dim_y = 0.001;
+  double dim_y1 = 0.001;
+  double dim_y2 = 0.001;
+  double dim_z = 0.001;
+  double box_half_x= 0.001;
+  double box_half_y= 0.001;
+  double box_half_z= 0.001;
+  double trap_half_x1= 0.001;
+  double trap_half_x2= 0.001;
+  double trap_half_y1= 0.001;
+  double trap_half_y2= 0.001;
+  double trap_half_z= 0.001;
+  
+  double pos_x = 0;
+  double pos_y = 0;
+  double pos_z = 0;
+  double EndcapModule_center_pos_x = 0;
+  double EndcapModule_center_pos_y = 0;
+  double EndcapModule_center_pos_z = 0;
+
+  int all_module0 = 0;
+  int all_module1 = 0;
+  int all_module2 = 0;
+  int all_module3 = 0;
+
+  for(xml_coll_t c(x_det.child(_U(dimensions)),_U(dimensions)); c; ++c) {
+    xml_comp_t l(c);
+    int N_bar = 0;
+    double volume_bar = 0;
+
+    int module_type = l.attr<int>(_Unicode(module_type));
+    int module_tag = l.attr<int>(_Unicode(id));
+    int module_number = l.attr<int>(_Unicode(module_number));
+    
+    if(module_type == 0 || module_type == 20){
+      dim_x = l.attr<double>(_Unicode(dim_x));
+      dim_y = l.attr<double>(_Unicode(dim_y));
+      dim_z = l.attr<double>(_Unicode(dim_z));
+      pos_x = l.attr<double>(_Unicode(x_offset));
+      pos_y = l.attr<double>(_Unicode(y_offset));
+      pos_z = l.attr<double>(_Unicode(z_offset));
+      box_half_x = dim_x/2.0; 
+      box_half_y = dim_y/2.0; 
+      box_half_z = dim_z/2.0; 
+    }
+    else if(module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22){
+      dim_x1 = l.attr<double>(_Unicode(dim_x1));
+      dim_x2 = l.attr<double>(_Unicode(dim_x2));
+      dim_y1 = l.attr<double>(_Unicode(dim_y1));
+      dim_y2 = l.attr<double>(_Unicode(dim_y2));
+      dim_z = l.attr<double>(_Unicode(dim_z));
+      pos_x = l.attr<double>(_Unicode(x_offset));
+      pos_y = l.attr<double>(_Unicode(y_offset));
+      pos_z = l.attr<double>(_Unicode(z_offset));
+      trap_half_x1 = dim_x1/2;
+      trap_half_x2 = dim_x2/2;
+      trap_half_y1 = dim_y1/2;
+      trap_half_y2 = dim_y2/2;
+      trap_half_z = dim_z/2; 
+    }
+    else if(module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6
+            || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10){
+      dim_x1 = l.attr<double>(_Unicode(dim_x1));
+      dim_x2 = l.attr<double>(_Unicode(dim_x2));
+      dim_x = l.attr<double>(_Unicode(dim_y1));
+      dim_y = l.attr<double>(_Unicode(dim_y1));
+      dim_y1 = l.attr<double>(_Unicode(dim_y1));
+      dim_y2 = l.attr<double>(_Unicode(dim_y2));
+      dim_z = l.attr<double>(_Unicode(dim_z));
+      pos_x = l.attr<double>(_Unicode(x_offset));
+      pos_y = l.attr<double>(_Unicode(y_offset));
+      pos_z = l.attr<double>(_Unicode(z_offset));
+      trap_half_x1 = dim_x1;
+      trap_half_x2 = dim_x2;
+      trap_half_y1 = dim_y1;
+      trap_half_y2 = dim_y2;
+      trap_half_z = dim_z;
+    }
+    else {
+      dim_x = l.attr<double>(_Unicode(dim_x));
+      dim_y = l.attr<double>(_Unicode(dim_y));
+      dim_z = l.attr<double>(_Unicode(dim_z));
+      pos_x = l.attr<double>(_Unicode(x_offset));
+      pos_y = l.attr<double>(_Unicode(y_offset));
+      pos_z = l.attr<double>(_Unicode(z_offset));
+    }
+
+
+    std::cout << "module_type: " << module_type << std::endl;
+    std::cout << "module_number: " << module_number << std::endl;
+    std::cout << "dim_x: " << dim_x << std::endl;
+    std::cout << "dim_x1: " << dim_x1 << std::endl;
+    std::cout << "dim_x2: " << dim_x2 << std::endl;
+    std::cout << "dim_y: " << dim_y << std::endl;
+    std::cout << "dim_y1: " << dim_y1 << std::endl;
+    std::cout << "dim_y2: " << dim_y2 << std::endl;
+    std::cout << "dim_z: " << dim_z << std::endl;
+    std::cout << "pos_x: " << pos_x << std::endl;
+    std::cout << "pos_y: " << pos_y << std::endl;
+    std::cout << "pos_z: " << pos_z << std::endl;
+
+
+    Box EndcapModule(box_half_x,box_half_y,box_half_z);
+    Trapezoid EndcapTrapIso(trap_half_x1, trap_half_x2, trap_half_y1, trap_half_y2, trap_half_z);
+    Trap EndcapTrapRight(trap_half_y1, trap_half_z, trap_half_x1, trap_half_x2);
+    double vertices[] = {-dim_x, -dim_x, -dim_x, dim_y, dim_y, dim_y, dim_y, -dim_x, -dim_x, -dim_x, -dim_x, dim_x, dim_x, dim_x, dim_x, -dim_x};
+    EightPointSolid EndcapPrism(dim_z/2,  vertices);
+
+    string envelopeVol_name   = det_name+_toString(endcapID,"_EndcapModule%d");
+    string envelopeVolTrapIso_name   = det_name+_toString(endcapID,"_EndcapModule%d");
+    string envelopeVolTrapRight_name   = det_name+_toString(endcapID,"_EndcapModule%d");
+    string envelopeVolPrism_name   = det_name+_toString(endcapID,"_EndcapModule%d");
+
+    Volume envelopeVol(envelopeVol_name,EndcapModule,stavesMaterial);
+    Volume envelopeVolTrapIso(envelopeVolTrapIso_name,EndcapTrapIso,stavesMaterial);
+    Volume envelopeVolTrapRight(envelopeVolTrapRight_name,EndcapTrapRight,stavesMaterial);
+    Volume envelopeVolPrism(envelopeVolPrism_name,EndcapPrism,stavesMaterial);
+
+    envelopeVol.setAttributes(theDetector,x_det.regionStr(),x_det.limitsStr(), "SeeThrough");
+    envelopeVolTrapIso.setAttributes(theDetector,x_det.regionStr(),x_det.limitsStr(), "SeeThrough");
+    envelopeVolTrapRight.setAttributes(theDetector,x_det.regionStr(),x_det.limitsStr(), "SeeThrough");
+    envelopeVolPrism.setAttributes(theDetector,x_det.regionStr(),x_det.limitsStr(), "SeeThrough");
+    
+    double layer_pos_z = -dim_z/2;
+    int layer_num = 1;
+    std::vector<dd4hep::rec::ECALModuleInfoData::LayerInfo> layerInfos;
+    layerInfos.clear();
+
+    for(xml_coll_t m(x_det,_U(layer)); m; ++m){  // loop over layers
+      xml_comp_t x_layer = m;
+	    int repeat = x_layer.repeat();
+      double layer_thickness = x_layer.thickness();
+      string layer_name = (module_type == 0 || module_type == 20) ? envelopeVol_name+_toString(0,"_Layer%d") : (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? envelopeVolTrapIso_name+_toString(1,"_Layer%d") 
+        : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? envelopeVolTrapRight_name+_toString(2,"_Layer%d") 
+        : envelopeVolPrism_name+_toString(3,"_Layer%d");
+      DetElement  layer(stave_det, layer_name, det_id);
+      Material layer_material  = theDetector.material(x_layer.materialStr());
+      string hardware_name = layer_name + "_hardware";
+
+      if(module_type == 0 || module_type == 20){ // for cube first place bar then place layer
+        double rot_layer = 0;
+        double active_layer_dim_x = box_half_x - EcalEndcap_carbonfiber_thickness;
+        double active_layer_dim_y = box_half_y - EcalEndcap_carbonfiber_thickness;
+        double active_layer_dim_z = layer_thickness/2.0;
+        
+        Volume layer_vol(layer_name, Box(active_layer_dim_x, active_layer_dim_y, active_layer_dim_z), mat_Air);
+        
+        Volume hardware_vol(hardware_name, Box(active_layer_dim_x, layer_thickness / 2.0, layer_thickness/2.0), mat_Air);
+        Volume esr_vol(hardware_name + "_ESR", Box(active_layer_dim_x - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness, layer_thickness / 2.0, layer_thickness/2.0), mat_ESR);
+        Volume crystal_vol(hardware_name + "_BGO", Box(active_layer_dim_x - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness - EcalEndcap_esr_thickness, layer_thickness / 2.0 - EcalEndcap_esr_thickness, layer_thickness/2.0 - EcalEndcap_esr_thickness), mat_BGO);
+        Volume sipm_vol(hardware_name + "_Sipm", Box(EcalEndcap_sipm_thickness / 2.0, EcalEndcap_sipm_width / 2.0, EcalEndcap_sipm_width / 2.0), mat_Si);
+        Volume electronics_vol(hardware_name + "_Electronics", Box(EcalEndcap_electronics_thickness / 2.0, layer_thickness / 2.0, layer_thickness/2.0), mat_PCB);
+        Volume cooling_vol(hardware_name + "_Cooling", Box(EcalEndcap_cu_thickness / 2.0, layer_thickness / 2.0, layer_thickness/2.0), mat_Cu);
+
+        crystal_vol.setSensitiveDetector(sens);
+
+        layer_vol.setVisAttributes(theDetector, "SeeThrough");
+        hardware_vol.setVisAttributes(theDetector, "SeeThrough");
+        esr_vol.setVisAttributes(theDetector, "CyanVis");
+        crystal_vol.setVisAttributes(theDetector, "EcalBarrelVis");
+        sipm_vol.setVisAttributes(theDetector, "BlueVis");
+        electronics_vol.setVisAttributes(theDetector, "RedVis");
+        cooling_vol.setVisAttributes(theDetector, "GreenVis");
+
+        PlacedVolume esr_phv = hardware_vol.placeVolume(esr_vol,Position(0, 0, 0));
+        PlacedVolume crystal_phv = esr_vol.placeVolume(crystal_vol,Position(0, 0, 0));
+        PlacedVolume sipm_phv_left = hardware_vol.placeVolume(sipm_vol,Position(active_layer_dim_x - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness / 2.0, 0, 0));
+        PlacedVolume sipm_phv_right = hardware_vol.placeVolume(sipm_vol,Position(-active_layer_dim_x + EcalEndcap_cu_thickness + EcalEndcap_electronics_thickness + EcalEndcap_sipm_thickness / 2.0, 0, 0));
+        PlacedVolume electronics_phv_left = hardware_vol.placeVolume(electronics_vol,Position(active_layer_dim_x - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness / 2.0, 0, 0)); 
+        PlacedVolume electronics_phv_right = hardware_vol.placeVolume(electronics_vol,Position(-active_layer_dim_x + EcalEndcap_cu_thickness + EcalEndcap_electronics_thickness / 2.0, 0, 0));
+        PlacedVolume cooling_phv_left = hardware_vol.placeVolume(cooling_vol,Position(active_layer_dim_x - EcalEndcap_cu_thickness / 2.0, 0, 0));
+        PlacedVolume cooling_phv_right = hardware_vol.placeVolume(cooling_vol,Position(-active_layer_dim_x + EcalEndcap_cu_thickness / 2.0, 0, 0));
+      
+        for (int ihardware = 0; ihardware < int(active_layer_dim_y*2/layer_thickness); ihardware++){
+          DetElement hardware(layer, _toString(ihardware,"hardware%d"), det_id);
+          PlacedVolume hardware_phv = layer_vol.placeVolume(hardware_vol,Position(0, -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware, 0));
+          hardware_phv.addPhysVolID("bar", ihardware);
+          hardware.setPlacement(hardware_phv);
+        }
+
+        // layer_vol.setAttributes(theDetector,x_layer.regionStr(),x_layer.limitsStr(),x_layer.visStr());
+        layer_pos_z += layer_thickness / 2.0;
+      
+        for (int j = 0; j < repeat; j++){
+          if(module_type == 0) rot_layer = (j%2==0)? -M_PI/2 : M_PI;
+          else rot_layer = (j%2==0)? -M_PI/2 : 0;
+          PlacedVolume layer_phv = envelopeVol.placeVolume(layer_vol, Transform3D(RotationZYX(rot_layer, 0, 0), Position(0,0,layer_pos_z)));
+
+          dd4hep::rec::ECALModuleInfoData::LayerInfo layerInfo;
+          if(j%2==0){
+            layerInfo.dlayerNumber = layer_num;
+            layerInfo.slayerNumber = 0;
+            layerInfo.barNumber = int(active_layer_dim_y*2/layer_thickness);
+            layer_phv.addPhysVolID("slayer", 0).addPhysVolID("dlayer", layer_num);
+          } 
+          else{
+            layerInfo.dlayerNumber = layer_num;
+            layerInfo.slayerNumber = 1;
+            layerInfo.barNumber = int(active_layer_dim_y*2/layer_thickness);
+            layer_phv.addPhysVolID("slayer", 1).addPhysVolID("dlayer", layer_num);
+            ++layer_num;
+          }
+
+          layer.setPlacement(layer_phv); 
+          layer_pos_z += layer_thickness; 
+          layerInfos.push_back(layerInfo);
+        }
+
+        N_bar = N_bar + int(active_layer_dim_y*2/layer_thickness)*repeat;
+        volume_bar = volume_bar + active_layer_dim_x*2*2*active_layer_dim_y*layer_thickness*repeat;
+      }
+      else{ //for trap first place layer then place bar
+        layer_pos_z += layer_thickness / 2.0;
+        double rot_layer = 0;
+        double delta_layer = 0;
+        for (int j = 0; j < repeat; j++){
+          
+          delta_layer = (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? layer_thickness*(trap_half_x1 - trap_half_x2)/dim_z 
+            : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? layer_thickness*(dim_x2 - dim_x1)/dim_z 
+            : layer_thickness*(dim_x-dim_y)/dim_z;
+
+          double active_layer_dim_x = (module_type == 1  || module_type == 2 || module_type == 21 || module_type == 22) ? trap_half_y1 - EcalEndcap_carbonfiber_thickness 
+            : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? trap_half_x1/2 - EcalEndcap_carbonfiber_thickness + j*delta_layer/2
+            : (dim_x + dim_y)/2 - EcalEndcap_carbonfiber_thickness + j*delta_layer/2; 
+          double active_layer_dim_y = (module_type == 1  || module_type == 2 || module_type == 21 || module_type == 22) ? trap_half_x1 - EcalEndcap_carbonfiber_thickness - j*delta_layer 
+            : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? layer_thickness/2.0 
+            : (dim_x + dim_y)/2 - EcalEndcap_carbonfiber_thickness + j*delta_layer/2; 
+          double active_layer_dim_z = (module_type == 1  || module_type == 2 || module_type == 21 || module_type == 22) ? layer_thickness/2.0 
+            : (module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6 || module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10) ? trap_half_y1/2 - EcalEndcap_carbonfiber_thickness
+            : layer_thickness/2.0;
+          
+          Volume layer_vol(layer_name, Box(active_layer_dim_x, active_layer_dim_y, active_layer_dim_z), mat_Air);
+          int hardware_num = 0;
+          
+          double hardware_x = 0;
+          double hardware_y = 0;
+          double hardware_z = 0;
+          double hardware_x_pos = 0;
+          double hardware_y_pos = 0;
+          double hardware_z_pos = 0;
+
+          if(module_type == 1 || module_type == 21){
+            hardware_num = (j%2==0) ? int(active_layer_dim_x*2/layer_thickness) : int(active_layer_dim_y*2/layer_thickness);
+          }
+          else if(module_type == 2 || module_type == 22){
+            hardware_num = (j%2==0) ? int(active_layer_dim_y*2/layer_thickness) : int(active_layer_dim_x*2/layer_thickness);
+          }
+          else if(module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6){
+            hardware_num = (j%2==0) ? int(active_layer_dim_z*2/layer_thickness) : int(active_layer_dim_x*2/layer_thickness);
+          }
+          else if(module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10){
+            hardware_num = (j%2==0) ? int(active_layer_dim_x*2/layer_thickness) : int(active_layer_dim_z*2/layer_thickness);
+          }
+          else {
+            hardware_num = (j%2==0) ? int(active_layer_dim_x*2/layer_thickness) : int(active_layer_dim_y*2/layer_thickness);
+          }
+          
+          if(module_type == 1 || module_type == 21){
+            hardware_x = (j%2==0) ? layer_thickness / 2.0 : active_layer_dim_x;
+            hardware_y = (j%2==0) ? active_layer_dim_y : layer_thickness / 2.0;
+            hardware_z = layer_thickness/2.0;
+          }
+          else if(module_type == 2  || module_type == 22){
+            hardware_x = (j%2==0) ? active_layer_dim_x : layer_thickness / 2.0;
+            hardware_y = (j%2==0) ? layer_thickness / 2.0 : active_layer_dim_y;
+            hardware_z = layer_thickness/2.0;
+          }
+          else if(module_type == 3 || module_type == 4 || module_type == 5 || module_type == 6){
+            hardware_x = (j%2==0) ? active_layer_dim_x : layer_thickness / 2.0;
+            hardware_y = layer_thickness / 2.0;
+            hardware_z = (j%2==0) ? layer_thickness / 2.0 : active_layer_dim_z;
+          }
+          else if(module_type == 7 || module_type == 8 || module_type == 9 || module_type == 10){
+            hardware_x = (j%2==0) ? layer_thickness / 2.0 : active_layer_dim_x;
+            hardware_y = layer_thickness / 2.0;
+            hardware_z = (j%2==0) ? active_layer_dim_z : layer_thickness / 2.0;
+          }
+          else if(module_type == 11 || module_type == 13 || module_type == 15 || module_type == 17){ 
+            hardware_x = (j%2==1) ? layer_thickness / 2.0 : active_layer_dim_x;
+            hardware_y = (j%2==1) ? active_layer_dim_y : layer_thickness / 2.0;
+            hardware_z = layer_thickness / 2.0;
+          }
+          else if(module_type == 12 || module_type == 14 || module_type == 16 || module_type == 18){
+            hardware_x = (j%2==1) ? active_layer_dim_x : layer_thickness / 2.0;
+            hardware_y = (j%2==1) ? layer_thickness / 2.0 : active_layer_dim_y;
+            hardware_z = layer_thickness / 2.0;
+          }
+          
+          string   hardware_name      = layer_name + _toString(j,"_hardware%d");
+          Volume hardware_vol(hardware_name, Box(hardware_x, hardware_y, hardware_z), mat_Air);
+          
+          int index = 0;
+          if(hardware_x != layer_thickness / 2.0) index = 1;
+          else if(hardware_y != layer_thickness / 2.0) index = 2;
+          else index = 3;
+
+
+
+          if(index == 1){
+            Volume esr_vol(hardware_name + "_ESR", Box(hardware_x - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness, layer_thickness / 2.0, layer_thickness/2.0), mat_ESR);
+            Volume crystal_vol(hardware_name + "_BGO", Box(hardware_x - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness - EcalEndcap_esr_thickness, layer_thickness / 2.0 - EcalEndcap_esr_thickness, layer_thickness/2.0 - EcalEndcap_esr_thickness), mat_BGO);
+            Volume sipm_vol(hardware_name + "_Sipm", Box(EcalEndcap_sipm_thickness / 2.0, EcalEndcap_sipm_width / 2.0, EcalEndcap_sipm_width / 2.0), mat_Si);
+            Volume electronics_vol(hardware_name + "_Electronics", Box(EcalEndcap_electronics_thickness / 2.0, layer_thickness / 2.0, layer_thickness/2.0), mat_PCB);
+            Volume cooling_vol(hardware_name + "_Cooling", Box(EcalEndcap_cu_thickness / 2.0, layer_thickness / 2.0, layer_thickness/2.0), mat_Cu);
+            crystal_vol.setSensitiveDetector(sens);
+            PlacedVolume esr_phv = hardware_vol.placeVolume(esr_vol,Position(0, 0, 0));
+            PlacedVolume crystal_phv = esr_vol.placeVolume(crystal_vol,Position(0, 0, 0));
+            PlacedVolume sipm_phv_left = hardware_vol.placeVolume(sipm_vol,Position(hardware_x - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness / 2.0, 0, 0));
+            PlacedVolume sipm_phv_right = hardware_vol.placeVolume(sipm_vol,Position(-hardware_x + EcalEndcap_cu_thickness + EcalEndcap_electronics_thickness + EcalEndcap_sipm_thickness / 2.0, 0, 0));
+            PlacedVolume electronics_phv_left = hardware_vol.placeVolume(electronics_vol,Position(hardware_x - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness / 2.0, 0, 0)); 
+            PlacedVolume electronics_phv_right = hardware_vol.placeVolume(electronics_vol,Position(-hardware_x + EcalEndcap_cu_thickness + EcalEndcap_electronics_thickness / 2.0, 0, 0));
+            PlacedVolume cooling_phv_left = hardware_vol.placeVolume(cooling_vol,Position(hardware_x - EcalEndcap_cu_thickness / 2.0, 0, 0));
+            PlacedVolume cooling_phv_right = hardware_vol.placeVolume(cooling_vol,Position(-hardware_x + EcalEndcap_cu_thickness / 2.0, 0, 0));  
+            layer_vol.setVisAttributes(theDetector, "SeeThrough");
+            hardware_vol.setVisAttributes(theDetector, "SeeThrough");
+            esr_vol.setVisAttributes(theDetector, "CyanVis");
+            crystal_vol.setVisAttributes(theDetector, "EcalBarrelVis");
+            sipm_vol.setVisAttributes(theDetector, "BlueVis");
+            electronics_vol.setVisAttributes(theDetector, "RedVis");
+            cooling_vol.setVisAttributes(theDetector, "GreenVis");          
+          }
+          else if (index == 2){
+            Volume esr_vol(hardware_name + "_ESR", Box(layer_thickness / 2.0, hardware_y - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness, layer_thickness/2.0), mat_ESR);
+            Volume crystal_vol(hardware_name + "_BGO", Box(layer_thickness / 2.0 - EcalEndcap_esr_thickness, hardware_y - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness - EcalEndcap_esr_thickness, layer_thickness/2.0 - EcalEndcap_esr_thickness), mat_BGO);
+            Volume sipm_vol(hardware_name + "_Sipm", Box(EcalEndcap_sipm_width / 2.0, EcalEndcap_sipm_thickness / 2.0, EcalEndcap_sipm_width / 2.0), mat_Si);
+            Volume electronics_vol(hardware_name + "_Electronics", Box(layer_thickness / 2.0, EcalEndcap_electronics_thickness / 2.0, layer_thickness/2.0), mat_PCB);
+            Volume cooling_vol(hardware_name + "_Cooling", Box(layer_thickness / 2.0, EcalEndcap_cu_thickness / 2.0, layer_thickness/2.0), mat_Cu);
+            crystal_vol.setSensitiveDetector(sens);
+            PlacedVolume esr_phv = hardware_vol.placeVolume(esr_vol,Position(0, 0, 0));
+            PlacedVolume crystal_phv = esr_vol.placeVolume(crystal_vol,Position(0, 0, 0));
+            PlacedVolume sipm_phv_left = hardware_vol.placeVolume(sipm_vol,Position(0, hardware_y - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness / 2.0, 0));
+            PlacedVolume sipm_phv_right = hardware_vol.placeVolume(sipm_vol,Position(0, -hardware_y + EcalEndcap_cu_thickness + EcalEndcap_electronics_thickness + EcalEndcap_sipm_thickness / 2.0, 0));
+            PlacedVolume electronics_phv_left = hardware_vol.placeVolume(electronics_vol,Position(0, hardware_y - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness / 2.0, 0)); 
+            PlacedVolume electronics_phv_right = hardware_vol.placeVolume(electronics_vol,Position(0, -hardware_y + EcalEndcap_cu_thickness + EcalEndcap_electronics_thickness / 2.0, 0));
+            PlacedVolume cooling_phv_left = hardware_vol.placeVolume(cooling_vol,Position(0, hardware_y - EcalEndcap_cu_thickness / 2.0, 0));
+            PlacedVolume cooling_phv_right = hardware_vol.placeVolume(cooling_vol,Position(0, -hardware_y + EcalEndcap_cu_thickness / 2.0, 0));  
+            layer_vol.setVisAttributes(theDetector, "SeeThrough");
+            hardware_vol.setVisAttributes(theDetector, "SeeThrough");
+            esr_vol.setVisAttributes(theDetector, "CyanVis");
+            crystal_vol.setVisAttributes(theDetector, "EcalBarrelVis");
+            sipm_vol.setVisAttributes(theDetector, "BlueVis");
+            electronics_vol.setVisAttributes(theDetector, "RedVis");
+            cooling_vol.setVisAttributes(theDetector, "GreenVis");          
+          }
+          else{
+            Volume esr_vol(hardware_name + "_ESR", Box(layer_thickness / 2.0, layer_thickness/2.0, hardware_z - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness), mat_ESR);
+            Volume crystal_vol(hardware_name + "_BGO", Box(layer_thickness / 2.0 - EcalEndcap_esr_thickness, layer_thickness/2.0 - EcalEndcap_esr_thickness, hardware_z - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness - EcalEndcap_esr_thickness), mat_BGO);
+            Volume sipm_vol(hardware_name + "_Sipm", Box(EcalEndcap_sipm_width / 2.0, EcalEndcap_sipm_width / 2.0, EcalEndcap_sipm_thickness / 2.0), mat_Si);
+            Volume electronics_vol(hardware_name + "_Electronics", Box(layer_thickness / 2.0, layer_thickness/2.0, EcalEndcap_electronics_thickness / 2.0), mat_PCB);
+            Volume cooling_vol(hardware_name + "_Cooling", Box(layer_thickness / 2.0, layer_thickness/2.0, EcalEndcap_cu_thickness / 2.0), mat_Cu);
+            crystal_vol.setSensitiveDetector(sens);
+            PlacedVolume esr_phv = hardware_vol.placeVolume(esr_vol,Position(0, 0, 0));
+            PlacedVolume crystal_phv = esr_vol.placeVolume(crystal_vol,Position(0, 0, 0));
+            PlacedVolume sipm_phv_left = hardware_vol.placeVolume(sipm_vol,Position(0, 0, hardware_z - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness - EcalEndcap_sipm_thickness / 2.0));
+            PlacedVolume sipm_phv_right = hardware_vol.placeVolume(sipm_vol,Position(0, 0, -hardware_z + EcalEndcap_cu_thickness + EcalEndcap_electronics_thickness + EcalEndcap_sipm_thickness / 2.0));
+            PlacedVolume electronics_phv_left = hardware_vol.placeVolume(electronics_vol,Position(0, 0, hardware_z - EcalEndcap_cu_thickness - EcalEndcap_electronics_thickness / 2.0)); 
+            PlacedVolume electronics_phv_right = hardware_vol.placeVolume(electronics_vol,Position(0, 0, -hardware_z + EcalEndcap_cu_thickness + EcalEndcap_electronics_thickness / 2.0));
+            PlacedVolume cooling_phv_left = hardware_vol.placeVolume(cooling_vol,Position(0, 0, hardware_z - EcalEndcap_cu_thickness / 2.0));
+            PlacedVolume cooling_phv_right = hardware_vol.placeVolume(cooling_vol,Position(0, 0, -hardware_z + EcalEndcap_cu_thickness / 2.0));  
+            layer_vol.setVisAttributes(theDetector, "SeeThrough");
+            hardware_vol.setVisAttributes(theDetector, "SeeThrough");
+            esr_vol.setVisAttributes(theDetector, "CyanVis");
+            crystal_vol.setVisAttributes(theDetector, "EcalBarrelVis");
+            sipm_vol.setVisAttributes(theDetector, "BlueVis");
+            electronics_vol.setVisAttributes(theDetector, "RedVis");
+            cooling_vol.setVisAttributes(theDetector, "GreenVis");
+          }
+
+
+          
+
+          
+          
+ 
+          for (int ihardware = 0; ihardware < hardware_num; ihardware++){
+            
+            
+            DetElement hardware(layer, _toString(j,"layer%d") + _toString(ihardware,"hardware%d"), det_id);
+            
+            
+
+            volume_bar = volume_bar + hardware_x*2*2*hardware_y*hardware_z*2;
+
+            if(module_type== 1){
+              hardware_x_pos = (j%2==0) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0;
+              hardware_y_pos = (j%2==0) ? 0 : -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware;
+              hardware_z_pos = 0;
+            }
+            else if(module_type== 2){
+              hardware_x_pos = (j%2==0) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware;
+              hardware_y_pos = (j%2==0) ? active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware: 0 ;
+              hardware_z_pos = 0;
+            }
+            if(module_type== 21){
+              hardware_x_pos = (j%2==0) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0;
+              hardware_y_pos = (j%2==0) ? 0 : active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware;
+              hardware_z_pos = 0;
+            }
+            else if(module_type== 22){
+              hardware_x_pos = (j%2==0) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware;
+              hardware_y_pos = (j%2==0) ? active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware: 0 ;
+              hardware_z_pos = 0;
+            }
+
+            else if(module_type == 3){
+              hardware_x_pos = (j%2==0) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware;
+              hardware_y_pos = 0;
+              hardware_z_pos = (j%2==0) ? -active_layer_dim_z + layer_thickness/2 + layer_thickness*ihardware : 0;
+            }
+            else if(module_type == 4){
+              hardware_x_pos = (j%2==0) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware;
+              hardware_y_pos = 0;
+              hardware_z_pos = (j%2==0) ? active_layer_dim_z - layer_thickness/2 - layer_thickness*ihardware : 0;
+            }
+            else if(module_type == 5){
+              hardware_x_pos = (j%2==0) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware;
+              hardware_y_pos = 0;
+              hardware_z_pos = (j%2==0) ? active_layer_dim_z - layer_thickness/2 - layer_thickness*ihardware : 0;
+            }
+            else if(module_type == 6){
+              hardware_x_pos = (j%2==0) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware;
+              hardware_y_pos = 0;
+              hardware_z_pos = (j%2==0) ? -active_layer_dim_z + layer_thickness/2 + layer_thickness*ihardware : 0;
+            }
+
+            else if(module_type == 7){
+              hardware_x_pos = (j%2==0) ? active_layer_dim_x - layer_thickness/2 -   layer_thickness*ihardware : 0;
+              hardware_y_pos = 0;
+              hardware_z_pos = (j%2==0) ? 0 : active_layer_dim_z - layer_thickness/2 - layer_thickness*ihardware;
+            }
+            else if(module_type == 8){
+              hardware_x_pos = (j%2==0) ? -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware : 0;
+              hardware_y_pos = 0;
+              hardware_z_pos = (j%2==0) ? 0 : -active_layer_dim_z + layer_thickness/2 + layer_thickness*ihardware;
+            }
+            else if(module_type == 9){
+              hardware_x_pos = (j%2==0) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0;
+              hardware_y_pos = 0;
+              hardware_z_pos = (j%2==0) ? 0 : -active_layer_dim_z + layer_thickness/2 + layer_thickness*ihardware;
+            }
+            else if(module_type == 10){
+              hardware_x_pos = (j%2==0) ? -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware : 0;
+              hardware_y_pos = 0;
+              hardware_z_pos = (j%2==0) ? 0 : active_layer_dim_z - layer_thickness/2 - layer_thickness*ihardware;
+            }
+            
+
+            else if(module_type == 11){
+              hardware_x_pos = (j%2==1) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0;
+              hardware_y_pos = (j%2==1) ? 0 : active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware;
+              hardware_z_pos = 0;
+            }
+            else if(module_type == 12){
+              hardware_x_pos = (j%2==1) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware;
+              hardware_y_pos = (j%2==1) ? active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware: 0 ;
+              hardware_z_pos = 0;
+            }
+            else if(module_type == 13){
+              hardware_x_pos = (j%2==1) ? -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware : 0;
+              hardware_y_pos = (j%2==1) ? 0 : -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware;
+              hardware_z_pos = 0;
+            }
+            else if(module_type == 14){
+              hardware_x_pos = (j%2==1) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware;
+              hardware_y_pos = (j%2==1) ? -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware: 0 ;
+              hardware_z_pos = 0;
+            }
+            else if(module_type == 15){
+              hardware_x_pos = (j%2==1) ? active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware : 0;
+              hardware_y_pos = (j%2==1) ? 0 : -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware;
+              hardware_z_pos = 0;
+            }
+            else if(module_type == 16){
+              hardware_x_pos = (j%2==1) ? 0 : -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware;
+              hardware_y_pos = (j%2==1) ? -active_layer_dim_y + layer_thickness/2 + layer_thickness*ihardware: 0 ;
+              hardware_z_pos = 0;
+            }
+            else if(module_type == 17){
+              hardware_x_pos = (j%2==1) ? -active_layer_dim_x + layer_thickness/2 + layer_thickness*ihardware : 0;
+              hardware_y_pos = (j%2==1) ? 0 : active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware;
+              hardware_z_pos = 0;
+            }
+            else if(module_type == 18){
+              hardware_x_pos = (j%2==1) ? 0 : active_layer_dim_x - layer_thickness/2 - layer_thickness*ihardware;
+              hardware_y_pos = (j%2==1) ? active_layer_dim_y - layer_thickness/2 - layer_thickness*ihardware: 0 ;
+              hardware_z_pos = 0;
+            }
+
+            PlacedVolume hardware_phv = layer_vol.placeVolume(hardware_vol,Position(hardware_x_pos, hardware_y_pos, hardware_z_pos));
+            hardware_phv.addPhysVolID("bar", ihardware);
+            hardware.setPlacement(hardware_phv);
+          }
+
+          // layer_vol.setAttributes(theDetector,x_layer.regionStr(),x_layer.limitsStr(),x_layer.visStr());
+          rot_layer = M_PI/2;
+          PlacedVolume layer_phv;
+          layer_phv = (module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22) ? envelopeVolTrapIso.placeVolume(layer_vol, Transform3D(RotationZYX(rot_layer, 0, 0), Position(0,0,layer_pos_z))) 
+            : (module_type>=3 && module_type<=10) ? envelopeVolTrapRight.placeVolume(layer_vol, Transform3D(RotationZYX( 0, 0, 0), Position( -(dim_x2 - dim_x1)/2  + j*delta_layer/2 + EcalEndcap_carbonfiber_thickness + 4.875*dd4hep::mm, layer_pos_z, 0))) 
+            : (module_type>=11 && module_type<=14) ? envelopeVolPrism.placeVolume(layer_vol, Position(-dim_x + active_layer_dim_x + EcalEndcap_carbonfiber_thickness, -dim_x + active_layer_dim_y + EcalEndcap_carbonfiber_thickness, layer_pos_z))
+            : envelopeVolPrism.placeVolume(layer_vol, Transform3D(RotationZYX( rot_layer, 0, 0), Position(-dim_x + active_layer_dim_x + EcalEndcap_carbonfiber_thickness, -dim_x + active_layer_dim_y + EcalEndcap_carbonfiber_thickness, layer_pos_z)));
+          
+          dd4hep::rec::ECALModuleInfoData::LayerInfo layerInfo;
+          if(j%2==0){
+            layerInfo.dlayerNumber = layer_num;
+            layerInfo.slayerNumber = 0;
+            layerInfo.barNumber = hardware_num;
+            layer_phv.addPhysVolID("slayer", 0).addPhysVolID("dlayer", layer_num);
+          } 
+          else{
+            layerInfo.dlayerNumber = layer_num;
+            layerInfo.slayerNumber = 1;
+            layerInfo.barNumber = hardware_num;
+            layer_phv.addPhysVolID("slayer", 1).addPhysVolID("dlayer", layer_num);
+            ++layer_num;
+          }
+          layer.setPlacement(layer_phv); 
+          layer_pos_z += layer_thickness;
+          layerInfos.push_back(layerInfo);
+          N_bar = N_bar + hardware_num;
+        }
+      }  
+    }
+
+    std::cout << "N_bar: " << N_bar << std::endl;
+    std::cout << "volume_bar: " << volume_bar << std::endl;
+
+    int sector_sum = 0;
+    if(module_type==1  || module_type==2 || module_type == 21 || module_type == 22) sector_sum = module_number;
+    else if(module_type>=11 && module_type<=18) sector_sum = module_number;
+    else sector_sum = module_number*2 + 1;
+
+    for (int sector_num=0;sector_num<sector_sum;sector_num++){
+      if(module_type>=3 && module_type<=6 && sector_num<module_number) continue;
+      if(module_type>=7 && module_type<=10 && sector_num>module_number) continue;
+
+      double EndcapModule_pos_x = 0;
+      double EndcapModule_pos_y = 0;
+      double EndcapModule_pos_z = pos_z;
+      double rot_EM = 0;
+      double rot_ES = 0;
+      double rot_EZ = 0;
+      double rot_EY = 0;
+      double rot_EX = 0;
+
+      if(module_type==0 || module_type==20){
+        if(sector_num<module_number){
+          EndcapModule_pos_x = pos_x;
+          EndcapModule_pos_y = pos_y + (module_number-sector_num)*dim_y;
+        }
+        else if(sector_num==module_number){
+          EndcapModule_pos_x = pos_x;
+          EndcapModule_pos_y = pos_y;
+        }
+        else{
+          EndcapModule_pos_x = pos_x + (sector_num-module_number)*dim_x;
+          EndcapModule_pos_y = pos_y;
+        }
+      }
+      else if(module_type==1  || module_type==2 || module_type == 21 || module_type == 22){
+        EndcapModule_pos_x = pos_x + sector_num*dim_y2;
+        EndcapModule_pos_y = pos_y;
+      }
+      else if(module_type>=3 && module_type<=10){
+        if(sector_num<module_number){
+          EndcapModule_pos_x = pos_y;
+          EndcapModule_pos_y = pos_x + (module_number-sector_num)*dim_y;
+        }
+        else if(sector_num==module_number){
+          EndcapModule_pos_x = pos_x;
+          EndcapModule_pos_y = pos_y;
+        }
+        else{
+          EndcapModule_pos_x = pos_x + (sector_num-module_number)*dim_x;
+          EndcapModule_pos_y = pos_y;
+        }
+      }
+      else{
+        EndcapModule_pos_x = pos_x;
+        EndcapModule_pos_y = pos_y;
+      }
+
+      
+      for(int stave_num=0;stave_num<4;stave_num++){
+        if((module_type==1 || module_type==21) && (stave_num==1 || stave_num==3)) continue;
+        if((module_type==2 || module_type==22) && (stave_num==0 || stave_num==2)) continue;
+        if((module_type==3 || module_type==5) && (stave_num==2 || stave_num==3)) continue;
+        if((module_type==4 || module_type==6) && (stave_num==0 || stave_num==1)) continue;
+        if((module_type==7 || module_type==9) && (stave_num==1 || stave_num==2)) continue;
+        if((module_type==8 || module_type==10) && (stave_num==0 || stave_num==3)) continue;
+
+        // Set the ID. The ID is composed of the module number, the stave number, the part number.
+        int stave_id = 0;
+        int part_id = 0;
+        if(module_type == 0 || module_type == 20){
+          if(stave_num==0 && sector_num<=module_number) { stave_id = 7 + module_tag;  part_id = 10 - sector_num; }
+          if(stave_num==0 && sector_num>module_number)  { stave_id = sector_num + 4 + 2*module_tag;  part_id = 7 + module_tag; }
+          if(stave_num==1 && sector_num<=module_number) { stave_id = 3 - module_tag;  part_id = 10 - sector_num; }
+          if(stave_num==1 && sector_num>module_number)  { stave_id = 6 - 2*module_tag - sector_num;  part_id = 7 + module_tag; }
+          if(stave_num==2 && sector_num<=module_number) { stave_id = 3 - module_tag;  part_id = sector_num; }
+          if(stave_num==2 && sector_num>module_number)  { stave_id = 6 - 2*module_tag - sector_num;  part_id = 3 - module_tag; }
+          if(stave_num==3 && sector_num<=module_number) { stave_id = 7 + module_tag;  part_id = sector_num; }
+          if(stave_num==3 && sector_num>module_number)  { stave_id = sector_num + 4 + 2*module_tag;  part_id = 3 - module_tag; }
+        }
+        else if(module_type == 1 || module_type == 2 || module_type == 21 || module_type == 22){ 
+          if(stave_num==0) { stave_id = 7 + sector_num;  part_id = 5; }
+          if(stave_num==1) { stave_id = 5;  part_id = 7 + sector_num; }
+          if(stave_num==2) { stave_id = 3 - sector_num;  part_id = 5; }
+          if(stave_num==3) { stave_id = 5;  part_id = 3 - sector_num; }
+        }
+        else if(module_type >= 3  && module_type <= 6){
+          if(stave_num==0) { stave_id = 2 + sector_num;  part_id = 6; }
+          if(stave_num==1) { stave_id = 8 - sector_num;  part_id = 6; }
+          if(stave_num==2) { stave_id = 8 - sector_num;  part_id = 4; }
+          if(stave_num==3) { stave_id = 2 + sector_num;  part_id = 4; }
+        }
+        else if(module_type >= 7  && module_type <= 10){
+          if(stave_num==0) { stave_id = 6;  part_id = 10 - sector_num; }
+          if(stave_num==1) { stave_id = 4;  part_id = 10 - sector_num; }
+          if(stave_num==2) { stave_id = 4;  part_id = sector_num; }
+          if(stave_num==3) { stave_id = 6;  part_id = sector_num; }
+        }
+        else {
+          if(stave_num==0) { stave_id = 6;  part_id = 6; }
+          if(stave_num==1) { stave_id = 4;  part_id = 6; }
+          if(stave_num==2) { stave_id = 4;  part_id = 4; }
+          if(stave_num==3) { stave_id = 6;  part_id = 4; }
+        }
+
+        double rot_FZ = 0;
+        double rot_FY = 0;
+        double rot_FX = 0;
+
+        if(module_type==0 || module_type==20){
+          EndcapModule_center_pos_x = (stave_num == 0) ? EndcapModule_pos_x : (stave_num == 1) ? -EndcapModule_pos_x : (stave_num == 2) ? -EndcapModule_pos_x : EndcapModule_pos_x;
+          EndcapModule_center_pos_y = (stave_num == 0) ? EndcapModule_pos_y : (stave_num == 1) ? EndcapModule_pos_y : (stave_num == 2) ? -EndcapModule_pos_y : -EndcapModule_pos_y;
+        }
+        else if(module_type==1  || module_type==2 || module_type == 21 || module_type == 22){
+          EndcapModule_center_pos_x = (stave_num == 0) ? EndcapModule_pos_x : (stave_num == 1) ? EndcapModule_pos_y : (stave_num == 2) ? -EndcapModule_pos_x : EndcapModule_pos_y;
+          EndcapModule_center_pos_y = (stave_num == 0) ? EndcapModule_pos_y : (stave_num == 1) ? EndcapModule_pos_x : (stave_num == 2) ? -EndcapModule_pos_y : -EndcapModule_pos_x;
+        }
+        else{
+          EndcapModule_center_pos_x = (stave_num == 0) ? EndcapModule_pos_x : (stave_num == 1) ? -EndcapModule_pos_x : (stave_num == 2) ? -EndcapModule_pos_x : EndcapModule_pos_x;
+          EndcapModule_center_pos_y = (stave_num == 0) ? EndcapModule_pos_y : (stave_num == 1) ? EndcapModule_pos_y : (stave_num == 2) ? -EndcapModule_pos_y : -EndcapModule_pos_y;
+        }
+
+        rot_ES = (stave_num == 0) ? M_PI/2 : (stave_num == 1) ? 0 : (stave_num == 2) ? M_PI/2 : 0;
+        if(sector_num<=module_number) rot_EX = (stave_num == 0) ? M_PI : (stave_num == 1) ? 0 : (stave_num == 2) ? 0 : M_PI;
+        else rot_EX = (stave_num == 0) ? M_PI+M_PI/2 : (stave_num == 1) ? 0-M_PI/2 : (stave_num == 2) ? 0+M_PI/2 : M_PI-M_PI/2;
+        rot_EZ = (stave_num == 0) ? 0 : (stave_num == 1) ? 0 : (stave_num == 2) ? 0 : 0;
+        
+
+        for(int module_num=0;module_num<2;module_num++) {
+        
+          if(module_num==0 && module_type==20) continue;
+          if(module_num==1 && module_type==0) continue;
+          if(module_num==0 && (module_type==21 || module_type==22)) continue;
+          if(module_num==1 && (module_type==1 || module_type==2)) continue;
+          if(module_num==0 && (module_type==5 || module_type==6 || module_type==9 || module_type==10)) continue;
+          if(module_num==1 && (module_type==3 || module_type==4 || module_type==7 || module_type==8)) continue;
+          if(module_num==0 && stave_num==0 && (module_type==12 || module_type==13 || module_type==14 || module_type==15 || module_type==16 || module_type==17 || module_type==18)) continue;
+          if(module_num==0 && stave_num==1 && (module_type==11 || module_type==13 || module_type==14 || module_type==15 || module_type==16 || module_type==17 || module_type==18)) continue;
+          if(module_num==0 && stave_num==2 && (module_type==11 || module_type==12 || module_type==14 || module_type==15 || module_type==16 || module_type==17 || module_type==18)) continue;
+          if(module_num==0 && stave_num==3 && (module_type==11 || module_type==12 || module_type==13 || module_type==15 || module_type==16 || module_type==17 || module_type==18)) continue;
+          if(module_num==1 && stave_num==0 && (module_type==11 || module_type==12 || module_type==13 || module_type==14 || module_type==16 || module_type==17 || module_type==18)) continue;
+          if(module_num==1 && stave_num==1 && (module_type==11 || module_type==12 || module_type==13 || module_type==14 || module_type==15 || module_type==17 || module_type==18)) continue;
+          if(module_num==1 && stave_num==2 && (module_type==11 || module_type==12 || module_type==13 || module_type==14 || module_type==15 || module_type==16 || module_type==18)) continue;
+          if(module_num==1 && stave_num==3 && (module_type==11 || module_type==12 || module_type==13 || module_type==14 || module_type==15 || module_type==16 || module_type==17)) continue;
+
+          int module_id = (module_num==0)? 0:1;
+           
+          if(module_type>=3 && module_type<=10){
+            if(sector_num<=module_number) rot_EM = (module_id==0)?M_PI*3/2: M_PI/2;
+            else rot_EM = (module_id==0)?M_PI*3/2: M_PI/2;
+            if(sector_num>module_number) rot_EY = (module_id==0)? rot_EX+M_PI : rot_EX;
+            else rot_EY = rot_EX;
+          } 
+          else rot_EM = (module_id==0)?M_PI:0;
+          
+          EndcapModule_center_pos_z = (module_id==0)? -EndcapModule_pos_z:EndcapModule_pos_z;
+          
+          PlacedVolume env_phv;
+
+          dd4hep::rec::ECALModuleInfoData ecalmoduleInfoData;
+          ecalmoduleInfoData.moduleNumber = module_id;
+          ecalmoduleInfoData.staveNumber = stave_id;
+          ecalmoduleInfoData.partNumber = part_id;
+          ecalmoduleInfoData.LayerInfos = layerInfos;
+          ecalSystemInfoData->ModuleInfos.push_back(ecalmoduleInfoData);
+          if(module_type==0 || module_type==20){
+            env_phv = envelope.placeVolume(envelopeVol,
+                        Transform3D(RotationX(rot_EM),
+                        Translation3D(EndcapModule_center_pos_x,
+                          EndcapModule_center_pos_y,
+                          EndcapModule_center_pos_z)));
+            env_phv.addPhysVolID("system",det_id).addPhysVolID("module", module_id).addPhysVolID("type", module_tag).addPhysVolID("part", part_id).addPhysVolID("stave", stave_id);
+            all_module0++;
+          }
+          else if(module_type==1  || module_type==2 || module_type == 21 || module_type == 22){
+            env_phv = envelope.placeVolume(envelopeVolTrapIso,
+                        Transform3D(RotationZYX(rot_ES, 0, rot_EM),
+                        Position(EndcapModule_center_pos_x,
+                          EndcapModule_center_pos_y,
+                          EndcapModule_center_pos_z)));
+            env_phv.addPhysVolID("system",det_id).addPhysVolID("module", module_id).addPhysVolID("type", module_tag).addPhysVolID("part", part_id).addPhysVolID("stave", stave_id);
+            all_module1++;
+          }
+          else if(module_type>=3 && module_type<=10){
+            if(sector_num==module_number){
+              continue;
+            }
+            else{
+              env_phv = envelope.placeVolume(envelopeVolTrapRight,
+                        Transform3D(RotationZYX(rot_EZ, rot_EY, rot_EM),
+                        Position(EndcapModule_center_pos_x,
+                          EndcapModule_center_pos_y,
+                          EndcapModule_center_pos_z)));
+              env_phv.addPhysVolID("system",det_id).addPhysVolID("module", module_id).addPhysVolID("type", module_tag).addPhysVolID("part", part_id).addPhysVolID("stave", stave_id);
+              all_module2++;
+            }
+          }
+          else{
+            if(module_id==0){
+              rot_FZ = (stave_num == 0) ? M_PI/2 : (stave_num == 1) ? 0: (stave_num == 2) ? -M_PI/2 : M_PI;  
+            } 
+            else{
+              rot_FZ = (stave_num == 0) ? M_PI : (stave_num == 1) ? -M_PI/2 : (stave_num == 2) ? 0 : M_PI/2;
+            }
+            rot_FY = (stave_num == 0) ? 0 : (stave_num == 1) ? 0 : (stave_num == 2) ? 0 : 0;
+            rot_FX = (module_id==0)?M_PI:0;
+            
+            env_phv = envelope.placeVolume(envelopeVolPrism,
+                        Transform3D(RotationZYX(rot_FZ, rot_FY, rot_FX),
+                        Position(EndcapModule_center_pos_x,
+                          EndcapModule_center_pos_y,
+                          EndcapModule_center_pos_z)));
+            env_phv.addPhysVolID("system",det_id).addPhysVolID("module", module_id).addPhysVolID("type", module_tag).addPhysVolID("part", part_id).addPhysVolID("stave", stave_id);
+            
+            all_module3++;
+          }
+          
+          DetElement sd = (module_id==0&&part_id==0&&stave_id==0) ? stave_det : stave_det.clone(_toString(module_id,"module%d")+_toString(stave_id,"stave%d")+_toString(part_id,"part%d"));	  
+	        sd.setPlacement(env_phv);
+        }
+      }
+    }
+    endcapID++;
+  }
+  cout<<"EndcapModule0: "<<all_module0<<endl;
+  cout<<"EndcapModule1: "<<all_module1<<endl;
+  cout<<"EndcapModule2: "<<all_module2<<endl;
+  cout<<"EndcapModule3: "<<all_module3<<endl;
+
+  sdet.addExtension<dd4hep::rec::ECALSystemInfoData>(ecalSystemInfoData);
+  return sdet;
+}
+
+DECLARE_DETELEMENT(LongCrystalBarEndcapCalorimeter_v04, create_detector)
\ No newline at end of file