CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDPixBarLayerAlgo.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 
6 using namespace std;
7 using namespace dd4hep;
8 using namespace cms;
9 using namespace cms_units::operators;
10 
11 static long algorithm(Detector& description, cms::DDParsingContext& ctxt, xml_h e) {
13  cms::DDNamespace ns(ctxt, e, true);
14  DDAlgoArguments args(ctxt, e);
15  string parentName = args.parentName();
16 
17  edm::LogVerbatim("PixelGeom") << "+++ Parsing arguments for Algorithm:" << args.name << " rParent:" << parentName;
18  string genMat = args.value<string>("GeneralMaterial");
19  int number = args.value<int>("Ladders");
20  double layerDz = args.value<double>("LayerDz");
21  double sensorEdge = args.value<double>("SensorEdge");
22  double coolDz = args.value<double>("CoolDz");
23  double coolWidth = args.value<double>("CoolWidth");
24  double coolSide = args.value<double>("CoolSide");
25  double coolThick = args.value<double>("CoolThick");
26  double coolDist = args.value<double>("CoolDist");
27  string coolMat = args.value<string>("CoolMaterial");
28  string tubeMat = args.value<string>("CoolTubeMaterial");
29  edm::LogVerbatim("PixelGeom") << "Parent " << parentName << " NameSpace " << ns.name() << "\n"
30  << "\tLadders " << number << "\tGeneral Material " << genMat << "\tLength " << layerDz
31  << "\tSensorEdge " << sensorEdge << "\tSpecification of Cooling Pieces:\n"
32  << "\tLength " << coolDz << " Width " << coolWidth << " Side " << coolSide
33  << " Thickness of Shell " << coolThick << " Radial distance " << coolDist
34  << " Materials " << coolMat << ", " << tubeMat;
35  vector<string> ladder = args.value<vector<string> >("LadderName");
36  vector<double> ladderWidth = args.value<vector<double> >("LadderWidth");
37  vector<double> ladderThick = args.value<vector<double> >("LadderThick");
38  edm::LogVerbatim("PixelGeom") << "Full Ladder " << ladder[0] << " width/thickness " << ladderWidth[0] << ", "
39  << ladderThick[0] << "\tHalf Ladder " << ladder[1] << " width/thickness "
40  << ladderWidth[1] << ", " << ladderThick[1];
41 
42  const std::string idName = ns.objName(parentName);
43  double dphi = 2_pi / number;
44  double d2 = 0.5 * coolWidth;
45  double d1 = d2 - coolSide * sin(0.5 * dphi);
46  double x1 = (d1 + d2) / (2. * sin(0.5 * dphi));
47  double x2 = coolDist * sin(0.5 * dphi);
48  double rmin = (coolDist - 0.5 * (d1 + d2)) * cos(0.5 * dphi) - 0.5 * ladderThick[0];
49  double rmax = (coolDist + 0.5 * (d1 + d2)) * cos(0.5 * dphi) + 0.5 * ladderThick[0];
50  double rmxh = rmax - 0.5 * ladderThick[0] + ladderThick[1];
51  edm::LogVerbatim("PixelGeom") << "Rmin/Rmax " << rmin << ", " << rmax << " d1/d2 " << d1 << ", " << d2 << " x1/x2 "
52  << x1 << ", " << x2;
53 
54  double rtmi = rmin + 0.5 * ladderThick[0] - ladderThick[1];
55  double rtmx = sqrt(rmxh * rmxh + ladderWidth[1] * ladderWidth[1]);
56  Solid solid = ns.addSolid(ns.prepend(idName), Tube(rtmi, rtmx, 0.5 * layerDz, 0, 2_pi));
57  edm::LogVerbatim("PixelGeom") << "IDname " << solid.name() << " Tubs made of " << genMat << " from 0 to "
58  << convertRadToDeg(2_pi) << " with Rin " << rtmi << " Rout " << rtmx << " ZHalf "
59  << 0.5 * layerDz;
60 
61  Volume layer = ns.addVolume(Volume(solid.name(), solid, ns.material(genMat)));
62  double rr = 0.5 * (rmax + rmin);
63  double dr = 0.5 * (rmax - rmin);
64  double h1 = 0.5 * coolSide * cos(0.5 * dphi);
65  std::string name = idName + "CoolTube";
66  solid = ns.addSolid(ns.prepend(name), Trap(0.5 * coolDz, 0, 0, h1, d2, d1, 0, h1, d2, d1, 0));
67  edm::LogVerbatim("PixelGeom") << "Solid " << solid.name() << " Trap made of " << tubeMat << " of dimensions "
68  << 0.5 * coolDz << ", 0, 0, " << h1 << ", " << d2 << ", " << d1 << ", 0, " << h1 << ", "
69  << d2 << ", " << d1 << ", 0";
70 
71  Volume coolTube = ns.addVolume(Volume(solid.name(), solid, description.material(tubeMat)));
72  h1 -= coolThick;
73  d1 -= coolThick;
74  d2 -= coolThick;
75  name = idName + "Coolant";
76  solid = ns.addSolid(ns.prepend(name), Trap(0.5 * coolDz, 0, 0, h1, d2, d1, 0, h1, d2, d1, 0));
77  edm::LogVerbatim("PixelGeom") << "Solid " << solid.name() << " Trap made of " << coolMat << " of dimensions "
78  << 0.5 * coolDz << ", 0, 0, " << h1 << ", " << d2 << ", " << d1 << ", 0, " << h1 << ", "
79  << d2 << ", " << d1 << ", 0";
80 
81  Volume cool = ns.addVolume(Volume(solid.name(), solid, description.material(coolMat)));
82  pv = coolTube.placeVolume(cool, 1);
83  edm::LogVerbatim("PixelGeom") << "Cool " << cool.name() << " number 1 positioned in " << coolTube.name()
84  << " at (0,0,0) with no rotation";
85 
86  string ladderFull = ladder[0];
87  string ladderHalf = ladder[1];
88  int nphi = number / 2, copy = 1, iup = -1;
89  double phi0 = 90_deg;
90  Volume ladderHalfVol = ns.volume(ladderHalf);
91  Volume ladderFullVol = ns.volume(ladderFull);
92 
93  for (int i = 0; i < number; i++) {
94  double phi = phi0 + i * dphi;
95  double phix, phiy, rrr, xx;
96  std::string rots;
97  Position tran;
98  Rotation3D rot;
99  if (i == 0 || i == nphi) {
100  rrr = rr + dr + 0.5 * (ladderThick[1] - ladderThick[0]);
101  xx = (0.5 * ladderWidth[1] - sensorEdge) * sin(phi);
102  tran = Position(xx, rrr * sin(phi), 0);
103  rots = idName + std::to_string(copy);
104  phix = phi - 90_deg;
105  phiy = 90_deg + phix;
106  edm::LogVerbatim("PixelGeom") << "Creating a new "
107  << "rotation: " << rots << "\t90., " << convertRadToDeg(phix) << ", 90.,"
108  << convertRadToDeg(phiy) << ", 0, 0";
109  rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);
110 
111  //cpv.position(ladderHalf, layer, copy, tran, rot);
112  pv = layer.placeVolume(ladderHalfVol, copy, Transform3D(rot, tran));
113  if (!pv.isValid()) {
114  }
115  edm::LogVerbatim("PixelGeom") << "ladderHalfVol: " << ladderHalfVol.name() << " number " << copy
116  << " positioned in " << layer.name() << " at " << tran << " with " << rot;
117  copy++;
118  iup = -1;
119  rrr = rr - dr - 0.5 * (ladderThick[1] - ladderThick[0]);
120  tran = Position(-xx, rrr * sin(phi), 0);
121  rots = idName + std::to_string(copy);
122  phix = phi + 90_deg;
123  phiy = 90_deg + phix;
124  edm::LogVerbatim("PixelGeom") << "Creating a new rotation: " << rots << "\t90., " << convertRadToDeg(phix)
125  << ", 90.," << convertRadToDeg(phiy) << ", 0, 0";
126  rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);
127  //cpv.position(ladderHalf, layer, copy, tran, rot);
128  pv = layer.placeVolume(ladderHalfVol, copy, Transform3D(rot, tran));
129  if (!pv.isValid()) {
130  }
131  edm::LogVerbatim("PixelGeom") << "ladderHalfVol: " << ladderHalfVol.name() << " number " << copy
132  << " positioned in " << layer.name() << " at " << tran << " with " << rot;
133  copy++;
134  } else {
135  iup = -iup;
136  rrr = rr + iup * dr;
137  tran = Position(rrr * cos(phi), rrr * sin(phi), 0);
138  rots = idName + std::to_string(copy);
139  if (iup > 0)
140  phix = phi - 90_deg;
141  else
142  phix = phi + 90_deg;
143  phiy = phix + 90._deg;
144  edm::LogVerbatim("PixelGeom") << "DDPixBarLayerAlgo test: Creating a new "
145  << "rotation: " << rots << "\t90., " << convertRadToDeg(phix) << ", 90.,"
146  << convertRadToDeg(phiy) << ", 0, 0";
147  rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);
148 
149  //cpv.position(ladderFull, layer, copy, tran, rot);
150  pv = layer.placeVolume(ladderFullVol, copy, Transform3D(rot, tran));
151  if (!pv.isValid()) {
152  }
153  edm::LogVerbatim("PixelGeom") << "test: " << ladderFullVol.name() << " number " << copy << " positioned in "
154  << layer.name() << " at " << tran << " with " << rot;
155  copy++;
156  }
157  rrr = coolDist * cos(0.5 * dphi);
158  tran = Position(rrr * cos(phi) - x2 * sin(phi), rrr * sin(phi) + x2 * cos(phi), 0);
159  rots = idName + std::to_string(i + 100);
160  phix = phi + 0.5 * dphi;
161  if (iup > 0)
162  phix += 180_deg;
163  phiy = phix + 90._deg;
164  edm::LogVerbatim("PixelGeom") << "Creating a new rotation: " << rots << "\t90., " << convertRadToDeg(phix)
165  << ", 90.," << convertRadToDeg(phiy) << ", 0, 0";
166 
167  rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);
168  pv = layer.placeVolume(coolTube, i + 1, Transform3D(rot, tran));
169  if (!pv.isValid()) {
170  }
171  edm::LogVerbatim("PixelGeom") << "coolTube: " << coolTube.name() << " number " << i + 1 << " positioned in "
172  << layer.name() << " at " << tran << " with " << rot;
173  }
174  edm::LogVerbatim("PixelGeom") << "Layer: " << layer.name();
175  return 1;
176 }
177 
178 // first argument is the type from the xml file
179 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDPixBarLayerAlgo, algorithm)
Log< level::Info, true > LogVerbatim
const int nphi
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T value(const std::string &name) const
dd4hep::Volume addVolume(dd4hep::Volume vol) const
Definition: DDNamespace.cc:221
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
constexpr std::array< uint8_t, layerIndexSize > layer
std::string_view name() const
Definition: DDNamespace.h:79
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
tuple dd4hep
Definition: dd4hep_cff.py:3
T sqrt(T t)
Definition: SSEVec.h:19
dd4hep::PlacedVolume PlacedVolume
static std::string objName(const std::string &)
Definition: DDNamespace.cc:129
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
dd4hep::Volume Volume
dd4hep::Solid addSolid(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:307
static constexpr float d1
std::string parentName() const
Access value of rParent child node.