DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ReflectedDetector_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 //==========================================================================
17 #include "DD4hep/Printout.h"
18 #include "DD4hep/DD4hepUnits.h"
19 #include "DD4hep/MatrixHelpers.h"
21 
22 using namespace std;
23 using namespace dd4hep;
24 using namespace dd4hep::detail;
25 
26 static Ref_t create_element(Detector& description, xml_h e, Ref_t sens) {
27  xml_det_t x_det (e);
28  SensitiveDetector sd = sens;
29  xml_dim_t x_pos = x_det.child(_U(position),false);
30  xml_dim_t x_rot = x_det.child(_U(rotation),false);
31  xml_dim_t x_refl = x_det.child(_U(reflect),false);
32  string ref_nam = x_det.attr<string>(_U(sdref));
33  DetElement ref_det = description.detector(ref_nam);
34  auto refl = ref_det.reflect(x_det.nameStr(), x_det.id(), sd);
35  Volume vol = refl.second;
36  DetElement sdet = refl.first;
37 
38  if ( !x_det.visStr().empty() )
39  vol.setVisAttributes(description, x_det.visStr());
40  if ( !x_det.limitsStr().empty() )
41  vol.setLimitSet(description, x_det.limitsStr());
42  if ( !x_det.regionStr().empty() )
43  vol.setRegion(description, x_det.regionStr());
44  if ( x_det.isSensitive() ) {
45  xml_dim_t sd_typ = x_det.child(_U(sensitive));
46  sd.setType(sd_typ.typeStr());
47  }
48  PlacedVolume pv;
49  RotationZYX rot3D;
50  Position tr3D;
51  Transform3D transform3D;
52  Volume mother = description.pickMotherVolume(sdet);
53  if ( x_pos ) {
54  tr3D = Position(x_pos.x(0),x_pos.y(0),x_pos.z(0));
55  }
56  if ( x_rot ) {
57  rot3D = RotationZYX(x_rot.z(0),x_rot.y(0),x_rot.x(0));
58  }
59  if ( !x_pos && !x_rot ) {
60  auto ref_pv = ref_det.placement();
61  matrix::_decompose(ref_pv.matrix(), tr3D, rot3D);
62  tr3D = tr3D * (-1.0 / dd4hep::mm);
63  }
64  char refl_type = 'Z';
65  if ( x_refl.hasAttr(_U(type)) ) refl_type = ::toupper(x_refl.attr<string>(_U(type))[0]);
66  if ( x_refl && refl_type == 'X' )
67  transform3D = Transform3D(Rotation3D(-1., 0., 0., 0., 1., 0., 0., 0., 1.) * rot3D, tr3D);
68  else if ( x_refl && refl_type == 'Y' )
69  transform3D = Transform3D(Rotation3D( 1., 0., 0., 0., -1., 0., 0., 0., 1.) * rot3D, tr3D);
70  else if ( x_refl && refl_type == 'Z' )
71  transform3D = Transform3D(Rotation3D( 1., 0., 0., 0., 1., 0., 0., 0., -1.) * rot3D, tr3D);
72  else // Z is default
73  transform3D = Transform3D(Rotation3D( 1., 0., 0., 0., 1., 0., 0., 0., -1.) * rot3D, tr3D);
74  pv = mother.placeVolume(vol, transform3D);
75  printout(INFO,"ReflectedDet","Transform3D placement at pos: %f %f %f rot: %f %f %f",
76  tr3D.X(),tr3D.Y(),tr3D.Z(), rot3D.Phi(),rot3D.Theta(),rot3D.Psi());
77 
78  if ( x_det.hasAttr(_U(id)) ) {
79  pv.addPhysVolID("system",x_det.id());
80  }
81  sdet.setPlacement(pv);
82  return sdet;
83 }
84 
85 DECLARE_DETELEMENT(DD4hep_ReflectedDetector,create_element)
dd4hep::Volume::setLimitSet
const Volume & setLimitSet(const Detector &description, const std::string &name) const
Set the limits to the volume. Note: If the name string is empty, the action is ignored.
Definition: Volumes.cpp:1261
dd4hep::Detector::detector
virtual DetElement detector(const std::string &name) const =0
Retrieve a subdetector element by its name from the detector description.
dd4hep::detail::matrix::_decompose
void _decompose(const TGeoMatrix &matrix, Position &pos, Rotation3D &rot)
Decompose a generic ROOT Matrix into a translation (Position) and a Rotation3D.
Definition: MatrixHelpers.cpp:203
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
MatrixHelpers.h
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:173
dd4hep::PlacedVolume::addPhysVolID
PlacedVolume & addPhysVolID(const std::string &name, int value)
Add identifier.
Definition: Volumes.cpp:485
dd4hep::Handle
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:84
dd4hep::Volume::setRegion
const Volume & setRegion(const Detector &description, const std::string &name) const
Set the regional attributes to the volume. Note: If the name string is empty, the action is ignored.
Definition: Volumes.cpp:1242
dd4hep::Rotation3D
ROOT::Math::Rotation3D Rotation3D
Definition: Objects.h:113
dd4hep::Detector::pickMotherVolume
virtual Volume pickMotherVolume(const DetElement &sd) const =0
Access mother volume by detector element.
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::Volume::placeVolume
PlacedVolume placeVolume(const Volume &volume) const
Place daughter volume. The position and rotation are the identity.
Definition: Volumes.cpp:830
dd4hep::DetElement::reflect
std::pair< DetElement, Volume > reflect(const std::string &new_name) const
Reflect (Deep copy) the DetElement structure with a new name.
Definition: DetElement.cpp:294
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:378
dd4hep::detail
DD4hep internal namespace.
Definition: Alignments.h:32
xml_det_t
dd4hep::xml::DetElement xml_det_t
Definition: XML.h:32
_U
#define _U(a)
Definition: Tags.h:23
dd4hep::DetElement::setPlacement
DetElement & setPlacement(const PlacedVolume &volume)
Set the physical volumes of the detector element.
Definition: DetElement.cpp:330
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::Volume::setVisAttributes
const Volume & setVisAttributes(const VisAttr &obj) const
Set Visualization attributes to the volume.
Definition: Volumes.cpp:1127
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
DD4hepUnits.h
Printout.h
xml_dim_t
dd4hep::xml::Dimension xml_dim_t
Definition: XML.h:31
dd4hep::SensitiveDetector::setType
SensitiveDetector & setType(const std::string &typ)
Set detector type (structure, tracker, calorimeter, etc.).
Definition: DetElement.cpp:403