From b1f0d356c6008e1c93149401df37cee0e2394153 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Thu, 9 Jun 2022 14:34:21 +0200
Subject: [PATCH] Improve examples

---
 .../ref/Ref_Eightpoint_Reflect_Volume.1.txt   | 22 +++++++++
 examples/ClientTests/scripts/TestGDML.C       | 47 ++++++++++++++++++
 examples/ClientTests/src/SingleShape_geo.cpp  | 49 +++++++++++++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 examples/ClientTests/ref/Ref_Eightpoint_Reflect_Volume.1.txt
 create mode 100644 examples/ClientTests/scripts/TestGDML.C
 create mode 100644 examples/ClientTests/src/SingleShape_geo.cpp

diff --git a/examples/ClientTests/ref/Ref_Eightpoint_Reflect_Volume.1.txt b/examples/ClientTests/ref/Ref_Eightpoint_Reflect_Volume.1.txt
new file mode 100644
index 000000000..b72ba6fe3
--- /dev/null
+++ b/examples/ClientTests/ref/Ref_Eightpoint_Reflect_Volume.1.txt
@@ -0,0 +1,22 @@
+ShapeCheck[0] TGeoArb8         8 Mesh-points:
+TGeoArb8         EightPointSolid N(mesh)=8  N(vert)=8  N(seg)=12  N(pols)=6
+TGeoArb8         0   Local  ( -30.00,  -25.00,  -30.00) Global ( -30.00,  -25.00,   70.00)
+TGeoArb8         1   Local  ( -25.00,   25.00,  -30.00) Global ( -25.00,   25.00,   70.00)
+TGeoArb8         2   Local  (   5.00,   25.00,  -30.00) Global (   5.00,   25.00,   70.00)
+TGeoArb8         3   Local  (  25.00,  -25.00,  -30.00) Global (  25.00,  -25.00,   70.00)
+TGeoArb8         4   Local  ( -28.00,  -23.00,   30.00) Global ( -28.00,  -23.00,  130.00)
+TGeoArb8         5   Local  ( -23.00,   27.00,   30.00) Global ( -23.00,   27.00,  130.00)
+TGeoArb8         6   Local  ( -23.00,   27.00,   30.00) Global ( -23.00,   27.00,  130.00)
+TGeoArb8         7   Local  (  13.00,  -27.00,   30.00) Global (  13.00,  -27.00,  130.00)
+TGeoArb8         Bounding box:  dx=  27.50 dy=  27.00 dz=  30.00 Origin: x=  -2.50 y=   0.00 z=   0.00
+ShapeCheck[1] TGeoScaledShape  8 Mesh-points:
+TGeoScaledShape  Shape_Trapezoid_vol_1_shape_refl N(mesh)=8  N(vert)=8  N(seg)=12  N(pols)=6
+TGeoScaledShape  0   Local  ( -30.00,  -25.00,   30.00) Global ( -30.00,  -25.00,  -70.00)
+TGeoScaledShape  1   Local  ( -25.00,   25.00,   30.00) Global ( -25.00,   25.00,  -70.00)
+TGeoScaledShape  2   Local  (   5.00,   25.00,   30.00) Global (   5.00,   25.00,  -70.00)
+TGeoScaledShape  3   Local  (  25.00,  -25.00,   30.00) Global (  25.00,  -25.00,  -70.00)
+TGeoScaledShape  4   Local  ( -28.00,  -23.00,  -30.00) Global ( -28.00,  -23.00, -130.00)
+TGeoScaledShape  5   Local  ( -23.00,   27.00,  -30.00) Global ( -23.00,   27.00, -130.00)
+TGeoScaledShape  6   Local  ( -23.00,   27.00,  -30.00) Global ( -23.00,   27.00, -130.00)
+TGeoScaledShape  7   Local  (  13.00,  -27.00,  -30.00) Global (  13.00,  -27.00, -130.00)
+TGeoScaledShape  Bounding box:  dx=  27.50 dy=  27.00 dz=  30.00 Origin: x=  -2.50 y=   0.00 z=  -0.00
diff --git a/examples/ClientTests/scripts/TestGDML.C b/examples/ClientTests/scripts/TestGDML.C
new file mode 100644
index 000000000..64db1e6cb
--- /dev/null
+++ b/examples/ClientTests/scripts/TestGDML.C
@@ -0,0 +1,47 @@
+#include <TGeoManager.h>
+#include <TGeoVolume.h>
+#include <TGeoElement.h>
+#include <TGeoMedium.h>
+#include <TSystem.h>
+#include <TGDMLWrite.h>
+#include <TGeoSystemOfUnits.h>
+#include <TGeant4SystemOfUnits.h>
+
+
+int TestGDML()   {
+  TGeoManager::LockDefaultUnits(false);
+
+  //TGeoManager::SetDefaultUnits(TGeoManager::kRootUnits);
+  //double unit_of_density = (TGeoUnit::g/TGeoUnit::cm3);
+  //double gramm_per_mole  =  (TGeoUnit::g/TGeoUnit::mole);
+  TGeoManager::SetDefaultUnits(TGeoManager::kG4Units);
+  //double unit_of_density = (TGeant4Unit::g/TGeant4Unit::cm3);
+  //double gramm_per_mole  =  (TGeant4Unit::g/TGeant4Unit::mole);
+  
+  TGeoManager::LockDefaultUnits(true);
+  TGeoManager* mgr = new TGeoManager();
+  TGeoElement* e = new TGeoElement("H","Hydro",1,3.0);
+  e->Print();
+
+  TGeoBBox*     world_shape = new TGeoBBox("WorldBox",100,100,100);
+  TGeoMaterial* world_mat   = mgr->GetMaterial("Hydrogen-1");
+  if ( !world_mat ) world_mat = new TGeoMaterial("Hydrogen-1", e, 1.0);
+  world_mat->Print();
+  TGeoMedium* world_med = new TGeoMedium(world_mat->GetName(), 1, world_mat);
+  TGeoVolume* world_vol = new TGeoVolume("World", world_shape, world_med);
+
+  TGeoBBox*     inner_shape = new TGeoBBox("InnerBox", 50, 50, 50);
+  TGeoMaterial* inner_mat   = mgr->GetMaterial("Hydrogen-2");
+  if ( !inner_mat ) inner_mat = new TGeoMaterial("Hydrogen-2", e, 5.0);
+  inner_mat->Print();
+  TGeoMedium* inner_med = new TGeoMedium(inner_mat->GetName(), 1, inner_mat);
+  TGeoVolume* inner_vol = new TGeoVolume("Inner", inner_shape, inner_med);
+
+  world_vol->AddNode(inner_vol, 1);
+  mgr->SetTopVolume(world_vol);
+  TGDMLWrite wr;
+  wr.WriteGDMLfile(mgr, "Test.gdml");
+  //world_vol->Draw("ogl");
+  gSystem->Exit(0);
+  return 0;
+}
diff --git a/examples/ClientTests/src/SingleShape_geo.cpp b/examples/ClientTests/src/SingleShape_geo.cpp
new file mode 100644
index 000000000..d478b2a80
--- /dev/null
+++ b/examples/ClientTests/src/SingleShape_geo.cpp
@@ -0,0 +1,49 @@
+//==========================================================================
+//  AIDA Detector description implementation 
+//--------------------------------------------------------------------------
+// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
+// All rights reserved.
+//
+// For the licensing terms see $DD4hepINSTALL/LICENSE.
+// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
+//
+// Author     : M.Frank
+//
+//==========================================================================
+
+// Framework includes
+#include <DD4hep/DetFactoryHelper.h>
+#include <XML/Utilities.h>
+
+using namespace dd4hep;
+using namespace dd4hep::detail;
+
+static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens)  {
+  xml_dim_t x_det = e;  
+  xml_comp_t xshape (x_det.child(_U(shape)));
+  xml_dim_t  xpos   (x_det.child(_U(position), false));
+  xml_elt_t  xmat   (x_det.child(_U(material)));
+  xml_dim_t  xshpos (xshape.child(_U(position)));
+  xml_dim_t  xbox   (x_det.child(_U(box)));
+  DetElement d_det(x_det.nameStr(),x_det.id());
+  Volume assembly(x_det.nameStr()+"_vol", Box(xbox.x(), xbox.y(), xbox.z()), description.air());
+  //Assembly  assembly(x_det.nameStr()+"_envelope");
+  Material   mat    (description.material(xmat.attr<std::string>(_U(name))));
+  Position   pos(xpos.x(),xpos.y(),xpos.z());
+  Solid  sh  = xml::createShape(description, xshape.typeStr(), xshape);
+  Volume vol = Volume(x_det.nameStr()+"_vol", sh, mat);
+  PlacedVolume pv;
+
+  sens.setType("calorimeter");
+  vol.setVisAttributes(description, x_det.visStr());
+  vol.setSensitiveDetector(sens);
+  
+  assembly.setVisAttributes(description, xbox.attr<std::string>(_U(vis)));
+  assembly.placeVolume(vol,Position(xshpos.x(),xshpos.y(),xshpos.z()));
+  pv = description.pickMotherVolume(d_det).placeVolume(assembly, pos);
+  pv.addPhysVolID("system",x_det.id());
+  d_det.setPlacement(pv);
+  return d_det;
+}
+
+DECLARE_DETELEMENT(DD4hep_SingleShape,create_detector)
-- 
GitLab