CMS 3D CMS Logo

DDHCalEndcapModuleAlgo.cc
Go to the documentation of this file.
1 // File: DDHCalEndcapModuleAlgo.cc
3 // adapted from CCal(G4)HcalEndcap.cc
4 // Description: Geometry factory class for Hcal Endcap
6 
7 #include <cmath>
8 #include <algorithm>
9 #include <string>
10 #include <vector>
11 
14 #include "DD4hep/DetFactoryHelper.h"
18 
19 //#define EDM_ML_DEBUG
20 using namespace angle_units::operators;
21 
23  std::string genMaterial; //General material
24  std::string absorberMat; //Absorber material
25  std::string plasticMat; //Plastic material cover
26  std::string scintMat; //Scintillator material
27  std::string rotstr; //Rotation matrix to place in mother
28  int sectors; //Number of potenital straight edges
29  double zMinBlock; //Minimum z extent of the block
30  double zMaxBlock; //Maximum
31  double z1Beam; //Position of gap end along z-axis
32  double ziDip; //Starting Z of dipped part of body
33  double dzStep; //Width in Z of a layer
34  double moduleThick; //Thickness of a layer (air/absorber)
35  double layerThick; //Thickness of a layer (plastic)
36  double scintThick; //Thickness of scinitllator
37  double rMaxBack; //Maximum R after the dip
38  double rMaxFront; //Maximum R before the dip
39  double slopeBot; //Slope of the bottom edge
40  double slopeTop; //Slope of the top edge
41  double slopeTopF; //Slope of the top front edge
42  double trimLeft; //Trim of the left edge
43  double trimRight; //Trim of the right edge
44  double tolAbs; //Tolerance for absorber
45  int modType; //Type of module
46  int modNumber; //Module number
47  int layerType; //Layer type
48  std::vector<int> layerNumber; //layer numbers
49  std::vector<std::string> phiName; //Name of Phi sections
50  std::vector<std::string> layerName; //Layer Names
51 
52  std::string idName; //Name of the "parent" volume.
53  std::string modName; //Module Name
54  int idOffset; // Geant4 ID's... = 4000;
55 
56  struct HcalEndcapPar {
57  double yh1, bl1, tl1, yh2, bl2, tl2, alp, theta, phi, xpos, ypos, zpos;
58  HcalEndcapPar(double yh1v = 0,
59  double bl1v = 0,
60  double tl1v = 0,
61  double yh2v = 0,
62  double bl2v = 0,
63  double tl2v = 0,
64  double alpv = 0,
65  double thv = 0,
66  double fiv = 0,
67  double x = 0,
68  double y = 0,
69  double z = 0)
70  : yh1(yh1v),
71  bl1(bl1v),
72  tl1(tl1v),
73  yh2(yh2v),
74  bl2(bl2v),
75  tl2(tl2v),
76  alp(alpv),
77  theta(thv),
78  phi(fiv),
79  xpos(x),
80  ypos(y),
81  zpos(z) {}
82  };
83 
84  HCalEndcapModuleAlgo() = delete;
85 
87  cms::DDNamespace ns(ctxt, e, true);
89 
90  genMaterial = args.value<std::string>("MaterialName");
91  absorberMat = args.value<std::string>("AbsorberMat");
92  plasticMat = args.value<std::string>("PlasticMat");
93  scintMat = args.value<std::string>("ScintMat");
94  rotstr = args.value<std::string>("Rotation");
95  sectors = args.value<int>("Sectors");
96 #ifdef EDM_ML_DEBUG
97  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: General material " << genMaterial << "\tAbsorber "
98  << absorberMat << "\tPlastic " << plasticMat << "\tScintillator " << scintMat
99  << "\tRotation " << rotstr << "\tSectors " << sectors;
100 #endif
101  zMinBlock = args.value<double>("ZMinBlock");
102  zMaxBlock = args.value<double>("ZMaxBlock");
103  z1Beam = args.value<double>("Z1Beam");
104  ziDip = args.value<double>("ZiDip");
105  dzStep = args.value<double>("DzStep");
106  moduleThick = args.value<double>("ModuleThick");
107  layerThick = args.value<double>("LayerThick");
108  scintThick = args.value<double>("ScintThick");
109 #ifdef EDM_ML_DEBUG
110  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Zmin " << cms::convert2mm(zMinBlock) << "\tZmax "
111  << cms::convert2mm(zMaxBlock) << "\tZ1Beam " << cms::convert2mm(z1Beam) << "\tZiDip "
112  << cms::convert2mm(ziDip) << "\tDzStep " << cms::convert2mm(dzStep) << "\tModuleThick "
113  << cms::convert2mm(moduleThick) << "\tLayerThick " << cms::convert2mm(layerThick)
114  << "\tScintThick " << cms::convert2mm(scintThick);
115 #endif
116  rMaxFront = args.value<double>("RMaxFront");
117  rMaxBack = args.value<double>("RMaxBack");
118  trimLeft = args.value<double>("TrimLeft");
119  trimRight = args.value<double>("TrimRight");
120  tolAbs = args.value<double>("TolAbs");
121 #ifdef EDM_ML_DEBUG
122  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: RMaxFront " << cms::convert2mm(rMaxFront) << "\tRmaxBack "
123  << cms::convert2mm(rMaxBack) << "\tTrims " << cms::convert2mm(trimLeft) << ":"
124  << cms::convert2mm(trimRight) << "\tTolAbs " << cms::convert2mm(tolAbs);
125 #endif
126  slopeBot = args.value<double>("SlopeBottom");
127  slopeTop = args.value<double>("SlopeTop");
128  slopeTopF = args.value<double>("SlopeTopFront");
129  modType = args.value<int>("ModType");
130  modNumber = args.value<int>("ModNumber");
131  layerType = args.value<int>("LayerType");
132 #ifdef EDM_ML_DEBUG
133  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: slopeBot " << slopeBot << "\tslopeTop " << slopeTop
134  << "\tslopeTopF " << slopeTopF << "\tmodType " << modType << "\tmodNumber "
135  << modNumber << "\tlayerType " << layerType;
136 #endif
137  layerNumber = args.value<std::vector<int> >("LayerNumber");
138 #ifdef EDM_ML_DEBUG
139  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << layerNumber.size() << " layer Numbers";
140  for (unsigned int i = 0; i < layerNumber.size(); ++i)
141  edm::LogVerbatim("HCalGeom") << "LayerNumber[" << i << "] = " << layerNumber[i];
142 #endif
143  phiName = args.value<std::vector<std::string> >("PhiName");
144 #ifdef EDM_ML_DEBUG
145  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << phiName.size() << " phi sectors";
146  for (unsigned int i = 0; i < phiName.size(); ++i)
147  edm::LogVerbatim("HCalGeom") << "PhiName[" << i << "] = " << phiName[i];
148 #endif
149  layerName = args.value<std::vector<std::string> >("LayerName");
150 #ifdef EDM_ML_DEBUG
151  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << layerName.size() << " layers";
152  for (unsigned int i = 0; i < layerName.size(); ++i)
153  edm::LogVerbatim("HCalGeom") << "LayerName[" << i << "] = " << layerName[i];
154 #endif
155  idName = args.value<std::string>("MotherName");
156  idOffset = args.value<int>("IdOffset");
157  modName = args.value<std::string>("ModName");
158 #ifdef EDM_ML_DEBUG
159  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Parent " << args.parentName() << " " << modName
160  << " idName " << idName << " NameSpace " << ns.name() << " Offset " << idOffset;
161 #endif
162 
163 #ifdef EDM_ML_DEBUG
164  edm::LogVerbatim("HCalGeom") << "==>> Constructing DDHCalEndcapModuleAlgo...";
165 #endif
166 
167  dd4hep::Volume mother = ns.volume(args.parentName());
168  if (modType == 0)
169  constructInsideModule0(ctxt, e, mother);
170  else
171  constructInsideModule(ctxt, e, mother);
172 #ifdef EDM_ML_DEBUG
173  edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalEndcapModuleAlgo construction ...";
174 #endif
175  }
176 
178  cms::DDNamespace ns(ctxt, e, true);
179 
180 #ifdef EDM_ML_DEBUG
181  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: \t\tInside module0";
182 #endif
183  //Pointers to the Materials
185  dd4hep::Material matabsorbr = ns.material(absorberMat);
186  dd4hep::Material matplastic = ns.material(plasticMat);
187  dd4hep::Rotation3D rot = getRotation(rotstr, ns);
188 
189  int layer = layerNumber[0];
190  int layer0 = layerNumber[1];
192  dd4hep::Solid solid;
193  dd4hep::Volume glog;
194  for (unsigned int iphi = 0; iphi < phiName.size(); iphi++) {
195  HCalEndcapModuleAlgo::HcalEndcapPar parm = parameterLayer0(iphi);
196  name = idName + modName + layerName[0] + phiName[iphi];
197  solid = dd4hep::Trap(ns.prepend(name),
198  0.5 * layerThick,
199  0,
200  0,
201  parm.yh1,
202  parm.bl1,
203  parm.tl1,
204  parm.alp,
205  parm.yh2,
206  parm.bl1,
207  parm.tl2,
208  parm.alp);
209 #ifdef EDM_ML_DEBUG
210  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of " << plasticMat
211  << " of dimensions " << cms::convert2mm(0.5 * layerThick) << ", 0, 0, "
212  << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
213  << cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
214  << cms::convert2mm(parm.yh2) << ", " << cms::convert2mm(parm.bl2) << ", "
215  << cms::convert2mm(parm.tl2) << ", " << convertRadToDeg(parm.alp);
216 #endif
217  glog = dd4hep::Volume(solid.name(), solid, matplastic);
218 
219  dd4hep::Position r1(parm.xpos, parm.ypos, parm.zpos);
220  module.placeVolume(glog, idOffset + layer + 1, dd4hep::Transform3D(rot, r1));
221 #ifdef EDM_ML_DEBUG
222  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << glog.name() << " number " << (idOffset + layer + 1)
223  << " positioned in " << module.name() << " at (" << cms::convert2mm(parm.xpos)
224  << ", " << cms::convert2mm(parm.ypos) << ", " << cms::convert2mm(parm.zpos)
225  << ") with rotation: " << rot;
226 #endif
227  //Now construct the layer of scintillator inside this
228  int copyNo = layer0 * 10 + layerType;
229  name = modName + layerName[0] + phiName[iphi];
230  constructScintLayer(glog, scintThick, parm, name, copyNo, ns);
231  }
232 
233  //Now the absorber layer
234  double zi = zMinBlock + layerThick;
235  double zo = zi + 0.5 * dzStep;
236  double rinF, routF, rinB, routB;
237  if (modNumber == 0) {
238  rinF = zi * slopeTopF;
239  routF = (zi - z1Beam) * slopeTop;
240  rinB = zo * slopeTopF;
241  routB = (zo - z1Beam) * slopeTop;
242  } else if (modNumber > 0) {
243  rinF = zi * slopeBot;
244  routF = zi * slopeTopF;
245  rinB = zo * slopeBot;
246  routB = zo * slopeTopF;
247  } else {
248  rinF = zi * slopeBot;
249  routF = (zi - z1Beam) * slopeTop;
250  rinB = zo * slopeBot;
251  routB = (zo - z1Beam) * slopeTop;
252  }
253 #ifdef EDM_ML_DEBUG
254  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Front " << cms::convert2mm(zi) << ", "
255  << cms::convert2mm(rinF) << ", " << cms::convert2mm(routF) << " Back "
256  << cms::convert2mm(zo) << ", " << cms::convert2mm(rinB) << ", "
257  << cms::convert2mm(routB);
258 #endif
259  HCalEndcapModuleAlgo::HcalEndcapPar parm = parameterLayer(0, rinF, routF, rinB, routB, zi, zo);
260 #ifdef EDM_ML_DEBUG
261  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Trim " << cms::convert2mm(tolAbs) << " Param "
262  << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
263  << cms::convert2mm(parm.tl1) << ", " << cms::convert2mm(parm.yh2) << ", "
264  << cms::convert2mm(parm.bl2) << ", " << cms::convert2mm(parm.tl2);
265 #endif
266  parm.bl1 -= tolAbs;
267  parm.tl1 -= tolAbs;
268  parm.bl2 -= tolAbs;
269  parm.tl2 -= tolAbs;
270 
271  name = idName + modName + layerName[0] + "Absorber";
272  solid = dd4hep::Trap(ns.prepend(name),
273  0.5 * moduleThick,
274  parm.theta,
275  parm.phi,
276  parm.yh1,
277  parm.bl1,
278  parm.tl1,
279  parm.alp,
280  parm.yh2,
281  parm.bl2,
282  parm.tl2,
283  parm.alp);
284 #ifdef EDM_ML_DEBUG
285  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of " << matabsorbr.name()
286  << " of dimensions " << cms::convert2mm(0.5 * moduleThick) << ", "
287  << convertRadToDeg(parm.theta) << ", " << convertRadToDeg(parm.phi) << ", "
288  << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
289  << cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
290  << cms::convert2mm(parm.yh2) << ", " << cms::convert2mm(parm.bl2) << ", "
291  << cms::convert2mm(parm.tl2) << ", " << convertRadToDeg(parm.alp);
292 #endif
293  glog = dd4hep::Volume(solid.name(), solid, matabsorbr);
294 
295  dd4hep::Position r2(parm.xpos, parm.ypos, parm.zpos);
296  module.placeVolume(glog, idOffset + layer + 1, dd4hep::Transform3D(rot, r2));
297 #ifdef EDM_ML_DEBUG
298  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << glog.name() << " number 1 positioned in "
299  << module.name() << " at (" << cms::convert2mm(parm.xpos) << ", "
300  << cms::convert2mm(parm.ypos) << ", " << cms::convert2mm(parm.zpos)
301  << ") with rotation: " << rot;
302 #endif
303  }
304 
306  cms::DDNamespace ns(ctxt, e, true);
307 #ifdef EDM_ML_DEBUG
308  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: \t\tInside module";
309 #endif
310  //Pointers to the Rotation Matrices and to the Materials
312  dd4hep::Material matter = ns.material(genMaterial);
313  dd4hep::Material matplastic = ns.material(plasticMat);
314  dd4hep::Rotation3D rot = getRotation(rotstr, ns);
315 
316  double alpha = (1._pi) / sectors;
317  double zi = zMinBlock;
318 
319  for (unsigned int i = 0; i < layerName.size(); i++) {
321  dd4hep::Solid solid;
322  dd4hep::Volume glog, plog;
323  int layer = layerNumber[i];
324  double zo = zi + 0.5 * dzStep;
325 
326  for (unsigned int iphi = 0; iphi < phiName.size(); iphi++) {
327  double ziAir = zo - moduleThick;
328  double rinF, rinB;
329  if (modNumber == 0) {
330  rinF = ziAir * slopeTopF;
331  rinB = zo * slopeTopF;
332  } else {
333  rinF = ziAir * slopeBot;
334  rinB = zo * slopeBot;
335  }
336  double routF = getRout(ziAir);
337  double routB = getRout(zo);
338 #ifdef EDM_ML_DEBUG
339  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: Layer " << i << " Phi " << iphi << " Front "
340  << cms::convert2mm(ziAir) << ", " << cms::convert2mm(rinF) << ", "
341  << cms::convert2mm(routF) << " Back " << cms::convert2mm(zo) << ", "
342  << cms::convert2mm(rinB) << ", " << cms::convert2mm(routB);
343 #endif
344  HCalEndcapModuleAlgo::HcalEndcapPar parm = parameterLayer(iphi, rinF, routF, rinB, routB, ziAir, zo);
345 
346  name = idName + modName + layerName[i] + phiName[iphi] + "Air";
347  solid = dd4hep::Trap(ns.prepend(name),
348  0.5 * moduleThick,
349  parm.theta,
350  parm.phi,
351  parm.yh1,
352  parm.bl1,
353  parm.tl1,
354  parm.alp,
355  parm.yh2,
356  parm.bl2,
357  parm.tl2,
358  parm.alp);
359 #ifdef EDM_ML_DEBUG
360  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of " << matter.name()
361  << " of dimensions " << cms::convert2mm(0.5 * moduleThick) << ", "
362  << convertRadToDeg(parm.theta) << ", " << convertRadToDeg(parm.phi) << ", "
363  << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
364  << cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
365  << cms::convert2mm(parm.yh2) << ", " << cms::convert2mm(parm.bl2) << ", "
366  << cms::convert2mm(parm.tl2) << ", " << convertRadToDeg(parm.alp);
367 #endif
368  glog = dd4hep::Volume(solid.name(), solid, matter);
369 
370  dd4hep::Position r1(parm.xpos, parm.ypos, parm.zpos);
371  module.placeVolume(glog, layer + 1, dd4hep::Transform3D(rot, r1));
372 #ifdef EDM_ML_DEBUG
373  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << glog.name() << " number " << (layer + 1)
374  << " positioned in " << module.name() << " at (" << cms::convert2mm(parm.xpos)
375  << ", " << cms::convert2mm(parm.ypos) << ", " << cms::convert2mm(parm.zpos)
376  << ") with rotation: " << rot;
377 #endif
378  //Now the plastic with scintillators
379  parm.yh1 = 0.5 * (routF - rinB) - getTrim(iphi);
380  parm.bl1 = 0.5 * rinB * tan(alpha) - getTrim(iphi);
381  parm.tl1 = 0.5 * routF * tan(alpha) - getTrim(iphi);
382  name = idName + modName + layerName[i] + phiName[iphi];
383  solid = dd4hep::Trap(ns.prepend(name),
384  0.5 * layerThick,
385  0,
386  0,
387  parm.yh1,
388  parm.bl1,
389  parm.tl1,
390  parm.alp,
391  parm.yh1,
392  parm.bl1,
393  parm.tl1,
394  parm.alp);
395 #ifdef EDM_ML_DEBUG
396  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of "
397  << matplastic.name() << " of dimensions " << cms::convert2mm(0.5 * layerThick)
398  << ", 0, 0, " << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1)
399  << ", " << cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
400  << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
401  << cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp);
402 #endif
403  plog = dd4hep::Volume(solid.name(), solid, matplastic);
404 
405  double ypos = 0.5 * (routF + rinB) - parm.xpos;
406  dd4hep::Position r2(0., ypos, 0.);
407  glog.placeVolume(plog, idOffset + layer + 1, r2);
408 #ifdef EDM_ML_DEBUG
409  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << plog.name() << " number "
410  << (idOffset + layer + 1) << " positioned in " << glog.name() << " at (0, "
411  << cms::convert2mm(ypos) << ", 0) with no rotation";
412 #endif
413  //Constructin the scintillators inside
414  int copyNo = layer * 10 + layerType;
415  name = modName + layerName[i] + phiName[iphi];
416  constructScintLayer(plog, scintThick, parm, name, copyNo, ns);
417  zo += 0.5 * dzStep;
418  } // End of loop over phi indices
419  zi = zo - 0.5 * dzStep;
420  } // End of loop on layers
421  }
422 
425  //Given module and layer number compute parameters of trapezoid
426  //and positioning parameters
427  double alpha = (1._pi) / sectors;
428 #ifdef EDM_ML_DEBUG
429  edm::LogVerbatim("HCalGeom") << "Input " << iphi << " Alpha " << convertRadToDeg(alpha);
430 #endif
431  double zi, zo;
432  if (iphi == 0) {
433  zi = zMinBlock;
434  zo = zi + layerThick;
435  } else {
436  zo = zMaxBlock;
437  zi = zo - layerThick;
438  }
439  double rin, rout;
440  if (modNumber == 0) {
441  rin = zo * slopeTopF;
442  rout = (zi - z1Beam) * slopeTop;
443  } else if (modNumber > 0) {
444  rin = zo * slopeBot;
445  rout = zi * slopeTopF;
446  } else {
447  rin = zo * slopeBot;
448  rout = (zi - z1Beam) * slopeTop;
449  }
450 #ifdef EDM_ML_DEBUG
451  edm::LogVerbatim("HCalGeom") << "ModNumber " << modNumber << " " << cms::convert2mm(zi) << " "
452  << cms::convert2mm(zo) << " " << slopeTopF << " " << slopeTop << " " << slopeBot << " "
453  << cms::convert2mm(rin) << " " << cms::convert2mm(rout) << " "
454  << cms::convert2mm(getTrim(iphi));
455 #endif
456  double yh = 0.5 * (rout - rin);
457  double bl = 0.5 * rin * tan(alpha);
458  double tl = 0.5 * rout * tan(alpha);
459  parm.xpos = 0.5 * (rin + rout);
460  parm.ypos = 0.5 * (bl + tl);
461  parm.zpos = 0.5 * (zi + zo);
462  parm.yh1 = parm.yh2 = yh - getTrim(iphi);
463  parm.bl1 = parm.bl2 = bl - getTrim(iphi);
464  parm.tl1 = parm.tl2 = tl - getTrim(iphi);
465  parm.alp = atan(0.5 * tan(alpha));
466  if (iphi == 0) {
467  parm.ypos = -parm.ypos;
468  } else {
469  parm.alp = -parm.alp;
470  }
471 #ifdef EDM_ML_DEBUG
472  edm::LogVerbatim("HCalGeom") << "Output Dimensions " << cms::convert2mm(parm.yh1) << " "
473  << cms::convert2mm(parm.bl1) << " " << cms::convert2mm(parm.tl1) << " "
474  << convertRadToDeg(parm.alp) << " Position " << cms::convert2mm(parm.xpos) << " "
475  << cms::convert2mm(parm.ypos) << " " << cms::convert2mm(parm.zpos);
476 #endif
477  return parm;
478  }
479 
481  unsigned int iphi, double rinF, double routF, double rinB, double routB, double zi, double zo) {
483  //Given rin, rout compute parameters of the trapezoid and
484  //position of the trapezoid for a standrd layer
485  double alpha = (1._pi) / sectors;
486 #ifdef EDM_ML_DEBUG
487  edm::LogVerbatim("HCalGeom") << "Input " << iphi << " Front " << cms::convert2mm(rinF) << " "
488  << cms::convert2mm(routF) << " " << cms::convert2mm(zi) << " Back "
489  << cms::convert2mm(rinB) << " " << cms::convert2mm(routB) << " " << cms::convert2mm(zo)
490  << " Alpha " << convertRadToDeg(alpha);
491 #endif
492  parm.yh1 = 0.5 * (routF - rinB);
493  parm.bl1 = 0.5 * rinB * tan(alpha);
494  parm.tl1 = 0.5 * routF * tan(alpha);
495  parm.yh2 = 0.5 * (routF - rinB);
496  parm.bl2 = 0.5 * rinB * tan(alpha);
497  parm.tl2 = 0.5 * routF * tan(alpha);
498  double dx = 0.25 * (parm.bl2 + parm.tl2 - parm.bl1 - parm.tl1);
499  double dy = 0.5 * (rinB + routF - rinB - routF);
500  parm.xpos = 0.25 * (rinB + routF + rinB + routF);
501  parm.ypos = 0.25 * (parm.bl2 + parm.tl2 + parm.bl1 + parm.tl1);
502  parm.zpos = 0.5 * (zi + zo);
503  parm.alp = atan(0.5 * tan(alpha));
504  if (iphi == 0) {
505  parm.ypos = -parm.ypos;
506  } else {
507  parm.alp = -parm.alp;
508  dx = -dx;
509  }
510  double r = sqrt(dx * dx + dy * dy);
511 #ifdef EDM_ML_DEBUG
512  edm::LogVerbatim("HCalGeom") << "dx|dy|r " << cms::convert2mm(dx) << ":" << cms::convert2mm(dy) << ":"
513  << cms::convert2mm(r);
514 #endif
515  if (r > 1.0e-8) {
516  parm.theta = atan(r / (zo - zi));
517  parm.phi = atan2(dy, dx);
518  } else {
519  parm.theta = parm.phi = 0;
520  }
521 #ifdef EDM_ML_DEBUG
522  edm::LogVerbatim("HCalGeom") << "Output Dimensions " << cms::convert2mm(parm.yh1) << " "
523  << cms::convert2mm(parm.bl1) << " " << cms::convert2mm(parm.tl1) << " "
524  << cms::convert2mm(parm.yh2) << " " << cms::convert2mm(parm.bl2) << " "
525  << cms::convert2mm(parm.tl2) << " " << convertRadToDeg(parm.alp) << " "
526  << convertRadToDeg(parm.theta) << " " << convertRadToDeg(parm.phi) << " Position "
527  << cms::convert2mm(parm.xpos) << " " << cms::convert2mm(parm.ypos) << " "
528  << cms::convert2mm(parm.zpos);
529 #endif
530  return parm;
531  }
532 
534  double dz,
536  const std::string& nm,
537  int id,
538  cms::DDNamespace& ns) {
539  dd4hep::Material matter = ns.material(scintMat);
540  std::string name = idName + "Scintillator" + nm;
541 
542  dd4hep::Solid solid = dd4hep::Trap(
543  ns.prepend(name), 0.5 * dz, 0, 0, parm.yh1, parm.bl1, parm.tl1, parm.alp, parm.yh1, parm.bl1, parm.tl1, parm.alp);
544 #ifdef EDM_ML_DEBUG
545  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << solid.name() << " Trap made of " << scintMat
546  << " of dimensions " << cms::convert2mm(0.5 * dz) << ", 0, 0, "
547  << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
548  << cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp) << ", "
549  << cms::convert2mm(parm.yh1) << ", " << cms::convert2mm(parm.bl1) << ", "
550  << cms::convert2mm(parm.tl1) << ", " << convertRadToDeg(parm.alp);
551 #endif
552  dd4hep::Volume glog(solid.name(), solid, matter);
553 
554  detector.placeVolume(glog, id);
555 #ifdef EDM_ML_DEBUG
556  edm::LogVerbatim("HCalGeom") << "DDHCalEndcapModuleAlgo: " << glog.name() << " number " << id << " positioned in "
557  << detector.name() << " at (0,0,0) with no rotation";
558 #endif
559  }
560 
561  double getTrim(unsigned int j) const {
562  if (j == 0)
563  return trimLeft;
564  else
565  return trimRight;
566  }
567 
568  double getRout(double z) const {
569  double r = (modNumber >= 0) ? ((z - z1Beam) * slopeTop) : z * slopeTopF;
570  if (z > ziDip) {
571  if (r > rMaxBack)
572  r = rMaxBack;
573  } else {
574  if (r > rMaxFront)
575  r = rMaxFront;
576  }
577  return r;
578  }
579 
580  dd4hep::Rotation3D getRotation(const std::string& rotstr, cms::DDNamespace& ns) {
581  std::string rot = (strchr(rotstr.c_str(), NAMESPACE_SEP) == nullptr) ? ("rotations:" + rotstr) : rotstr;
582 #ifdef EDM_ML_DEBUG
583  edm::LogVerbatim("HCalGeom") << "getRotation: " << rotstr << ":" << rot << ":" << ns.rotation(rot);
584 #endif
585  return ns.rotation(rot);
586  }
587 };
588 
589 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
590  HCalEndcapModuleAlgo hcalendcapalgo(ctxt, e);
591  return cms::s_executed;
592 }
593 
594 // first argument is the type from the xml file
595 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalEndcapModuleAlgo, algorithm)
Log< level::Info, true > LogVerbatim
const dd4hep::Rotation3D & rotation(const std::string &name) const
Definition: DDNamespace.cc:182
void constructInsideModule0(cms::DDParsingContext &ctxt, xml_h e, dd4hep::Volume &module)
HCalEndcapModuleAlgo(cms::DDParsingContext &ctxt, xml_h e)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
void constructScintLayer(dd4hep::Volume &detector, double dz, HCalEndcapModuleAlgo::HcalEndcapPar parm, const std::string &nm, int id, cms::DDNamespace &ns)
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
double getRout(double z) const
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)
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
HcalEndcapPar parameterLayer0(unsigned int iphi)
static constexpr long s_executed
double getTrim(unsigned int j) const
T sqrt(T t)
Definition: SSEVec.h:19
std::string_view name() const
Definition: DDNamespace.h:79
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
dd4hep::Volume Volume
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
std::vector< std::string > layerName
std::vector< int > layerNumber
dd4hep::Rotation3D getRotation(const std::string &rotstr, cms::DDNamespace &ns)
std::vector< std::string > phiName
float x
Geom::Theta< T > theta() const
HcalEndcapPar parameterLayer(unsigned int iphi, double rinF, double routF, double rinB, double routB, double zi, double zo)
void constructInsideModule(cms::DDParsingContext &ctxt, xml_h e, dd4hep::Volume &module)
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
#define NAMESPACE_SEP
Definition: DDNamespace.h:92