CMS 3D CMS Logo

DDTIDAxialCableAlgo.cc
Go to the documentation of this file.
1 // File: DDTIDAxialCableAlgo.cc
3 // Description: Create and position TID axial cables at prescribed phi values
5 
6 #include <algorithm>
7 #include <cmath>
9 #include "DD4hep/DetFactoryHelper.h"
12 
13 using namespace edm;
14 using namespace dd4hep;
15 using namespace cms;
16 using namespace cms_units::operators;
17 
18 namespace {
20  cms::DDNamespace ns(ctxt, e, true);
21  cms::DDAlgoArguments args(ctxt, e);
22 
23  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo info: Creating an instance...";
24 
25  double zBend = args.value<double>("ZBend"); // Start z (at bending)........
26  double zEnd = args.value<double>("ZEnd"); // End z ........
27  double rMin = args.value<double>("RMin"); // Minimum radius ........
28  double rMax = args.value<double>("RMax"); // Maximum radius ........
29  double rTop = args.value<double>("RTop"); // Maximum radius (top)........
30  double width = args.value<double>("Width"); // Angular width
31  double thick = args.value<double>("Thick"); // Thickness
32  std::vector<double> angles = args.value<std::vector<double>>("Angles"); // Phi Angles
33  std::vector<double> zposWheel = args.value<std::vector<double>>("ZPosWheel"); // Z position of wheels
34  std::vector<double> zposRing = args.value<std::vector<double>>("ZPosRing"); // Z position of rings inside wheels
35 
36  std::string childName = args.value<std::string>("ChildName"); // Child name
37  std::string matIn = args.value<std::string>("MaterialIn"); // Material name (for inner parts)
38  std::string matOut = args.value<std::string>("MaterialOut"); // Material name (for outer part)
39 
40  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo debug: Parameters for creating " << (zposWheel.size() + 2)
41  << " axial cables and positioning" << angles.size() << "copies in Service volume"
42  << "\nzBend " << zBend << "\nzEnd " << zEnd << "\nrMin " << rMin << "\nrMax " << rMax
43  << "\nCable width " << convertRadToDeg(width) << "\nthickness " << thick << " with Angles";
44 
45  for (int i = 0; i < (int)(angles.size()); i++)
46  LogVerbatim("TIDGeom") << "\n\tangles[" << i << "] = " << convertRadToDeg(angles[i]);
47 
48  LogVerbatim("TIDGeom") << "\nWheels " << zposWheel.size() << " at Z";
49 
50  for (int i = 0; i < (int)(zposWheel.size()); i++)
51  LogVerbatim("TIDGeom") << "\n\tzposWheel[" << i << "] = " << zposWheel[i];
52 
53  LogVerbatim("TIDGeom") << "\neach with " << zposRing.size() << " Rings at Z";
54 
55  for (int i = 0; i < (int)(zposRing.size()); i++)
56  LogVerbatim("TIDGeom") << "\tzposRing[" << i << "] = " << zposRing[i];
57 
58  Volume mother = ns.volume(args.parentName());
59 
60  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo debug: Parent " << mother.name() << "\tChild " << childName
61  << " NameSpace " << ns.name() << "\tMaterial " << matIn << " and " << matOut;
62 
63  std::vector<Volume> logs;
64  const double thk = thick / zposRing.size();
65  double r = rMin;
66  double thktot = 0;
67  double z;
68 
69  // Cables between the wheels
70  for (int k = 0; k < (int)(zposWheel.size()); k++) {
71  std::vector<double> pconZ, pconRmin, pconRmax;
72 
73  for (int i = 0; i < (int)(zposRing.size()); i++) {
74  thktot += thk;
75  z = zposWheel[k] + zposRing[i] - 0.5 * thk;
76 
77  if (i != 0) {
78  pconZ.emplace_back(z);
79  pconRmin.emplace_back(r);
80  pconRmax.emplace_back(rMax);
81  }
82 
83  r = rMin;
84  pconZ.emplace_back(z);
85  pconRmin.emplace_back(r);
86  pconRmax.emplace_back(rMax);
87 
88  z += thk;
89  pconZ.emplace_back(z);
90  pconRmin.emplace_back(r);
91  pconRmax.emplace_back(rMax);
92 
93  r = rMax - thktot;
94  pconZ.emplace_back(z);
95  pconRmin.emplace_back(r);
96  pconRmax.emplace_back(rMax);
97  }
98 
99  if (k >= ((int)(zposWheel.size()) - 1))
100  z = zBend;
101  else
102  z = zposWheel[k + 1] + zposRing[0] - 0.5 * thk;
103 
104  pconZ.emplace_back(z);
105  pconRmin.emplace_back(r);
106  pconRmax.emplace_back(rMax);
107 
108  std::string name = childName + std::to_string(k);
109 
110  Solid solid = ns.addSolid(name, Polycone(-0.5 * width, width, pconRmin, pconRmax, pconZ));
111 
112  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: " << solid.name() << " Polycone made of " << matIn
113  << " from " << convertRadToDeg(-0.5 * width) << " to " << convertRadToDeg(0.5 * width)
114  << " and with " << pconZ.size() << " sections ";
115 
116  for (int i = 0; i < (int)(pconZ.size()); i++)
117  LogVerbatim("TIDGeom") << "\t[" << i << "]\tZ = " << pconZ[i] << "\tRmin = " << pconRmin[i]
118  << "\tRmax = " << pconRmax[i];
119 
120  logs.emplace_back(Volume(solid.name(), solid, ns.material("materials:Air")));
121  }
122 
123  // Cable in the vertical part
124  std::vector<double> pconZ, pconRmin, pconRmax;
125  r = thktot * rMax / rTop;
126  z = zBend - thktot;
127  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: Thk " << thk << " Total " << thktot << " rMax " << rMax
128  << " rTop " << rTop << " dR " << r << " z " << z;
129 
130  pconZ.emplace_back(z);
131  pconRmin.emplace_back(rMax);
132  pconRmax.emplace_back(rMax);
133 
134  z = zBend - r;
135  pconZ.emplace_back(z);
136  pconRmin.emplace_back(rMax);
137  pconRmax.emplace_back(rTop);
138 
139  pconZ.emplace_back(zBend);
140  pconRmin.emplace_back(rMax);
141  pconRmax.emplace_back(rTop);
142 
143  std::string name = childName + std::to_string(zposWheel.size());
144 
145  Solid solid = ns.addSolid(name, Polycone(-0.5 * width, width, pconRmin, pconRmax, pconZ));
146 
147  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: " << solid.name() << " Polycone made of " << matIn << " from "
148  << convertRadToDeg(-0.5 * width) << " to " << convertRadToDeg(0.5 * width) << " and with "
149  << pconZ.size() << " sections ";
150 
151  for (int i = 0; i < (int)(pconZ.size()); i++)
152  LogVerbatim("TIDGeom") << "\t[" << i << "]\tZ = " << pconZ[i] << "\tRmin = " << pconRmin[i]
153  << "\tRmax = " << pconRmax[i];
154 
155  logs.emplace_back(Volume(solid.name(), solid, ns.material(matIn)));
156 
157  // Cable in the outer part
158  name = childName + std::to_string(zposWheel.size() + 1);
159  r = rTop - r;
160  solid = ns.addSolid(name, Tube(r, rTop, 0.5 * (zEnd - zBend), -0.5 * width, width));
161 
162  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: " << solid.name() << " Tubs made of " << matOut << " from "
163  << convertRadToDeg(-0.5 * width) << " to " << convertRadToDeg(0.5 * width) << " with Rin "
164  << r << " Rout " << rTop << " ZHalf " << 0.5 * (zEnd - zBend);
165 
166  logs.emplace_back(Volume(solid.name(), solid, ns.material(matOut)));
167 
168  // Position the cables
169  constexpr double theta = 90_deg;
170 
171  for (int i = 0; i < (int)(angles.size()); i++) {
172  double phix = angles[i];
173  double phiy = phix + 90_deg;
174 
175  Rotation3D rotation = cms::makeRotation3D(theta, phix, theta, phiy, 0., 0.);
176  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: Creating a new "
177  << "rotation: " << convertRadToDeg(theta) << ", " << convertRadToDeg(phix) << ", "
178  << convertRadToDeg(theta) << ", " << convertRadToDeg(phiy) << ", 0, 0";
179 
180  for (int k = 0; k < (int)(logs.size()); k++) {
181  Position tran = Position(0., 0., 0.);
182 
183  if (k == ((int)(logs.size()) - 1))
184  tran = Position(0., 0., 0.5 * (zEnd + zBend));
185 
186  mother.placeVolume(logs[k], i + 1, Transform3D(rotation, tran));
187 
188  LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test " << logs[k].name() << " number " << i + 1
189  << " positioned in " << mother.name() << " at " << tran << " with " << rotation;
190  }
191  }
192  return s_executed;
193  }
194 } // namespace
195 
196 // first argument is the type from the xml file
197 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTIDAxialCableAlgo, algorithm)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Geom::Theta< T > theta() const
float float float z
dd4hep::Rotation3D makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
static constexpr long s_executed
dd4hep::Volume Volume
Namespace of DDCMS conversion namespace.
HLT enums.
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:30
#define constexpr