DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
PolyhedraEndcapCalorimeter2_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 "XML/Layering.h"
19 
20 using namespace std;
21 using namespace dd4hep;
22 using namespace dd4hep::detail;
23 
24 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
25  xml_det_t x_det = e;
26  xml_dim_t dim = x_det.dimensions();
27  int det_id = x_det.id();
28  bool reflect = x_det.reflect(true);
29  string det_name = x_det.nameStr();
30  Material air = description.air();
31  int numsides = dim.numsides();
32  double rmin = dim.rmin();
33  double rmax = dim.rmax()*std::cos(M_PI/numsides);
34  double zmin = dim.zmin();
35  Layering layering(x_det);
36  double totalThickness = layering.totalThickness();
37  Volume endcapVol("endcap",PolyhedraRegular(numsides,rmin,rmax,totalThickness),air);
38  DetElement endcap("endcap",det_id);
39 
40  int l_num = 1;
41  int layerType = 0;
42  double layerZ = -totalThickness/2;
43 
44  endcapVol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
45 
46  for(xml_coll_t xc(x_det,_U(layer)); xc; ++xc) {
47  xml_comp_t x_layer = xc;
48  double l_thick = layering.layer(l_num-1)->thickness();
49  string l_name = _toString(layerType,"layer%d");
50  int l_repeat = x_layer.repeat();
51  Volume l_vol(l_name,PolyhedraRegular(numsides,rmin,rmax,l_thick),air);
52  vector<PlacedVolume> sensitives;
53 
54  int s_num = 1;
55  double sliceZ = -l_thick/2;
56  for(xml_coll_t xs(x_layer,_U(slice)); xs; ++xs) {
57  xml_comp_t x_slice = xs;
58  string s_name = _toString(s_num,"slice%d");
59  double s_thick = x_slice.thickness();
60  Material s_mat = description.material(x_slice.materialStr());
61  Volume s_vol(s_name,PolyhedraRegular(numsides,rmin,rmax,s_thick),s_mat);
62 
63  s_vol.setVisAttributes(description.visAttributes(x_slice.visStr()));
64  sliceZ += s_thick/2;
65  PlacedVolume s_phv = l_vol.placeVolume(s_vol,Position(0,0,sliceZ));
66  s_phv.addPhysVolID("slice",s_num);
67  if ( x_slice.isSensitive() ) {
68  sens.setType("calorimeter");
69  s_vol.setSensitiveDetector(sens);
70  sensitives.push_back(s_phv);
71  }
72  sliceZ += s_thick/2;
73  s_num++;
74  }
75  l_vol.setVisAttributes(description.visAttributes(x_layer.visStr()));
76  if ( l_repeat <= 0 ) throw std::runtime_error(x_det.nameStr()+"> Invalid repeat value");
77  for(int j=0; j<l_repeat; ++j) {
78  string phys_lay = _toString(l_num,"layer%d");
79  layerZ += l_thick/2;
80  DetElement layer_elt(endcap, phys_lay, l_num);
81  PlacedVolume pv = endcapVol.placeVolume(l_vol,Position(0,0,layerZ));
82  pv.addPhysVolID("layer", l_num);
83  layer_elt.setPlacement(pv);
84  for(size_t ic=0; ic<sensitives.size(); ++ic) {
85  PlacedVolume sens_pv = sensitives[ic];
86  DetElement comp_elt(layer_elt,sens_pv.volume().name(),l_num);
87  comp_elt.setPlacement(sens_pv);
88  }
89  layerZ += l_thick/2;
90  ++l_num;
91  }
92  ++layerType;
93  }
94 
95  double z_pos = zmin+totalThickness/2;
96  PlacedVolume pv;
97  // Reflect it.
98  if ( reflect ) {
99  Assembly assembly(det_name);
100  DetElement both_endcaps(det_name,det_id);
101  Volume motherVol = description.pickMotherVolume(both_endcaps);
102  DetElement sdetA = endcap;
103  Ref_t(sdetA)->SetName((det_name+"_A").c_str());
104  DetElement sdetB = endcap.clone(det_name+"_B",x_det.id());
105 
106  pv = assembly.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,0,0),
107  Position(0,0,z_pos)));
108  pv.addPhysVolID("barrel", 1);
109  sdetA.setPlacement(pv);
110 
111  pv = assembly.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,M_PI,0),
112  Position(0,0,-z_pos)));
113  pv.addPhysVolID("barrel", 2);
114  sdetB.setPlacement(pv);
115 
116  pv = motherVol.placeVolume(assembly);
117  pv.addPhysVolID("system", det_id);
118  both_endcaps.setPlacement(pv);
119  both_endcaps.add(sdetA);
120  both_endcaps.add(sdetB);
121  return both_endcaps;
122  }
123  Volume motherVol = description.pickMotherVolume(endcap);
124  pv = motherVol.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,0,0),
125  Position(0,0,z_pos)));
126  pv.addPhysVolID("system", det_id);
127  pv.addPhysVolID("barrel", 1);
128  endcap.setPlacement(pv);
129  Ref_t(endcap)->SetName(det_name.c_str());
130  return endcap;
131 }
132 
133 DECLARE_DETELEMENT(DD4hep_PolyhedraEndcapCalorimeter2,create_detector)
134 
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
dd4hep::PolyhedraRegular
Class describing a regular polyhedron shape.
Definition: Shapes.h:1493
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
DECLARE_DETELEMENT
#define DECLARE_DETELEMENT(name, func)
Definition: Factories.h:339
M_PI
#define M_PI
Definition: Handle.h:33
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::DetElement::clone
DetElement clone(int flag) const
Clone (Deep copy) the DetElement structure.
Definition: DetElement.cpp:274
dd4hep::PlacedVolume::addPhysVolID
PlacedVolume & addPhysVolID(const std::string &name, int value)
Add identifier.
Definition: Volumes.cpp:485
dd4hep::Handle< NamedObject >
dd4hep::_toString
std::string _toString(bool value)
String conversions: boolean value to string.
Definition: Handle.cpp:332
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::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::Assembly
Implementation class extending the ROOT assembly volumes (TGeoVolumeAssembly)
Definition: Volumes.h:762
dd4hep::Volume::placeVolume
PlacedVolume placeVolume(const Volume &volume) const
Place daughter volume. The position and rotation are the identity.
Definition: Volumes.cpp:830
dd4hep::NamedObject::SetName
void SetName(const char *nam)
Set name (used by Handle)
Definition: NamedObject.h:62
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::Detector::air
virtual Material air() const =0
Return handle to material describing air.
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
Layering.h
dd4hep::DetElement::setPlacement
DetElement & setPlacement(const PlacedVolume &volume)
Set the physical volumes of the detector element.
Definition: DetElement.cpp:330
dd4hep::Detector::visAttributes
virtual const HandleMap & visAttributes() const =0
Accessor to the map of visualisation attributes.
dd4hep::Transform3D
ROOT::Math::Transform3D Transform3D
Definition: Objects.h:117
dd4hep::Layering
Class to convert a layering object from the compact notation.
Definition: Layering.h:116
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
dd4hep::Ref_t
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
Definition: Handle.h:182
DetFactoryHelper.h
std
Definition: Plugins.h:30
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::PlacedVolume::volume
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:452
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
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