Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PrimitivesFactory.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PrimitivesFactory.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include <DD4hep/DetFactoryHelper.h>
12 #include <DD4hep/Objects.h>
13 #include <XML/Utilities.h>
14 
15 #include "DD4hepTestsHelper.hpp"
16 
17 using namespace std;
18 using namespace dd4hep;
19 
27 static Ref_t create_cylinder(Detector &dd, xml_h xml,
28  SensitiveDetector /*sens*/) {
29  xml_det_t x_det = xml;
30  string detName = x_det.nameStr();
31 
32  // Make Volume
33  xml_comp_t x_det_tubs = x_det.child(_U(tubs));
34 
35  // Make DetElement
36  DetElement cylinderElement(detName, x_det.id());
37  dd4hep::xml::setDetectorTypeFlag(xml, cylinderElement);
38 
39  string shapeName = x_det_tubs.nameStr();
40  double phiMin = Acts::getAttrValueOr<double>(x_det_tubs, "phimin", 0.);
41  double phiMax = Acts::getAttrValueOr<double>(x_det_tubs, "phimax", 360.);
42  Tube tubeShape(shapeName, x_det_tubs.rmin(), x_det_tubs.rmax(),
43  x_det_tubs.dz(), phiMin, phiMax);
44  Volume tubeVolume(detName, tubeShape, dd.material(x_det_tubs.materialStr()));
45  tubeVolume.setVisAttributes(dd, x_det.visStr());
46 
47  // Place it in the mother
48  Volume motherVolume = dd.pickMotherVolume(cylinderElement);
49  PlacedVolume placedTube = motherVolume.placeVolume(
50  tubeVolume, DD4hepTestsHelper::createTransform(x_det_tubs));
51  placedTube.addPhysVolID(detName, cylinderElement.id());
52  cylinderElement.setPlacement(placedTube);
53 
54  // And return the element for further parsing
55  return cylinderElement;
56 }
57 
58 DECLARE_DETELEMENT(Cylinder, create_cylinder)
59 
60 
61 
62 
63 
64 
65 
66 
67 static Ref_t create_disc(Detector &dd, xml_h xml, SensitiveDetector /*sens*/) {
68  xml_det_t x_det = xml;
69  string detName = x_det.nameStr();
70 
71  // Make Volume
72  xml_comp_t x_det_tubs = x_det.child(_U(tubs));
73 
74  // Make DetElement
75  DetElement discElement(detName, x_det.id());
76  dd4hep::xml::setDetectorTypeFlag(xml, discElement);
77 
78  string shapeName = x_det_tubs.nameStr();
79  double phiMin = Acts::getAttrValueOr<double>(x_det_tubs, "phimin", 0.);
80  double phiMax = Acts::getAttrValueOr<double>(x_det_tubs, "phimax", 360.);
81 
82  Tube discShape = Tube(shapeName, x_det_tubs.rmin(), x_det_tubs.rmax(),
83  x_det_tubs.dz(), phiMin, phiMax);
84 
85  Volume discVolume(detName, discShape, dd.material(x_det_tubs.materialStr()));
86  discVolume.setVisAttributes(dd, x_det.visStr());
87 
88  // Place it in the mother
89  Volume motherVolume = dd.pickMotherVolume(discElement);
90  PlacedVolume placedTube = motherVolume.placeVolume(
91  discVolume, DD4hepTestsHelper::createTransform(x_det_tubs));
92  placedTube.addPhysVolID(detName, discElement.id());
93  discElement.setPlacement(placedTube);
94 
95  // And return the element for further parsing
96  return discElement;
97 }
98 
99 DECLARE_DETELEMENT(Disc, create_disc)
100 
101 
102 
103 
104 
105 
106 
107 
108 static Ref_t create_rectangle(Detector &dd, xml_h xml,
109  SensitiveDetector /*sens*/) {
110  xml_det_t x_det = xml;
111  string detName = x_det.nameStr();
112 
113  // Make Volume
114  xml_comp_t x_det_box = x_det.child(_U(box));
115 
116  // Make DetElement
117  DetElement rectElement(detName, x_det.id());
118  dd4hep::xml::setDetectorTypeFlag(xml, rectElement);
119 
120  string shapeName = x_det_box.nameStr();
121  Box rectShape(shapeName, 0.5 * x_det_box.dx(), 0.5 * x_det_box.dy(),
122  0.5 * x_det_box.dz());
123 
124  Volume rectVolume(detName, rectShape, dd.material(x_det_box.materialStr()));
125  rectVolume.setVisAttributes(dd, x_det.visStr());
126 
127  // Place it in the mother
128  Volume motherVolume = dd.pickMotherVolume(rectElement);
129  PlacedVolume placedRect = motherVolume.placeVolume(
130  rectVolume, DD4hepTestsHelper::createTransform(x_det_box));
131  placedRect.addPhysVolID(detName, rectElement.id());
132  rectElement.setPlacement(placedRect);
133 
134  // And return the element for further parsing
135  return rectElement;
136 }
137 
138 DECLARE_DETELEMENT(Rectangle, create_rectangle)
139 
140 
141 
142 
143 
144 
145 
146 
147 static Ref_t create_trapezoid(Detector &dd, xml_h xml,
148  SensitiveDetector /*sens*/) {
149  xml_det_t x_det = xml;
150  string detName = x_det.nameStr();
151 
152  // Make Volume
153  xml_comp_t x_det_trap = x_det.child(_U(trap));
154 
155  // Make DetElement
156  DetElement trapElement(detName, x_det.id());
157  dd4hep::xml::setDetectorTypeFlag(xml, trapElement);
158 
159  string shapeName = x_det_trap.nameStr();
160 
161  // Due to convention this causes an axis flip on x
162  Trapezoid trapShape(x_det_trap.x1(), x_det_trap.x2(), 0.5 * x_det_trap.dz(),
163  0.5 * x_det_trap.dz(), 0.5 * x_det_trap.dy());
164 
165  Volume trapVolume(detName, trapShape, dd.material(x_det_trap.materialStr()));
166  trapVolume.setVisAttributes(dd, x_det.visStr());
167 
168  // Place it in the mother
169  Volume motherVolume = dd.pickMotherVolume(trapElement);
170  PlacedVolume placedTrap = motherVolume.placeVolume(
171  trapVolume, DD4hepTestsHelper::createTransform(x_det_trap));
172  placedTrap.addPhysVolID(detName, trapElement.id());
173  trapElement.setPlacement(placedTrap);
174 
175  // And return the element for further parsing
176  return trapElement;
177 }
178 
179 DECLARE_DETELEMENT(Trapezoid, create_trapezoid)