CMS 3D CMS Logo

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