CMS 3D CMS Logo

DDHGCalHEAlgo.cc
Go to the documentation of this file.
1 // File: DDHGCalHEAlgo.cc
3 // Description: Geometry factory class for HGCal (Mix)
4 // Author : Raman Sehgal
5 // DD4hep code for, HGCalHEAlgo, developed by Sunanda Banerjee
7 
8 #include <cmath>
9 #include <memory>
10 #include <string>
11 #include <unordered_set>
12 #include <vector>
13 
14 #include "DD4hep/DetFactoryHelper.h"
23 
24 //#define EDM_ML_DEBUG
25 using namespace angle_units::operators;
26 
27 struct HGCalHEAlgo {
28  HGCalHEAlgo() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalHEAlgo"; }
30  cms::DDNamespace ns(ctxt, e, true);
32 
33 #ifdef EDM_ML_DEBUG
34  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: Creating an instance";
35 #endif
36 
37  dd4hep::Volume mother = ns.volume(args.parentName());
38  waferNames_ = args.value<std::vector<std::string>>("WaferNames");
39 #ifdef EDM_ML_DEBUG
40  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << waferNames_.size() << " wafers";
41  for (unsigned int i = 0; i < waferNames_.size(); ++i)
42  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << waferNames_[i];
43 #endif
44  materials_ = args.value<std::vector<std::string>>("MaterialNames");
45  volumeNames_ = args.value<std::vector<std::string>>("VolumeNames");
46  thickness_ = args.value<std::vector<double>>("Thickness");
47  copyNumber_.resize(materials_.size(), 1);
48 #ifdef EDM_ML_DEBUG
49  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << materials_.size() << " types of volumes";
50  for (unsigned int i = 0; i < volumeNames_.size(); ++i)
51  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << volumeNames_[i] << " of thickness "
52  << cms::convert2mm(thickness_[i]) << " filled with " << materials_[i]
53  << " first copy number " << copyNumber_[i];
54 #endif
55  layerNumbers_ = args.value<std::vector<int>>("Layers");
56  layerThick_ = args.value<std::vector<double>>("LayerThick");
57  rMixLayer_ = args.value<std::vector<double>>("LayerRmix");
58 #ifdef EDM_ML_DEBUG
59  edm::LogVerbatim("HGCalGeom") << "There are " << layerNumbers_.size() << " blocks";
60  for (unsigned int i = 0; i < layerNumbers_.size(); ++i)
61  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << cms::convert2mm(layerThick_[i])
62  << " Rmid " << cms::convert2mm(rMixLayer_[i]) << " with " << layerNumbers_[i]
63  << " layers";
64 #endif
65  layerType_ = args.value<std::vector<int>>("LayerType");
66  layerSense_ = args.value<std::vector<int>>("LayerSense");
67  firstLayer_ = args.value<int>("FirstLayer");
68  absorbMode_ = args.value<int>("AbsorberMode");
69  sensitiveMode_ = args.value<int>("SensitiveMode");
70 #ifdef EDM_ML_DEBUG
71  edm::LogVerbatim("HGCalGeom") << "First Layer " << firstLayer_ << " and "
72  << "Absober:Sensitive mode " << absorbMode_ << ":" << sensitiveMode_;
73 #endif
74  layerCenter_ = args.value<std::vector<int>>("LayerCenter");
75 #ifdef EDM_ML_DEBUG
76  for (unsigned int i = 0; i < layerCenter_.size(); ++i)
77  edm::LogVerbatim("HGCalGeom") << "LayerCenter [" << i << "] " << layerCenter_[i];
78 #endif
79  if (firstLayer_ > 0) {
80  for (unsigned int i = 0; i < layerType_.size(); ++i) {
81  if (layerSense_[i] > 0) {
82  int ii = layerType_[i];
83  copyNumber_[ii] = firstLayer_;
84 #ifdef EDM_ML_DEBUG
85  edm::LogVerbatim("HGCalGeom") << "First copy number for layer type " << i << ":" << ii << " with "
86  << materials_[ii] << " changed to " << copyNumber_[ii];
87 #endif
88  break;
89  }
90  }
91  }
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " layers";
94  for (unsigned int i = 0; i < layerType_.size(); ++i)
95  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
96  << layerSense_[i];
97 #endif
98  materialsTop_ = args.value<std::vector<std::string>>("TopMaterialNames");
99  namesTop_ = args.value<std::vector<std::string>>("TopVolumeNames");
100  layerThickTop_ = args.value<std::vector<double>>("TopLayerThickness");
101  layerTypeTop_ = args.value<std::vector<int>>("TopLayerType");
102  copyNumberTop_.resize(materialsTop_.size(), 1);
103 #ifdef EDM_ML_DEBUG
104  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << materialsTop_.size() << " types of volumes in the top part";
105  for (unsigned int i = 0; i < materialsTop_.size(); ++i)
106  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << namesTop_[i] << " of thickness "
107  << cms::convert2mm(layerThickTop_[i]) << " filled with " << materialsTop_[i]
108  << " first copy number " << copyNumberTop_[i];
109  edm::LogVerbatim("HGCalGeom") << "There are " << layerTypeTop_.size() << " layers in the top part";
110  for (unsigned int i = 0; i < layerTypeTop_.size(); ++i)
111  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerTypeTop_[i];
112 #endif
113  materialsBot_ = args.value<std::vector<std::string>>("BottomMaterialNames");
114  namesBot_ = args.value<std::vector<std::string>>("BottomVolumeNames");
115  layerTypeBot_ = args.value<std::vector<int>>("BottomLayerType");
116  layerSenseBot_ = args.value<std::vector<int>>("BottomLayerSense");
117  layerThickBot_ = args.value<std::vector<double>>("BottomLayerThickness");
118  copyNumberBot_.resize(materialsBot_.size(), 1);
119 #ifdef EDM_ML_DEBUG
120  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << materialsBot_.size()
121  << " types of volumes in the bottom part";
122  for (unsigned int i = 0; i < materialsBot_.size(); ++i)
123  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << namesBot_[i] << " of thickness "
124  << cms::convert2mm(layerThickBot_[i]) << " filled with " << materialsBot_[i]
125  << " first copy number " << copyNumberBot_[i];
126  edm::LogVerbatim("HGCalGeom") << "There are " << layerTypeBot_.size() << " layers in the bottom part";
127  for (unsigned int i = 0; i < layerTypeBot_.size(); ++i)
128  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerTypeBot_[i]
129  << " sensitive class " << layerSenseBot_[i];
130 #endif
131  zMinBlock_ = args.value<double>("zMinBlock");
132  rad100to200_ = args.value<std::vector<double>>("rad100to200");
133  rad200to300_ = args.value<std::vector<double>>("rad200to300");
134  zMinRadPar_ = args.value<double>("zMinForRadPar");
135  choiceType_ = args.value<int>("choiceType");
136  nCutRadPar_ = args.value<int>("nCornerCut");
137  fracAreaMin_ = args.value<double>("fracAreaMin");
138  waferSize_ = args.value<double>("waferSize");
139  waferSepar_ = args.value<double>("SensorSeparation");
140  sectors_ = args.value<int>("Sectors");
141  alpha_ = (1._pi) / sectors_;
142  cosAlpha_ = cos(alpha_);
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: zStart " << cms::convert2mm(zMinBlock_)
145  << " radius for wafer type separation uses " << rad100to200_.size()
146  << " parameters; zmin " << cms::convert2mm(zMinRadPar_) << " cutoff " << choiceType_
147  << ":" << nCutRadPar_ << ":" << fracAreaMin_ << " wafer width "
148  << cms::convert2mm(waferSize_) << " separations " << cms::convert2mm(waferSepar_)
149  << " sectors " << sectors_ << ":" << convertRadToDeg(alpha_) << ":" << cosAlpha_;
150  for (unsigned int k = 0; k < rad100to200_.size(); ++k)
151  edm::LogVerbatim("HGCalGeom") << "[" << k << "] 100-200 " << rad100to200_[k] << " 200-300 " << rad200to300_[k];
152 #endif
153  slopeB_ = args.value<std::vector<double>>("SlopeBottom");
154  zFrontB_ = args.value<std::vector<double>>("ZFrontBottom");
155  rMinFront_ = args.value<std::vector<double>>("RMinFront");
156  slopeT_ = args.value<std::vector<double>>("SlopeTop");
157  zFrontT_ = args.value<std::vector<double>>("ZFrontTop");
158  rMaxFront_ = args.value<std::vector<double>>("RMaxFront");
159 #ifdef EDM_ML_DEBUG
160  for (unsigned int i = 0; i < slopeB_.size(); ++i)
161  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << cms::convert2mm(zFrontB_[i]) << " Rmin "
162  << cms::convert2mm(rMinFront_[i]) << " Slope " << slopeB_[i];
163  for (unsigned int i = 0; i < slopeT_.size(); ++i)
164  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << cms::convert2mm(zFrontT_[i]) << " Rmax "
165  << cms::convert2mm(rMaxFront_[i]) << " Slope " << slopeT_[i];
166  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: NameSpace " << ns.name();
167 #endif
168 
169  waferType_ = std::make_unique<HGCalWaferType>(rad100to200_,
170  rad200to300_,
171  cms::convert2mm((waferSize_ + waferSepar_)),
172  cms::convert2mm(zMinRadPar_),
173  choiceType_,
174  nCutRadPar_,
175  fracAreaMin_);
176 
177 #ifdef EDM_ML_DEBUG
178  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalHEAlgo...";
179  copies_.clear();
180 #endif
181 
182  double zi(zMinBlock_);
183  int laymin(0);
184  for (unsigned int i = 0; i < layerNumbers_.size(); i++) {
185  double zo = zi + layerThick_[i];
186  double routF = HGCalGeomTools::radius(zi, zFrontT_, rMaxFront_, slopeT_);
187  int laymax = laymin + layerNumbers_[i];
188  double zz = zi;
189  double thickTot(0);
190  for (int ly = laymin; ly < laymax; ++ly) {
191  int ii = layerType_[ly];
192  int copy = copyNumber_[ii];
193  double hthick = 0.5 * thickness_[ii];
194  double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_);
195  zz += hthick;
196  thickTot += thickness_[ii];
197 
198  std::string name = volumeNames_[ii] + std::to_string(copy);
199 
200 #ifdef EDM_ML_DEBUG
201  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: Layer " << ly << ":" << ii << " Front " << cms::convert2mm(zi)
202  << ", " << cms::convert2mm(routF) << " Back " << cms::convert2mm(zo) << ", "
203  << cms::convert2mm(rinB) << " superlayer thickness "
204  << cms::convert2mm(layerThick_[i]);
205 #endif
206 
207  dd4hep::Material matter = ns.material(materials_[ii]);
208  dd4hep::Volume glog;
209 
210  if (layerSense_[ly] < 1) {
211  std::vector<double> pgonZ, pgonRin, pgonRout;
212  if (layerSense_[ly] == 0 || absorbMode_ == 0) {
213  double rmax =
214  (std::min(routF, HGCalGeomTools::radius(zz + hthick, zFrontT_, rMaxFront_, slopeT_)) * cosAlpha_) -
215  tol1_;
216  pgonZ.emplace_back(-hthick);
217  pgonZ.emplace_back(hthick);
218  pgonRin.emplace_back(rinB);
219  pgonRin.emplace_back(rinB);
220  pgonRout.emplace_back(rmax);
221  pgonRout.emplace_back(rmax);
222  } else {
223  HGCalGeomTools::radius(zz - hthick,
224  zz + hthick,
225  zFrontB_,
226  rMinFront_,
227  slopeB_,
228  zFrontT_,
229  rMaxFront_,
230  slopeT_,
231  -layerSense_[ly],
232  pgonZ,
233  pgonRin,
234  pgonRout);
235  for (unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
236  pgonZ[isec] -= zz;
237  pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1_;
238  }
239  }
240 
241  dd4hep::Solid solid = dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
242  ns.addSolidNS(ns.prepend(name), solid);
243  glog = dd4hep::Volume(solid.name(), solid, matter);
244  ns.addVolumeNS(glog);
245 #ifdef EDM_ML_DEBUG
246  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << solid.name() << " polyhedra of " << sectors_
247  << " sectors covering " << convertRadToDeg(-alpha_) << ":"
248  << convertRadToDeg(-alpha_ + 2._pi) << " with " << pgonZ.size() << " sections";
249  for (unsigned int k = 0; k < pgonZ.size(); ++k)
250  edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << cms::convert2mm(pgonZ[k]) << " R "
251  << cms::convert2mm(pgonRin[k]) << ":" << cms::convert2mm(pgonRout[k]);
252 #endif
253  } else {
254  double rins =
255  (sensitiveMode_ < 1) ? rinB : HGCalGeomTools::radius(zz + hthick, zFrontB_, rMinFront_, slopeB_);
256  double routs =
257  (sensitiveMode_ < 1) ? routF : HGCalGeomTools::radius(zz - hthick, zFrontT_, rMaxFront_, slopeT_);
258  dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
259  ns.addSolidNS(ns.prepend(name), solid);
260  glog = dd4hep::Volume(solid.name(), solid, matter);
261  ns.addVolumeNS(glog);
262 
263 #ifdef EDM_ML_DEBUG
264  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << solid.name() << " Tubs made of " << matter.name()
265  << " of dimensions " << cms::convert2mm(rinB) << ":" << cms::convert2mm(rins)
266  << ", " << cms::convert2mm(routF) << ":" << cms::convert2mm(routs) << ", "
267  << cms::convert2mm(hthick) << ", 0.0, 360.0 and positioned in: " << glog.name()
268  << " number " << copy;
269 #endif
270  positionMix(ctxt, e, glog, name, copy, thickness_[ii], matter, rins, rMixLayer_[i], routs, zz);
271  }
272 
273  dd4hep::Position r1(0, 0, zz);
274  mother.placeVolume(glog, copy, r1);
275  ++copyNumber_[ii];
276 #ifdef EDM_ML_DEBUG
277  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << glog.name() << " number " << copy << " positioned in "
278  << mother.name() << " at (0,0," << cms::convert2mm(zz) << ") with no rotation";
279 #endif
280  zz += hthick;
281  } // End of loop over layers in a block
282  zi = zo;
283  laymin = laymax;
284  if (std::abs(thickTot - layerThick_[i]) >= tol2_) {
285  if (thickTot > layerThick_[i]) {
286  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick_[i])
287  << " is smaller than " << cms::convert2mm(thickTot)
288  << ": thickness of all its components **** ERROR ****";
289  } else {
290  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick_[i])
291  << " does not match with " << cms::convert2mm(thickTot) << " of the components";
292  }
293  }
294  } // End of loop over blocks
295 
296 #ifdef EDM_ML_DEBUG
297  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << copies_.size() << " different wafer copy numbers";
298  int k(0);
299  for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++k) {
300  edm::LogVerbatim("HGCalGeom") << "Copy [" << k << "] : " << (*itr);
301  }
302  copies_.clear();
303  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalHEAlgo construction...";
304 #endif
305  }
306 
308  xml_h e,
309  const dd4hep::Volume& glog,
310  const std::string& nameM,
311  int copyM,
312  double thick,
313  const dd4hep::Material& matter,
314  double rin,
315  double rmid,
316  double rout,
317  double zz) {
318  cms::DDNamespace ns(ctxt, e, true);
319 
320  dd4hep::Volume glog1;
321  for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
322  int ii = layerTypeTop_[ly];
323  copyNumberTop_[ii] = copyM;
324  }
325  for (unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
326  int ii = layerTypeBot_[ly];
327  copyNumberBot_[ii] = copyM;
328  }
329  double hthick = 0.5 * thick;
330  // Make the top part first
331  std::string name = nameM + "Top";
332 
333  dd4hep::Solid solid = dd4hep::Tube(rmid, rout, hthick, 0.0, 2._pi);
334  ns.addSolidNS(ns.prepend(name), solid);
335  glog1 = dd4hep::Volume(solid.name(), solid, matter);
336  ns.addVolumeNS(glog1);
337 #ifdef EDM_ML_DEBUG
338  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << solid.name() << " Tubs made of " << matter.name()
339  << " of dimensions " << cms::convert2mm(rmid) << ", " << cms::convert2mm(rout) << ", "
340  << cms::convert2mm(hthick) << ", 0.0, 360.0";
341 #endif
342  glog.placeVolume(glog1, 1);
343 
344 #ifdef EDM_ML_DEBUG
345  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << glog1.name() << " number 1 positioned in " << glog.name()
346  << " at (0,0,0) with no rotation";
347 #endif
348  double thickTot(0), zpos(-hthick);
349  for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
350  int ii = layerTypeTop_[ly];
351  int copy = copyNumberTop_[ii];
352  double hthickl = 0.5 * layerThickTop_[ii];
353  thickTot += layerThickTop_[ii];
354  name = namesTop_[ii] + std::to_string(copy);
355 #ifdef EDM_ML_DEBUG
356  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: Layer " << ly << ":" << ii << " R " << cms::convert2mm(rmid)
357  << ":" << cms::convert2mm(rout) << " Thick " << cms::convert2mm(layerThickTop_[ii]);
358 #endif
359 
360  dd4hep::Material matter1 = ns.material(materialsTop_[ii]);
361  solid = dd4hep::Tube(rmid, rout, hthickl, 0.0, 2._pi);
362  ns.addSolidNS(ns.prepend(name), solid);
363  dd4hep::Volume glog2 = dd4hep::Volume(solid.name(), solid, matter1);
364  ns.addVolumeNS(glog2);
365 
366 #ifdef EDM_ML_DEBUG
367  double eta1 = -log(tan(0.5 * atan(rmid / zz)));
368  double eta2 = -log(tan(0.5 * atan(rout / zz)));
369  edm::LogVerbatim("HGCalGeom") << name << " z|rin|rout " << cms::convert2mm(zz) << ":" << cms::convert2mm(rmid)
370  << ":" << cms::convert2mm(rout) << " eta " << eta1 << ":" << eta2;
371  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << solid.name() << " Tubs made of " << matter1.name()
372  << " of dimensions " << cms::convert2mm(rmid) << ", " << cms::convert2mm(rout)
373  << ", " << cms::convert2mm(hthickl) << ", 0.0, 360.0";
374 #endif
375  zpos += hthickl;
376 
377  dd4hep::Position r1(0, 0, zpos);
378  glog1.placeVolume(glog2, copy, r1);
379 
380 #ifdef EDM_ML_DEBUG
381  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: Position " << glog2.name() << " number " << copy << " in "
382  << glog1.name() << " at (0,0," << cms::convert2mm(zpos) << ") with no rotation";
383 #endif
384  ++copyNumberTop_[ii];
385  zpos += hthickl;
386  }
387  if (std::abs(thickTot - thick) >= tol2_) {
388  if (thickTot > thick) {
389  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
390  << cms::convert2mm(thickTot)
391  << ": thickness of all its components in the top part **** ERROR ****";
392  } else {
393  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
394  << " does not match with " << cms::convert2mm(thickTot)
395  << " of the components in top part";
396  }
397  }
398 
399  // Make the bottom part next
400  name = nameM + "Bottom";
401 
402  solid = dd4hep::Tube(rin, rmid, hthick, 0.0, 2._pi);
403  ns.addSolidNS(ns.prepend(name), solid);
404  glog1 = dd4hep::Volume(solid.name(), solid, matter);
405  ns.addVolumeNS(glog1);
406 
407 #ifdef EDM_ML_DEBUG
408  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << solid.name() << " Tubs made of " << matter.name()
409  << " of dimensions " << cms::convert2mm(rin) << ", " << cms::convert2mm(rmid) << ", "
410  << cms::convert2mm(hthick) << ", 0.0, 360.0";
411 #endif
412 
413  glog.placeVolume(glog1, 1);
414 #ifdef EDM_ML_DEBUG
415  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << glog1.name() << " number 1 positioned in " << glog.name()
416  << " at (0,0,0) with no rotation";
417 #endif
418  thickTot = 0;
419  zpos = -hthick;
420  for (unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
421  int ii = layerTypeBot_[ly];
422  int copy = copyNumberBot_[ii];
423  double hthickl = 0.5 * layerThickBot_[ii];
424  thickTot += layerThickBot_[ii];
425  name = namesBot_[ii] + std::to_string(copy);
426 #ifdef EDM_ML_DEBUG
427  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: Layer " << ly << ":" << ii << " R " << cms::convert2mm(rin)
428  << ":" << cms::convert2mm(rmid) << " Thick " << cms::convert2mm(layerThickBot_[ii]);
429 #endif
430 
431  dd4hep::Material matter1 = ns.material(materialsBot_[ii]);
432  solid = dd4hep::Tube(rin, rmid, hthickl, 0.0, 2._pi);
433  ns.addSolidNS(ns.prepend(name), solid);
434  dd4hep::Volume glog2 = dd4hep::Volume(solid.name(), solid, matter1);
435  ns.addVolumeNS(glog2);
436 
437 #ifdef EDM_ML_DEBUG
438  double eta1 = -log(tan(0.5 * atan(rin / zz)));
439  double eta2 = -log(tan(0.5 * atan(rmid / zz)));
440  edm::LogVerbatim("HGCalGeom") << name << " z|rin|rout " << cms::convert2mm(zz) << ":" << cms::convert2mm(rin)
441  << ":" << cms::convert2mm(rmid) << " eta " << eta1 << ":" << eta2;
442  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << solid.name() << " Tubs made of " << matter1.name()
443  << " of dimensions " << cms::convert2mm(rin) << ", " << cms::convert2mm(rmid)
444  << ", " << cms::convert2mm(hthickl) << ", 0.0, 360.0";
445 #endif
446  zpos += hthickl;
447 
448  dd4hep::Position r1(0, 0, zpos);
449  glog1.placeVolume(glog2, copy, r1);
450 #ifdef EDM_ML_DEBUG
451  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: Position " << glog2.name() << " number " << copy << " in "
452  << glog1.name() << " at (0,0," << cms::convert2mm(zpos) << ") with no rotation";
453 #endif
454  if (layerSenseBot_[ly] != 0) {
455 #ifdef EDM_ML_DEBUG
456  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: z " << cms::convert2mm((zz + zpos)) << " Center " << copy
457  << ":" << (copy - firstLayer_) << ":" << layerCenter_[copy - firstLayer_];
458 #endif
459  positionSensitive(ctxt, e, glog2, rin, rmid, zz + zpos, layerSenseBot_[ly], layerCenter_[copy - firstLayer_]);
460  }
461  zpos += hthickl;
462  ++copyNumberBot_[ii];
463  }
464  if (std::abs(thickTot - thick) >= tol2_) {
465  if (thickTot > thick) {
466  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
467  << cms::convert2mm(thickTot)
468  << ": thickness of all its components in the top part **** ERROR ****";
469  } else {
470  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
471  << " does not match with " << cms::convert2mm(thickTot)
472  << " of the components in top part";
473  }
474  }
475  }
476 
478  xml_h e,
479  const dd4hep::Volume& glog,
480  double rin,
481  double rout,
482  double zpos,
483  int layertype,
484  int layercenter) {
485  cms::DDNamespace ns(ctxt, e, true);
486  static const double sqrt3 = std::sqrt(3.0);
487  double r = 0.5 * (waferSize_ + waferSepar_);
488  double R = 2.0 * r / sqrt3;
489  double dy = 0.75 * R;
490  int N = (int)(0.5 * rout / r) + 2;
491  const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
492 #ifdef EDM_ML_DEBUG
493  int ium(0), ivm(0), iumAll(0), ivmAll(0), kount(0), ntot(0), nin(0);
494  std::vector<int> ntype(6, 0);
495  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: " << glog.name() << " rout " << cms::convert2mm(rout) << " N " << N
496  << " for maximum u, v Offset; Shift " << cms::convert2mm(xyoff.first) << ":"
497  << cms::convert2mm(xyoff.second) << " WaferSize "
498  << cms::convert2mm((waferSize_ + waferSepar_));
499 #endif
500  for (int u = -N; u <= N; ++u) {
501  for (int v = -N; v <= N; ++v) {
502  int nr = 2 * v;
503  int nc = -2 * u + v;
504  double xpos = xyoff.first + nc * r;
505  double ypos = xyoff.second + nr * dy;
506  const auto& corner = HGCalGeomTools::waferCorner(xpos, ypos, r, R, rin, rout, false);
507 #ifdef EDM_ML_DEBUG
508  int iu = std::abs(u);
509  int iv = std::abs(v);
510  ++ntot;
511 #endif
512  if (corner.first > 0) {
513  int type = waferType_->getType((xpos / dd4hep::mm), (ypos / dd4hep::mm), (zpos / dd4hep::mm));
514  int copy = HGCalTypes::packTypeUV(type, u, v);
515 #ifdef EDM_ML_DEBUG
516  if (iu > ium)
517  ium = iu;
518  if (iv > ivm)
519  ivm = iv;
520  kount++;
521  if (copies_.count(copy) == 0)
522  copies_.insert(copy);
523 #endif
524  if (corner.first == (int)(HGCalParameters::k_CornerSize)) {
525 #ifdef EDM_ML_DEBUG
526  if (iu > iumAll)
527  iumAll = iu;
528  if (iv > ivmAll)
529  ivmAll = iv;
530  ++nin;
531 #endif
532 
533  dd4hep::Position tran(xpos, ypos, 0.0);
534  if (layertype > 1)
535  type += 3;
536  glog.placeVolume(ns.volume(waferNames_[type]), copy, tran);
537 
538 #ifdef EDM_ML_DEBUG
539  ++ntype[type];
540  edm::LogVerbatim("HGCalGeom")
541  << "DDHGCalHEAlgo: " << glog.name() << " number " << copy << " positioned in " << glog.name() << " at ("
542  << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with no rotation";
543 #endif
544  }
545  }
546  }
547  }
548 #ifdef EDM_ML_DEBUG
549  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEAlgo: Maximum # of u " << ium << ":" << iumAll << " # of v " << ivm
550  << ":" << ivmAll << " and " << nin << ":" << kount << ":" << ntot << " wafers ("
551  << ntype[0] << ":" << ntype[1] << ":" << ntype[2] << ":" << ntype[3] << ":"
552  << ntype[4] << ":" << ntype[5] << ") for " << glog.name() << " R "
553  << cms::convert2mm(rin) << ":" << cms::convert2mm(rout);
554 #endif
555  }
556 
557  //Required data members to cache the values from XML file
559  std::unique_ptr<HGCalWaferType> waferType_;
560 
561  std::vector<std::string> waferNames_; // Wafer names
562  std::vector<std::string> materials_; // Materials
563  std::vector<std::string> volumeNames_; // Names
564  std::vector<double> thickness_; // Thickness of the material
565  std::vector<int> copyNumber_; // Initial copy numbers
566  std::vector<int> layerNumbers_; // Number of layers in a section
567  std::vector<double> layerThick_; // Thickness of each section
568  std::vector<double> rMixLayer_; // Partition between Si/Sci part
569  std::vector<int> layerType_; // Type of the layer
570  std::vector<int> layerSense_; // Content of a layer (sensitive?)
571  int firstLayer_; // Copy # of the first sensitive layer
572  int absorbMode_; // Absorber mode
573  int sensitiveMode_; // Sensitive mode
574  std::vector<std::string> materialsTop_; // Materials of top layers
575  std::vector<std::string> namesTop_; // Names of top layers
576  std::vector<double> layerThickTop_; // Thickness of the top sections
577  std::vector<int> layerTypeTop_; // Type of the Top layer
578  std::vector<int> copyNumberTop_; // Initial copy numbers (top section)
579  std::vector<std::string> materialsBot_; // Materials of bottom layers
580  std::vector<std::string> namesBot_; // Names of bottom layers
581  std::vector<double> layerThickBot_; // Thickness of the bottom sections
582  std::vector<int> layerTypeBot_; // Type of the bottom layers
583  std::vector<int> copyNumberBot_; // Initial copy numbers (bot section)
584  std::vector<int> layerSenseBot_; // Content of bottom layer (sensitive?)
585  std::vector<int> layerCenter_; // Centering of the wafers
586 
587  double zMinBlock_; // Starting z-value of the block
588  std::vector<double> rad100to200_; // Parameters for 120-200mum trans.
589  std::vector<double> rad200to300_; // Parameters for 200-300mum trans.
590  double zMinRadPar_; // Minimum z for radius parametriz.
591  int choiceType_; // Type of parametrization to be used
592  int nCutRadPar_; // Cut off threshold for corners
593  double fracAreaMin_; // Minimum fractional conatined area
594  double waferSize_; // Width of the wafer
595  double waferSepar_; // Sensor separation
596  int sectors_; // Sectors
597  std::vector<double> slopeB_; // Slope at the lower R
598  std::vector<double> zFrontB_; // Starting Z values for the slopes
599  std::vector<double> rMinFront_; // Corresponding rMin's
600  std::vector<double> slopeT_; // Slopes at the larger R
601  std::vector<double> zFrontT_; // Starting Z values for the slopes
602  std::vector<double> rMaxFront_; // Corresponding rMax's
603  std::unordered_set<int> copies_; // List of copy #'s
604  double alpha_, cosAlpha_;
605 
606  static constexpr double tol1_ = 0.01 * dd4hep::mm;
607  static constexpr double tol2_ = 0.00001 * dd4hep::mm;
608 };
609 
610 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
611  HGCalHEAlgo healgo(ctxt, e);
612  return cms::s_executed;
613 }
614 
615 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalHEAlgo, algorithm)
std::vector< int > layerNumbers_
Log< level::Info, true > LogVerbatim
std::vector< double > rad100to200_
static void radius(double zf, double zb, std::vector< double > const &zFront1, std::vector< double > const &rFront1, std::vector< double > const &slope1, std::vector< double > const &zFront2, std::vector< double > const &rFront2, std::vector< double > const &slope2, int flag, std::vector< double > &zz, std::vector< double > &rin, std::vector< double > &rout)
void positionMix(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, const std::string &nameM, int copyM, double thick, const dd4hep::Material &matter, double rin, double rmid, double rout, double zz)
HGCalGeomTools geomTools_
std::unordered_set< int > copies_
std::vector< double > slopeT_
int32_t *__restrict__ iv
std::vector< std::string > volumeNames_
std::vector< double > rMixLayer_
double zMinBlock_
std::vector< double > thickness_
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
HGCalHEAlgo(cms::DDParsingContext &ctxt, xml_h e)
void positionSensitive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, double rin, double rout, double zpos, int layertype, int layercenter)
std::vector< int > copyNumberTop_
std::string to_string(const V &value)
Definition: OMSAccess.h:77
std::vector< double > layerThick_
std::vector< double > rMaxFront_
double waferSepar_
std::vector< int > layerSense_
std::vector< int > layerTypeTop_
Log< level::Error, false > LogError
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
std::vector< double > zFrontT_
std::vector< std::string > namesBot_
std::vector< std::string > materialsTop_
static constexpr uint32_t k_CornerSize
std::vector< double > zFrontB_
std::vector< std::string > waferNames_
std::vector< std::string > materialsBot_
std::vector< double > layerThickTop_
std::vector< int > layerSenseBot_
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static std::pair< int32_t, int32_t > waferCorner(double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug=false)
double cosAlpha_
std::vector< double > slopeB_
static constexpr long s_executed
std::unique_ptr< HGCalWaferType > waferType_
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< double > rMinFront_
std::vector< int > layerType_
std::string_view name() const
Definition: DDNamespace.h:79
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< int > copyNumber_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< int > layerTypeBot_
std::vector< std::string > namesTop_
dd4hep::Volume Volume
ii
Definition: cuy.py:589
std::vector< std::string > materials_
#define N
Definition: blowfish.cc:9
double zMinRadPar_
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
std::vector< double > rad200to300_
std::vector< int > copyNumberBot_
double waferSize_
static int32_t packTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:3
double fracAreaMin_
Log< level::Warning, false > LogWarning
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:202
__shared__ uint32_t ntot
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::vector< double > layerThickBot_
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:292
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
std::vector< int > layerCenter_