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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
|
///////////////////////////////////////////////////////////////////////////////
// File: DDHCalEndcapModuleAlgo.cc
// adapted from CCal(G4)HcalEndcap.cc
// Description: Geometry factory class for Hcal Endcap
///////////////////////////////////////////////////////////////////////////////
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include "DataFormats/Math/interface/angle_units.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DD4hep/DetFactoryHelper.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "DetectorDescription/DDCMS/interface/DDutils.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
//#define EDM_ML_DEBUG
using namespace angle_units::operators;
struct HCalEndcapModuleAlgo {
std::string genMaterial; //General material
std::string absorberMat; //Absorber material
std::string plasticMat; //Plastic material cover
std::string scintMat; //Scintillator material
std::string rotstr; //Rotation matrix to place in mother
int sectors; //Number of potenital straight edges
double zMinBlock; //Minimum z extent of the block
double zMaxBlock; //Maximum
double z1Beam; //Position of gap end along z-axis
double ziDip; //Starting Z of dipped part of body
double dzStep; //Width in Z of a layer
double moduleThick; //Thickness of a layer (air/absorber)
double layerThick; //Thickness of a layer (plastic)
double scintThick; //Thickness of scinitllator
double rMaxBack; //Maximum R after the dip
double rMaxFront; //Maximum R before the dip
double slopeBot; //Slope of the bottom edge
double slopeTop; //Slope of the top edge
double slopeTopF; //Slope of the top front edge
double trimLeft; //Trim of the left edge
double trimRight; //Trim of the right edge
double tolAbs; //Tolerance for absorber
int modType; //Type of module
int modNumber; //Module number
int layerType; //Layer type
std::vector<int> layerNumber; //layer numbers
std::vector<std::string> phiName; //Name of Phi sections
std::vector<std::string> layerName; //Layer Names
std::string idName; //Name of the "parent" volume.
std::string modName; //Module Name
int idOffset; // Geant4 ID's... = 4000;
struct HcalEndcapPar {
double yh1, bl1, tl1, yh2, bl2, tl2, alp, theta, phi, xpos, ypos, zpos;
HcalEndcapPar(double yh1v = 0,
double bl1v = 0,
double tl1v = 0,
double yh2v = 0,
double bl2v = 0,
double tl2v = 0,
double alpv = 0,
double thv = 0,
double fiv = 0,
double x = 0,
double y = 0,
double z = 0)
: yh1(yh1v),
bl1(bl1v),
tl1(tl1v),
yh2(yh2v),
bl2(bl2v),
tl2(tl2v),
alp(alpv),
theta(thv),
phi(fiv),
xpos(x),
ypos(y),
zpos(z) {}
};
HCalEndcapModuleAlgo() = delete;
HCalEndcapModuleAlgo(cms::DDParsingContext& ctxt, xml_h e) {
cms::DDNamespace ns(ctxt, e, true);
cms::DDAlgoArguments args(ctxt, e);
genMaterial = args.value<std::string>("MaterialName");
absorberMat = args.value<std::string>("AbsorberMat");
plasticMat = args.value<std::string>("PlasticMat");
scintMat = args.value<std::string>("ScintMat");
rotstr = args.value<std::string>("Rotation");
sectors = args.value<int>("Sectors");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: General material " << genMaterial << "\tAbsorber "
<< absorberMat << "\tPlastic " << plasticMat << "\tScintillator " << scintMat
<< "\tRotation " << rotstr << "\tSectors " << sectors;
#endif
zMinBlock = args.value<double>("ZMinBlock");
zMaxBlock = args.value<double>("ZMaxBlock");
z1Beam = args.value<double>("Z1Beam");
ziDip = args.value<double>("ZiDip");
dzStep = args.value<double>("DzStep");
moduleThick = args.value<double>("ModuleThick");
layerThick = args.value<double>("LayerThick");
scintThick = args.value<double>("ScintThick");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Zmin " << cms::convert2mm(zMinBlock) << "\tZmax "
<< cms::convert2mm(zMaxBlock) << "\tZ1Beam " << cms::convert2mm(z1Beam) << "\tZiDip "
<< cms::convert2mm(ziDip) << "\tDzStep " << cms::convert2mm(dzStep) << "\tModuleThick "
<< cms::convert2mm(moduleThick) << "\tLayerThick " << cms::convert2mm(layerThick)
<< "\tScintThick " << cms::convert2mm(scintThick);
#endif
rMaxFront = args.value<double>("RMaxFront");
rMaxBack = args.value<double>("RMaxBack");
trimLeft = args.value<double>("TrimLeft");
trimRight = args.value<double>("TrimRight");
tolAbs = args.value<double>("TolAbs");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: RMaxFront " << cms::convert2mm(rMaxFront) << "\tRmaxBack "
<< cms::convert2mm(rMaxBack) << "\tTrims " << cms::convert2mm(trimLeft) << ":"
<< cms::convert2mm(trimRight) << "\tTolAbs " << cms::convert2mm(tolAbs);
#endif
slopeBot = args.value<double>("SlopeBottom");
slopeTop = args.value<double>("SlopeTop");
slopeTopF = args.value<double>("SlopeTopFront");
modType = args.value<int>("ModType");
modNumber = args.value<int>("ModNumber");
layerType = args.value<int>("LayerType");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: slopeBot " << slopeBot << "\tslopeTop " << slopeTop
<< "\tslopeTopF " << slopeTopF << "\tmodType " << modType << "\tmodNumber "
<< modNumber << "\tlayerType " << layerType;
#endif
layerNumber = args.value<std::vector<int> >("LayerNumber");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << layerNumber.size() << " layer Numbers";
for (unsigned int i = 0; i < layerNumber.size(); ++i)
edm::LogVerbatim("HCalGeom") << "LayerNumber[" << i << "] = " << layerNumber[i];
#endif
phiName = args.value<std::vector<std::string> >("PhiName");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << phiName.size() << " phi sectors";
for (unsigned int i = 0; i < phiName.size(); ++i)
edm::LogVerbatim("HCalGeom") << "PhiName[" << i << "] = " << phiName[i];
#endif
layerName = args.value<std::vector<std::string> >("LayerName");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << layerName.size() << " layers";
for (unsigned int i = 0; i < layerName.size(); ++i)
edm::LogVerbatim("HCalGeom") << "LayerName[" << i << "] = " << layerName[i];
#endif
idName = args.value<std::string>("MotherName");
idOffset = args.value<int>("IdOffset");
modName = args.value<std::string>("ModName");
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Parent " << args.parentName() << " " << modName
<< " idName " << idName << " NameSpace " << ns.name() << " Offset " << idOffset;
#endif
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "==>> Constructing DDHCalEndcapModuleAlgo...";
#endif
dd4hep::Volume mother = ns.volume(args.parentName());
if (modType == 0)
constructInsideModule0(ctxt, e, mother);
else
constructInsideModule(ctxt, e, mother);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalEndcapModuleAlgo construction ...";
#endif
}
void constructInsideModule0(cms::DDParsingContext& ctxt, xml_h e, dd4hep::Volume& module) {
cms::DDNamespace ns(ctxt, e, true);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: \t\tInside module0";
#endif
///////////////////////////////////////////////////////////////
//Pointers to the Materials
dd4hep::Material matabsorbr = ns.material(absorberMat);
dd4hep::Material matplastic = ns.material(plasticMat);
dd4hep::Rotation3D rot = getRotation(rotstr, ns);
int layer = layerNumber[0];
int layer0 = layerNumber[1];
std::string name;
dd4hep::Solid solid;
dd4hep::Volume glog;
for (unsigned int iphi = 0; iphi < phiName.size(); iphi++) {
HCalEndcapModuleAlgo::HcalEndcapPar parm = parameterLayer0(iphi);
name = idName + modName + layerName[0] + phiName[iphi];
solid = dd4hep::Trap(ns.prepend(name),
0.5 * layerThick,
0,
0,
parm.yh1,
parm.bl1,
parm.tl1,
parm.alp,
parm.yh2,
parm.bl1,
parm.tl2,
parm.alp);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of " << plasticMat
<< " of dimensions " << cms::convert2mm(0.5 * layerThick) << ", 0, 0, "
<< cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
<< cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
<< cms::convert2mm(parm.yh2) << ", " << cms::convert2mm(parm.bl2) << ", "
<< cms::convert2mm(parm.tl2) << ", " << convertRadToDeg(parm.alp);
#endif
glog = dd4hep::Volume(solid.name(), solid, matplastic);
dd4hep::Position r1(parm.xpos, parm.ypos, parm.zpos);
module.placeVolume(glog, idOffset + layer + 1, dd4hep::Transform3D(rot, r1));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << glog.name() << " number " << (idOffset + layer + 1)
<< " positioned in " << module.name() << " at (" << cms::convert2mm(parm.xpos)
<< ", " << cms::convert2mm(parm.ypos) << ", " << cms::convert2mm(parm.zpos)
<< ") with rotation: " << rot;
#endif
//Now construct the layer of scintillator inside this
int copyNo = layer0 * 10 + layerType;
name = modName + layerName[0] + phiName[iphi];
constructScintLayer(glog, scintThick, parm, name, copyNo, ns);
}
//Now the absorber layer
double zi = zMinBlock + layerThick;
double zo = zi + 0.5 * dzStep;
double rinF, routF, rinB, routB;
if (modNumber == 0) {
rinF = zi * slopeTopF;
routF = (zi - z1Beam) * slopeTop;
rinB = zo * slopeTopF;
routB = (zo - z1Beam) * slopeTop;
} else if (modNumber > 0) {
rinF = zi * slopeBot;
routF = zi * slopeTopF;
rinB = zo * slopeBot;
routB = zo * slopeTopF;
} else {
rinF = zi * slopeBot;
routF = (zi - z1Beam) * slopeTop;
rinB = zo * slopeBot;
routB = (zo - z1Beam) * slopeTop;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Front " << cms::convert2mm(zi) << ", "
<< cms::convert2mm(rinF) << ", " << cms::convert2mm(routF) << " Back "
<< cms::convert2mm(zo) << ", " << cms::convert2mm(rinB) << ", "
<< cms::convert2mm(routB);
#endif
HCalEndcapModuleAlgo::HcalEndcapPar parm = parameterLayer(0, rinF, routF, rinB, routB, zi, zo);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Trim " << cms::convert2mm(tolAbs) << " Param "
<< cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
<< cms::convert2mm(parm.tl1) << ", " << cms::convert2mm(parm.yh2) << ", "
<< cms::convert2mm(parm.bl2) << ", " << cms::convert2mm(parm.tl2);
#endif
parm.bl1 -= tolAbs;
parm.tl1 -= tolAbs;
parm.bl2 -= tolAbs;
parm.tl2 -= tolAbs;
name = idName + modName + layerName[0] + "Absorber";
solid = dd4hep::Trap(ns.prepend(name),
0.5 * moduleThick,
parm.theta,
parm.phi,
parm.yh1,
parm.bl1,
parm.tl1,
parm.alp,
parm.yh2,
parm.bl2,
parm.tl2,
parm.alp);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of " << matabsorbr.name()
<< " of dimensions " << cms::convert2mm(0.5 * moduleThick) << ", "
<< convertRadToDeg(parm.theta) << ", " << convertRadToDeg(parm.phi) << ", "
<< cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
<< cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
<< cms::convert2mm(parm.yh2) << ", " << cms::convert2mm(parm.bl2) << ", "
<< cms::convert2mm(parm.tl2) << ", " << convertRadToDeg(parm.alp);
#endif
glog = dd4hep::Volume(solid.name(), solid, matabsorbr);
dd4hep::Position r2(parm.xpos, parm.ypos, parm.zpos);
module.placeVolume(glog, idOffset + layer + 1, dd4hep::Transform3D(rot, r2));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << glog.name() << " number 1 positioned in "
<< module.name() << " at (" << cms::convert2mm(parm.xpos) << ", "
<< cms::convert2mm(parm.ypos) << ", " << cms::convert2mm(parm.zpos)
<< ") with rotation: " << rot;
#endif
}
void constructInsideModule(cms::DDParsingContext& ctxt, xml_h e, dd4hep::Volume& module) {
cms::DDNamespace ns(ctxt, e, true);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: \t\tInside module";
#endif
///////////////////////////////////////////////////////////////
//Pointers to the Rotation Matrices and to the Materials
dd4hep::Material matter = ns.material(genMaterial);
dd4hep::Material matplastic = ns.material(plasticMat);
dd4hep::Rotation3D rot = getRotation(rotstr, ns);
double alpha = (1._pi) / sectors;
double zi = zMinBlock;
for (unsigned int i = 0; i < layerName.size(); i++) {
std::string name;
dd4hep::Solid solid;
dd4hep::Volume glog, plog;
int layer = layerNumber[i];
double zo = zi + 0.5 * dzStep;
for (unsigned int iphi = 0; iphi < phiName.size(); iphi++) {
double ziAir = zo - moduleThick;
double rinF, rinB;
if (modNumber == 0) {
rinF = ziAir * slopeTopF;
rinB = zo * slopeTopF;
} else {
rinF = ziAir * slopeBot;
rinB = zo * slopeBot;
}
double routF = getRout(ziAir);
double routB = getRout(zo);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Layer " << i << " Phi " << iphi << " Front "
<< cms::convert2mm(ziAir) << ", " << cms::convert2mm(rinF) << ", "
<< cms::convert2mm(routF) << " Back " << cms::convert2mm(zo) << ", "
<< cms::convert2mm(rinB) << ", " << cms::convert2mm(routB);
#endif
HCalEndcapModuleAlgo::HcalEndcapPar parm = parameterLayer(iphi, rinF, routF, rinB, routB, ziAir, zo);
name = idName + modName + layerName[i] + phiName[iphi] + "Air";
solid = dd4hep::Trap(ns.prepend(name),
0.5 * moduleThick,
parm.theta,
parm.phi,
parm.yh1,
parm.bl1,
parm.tl1,
parm.alp,
parm.yh2,
parm.bl2,
parm.tl2,
parm.alp);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of " << matter.name()
<< " of dimensions " << cms::convert2mm(0.5 * moduleThick) << ", "
<< convertRadToDeg(parm.theta) << ", " << convertRadToDeg(parm.phi) << ", "
<< cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
<< cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
<< cms::convert2mm(parm.yh2) << ", " << cms::convert2mm(parm.bl2) << ", "
<< cms::convert2mm(parm.tl2) << ", " << convertRadToDeg(parm.alp);
#endif
glog = dd4hep::Volume(solid.name(), solid, matter);
dd4hep::Position r1(parm.xpos, parm.ypos, parm.zpos);
module.placeVolume(glog, layer + 1, dd4hep::Transform3D(rot, r1));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << glog.name() << " number " << (layer + 1)
<< " positioned in " << module.name() << " at (" << cms::convert2mm(parm.xpos)
<< ", " << cms::convert2mm(parm.ypos) << ", " << cms::convert2mm(parm.zpos)
<< ") with rotation: " << rot;
#endif
//Now the plastic with scintillators
parm.yh1 = 0.5 * (routF - rinB) - getTrim(iphi);
parm.bl1 = 0.5 * rinB * tan(alpha) - getTrim(iphi);
parm.tl1 = 0.5 * routF * tan(alpha) - getTrim(iphi);
name = idName + modName + layerName[i] + phiName[iphi];
solid = dd4hep::Trap(ns.prepend(name),
0.5 * layerThick,
0,
0,
parm.yh1,
parm.bl1,
parm.tl1,
parm.alp,
parm.yh1,
parm.bl1,
parm.tl1,
parm.alp);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of "
<< matplastic.name() << " of dimensions " << cms::convert2mm(0.5 * layerThick)
<< ", 0, 0, " << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1)
<< ", " << cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
<< cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
<< cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp);
#endif
plog = dd4hep::Volume(solid.name(), solid, matplastic);
double ypos = 0.5 * (routF + rinB) - parm.xpos;
dd4hep::Position r2(0., ypos, 0.);
glog.placeVolume(plog, idOffset + layer + 1, r2);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << plog.name() << " number "
<< (idOffset + layer + 1) << " positioned in " << glog.name() << " at (0, "
<< cms::convert2mm(ypos) << ", 0) with no rotation";
#endif
//Constructin the scintillators inside
int copyNo = layer * 10 + layerType;
name = modName + layerName[i] + phiName[iphi];
constructScintLayer(plog, scintThick, parm, name, copyNo, ns);
zo += 0.5 * dzStep;
} // End of loop over phi indices
zi = zo - 0.5 * dzStep;
} // End of loop on layers
}
HcalEndcapPar parameterLayer0(unsigned int iphi) {
HCalEndcapModuleAlgo::HcalEndcapPar parm;
//Given module and layer number compute parameters of trapezoid
//and positioning parameters
double alpha = (1._pi) / sectors;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "Input " << iphi << " Alpha " << convertRadToDeg(alpha);
#endif
double zi, zo;
if (iphi == 0) {
zi = zMinBlock;
zo = zi + layerThick;
} else {
zo = zMaxBlock;
zi = zo - layerThick;
}
double rin, rout;
if (modNumber == 0) {
rin = zo * slopeTopF;
rout = (zi - z1Beam) * slopeTop;
} else if (modNumber > 0) {
rin = zo * slopeBot;
rout = zi * slopeTopF;
} else {
rin = zo * slopeBot;
rout = (zi - z1Beam) * slopeTop;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "ModNumber " << modNumber << " " << cms::convert2mm(zi) << " "
<< cms::convert2mm(zo) << " " << slopeTopF << " " << slopeTop << " " << slopeBot << " "
<< cms::convert2mm(rin) << " " << cms::convert2mm(rout) << " "
<< cms::convert2mm(getTrim(iphi));
#endif
double yh = 0.5 * (rout - rin);
double bl = 0.5 * rin * tan(alpha);
double tl = 0.5 * rout * tan(alpha);
parm.xpos = 0.5 * (rin + rout);
parm.ypos = 0.5 * (bl + tl);
parm.zpos = 0.5 * (zi + zo);
parm.yh1 = parm.yh2 = yh - getTrim(iphi);
parm.bl1 = parm.bl2 = bl - getTrim(iphi);
parm.tl1 = parm.tl2 = tl - getTrim(iphi);
parm.alp = atan(0.5 * tan(alpha));
if (iphi == 0) {
parm.ypos = -parm.ypos;
} else {
parm.alp = -parm.alp;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "Output Dimensions " << cms::convert2mm(parm.yh1) << " "
<< cms::convert2mm(parm.bl1) << " " << cms::convert2mm(parm.tl1) << " "
<< convertRadToDeg(parm.alp) << " Position " << cms::convert2mm(parm.xpos) << " "
<< cms::convert2mm(parm.ypos) << " " << cms::convert2mm(parm.zpos);
#endif
return parm;
}
HcalEndcapPar parameterLayer(
unsigned int iphi, double rinF, double routF, double rinB, double routB, double zi, double zo) {
HCalEndcapModuleAlgo::HcalEndcapPar parm;
//Given rin, rout compute parameters of the trapezoid and
//position of the trapezoid for a standrd layer
double alpha = (1._pi) / sectors;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "Input " << iphi << " Front " << cms::convert2mm(rinF) << " "
<< cms::convert2mm(routF) << " " << cms::convert2mm(zi) << " Back "
<< cms::convert2mm(rinB) << " " << cms::convert2mm(routB) << " " << cms::convert2mm(zo)
<< " Alpha " << convertRadToDeg(alpha);
#endif
parm.yh1 = 0.5 * (routF - rinB);
parm.bl1 = 0.5 * rinB * tan(alpha);
parm.tl1 = 0.5 * routF * tan(alpha);
parm.yh2 = 0.5 * (routF - rinB);
parm.bl2 = 0.5 * rinB * tan(alpha);
parm.tl2 = 0.5 * routF * tan(alpha);
double dx = 0.25 * (parm.bl2 + parm.tl2 - parm.bl1 - parm.tl1);
double dy = 0.5 * (rinB + routF - rinB - routF);
parm.xpos = 0.25 * (rinB + routF + rinB + routF);
parm.ypos = 0.25 * (parm.bl2 + parm.tl2 + parm.bl1 + parm.tl1);
parm.zpos = 0.5 * (zi + zo);
parm.alp = atan(0.5 * tan(alpha));
if (iphi == 0) {
parm.ypos = -parm.ypos;
} else {
parm.alp = -parm.alp;
dx = -dx;
}
double r = sqrt(dx * dx + dy * dy);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "dx|dy|r " << cms::convert2mm(dx) << ":" << cms::convert2mm(dy) << ":"
<< cms::convert2mm(r);
#endif
if (r > 1.0e-8) {
parm.theta = atan(r / (zo - zi));
parm.phi = atan2(dy, dx);
} else {
parm.theta = parm.phi = 0;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "Output Dimensions " << cms::convert2mm(parm.yh1) << " "
<< cms::convert2mm(parm.bl1) << " " << cms::convert2mm(parm.tl1) << " "
<< cms::convert2mm(parm.yh2) << " " << cms::convert2mm(parm.bl2) << " "
<< cms::convert2mm(parm.tl2) << " " << convertRadToDeg(parm.alp) << " "
<< convertRadToDeg(parm.theta) << " " << convertRadToDeg(parm.phi) << " Position "
<< cms::convert2mm(parm.xpos) << " " << cms::convert2mm(parm.ypos) << " "
<< cms::convert2mm(parm.zpos);
#endif
return parm;
}
void constructScintLayer(dd4hep::Volume& detector,
double dz,
HCalEndcapModuleAlgo::HcalEndcapPar parm,
const std::string& nm,
int id,
cms::DDNamespace& ns) {
dd4hep::Material matter = ns.material(scintMat);
std::string name = idName + "Scintillator" + nm;
dd4hep::Solid solid = dd4hep::Trap(
ns.prepend(name), 0.5 * dz, 0, 0, parm.yh1, parm.bl1, parm.tl1, parm.alp, parm.yh1, parm.bl1, parm.tl1, parm.alp);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of " << scintMat
<< " of dimensions " << cms::convert2mm(0.5 * dz) << ", 0, 0, "
<< cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
<< cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
<< cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
<< cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp);
#endif
dd4hep::Volume glog(solid.name(), solid, matter);
detector.placeVolume(glog, id);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << glog.name() << " number " << id << " positioned in "
<< detector.name() << " at (0,0,0) with no rotation";
#endif
}
double getTrim(unsigned int j) const {
if (j == 0)
return trimLeft;
else
return trimRight;
}
double getRout(double z) const {
double r = (modNumber >= 0) ? ((z - z1Beam) * slopeTop) : z * slopeTopF;
if (z > ziDip) {
if (r > rMaxBack)
r = rMaxBack;
} else {
if (r > rMaxFront)
r = rMaxFront;
}
return r;
}
dd4hep::Rotation3D getRotation(const std::string& rotstr, cms::DDNamespace& ns) {
std::string rot = (strchr(rotstr.c_str(), NAMESPACE_SEP) == nullptr) ? ("rotations:" + rotstr) : rotstr;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "getRotation: " << rotstr << ":" << rot << ":" << ns.rotation(rot);
#endif
return ns.rotation(rot);
}
};
static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
HCalEndcapModuleAlgo hcalendcapalgo(ctxt, e);
return cms::s_executed;
}
// first argument is the type from the xml file
DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalEndcapModuleAlgo, algorithm)
|