Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//==========================================================================
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
//
// Author : M.Frank
//
//==========================================================================
//
// Specialized generic detector constructor
//
//==========================================================================
// Framework include files
#include "DD4hep/DetFactoryHelper.h"
#include "DD4hep/Printout.h"
#include "DDCMS/DDCMSPlugins.h"
#include "CLHEP/Units/SystemOfUnits.h"
// C/C++ include files
#include <sstream>
using namespace std;
using namespace dd4hep;
using namespace dd4hep::detail;
using namespace dd4hep::cms;
static Ref_t create_element(Detector& description, ParsingContext& ctxt, xml_h e, SensitiveDetector& /* sens */) {
stringstream str;
PlacedVolume pv;
Namespace ns(ctxt);
AlgoArguments args(ctxt, e);
string parentName = args.parentName();
printout(INFO,"DDCMS","+++ Parsing arguments for Algorithm:%-24s rParent:%s",
args.name.c_str(), parentName.c_str());
string genMat = args.value<string>("GeneralMaterial");
int number = args.value<int>("Ladders");
double layerDz = args.value<double>("LayerDz");
double sensorEdge= args.value<double>("SensorEdge");
double coolDz = args.value<double>("CoolDz");
double coolWidth = args.value<double>("CoolWidth");
double coolSide = args.value<double>("CoolSide");
double coolThick = args.value<double>("CoolThick");
double coolDist = args.value<double>("CoolDist");
string coolMat = args.value<string>("CoolMaterial");
string tubeMat = args.value<string>("CoolTubeMaterial");
str.str("");
str << "DDPixBarLayerAlgo debug: Parent " << parentName
<< " NameSpace " << ns.name << "\n"
<< "\tLadders " << number << "\tGeneral Material "
<< genMat << "\tLength " << layerDz << "\tSensorEdge "
<< sensorEdge << "\tSpecification of Cooling Pieces:\n"
<< "\tLength " << coolDz << " Width " << coolWidth
<< " Side " << coolSide << " Thickness of Shell "
<< coolThick << " Radial distance " << coolDist
<< " Materials " << coolMat << ", " << tubeMat;
printout(DEBUG,"PixelGeom",str.str().c_str());
vector<string> ladder = args.value<vector<string> >("LadderName");
vector<double> ladderWidth = args.value<vector<double> >("LadderWidth");
vector<double> ladderThick = args.value<vector<double> >("LadderThick");
str.str("");
str << "DDPixBarLayerAlgo debug: Full Ladder "
<< ladder[0] << " width/thickness " << ladderWidth[0]
<< ", " << ladderThick[0] << "\tHalf Ladder "
<< ladder[1] << " width/thickness " << ladderWidth[1]
<< ", " << ladderThick[1];
printout(DEBUG,"PixelGeom",str.str().c_str());
string mother = parentName;
const std::string &idName = mother;
double dphi = CLHEP::twopi/number;
double d2 = 0.5*coolWidth;
double d1 = d2 - coolSide*sin(0.5*dphi);
double x1 = (d1+d2)/(2.*sin(0.5*dphi));
double x2 = coolDist*sin(0.5*dphi);
double rmin = (coolDist-0.5*(d1+d2))*cos(0.5*dphi)-0.5*ladderThick[0];
double rmax = (coolDist+0.5*(d1+d2))*cos(0.5*dphi)+0.5*ladderThick[0];
double rmxh = rmax - 0.5*ladderThick[0] + ladderThick[1];
str.str("");
str << "DDPixBarLayerAlgo test: Rmin/Rmax " << rmin
<< ", " << rmax << " d1/d2 " << d1 << ", " << d2
<< " x1/x2 " << x1 << ", " << x2;
printout(DEBUG,"PixelGeom",str.str().c_str());
double rtmi = rmin + 0.5*ladderThick[0] - ladderThick[1];
double rtmx = sqrt(rmxh*rmxh+ladderWidth[1]*ladderWidth[1]);
Solid solid = Tube(rtmi, rtmx, 0.5*layerDz, 0, CLHEP::twopi);
solid.setName(idName);
str.str("");
str << "DDPixBarLayerAlgo test: "
<< idName << " Tubs made of "
<< genMat << " from 0 to " << CLHEP::twopi/CLHEP::deg
<< " with Rin " << rtmi << " Rout " << rtmx
<< " ZHalf " << 0.5*layerDz;
printout(DEBUG,"PixelGeom",str.str().c_str());
Material matter;
Volume layer(solid.name(), solid, description.material(genMat));
double rr = 0.5*(rmax+rmin);
double dr = 0.5*(rmax-rmin);
double h1 = 0.5*coolSide*cos(0.5*dphi);
std::string name = idName + "CoolTube";
solid = Trap(0.5*coolDz, 0, 0, h1, d2, d1, 0, h1, d2, d1, 0);
solid.setName(idName+"CoolTube");
str.str("");
str << "DDPixBarLayerAlgo test: " <<solid.name()
<< " Trap made of " << tubeMat << " of dimensions "
<< 0.5*coolDz << ", 0, 0, " << h1 << ", " << d2
<< ", " << d1 << ", 0, " << h1 << ", " << d2 << ", "
<< d1 << ", 0";
printout(DEBUG,"PixelGeom",str.str().c_str());
Volume coolTube(solid.name(), solid, description.material(tubeMat));
h1 -= coolThick;
d1 -= coolThick;
d2 -= coolThick;
solid = Trap(0.5*coolDz, 0, 0, h1, d2, d1, 0, h1, d2, d1, 0);
solid.setName(idName + "Coolant");
str.str("");
str << "DDPixBarLayerAlgo test: " <<solid.name()
<< " Trap made of " << coolMat << " of dimensions "
<< 0.5*coolDz << ", 0, 0, " << h1 << ", " << d2
<< ", " << d1 << ", 0, " << h1 << ", " << d2 << ", "
<< d1 << ", 0";
printout(DEBUG,"PixelGeom",str.str().c_str());
Volume cool(solid.name(), solid, description.material(coolMat));
//cpv.position(cool, coolTube, 1, DDTranslation(0.0, 0.0, 0.0), DDRotation());
pv = coolTube.placeVolume(cool);
str.str("");
str << "DDPixBarLayerAlgo test: " << cool.name()
<< " number 1 positioned in " << coolTube.name()
<< " at (0,0,0) with no rotation";
printout(DEBUG,"PixelGeom",str.str().c_str());
string ladderFull = ladder[0];
string ladderHalf = ladder[1];
int nphi=number/2, copy=1, iup=-1;
double phi0 = 90*CLHEP::deg;
Volume ladderHalfVol = ctxt.volume(ladderHalf);
Volume ladderFullVol = ctxt.volume(ladderFull);
for (int i=0; i<number; i++) {
double phi = phi0 + i*dphi;
double phix, phiy, rrr, xx;
std::string rots;
Position tran;
Rotation3D rot;
if (i == 0 || i == nphi) {
rrr = rr + dr + 0.5*(ladderThick[1]-ladderThick[0]);
xx = (0.5*ladderWidth[1] - sensorEdge) * sin(phi);
tran = Position(xx, rrr*sin(phi), 0);
rots = idName + std::to_string(copy);
phix = phi-90*CLHEP::deg;
phiy = 90*CLHEP::deg+phix;
str.str("");
str << "DDPixBarLayerAlgo test: Creating a new "
<< "rotation: " << rots << "\t90., "
<< phix/CLHEP::deg << ", 90.," << phiy/CLHEP::deg
<< ", 0, 0";
printout(DEBUG,"PixelGeom",str.str().c_str());
rot = make_rotation3D(90*CLHEP::deg, phix, 90*CLHEP::deg, phiy, 0.,0.);
//cpv.position(ladderHalf, layer, copy, tran, rot);
pv = layer.placeVolume(ladderHalfVol, Transform3D(rot,tran));
if ( !pv.isValid() ) { }
str.str("");
str << "DDPixBarLayerAlgo test: " << ladderHalfVol.name()
<< " number " << copy << " positioned in "
<< layer.name() << " at " << tran << " with "
<< rot;
printout(DEBUG,"PixelGeom",str.str().c_str());
copy++;
iup = -1;
rrr = rr - dr - 0.5*(ladderThick[1]-ladderThick[0]);
tran = Position(-xx, rrr*sin(phi), 0);
rots = idName + std::to_string(copy);
phix = phi+90*CLHEP::deg;
phiy = 90*CLHEP::deg+phix;
str.str("");
str << "DDPixBarLayerAlgo test: Creating a new "
<< "rotation: " << rots << "\t90., "
<< phix/CLHEP::deg << ", 90.," << phiy/CLHEP::deg
<< ", 0, 0";
printout(DEBUG,"PixelGeom",str.str().c_str());
rot = make_rotation3D(90*CLHEP::deg, phix, 90*CLHEP::deg, phiy, 0.,0.);
//cpv.position(ladderHalf, layer, copy, tran, rot);
pv = layer.placeVolume(ladderHalfVol, Transform3D(rot,tran));
if ( !pv.isValid() ) { }
str.str("");
str << "DDPixBarLayerAlgo test: " << ladderHalfVol.name()
<< " number " << copy << " positioned in "
<< layer.name() << " at " << tran << " with "
<< rot;
printout(DEBUG,"PixelGeom",str.str().c_str());
copy++;
} else {
iup =-iup;
rrr = rr + iup*dr;
tran = Position(rrr*cos(phi), rrr*sin(phi), 0);
rots = idName + std::to_string(copy);
if (iup > 0) phix = phi-90*CLHEP::deg;
else phix = phi+90*CLHEP::deg;
phiy = phix+90.*CLHEP::deg;
str.str("");
str << "DDPixBarLayerAlgo test: Creating a new "
<< "rotation: " << rots << "\t90., "
<< phix/CLHEP::deg << ", 90.," << phiy/CLHEP::deg
<< ", 0, 0";
printout(DEBUG,"PixelGeom",str.str().c_str());
rot = make_rotation3D(90*CLHEP::deg, phix, 90*CLHEP::deg, phiy, 0.,0.);
//cpv.position(ladderFull, layer, copy, tran, rot);
pv = layer.placeVolume(ladderFullVol, Transform3D(rot,tran));
if ( !pv.isValid() ) { }
str.str("");
str << "DDPixBarLayerAlgo test: " << ladderFullVol.name()
<< " number " << copy << " positioned in "
<< layer.name() << " at " << tran << " with "
<< rot;
printout(DEBUG,"PixelGeom",str.str().c_str());
copy++;
}
rrr = coolDist*cos(0.5*dphi);
tran = Position(rrr*cos(phi)-x2*sin(phi), rrr*sin(phi)+x2*cos(phi), 0);
rots = idName + std::to_string(i+100);
phix = phi+0.5*dphi;
if (iup > 0) phix += 180*CLHEP::deg;
phiy = phix+90.*CLHEP::deg;
str.str("");
str << "DDPixBarLayerAlgo test: Creating a new "
<< "rotation: " << rots << "\t90., "
<< phix/CLHEP::deg << ", 90.," << phiy/CLHEP::deg
<< ", 0, 0";
printout(DEBUG,"PixelGeom",str.str().c_str());
rot = make_rotation3D(90*CLHEP::deg, phix, 90*CLHEP::deg, phiy, 0.,0.);
//cpv.position(coolTube, layer, i+1, tran, rot);
pv = layer.placeVolume(coolTube,Transform3D(rot,tran));
if ( !pv.isValid() ) { }
str.str("");
str << "DDPixBarLayerAlgo test: " << coolTube.name()
<< " number " << i+1 << " positioned in "
<< layer.name() << " at " << tran << " with "<< rot;
printout(DEBUG,"PixelGeom",str.str().c_str());
}
// Now we have built the layer.....create the DetElement object
string det_name = "Layer_"+idName;
DetElement det_elt(det_name,0);
Assembly assembly(det_name);
Volume motherVol = description.pickMotherVolume(det_elt);
pv = assembly.placeVolume(layer);
pv = motherVol.placeVolume(assembly);
det_elt.setPlacement(pv);
return det_elt;
}
// first argument is the type from the xml file
DECLARE_DDCMS_DETELEMENT(track_DDPixBarLayerAlgo,create_element)