DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
SubdetectorAssembly_geo.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 //
14 // Specialized generic detector constructor
15 //
16 //==========================================================================
18 #include "DD4hep/Printout.h"
19 #include "XML/Utilities.h"
20 
21 using namespace std;
22 using namespace dd4hep;
23 using namespace dd4hep::detail;
24 
25 static Ref_t create_element(Detector& description, xml_h e, Ref_t) {
26  xml_det_t x_det (e);
27  string det_name = x_det.nameStr();
28  DetElement sdet(det_name, x_det.id());
29  Volume vol;
30 
31  bool useRot = x_det.hasChild(_U(rotation));
32  bool usePos = x_det.hasChild(_U(position));
33  Position pos;
34  RotationZYX rot;
35 
36  sdet.setType("compound");
37  xml::setDetectorTypeFlag( e, sdet ) ;
38 
39  if( usePos ) {
40  pos = Position(x_det.position().x(), x_det.position().y(), x_det.position().z());
41  }
42  if( useRot ) {
43  rot = RotationZYX(x_det.rotation().x(), x_det.rotation().y(), x_det.rotation().z());
44  }
45 
46  if ( x_det.hasChild(_U(shape)) ) {
47  xml_comp_t x_shape = x_det.child(_U(shape));
48  string type = x_shape.typeStr();
49  Solid solid = xml::createShape(description, type, x_shape);
50  Material mat = description.material(x_shape.materialStr());
51  printout(DEBUG,det_name,"+++ Creating detector assembly with shape of type:%s",type.c_str());
52  vol = Volume(det_name,solid,mat);
53  }
54  else {
55  printout(DEBUG,det_name,"+++ Creating detector assembly without shape");
56  vol = Assembly(det_name);
57  }
58 
59  vol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
60 
61  Volume mother = description.pickMotherVolume(sdet);
62  PlacedVolume pv;
63  if( useRot && usePos ){
64  pv = mother.placeVolume(vol, Transform3D(rot, pos));
65  } else if( useRot ){
66  pv = mother.placeVolume(vol, rot);
67  } else if( usePos ){
68  pv = mother.placeVolume(vol, pos);
69  } else {
70  pv = mother.placeVolume(vol);
71  }
72  sdet.setPlacement(pv);
73  for(xml_coll_t c(x_det,_U(composite)); c; ++c) {
74  xml_dim_t component = c;
75  string nam = component.nameStr();
76  description.declareParent(nam, sdet);
77  }
78  return sdet;
79 }
80 
81 DECLARE_DETELEMENT(DD4hep_SubdetectorAssembly,create_element)
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
DECLARE_DETELEMENT
#define DECLARE_DETELEMENT(name, func)
Definition: Factories.h:339
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:163
dd4hep::Handle< NamedObject >
dd4hep::Detector::pickMotherVolume
virtual Volume pickMotherVolume(const DetElement &sd) const =0
Access mother volume by detector element.
dd4hep::Solid_type< TGeoShape >
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::Assembly
Implementation class extending the ROOT assembly volumes (TGeoVolumeAssembly)
Definition: Volumes.h:761
dd4hep::Volume::placeVolume
PlacedVolume placeVolume(const Volume &volume) const
Place daughter volume. The position and rotation are the identity.
Definition: Volumes.cpp:859
xml_comp_t
dd4hep::xml::Component xml_comp_t
Definition: XML.h:33
dd4hep::Material
Handle class describing a material.
Definition: Objects.h:272
dd4hep::Detector::material
virtual Material material(const std::string &name) const =0
Retrieve a matrial by its name from the detector description.
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:370
dd4hep::detail
DD4hep internal namespace.
Definition: Alignments.h:32
dd4hep::xml::createShape
Solid createShape(Detector &description, const std::string &shape_type, xml::Element element)
Create a solid shape using the plugin mechanism from the attributes of the XML element.
Definition: Utilities.cpp:84
xml_det_t
dd4hep::xml::DetElement xml_det_t
Definition: XML.h:32
_U
#define _U(a)
Definition: Tags.h:23
dd4hep::xml::setDetectorTypeFlag
void setDetectorTypeFlag(dd4hep::xml::Handle_t e, dd4hep::DetElement sdet)
Definition: Utilities.cpp:284
dd4hep::Transform3D
ROOT::Math::Transform3D Transform3D
Definition: Objects.h:117
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
DetFactoryHelper.h
std
Definition: Plugins.h:30
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::RotationZYX
ROOT::Math::RotationZYX RotationZYX
Definition: Objects.h:105
dd4hep::Volume::setAttributes
const Volume & setAttributes(const Detector &description, const std::string &region, const std::string &limits, const std::string &vis) const
Attach attributes to the volume.
Definition: Volumes.cpp:1229
dd4hep::Detector::declareParent
virtual void declareParent(const std::string &detector_name, const DetElement &det)=0
Register new parent detector using the detector name.
Printout.h
xml_dim_t
dd4hep::xml::Dimension xml_dim_t
Definition: XML.h:31
Utilities.h