From e1f7796a8e8eca942b2a0458aef506d1fbae765e Mon Sep 17 00:00:00 2001
From: myliu <201916234@mail.sdu.edu.cn>
Date: Thu, 21 Jan 2021 20:58:24 +0800
Subject: [PATCH] Add two virtual end caps

---
 Detector/DetDriftChamber/compact/det.xml         |  8 ++++++--
 .../src/driftchamber/DriftChamber.cpp            | 16 ++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/Detector/DetDriftChamber/compact/det.xml b/Detector/DetDriftChamber/compact/det.xml
index bfd81e73..b9997bbe 100644
--- a/Detector/DetDriftChamber/compact/det.xml
+++ b/Detector/DetDriftChamber/compact/det.xml
@@ -53,6 +53,10 @@
     <constant name="SDT_outer_chamber_outer_wall_radius_min" value="1715*mm"/>
     <constant name="SDT_outer_chamber_outer_wall_radius_max" value="1717.8*mm"/>
 
+    <constant name="SDT_Endcap_rmin" value="SDT_radius_min"/>
+    <constant name="SDT_Endcap_rmax" value="SDT_radius_max"/>
+    <constant name="SDT_Endcap_dz" value="0.1*mm"/>
+
   </define>
 
   <display>
@@ -72,8 +76,8 @@
     <detector id="7" name="DriftChamber" type="DriftChamber" readout="DriftChamberHitsCollection" vis="VisibleBlue" sensitive="true" region="DriftChamberRegion">
       <envelope vis="SeeThrough">
         <shape type="BooleanShape" operation="Union" material="Air">
-          <shape type="Tube" rmin="SDT_radius_min" rmax="909*mm" dz="SDT_half_length" />
-          <shape type="Tube" rmin="1084.8*mm" rmax="SDT_radius_max" dz="SDT_half_length" />
+          <shape type="Tube" rmin="SDT_radius_min" rmax="909*mm" dz="SDT_half_length+SDT_Endcap_dz" />
+          <shape type="Tube" rmin="1084.8*mm" rmax="SDT_radius_max" dz="SDT_half_length+SDT_Endcap_dz" />
         </shape>
       </envelope>
 
diff --git a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
index 8a978ef4..61c48f89 100644
--- a/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
+++ b/Detector/DetDriftChamber/src/driftchamber/DriftChamber.cpp
@@ -143,6 +143,14 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
       }
   }
 
+    // End cap
+    double Endcap_rmin = theDetector.constant<double>("SDT_Endcap_rmin");
+    double Endcap_rmax = theDetector.constant<double>("SDT_Endcap_rmax");
+    double Endcap_z = theDetector.constant<double>("SDT_Endcap_dz");
+    dd4hep::Tube det_Endcap_solid(Endcap_rmin,Endcap_rmax,Endcap_z);
+    dd4hep::Volume det_Endcap_vol(det_name+"Endcap",det_Endcap_solid,det_mat);
+    det_Endcap_vol.setVisAttributes(theDetector,"VisibleRed");
+
     //Initialize the segmentation
     dd4hep::Readout readout = sd.readout();
     dd4hep::Segmentation geomseg = readout.segmentation();
@@ -256,6 +264,14 @@ static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector,
        dd4hep::PlacedVolume wall_phy = envelope.placeVolume(wall_vol,transform);
     }
 
+    // - place Endcap
+    double endcap_pos[2] = {chamber_length*0.5+Endcap_z*0.5,-chamber_length*0.5-Endcap_z*0.5};
+    dd4hep::PlacedVolume endcap_phy;
+    for(int i=0; i<2; i++) {
+        dd4hep::Transform3D Endcap_transform(dd4hep::Rotation3D(),dd4hep::Position(0,0,endcap_pos[i]));
+        endcap_phy = envelope.placeVolume(det_Endcap_vol,Endcap_transform);
+   }
+
     if ( x_det.hasAttr(_U(id)) )  {
         phv.addPhysVolID("system",x_det.id());
     }
-- 
GitLab