DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
CylindricalEndcapCalorimeter_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/Layering.h"
20 
21 using namespace std;
22 using namespace dd4hep;
23 using namespace dd4hep::detail;
24 
25 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
26  xml_det_t x_det = e;
27  xml_dim_t dim = x_det.dimensions();
28  Material air = description.air();
29  string det_name = x_det.nameStr();
30  bool reflect = x_det.reflect();
31  double zmin = dim.inner_z();
32  double rmin = dim.inner_r();
33  double rmax = dim.outer_r();
34  double totWidth = Layering(x_det).totalThickness();
35  double z = zmin;
36  Tube envelope (rmin,rmax,totWidth/2);
37  Volume envelopeVol(det_name+"_envelope",envelope,air);
38  int layer_num = 1;
39  PlacedVolume pv;
40 
41  // Set attributes of slice
42  for(xml_coll_t c(x_det,_U(layer)); c; ++c) {
43  xml_comp_t x_layer = c;
44  double layerWidth = 0;
45  for(xml_coll_t l(x_layer,_U(slice)); l; ++l)
46  layerWidth += xml_comp_t(l).thickness();
47  for(int i=0, im=0, repeat=x_layer.repeat(); i<repeat; ++i) {
48  double zlayer = z;
49  string layer_name = det_name + _toString(layer_num,"_layer%d");
50  Volume layer_vol(layer_name,Tube(rmin,rmax,layerWidth * 0.5),air);
51 
52  for(xml_coll_t l(x_layer,_U(slice)); l; ++l, ++im) {
53  xml_comp_t x_slice = l;
54  double w = x_slice.thickness();
55  string slice_name = layer_name + _toString(im+1,"slice%d");
56  Material slice_mat = description.material(x_slice.materialStr());
57  Volume slice_vol (slice_name,Tube(rmin,rmax,w * 0.5),slice_mat);
58 
59  if ( x_slice.isSensitive() ) {
60  sens.setType("calorimeter");
61  slice_vol.setSensitiveDetector(sens);
62  }
63  slice_vol.setAttributes(description,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
64  pv = layer_vol.placeVolume(slice_vol,Position(0,0,z-zlayer-layerWidth/2+w/2));
65  pv.addPhysVolID("slice", im+1);
66  z += w;
67  }
68  layer_vol.setVisAttributes(description,x_layer.visStr());
69 
70  Position layer_pos(0,0,zlayer-zmin-totWidth/2+layerWidth/2);
71  pv = envelopeVol.placeVolume(layer_vol,layer_pos);
72  pv.addPhysVolID("layer",layer_num);
73  printout(DEBUG,"Calo","CylindricalEndcapCalorimeter: built layer %d -> %s",layer_num,layer_name.c_str());
74  ++layer_num;
75  }
76  }
77  envelope.setDimensions(rmin,rmax,totWidth/2);
78  // Set attributes of slice
79  envelopeVol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
80 
81  DetElement sdet(det_name,x_det.id());
82  Assembly assembly(det_name+"_assembly");
83  Volume motherVol = description.pickMotherVolume(sdet);
84  PlacedVolume phv = motherVol.placeVolume(assembly);
85  phv.addPhysVolID("system",sdet.id());
86  sdet.setPlacement(phv);
87 
88  DetElement sdetA(sdet,det_name+(reflect ? "_A" : ""),x_det.id());
89  phv = assembly.placeVolume(envelopeVol,Position(0,0,zmin+totWidth/2));
90  phv.addPhysVolID("barrel",1);
91  sdetA.setPlacement(phv);
92 
93  if ( reflect ) {
94  phv=assembly.placeVolume(envelopeVol,Transform3D(RotationZ(M_PI),Position(0,0,-zmin-totWidth/2)));
95  phv.addPhysVolID("barrel",2);
97  DetElement sdetB(sdet,det_name+"_B",x_det.id());
98  sdetB.setPlacement(phv);
99  }
100  return sdet;
101 }
102 
103 DECLARE_DETELEMENT(DD4hep_CylindricalEndcapCalorimeter,create_detector)
dd4hep::Layering::totalThickness
double totalThickness() const
Definition: Layering.h:131
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
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:163
dd4hep::PlacedVolume::addPhysVolID
PlacedVolume & addPhysVolID(const std::string &name, int value)
Add identifier.
Definition: Volumes.cpp:501
dd4hep::Handle
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:84
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::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::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:370
dd4hep::detail
DD4hep internal namespace.
Definition: Alignments.h:32
dd4hep::RotationZ
ROOT::Math::RotationZ RotationZ
Definition: Objects.h:107
xml_det_t
dd4hep::xml::DetElement xml_det_t
Definition: XML.h:32
_U
#define _U(a)
Definition: Tags.h:23
Layering.h
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
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::Tube
Class describing a tube shape of a section of a tube.
Definition: Shapes.h:628
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