From 6ce0a37b33908fd0857d73c16ea90f12d3decd98 Mon Sep 17 00:00:00 2001
From: Chengdong Fu <fucd@ihep.ac.cn>
Date: Wed, 13 Jan 2021 16:44:47 +0800
Subject: [PATCH] add coil and muon option and fix overlap

---
 .../DetCEPCv4/compact/Beampipe_o1_v01_01.xml  | 19 +++++-----
 .../DetCEPCv4/compact/CepC_v4-onlyTracker.xml |  2 +-
 Detector/DetCEPCv4/compact/CepC_v4.xml        | 22 +++++++++--
 .../compact/SHcalRpc01_EndcapRing_01.xml      |  2 +-
 Detector/DetCEPCv4/compact/Yoke05_Barrel.xml  | 10 ++---
 Detector/DetCEPCv4/compact/Yoke05_Endcaps.xml |  9 ++---
 Detector/DetCEPCv4/compact/coil03.xml         | 38 +++++++++----------
 Detector/DetCEPCv4/compact/envelope_defs.xml  |  5 ++-
 Detector/DetCEPCv4/compact/top_defs.xml       | 11 +++---
 Detector/DetCEPCv4/compact/yoke_defs.xml      |  1 +
 10 files changed, 68 insertions(+), 51 deletions(-)

diff --git a/Detector/DetCEPCv4/compact/Beampipe_o1_v01_01.xml b/Detector/DetCEPCv4/compact/Beampipe_o1_v01_01.xml
index a7ce385d..6dd10eac 100644
--- a/Detector/DetCEPCv4/compact/Beampipe_o1_v01_01.xml
+++ b/Detector/DetCEPCv4/compact/Beampipe_o1_v01_01.xml
@@ -160,12 +160,12 @@
   <type_flags type="DetType_SUPPORT + DetType_BEAMPIPE "/>
 
   <section start="TUBE_QD0_Lstar-20*mm" end="TUBE_QD0_Lstar+TUBE_QD0_cryostat_length"
-	   rMin="235.*mm" rMax="250.*mm"
+	   rMin="170.*mm" rMax="185.*mm"
 	   material="stainless_steel"
 	   name="qd0_cryostat"/>
 
   <section start="TUBE_QD0_Lstar-20*mm" end="TUBE_QD0_Lstar+TUBE_QD0_cryostat_length"
-	   rMin="235.*mm" rMax="250.*mm"
+	   rMin="205.*mm" rMax="210.*mm"
 	   material="stainless_steel"
 	   name="qd0_cryostat_wall"/>
 
@@ -183,7 +183,7 @@
 
 </detector>
 
-<detector name="QD0_support" type="BoxSupport_o1_v01" vis="BeamPipeVis" id="ILDDetID_NOTUSED" reflect="true">
+<detector name="QD0_support" type="TubeSupport_o1_v01" vis="BeamPipeVis" id="ILDDetID_NOTUSED" reflect="true">
 
   <envelope vis="BlueVis">
     <shape type="Assembly"/>
@@ -191,18 +191,19 @@
 
   <type_flags type="DetType_SUPPORT + DetType_BEAMPIPE "/>
 
-  <section start="TUBE_QD0_Lstar+20*mm" end="TUBE_QD0_Lstar+TUBE_QD0_cryostat_length"
-	   rMin="275.*mm" rMax="300*mm"
+  <section start="TUBE_QD0_Lstar-20*mm" end="TUBE_QD0_Lstar+TUBE_QD0_cryostat_length"
+	   rMin="240.*mm" rMax="310*mm"
 	   material="stainless_steel"
 	   name="qd0_support"/>
 
-  <section start="Ecal_endcap_zmin" end="Ecal_endcap_zmin+Ecal_barrel_thickness"
+  <!--section start="Ecal_endcap_zmin" end="Ecal_endcap_zmin+Ecal_barrel_thickness"
 	   rMin="EcalEndcapRing_outer_radius + 2*env_safety" rMax="EcalEndcap_inner_radius - 2*env_safety"
 	   material="stainless_steel"
-	   name="forward_support_tube"/>
+	   name="forward_support_tube"/-->
 
-  <section start="top_LHCal_min_z + top_LHCal_thickness+10*mm" end="BeamCal_min_z + top_BeamCal_thickness+4600*mm"
-	   rMin="305*mm" rMax="325*mm"
+  <!--section start="top_LHCal_min_z + top_LHCal_thickness+10*mm" end="BeamCal_min_z + top_BeamCal_thickness+4600*mm"-->
+  <section start="top_LHCal_min_z + top_LHCal_thickness+10*mm" end="TUBE_QD0_Lstar-20*mm"
+	   rMin="175*mm" rMax="240*mm"
 	   material="stainless_steel"
 	   name="forward_support_tube"/>
 
diff --git a/Detector/DetCEPCv4/compact/CepC_v4-onlyTracker.xml b/Detector/DetCEPCv4/compact/CepC_v4-onlyTracker.xml
index 7610072d..bf5aace8 100644
--- a/Detector/DetCEPCv4/compact/CepC_v4-onlyTracker.xml
+++ b/Detector/DetCEPCv4/compact/CepC_v4-onlyTracker.xml
@@ -78,7 +78,7 @@
   <fields>
     <field name="GlobalSolenoid" type="solenoid"
            inner_field="Field_nominal_value"
-           outer_field="outerField_nominal_value"
+           outer_field="Field_outer_nominal_value"
            zmax="TPC_Ecal_Hcal_barrel_halfZ + Coil_extra_size"
            outer_radius="Hcal_outer_radius + Coil_thickness/2">
     </field>
diff --git a/Detector/DetCEPCv4/compact/CepC_v4.xml b/Detector/DetCEPCv4/compact/CepC_v4.xml
index 356e5bea..105a0071 100644
--- a/Detector/DetCEPCv4/compact/CepC_v4.xml
+++ b/Detector/DetCEPCv4/compact/CepC_v4.xml
@@ -67,14 +67,14 @@
   <include ref="SHcalRpc01_Barrel_01.xml"/>
   <include ref="SHcalRpc01_Endcaps_01.xml"/>
   <include ref="SHcalRpc01_EndcapRing_01.xml"/>
-  <!--include ref="Yoke05_Barrel.xml"/>
+  <include ref="Yoke05_Barrel.xml"/>
   <include ref="Yoke05_Endcaps.xml"/>
-  <include ref="LumiCal.xml"/-->
+  <!--include ref="LumiCal.xml"/-->
 
   <!--include ref="LHCal01.xml"/>
   <include ref="BeamCal08.xml"/-->
 
-  <!--include ref="coil03.xml"/-->
+  <include ref="coil03.xml"/>
   <!--include ref="SServices00.xml"/-->
   <plugins>
     <plugin name="DD4hepVolumeManager"/>
@@ -83,4 +83,20 @@
   <!--include ref="Field_Solenoid_Map_s_4.0T.xml"/>
   <include ref="Field_AntiDID_Map_s.xml"/>
   <include ref="Field_FwdMagnets_Ideal_1000GeV.xml"/-->
+  <fields>
+    <field name="InnerSolenoid" type="solenoid"
+           inner_field="Field_nominal_value"
+           outer_field="0"
+           zmax="Coil_half_length"
+	   inner_radius="Hcal_outer_radius+Coil_thickness/2"
+           outer_radius="Yoke_barrel_inner_radius">
+    </field>
+    <field name="OuterSolenoid" type="solenoid"
+           inner_field="0"
+           outer_field="Field_outer_nominal_value"
+           zmax="Coil_half_length"
+	   inner_radius="Yoke_barrel_inner_radius"
+           outer_radius="Yoke_barrel_inner_radius+Field_outer_thickness">
+    </field>
+  </fields>
 </lccdd>
diff --git a/Detector/DetCEPCv4/compact/SHcalRpc01_EndcapRing_01.xml b/Detector/DetCEPCv4/compact/SHcalRpc01_EndcapRing_01.xml
index 824b932c..ab41b9af 100644
--- a/Detector/DetCEPCv4/compact/SHcalRpc01_EndcapRing_01.xml
+++ b/Detector/DetCEPCv4/compact/SHcalRpc01_EndcapRing_01.xml
@@ -9,7 +9,7 @@
             <shape type="Box" dx="HcalEndcapRing_outer_radius + 2.0*env_safety" dy="HcalEndcapRing_outer_radius + 2.0*env_safety"
                    dz="HcalEndcapRing_max_z + 2.0*env_safety"/>
             <shape type="PolyhedraRegular" numsides="Hcal_ring_inner_symmetry" rmin="HcalEndcapRing_inner_radius - env_safety"
-                   rmax="HcalEndcapRing_outer_radius + env_safety" dz="2.0*HcalEndcapRing_max_z + env_safety" material="Air"/>
+                   rmax="HcalEndcapRing_outer_radius*cos(pi/Hcal_ring_outer_symmetry) + env_safety" dz="2.0*HcalEndcapRing_max_z + env_safety" material="Air"/>
             <rotation x="0" y="0" z="90*deg-180*deg/Hcal_ring_inner_symmetry"/>
           </shape>
           <shape type="Box" dx="HcalEndcapRing_outer_radius + 2.0*env_safety" dy="HcalEndcapRing_outer_radius + 2.0*env_safety"
diff --git a/Detector/DetCEPCv4/compact/Yoke05_Barrel.xml b/Detector/DetCEPCv4/compact/Yoke05_Barrel.xml
index 00c8d264..a742d756 100644
--- a/Detector/DetCEPCv4/compact/Yoke05_Barrel.xml
+++ b/Detector/DetCEPCv4/compact/Yoke05_Barrel.xml
@@ -1,13 +1,11 @@
 <!-- comment>Calorimeters</comment -->
 <lccdd>
   <detectors>
-    <detector name="YokeBarrel" type="Yoke05_Barrel" id="ILDDetID_YOKE" readout="YokeBarrelCollection" vis="YellowVis" insideTrackingVolume="false" buildType="BUILD_ENVELOPE">
+    <detector name="YokeBarrel" type="Yoke05_Barrel" id="ILDDetID_YOKE" readout="MuonBarrelCollection" vis="YellowVis" insideTrackingVolume="false" buildType="BUILD_ENVELOPE">
       <envelope vis="ILD_YOKEVis">
         <shape type="BooleanShape" operation="Intersection" material="Air" >
-          <shape type="Box" dx="Yoke_outer_radius + env_safety" dy="Yoke_outer_radius + env_safety"
-                 dz="Yoke_half_length + env_safety"/> <!--Box defined the coordinate system-->
-          <shape type="PolyhedraRegular" numsides="Yoke_symmetry"  rmin="Yoke_inner_radius"
-                 rmax="Yoke_outer_radius" dz="2.0*Yoke_half_length"  material = "Air" />
+          <shape type="Box" dx="Yoke_outer_radius + env_safety" dy="Yoke_outer_radius + env_safety" dz="Yoke_half_length + env_safety"/> <!--Box defined the coordinate system-->
+          <shape type="PolyhedraRegular" numsides="Yoke_symmetry"  rmin="Yoke_inner_radius" rmax="Yoke_outer_radius" dz="2.0*Yoke_half_length"  material = "Air" />
           <rotation x="0*deg" y="0*deg" z="90*deg-180*deg/Yoke_symmetry"/>
         </shape>
       </envelope>
@@ -28,7 +26,7 @@
   </detectors>
 
   <readouts>
-    <readout name="YokeBarrelCollection">
+    <readout name="MuonBarrelCollection">
       <segmentation type="CartesianGridXZ" grid_size_x="Yoke_cells_size" grid_size_z="Yoke_cells_size"/>
       <id>system:5,module:3,stave:4,tower:3,layer:6,x:32:-16,z:-16</id>
     </readout>
diff --git a/Detector/DetCEPCv4/compact/Yoke05_Endcaps.xml b/Detector/DetCEPCv4/compact/Yoke05_Endcaps.xml
index 6115d54d..74b85fdd 100644
--- a/Detector/DetCEPCv4/compact/Yoke05_Endcaps.xml
+++ b/Detector/DetCEPCv4/compact/Yoke05_Endcaps.xml
@@ -1,8 +1,7 @@
 <!-- comment>Calorimeters</comment -->
 <lccdd>
   <detectors>
-    <detector name="YokeEndcap" type="Yoke05_Endcaps" id="ILDDetID_YOKE_ENDCAP" readout="YokeEndcapsCollection" vis="YellowVis" insideTrackingVolume="false" >
-
+    <detector name="YokeEndcap" type="Yoke05_Endcaps" id="ILDDetID_YOKE_ENDCAP" readout="MuonEndcapsCollection" vis="YellowVis" insideTrackingVolume="false" >
       <envelope vis="ILD_YOKEVis">
         <shape type="BooleanShape" operation="Subtraction" material="Air">
           <shape type="BooleanShape" operation="Subtraction" material="Air">
@@ -16,7 +15,7 @@
             <shape type="Box" dx="YokeEndcap_outer_radius + 1.5*env_safety" dy="YokeEndcap_outer_radius + 1.5*env_safety"
                    dz="YokeEndcapPlug_min_z - env_safety"/>
           </shape>
-          <shape type="PolyhedraRegular" numsides="YokeEndcapPlug_symmetry"  rmin="YokeEndcapPlug_outer_radius + env_safety"
+          <shape type="PolyhedraRegular" numsides="YokeEndcapPlug_symmetry"  rmin="YokeEndcapPlug_outer_radius*cos(pi/Hcal_ring_outer_symmetry) + env_safety"
                  rmax="YokeEndcap_outer_radius + 2.0*env_safety" dz="2.*YokeEndcap_min_z - env_safety" />
           <rotation x="0*deg" y="0*deg" z="90*deg-180*deg/YokeEndcapPlug_symmetry"/>
         </shape>
@@ -24,7 +23,7 @@
 
       <type_flags type=" DetType_CALORIMETER + DetType_ENDCAP + DetType_MUON " />
 
-      <dimensions numsides="12" rmin="Yoke_inner_radius" z="Yoke_barrel_halfZ" />
+      <dimensions numsides="Yoke_symmetry" rmin="Yoke_inner_radius" z="Yoke_barrel_halfZ" />
       <material name="Iron"/>
       <layer repeat="12" vis="SeeThrough">
         <slice material = "Air"            thickness = "15.0*mm"                    vis="YellowVis" />
@@ -35,7 +34,7 @@
   </detectors>
 
   <readouts>
-    <readout name="YokeEndcapsCollection">
+    <readout name="MuonEndcapsCollection">
       <segmentation type="CartesianGridXY" grid_size_x="Yoke_cells_size" grid_size_y="Yoke_cells_size"/>
       <id>system:5,module:3,stave:4,tower:3,layer:6,x:32:-16,y:-16</id>
     </readout>
diff --git a/Detector/DetCEPCv4/compact/coil03.xml b/Detector/DetCEPCv4/compact/coil03.xml
index 3f176d28..1714b455 100644
--- a/Detector/DetCEPCv4/compact/coil03.xml
+++ b/Detector/DetCEPCv4/compact/coil03.xml
@@ -2,29 +2,29 @@
      Coil parameters for ILD_o1_v5  
 -->
 <lccdd>
-<detectors>
-
-<detector name="Coil" type="SCoil02" vis="CoilVis" id="ILDDetID_COIL" insideTrackingVolume="false" sensitive="no">
-
+  <detectors>
+    <detector name="Coil" type="SCoil02" vis="ILD_COILVis" id="ILDDetID_COIL" insideTrackingVolume="false" readout="COILCollection">
   <!-- fg: taken from SCoil02.cc::PreLoadScriptAction() : 
        there the variable Hcal_R_max was used, which was set from Hcal_module_radius in the SHcal driver - 
        here we simply use the value Hcal_outer_radius defined in ILD_l1_v01
 
        -> now (03/2015) done in main compact file ILD_l1_v01.xml
   -->
-
-  <envelope vis="ILD_COILVis">
-    <shape type="Tube" rmin="Coil_inner_radius" rmax="Coil_outer_radius" 
-	   dz="Coil_half_length" material="Air"/>
-  </envelope>
-
-  <type_flags type=" DetType_SUPPORT + DetType_COIL " />
-
-  <!--fg: for now only a simple aluminum cylinder is created inside the envelope -->
-  <tube rmin="Coil_inner_radius+env_safety" rmax="Coil_outer_radius-env_safety" 
-	dz="Coil_half_length-env_safety" material="G4_Al"/>
-
-</detector>
-
-</detectors>
+      <envelope vis="SeeThrough">
+	<shape type="Tube" rmin="Coil_inner_radius" rmax="Coil_outer_radius" dz="Coil_half_length" material="Air"/>
+      </envelope>
+  
+      <type_flags type=" DetType_SUPPORT + DetType_COIL " />
+  
+      <!--fg: for now only a simple aluminum cylinder is created inside the envelope -->
+      <tube rmin="Coil_inner_radius" rmax="Coil_outer_radius" dz="Coil_half_length" material="G4_Al"/>
+      
+    </detector>
+  </detectors>
+
+  <readouts>
+    <readout name="COILCollection">
+      <id>system:5,side:-2,layer:9,module:8,sensor:8,barrelside:-2</id>
+    </readout>
+  </readouts>
 </lccdd>
diff --git a/Detector/DetCEPCv4/compact/envelope_defs.xml b/Detector/DetCEPCv4/compact/envelope_defs.xml
index 5b900a1b..0c6db073 100644
--- a/Detector/DetCEPCv4/compact/envelope_defs.xml
+++ b/Detector/DetCEPCv4/compact/envelope_defs.xml
@@ -94,7 +94,7 @@
 
   <constant name="Hcal_inner_radius"    value="Ecal_outer_radius+Hcal_Ecal_gap"/>
   <!--constant name="Hcal_outer_radius"    value="(Hcal_inner_radius+Hcal_barrel_thickness)/cos(pi/Hcal_outer_symmetry)"/--> <!-- cos(pi/16)   -->
-  <constant name="Hcal_outer_radius"    value="3144.43*mm"/>
+  <constant name="Hcal_outer_radius"    value="3144.43*mm + 0.00244676*mm"/>
   <constant name="Hcal_half_length"     value="TPC_Ecal_Hcal_barrel_halfZ"/>
   <constant name="Hcal_inner_symmetry"  value="Ecal_Hcal_symmetry"/>
 
@@ -120,7 +120,8 @@
   <constant name="Coil_outer_radius"    value="Hcal_outer_radius+Hcal_Coil_additional_gap+Coil_thickness"/>
   <constant name="Coil_half_length"     value="TPC_Ecal_Hcal_barrel_halfZ+Coil_extra_size"/>
 
-  <constant name="Yoke_inner_radius"    value="Coil_outer_radius+top_Hcal_Yoke_gap"/>
+  <!--constant name="Yoke_inner_radius"    value="Hcal_outer_radius+top_Hcal_Yoke_gap"/--><!--two ways to obtain Yoke_inner_radius--> 
+  <constant name="Yoke_inner_radius"    value="Coil_outer_radius+Coil_Yoke_radial_clearance"/>
   <constant name="Yoke_outer_radius"    value="Yoke_inner_radius+top_Yoke_thickness"/>
   <constant name="Yoke_half_length"     value="top_Yoke_half_length"/>
   <constant name="Yoke_symmetry"        value="top_Yoke_symmetry"/>
diff --git a/Detector/DetCEPCv4/compact/top_defs.xml b/Detector/DetCEPCv4/compact/top_defs.xml
index 6b09c8a3..021f80a8 100644
--- a/Detector/DetCEPCv4/compact/top_defs.xml
+++ b/Detector/DetCEPCv4/compact/top_defs.xml
@@ -10,8 +10,8 @@
   <constant name="CepC_Main_Crossing_Angle" value="33*mrad"/>
 
   <!-- the field inside and outside the solenoid -->
-  <constant name="outerField_nominal_value" value="-1.33716*tesla"/>
-
+  <constant name="Field_outer_nominal_value" value="-1.33716*tesla"/>
+  <constant name="Field_outer_thickness" value="2550*mm"/>
 
   <!-- VXD -->
   <constant name="top_VXD_inner_radius"   value="15*mm "/>
@@ -58,7 +58,7 @@
   <constant name="Ecal_EC_Ring_gap" value="10*mm"/>
 
   <!-- HCAL -->
-  <constant name="Hcal_barrel_thickness" value="1086.43*mm"/>
+  <!--constant name="Hcal_barrel_thickness" value="1086.43*mm"/-->
   <constant name="Hcal_Coil_additional_gap" value="29.5*mm"/>
   <!--constant name="Hcal_outer_symmetry" value="16"/-->
   <constant name="Hcal_outer_symmetry" value="8"/>
@@ -81,8 +81,9 @@
        <constant name="top_Yoke_inner_radius"    value="4424.0*mm"/>
        <constant name="top_Yoke_outer_radius"    value="7725.0*mm"/>
        -->
-  <constant name="top_Hcal_Yoke_gap"       value="300*mm"/>
-  <constant name="top_Yoke_thickness"      value="2550*mm"/>
+  <constant name="Coil_Yoke_radial_clearance" value="250*mm"/>
+  <constant name="top_Hcal_Yoke_gap"       value="Hcal_Coil_additional_gap+Coil_thickness+Coil_Yoke_radial_clearance"/>
+  <constant name="top_Yoke_thickness"      value="3241*mm"/>
 
   <constant name="top_Yoke_half_length"     value="4047.0*mm"/>
   <constant name="Yoke_Z_start_endcaps"     value="4072.0*mm"/>
diff --git a/Detector/DetCEPCv4/compact/yoke_defs.xml b/Detector/DetCEPCv4/compact/yoke_defs.xml
index 59672a5a..f299a282 100644
--- a/Detector/DetCEPCv4/compact/yoke_defs.xml
+++ b/Detector/DetCEPCv4/compact/yoke_defs.xml
@@ -1,6 +1,7 @@
 <define>
   <constant name="Yoke_cells_size" value="30*mm"/>
   <constant name="Yoke_barrel_inner_radius" value="Yoke_inner_radius"/>
+  <constant name="Hcal_Yoke_plug_gap" value="45*mm"/>
 </define>
 
 
-- 
GitLab