From ce3bc07084bfdfbeb04695b6c9ae1c395d65acb8 Mon Sep 17 00:00:00 2001
From: Frank Gaede <frank.gaede@desy.de>
Date: Tue, 29 Apr 2014 12:43:58 +0000
Subject: [PATCH]    - added some assemblies to VXd, SIT and AhcalEndcap     
 to provide some hierarchical strucutre to the geometry

---
 .../src/AhcalEndcapCalorimeter_geo.cpp        | 25 ++++++++++++++-----
 examples/ILDExDet/src/ILDExSIT_geo.cpp        | 17 +++++++++++--
 examples/ILDExDet/src/ILDExVXD_geo.cpp        |  2 +-
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/examples/ILDExDet/src/AhcalEndcapCalorimeter_geo.cpp b/examples/ILDExDet/src/AhcalEndcapCalorimeter_geo.cpp
index 0610f4241..d4afa38dd 100644
--- a/examples/ILDExDet/src/AhcalEndcapCalorimeter_geo.cpp
+++ b/examples/ILDExDet/src/AhcalEndcapCalorimeter_geo.cpp
@@ -38,6 +38,11 @@ static Ref_t create_detector(LCDD& lcdd, xml_h element, SensitiveDetector sens)
   xml_dim_t   dim         = x_det.dimensions();
   string      det_name    = x_det.nameStr();
   string      det_type    = x_det.typeStr();
+
+  Assembly    assembly(det_name+"_assembly");
+  // Assembly    assembly_fwd(det_name+"_assembly_fwd");
+  // Assembly    assembly_bwd(det_name+"_assembly_bwd");
+
   Material    air         = lcdd.air();
   Material    Steel235    = lcdd.material(x_det.materialStr());
   double      gap         = xml_dim_t(x_det).gap();
@@ -87,7 +92,6 @@ static Ref_t create_detector(LCDD& lcdd, xml_h element, SensitiveDetector sens)
   
   
   DetElement   sdet(det_name,x_det.id());
-  Volume      motherVol = lcdd.pickMotherVolume(sdet); 
   
   // ========= Create Hcal Endcap Modules envelope ============================
   //  They will be the volume for palcing the Hcal Chamber(i.e. Layers).
@@ -258,12 +262,15 @@ static Ref_t create_detector(LCDD& lcdd, xml_h element, SensitiveDetector sens)
 	  
 	  EndcapModule_pos_z = (module_num==0)?EndcapModule_pos_z:-EndcapModule_pos_z;
 
-	  PlacedVolume env_phv = motherVol.placeVolume(envelopeVol,
-						       Transform3D(RotationX(rot_EM),
-								   Translation3D(EndcapModule_pos_x,
-										 EndcapModule_pos_y,
-										 EndcapModule_pos_z)));
+	  //	  Assembly& assembly = (module_num==0)?assembly_fwd:assembly_bwd;
+	  
+	  PlacedVolume env_phv = assembly.placeVolume(envelopeVol,
+						      Transform3D(RotationX(rot_EM),
+								  Translation3D(EndcapModule_pos_x,
+										EndcapModule_pos_y,
+										EndcapModule_pos_z)));
 	  
+
 	  env_phv.addPhysVolID("stave",stave_num);   // y: up /down
 	  env_phv.addPhysVolID("module",module_num); // z: +/-
 	  env_phv.addPhysVolID("system",x_det.id());
@@ -276,6 +283,12 @@ static Ref_t create_detector(LCDD& lcdd, xml_h element, SensitiveDetector sens)
     }
   
   
+
+  Volume mother = lcdd.pickMotherVolume(sdet); 
+  PlacedVolume pv = mother.placeVolume(assembly);
+  pv.addPhysVolID( "system", x_det.id() )  ;
+  
+  sdet.setPlacement(pv);
   
   return sdet;
 }
diff --git a/examples/ILDExDet/src/ILDExSIT_geo.cpp b/examples/ILDExDet/src/ILDExSIT_geo.cpp
index 22a74713c..c75b4857c 100644
--- a/examples/ILDExDet/src/ILDExSIT_geo.cpp
+++ b/examples/ILDExDet/src/ILDExSIT_geo.cpp
@@ -24,7 +24,7 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens)  {
   xml_det_t    x_det = e;
   string       name  = x_det.nameStr();
   DetElement   sit(name,x_det.id());
-  Assembly assembly( name + "assembly"  ) ;
+  Assembly assembly( name + "_assembly"  ) ;
   PlacedVolume pv;
 
   
@@ -64,6 +64,19 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens)  {
     Volume      suppvol   (layername+"_supp",suppbox,lcdd.material(x_support.materialStr()));
 
 
+    // --- create an assembly and DetElement for the layer 
+
+    Assembly     layer_assembly( layername );
+    
+    DetElement   layerDE( sit , _toString(layer_id,"layer_%d"), x_det.id() );
+    
+    pv = assembly.placeVolume(  layer_assembly );
+    pv.addPhysVolID("layer", layer_id );  
+
+    layerDE.setPlacement( pv ) ;
+
+    //--------------------------------
+
     // create a measurement plane for the tracking surface attched to the sensitive volume 
     Vector3D u( 0. , 1. , 0. ) ;
     Vector3D v( 0. , 0. , 1. ) ;
@@ -105,7 +118,7 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens)  {
       string laddername = layername + _toString(j,"_ladder%d");
       Position pos(radius*cos(j*dphi),radius*sin(j*dphi),0.);
 
-      pv = assembly.placeVolume(laddervol,Transform3D(RotationZ(j*dphi),pos));
+      pv = layer_assembly.placeVolume(laddervol,Transform3D(RotationZ(j*dphi),pos));
 
       // this will result int the correct cellID to be set...
       pv.addPhysVolID("layer",layer_id).addPhysVolID("module",j).addPhysVolID("sensor",0 ) ;
diff --git a/examples/ILDExDet/src/ILDExVXD_geo.cpp b/examples/ILDExDet/src/ILDExVXD_geo.cpp
index a081cd478..66ad3a608 100644
--- a/examples/ILDExDet/src/ILDExVXD_geo.cpp
+++ b/examples/ILDExDet/src/ILDExVXD_geo.cpp
@@ -65,7 +65,7 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens)  {
 
 
     /// ======== test layer assembly -> results in assembly in assembly and
-#define use_layer_assembly 0         // crashes ild_exsimu
+#define use_layer_assembly 1        // crashes ild_exsimu
 #if use_layer_assembly 
 
     // --- create an assembly and DetElement for the layer 
-- 
GitLab