diff --git a/DDCore/include/DD4hep/Shapes.h b/DDCore/include/DD4hep/Shapes.h index 4d7860a010eff6fdcd897387bb64dbeee6c71331..de932ffae305e4825d14d558de5ab7db6f577d58 100644 --- a/DDCore/include/DD4hep/Shapes.h +++ b/DDCore/include/DD4hep/Shapes.h @@ -502,8 +502,8 @@ namespace dd4hep { template <typename Q> Trap(const Handle<Q>& e) : Solid_type<Object>(e) { } /// Constructor to create a new anonymous object with attribute initialization Trap(double z, double theta, double phi, - double y1, double x1, double x2, double alpha1, - double y2, double x3, double x4, double alpha2); + double h1, double bl1, double tl1, double alpha1, + double h2, double bl2, double tl2, double alpha2); /// Constructor to create a new anonymous object for right angular wedge from STEP (Se G4 manual for details) Trap(double pz, double py, double px, double pLTX) { make(pz,py,px,pLTX); } /// Constructor to create a new anonymous object with attribute initialization @@ -512,9 +512,9 @@ namespace dd4hep { /// Assignment operator Trap& operator=(const Trap& copy) = default; /// Set the trap dimensions - Trap& setDimensions(double z, double theta, double phi, - double y1, double x1, double x2, double alpha1, - double y2, double x3, double x4, double alpha2); + Trap& setDimensions(double z, double theta, double phi, + double h1, double bl1, double tl1, double alpha1, + double h2, double bl2, double tl2, double alpha2); }; /// Class describing a pseudo trap shape (CMS'ism) diff --git a/DDCore/include/Parsers/detail/Dimension.h b/DDCore/include/Parsers/detail/Dimension.h index 07166bbda7a4f1d8e28209d6b4b3dc25216cfc88..eba4aafbdf9fa8e1274c0a752a3d914849f84c80 100644 --- a/DDCore/include/Parsers/detail/Dimension.h +++ b/DDCore/include/Parsers/detail/Dimension.h @@ -554,6 +554,16 @@ namespace dd4hep { Dimension position(bool throw_if_not_present = true) const; /// Child access: rotation Dimension rotation(bool throw_if_not_present = true) const; + /// Child access: cone + Dimension cone(bool throw_if_not_present = true) const; + /// Child access: sphere + Dimension sphere(bool throw_if_not_present = true) const; + /// Child access: torus + Dimension torus(bool throw_if_not_present = true) const; + /// Child access: trap + Dimension trap(bool throw_if_not_present = true) const; + /// Child access: trapezoid + Dimension trapezoid(bool throw_if_not_present = true) const; /// Child access: trd Dimension trd(bool throw_if_not_present = true) const; /// Child access: tubs @@ -562,6 +572,8 @@ namespace dd4hep { Dimension staves(bool throw_if_not_present = true) const; /// Child access: beampipe Dimension beampipe(bool throw_if_not_present = true) const; + /// Child access: beampipe + Dimension envelope(bool throw_if_not_present = true) const; /// Access "name" attribute as STL string std::string nameStr() const; diff --git a/DDCore/include/Parsers/detail/Dimension.imp b/DDCore/include/Parsers/detail/Dimension.imp index 1380c248caa926a6eeaf02deca018c2f73095064..411268fd05214aa8ab61ed925e8feafc32a45795 100644 --- a/DDCore/include/Parsers/detail/Dimension.imp +++ b/DDCore/include/Parsers/detail/Dimension.imp @@ -184,9 +184,15 @@ XML_ATTR_ACCESSOR_DOUBLE(temperature) XML_CHILD_ACCESSOR_XML_DIM(dimensions) XML_CHILD_ACCESSOR_XML_DIM(position) XML_CHILD_ACCESSOR_XML_DIM(rotation) +XML_CHILD_ACCESSOR_XML_DIM(cone) +XML_CHILD_ACCESSOR_XML_DIM(sphere) +XML_CHILD_ACCESSOR_XML_DIM(torus) +XML_CHILD_ACCESSOR_XML_DIM(trap) +XML_CHILD_ACCESSOR_XML_DIM(trapezoid) XML_CHILD_ACCESSOR_XML_DIM(trd) XML_CHILD_ACCESSOR_XML_DIM(tubs) XML_CHILD_ACCESSOR_XML_DIM(staves) +XML_CHILD_ACCESSOR_XML_DIM(envelope) XML_CHILD_ACCESSOR_XML_DIM(beampipe) std::string dd4hep::DD4HEP_DIMENSION_NS::Dimension::padType() const { diff --git a/DDCore/include/XML/UnicodeValues.h b/DDCore/include/XML/UnicodeValues.h index e13a9ad5a6b0bceb0ba18994ca54828651bdb633..f5bf9f125bf5b1d4d134dea145b8c20209d726f2 100644 --- a/DDCore/include/XML/UnicodeValues.h +++ b/DDCore/include/XML/UnicodeValues.h @@ -125,6 +125,7 @@ UNICODE (end_module); UNICODE (end_modules); UNICODE (endcap); UNICODE (endphi); +UNICODE (envelope); UNICODE (epsilon); UNICODE (eunit); UNICODE (end_x); @@ -387,6 +388,7 @@ UNICODE (sensor); UNICODE (sequence); UNICODE (setup); UNICODE (shape); +UNICODE (shield); UNICODE (show_daughters); UNICODE (showDaughters); UNICODE (size); @@ -399,6 +401,7 @@ UNICODE (solids); UNICODE (solidref); UNICODE (spacer); UNICODE (sphere); +UNICODE (station); UNICODE (status); UNICODE (start); UNICODE (start_x); @@ -430,6 +433,7 @@ UNICODE (tracker); UNICODE (tracking_cylinder); UNICODE (tracking_volume); UNICODE (trap); +UNICODE (trapezoid); UNICODE (trd); UNICODE (true); UNICODE (tube); diff --git a/DDCore/src/Shapes.cpp b/DDCore/src/Shapes.cpp index dafbadbaffb6aa37359815ba5a769424a206ffb1..7fd78f314d40e964b3e892ffa71efb87bf3e8482 100644 --- a/DDCore/src/Shapes.cpp +++ b/DDCore/src/Shapes.cpp @@ -452,7 +452,9 @@ Hyperboloid& Hyperboloid::setDimensions(double rin, double stin, double rout, do /// Constructor to be used when creating a new object with attribute initialization Sphere::Sphere(double rmin, double rmax, double theta, double delta_theta, double phi, double delta_phi) { - _assign(new TGeoSphere(rmin, rmax, theta/units::deg, delta_theta/units::deg, phi/units::deg, delta_phi/units::deg), "", "sphere", true); + _assign(new TGeoSphere(rmin, rmax, + theta/units::deg, delta_theta/units::deg, + phi/units::deg, delta_phi/units::deg), "", "sphere", true); } /// Set the Sphere dimensions @@ -475,42 +477,51 @@ Torus& Torus::setDimensions(double r, double rmin, double rmax, double phi, doub } /// Constructor to be used when creating a new anonymous object with attribute initialization -Trap::Trap(double z, double theta, double phi, double y1, double x1, double x2, double alpha1, double y2, double x3, double x4, - double alpha2) { - _assign(new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1/units::deg, y2, x3, x4, alpha2/units::deg), "", "trap", true); +Trap::Trap(double z, double theta, double phi, + double h1, double bl1, double tl1, double alpha1, + double h2, double bl2, double tl2, double alpha2) { + _assign(new TGeoTrap(z, theta/units::deg, phi/units::deg, + h1, bl1, tl1, alpha1/units::deg, + h2, bl2, tl2, alpha2/units::deg), "", "trap", true); } /// Constructor to be used when creating a new anonymous object with attribute initialization void Trap::make(double pz, double py, double px, double pLTX) { - double z = pz / 2e0; - double theta = 0e0; - double phi = 0e0; - double y1 = py / 2e0; - double x1 = px / 2e0; - double x2 = pLTX / 2e0; + double z = pz / 2e0; + double theta = 0e0; + double phi = 0e0; + double h = py / 2e0; + double bl = px / 2e0; + double tl = pLTX / 2e0; double alpha1 = (pLTX - px) / py; - _assign(new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1/units::deg, y1, x1, x2, alpha1/units::deg), "", "trap", true); + _assign(new TGeoTrap(z, theta, phi, + h, bl, tl, alpha1/units::deg, + h, bl, tl, alpha1/units::deg), "", "trap", true); } /// Set the trap dimensions -Trap& Trap::setDimensions(double z, double theta, double phi, double y1, double x1, double x2, double alpha1, double y2, - double x3, double x4, double alpha2) { - double params[] = { z, theta, phi, y1, x1, x2, alpha1/units::deg, y2, x3, x4, alpha2/units::deg }; +Trap& Trap::setDimensions(double z, double theta, double phi, + double h1, double bl1, double tl1, double alpha1, + double h2, double bl2, double tl2, double alpha2) { + double params[] = { z, theta/units::deg, phi/units::deg, + h1, bl1, tl1, alpha1/units::deg, + h2, bl2, tl2, alpha2/units::deg }; _setDimensions(params); return *this; } /// Internal helper method to support object construction void PseudoTrap::make(double x1, double x2, double y1, double y2, double z, double r, bool atMinusZ) { - double x = atMinusZ ? x1 : x2; - double h = 0; - bool intersec = false; // union or intersection solid - double halfOpeningAngle = std::asin( x / std::abs( r ))/units::deg; + double x = atMinusZ ? x1 : x2; + double h = 0; + bool intersec = false; // union or intersection solid double displacement = 0; - double startPhi = 0; - double halfZ = z/2.; - /* calculate the displacement of the tubs w.r.t. to the trap, determine the opening angle of the tubs */ - double delta = std::sqrt( r * r - x * x ); + double startPhi = 0; + double halfZ = z; + double halfOpeningAngle = std::asin( x / std::abs( r ))/units::deg; + + /// calculate the displacement of the tubs w.r.t. to the trap, determine the opening angle of the tubs + double delta = std::sqrt( r * r - x * x ); if( r < 0 && std::abs( r ) >= x ) { intersec = true; // intersection solid diff --git a/DDDetectors/src/ConeSegment_geo.cpp b/DDDetectors/src/ConeSegment_geo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b9f87826fe3a6c621dfa852bd17f27d89d88b73 --- /dev/null +++ b/DDDetectors/src/ConeSegment_geo.cpp @@ -0,0 +1,54 @@ +//========================================================================== +// 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 +// +//========================================================================== +// +// Specialized generic detector constructor +// +//========================================================================== +#include "DD4hep/DetFactoryHelper.h" + +using namespace std; +using namespace dd4hep; +using namespace dd4hep::detail; + +static Ref_t create_element(Detector& description, xml_h e, Ref_t sens) { + xml_det_t x_det (e); + xml_comp_t x_cone = x_det.cone(); + xml_dim_t pos = x_det.position(); + xml_dim_t rot = x_det.rotation(); + string name = x_det.nameStr(); + Cone cone (x_cone.dz(),x_cone.rmin1(),x_cone.rmax1(),x_cone.rmin2(),x_cone.rmax2()); + Volume vol (name,cone,description.material(x_det.materialStr())); + + vol.setVisAttributes(description, x_det.visStr()); + vol.setLimitSet(description, x_det.limitsStr()); + vol.setRegion(description, x_det.regionStr()); + if ( x_det.isSensitive() ) { + SensitiveDetector sd = sens; + xml_dim_t sd_typ = x_det.child(_U(sensitive)); + vol.setSensitiveDetector(sens); + sd.setType(sd_typ.typeStr()); + } + + DetElement sdet(name,x_det.id()); + Volume mother = description.pickMotherVolume(sdet); + PlacedVolume phv = + mother.placeVolume(vol,Transform3D(RotationZYX(rot.z(),rot.y(),rot.x()),Position(-pos.x(),-pos.y(),pos.z()))); + if ( x_det.hasAttr(_U(id)) ) { + phv.addPhysVolID("system",x_det.id()); + } + sdet.setPlacement(phv); + return sdet; +} + +DECLARE_DETELEMENT(DD4hep_ConeSegment,create_element) + diff --git a/examples/DDCodex/CMakeLists.txt b/examples/DDCodex/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e61b4889cfd31a01146f3a9a86eca5fc7fc8c7c2 --- /dev/null +++ b/examples/DDCodex/CMakeLists.txt @@ -0,0 +1,34 @@ +#========================================================================== +# 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. +# +#========================================================================== +cmake_minimum_required(VERSION 3.3 FATAL_ERROR) +include ( ${DD4hep_DIR}/cmake/DD4hep.cmake ) + +#----------------------------------------------------------------------------------- +dd4hep_configure_output () +dd4hep_package ( DDCodex MAJOR 0 MINOR 0 PATCH 1 + USES [ROOT REQUIRED COMPONENTS Geom] + [DD4hep REQUIRED COMPONENTS DDCore] + ) +# +#---DDCodex plugin library ------------------------------------------------------- +dd4hep_add_plugin(DDCodexPlugins + SOURCES src/*.cpp + USES [ROOT REQUIRED COMPONENTS Geom GenVector] +) +# +# +dd4hep_install_dir( compact scripts DESTINATION ${DD4hep_DIR}/examples/DDCodex ) +#-------------------------------------------------------------------------- +# +dd4hep_configure_scripts ( DDCodex DEFAULT_SETUP WITH_TESTS ) +# +#---Testing------------------------------------------------------------------------- +# diff --git a/examples/DDCodex/CODEX-b.jpg b/examples/DDCodex/CODEX-b.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6998e2bd3618c8cd8976db3d364f32de5f285a18 Binary files /dev/null and b/examples/DDCodex/CODEX-b.jpg differ diff --git a/examples/DDCodex/README.txt b/examples/DDCodex/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..617ba4d5f3f95c1022835ffe83ea00bc932be531 --- /dev/null +++ b/examples/DDCodex/README.txt @@ -0,0 +1,77 @@ +CODEX starting kit +================== + + +Small geometry driver for CODEX-b sketch. + + +To execute: +---------------------------------------------------------------------------- +$> geoPluginRun -ui -inter +... +root [0] gDD4hepUI->importROOT("Upgrade.root") +root [1] gDD4hepUI->fromXML("checkout/examples/DDCodex/compact/CODEX-b.xml") +root [2] gDD4hepUI->draw() + + +Output: +---------------------------------------------------------------------------- +17:25:30-frankm~/SW/DD4hep_head_dbg.root_v6.12.06.g4_10.04.p01_MT/build$ geoPluginRun -ui -inter +PersistencyIO INFO +++ Set Streamer to dd4hep::OpaqueDataBlock +PersistencyIO INFO +++ Patching TGeoVolume.fUserExtension to persistent +PersistencyIO INFO +++ Patching TGeoNode.fUserExtension to persistent +Info in <TGeoManager::TGeoManager>: Geometry world, Detector Geometry created +geoPluginRun: No geometry input supplied. No geometry will be loaded. +DD4hepUI Use the ROOT interpreter variable gDD4hepUI to interact with the detector description. + ------------------------------------------------------------ + | Welcome to ROOT 6.12/06 http://root.cern.ch | + | (c) 1995-2017, The ROOT Team | + | Built for linuxx8664gcc | + | From tag v6-12-06, 9 February 2018 | + | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' | + ------------------------------------------------------------ + +root [0] gDD4hepUI->importROOT("Upgrade.root") +DD4hepRootLoader INFO +++ Read geometry from root file:Upgrade.root +Warning in <TGeoManager::Init>: Deleting previous geometry: world/Detector Geometry +Info in <TGeoManager::CloseGeometry>: Geometry loaded from file... +Info in <TGeoManager::SetTopVolume>: Top volume is world_volume. Master volume is world_volume +Info in <TGeoNavigator::BuildCache>: --- Maximum geometry depth set to 100 +Info in <TGeoManager::Voxelize>: Voxelizing... +Error in <TGeoVoxelFinder::SortAll>: Volume lvAsicGroup16: Cannot make slices on any axis +Error in <TGeoVoxelFinder::SortAll>: Volume lvAsicGroup4: Cannot make slices on any axis +Error in <TGeoVoxelFinder::SortAll>: Volume lvAsicGroup8: Cannot make slices on any axis +Info in <TGeoManager::CountLevels>: max level = 11, max placements = 171 +Info in <TGeoManager::CloseGeometry>: 18553873 nodes/ 2754 volume UID's in Detector Geometry +Info in <TGeoManager::CloseGeometry>: ----------------modeler ready---------------- +DD4hepRootPersistency +++ Fixed 0 segmentation objects. +DD4hepRootPersistency +++ Volume manager NOT restored. [Was it ever up when saved?] +DD4hepRootPersistency +++ Successfully loaded detector description from file:Upgrade.root [ 7.322 seconds] +(long) 1 +root [1] gDD4hepUI->fromXML("checkout/examples/DDCodex/compact/CODEX-b.xml") +CODEX-b INFO COBEXb Envelope: dz=2000 r1=0 r2=400 beam-angle=1.0472 atan(cone)=0.0996687 +CODEX-b INFO COBEXb Shield: Pb-shield-1 [Lead] z= 700 dz= 150 r1=69.6526 r2=84.5782 +CODEX-b INFO COBEXb Shield: Shield-veto [Si] z= 850 dz= 10 r1=84.5782 r2=85.5732 +CODEX-b INFO COBEXb Shield: Pb-shield-2 [Lead] z= 860 dz= 50 r1=85.5732 r2=90.5484 +CODEX-b INFO COBEXb X_tot= 532 +CODEX-b INFO COBEXb Module: 0 [Si] x=-307.15 y=0 z= 1732 Dist:22 dx:25.4034 dz:44 +CODEX-b INFO COBEXb Module: 1 [Si] x=-281.747 y=0 z= 1776 Dist:22 dx:25.4034 dz:44 +CODEX-b INFO COBEXb Module: 2 [Si] x=-256.344 y=0 z= 1820 Dist:22 dx:25.4034 dz:44 +CODEX-b INFO COBEXb Module: 3 [Si] x=-230.94 y=0 z= 1864 Dist:32 dx:36.9504 dz:64 +CODEX-b INFO COBEXb Module: 4 [Si] x=-193.99 y=0 z= 1928 Dist:32 dx:36.9504 dz:64 +CODEX-b INFO COBEXb Module: 5 [Si] x=-157.039 y=0 z= 1992 Dist:32 dx:36.9504 dz:64 +CODEX-b INFO COBEXb Module: 6 [Si] x=-120.089 y=0 z= 2056 Dist:32 dx:36.9504 dz:64 +CODEX-b INFO COBEXb Module: 7 [Si] x=-83.1384 y=0 z= 2120 Dist:32 dx:36.9504 dz:64 +CODEX-b INFO COBEXb Module: 8 [Si] x=-46.188 y=0 z= 2184 Dist:32 dx:36.9504 dz:64 +CODEX-b INFO COBEXb Module: 9 [Si] x=-9.2376 y=0 z= 2248 Dist:32 dx:36.9504 dz:64 +CODEX-b INFO COBEXb Module: 10 [Si] x=27.7128 y=0 z= 2312 Dist:32 dx:36.9504 dz:64 +CODEX-b INFO COBEXb Module: 11 [Si] x=64.6632 y=0 z= 2376 Dist:42 dx:48.4974 dz:84 +CODEX-b INFO COBEXb Module: 12 [Si] x=113.161 y=0 z= 2460 Dist:42 dx:48.4974 dz:84 +CODEX-b INFO COBEXb Module: 13 [Si] x=161.658 y=0 z= 2544 Dist:42 dx:48.4974 dz:84 +CODEX-b INFO COBEXb Module: 14 [Si] x=210.155 y=0 z= 2628 Dist:42 dx:48.4974 dz:84 +CODEX-b INFO COBEXb Module: 15 [Si] x=258.653 y=0 z= 2712 Dist:42 dx:48.4974 dz:84 +Compact INFO ++ Converted subdetector:COBEXb of type DD4hep_CODEXb +root [2] gDD4hepUI->draw() +Info in <TGeoManager::SetVisLevel>: Automatic visible depth disabled +Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 +root [3] diff --git a/examples/DDCodex/compact/CODEX-b.xml b/examples/DDCodex/compact/CODEX-b.xml new file mode 100644 index 0000000000000000000000000000000000000000..4a97c7da08b990776594e7333ff896706252dbcc --- /dev/null +++ b/examples/DDCodex/compact/CODEX-b.xml @@ -0,0 +1,53 @@ +<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> +<!-- + <includes> + <gdmlFile ref="elements.xml"/> + <gdmlFile ref="materials.xml"/> + </includes> +--> + <define> + <constant name="COBEX_beam_angle" value="60*degree"/> + <constant name="COBEX_cone_len" value="40*m"/> + </define> + + <comment>Common Generic visualization attributes</comment> + <display> + <vis name="BlackVis" alpha="1" r="0.1" g="0.1" b="0.1" showDaughters="false" visible="true"/> + <vis name="Codex_Envelope_Vis" alpha=".3" r="0.7" g="0.7" b="0.7" showDaughters="true" visible="true"/> + <vis name="Codex_Module1_Vis" alpha="1" r="0.8" g="0.2" b="0.2" showDaughters="true" visible="true"/> + <vis name="Codex_Module2_Vis" alpha="1" r="0.2" g="0.8" b="0.2" showDaughters="true" visible="true"/> + <vis name="Codex_Module3_Vis" alpha="1" r="0.2" g="0.2" b="0.8" showDaughters="true" visible="true"/> + <vis name="Codex_Shield_Pb_Vis" alpha="1" r="0.4" g="0.4" b="0.4" showDaughters="false" visible="true"/> + <vis name="Codex_Shield_Veto_Vis" alpha="1" r="0.9" g="0.9" b="0.0" showDaughters="true" visible="true"/> + </display> + + <geometry open="false" close="false"/> + + <!-- Includes for sensitives and support --> + <detectors> + + <detector name="COBEXb" type="DD4hep_CODEXb" vis="Codex_Envelope_Vis"> + <envelope angle="COBEX_beam_angle" dz="COBEX_cone_len" rmax="4*m"/> + <shield name="Pb-shield-1" z="7*m" dz="1.5*m" material="Lead" sensitive="false" vis="Codex_Shield_Pb_Vis"/> + <shield name="Shield-veto" z="8.5*m" dz="0.1*m" material="Si" sensitive="true" vis="Codex_Shield_Veto_Vis"/> + <shield name="Pb-shield-2" z="8.6*m" dz="0.5*m" material="Lead" sensitive="false" vis="Codex_Shield_Pb_Vis"/> + + <station z="12*m" width="10*m" height="10*m" thickness="2*cm" + material="Si" sensitive="true" vis="Codex_Module1_Vis" + repeat="3" distance="20*cm"/> + <station width="10*m" height="10*m" thickness="2*cm" + material="Si" sensitive="true" vis="Codex_Module2_Vis" + repeat="8" distance="30*cm"/> + <station width="10*m" height="10*m" thickness="2*cm" + material="Si" sensitive="true" vis="Codex_Module3_Vis" + repeat="5" distance="40*cm"/> + + <position x="-sin(COBEX_beam_angle)*COBEX_cone_len/2" y="0" z="cos(COBEX_beam_angle)*COBEX_cone_len/2"/> + <rotation x="0" y="COBEX_beam_angle" z="0"/> + + </detector> + </detectors> + +</lccdd> diff --git a/examples/DDCodex/src/CODEXb_geo.cpp b/examples/DDCodex/src/CODEXb_geo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e104a07dd92a5fc947c9e7fdc51cb7990ca9653 --- /dev/null +++ b/examples/DDCodex/src/CODEXb_geo.cpp @@ -0,0 +1,130 @@ +//========================================================================== +// 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 +// +//========================================================================== +// +// Specialized generic detector constructor +// +//========================================================================== +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/Printout.h" + +using namespace std; +using namespace dd4hep; +using namespace dd4hep::detail; + + +static Ref_t create_element(Detector& description, xml_h e, Ref_t sens) { + xml_det_t x_det (e); + xml_comp_t x_envelope = x_det.envelope(); + xml_dim_t pos = x_det.position(); + xml_dim_t rot = x_det.rotation(); + string det_name = x_det.nameStr(); + DetElement sdet(det_name,x_det.id()); + double env_angle = x_envelope.angle(); + double env_dz = x_envelope.dz()/2.0; + double sin_cone = std::sin(std::atan(x_envelope.rmax()/env_dz/2.0)); + double cos_beam = std::cos(env_angle); + double sin_beam = std::sin(env_angle); + Cone env_cone(env_dz,0,0.0001,x_envelope.rmax(),x_envelope.rmax()+0.0001); + Volume env_vol (det_name,env_cone,description.air()); + PlacedVolume pv; + + env_vol.setRegion(description, x_det.regionStr()); + env_vol.setLimitSet(description, x_det.limitsStr()); + env_vol.setVisAttributes(description, x_det.visStr()); + printout(INFO,"CODEX-b","%s Envelope: dz=%g r1=%g r2=%g beam-angle=%g atan(cone)=%g", + det_name.c_str(), env_cone->GetDz(), env_cone->GetRmin1(), env_cone->GetRmax2(), + env_angle, std::atan(x_envelope.rmax()/env_dz/2.0)); + + Tube tub(0, 3, x_envelope.dz()+500); + Volume tub_vol("Tube", tub, description.air()); + tub_vol.setVisAttributes(description, "BlackVis"); + pv = env_vol.placeVolume(tub_vol, Position(0,0,0)); + + int num_sensitive = 0; + for(xml_coll_t i(x_det,_U(shield)); i; ++i) { + xml_comp_t s = i; + double z = s.z(), dz = s.dz(); + double r1 = sin_cone*z, r2 = sin_cone*(z+dz); + string nam = s.nameStr(); + Cone con(dz/2., 0., r1, 0., r2); + Material mat(description.material(s.attr<string>(_U(material)))); + Volume vol(nam,con,mat); + + printout(INFO,"CODEX-b","%s Shield: %-12s %-12s z=%7g dz=%7g r1=%7g r2=%7g", + det_name.c_str(), vol.name(), ('['+string(mat.name())+']').c_str(), z, dz, r1, r2); + vol.setVisAttributes(description, s.visStr()); + pv = env_vol.placeVolume(vol, Position(0,0,-env_dz+z+dz/2.0)); + if ( s.isSensitive() ) { + DetElement det(sdet, "shield_"+nam, x_det.id()); + pv.addPhysVolID("type", 0); + pv.addPhysVolID("module", num_sensitive); + det.setPlacement(pv); + ++num_sensitive; + } + } + + int type_num = 0, station_number = 0; + double z0 = 0.0, x0 = 0.0, x_tot = 0.0; + for(xml_coll_t i(x_det,_U(station)); i; ++i, ++type_num) { + xml_comp_t s = i; + x_tot += double(s.repeat())*(s.distance()+s.thickness()); + } + printout(INFO,"CODEX-b","%s X_tot= %g",det_name.c_str(), x_tot); + for(xml_coll_t i(x_det,_U(station)); i; ++i, ++type_num) { + xml_comp_t s = i; + int repeat = s.repeat(); + string nam = _toString(station_number,"CODEX_station_type%d"); + Box box(s.width()/2., s.height()/2., s.thickness()/2.); + Material mat(description.material(s.attr<string>(_U(material)))); + Volume vol(nam,box,mat); + double dist = s.thickness()+s.distance(); + double dx = dist/sin_beam; + double dz = dist/cos_beam; + if ( s.hasAttr(_U(z)) ) { + z0 = s.z()+x_tot/2.0/cos_beam; + x0 = -x_tot/2.0/sin_beam; + } + vol.setVisAttributes(description, s.visStr()); + for(int j=0; j < repeat; ++j) { + DetElement det(sdet, _toString(station_number,"module%d"), station_number); + pv = env_vol.placeVolume(vol, Transform3D(RotationZYX(0,M_PI/2.0-env_angle,0), Position(x0,0,z0))); + pv.addPhysVolID("type", 1); + pv.addPhysVolID("module", station_number); + printout(INFO,"CODEX-b","%s Module: %2d %-12s x=%g y=%g z=%7g Dist:%g dx:%g dz:%g", + det_name.c_str(), station_number, ('['+string(mat.name())+']').c_str(), + x0, 0.0, z0, dist, dx, dz); + det.setPlacement(pv); + x0 += dx; + z0 += dz; + ++station_number; + } + } + + if ( x_det.isSensitive() ) { + SensitiveDetector sd = sens; + xml_dim_t sd_typ = x_det.child(_U(sensitive)); + env_vol.setSensitiveDetector(sens); + sd.setType(sd_typ.typeStr()); + } + + Volume mother = description.pickMotherVolume(sdet); + pv = mother.placeVolume(env_vol,Transform3D(RotationZYX(rot.z(),rot.y(),rot.x()),Position(-pos.x(),-pos.y(),pos.z()))); + if ( x_det.hasAttr(_U(id)) ) { + pv.addPhysVolID("system",x_det.id()); + } + sdet.setPlacement(pv); + return sdet; +} + +DECLARE_DETELEMENT(DD4hep_CODEXb,create_element) +