1 #include "DD4hep/DetFactoryHelper.h"
5 #include "DD4hep/Shapes.h"
15 static constexpr
float const&
k_half = 0.5;
22 vector<string> materials;
23 vector<string> layName;
24 vector<string> ladPfx;
25 vector<string> typesL5;
26 vector<string> typesL4;
27 vector<string> typeOfLaddRow0;
28 vector<string> typeOfLaddRow1;
29 vector<string> typeOfLaddRow2;
30 vector<string> typeOfLaddRow3;
32 vector<float> thickLayers;
33 vector<float> abs1stx;
34 vector<float> abs1sty;
35 vector<float> abs2ndx;
36 vector<float> abs2ndy;
37 vector<float> asymLadd;
38 vector<float> rminVec;
39 vector<float> rmaxVec;
40 vector<float> noLaddInCol;
41 vector<float> startOfFirstLadd;
42 vector<float> laddL5map;
43 vector<float> laddL4map;
49 float waf_intra_col_sep;
50 float waf_inter_col_sep;
54 float zwedge_ceramic_diff;
55 float ywedge_ceramic_diff;
63 float micromodule_length;
66 float absAlX_subtr1_Xshift;
67 float absAlX_subtr1_Yshift;
71 float absAlY_subtr1_Xshift;
72 float absAlY_subtr1_Yshift;
78 float wedge_back_thick;
94 es.asymLadd =
args.vecFloat(
"ASYMETRIC_LADDER");
95 es.typesL5 =
args.vecStr(
"TYPES_OF_LADD_L5");
96 es.typesL4 =
args.vecStr(
"TYPES_OF_LADD_L4");
97 es.laddL5map =
args.vecFloat(
"LADD_L5_MAP");
98 es.laddL4map =
args.vecFloat(
"LADD_L4_MAP");
99 es.noLaddInCol =
args.vecFloat(
"NUMB_OF_LADD_IN_COL");
100 es.startOfFirstLadd =
args.vecFloat(
"START_OF_1ST_LADD");
101 es.typeOfLaddRow0 =
args.vecStr(
"TYPE_OF_LADD_1");
102 es.typeOfLaddRow1 =
args.vecStr(
"TYPE_OF_LADD_2");
103 es.typeOfLaddRow2 =
args.vecStr(
"TYPE_OF_LADD_3");
104 es.typeOfLaddRow3 =
args.vecStr(
"TYPE_OF_LADD_4");
105 es.thickLayers =
args.vecFloat(
"Layers");
106 es.thickness =
args.dble(
"PRESH_Z_TOTAL");
107 es.materials =
args.vecStr(
"LayMat");
108 es.layName =
args.vecStr(
"LayName");
109 es.rmaxVec =
args.vecFloat(
"R_MAX");
110 es.rminVec =
args.vecFloat(
"R_MIN");
111 es.waf_intra_col_sep =
args.dble(
"waf_intra_col_sep");
112 es.waf_inter_col_sep =
args.dble(
"waf_inter_col_sep");
113 es.waf_active =
args.dble(
"waf_active");
114 es.wedge_length =
args.dble(
"wedge_length");
115 es.wedge_offset =
args.dble(
"wedge_offset");
116 es.zwedge_ceramic_diff =
args.dble(
"zwedge_ceramic_diff");
117 es.ywedge_ceramic_diff =
args.dble(
"ywedge_ceramic_diff");
118 es.ceramic_length =
args.dble(
"ceramic_length");
119 es.wedge_angle =
args.dble(
"wedge_angle");
120 es.wedge_back_thick =
args.dble(
"wedge_back_thick");
121 es.ladder_thick =
args.dble(
"ladder_thick");
122 es.ladder_width =
args.dble(
"ladder_width");
123 es.micromodule_length =
args.dble(
"micromodule_length");
124 es.box_thick =
args.dble(
"box_thick");
125 es.abs1stx =
args.vecFloat(
"1ST_ABSX");
126 es.abs1sty =
args.vecFloat(
"1ST_ABSY");
127 es.abs2ndx =
args.vecFloat(
"2ND_ABSX");
128 es.abs2ndy =
args.vecFloat(
"2ND_ABSY");
129 es.ladPfx =
args.vecStr(
"LadPrefix");
130 es.laddMaterial =
args.str(
"LadderMaterial");
131 es.ldrFrnt_Length =
args.dble(
"LdrFrnt_Length");
132 es.ldrFrnt_Offset =
args.dble(
"LdrFrnt_Offset");
133 es.ldrBck_Length =
args.dble(
"LdrBck_Length");
134 es.ldrBck_Offset =
args.dble(
"LdrBck_Offset");
135 es.dee_separation =
args.dble(
"dee_sep");
136 es.in_rad_Abs_Al =
args.dble(
"R_MIN_Abs_Al");
137 es.in_rad_Abs_Pb =
args.dble(
"R_MIN_Abs_Pb");
138 es.rMax_Abs_Al =
args.dble(
"R_MAX_Abs_Al");
139 es.absAlX_X =
args.dble(
"AbsAlX_X");
140 es.absAlX_Y =
args.dble(
"AbsAlX_Y");
141 es.absAlX_subtr1_Xshift =
args.dble(
"AbsAlX_subtr1_Xshift");
142 es.absAlX_subtr1_Yshift =
args.dble(
"AbsAlX_subtr1_Yshift");
143 es.absAlY_X =
args.dble(
"AbsAlY_X");
144 es.absAlY_Y =
args.dble(
"AbsAlY_Y");
145 es.absAlY_subtr1_Xshift =
args.dble(
"AbsAlY_subtr1_Xshift");
146 es.absAlY_subtr1_Yshift =
args.dble(
"AbsAlY_subtr1_Yshift");
150 double zpos = -es.thickness *
k_half, sdx(0), sdy(0), bdx(0), bdy(0);
152 for (
size_t i = 0;
i < es.thickLayers.size(); ++
i) {
155 float rIn(0), rOut(0), zHalf(0);
158 const string& ddname(
"esalgo:" + es.layName[
i]);
162 rOut = es.rmaxVec[
i];
163 zHalf = es.thickLayers[
i] *
k_half;
166 Solid solid = ns.
addSolid(ddname, Tube(ddname, rIn, rOut, zHalf, 0., 360._deg));
174 if (
I == 2 ||
I == 28 ||
I == 13 ||
I == 23) {
180 es.zlead1 = zpos + zHalf;
183 es.zlead2 = zpos + zHalf;
186 if (
I == 10 ||
I == 20) {
189 double outalbx, outalby, shiftR, outalbx2, outalby2, shiftR2;
191 absz =
int(es.abs1stx.size());
193 absz =
int(es.abs2ndx.size());
197 const string& dd_tmp_name_b(
"esalgo:" + es.layName[
i] +
"Lcut");
198 const string& dd_tmp_name_c(
"esalgo:" + es.layName[
i] +
"tmpb");
199 const string& dd_tmp_name_d(
"esalgo:" + es.layName[
i] +
"LinPb");
200 const string& dd_tmp_name_e(
"esalgo:" + es.layName[
i] +
"LinAl");
201 const string& dd_tmp_name_f(
"esalgo:" + es.layName[
i] +
"LOutAl");
203 const string& dd_Alname_f(
"esalgo:" + es.layName[
i] +
"LOutAl");
204 const string& dd_Alname_g(
"esalgo:" + es.layName[
i] +
"LOutAl2");
205 const string& dd_Alname_h(
"esalgo:" + es.layName[
i] +
"LOutAltmp");
206 const string& dd_Alname_i(
"esalgo:" + es.layName[
i] +
"LOutAltmp2");
207 const string& dd_Alname_j(
"esalgo:" + es.layName[
i] +
"LOutAltmp3");
208 const string& dd_Alname_k(
"esalgo:" + es.layName[
i] +
"LOutAltmp4");
209 const string& dd_Alname_l(
"esalgo:" + es.layName[
i] +
"LOutAltmp5");
210 const string& dd_Alname_m(
"esalgo:" + es.layName[
i] +
"LOutAltmp6");
213 ns.
addSolid(dd_Alname_f, Tube(dd_Alname_f, es.rMax_Abs_Al - 70_cm, es.rMax_Abs_Al, zHalf, 0., 90._deg));
215 outalbx = es.absAlX_X * 0.1;
216 outalby = es.rMax_Abs_Al + 0.1_mm - es.absAlX_subtr1_Yshift;
217 shiftR = es.absAlX_subtr1_Yshift;
219 outalbx = es.absAlY_X * 0.1;
220 outalby = es.rMax_Abs_Al + 0.1_mm - es.absAlY_subtr1_Yshift;
221 shiftR = es.absAlY_subtr1_Xshift;
224 dd_Alname_h, Box(dd_Alname_h, outalbx *
k_half + 0.1_mm, outalby *
k_half + 0.1_mm, zHalf + 0.1_mm));
227 SubtractionSolid(dd_Alname_j, outAl, outAltmp,
Position(outalbx *
k_half, outalby *
k_half + shiftR, 0)));
229 outalby2 = es.absAlX_Y * 0.1;
230 outalbx2 = es.rMax_Abs_Al + 0.1_mm - es.absAlX_subtr1_Xshift;
231 shiftR2 = es.absAlX_subtr1_Xshift;
233 outalby2 = es.absAlY_Y * 0.1;
234 outalbx2 = es.rMax_Abs_Al + 0.1_mm - es.absAlY_subtr1_Xshift;
235 shiftR2 = es.absAlY_subtr1_Xshift;
238 dd_Alname_i, Box(dd_Alname_i, outalbx2 *
k_half + 0.1_mm, outalby2 *
k_half + 0.1_mm, zHalf + 0.1_mm));
242 dd_Alname_k, outAltmp3, outAltmp2,
Position(outalbx2 *
k_half + shiftR2, outalby2 *
k_half, 0)));
244 ns.
addSolid(dd_Alname_l, UnionSolid(dd_Alname_l, outAltmp4, outAltmp4, ns.
rotation(
"esalgo:RABS90")));
246 ns.
addSolid(dd_Alname_m, UnionSolid(dd_Alname_m, outAltmp5, outAltmp4, ns.
rotation(
"esalgo:RABS180B")));
248 ns.
addSolid(dd_Alname_g, UnionSolid(dd_Alname_g, outAltmp6, outAltmp4, ns.
rotation(
"esalgo:R180")));
250 Solid outAlCut = Box(65_cm, 60_cm - 0.1_mm, zHalf + 0.2_mm);
251 Solid outAlFin = SubtractionSolid(outAl2, outAlCut);
255 for (
int L = 0;
L < absz; ++
L) {
257 ostringstream tmp_name_b, tmp_name_b2, tmp_FAl_name_c, tmp_FAl_name_d1, tmp_FAl_name_d2, tmp_FAl_name_d3,
259 tmp_name_b << es.layName[
i] <<
"L" << K;
260 tmp_name_b2 << es.layName[
i] <<
"Lb2" << K;
263 tmp_FAl_name_c << es.layName[
i] <<
"LOutAl2";
265 tmp_FAl_name_c << es.layName[
i] <<
"LtmpAl" << K - 1;
267 tmp_FAl_name_d1 << es.layName[
i] <<
"LtmpAl" << K <<
"_1";
268 tmp_FAl_name_d2 << es.layName[
i] <<
"LtmpAl" << K <<
"_2";
269 tmp_FAl_name_d3 << es.layName[
i] <<
"LtmpAl" << K <<
"_3";
270 tmp_FAl_name_d << es.layName[
i] <<
"LtmpAl" << K;
272 const string& dd_tmp_name_b(
"esalgo:" + tmp_name_b.str());
273 const string& dd_tmp_name_b2(
"esalgo:" + tmp_name_b2.str());
274 const string& dd_FAl_name_c(
"esalgo:" + tmp_FAl_name_c.str());
275 const string& dd_FAl_name_d1(
"esalgo:" + tmp_FAl_name_d1.str());
276 const string& dd_FAl_name_d2(
"esalgo:" + tmp_FAl_name_d2.str());
277 const string& dd_FAl_name_d3(
"esalgo:" + tmp_FAl_name_d3.str());
278 const string& dd_FAl_name_d(
"esalgo:" + tmp_FAl_name_d.str());
283 bdx =
abs(es.abs1stx[K] - es.abs1stx[K - 1]) *
k_half;
285 if (es.abs1stx[K] < rIn + 30_cm) {
286 bdy = es.abs1sty[K] *
k_half - 30_cm;
294 bdx =
abs(es.abs2ndx[K] - es.abs2ndx[K - 1]) *
k_half;
298 if ((es.abs2ndx[K] < rIn + 30_cm) &&
I == 20) {
299 bdy = es.abs2ndy[K] *
k_half - 30_cm;
303 Solid solid_b = Box(dd_tmp_name_b, bdx, bdy, zHalf);
304 Solid solid_b2 = Box(dd_tmp_name_b2, bdx + 0.1_mm, bdy + 0.1_mm, zHalf);
306 sdx = es.abs1stx[K] - bdx;
308 if (es.abs1stx[K] < rIn + 30_cm)
309 sdy = es.abs1sty[K] - bdy;
312 sdx = es.abs2ndx[K] - bdx;
315 if ((es.abs2ndx[K] < rIn + 30_cm) &&
I == 20)
316 sdy = es.abs2ndy[K] - bdy;
320 layerFinOutAl.placeVolume(layer, 1,
Position(sdx, sdy, 0));
321 layerFinOutAl.placeVolume(layer, 2,
Position(-sdx, sdy, 0));
323 Solid solid_c = ns.
solid(dd_FAl_name_c);
325 ns.
addSolid(dd_FAl_name_d1, UnionSolid(dd_FAl_name_d1, solid_c, solid_b2,
Position(sdx, sdy, 0)));
327 ns.
addSolid(dd_FAl_name_d, UnionSolid(dd_FAl_name_d, solid_d1, solid_b2,
Position(-sdx, -sdy, 0)));
329 if (((es.abs1stx[K] < rIn + 30_cm) &&
I == 10) || ((es.abs2ndx[K] < rIn + 30_cm) &&
I == 20)) {
330 layerFinOutAl.placeVolume(layer, 3,
Position(sdx, -sdy, 0));
331 layerFinOutAl.placeVolume(layer, 4,
Position(-sdx, -sdy, 0));
333 Solid solid_c = ns.
solid(dd_FAl_name_c);
334 Solid solid_d1 = UnionSolid(dd_FAl_name_d1, solid_c, solid_b2,
Position(sdx, sdy, 0));
335 ns.
addSolid(dd_FAl_name_d2, UnionSolid(dd_FAl_name_d2, solid_d1, solid_b2,
Position(sdx, -sdy, 0)));
336 Solid solid_d3 = UnionSolid(dd_FAl_name_d3, solid_d2, solid_b2,
Position(-sdx, sdy, 0));
337 ns.
addSolid(dd_FAl_name_d, UnionSolid(dd_FAl_name_d, solid_d3, solid_b2,
Position(-sdx, -sdy, 0)));
341 bdx = es.abs1stx[cutabsx];
343 bdx = es.abs2ndx[cutabsy];
346 Solid solidcut = Box(dd_tmp_name_b, bdx, bdy, zHalf);
347 Solid iner = Tube(dd_tmp_name_c, 0, es.in_rad_Abs_Pb, zHalf + 0.1_mm, 0., 360._deg);
348 Solid
final = SubtractionSolid(dd_tmp_name_d, solidcut, iner);
351 parentVolume.placeVolume(blayer, 1,
Position(0, 0, zpos));
353 Solid iner_Al = Tube(dd_tmp_name_e, es.in_rad_Abs_Al, es.in_rad_Abs_Pb - 0.01_mm, zHalf, 0., 360._deg);
355 parentVolume.placeVolume(layerAl, 1,
Position(0, 0, zpos));
356 parentVolume.placeVolume(layerFinOutAl, 1,
Position(0, 0, zpos));
358 parentVolume.placeVolume(layer, 1,
Position(0., 0., zpos));
365 double xpos(0.), ypos(0.), zpos(0.);
366 float prev_length(0.), ladder_new_length(0.);
367 float ladd_shift(0.);
368 float ladder_length(0.);
369 int swed_scopy_glob(0);
371 for (
int M = 0; M <
int(es.typesL5.size() + es.typesL4.size()); M++) {
373 int ladd_not_plain(0), ladd_subtr_no(0), ladd_upper(0);
377 if (M <
int(es.typesL5.size())) {
378 for (
int i = 0;
i <= 1;
i++) {
379 for (
int j = 0;
j <= 3;
j++) {
380 if (es.laddL5map[(
i +
j * 2 + M * 10)] != 1) {
389 const string& ddname(
"esalgo:" + es.ladPfx[0] + es.typesL5[M]);
390 ladder_length = es.micromodule_length + 4 * es.waf_active + 0.1_mm;
392 if (ladd_not_plain) {
395 ns.
addAssembly(
"esalgo:" + es.ladPfx[1] + es.typesL5[M]);
400 ns.
addAssembly(
"esalgo:" + es.ladPfx[1] + es.typesL5[M]);
406 if (M >=
int(es.typesL5.size())) {
407 int d = M - es.typesL5.size();
409 for (
int i = 0;
i <= 1;
i++) {
410 for (
int j = 0;
j <= 3;
j++) {
411 if (es.laddL4map[(
i +
j * 2 + (M - es.typesL5.size()) * 8)] != 1) {
420 const string& ddname(
"esalgo:" + es.ladPfx[0] + es.typesL4[
d]);
421 ladder_length = es.micromodule_length + 3 * es.waf_active + 0.1_mm;
423 if (ladd_not_plain) {
426 ns.
addAssembly(
"esalgo:" + es.ladPfx[1] + es.typesL4[
d]);
430 if (ladd_subtr_no > 1) {
432 ns.
addAssembly(
"esalgo:" + es.ladPfx[1] + es.typesL4[
d]);
435 ns.
addAssembly(
"esalgo:" + es.ladPfx[1] + es.typesL4[
d]);
441 ns.
addAssembly(
"esalgo:" + es.ladPfx[1] + es.typesL4[
d]);
447 if (M <
int(es.typesL5.size())) {
448 const string& ddname(
"esalgo:" + es.ladPfx[0] + es.typesL5[M]);
449 const string& ddname2(
"esalgo:" + es.ladPfx[1] + es.typesL5[M]);
450 for (
int i = 0;
i <= 1;
i++) {
451 for (
int j = 0;
j <= 4;
j++) {
452 xpos = (
i * 2 - 1) * es.waf_intra_col_sep *
k_half;
453 ypos = -ladder_length *
k_half + 0.05_mm - (es.ldrFrnt_Length - es.ldrBck_Length) *
k_half +
454 es.wedge_length *
k_half +
j * es.waf_active;
455 zpos = -es.ladder_thick *
k_half + 0.005_mm + es.wedge_offset;
456 if (es.laddL5map[(
i +
j * 2 + M * 10)] == 1) {
458 ns.
assembly(ddname).placeVolume(swedLog,
459 scopy + 1000 * swed_scopy_glob,
461 ns.
assembly(ddname2).placeVolume(swedLog,
462 scopy + 1000 * swed_scopy_glob + 100,
465 ypos = ypos + es.ywedge_ceramic_diff;
466 zpos = -es.ladder_thick *
k_half + 0.005_mm + es.zwedge_ceramic_diff;
467 ns.
assembly(ddname).placeVolume(sfbxLog,
468 scopy + 1000 * swed_scopy_glob,
470 ns.
assembly(ddname2).placeVolume(sfbyLog,
471 scopy + 1000 * swed_scopy_glob,
477 int d = M - es.typesL5.size();
478 const string& ddname(
"esalgo:" + es.ladPfx[0] + es.typesL4[
d]);
479 const string& ddname2(
"esalgo:" + es.ladPfx[1] + es.typesL4[
d]);
480 for (
int i = 0;
i <= 1;
i++) {
481 for (
int j = 0;
j <= 3;
j++) {
482 xpos = (
i * 2 - 1) * es.waf_intra_col_sep *
k_half;
483 ypos = -ladder_length *
k_half + 0.05_mm - (es.ldrFrnt_Length - es.ldrBck_Length) *
k_half +
484 es.wedge_length *
k_half +
j * es.waf_active;
485 zpos = -es.ladder_thick *
k_half + 0.005_mm + es.wedge_offset;
486 if (es.laddL4map[(
i +
j * 2 + (M - es.typesL5.size()) * 8)] == 1) {
488 ns.
assembly(ddname).placeVolume(swedLog,
489 scopy + 1000 * swed_scopy_glob,
491 ns.
assembly(ddname2).placeVolume(swedLog,
492 scopy + 1000 * swed_scopy_glob + 100,
495 ypos = ypos + es.ywedge_ceramic_diff;
496 zpos = -es.ladder_thick *
k_half + 0.005_mm + es.zwedge_ceramic_diff;
497 ns.
assembly(ddname).placeVolume(sfbxLog,
498 scopy + 1000 * swed_scopy_glob,
500 ns.
assembly(ddname2).placeVolume(sfbyLog,
501 scopy + 1000 * swed_scopy_glob,
510 int icopy[100] = {0};
511 constexpr
int sz = 20;
513 for (
int I = -9;
I <= 9; ++
I) {
516 for (
int K = 0; K < es.noLaddInCol[J]; K++) {
519 ladder_new_length = es.micromodule_length + 3. * es.waf_active;
520 ladd_shift = 4. * es.waf_active;
523 type = es.typeOfLaddRow0[J];
525 type = es.typeOfLaddRow1[J];
527 type = es.typeOfLaddRow2[J];
529 type = es.typeOfLaddRow3[J];
531 for (
const auto&
i : es.typesL5)
533 ladder_new_length = es.micromodule_length + 4. * es.waf_active;
534 ladd_shift = 5. * es.waf_active;
539 for (
int t = 0;
t <
int(es.typesL5.size());
t++)
540 if (
type == es.typesL5[
t]) {
542 if (
I < 0 && es.asymLadd[
t] == 1) {
544 type = es.typesL5[
j];
547 for (
int t = 0;
t <
int(es.typesL4.size());
t++)
548 if (
type == es.typesL4[
t]) {
549 j =
t + es.typesL5.size();
550 if (
I < 0 && es.asymLadd[(
t + es.typesL5.size())] == 1) {
552 type = es.typesL4[
j - es.typesL5.size()];
556 xpos =
I * (2 * es.waf_intra_col_sep + es.waf_inter_col_sep);
558 xpos = xpos + es.dee_separation;
560 xpos = xpos - es.dee_separation;
562 ypos = (sz -
int(es.startOfFirstLadd[J])) * es.waf_active - ladder_new_length *
k_half +
563 (es.ldrFrnt_Length - es.ldrBck_Length) *
k_half + es.micromodule_length + 0.05_cm - prev_length;
565 prev_length += ladd_shift;
567 zpos = es.zlead1 + es.ladder_thick *
k_half + 0.01_mm;
570 sfLog.placeVolume(ns.
assembly(
"esalgo:" + es.ladPfx[0] +
type), icopy[
j],
Position(xpos, ypos, zpos));
572 xpos =
I * (2 * es.waf_intra_col_sep + es.waf_inter_col_sep);
574 sfLog.placeVolume(ns.
assembly(
"esalgo:" + es.ladPfx[1] +
type),
576 Transform3D(ns.
rotation(
"esalgo:R270"),
Position(ypos, -xpos, zpos - es.zlead1 + es.zlead2)));
579 for (
int t = 0;
t <
int(es.typesL5.size());
t++)
580 if (
type == es.typesL5[
t]) {
582 if (es.asymLadd[
t] == 2 && !changed) {
586 if (es.asymLadd[
t] == 1 && !changed) {
590 type = es.typesL5[
j];
592 for (
int t = 0;
t <
int(es.typesL4.size());
t++)
593 if (
type == es.typesL4[
t]) {
594 j =
t + es.typesL5.size();
595 if (es.asymLadd[(
t + es.typesL5.size())] == 2 && !changed) {
599 if (es.asymLadd[(
t + es.typesL5.size())] == 1 && !changed) {
603 type = es.typesL4[
j - es.typesL5.size()];
609 xpos = xpos + es.dee_separation;
611 xpos = xpos - es.dee_separation;
613 sfLog.placeVolume(ns.
assembly(
"esalgo:" + es.ladPfx[0] +
type),
617 xpos =
I * (2 * es.waf_intra_col_sep + es.waf_inter_col_sep);
622 Transform3D(ns.
rotation(
"esalgo:R090"),
Position(-ypos, -xpos, zpos - es.zlead1 + es.zlead2)));
628 float xpos(0), ypos(0);
634 for (
size_t i = 0;
i < 32; ++
i) {
636 sfwxLog.placeVolume(sfsxLog,
i + 1,
Position(xpos, 0., 0.));
639 sfwyLog.placeVolume(sfsyLog,
i + 1,
Position(0., ypos, 0.));