CMS 3D CMS Logo

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